@Deprecated // use methods of interface Person public static Plan createAndAddPlan(Person person, final boolean selected) { Plan p = PopulationUtils.createPlan(person); person.addPlan(p); if (selected) { person.setSelectedPlan(p); } return p; }
@Override public void writeExperiencedPlans(String iterationFilename) { // finishIteration(); // already called somewhere else in pgm flow. Population tmpPop = PopulationUtils.createPopulation(config); for (Map.Entry<Id<Person>, Plan> entry : this.agentRecords.entrySet()) { Person person = PopulationUtils.getFactory().createPerson(entry.getKey()); Plan plan = entry.getValue(); person.addPlan(plan); tmpPop.addPerson(person); } new PopulationWriter(tmpPop, null).write(iterationFilename); // I removed the "V5" here in the assumption that it is better to move along with future format changes. If this is // undesired, please change back but could you then please also add a comment why you prefer this. Thanks. // kai, jan'16 } @Override
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; } }
public static GroupPlans copyPlans( final JointPlanFactory jointPlanFactory, final GroupPlans plans) { List<JointPlan> jps = new ArrayList<JointPlan>(); List<Plan> ps = new ArrayList<Plan>(); for (JointPlan jp : plans.getJointPlans()) { jps.add( jointPlanFactory.copyJointPlan( jp ) ); } for (Plan p : plans.getIndividualPlans()) { Plan newPlan = JointPlanFactory.createIndividualPlan( p.getPerson() ); ((PlanWithCachedJointPlan)newPlan).copyFrom( p ); // I think that the above cast will now fail. It probably worked originally, since JointPlan was an extension of PlanImpl, which is // no longer allowed. I would, however, say that it was not a clean copy anyways, since it ignored the additional fields // of JointPlan. Thibaut, I am confident that you can resolve this if you encounter it, but please let me know if you want to dicuss. // kai, nov'15 p.getPerson().addPlan( newPlan ); ps.add( newPlan ); } return new GroupPlans( jps , ps ); } }
@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); }
/** * @author mrieser */ public void testGetBestPlan_allWithoutScore() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); Plan p2 = PopulationUtils.createPlan(); person.addPlan(p1); person.addPlan(p2); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertTrue(p == p1 || p == p2); } }
/** * @author mrieser */ public void testGetBestPlan_oneWithoutScore() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); Plan p2 = PopulationUtils.createPlan(); p2.setScore(80.0); person.addPlan(p1); person.addPlan(p2); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertEquals(p2, p); }
/** * @author mrieser */ public void testGetBestPlan_multipleBest() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); p1.setScore(11.0); Plan p2 = PopulationUtils.createPlan(); p2.setScore(5.0); Plan p3 = PopulationUtils.createPlan(); p3.setScore(11.0); person.addPlan(p1); person.addPlan(p2); person.addPlan(p3); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertTrue(p == p1 || p == p3); }
/** * @author mrieser */ public void testGetBestPlan() { Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan p1 = PopulationUtils.createPlan(); p1.setScore(90.0); Plan p2 = PopulationUtils.createPlan(); p2.setScore(89.0); person.addPlan(p1); person.addPlan(p2); Plan p = new BestPlanSelector<Plan, Person>().selectPlan(person); assertEquals(p1, p); }
@Test public void testAdd() { Fixture f = new Fixture(isUsingFastCapacityUpdate); assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); QVehicle v = new QVehicleImpl(f.basicVehicle); Person p = PopulationUtils.getFactory().createPerson(Id.create("1", Person.class)); p.addPlan(PopulationUtils.createPlan()); v.setDriver(createAndInsertPersonDriverAgentImpl(p, f.sim)); f.qlink1.getAcceptingQLane().addFromUpstream(v); assertEquals(1, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertFalse(f.qlink1.getAcceptingQLane().isAcceptingFromUpstream()); assertTrue(f.qlink1.isNotOfferingVehicle()); }
@Test public void testOverrideAgentFactory() { Config config = ConfigUtils.createConfig(); config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.controler().setLastIteration(0); Scenario scenario = ScenarioUtils.loadScenario(config); Person person = scenario.getPopulation().getFactory().createPerson(Id.createPersonId("person")); person.addPlan(scenario.getPopulation().getFactory().createPlan()); scenario.getPopulation().addPerson(person); AtomicLong value = new AtomicLong(0); Controler controler = new Controler(scenario); controler.addOverridingQSimModule(new TestQSimModule(value)); controler.run(); Assert.assertTrue(value.get() > 0); }
private void createPopulation() { Population pop = this.scenario.getPopulation(); PopulationFactory f = pop.getFactory(); Person p = f.createPerson(Id.create(1, Person.class)); pop.addPerson(p); Plan plan = f.createPlan(); p.addPlan(plan); Activity act = f.createActivityFromLinkId("home", Id.create(1, Link.class)); act.setEndTime(2000.0); plan.addActivity(act); Leg leg = f.createLeg(TransportMode.car); plan.addLeg(leg); act = f.createActivityFromLinkId("home", Id.create(34, Link.class)); plan.addActivity(act); }
private Person createPerson2(Id<Person> personId, Fixture f) { final Id<Person> id = personId; Person p = PopulationUtils.getFactory().createPerson(id); Plan plan = PopulationUtils.createPlan(); p.addPlan(plan); plan.addActivity(PopulationUtils.createActivityFromLinkId("home", f.link1.getId())); Leg leg = PopulationUtils.createLeg(TransportMode.car); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(f.link1.getId(), f.link2.getId()); route.setVehicleId(f.basicVehicle.getId()); leg.setRoute(route); plan.addLeg(leg); plan.addActivity(PopulationUtils.createActivityFromLinkId("work", f.link2.getId())); return p; }
private void createPopulation(){ for(int i=1;i<3;i++){ Id<Person> id = Id.createPersonId(i); Person p = population.getFactory().createPerson(id); Plan plan = population.getFactory().createPlan(); p.addPlan(plan); Activity a1 = population.getFactory().createActivityFromLinkId("h", link1.getId()); a1.setEndTime(0*3600); Leg leg = population.getFactory().createLeg(TransportMode.car); plan.addActivity(a1); plan.addLeg(leg); LinkNetworkRouteFactory factory = new LinkNetworkRouteFactory(); NetworkRoute route; List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); route= (NetworkRoute) factory.createRoute(link1.getId(), link3.getId()); linkIds.add(link2.getId()); route.setLinkIds(link1.getId(), linkIds, link3.getId()); leg.setRoute(route); Activity a2 = population.getFactory().createActivityFromLinkId("w", link3.getId()); plan.addActivity(a2); population.addPerson(p); } } }
private Person createPerson(Scenario scenario, String id) { Person person = scenario.getPopulation().getFactory().createPerson(Id.create(id, Person.class)); Activity from = scenario.getPopulation().getFactory().createActivityFromLinkId("home", Id.create("l0", Link.class)); Leg leg = scenario.getPopulation().getFactory().createLeg(TransportMode.car); Activity to = scenario.getPopulation().getFactory().createActivityFromLinkId("home", Id.create("l2", Link.class)); from.setEndTime(8*3600); leg.setDepartureTime(8*3600); RouteFactory routeFactory = new LinkNetworkRouteFactory(); Id<Link> startLinkId = Id.create("l0", Link.class); Id<Link> endLinkId = Id.create("l2", Link.class); NetworkRoute route = (NetworkRoute) routeFactory.createRoute(startLinkId, endLinkId); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); linkIds.add(Id.create("l1", Link.class)); route.setLinkIds(startLinkId, linkIds, endLinkId); leg.setRoute(route); Plan plan = scenario.getPopulation().getFactory().createPlan(); plan.addActivity(from); plan.addLeg(leg); plan.addActivity(to); person.addPlan(plan); return person; }
private Person createPersonWithPlan(PopulationFactory factory, String id, double homeX, double homeY, double workX, double workY) { Person person = factory.createPerson(Id.create(id, Person.class)); Plan plan = factory.createPlan(); person.addPlan(plan); Activity home1 = factory.createActivityFromCoord("home", new Coord(homeX, homeY)); home1.setEndTime(8*3600); Activity work = factory.createActivityFromCoord("work", new Coord(workX, workY)); work.setEndTime(17*3600); Activity home2 = factory.createActivityFromCoord("home", new Coord(homeX, homeY)); plan.addActivity(home1); plan.addLeg(factory.createLeg("car")); plan.addActivity(work); plan.addLeg(factory.createLeg("car")); plan.addActivity(home2); return person; }
@Test public void testCoord3dIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final Plan plan = population.getFactory().createPlan(); person.addPlan( plan ); plan.addActivity(population.getFactory().createActivityFromCoord( "speech" , new Coord( 0 , 0 ) )); plan.addActivity(population.getFactory().createActivityFromCoord( "tweet" , new Coord( 0 , 0 , -100 ) )); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); final Activity readSpeach = (Activity) readPerson.getSelectedPlan().getPlanElements().get( 0 ); final Activity readTweet = (Activity) readPerson.getSelectedPlan().getPlanElements().get( 1 ); Assert.assertFalse( "did not expect Z value in "+readSpeach.getCoord() , readSpeach.getCoord().hasZ() ); Assert.assertTrue( "did expect T value in "+readTweet.getCoord() , readTweet.getCoord().hasZ() ); Assert.assertEquals( "unexpected Z value in "+readTweet.getCoord(), -100, readTweet.getCoord().getZ(), MatsimTestUtils.EPSILON ); }
@Test public void testLegAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final Plan plan = population.getFactory().createPlan(); person.addPlan( plan ); final Leg leg = population.getFactory().createLeg( "SUV" ); plan.addActivity( population.getFactory().createActivityFromLinkId( "speech" , Id.createLinkId( 1 ))); plan.addLeg( leg ); plan.addActivity( population.getFactory().createActivityFromLinkId( "tweet" , Id.createLinkId( 2 ))); leg.getAttributes().putAttribute( "mpg" , 0.000001d ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); final Leg readLeg = (Leg) readPerson.getSelectedPlan().getPlanElements().get( 1 ); Assert.assertEquals( "Unexpected Double attribute in " + readLeg.getAttributes(), leg.getAttributes().getAttribute( "mpg" ) , readLeg.getAttributes().getAttribute( "mpg" ) ); }
@Test public void testActivityAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final Plan plan = population.getFactory().createPlan(); person.addPlan( plan ); final Activity act = population.getFactory().createActivityFromCoord( "speech" , new Coord( 0 , 0 ) ); plan.addActivity( act ); act.getAttributes().putAttribute( "makes sense" , false ); act.getAttributes().putAttribute( "length" , 1895L ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); final Activity readAct = (Activity) readPerson.getSelectedPlan().getPlanElements().get( 0 ); Assert.assertEquals( "Unexpected boolean attribute in " + readAct.getAttributes(), act.getAttributes().getAttribute( "makes sense" ) , readAct.getAttributes().getAttribute( "makes sense" ) ); Assert.assertEquals( "Unexpected Long attribute in " + readAct.getAttributes(), act.getAttributes().getAttribute( "length" ) , readAct.getAttributes().getAttribute( "length" ) ); }
@Test public void testPlanAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final Plan plan = population.getFactory().createPlan(); person.addPlan( plan ); final Leg leg = population.getFactory().createLeg( "SUV" ); plan.addActivity( population.getFactory().createActivityFromLinkId( "speech" , Id.createLinkId( 1 ))); plan.addLeg( leg ); plan.addActivity( population.getFactory().createActivityFromLinkId( "tweet" , Id.createLinkId( 2 ))); plan.getAttributes().putAttribute( "beauty" , 0.000001d ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); final Plan readPlan = readPerson.getSelectedPlan() ; Assert.assertEquals( plan.getAttributes().getAttribute( "beauty" ) , readPlan.getAttributes().getAttribute( "beauty" ) ); }