-
-
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
Urgent help regarding a problem #171
Comments
Since the value of the variable hasn't been set yet, it defaults to 0. The values are typically set in the Initialization step. For example, here I create 100 random solution for the DTLZ2 problem and print their variables: Problem problem = new DTLZ2(2);
RandomInitialization initialization = new RandomInitialization(problem, 100);
for (Solution solution : initialization.initialize()) {
System.out.println(Arrays.toString(EncodingUtils.getReal(solution)));
} If you just want to see what a randomly created variable looks like, you can call Variable variable = EncodingUtils.newInt(0, 5);
variable.randomize();
System.out.println(EncodingUtils.getInt(variable)); |
@dhadka Thanks for the quick prompt..... Thanks in advance. |
I see. In that case, you would just need to use one of the Please note though that public void NoInitialization implements Initialization {
protected final Problem problem;
protected final int populationSize;
public NoInitialization(Problem problem, int populationSize) {
super();
this.problem = problem;
this.populationSize = populationSize;
}
public Solution[] initialize() {
Solution[] initialPopulation = new Solution[populationSize];
for (int i = 0; i < populationSize; i++) {
Solution solution = problem.newSolution();
// Assume that the solutions are already initialized. Skip calling randomize().
initialPopulation[i] = solution;
}
return initialPopulation;
}
} |
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 everyone,
i am trying to generate a custom population by overriding the newSolution() method in my problem class.
the code looks like:-
@OverRide
public Solution newSolution() {
Solution solution = new Solution(getNumberOfVariables(), getNumberOfObjectives());
for (int i = 0; i < totalClasses; i++)
{
RealVariable val = EncodingUtils.newInt(1, totalClasses);
solution.setVariable(i, val);
Variable value = solution.getVariable(i);
System.out.println(EncodingUtils.getInt(value));
}
for(int j = totalClasses; j < getNumberOfVariables(); j++)
solution.setVariable(j, EncodingUtils.newInt(1, tClass));
return solution;
}
Here, totalClasses is any number between 1 and getNumberOfVariables() value; Actually i want to initialize all values in solution before totalClasses randomly and rest of the values in solution based on already assigned values. in my above code i keep on getting output as zero always (of the statement:- System.out.println(EncodingUtils.getInt(value)))
kindly help me
and if i am doing something wrong with my implementation then kindly correct me.
Thanks in advance
The text was updated successfully, but these errors were encountered: