Created
December 1, 2015 17:45
-
-
Save dhadka/103bf734ed5f3c744759 to your computer and use it in GitHub Desktop.
Scaled Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ScaledProblem implements Problem { | |
private final Problem problem; | |
private final double[] factors; | |
public ScaledProblem(Problem problem, double base) { | |
super(); | |
this.problem = problem; | |
factors = new double[problem.getNumberOfObjectives()]; | |
for (int i = 0; i < problem.getNumberOfObjectives(); i++) { | |
factors[i] = Math.pow(base, i); | |
} | |
} | |
@Override | |
public String getName() { | |
return "Scaled " + problem.getName(); | |
} | |
@Override | |
public int getNumberOfVariables() { | |
return problem.getNumberOfVariables(); | |
} | |
@Override | |
public int getNumberOfObjectives() { | |
return problem.getNumberOfObjectives(); | |
} | |
@Override | |
public int getNumberOfConstraints() { | |
return problem.getNumberOfConstraints(); | |
} | |
@Override | |
public void evaluate(Solution solution) { | |
problem.evaluate(solution); | |
for (int i = 0; i < problem.getNumberOfObjectives(); i++) { | |
solution.setObjective(i, solution.getObjective(i) * factors[i]); | |
} | |
} | |
@Override | |
public Solution newSolution() { | |
return problem.newSolution(); | |
} | |
@Override | |
public void close() { | |
problem.close(); | |
} | |
public void scaleReferenceSet(File file, File scaledFile) throws IOException { | |
Population population = PopulationIO.readObjectives(file); | |
for (Solution solution : population) { | |
for (int i = 0; i < solution.getNumberOfObjectives(); i++) { | |
solution.setObjective(i, solution.getObjective(i) * factors[i]); | |
} | |
} | |
PopulationIO.writeObjectives(scaledFile, population); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment