コード例 #1
0
  private Population getTestPopulation() {
    Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    Network network = scenario.getNetwork();
    new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml");

    Link link1 = network.getLinks().get(Id.create(1, Link.class));
    Link link20 = network.getLinks().get(Id.create(20, Link.class));

    Population population = scenario.getPopulation();

    Person person;
    PlanImpl plan;
    LegImpl leg;
    NetworkRoute route;

    person = PopulationUtils.createPerson(Id.create("1", Person.class));
    plan = PersonUtils.createAndAddPlan(person, true);
    ActivityImpl a = plan.createAndAddActivity("h", link1.getId());
    a.setEndTime(7.0 * 3600);
    leg = plan.createAndAddLeg(TransportMode.car);
    route = new LinkNetworkRouteImpl(link1.getId(), link20.getId());
    route.setLinkIds(link1.getId(), NetworkUtils.getLinkIds("6 15"), link20.getId());
    leg.setRoute(route);
    plan.createAndAddActivity("w", link20.getId());
    population.addPerson(person);

    person = PopulationUtils.createPerson(Id.create("2", Person.class));
    plan = PersonUtils.createAndAddPlan(person, true);
    ActivityImpl a2 = plan.createAndAddActivity("h", link1.getId());
    a2.setEndTime(7.0 * 3600 + 5.0 * 60);
    leg = plan.createAndAddLeg(TransportMode.car);
    route = new LinkNetworkRouteImpl(link1.getId(), link20.getId());
    route.setLinkIds(link1.getId(), NetworkUtils.getLinkIds("6 15"), link20.getId());
    leg.setRoute(route);
    plan.createAndAddActivity("w", link20.getId());
    population.addPerson(person);

    person = PopulationUtils.createPerson(Id.create("3", Person.class));
    plan = PersonUtils.createAndAddPlan(person, true);
    ActivityImpl a3 = plan.createAndAddActivity("h", link1.getId());
    a3.setEndTime(7.0 * 3600 + 10.0 * 60);
    leg = plan.createAndAddLeg(TransportMode.car);
    route = new LinkNetworkRouteImpl(link1.getId(), link20.getId());
    route.setLinkIds(link1.getId(), NetworkUtils.getLinkIds("5 14"), link20.getId());
    leg.setRoute(route);
    plan.createAndAddActivity("w", link20.getId());
    population.addPerson(person);

    return population;
  }
コード例 #2
0
ファイル: ZHCutter.java プロジェクト: sebhoerl/matsim
 public Population geographicallyFilterPopulation(
     final Population origPopulation, final ObjectAttributes personAttributes) {
   Population filteredPopulation = PopulationUtils.createPopulation(ConfigUtils.createConfig());
   Counter counter = new Counter(" person # ");
   boolean actInArea;
   for (Person p : origPopulation.getPersons().values()) {
     counter.incCounter();
     if (p.getSelectedPlan() != null) {
       actInArea = false;
       for (PlanElement pe : p.getSelectedPlan().getPlanElements()) {
         if (!actInArea && pe instanceof ActivityImpl) {
           ActivityImpl act = (ActivityImpl) pe;
           if (inArea(act.getCoord())) {
             actInArea = true;
           }
         }
       }
       if (actInArea) {
         filteredPopulation.addPerson(p);
         filteredAgents.put(p.getId(), p);
       } else {
         personAttributes.removeAllAttributes(p.toString());
       }
     }
   }
   return filteredPopulation;
 }
コード例 #3
0
  @Test
  // tests concatenation and ordering of given Populations, limited by maxIndexExclusive
  public void testConcatenate2() throws Exception {
    SimpleIndividual[] ind1 =
        new SimpleIndividual[] {
          new SimpleIndividual(1, 1.0, null),
          new SimpleIndividual(2, 3.0, null),
          new SimpleIndividual(5, 3.0, null)
        };
    SimpleIndividual[] ind2 =
        new SimpleIndividual[] {
          new SimpleIndividual(10, 0.0, null), new SimpleIndividual(2, 2.0, null)
        };

    Individual[] indOut =
        PopulationUtils.concatenate(
                new Population[] {
                  new SimplePopulation(ind1), new SimplePopulation(ind2), new SimplePopulation(ind1)
                },
                new SimplePopulationFactory(),
                2)
            .getIndividuals();

    assertTrue(indOut[0] == ind1[0]);
    assertTrue(indOut[1] == ind1[1]);
    assertTrue(indOut[2] == ind1[2]);
    assertTrue(indOut[3] == ind2[0]);
    assertTrue(indOut[4] == ind2[1]);
    assertTrue(indOut.length == ind1.length + ind2.length);
  }
コード例 #4
0
 @Test
 // tests appending at the beginning of the empty populations
 public void testAppendPopulation4() {
   Population populationToAppend = new SimplePopulation();
   Population[] results = PopulationUtils.appendPopulation(null, populationToAppend, false);
   assertEquals(1, results.length);
   assertSame(populationToAppend, results[0]);
 }
コード例 #5
0
  @Test
  // tests concatenation of single EMPTY Population
  public void testConcatenate4() throws Exception {
    SimplePopulation pop1 = new SimplePopulation();

    Individual[] indOut =
        PopulationUtils.concatenate(new Population[] {pop1}, new SimplePopulationFactory())
            .getIndividuals();

    assertTrue(pop1.getIndividuals() == indOut || indOut.length == 0);
  }
コード例 #6
0
 @Test
 // tests appending at the beginning of the population
 public void testAppendPopulation2() {
   Population[] inputPopulations =
       new Population[] {new SimplePopulation(), new SimplePopulation(), new SimplePopulation()};
   Population populationToAppend = new SimplePopulation();
   Population[] results =
       PopulationUtils.appendPopulation(inputPopulations, populationToAppend, false);
   assertEquals(4, results.length);
   assertSame(populationToAppend, results[0]);
   assertSame(inputPopulations[0], results[1]);
   assertSame(inputPopulations[1], results[2]);
   assertSame(inputPopulations[2], results[3]);
 }
コード例 #7
0
ファイル: GeneralLib.java プロジェクト: nkuehnel/matsim
  /**
   * TODO: write test.
   *
   * @param persons
   * @param outputPlansFileName
   * @param network
   */
  public static void writePersons(
      Collection<? extends Person> persons, String outputPlansFileName, Network network) {
    PopulationWriter popWriter =
        new PopulationWriter(
            PopulationUtils.createPopulation(
                ((MutableScenario) null).getConfig(), ((MutableScenario) null).getNetwork()),
            network);
    popWriter.writeStartPlans(outputPlansFileName);

    for (Person person : persons) {
      popWriter.writePerson(person);
    }

    popWriter.writeEndPlans();
  }
コード例 #8
0
  private void startPerson(final Attributes atts) {
    this.currperson = PopulationUtils.createPerson(Id.create(atts.getValue("id"), Person.class));
    PersonUtils.setSex(this.currperson, atts.getValue("sex"));

    PersonUtils.setAge(this.currperson, Integer.parseInt(atts.getValue("age")));

    PersonUtils.setLicence(this.currperson, atts.getValue("license"));
    PersonUtils.setCarAvail(this.currperson, atts.getValue("car_avail"));
    String employed = atts.getValue("employed");
    if (employed == null) {
      PersonUtils.setEmployed(this.currperson, null);
    } else {
      PersonUtils.setEmployed(this.currperson, "yes".equals(employed));
    }
  }
コード例 #9
0
  @Test
  // tests concatenation of single Population - creation of new array of Individual
  public void testConcatenate3() throws Exception {
    SimpleIndividual[] ind1 =
        new SimpleIndividual[] {
          new SimpleIndividual(1, 1.0, null),
          new SimpleIndividual(2, 3.0, null),
          new SimpleIndividual(5, 3.0, null)
        };
    SimplePopulation pop1 = new SimplePopulation(ind1);

    Individual[] indOut =
        PopulationUtils.concatenate(new Population[] {pop1}, new SimplePopulationFactory())
            .getIndividuals();

    assertTrue(indOut[0] == ind1[0]);
    assertTrue(indOut[1] == ind1[1]);
    assertTrue(indOut[2] == ind1[2]);
    assertNotSame(pop1.getIndividuals(), indOut);
    assertNotSame(ind1, indOut);
    assertTrue(indOut.length == ind1.length);
  }
コード例 #10
0
 @Test
 // tests appending empty population at the beginning of the empty populations
 public void testAppendPopulation5() {
   Population[] results = PopulationUtils.appendPopulation(null, null, true);
   assertEquals(null, results);
 }