TorusPredPreyTask extends NoisyLonerTask<T> implements TUGTask, NetworkTask, HyperNEATTask { @Override public String[] sensorLabels() { return TorusPredPreyTask.preyEvolve ? (new NNTorusPredPreyController(null,false)).sensorLabels() : (new NNTorusPredPreyController(null,true)).sensorLabels(); } TorusPredPreyTask();  TorusPredPreyTask(boolean preyEvolve);  TorusPredPreyTask(boolean preyEvolve, boolean competitive); abstract TorusPredPreyController[] getPredAgents(Genotype<T> individual); abstract TorusPredPreyController[] getPreyAgents(Genotype<T> individual); final void addObjective(GridTorusObjective<T> o, ArrayList<ArrayList<GridTorusObjective<T>>> list, int pop); final void addObjective(GridTorusObjective<T> o, ArrayList<ArrayList<GridTorusObjective<T>>> list, boolean affectsSelection, int pop); @Override /** * A method that evaluates a single genotype Provides fitness for that * genotype based on the game time as well as other scores * * @param individual * genotype being evaluated * @param num * number of current evaluation * @return A Pair of double arrays containing the fitness and other scores */ Pair<double[], double[]> oneEval(Genotype<T> individual, int num); TorusPredPreyGame runEval(TorusPredPreyController[] predAgents, TorusPredPreyController[] preyAgents); @Override int numObjectives(); @Override int numOtherScores(); @Override double[] startingGoals(); @Override double[] minScores(); @Override String[] sensorLabels(); @Override String[] outputLabels(); static String[] outputLabels(boolean forPredators); @Override double getTimeStamp(); static TorusPredPreyController[] getStaticControllers(boolean isPred, int num); static void getEvolvedControllers(TorusPredPreyController[] container, Genotype<T> g, boolean isPred); static void getEvolvedControllers(TorusPredPreyController[] container, Genotype<T> g, boolean isPred, int startIndex, int numCopies); static void getEvolvedControllers(TorusPredPreyController[] container, Genotype<T>[] genotypes, boolean isPred); static void getEvolvedControllers(TorusPredPreyController[] container, Genotype<T>[] genotypes, boolean isPred, int startIndex); void addAllObjectives(); void addAllObjectives(int pop); void addAllObjectives(int pop, boolean isPreyPop); @Override List<Substrate> getSubstrateInformation(); @Override List<Triple<String, String, Boolean>> getSubstrateConnectivity(); double[] getSubstrateInputs(List<Substrate> subs); @Override int numCPPNInputs(); @Override double[] filterCPPNInputs(double[] fullInputs); static final String[] ALL_ACTIONS; static final String[] MOVEMENT_ACTIONS; static final int HYPERNEAT_OUTPUT_SUBSTRATE_DIMENSION; public TorusPredPreyController[] evolved; static boolean preyEvolve; final boolean competitive; public ArrayList<ArrayList<GridTorusObjective<T>>> objectives; public ArrayList<ArrayList<GridTorusObjective<T>>> otherScores; }
@SuppressWarnings("rawtypes") @Test public void testSensorLabels() { MMNEAT.task = new TorusEvolvedPredatorsVsStaticPreyTask(); homoPred = (TorusEvolvedPredatorsVsStaticPreyTask)MMNEAT.task; int numPreds = 3; int numPrey = 2; String type1 = "Closest Prey"; String type2 = "Closest Pred"; String[] result = new String[(numPreds-1+numPrey) * 2]; for (int i = 0; i < numPrey; i++) { result[(2 * i)] = "X Offset to " + type1 + " " + i; result[(2 * i) + 1] = "Y Offset to " + type1 + " " + i; } for (int i = numPrey; i < numPreds-1+numPrey; i++) { result[(2 * i)] = "X Offset to " + type2 + " " + (i-numPrey); result[(2 * i) + 1] = "Y Offset to " + type2 + " " + (i-numPrey); } String[] resultWithBias = new String[(numPreds-1+numPrey) * 2 + 1]; resultWithBias[0] = "Bias"; System.arraycopy(result, 0, resultWithBias, 1, result.length); assertArrayEquals(homoPred.sensorLabels(), resultWithBias); Parameters.initializeParameterCollections(new String[] { "io:false", "netio:false", "torusTimeLimit:1000", "torusPreys:2", "torusPredators:3", "allowDoNothingActionForPredators:false", "torusSenseTeammates:true", "staticPreyController:edu.utexas.cs.nn.gridTorus.controllers.PreyFleeClosestPredatorController", "torusSenseByProximity:false", "predatorCatchClose:false", "preyRRM:false" }); MMNEAT.loadClasses(); MMNEAT.task = new TorusEvolvedPredatorsVsStaticPreyTask(); homoPred = (TorusEvolvedPredatorsVsStaticPreyTask)MMNEAT.task; numPreds = 3; numPrey = 2; type1 = "Prey"; type2 = "Pred"; result = new String[(numPreds-1+numPrey) * 2]; for (int i = 0; i < numPrey; i++) { result[(2 * i)] = "X Offset to " + type1 + " " + i; result[(2 * i) + 1] = "Y Offset to " + type1 + " " + i; } for (int i = numPrey; i < numPreds-1+numPrey; i++) { result[(2 * i)] = "X Offset to " + type2 + " " + (i-numPrey); result[(2 * i) + 1] = "Y Offset to " + type2 + " " + (i-numPrey); } resultWithBias = new String[(numPreds-1+numPrey) * 2 + 1]; resultWithBias[0] = "Bias"; System.arraycopy(result, 0, resultWithBias, 1, result.length); assertArrayEquals(homoPred.sensorLabels(), resultWithBias); Parameters.initializeParameterCollections(new String[] { "io:false", "netio:false", "torusTimeLimit:1000", "torusPreys:2", "torusPredators:3", "allowDoNothingActionForPredators:false", "torusSenseTeammates:false", "staticPreyController:edu.utexas.cs.nn.gridTorus.controllers.PreyFleeClosestPredatorController", "torusSenseByProximity:true", "predatorCatchClose:false", "preyRRM:false" }); MMNEAT.loadClasses(); MMNEAT.task = new TorusEvolvedPredatorsVsStaticPreyTask(); homoPred = (TorusEvolvedPredatorsVsStaticPreyTask)MMNEAT.task; numPrey = 2; String type = "Closest Prey"; result = new String[(numPrey) * 2]; for (int i = 0; i < numPrey; i++) { result[(2 * i)] = "X Offset to " + type + " " + i; result[(2 * i) + 1] = "Y Offset to " + type + " " + i; } resultWithBias = new String[(numPrey) * 2 + 1]; resultWithBias[0] = "Bias"; System.arraycopy(result, 0, resultWithBias, 1, result.length); assertArrayEquals(homoPred.sensorLabels(), resultWithBias); Parameters.initializeParameterCollections(new String[] { "io:false", "netio:false", "torusTimeLimit:1000", "torusPreys:2", "torusPredators:3", "allowDoNothingActionForPredators:false", "torusSenseTeammates:false", "staticPreyController:edu.utexas.cs.nn.gridTorus.controllers.PreyFleeClosestPredatorController", "torusSenseByProximity:false", "predatorCatchClose:false", "preyRRM:false" }); MMNEAT.loadClasses(); MMNEAT.task = new TorusEvolvedPredatorsVsStaticPreyTask(); homoPred = (TorusEvolvedPredatorsVsStaticPreyTask)MMNEAT.task; numPrey = 2; type = "Prey"; result = new String[(numPrey) * 2]; for (int i = 0; i < numPrey; i++) { result[(2 * i)] = "X Offset to " + type + " " + i; result[(2 * i) + 1] = "Y Offset to " + type + " " + i; } resultWithBias = new String[(numPrey) * 2 + 1]; resultWithBias[0] = "Bias"; System.arraycopy(result, 0, resultWithBias, 1, result.length); assertArrayEquals(homoPred.sensorLabels(), resultWithBias); }