org.matsim.api.core.v01.population.Population.getPersons()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中org.matsim.api.core.v01.population.Population.getPersons()方法的一些代码示例,展示了Population.getPersons()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Population.getPersons()方法的具体详情如下:
包路径:org.matsim.api.core.v01.population.Population
类名称:Population
方法名:getPersons

Population.getPersons介绍

暂无

代码示例

代码示例来源: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

/**
 * 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: matsim-org/matsim

@Override
  public Map<Id<Person>, Plan> getExecutedPlans() {
    Map<Id<Person>,Plan> map = new HashMap<>() ;
    for ( Person pp : this.experiencedPopulation.getPersons().values() ) {
      map.put( pp.getId(), pp.getSelectedPlan() ) ;
    }
    return map ;
  }
}

代码示例来源:origin: matsim-org/matsim

@Override
  public void notifyIterationStarts(IterationStartsEvent event) {
    for (Person person : population.getPersons().values()) {
      agentRecords.put(person.getId(), PopulationUtils.createPlan());
    }
  }
});

代码示例来源:origin: matsim-org/matsim

public static void removePersonsNotUsingMode(String mode, Scenario scenario) {
  Map<Id<Person>, ? extends Person> persons = scenario.getPopulation().getPersons();
  Iterator<? extends Person> personIter = persons.values().iterator();
  while (personIter.hasNext()) {
    Plan selectedPlan = personIter.next().getSelectedPlan();
    if (!hasLegOfMode(selectedPlan, mode)) {
      personIter.remove();
    }
  }
}

代码示例来源:origin: matsim-org/matsim

@Override
public void notifyIterationEnds(IterationEndsEvent event) {
  if (this.isQSimIteration())
    return;
  Iterator<Map.Entry<Id<Person>, Double>> iterator = selectedPlanScoreMemory.entrySet().iterator();
  while (iterator.hasNext()) {
    Map.Entry<Id<Person>, Double> entry = iterator.next();
    scenario.getPopulation().getPersons().get(entry.getKey()).getSelectedPlan().setScore(entry.getValue());
  }
}

代码示例来源:origin: matsim-org/matsim

public final void run(final Population plans) {
  log.info("running " + this.getClass().getName() + " algorithm...");
  Counter counter = new Counter(" person # ");
  for (Person p : plans.getPersons().values()) {
    counter.incCounter();
    this.run(p);
  }
  counter.printCounter();
  log.info("done running algorithm.");
}

代码示例来源:origin: matsim-org/matsim

@Override
public void notifyIterationStarts(IterationStartsEvent event) {
  if (determineIfQSimIter(event.getIteration())) {
    Logger.getLogger(this.getClass()).warn("Running full queue simulation");
  } else {
    Logger.getLogger(this.getClass()).info("Running PSim");
    plancatcher.init();
    for (Person person : scenario.getPopulation().getPersons().values()) {
        plancatcher.addPlansForPsim(person.getSelectedPlan());
    }
  }
}

代码示例来源:origin: matsim-org/matsim

public void transmitPerformance() throws IOException {
  if (totalIterationTime > 0) {
    slaveLogger.warn("Spent a total of " + totalIterationTime +
        " running " + executedPlanCount +
        " person plans for " + numberOfPSimIterationsPerCycle +
        " PSim iterations.");
  }
  writer.writeDouble(totalIterationTime);
  writer.writeInt(matsimControler.getScenario().getPopulation().getPersons().size());
  //send memory usage fraction of max to prevent being assigned more persons
  writeMemoryStats();
}

代码示例来源:origin: matsim-org/matsim

@Override
public void handleEvent(PersonMoneyEvent event) {
  List<String> legTypes = new ArrayList<>() ;
  final Population pop = this.scenario.getPopulation();
  Person person = pop.getPersons().get( event.getPersonId() ) ;
  legTypes.add( this.getSubpopName(person)) ;
  double item = - event.getAmount() ;
  this.addItemToAllRegisteredTypes(legTypes, StatType.personPayments, item);
  // (this is not additive by person, but it is additive by legType.  So if a person has multiple money events, they
  // are added up in the legType category.  kai, feb'14)
  add(person.getId(), item, PAYMENTS);
}

代码示例来源:origin: matsim-org/matsim

public static void convertLegModes(List<String> passengerIds, String mode, Scenario scenario) {
  Map<Id<Person>, ? extends Person> persons = scenario.getPopulation().getPersons();
  for (String id : passengerIds) {
    Person person = persons.get(Id.create(id, Person.class));
    for (PlanElement pe : person.getSelectedPlan().getPlanElements()) {
      if (pe instanceof Leg) {
        ((Leg)pe).setMode(mode);
      }
    }
  }
}

代码示例来源:origin: matsim-org/matsim

private void writeMaxEps() {
  for (Person person : this.scenario.getPopulation().getPersons().values()) {
    for (String flexibleType : this.flexibleTypes) {
      double maxType = (Double)person.getCustomAttributes().get(flexibleType);
      this.personsMaxDCScoreUnscaled.putAttribute(person.getId().toString(), flexibleType, maxType);
    }    
  }
  ObjectAttributesXmlWriter attributesWriter = new ObjectAttributesXmlWriter(this.personsMaxDCScoreUnscaled);
  attributesWriter.writeFile(this.config.controler().getOutputDirectory() + maxEpsFile);
}

代码示例来源:origin: matsim-org/matsim

@Override
  public void notifyBeforeMobsim(BeforeMobsimEvent event) {
    Collection<Plan> plans = new ArrayList<>();
    for(Person person:controler.getScenario().getPopulation().getPersons().values()){
      plans.add(person.getSelectedPlan());
    }
    pSimProvider.setWaitTime(waitTimeCalculator.get());
    pSimProvider.setTravelTime(travelTimeCalculator.getLinkTravelTimes());
    pSimProvider.setStopStopTime(stopStopTimeCalculator.get());
  }
}

代码示例来源:origin: matsim-org/matsim

@Override
public void notifyBeforeMobsim(final BeforeMobsimEvent event) {
  this.cadytsPtOccupAnalyzer.reset(event.getIteration());
  for (Person person : scenario.getPopulation().getPersons().values()) {
    this.calibrator.addToDemand(ptStep.getCadytsPlan(person.getSelectedPlan()));
  }
}

代码示例来源:origin: matsim-org/matsim

private void assignKValuesPersons() {
  for (Person p : this.scenario.getPopulation().getPersons().values()) {
    this.personsKValues.putAttribute(p.getId().toString(), "k", rnd.getUniform(1.0));
  }
  // write person k values
  ObjectAttributesXmlWriter attributesWriter = new ObjectAttributesXmlWriter(this.personsKValues);
  attributesWriter.writeFile(config.controler().getOutputDirectory() + pkValuesFile);
}    
private void assignKValuesAlternatives() {

代码示例来源:origin: matsim-org/matsim

public void modifyPopulation(Population population) {
  // modify population: a plan was needed, which contained some properties to be compared with C++
  Person p = population.getPersons().get(Id.create("1", Person.class));
  Plan plan = p.getSelectedPlan();
  List<? extends PlanElement> actsLegs = plan.getPlanElements();
  ((Activity)actsLegs.get(0)).setEndTime(360);
  ((Activity)actsLegs.get(2)).setEndTime(900); // this requires immediate departure after arrival
  ((Activity)actsLegs.get(4)).setEndTime(2000);
}

代码示例来源:origin: matsim-org/matsim

@Test
  public void testLoadingScenarioFromURLWorks() throws MalformedURLException {
//        Config config = ConfigUtils.loadConfig(new URL("https://raw.githubusercontent.com/matsim-org/matsimExamples/master/tutorial/lesson-3/config.xml"));
    Config config = ConfigUtils.loadConfig(new URL("https://github.com/matsim-org/matsim/raw/master/examples/scenarios/lesson-3/config.xml"));
    Scenario scenario = ScenarioUtils.loadScenario(config);
    assertThat("Network has expected size.", scenario.getNetwork().getLinks().size(), equalTo(12940));
    assertThat("Population has expected size.", scenario.getPopulation().getPersons().size(), equalTo(8760));
    assertThat("There are the expected number of activity facilities.", scenario.getActivityFacilities().getFacilities().size(), equalTo(10281));
  }

代码示例来源:origin: matsim-org/matsim

@Override
  public boolean invoke() {
    Population inPopulation = loadPopulation(outputDirectoryHierarchy.getTempPath()+"/test_plans.in.xml");
    for (Person person : inPopulation.getPersons().values()) {
      person.getSelectedPlan().getPlanElements().clear();
    }
    new PopulationWriter(inPopulation).write(outputDirectoryHierarchy.getTempPath()+"/test_plans.out.xml");
    return true;
  }
}, "test", outputDirectoryHierarchy, scenario);

代码示例来源:origin: matsim-org/matsim

@Test
  public void testReadingPlansV4parallel() {
    Config config = ConfigUtils.createConfig();
    config.plans().setNetworkRouteType("CompressedNetworkRoute");
    Scenario s = ScenarioUtils.createScenario(config);
    new MatsimNetworkReader(s.getNetwork()).readFile("test/scenarios/equil/network.xml");
    new ParallelPopulationReaderMatsimV4(s).readFile("test/scenarios/equil/plans1.xml");
    Assert.assertEquals(1, s.getPopulation().getPersons().size());
    Leg firstPersonsLeg = (Leg) s.getPopulation().getPersons().get(Id.create("1", Person.class)).getSelectedPlan().getPlanElements().get(1);
//        Assert.assertTrue(firstPersonsLeg.getRoute() instanceof CompressedNetworkRouteImpl);
  }

代码示例来源:origin: matsim-org/matsim

@Test
public void test_Berlin_TestHandlerDetailedEventChecker() {
  Config config = ConfigUtils.loadConfig("test/scenarios/berlin/config.xml");
  MatsimRandom.reset(config.global().getRandomSeed());
  Scenario scenario = ScenarioUtils.createScenario(config);
  ScenarioUtils.loadScenario(scenario);
  this.runJDEQSim(scenario);
  
  assertEquals(scenario.getPopulation().getPersons().size(), super.eventsByPerson.size());
  super.checkAscendingTimeStamps();
  super.checkEventsCorrespondToPlans(scenario.getPopulation());
}

相关文章