本文整理了Java中org.matsim.api.core.v01.population.Population
类的一些代码示例,展示了Population
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Population
类的具体详情如下:
包路径:org.matsim.api.core.v01.population.Population
类名称:Population
[英]Root class of the population description (previously also called "plans file")
[中]总体描述的根类(以前也称为“计划文件”)
代码示例来源:origin: matsim-org/matsim
/**
* @return sorted map containing containing the persons as values and their ids as keys.
*/
public static SortedMap<Id<Person>, Person> getSortedPersons(final Population population) {
return new TreeMap<>(population.getPersons());
}
代码示例来源:origin: matsim-org/matsim
@Override
public PopulationFactory getFactory() {
return population.getFactory();
}
代码示例来源: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 startPlans(final Population plans, final BufferedWriter out) throws IOException {
out.write("<population");
if (plans.getName() != null) {
out.write(" desc=\"" + plans.getName() + "\"");
}
out.write(">\n\n");
this.attributesWriter.writeAttributes( "\t" , out , plans.getAttributes() );
out.write("\n\n");
}
代码示例来源:origin: matsim-org/matsim
/**
* Randomly chooses for each person of the population a strategy and uses that
* strategy on the person.
*
*/
public final void run(final Population population, final ReplanningContext replanningContext) {
beforePopulationRunHook(population, replanningContext);
delegate.run(population.getPersons().values(), population.getPersonAttributes(), replanningContext);
afterRunHook(population);
}
代码示例来源:origin: matsim-org/matsim
delegate.addPerson(p);
delegate.removePerson(p.getId());
代码示例来源: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
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
final Person person = sc.getPopulation().getFactory().createPerson(Id.createPersonId(i));
sc.getPopulation().addPerson(person);
sc.getPopulation().getPersonAttributes().putAttribute(person.getId().toString(), "subpopulation", subpop);
代码示例来源:origin: matsim-org/matsim
@Override
public ObjectAttributes getPersonAttributes() {
return population.getPersonAttributes();
}
代码示例来源:origin: matsim-org/matsim
@Override
public Attributes getAttributes() {
return delegate.getAttributes();
}
}
代码示例来源: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" ) );
}
代码示例来源: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: matsim-org/matsim
@Override
public void reset(final int iteration) {
delegate.reset(iteration);
this.agentDepartures.clear();
this.agentLegs.clear();
for ( StatType type : StatType.values() ) {
this.statsContainer.get(type).clear() ;
if ( this.sumsContainer.get(type)==null ) {
this.sumsContainer.put( type, new DataMap<String>() ) ;
}
this.sumsContainer.get(type).clear() ;
}
for ( Person person : this.scenario.getPopulation().getPersons().values() ) {
ObjectAttributes attribs = this.scenario.getPopulation().getPersonAttributes() ;
attribs.putAttribute( person.getId().toString(), TRAV_TIME, 0. ) ;
if ( attribs.getAttribute( person.getId().toString(), CERTAIN_LINKS_CNT ) != null ) {
attribs.putAttribute( person.getId().toString(), CERTAIN_LINKS_CNT, 0. ) ;
}
if ( attribs.getAttribute( person.getId().toString(), PAYMENTS) != null ) {
attribs.putAttribute( person.getId().toString(), PAYMENTS, 0. ) ;
}
}
// (yy not sure if I like the above; might be better to just use a local data structure. kai, may'14)
controlStatisticsSum = 0. ;
controlStatisticsCnt = 0. ;
}
代码示例来源:origin: matsim-org/matsim
@Override public ObjectAttributes getPersonAttributes() {
return delegate.getPersonAttributes();
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testPopulationAttributesIO() {
final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() );
population.getAttributes().putAttribute( "type" , "candidates" );
population.getAttributes().putAttribute( "number" , 2 );
final String file = utils.getOutputDirectory()+"/population.xml";
new PopulationWriter( population ).writeV6( file );
final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() );
new PopulationReader( readScenario ).readFile( file );
Assert.assertEquals( "Unexpected numeric attribute in " + readScenario.getPopulation().getAttributes(),
population.getAttributes().getAttribute( "number" ) ,
readScenario.getPopulation().getAttributes().getAttribute( "number" ) );
Assert.assertEquals( "Unexpected String attribute in " + readScenario.getPopulation().getAttributes(),
population.getAttributes().getAttribute( "type" ) ,
readScenario.getPopulation().getAttributes().getAttribute( "type" ) );
}
}
代码示例来源: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
/**
* Sorts the persons in the given population.
*/
@SuppressWarnings("unchecked")
public static void sortPersons(final Population population) {
Map<Id<Person>, Person> map = (Map<Id<Person>, Person>) population.getPersons();
if (map instanceof SortedMap) return;
Map<Id<Person>, Person> treeMap = new TreeMap<>(map);
map.clear();
map.putAll(treeMap);
}
代码示例来源:origin: io.github.agentsoz/util
public static void addPersonWithActivity(String actType,
Coordinates coordsOfAct, double actEndTime, Scenario scenario) {
PopulationFactory populationFactory = scenario.getPopulation()
.getFactory();
Coord matSimCoord = new Coord(coordsOfAct.getLongitude(),
coordsOfAct.getLatitude());
// Create a new plan
Plan plan = populationFactory.createPlan();
// Create a new activity with the end time and add it to the plan
Activity act = populationFactory.createActivityFromCoord(actType,
matSimCoord);
act.setEndTime(actEndTime);
plan.addActivity(act);
// Add a new leg to the plan. Needed, otherwise MATSim won't add this
// leg-less plan to the simulation
plan.addLeg(populationFactory.createLeg("car"));
// Create a second activity (all plans must end in an activity)
act = populationFactory.createActivityFromCoord(actType.toString(),
matSimCoord);
plan.addActivity(act);
Person person = populationFactory.createPerson(Id
.createPersonId(personIdPrefix + personId++));
person.addPlan(plan);
scenario.getPopulation().addPerson(person);
}
代码示例来源:origin: matsim-org/matsim
@Override public PopulationFactory getFactory() {
return delegate.getFactory();
}
@Override public String getName() {
内容来源于网络,如有侵权,请联系作者删除!