@Test public void testCreateRandomIndividual() throws Exception { RandomDataGenerator random = new RandomDataGenerator(); StateTrajectoryFactory<OthelloState> factory = new StateTrajectoryFactory<>(new OthelloSelfPlayEnvironment()); for (int i = 0; i < 10; i++) { StateTrajectory<OthelloState> trajectory = factory.createRandomIndividual(random); Assert.assertTrue(trajectory.getDepth() >= 1); Assert.assertTrue(trajectory.getDepth() <= 100); } }
@Override public StateTrajectory<S> createRandomIndividual(RandomDataGenerator random) { List<S> states = new ArrayList<>(); S state = environment.sampleInitialStateDistribution(random); while (!environment.isTerminal(state)) { states.add(state); AgentTransition<S, ?> agentTransition = StateTrajectory.getRandomTransition(environment, state, random); state = agentTransition.getAfterState(); } int toIndex = random.nextInt(Math.min(minDepth, states.size() - 2), Math.min(maxDepth, states.size() - 1)); return new StateTrajectory<>(states.subList(0, toIndex)); }
StateTrajectoryFactory implements IndividualFactory<StateTrajectory<S>> { @Override public StateTrajectory<S> createRandomIndividual(RandomDataGenerator random) { List<S> states = new ArrayList<>(); S state = environment.sampleInitialStateDistribution(random); while (!environment.isTerminal(state)) { states.add(state); AgentTransition<S, ?> agentTransition = StateTrajectory.getRandomTransition(environment, state, random); state = agentTransition.getAfterState(); } int toIndex = random.nextInt(Math.min(minDepth, states.size() - 2), Math.min(maxDepth, states.size() - 1)); return new StateTrajectory<>(states.subList(0, toIndex)); } }
StateTrajectoryFactory implements IndividualFactory<StateTrajectory<S>> { @Override public StateTrajectory<S> createRandomIndividual(RandomDataGenerator random) { List<S> states = new ArrayList<>(); S state = environment.sampleInitialStateDistribution(random); while (!environment.isTerminal(state)) { states.add(state); AgentTransition<S, ?> agentTransition = StateTrajectory.getRandomTransition(environment, state, random); state = agentTransition.getAfterState(); } int toIndex = random.nextInt(Math.min(minDepth, states.size() - 2), Math.min(maxDepth, states.size() - 1)); return new StateTrajectory<>(states.subList(0, toIndex)); } @AccessedViaReflection  StateTrajectoryFactory(Environment<S, ?> environment); @AccessedViaReflection  StateTrajectoryFactory(Environment<S, ?> environment, int minDepth, int maxDepth); }
StateTrajectoryFactory implements IndividualFactory<StateTrajectory<S>> { @Override public StateTrajectory<S> createRandomIndividual(RandomDataGenerator random) { List<S> states = new ArrayList<>(); S state = environment.sampleInitialStateDistribution(random); while (!environment.isTerminal(state)) { states.add(state); AgentTransition<S, ?> agentTransition = StateTrajectory.getRandomTransition(environment, state, random); state = agentTransition.getAfterState(); } int toIndex = random.nextInt(Math.min(minDepth, states.size() - 2), Math.min(maxDepth, states.size() - 1)); return new StateTrajectory<>(states.subList(0, toIndex)); } @AccessedViaReflection  StateTrajectoryFactory(Environment<S, ?> environment); @AccessedViaReflection  StateTrajectoryFactory(Environment<S, ?> environment, int minDepth, int maxDepth); @Override StateTrajectory<S> createRandomIndividual(RandomDataGenerator random); }
StateTrajectoryFactory implements IndividualFactory<StateTrajectory<S>> { @Override public StateTrajectory<S> createRandomIndividual(RandomDataGenerator random) { List<S> states = new ArrayList<>(); S state = environment.sampleInitialStateDistribution(random); while (!environment.isTerminal(state)) { states.add(state); AgentTransition<S, ?> agentTransition = StateTrajectory.getRandomTransition(environment, state, random); state = agentTransition.getAfterState(); } int toIndex = random.nextInt(Math.min(minDepth, states.size() - 2), Math.min(maxDepth, states.size() - 1)); return new StateTrajectory<>(states.subList(0, toIndex)); } @AccessedViaReflection  StateTrajectoryFactory(Environment<S, ?> environment); @AccessedViaReflection  StateTrajectoryFactory(Environment<S, ?> environment, int minDepth, int maxDepth); @Override StateTrajectory<S> createRandomIndividual(RandomDataGenerator random);  }