PopulationFactory fac = pop.getFactory(); for (int i = 0; i < 20; i++) { Person pers = fac.createPerson(Id.createPersonId(i)); pop.addPerson(pers); Plan plan = fac.createPlan(); pers.addPlan(plan); Activity a0 = fac.createActivityFromLinkId("origin",Id.createLinkId(0)); a0.setEndTime(i); plan.addActivity(a0); Leg leg = fac.createLeg("car"); plan.addLeg(leg); Activity a1 = fac.createActivityFromLinkId("destination",Id.createLinkId(3)); plan.addActivity(a1);
public EditRoutes( Network network, LeastCostPathCalculator pathCalculator, PopulationFactory popFactory ) { this.network = network ; this.pathCalculator = pathCalculator ; this.routeFactories = popFactory.getRouteFactories() ; }
@Test( expected=NullPointerException.class ) public void testNPEWhenLocationNullInSubtourAnalysis() { // this may sound surprising, but for a long time the algorithm // was perfectly fine with that if assertions were disabled... final Plan plan = populationFactory.createPlan(); // link ids are null plan.addActivity( populationFactory.createActivityFromCoord( "type", new Coord((double) 0, (double) 0)) ); plan.addLeg( populationFactory.createLeg( "mode" ) ); plan.addActivity( populationFactory.createActivityFromCoord( "type", new Coord((double) 0, (double) 0)) ); TripStructureUtils.getSubtours( plan , EmptyStageActivityTypes.INSTANCE ); } }
protected Leg createLeg(DriveTask task) { Leg leg = populFactory.createLeg(TransportMode.car); leg.setRoute(VrpPaths.createNetworkRoute(task.getPath(), populFactory.getRouteFactories())); return leg; }
@Override public Plan createNewPlanInstance() { final PopulationFactory fact = createPopulationFactory(); final Id<Link> id1 = Id.create( 1, Link.class ); final Id<Link> id3 = Id.create( 3, Link.class ); final Plan plan = fact.createPlan(); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) ); plan.addLeg( fact.createLeg( TransportMode.walk ) ); plan.addActivity( fact.createActivityFromLinkId( "w" , id3 ) ); plan.addLeg( fact.createLeg( TransportMode.walk ) ); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) ); return plan; } };
private Person createDriverPerson(Id<Person> driverId) { final Id<Person> id = driverId; Person person = PopulationUtils.getFactory().createPerson(id); 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 ); }
public final static boolean insertEmptyTrip( Plan plan, Activity fromActivity, Activity toActivity, String mainMode, PopulationFactory pf ) { // if ( true ) { // throw new RuntimeException(" this currently does not work, since the EvacAgents do not have the on-demand " // + "replanning switched on. kai, nov'17" ) ; // } List<Leg> list = Collections.singletonList( pf.createLeg( mainMode ) ) ; TripRouter.insertTrip(plan, fromActivity, list, toActivity ) ; return true ; } public final boolean insertEmptyTrip( Plan plan, Activity fromActivity, Activity toActivity, String mainMode ) {
PopulationFactory pf = population.getFactory(); Id<Person> personId = Id.create(1, Person.class); Person p = pf.createPerson(personId); population.addPerson(p); RecordingScoringFunction rs = (RecordingScoringFunction) s; sf.handleActivity(new PersonExperiencedActivity(personId, pf.createActivityFromCoord("home", new Coord(100, 100)))); Assert.assertEquals(0, rs.tripCounter); sf.handleLeg(new PersonExperiencedLeg(personId, pf.createLeg("walk"))); Assert.assertEquals(0, rs.tripCounter); sf.handleActivity(new PersonExperiencedActivity(personId, pf.createActivityFromCoord("work", new Coord(1000, 100)))); Assert.assertEquals(1, rs.tripCounter); Assert.assertEquals(1, rs.lastTrip.getTripElements().size()); Assert.assertEquals("walk", ((Leg) rs.lastTrip.getTripElements().get(0)).getMode()); sf.handleLeg(new PersonExperiencedLeg(personId, pf.createLeg("transit_walk"))); sf.handleActivity(new PersonExperiencedActivity(personId, pf.createActivityFromCoord("pt_interaction", new Coord(1000, 200)))); Assert.assertEquals(1, rs.tripCounter); sf.handleLeg(new PersonExperiencedLeg(personId, pf.createLeg("pt"))); sf.handleActivity(new PersonExperiencedActivity(personId, pf.createActivityFromCoord("pt_interaction", new Coord(1000, 200)))); Assert.assertEquals(1, rs.tripCounter); sf.handleLeg(new PersonExperiencedLeg(personId, pf.createLeg("transit_walk"))); sf.handleActivity(new PersonExperiencedActivity(personId, pf.createActivityFromCoord("leisure", new Coord(1000, 200)))); Assert.assertEquals(2, rs.tripCounter); Assert.assertEquals(5, rs.lastTrip.getTripElements().size());
@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); }
public Activity createFinalActivity(String type, Id<Link> newLinkId) { Activity newAct = this.pf.createActivityFromLinkId(type, newLinkId);; newAct.setEndTime( Double.POSITIVE_INFINITY ) ; return newAct ; } // public Activity createAgentThatKeepsMatsimAlive( String type, Id<Link> newLinkId) {
private static Person createPerson(Id<Person> personId, MutableScenario scenario, Link link1, Link link2) { final Id<Person> id = personId; Person p = PopulationUtils.getFactory().createPerson(id); Plan plan = PersonUtils.createAndAddPlan(p, true); PopulationUtils.createAndAddActivityFromLinkId(plan, "h", link1.getId()); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); NetworkRoute route = ((PopulationFactory) scenario.getPopulation().getFactory()).getRouteFactories().createRoute(NetworkRoute.class, link1.getId(), link2.getId()); leg.setRoute(route); route.setLinkIds(link1.getId(), null, link2.getId()); leg.setRoute(route); PopulationUtils.createAndAddActivityFromLinkId(plan, "w", link2.getId()); return p; }
public static Plan createPlan() { return getFactory().createPlan() ; }
public static Activity createActivityFromCoord(String type, Coord coord) { return getFactory().createActivityFromCoord(type, coord) ; }
final Plan plan = fact.createPlan(); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) ); plan.addLeg( fact.createLeg( TransportMode.transit_walk ) ); plan.addActivity( fact.createActivityFromLinkId( STAGE , id2 ) ); plan.addLeg( fact.createLeg( TransportMode.pt ) ); plan.addActivity( fact.createActivityFromLinkId( STAGE , id3 ) ); plan.addLeg( fact.createLeg( TransportMode.transit_walk ) ); plan.addActivity( fact.createActivityFromLinkId( "w" , id3 ) ); plan.addLeg( fact.createLeg( TransportMode.transit_walk ) ); plan.addActivity( fact.createActivityFromLinkId( STAGE , id2 ) ); plan.addLeg( fact.createLeg( TransportMode.pt ) ); plan.addActivity( fact.createActivityFromLinkId( STAGE , id3 ) ); plan.addLeg( fact.createLeg( TransportMode.transit_walk ) ); plan.addLeg( fact.createLeg( TransportMode.pt ) ); plan.addLeg( fact.createLeg( TransportMode.transit_walk ) ); plan.addActivity( fact.createActivityFromLinkId( STAGE , id2 ) ); plan.addLeg( fact.createLeg( TransportMode.pt ) ); plan.addActivity( fact.createActivityFromLinkId( STAGE , id1 ) ); plan.addLeg( fact.createLeg( TransportMode.transit_walk ) ); plan.addActivity( fact.createActivityFromLinkId( STAGE , id2 ) ); plan.addLeg( fact.createLeg( TransportMode.transit_walk ) ); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) );
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 protected void setUp() throws Exception { super.setUp(); final Config config = ConfigUtils.createConfig(); final Scenario scenario = ScenarioUtils.createScenario( config ); this.facilities = scenario.getActivityFacilities() ; // create facilities, activities in it and open times final ActivityFacilitiesFactory facilitiesFactory = this.facilities.getFactory(); Coord defaultCoord = new Coord(0.0, 0.0); ActivityFacility testFacility = facilitiesFactory.createActivityFacility(Id.create(0, ActivityFacility.class), defaultCoord) ; this.facilities.addActivityFacility(testFacility); ActivityOption ao = facilitiesFactory.createActivityOption("shop") ; testFacility.addActivityOption(ao); ao.addOpeningTime(new OpeningTimeImpl(6.0 * 3600, 11.0 * 3600)); ao.addOpeningTime(new OpeningTimeImpl(13.0 * 3600, 19.0 * 3600)); // here, we don't test the scoring function itself, but just the method to retrieve opening times // we don't really need persons and plans, they're just used to initialize the ScoringFunction object final PopulationFactory pf = scenario.getPopulation().getFactory(); this.person = pf.createPerson(Id.create(1, Person.class)); Plan plan = pf.createPlan() ; this.person.addPlan(plan); Activity act = pf.createActivityFromCoord("shop", defaultCoord ) ; plan.addActivity(act); act.setFacilityId(testFacility.getId()); act.setStartTime(8.0 * 3600); act.setEndTime(16.0 * 3600); }
public static Leg createLeg(String transportMode) { return getFactory().createLeg(transportMode) ; }
public static Activity createActivityFromLinkId(String type, Id<Link> linkId) { return getFactory().createActivityFromLinkId(type, linkId) ; }
public static Plan createPlan(Person person) { Plan plan = getFactory().createPlan() ; plan.setPerson(person); return plan ; }