-
Notifications
You must be signed in to change notification settings - Fork 1
/
Problem.java
124 lines (97 loc) · 2.92 KB
/
Problem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* The problem contains some basic properties of the coco_problem_t structure that can be accessed
* through its getter functions.
*/
public class Problem {
private long pointer; // Pointer to the coco_problem_t object
private int dimension;
private int number_of_objectives;
private int number_of_constraints;
private double[] lower_bounds;
private double[] upper_bounds;
private String id;
private String name;
private long index;
/**
* Constructs the problem from the pointer.
* @param pointer pointer to the coco_problem_t object
* @throws Exception
*/
public Problem(long pointer) throws Exception {
super();
try {
this.dimension = CocoJNI.cocoProblemGetDimension(pointer);
this.number_of_objectives = CocoJNI.cocoProblemGetNumberOfObjectives(pointer);
this.number_of_constraints = CocoJNI.cocoProblemGetNumberOfConstraints(pointer);
this.lower_bounds = CocoJNI.cocoProblemGetSmallestValuesOfInterest(pointer);
this.upper_bounds = CocoJNI.cocoProblemGetLargestValuesOfInterest(pointer);
this.id = CocoJNI.cocoProblemGetId(pointer);
this.name = CocoJNI.cocoProblemGetName(pointer);
this.index = CocoJNI.cocoProblemGetIndex(pointer);
this.pointer = pointer;
} catch (Exception e) {
throw new Exception("Problem constructor failed.\n" + e.toString());
}
}
/**
* Evaluates the function in point x and returns the result as an array of doubles.
* @param x
* @return the result of the function evaluation in point x
*/
public double[] evaluateFunction(double[] x) {
return CocoJNI.cocoEvaluateFunction(this.pointer, x);
}
/**
* Evaluates the constraint in point x and returns the result as an array of doubles.
* @param x
* @return the result of the constraint evaluation in point x
*/
public double[] evaluateConstraint(double[] x) {
return CocoJNI.cocoEvaluateConstraint(this.pointer, x);
}
// Getters
public long getPointer() {
return this.pointer;
}
public int getDimension() {
return this.dimension;
}
public int getNumberOfObjectives() {
return this.number_of_objectives;
}
public int getNumberOfConstraints() {
return this.number_of_constraints;
}
public double[] getSmallestValuesOfInterest() {
return this.lower_bounds;
}
public double getSmallestValueOfInterest(int index) {
return this.lower_bounds[index];
}
public double[] getLargestValuesOfInterest() {
return this.upper_bounds;
}
public double getLargestValueOfInterest(int index) {
return this.upper_bounds[index];
}
public String getId() {
return this.id;
}
public String getName() {
return this.name;
}
public long getEvaluations() {
return CocoJNI.cocoProblemGetEvaluations(pointer);
}
public long getIndex() {
return this.index;
}
public boolean isFinalTargetHit() {
return (CocoJNI.cocoProblemIsFinalTargetHit(pointer) == 1);
}
/* toString method */
@Override
public String toString() {
return this.getId();
}
}