private Person createDriverPerson(Id<Person> driverId) { final Id<Person> id = driverId; Person person = PopulationUtils.getFactory().createPerson(id); return person; }
public Person getPerson() { Person person = PopulationUtils.getFactory().createPerson(Id.createPersonId(id)); for (PlanSerializable planSer : plans) { Plan plan = planSer.getPlan(person); person.addPlan(plan); if(planSer.equals(selectedPlan)) person.setSelectedPlan(plan); } return person; } }
@Override public void handlePlan(final Plan plan) { // Creating a dummy population which only contains the plans which are passed here. // I need to copy the plans because I am not supposed to add a plan to a different Person. // I also need to memorize the plans which are passed here, because I am supposed to mutate them. final Person personWithOnlySelectedPlan = this.exportPopulation.getFactory().createPerson(plan.getPerson().getId()); final Plan planForNewPerson = PopulationUtils.createPlan(personWithOnlySelectedPlan); PopulationUtils.copyFromTo(plan, planForNewPerson); personWithOnlySelectedPlan.addPlan(planForNewPerson); this.exportPopulation.addPerson(personWithOnlySelectedPlan); this.plansToMutate.put(plan.getPerson().getId(), plan); }
private static Plan createPlan(ActivityFacilities facilities, String facString, String mode) { Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); Plan plan = TestsUtil.createPlanFromFacilities((ActivityFacilitiesImpl) facilities, person, mode, facString); return plan; }
private static Plan createPlan(Network network, String facString, String mode) { Person person = PopulationUtils.getFactory().createPerson(Id.create("1000", Person.class)); Plan plan = TestsUtil.createPlanFromLinks(network, person, mode, facString); return plan; }
@Before public void fixtureWithNothing() { String name = "no information"; Person person = PopulationUtils.getFactory().createPerson(Id.create(name, Person.class)); Plan plan = PopulationUtils.createPlan(person); fixtures.add( new Fixture( name , plan , true ) ); }
@Before public void fixtureWithNoLicense() { String name = "no License"; Person person = PopulationUtils.getFactory().createPerson(Id.create(name, Person.class)); Plan plan = PopulationUtils.createPlan(person); PersonUtils.setLicence(person, "no"); fixtures.add( new Fixture( name , plan , false ) ); }
@Before public void fixtureWithNoCar() { String name = "no car" ; Person person = PopulationUtils.getFactory().createPerson(Id.create(name, Person.class)); Plan plan = PopulationUtils.createPlan(person); PersonUtils.setCarAvail(person, "never"); fixtures.add( new Fixture( name , plan , false ) ); }
@Before public void fixtureWithCarSometimes() { String name = "car sometimes"; Person person = PopulationUtils.getFactory().createPerson(Id.create(name, Person.class)); Plan plan = PopulationUtils.createPlan(person); PersonUtils.setCarAvail(person, "sometimes"); fixtures.add( new Fixture( name , plan , true ) ); }
/** * Test how a plan selector reacts when a person has no plans at all. The correct behavior would be * to just return null, as stated in * {@link PlanSelector#selectPlan(HasPlansAndId) PlanSelector.selectPlan(Person)} * * @author mrieser */ public void testNoPlans() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); assertNull(getPlanSelector().selectPlan(person)); }
public void testHandleEmptyPlan() { ChooseRandomLegMode algo = new ChooseRandomLegMode(new String[] {TransportMode.car, TransportMode.pt, TransportMode.walk}, MatsimRandom.getRandom(), false); Plan plan = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(1, Person.class))); algo.run(plan); // no specific assert, but there should also be no NullPointerException or similar stuff that could theoretically happen }
@Test public void testHandleEmptyPlan() { ChooseRandomSingleLegMode algo = new ChooseRandomSingleLegMode(new String[] {TransportMode.car, TransportMode.pt, TransportMode.walk}, MatsimRandom.getRandom(),false); Plan plan = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(1, Person.class))); algo.run(plan); // no specific assert, but there should also be no NullPointerException or similar stuff that could theoretically happen }
/** * Test how a plan selector reacts when a plan has a score of zero (0.0). * This test only ensures that a plan is returned and no Exception occurred when selecting a plan. */ public void testZeroScore() { PlanSelector<Plan, Person> selector = getPlanSelector(); Plan plan; Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); plan = PersonUtils.createAndAddPlan(person, false); plan.setScore(0.0); assertNotNull(selector.selectPlan(person)); }
public void testHandlePlanWithoutLeg() { ChooseRandomLegMode algo = new ChooseRandomLegMode(new String[] {TransportMode.car, TransportMode.pt, TransportMode.walk}, MatsimRandom.getRandom(), false); Plan plan = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(1, Person.class))); PopulationUtils.createAndAddActivityFromCoord(plan, "home", new Coord(0, 0)); algo.run(plan); // no specific assert, but there should also be no NullPointerException or similar stuff that could theoretically happen }
public void testWriteReadXml() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); VehicleType vehicleType = new VehicleTypeImpl(Id.create("testVehType", VehicleType.class)); Vehicle vehicle = new VehicleImpl(Id.create(80, Vehicle.class), vehicleType); PersonLeavesVehicleEvent event = new PersonLeavesVehicleEvent(5.0 * 3600 + 11.0 * 60, person.getId(), vehicle.getId()); PersonLeavesVehicleEvent event2 = XmlEventsTester.testWriteReadXml(getOutputDirectory() + "events.xml", event); assertEquals("wrong time of event.", 5.0 * 3600 + 11.0 * 60, event2.getTime(), EPSILON); assertEquals("wrong vehicle id.", "80", event2.getVehicleId().toString()); } }
public void testReadWriteXml() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); VehicleType vehicleType = new VehicleTypeImpl(Id.create("testVehType", VehicleType.class)); Vehicle vehicle = new VehicleImpl(Id.create(80, Vehicle.class), vehicleType); PersonEntersVehicleEvent event = new PersonEntersVehicleEvent(5.0 * 3600 + 11.0 * 60, person.getId(), vehicle.getId()); PersonEntersVehicleEvent event2 = XmlEventsTester.testWriteReadXml(getOutputDirectory() + "events.xml", event); assertEquals("wrong time of event.", 5.0 * 3600 + 11.0 * 60, event2.getTime(), EPSILON); assertEquals("wrong vehicle id.", "80", event2.getVehicleId().toString()); } }
public Fixture() { this.scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); new MatsimNetworkReader(this.scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); this.person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); this.vehicle = new VehicleImpl(null, null); this.costFunction = new PersonEnforcingTravelDisutility(); this.costFunction.setExpectations(this.person, this.vehicle); this.network = this.scenario.getNetwork(); } }
@Test public void testEmptyPersonAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); // just check everything works without attributes (dtd validation etc) final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); }
public void testRandomChoiceWithinListedModesOnlyWorks() { ChooseRandomLegMode algo = new ChooseRandomLegMode(new String[] {TransportMode.pt, TransportMode.walk}, MatsimRandom.getRandom(), true); Plan plan = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(1, Person.class))); PopulationUtils.createAndAddActivityFromCoord(plan, "home", new Coord(0, 0)); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); PopulationUtils.createAndAddActivityFromCoord(plan, "work", new Coord((double) 0, (double) 0)); String previousMode = leg.getMode(); algo.run(plan); assertSame("leg mode must have changed.", previousMode, leg.getMode()); }
@Test public void testEmptyPopulationVsOnePerson() { Scenario s1 = ScenarioUtils.createScenario(ConfigUtils.createConfig()); Scenario s2 = ScenarioUtils.createScenario(ConfigUtils.createConfig()); Person person = s2.getPopulation().getFactory().createPerson(Id.create("1", Person.class)); s2.getPopulation().addPerson(person); Assert.assertFalse(PopulationUtils.equalPopulation(s1.getPopulation(), s2.getPopulation())); Assert.assertFalse(PopulationUtils.equalPopulation(s2.getPopulation(), s1.getPopulation())); }