@Override public void evaluate(IntegerSolution solution) { int[] variables = new int[getNumberOfVariables()]; for (int i = 0; i < variables.length; i++) { variables[i] = solution.getVariableValue(i); } int sum = 30 * variables[0] + 60 * variables[1] + 90 * variables[2]; solution.setObjective(0, Math.abs(this.cargaHoraria - sum)); }
@Test public void testOperator1() { SimpleIntegerProblem problem = new SimpleIntegerProblem(1, 19, 0, 4); DefaultIntegerSolution solution = new DefaultIntegerSolution(problem); MovementEnum[] actualParentMoves = new MovementEnum[solution.getNumberOfVariables()]; for (int i = 0; i < solution.getNumberOfVariables(); i++) { Integer variableValue = solution.getVariableValue(i); MovementEnum moveFromInteger = MovementEnum.getMoveFromInteger(variableValue); actualParentMoves[i] = moveFromInteger; } String parent = Arrays.toString(actualParentMoves).replace(" ", ""); System.out.println(parent); proteinBuilder.buildProteinAminoAcidList(solution, aminoAcidSequence, 40); List<AminoAcid> aminoAcidsList = proteinBuilder.getAminoAcidsList(); Set<TopologyContact> topologyContacts = EnergyFunction.getTopologyContacts(aminoAcidsList); int collisionsCount = EnergyFunction.getCollisionsCount(aminoAcidsList); int fitness = topologyContacts.size(); System.out.println("fitness: " + fitness); System.out.println("collisions: " + collisionsCount); IntegerSolution execute = operator.execute(solution); MovementEnum[] actualOffspringMoves = new MovementEnum[execute.getNumberOfVariables()]; for (int i = 0; i < execute.getNumberOfVariables(); i++) { Integer variableValue = execute.getVariableValue(i); MovementEnum moveFromInteger = MovementEnum.getMoveFromInteger(variableValue); actualOffspringMoves[i] = moveFromInteger; } String offSpring = Arrays.toString(actualOffspringMoves).replace(" ", ""); System.out.println(offSpring); proteinBuilder.buildProteinAminoAcidList(execute, aminoAcidSequence, 40); aminoAcidsList = proteinBuilder.getAminoAcidsList(); topologyContacts = EnergyFunction.getTopologyContacts(aminoAcidsList); collisionsCount = EnergyFunction.getCollisionsCount(aminoAcidsList); fitness = topologyContacts.size(); System.out.println("fitness: " + fitness); System.out.println("collisions: " + collisionsCount); }