TorusPredPreyTask extends NoisyLonerTask<T> implements TUGTask, NetworkTask, HyperNEATTask { public static <T extends TorusPredPreyController> TorusPredPreyController[] getStaticControllers(boolean isPred, int num) { TorusPredPreyController[] staticAgents = new TorusPredPreyController[num]; try { for (int i = 0; i < num; i++) { staticAgents[i] = (TorusPredPreyController) ClassCreation.createObject(isPred ? "staticPredatorController" : "staticPreyController"); } } catch (NoSuchMethodException e) { e.printStackTrace(); System.out.println("Could not load static agents"); System.exit(1); } return staticAgents; } 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", "static-access" }) @Test public void testGetStaticControllers() { 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", "staticPredatorController:edu.utexas.cs.nn.gridTorus.controllers.RandomPredatorController", "torusSenseByProximity:true", "predatorCatchClose:false", "preyRRM:false" }); MMNEAT.loadClasses(); MMNEAT.task = new TorusEvolvedPredatorsVsStaticPreyTask(); homoPred = (TorusEvolvedPredatorsVsStaticPreyTask)MMNEAT.task; TorusPredPreyController[] staticControllers; staticControllers = homoPred.getStaticControllers(false, 2); assertEquals(staticControllers.length, 2); assertTrue(staticControllers[0] instanceof PreyFleeClosestPredatorController); assertTrue(staticControllers[1] instanceof PreyFleeClosestPredatorController); staticControllers = homoPred.getStaticControllers(true, 3); assertEquals(staticControllers.length, 3); assertTrue(staticControllers[0] instanceof RandomPredatorController); assertTrue(staticControllers[1] instanceof RandomPredatorController); assertTrue(staticControllers[2] instanceof RandomPredatorController); }