@Override public Iterable<Id<Clique>> getGroups(final Person person) { return Arrays.asList( personIdToGroupId.get( person.getId() ), fullGroupId); } }
private int getNumberOfTrips(final Person person) { int numberOfLegs=0; for (PlanElement pe : person.getSelectedPlan().getPlanElements()) { if (pe instanceof Leg) { numberOfLegs++; } } return numberOfLegs; }
@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; }
public PersonSerializable(Person p) { this.id = p.getId().toString(); Person person = p; for (Plan plan : person.getPlans()) { PlanSerializable planSerializable = new PlanSerializable(plan); plans.add(planSerializable); if (plan.equals(person.getSelectedPlan())) this.selectedPlan = planSerializable; } }
/** * convenience method for often used demographic attribute */ public static void setEmployed(Person person, final Boolean employed) { if (employed!=null){ person.getCustomAttributes().put(EMPLOYED, employed); person.getAttributes().putAttribute(EMPLOYED,employed ) ; } }
@Override public void notifyStartup(StartupEvent event) { masterLogger.warn(masterInitialLogString); startSlaveHandlersInMode(CommunicationsMode.TRANSMIT_SCENARIO); if (initialRoutingOnSlaves) { waitForSlaveThreads(); startSlaveHandlersInMode(CommunicationsMode.TRANSMIT_PLANS_TO_MASTER); waitForSlaveThreads(); mergePlansFromSlaves(); //this code is a copy of the replanning strategy for (Person person : matsimControler.getScenario().getPopulation().getPersons().values()) { // person.removePlan(person.getSelectedPlan()); Plan plan = newPlans.get(person.getId().toString()); person.addPlan(plan); person.setSelectedPlan(plan); } if (slaveHandlerTreeMap.size() > 1 || slavesHaveRequestedShutdown() || hydra.hydraSlaves.size() > 0) loadBalance(); if (SelectedSimulationMode.equals(SimulationMode.PARALLEL)) { waitForSlaveThreads(); startSlaveHandlersInMode(CommunicationsMode.CONTINUE); } } }
@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" ) ); }
@Override public void run(final Person person) { for (Plan plan : person.getPlans()) { run(plan); } }
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { double randomizedTimeDistanceDisutilityForLink = this.randomizedTimeDistanceTravelDisutility.getLinkTravelDisutility(link, time, person, vehicle); double logNormalRnd = 1. ; if ( sigma != 0. ) { logNormalRnd = (double) person.getCustomAttributes().get("logNormalRnd") ; } double linkExpectedTollDisutility = calculateExpectedTollDisutility(link.getId(), time, person.getId()); double randomizedTollDisutility = linkExpectedTollDisutility * logNormalRnd; return randomizedTimeDistanceDisutilityForLink + randomizedTollDisutility; }
@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
private void startPerson(final Person person, final BufferedWriter out) throws IOException { out.write("\t<person id=\""); out.write(person.getId().toString()); out.write("\""); out.write(">\n"); this.attributesWriter.writeAttributes( "\t\t" , out , person.getAttributes() ); }
@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); }
public void testSetSelectedPlan() { Person person = PopulationUtils.getFactory().createPerson(Id.create(11, Person.class)); Plan p1 = PersonUtils.createAndAddPlan(person, false); assertEquals(p1, person.getSelectedPlan()); Plan p2 = PersonUtils.createAndAddPlan(person, false); assertEquals(p1, person.getSelectedPlan()); Plan p3 = PersonUtils.createAndAddPlan(person, true); assertEquals(p3, person.getSelectedPlan()); person.setSelectedPlan(p2); assertEquals(p2, person.getSelectedPlan()); Plan p4 = PopulationUtils.createPlan(null); try { person.setSelectedPlan(p4); fail("expected Exception when setting a plan as selected that is not part of person."); } catch (IllegalStateException e) { log.info("catched expected exception: " + e.getMessage()); } }
@SuppressWarnings("unchecked") @Deprecated // use PersonAttributes public static TreeSet<String> getTravelcards(Person person) { return (TreeSet<String>) person.getCustomAttributes().get(TRAVELCARDS); }
/** * convenience method for often used demographic attribute */ public static String getCarAvail(Person person) { return (String) person.getAttributes().getAttribute(CAR_AVAIL); }
private static void select(final GroupPlans plans) { for (JointPlan jp : plans.getJointPlans()) { for (Plan p : jp.getIndividualPlans().values()) { p.getPerson().setSelectedPlan(p); } } for (Plan p : plans.getIndividualPlans()) { p.getPerson().setSelectedPlan(p); } }
MobsimAgent agent = this.mobsimDataProvider.getAgent(person.getId()); Person experiencedPerson = experiencedPopulation.getFactory().createPerson(person.getId()); experiencedPerson.addPlan(plan); experiencedPerson.setSelectedPlan(plan);
@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" ) ); }