-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setting decision variable for custom operators #174
Comments
CustomDecisionVariable var = (CustomDecisionVariable)solution.getVariable(0);
private String encode(Variable variable) throws IOException {
StringBuilder sb = new StringBuilder();
if (variable instanceof RealVariable) {
RealVariable rv = (RealVariable)variable;
sb.append(rv.getValue());
} else if (variable instanceof BinaryVariable) {
BinaryVariable bv = (BinaryVariable)variable;
for (int i=0; i<bv.getNumberOfBits(); i++) {
sb.append(bv.get(i) ? "1" : "0");
}
} else if (variable instanceof Permutation) {
Permutation p = (Permutation)variable;
for (int i=0; i<p.size(); i++) {
if (i > 0) {
sb.append(',');
}
sb.append(p.get(i));
}
} else {
throw new IOException("type not supported");
}
return sb.toString();
} Then call
|
Sorry but I have 2 more questions
Thanks for the clarification, I am trying to understand the mechanisms of the framework. |
public class TestEvaluate {
public static int callsToEvaluate = 0;
public static class TestProblem extends AbstractProblem {
public TestProblem() {
super(1, 1);
}
@Override
public void evaluate(Solution solution) {
callsToEvaluate++;
}
@Override
public Solution newSolution() {
Solution solution = new Solution(1, 1);
solution.setVariable(0, EncodingUtils.newReal(0.0, 1.0));
return solution;
}
}
public static void main(String[] args) {
NondominatedPopulation result = new Executor()
.withProblemClass(TestProblem.class)
.withAlgorithm("NSGAII")
.withMaxEvaluations(1)
.withProperty("populationSize", 1)
.run();
System.out.println("Evaluate called " + callsToEvaluate + " times...");
}
} |
This is an automated message. This issue is flagged as stale and will be closed in 7 days. If you feel this issue is still relevant, leave a comment to keep the issue open. Please also consider contributing a fix for the issue. |
Hello @dhadka,
Question 1
How can I set a custom decision variable in the evaluate method?
Question 2:
How do I can I print out the final set of results? I try the line of code below but I only get a representative string and not the variable itself.
System.out.print(result.get(0).getVariable(0).toString());
Question 3:
Is it fine to use a built-in initialization like RandomInitialization for a custom problem? e.g.
Initialization initialization = new RandomInitialization(problem, x);
// x = population sizeThank you for your time.
The text was updated successfully, but these errors were encountered: