本文整理了Java中org.matsim.api.core.v01.population.Population.addPerson()
方法的一些代码示例,展示了Population.addPerson()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Population.addPerson()
方法的具体详情如下:
包路径:org.matsim.api.core.v01.population.Population
类名称:Population
方法名:addPerson
暂无
代码示例来源:origin: matsim-org/matsim
@Override
public void endTag(final String name, final String content, final Stack<String> context) {
if (PERSON.equals(name)) {
this.plans.addPerson(this.currperson);
this.currperson = null;
} else if (PLAN.equals(name)) {
this.currplan = null;
} else if (LEG.equals(name)) {
this.currleg = null;
} else if (ROUTE.equals(name)) {
this.routeNodes = content;
}
}
代码示例来源:origin: matsim-org/matsim
@Override
public void endTag(final String name, final String content,
final Stack<String> context) {
if (PERSON.equals(name)) {
this.plans.addPerson(this.currperson);
this.currperson = null;
} else if (ACTIVITY.equals(name)) {
this.curracttype = null;
} else if (LOCATION.equals(name)) {
this.curractivity = null;
} else if (PLAN.equals(name)) {
if (this.currplan.getPlanElements() instanceof ArrayList<?>) {
((ArrayList<?>) this.currplan.getPlanElements()).trimToSize();
}
this.currplan = null;
} else if (ACT.equals(name)) {
this.prevAct = this.curract;
this.curract = null;
} else if (ROUTE.equals(name)) {
this.routeDescription = content;
}
}
代码示例来源:origin: matsim-org/matsim
@Override
public void endTag(final String name, final String content,
final Stack<String> context) {
if (PERSON.equals(name)) {
this.plans.addPerson(this.currperson);
this.currperson = null;
}
else if (PLAN.equals(name)) {
if (this.currplan.getPlanElements() instanceof ArrayList) {
((ArrayList<?>) this.currplan.getPlanElements()).trimToSize();
}
this.currplan = null;
}
else if (LEG.equals(name)) {
this.currleg = null;
}
else if (ROUTE.equals(name)) {
this.routeNodes = content;
}
}
代码示例来源:origin: matsim-org/matsim
private void addPersons(List<PersonSerializable> persons) {
for (PersonSerializable person : persons) {
matsimControler.getScenario().getPopulation().addPerson(person.getPerson());
}
slaveLogger.warn("Added " + persons.size() + " pax to my population.");
}
代码示例来源:origin: matsim-org/matsim
@Override
public void endTag(final String name, final String content, final Stack<String> context) {
if (PERSON.equals(name)) {
this.plans.addPerson(this.currperson);
this.currperson = null;
} else if (PLAN.equals(name)) {
if (this.currplan.getPlanElements() instanceof ArrayList<?>) {
((ArrayList<?>) this.currplan.getPlanElements()).trimToSize();
}
this.currplan = null;
} else if (ACT.equals(name)) {
this.prevAct = this.curract;
this.curract = null;
} else if (ROUTE.equals(name)) {
endRoute(content);
}
}
代码示例来源:origin: matsim-org/matsim
@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
代码示例来源:origin: matsim-org/matsim
private void createPopulation() {
Population pop = scenario.getPopulation();
PopulationFactory factory = pop.getFactory();
pop.addPerson(createPersonWithPlan(factory, "1", 200, 10, 800, 300));
pop.addPerson(createPersonWithPlan(factory, "2", 500, -10, 800, 300));
pop.addPerson(createPersonWithPlan(factory, "3", 600, 20, 800, 300));
pop.addPerson(createPersonWithPlan(factory, "4", 900, 100, 400, 500));
pop.addPerson(createPersonWithPlan(factory, "5", 1000, 300, 400, 500));
pop.addPerson(createPersonWithPlan(factory, "6", 700, 300, 400, 500));
pop.addPerson(createPersonWithPlan(factory, "7", 800, 400, 400, 500));
pop.addPerson(createPersonWithPlan(factory, "8", 440, 500, 300, 100));
pop.addPerson(createPersonWithPlan(factory, "9", 250, 250, 300, 100));
pop.addPerson(createPersonWithPlan(factory, "0", 0, 100, 300, 100));
}
代码示例来源:origin: matsim-org/matsim
@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);
}
代码示例来源:origin: io.github.agentsoz/bdi-matsim
public static void populationWithBDIAttributeExample() {
{
Config config = ConfigUtils.createConfig() ;
Scenario scenario = ScenarioUtils.createScenario( config ) ;
Population pop = scenario.getPopulation() ;
PopulationFactory pf = pop.getFactory() ;
for ( int ii=0 ; ii<10 ; ii++ ) {
Person person = pf.createPerson( Id.createPersonId(ii)) ;
person.getAttributes().putAttribute("isBDIAgent", true ) ;
pop.addPerson(person);
}
PopulationUtils.writePopulation(pop, "pop.xml");
}
{
Config config = ConfigUtils.createConfig() ;
config.plans().setInputFile("pop.xml");
Scenario scenario = ScenarioUtils.loadScenario( config ) ;
for ( Person person : scenario.getPopulation().getPersons().values() ) {
final String attribute = (String) person.getAttributes().getAttribute("isBDIAgent");
System.out.println( "id=" + person.getId() + "; isBdi=" + attribute ) ;
}
}
}
代码示例来源:origin: matsim-org/matsim
@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);
}
代码示例来源:origin: matsim-org/matsim
/**
* Tests that no Exception occurs if an agent has no leg at all.
*
* @author mrieser
*/
@Test
public void testAgentWithoutLeg() {
Fixture f = new Fixture(isUsingFastCapacityUpdate);
Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class));
Plan plan = PersonUtils.createAndAddPlan(person, true);
PopulationUtils.createAndAddActivityFromLinkId(plan, "home", f.link1.getId());
f.plans.addPerson(person);
/* build events */
EventsManager events = EventsUtils.createEventsManager();
LinkEnterEventCollector collector = new LinkEnterEventCollector();
events.addHandler(collector);
/* run sim */
QSim sim = createQSim(f, events);
sim.run();
/* finish */
Assert.assertEquals("wrong number of link enter events.", 0, collector.events.size());
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testCrashingAlgorithm() {
try {
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
Population population = scenario.getPopulation();
for (int i = 0; i < 10; i++) {
Person person = PopulationUtils.getFactory().createPerson(Id.create(i, Person.class));
population.addPerson(person);
}
ParallelPersonAlgorithmUtils.run(population, 2, new AbstractPersonAlgorithm() {
@Override
public void run(Person person) {
person.getPlans().get(0).setScore(null); // this will result in an IndexOutOfBoundsException
}
});
Assert.fail("Expected Exception, got none.");
} catch (RuntimeException e) {
Log.info("Catched expected exception.", e);
}
}
代码示例来源:origin: matsim-org/matsim
@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 );
}
代码示例来源:origin: matsim-org/matsim
/**
* Tests that no Exception occurs if an agent has no leg at all, but the only activity has an end time set.
*
* @author mrieser
*/
@Test
public void testAgentWithoutLegWithEndtime() {
Fixture f = new Fixture(isUsingFastCapacityUpdate);
Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class));
Plan plan = PersonUtils.createAndAddPlan(person, true);
Activity act = PopulationUtils.createAndAddActivityFromLinkId(plan, "home", f.link1.getId());
act.setEndTime(6.0 * 3600);
f.plans.addPerson(person);
/* build events */
EventsManager events = EventsUtils.createEventsManager();
LinkEnterEventCollector collector = new LinkEnterEventCollector();
events.addHandler(collector);
/* run sim */
QSim sim = createQSim(f, events);
sim.run();
/* finish */
Assert.assertEquals("wrong number of link enter events.", 0, collector.events.size());
}
代码示例来源:origin: matsim-org/matsim
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);
}
代码示例来源:origin: matsim-org/matsim
@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()));
}
代码示例来源:origin: matsim-org/matsim
/**
* Tests that an AgentUtilityEvent is handled by calling the method addUtility() of a scoring function.
*/
public void testAddMoney() {
MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
Population population = scenario.getPopulation();
Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class));
population.addPerson(person);
MockScoringFunctionFactory sfFactory = new MockScoringFunctionFactory();
EventsManager events = EventsUtils.createEventsManager();
EventsToScore e2s = EventsToScore.createWithoutScoreUpdating(scenario, sfFactory, events);
e2s.beginIteration(0);
events.processEvent(new PersonMoneyEvent(3600.0, person.getId(), 3.4));
e2s.finish();
assertEquals(3.4, e2s.getAgentScore(person.getId()));
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testPersonAttributesIO() {
final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() );
final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump"));
population.addPerson( person );
person.getAttributes().putAttribute( "brain" , false );
person.getAttributes().putAttribute( "party" , "republican" );
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" ) );
Assert.assertEquals( "Unexpected boolean attribute in " + readPerson.getAttributes(),
person.getAttributes().getAttribute( "brain" ) ,
readPerson.getAttributes().getAttribute( "brain" ) );
Assert.assertEquals( "Unexpected String attribute in " + readPerson.getAttributes(),
person.getAttributes().getAttribute( "party" ) ,
readPerson.getAttributes().getAttribute( "party" ) );
}
代码示例来源:origin: matsim-org/matsim
@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" ) );
}
代码示例来源:origin: matsim-org/matsim
@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" ) );
}
内容来源于网络,如有侵权,请联系作者删除!