Hi, Every One
Due of being a new user of Java as well MOEA, please can anyone provide me with details of how to extend the RealVariable class or the EncodingUtils.newReal to set the decision variables bounds (lower & upper) to a variables declared somewhere else in my program out side the newSolution method as shown bellow
This is part of my code
@Override
public void evaluate (Solution solution) {
.....
.....
// finding the smallest and largest numbers in an array
largest = points [0] [0] ;
smallest = points [0] [0] ;
for (int i = 0; i < 40; ++i)
{
for (int j = 0; j < 3; ++j)
{
if(points[i] [j] > largest)
largest = points[i] [j];
else if (points[i] [j] < smallest)
smallest = points[i] [j];
}
}
............
............
// setting the decision variables bounds to the lowest and highest values of the array
@Override
public Solution newSolution ()
{
Solution solution = new Solution(numberOfVariables,
numberOfObjectives);
for(int i=0; i< numberOfVariables; i++)
{
solution.setVariable(i, new RealVariable(smallest, largest));
}
return solution;
}
Thank you
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
Here is an example. The lower and upper bound are stored in a static array that you can modify.
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
Hi, thank you very much for your help
When I runThe code I have got 2 errors as follows:
1- with the code part
@Override
public void randomize() {
setValue(PRNG.nextDouble(getLowerBound(), getUpperBound()));
}
I got this error message
((method randomize() of type Example4.ExtendedRealVariable must override or implement a supertype method))
2- withe the statement
solution.setVariable(i, new ExtendedRealVariable(lowerBounds, upperBounds, i));
I got this error message
((No enclosing instance of type Example4 is accessible. Must qualify the allocation with an enclosing instance of type Example4 (e.g. x.new A() where x is an instance of Example4))
So can you please tell me what I should do to correct these errors
Thank you
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
To fix the first issue, upgrade to version 2.7 of the software.
For the second error, make the ExtendedRealVariable class static:
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
Thank you again
for the second error I have made the ExtendedRealVariable class static as you mentioned and it solved the issue.
for the first error I have removed the @Override annotation befote the (public void randomize()) method, and now the code is running and giving results. So is removing the @Override correct or not???
Thanks