-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCocoProblem.java
More file actions
57 lines (41 loc) · 1.47 KB
/
CocoProblem.java
File metadata and controls
57 lines (41 loc) · 1.47 KB
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
// CocoProblem.java
import jmetal.core.Solution;
import jmetal.core.Variable;
import jmetal.encodings.solutionType.BinaryRealSolutionType;
import jmetal.encodings.solutionType.RealSolutionType;
import jmetal.util.JMException;
/**
* Class representing problem CocoProblem
*/
public class CocoProblem extends jmetal.core.Problem {
public static Problem PROBLEM;
public CocoProblem (Problem PROBLEM,
int dimension,
int numberOfObjectives,
double[] lowerBounds,
double[] upperBounds) {
this.PROBLEM = PROBLEM;
numberOfVariables_ = dimension;
numberOfObjectives_ = numberOfObjectives;
numberOfConstraints_= 0;
problemName_ = "CocoProblem";
lowerLimit_ = lowerBounds;
upperLimit_ = upperBounds;
solutionType_ = new RealSolutionType(this) ;
}
/**
* Evaluates a solution
* @param solution The solution to evaluate
* @throws JMException
*/
public void evaluate(Solution solution) throws JMException {
Variable[] gen = solution.getDecisionVariables();
double [] x = new double[numberOfVariables_];
double [] y = new double[numberOfObjectives_];
for (int i = 0; i < numberOfVariables_; i++)
x[i] = gen[i].getValue();
y = PROBLEM.evaluateFunction(x);
for (int i = 0; i < numberOfObjectives_; i++)
solution.setObjective(i,y[i]);
} // evaluate
}