@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"));
  }
Exemple #2
0
  public void plans2Shape(Population population, String outputFile) {

    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.setName("shape");
    typeBuilder.add("geometry", Point.class);
    typeBuilder.add("id", String.class);
    typeBuilder.add("actType", String.class);
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());

    List<SimpleFeature> features = new ArrayList<SimpleFeature>();

    for (Person person : population.getPersons().values()) {

      for (PlanElement pe : person.getSelectedPlan().getPlanElements()) {

        if (pe instanceof Activity) {

          Activity act = (Activity) pe;
          Coord coord = act.getCoord();

          SimpleFeature feature =
              builder.buildFeature(
                  null,
                  new Object[] {
                    new GeometryFactory().createPoint(new Coordinate(coord.getX(), coord.getY())),
                    person.getId().toString(),
                    act.getType()
                  });
          features.add(feature);
        }
      }
    }

    ShapeFileWriter.writeGeometries(features, outputFile);
  }
  private void createDemand() {

    Population pop = sc.getPopulation();
    PopulationFactory fact = pop.getFactory();

    for (int i = 1; i <= 400; i++) {

      Person p = fact.createPerson(Id.createPersonId(i));
      Plan plan = fact.createPlan();
      p.addPlan(plan);
      Leg leg = fact.createLeg(TransportMode.car);
      Activity home;
      Activity work;

      if (i % 2 == 0) { // o --d1
        home = fact.createActivityFromCoord("o1", lo.getCoord());
        home.setEndTime(7 * 3600 + i);
        work = fact.createActivityFromCoord("d1", ld1.getCoord());
      } else /*if(i%2==0)*/ { // o --d2
        home = fact.createActivityFromCoord("o1", lo.getCoord());
        home.setEndTime(7 * 3600 + i);
        work = fact.createActivityFromCoord("d2", ld2.getCoord());
      }
      plan.addActivity(home);
      plan.addLeg(leg);
      plan.addActivity(work);
      pop.addPerson(p);
    }
    new PopulationWriter(pop).write(outputDir + "/input/input_plans.xml.gz");
  }
  @Test
  public void testNumberOfSelectedJointPlans() throws Exception {
    final JointPlans jointPlans = new JointPlans();
    final GroupPlanStrategy strategy =
        new GroupPlanStrategy(
            new HighestScoreSumSelector(new EmptyIncompatiblePlansIdentifierFactory()));
    strategy.addStrategyModule(new JointStructureInvertingModule(jointPlans.getFactory()));

    final ReplanningGroup group = createTestGroup(jointPlans);
    strategy.run(createContext(), jointPlans, Arrays.asList(group));

    int countSelectedJoint = 0;
    int countSelectedIndiv = 0;
    for (Person person : group.getPersons()) {
      for (Plan plan : person.getPlans()) {
        if (plan.isSelected() && jointPlans.getJointPlan(plan) != null) {
          countSelectedJoint++;
        }
        if (plan.isSelected() && jointPlans.getJointPlan(plan) == null) {
          countSelectedIndiv++;
        }
      }
    }

    assertEquals(
        "wrong number of selected plans in joint plans",
        N_INITIALLY_INDIV_PLANS,
        countSelectedJoint);
    assertEquals(
        "wrong number of selected plans in individual plans",
        N_INITIALLY_JOINT_PLANS,
        countSelectedIndiv);
  }
Exemple #5
0
 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;
 }
  public static void main(String[] args) {

    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    MatsimReader populationReader = new PopulationReader(scenario);
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario.getNetwork());
    networkReader.readFile(args[1]);
    populationReader.readFile(args[2]);

    ObjectAttributes bla = new ObjectAttributes();

    new ObjectAttributesXmlReader(bla).readFile(args[0]);

    for (Person p : scenario.getPopulation().getPersons().values()) {
      String act = "home";
      if (bla.getAttribute(p.getId().toString(), "earliestEndTime_leisure") != null)
        act = act + ",leisure";
      //	if (bla.getAttribute(p.getId().toString(), "earliestEndTime_work") != null)
      //		act = act + ",work";
      if (bla.getAttribute(p.getId().toString(), "earliestEndTime_shop") != null)
        act = act + ",shop";
      //	if (bla.getAttribute(p.getId().toString(), "earliestEndTime_education") != null)
      //		act = act + ",education";

      bla.putAttribute(p.getId().toString(), "activities", act);
    }

    ObjectAttributesXmlWriter betaWriter = new ObjectAttributesXmlWriter(bla);
    betaWriter.writeFile(args[3]);
  }
Exemple #7
0
  public final void createPersonQuadTree() {
    log.info("TEST");
    double minx = (1.0D / 0.0D);
    double miny = (1.0D / 0.0D);
    double maxx = (-1.0D / 0.0D);
    double maxy = (-1.0D / 0.0D);

    for (ActivityFacility f : this.scenario.getActivityFacilities().getFacilities().values()) {
      if (f.getCoord().getX() < minx) minx = f.getCoord().getX();
      if (f.getCoord().getY() < miny) miny = f.getCoord().getY();
      if (f.getCoord().getX() > maxx) maxx = f.getCoord().getX();
      if (f.getCoord().getY() > maxy) maxy = f.getCoord().getY();
    }
    minx -= 1.0D;
    miny -= 1.0D;
    maxx += 1.0D;
    maxy += 1.0D;
    QuadTree<Person> personQuadTree = new QuadTree<>(minx, miny, maxx, maxy);
    for (Person p : this.scenario.getPopulation().getPersons().values()) {
      Coord c =
          ((ActivityFacility)
                  this.scenario
                      .getActivityFacilities()
                      .getFacilities()
                      .get(
                          PopulationUtils.getFirstActivity(((Plan) p.getSelectedPlan()))
                              .getFacilityId()))
              .getCoord();
      personQuadTree.put(c.getX(), c.getY(), p);
    }
    log.info("PersonQuadTree has been created");
    this.personQuadTree = personQuadTree;
  }
  @Test
  public void testCoord3dIO() {
    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);
    plan.addActivity(population.getFactory().createActivityFromCoord("speech", new Coord(0, 0)));
    plan.addActivity(
        population.getFactory().createActivityFromCoord("tweet", new Coord(0, 0, -100)));

    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 readSpeach = (Activity) readPerson.getSelectedPlan().getPlanElements().get(0);
    final Activity readTweet = (Activity) readPerson.getSelectedPlan().getPlanElements().get(1);

    Assert.assertFalse(
        "did not expect Z value in " + readSpeach.getCoord(), readSpeach.getCoord().hasZ());

    Assert.assertTrue("did expect T value in " + readTweet.getCoord(), readTweet.getCoord().hasZ());

    Assert.assertEquals(
        "unexpected Z value in " + readTweet.getCoord(),
        -100,
        readTweet.getCoord().getZ(),
        MatsimTestUtils.EPSILON);
  }
  @Test
  public void testNewPlanIsSelected() throws Exception {
    final JointPlans jointPlans = new JointPlans();
    final GroupPlanStrategy strategy =
        new GroupPlanStrategy(
            new HighestScoreSumSelector(new EmptyIncompatiblePlansIdentifierFactory()));
    strategy.addStrategyModule(new JointStructureInvertingModule(jointPlans.getFactory()));

    final List<Plan> selectedPlans = new ArrayList<Plan>();
    final ReplanningGroup group = createTestGroup(jointPlans);
    for (Person p : group.getPersons()) {
      selectedPlans.add(p.getSelectedPlan());
    }

    strategy.run(createContext(), jointPlans, Arrays.asList(group));
    for (Person person : group.getPersons()) {
      for (Plan plan : person.getPlans()) {
        if (plan.isSelected()) {
          // new plan: selection status inverted
          assertFalse("old plan still selected", selectedPlans.contains(plan));
        } else {
          assertTrue("old plan still selected", selectedPlans.contains(plan));
        }
      }
    }
  }
  @Override
  public ScoringFunction createNewScoringFunction(Person person) {

    ScoringFunctionAccumulator scoringFunctionAccumulator = new ScoringFunctionAccumulator();

    //		scoringFunctionAccumulator.addScoringFunction(new ActivityScoringFunction(plan,
    // super.getParams()));

    scoringFunctionAccumulator.addScoringFunction(
        new ActivityScoringFunction(
            person.getSelectedPlan(),
            CharyparNagelScoringParameters.getBuilder(config.planCalcScore(), config.scenario())
                .create(),
            this.facilityPenalties,
            this.facilities,
            this.config));
    scoringFunctionAccumulator.addScoringFunction(
        new LegScoringFunction(
            person.getSelectedPlan(),
            CharyparNagelScoringParameters.getBuilder(config.planCalcScore(), config.scenario())
                .create(),
            config,
            this.network,
            this.ktiConfigGroup));
    scoringFunctionAccumulator.addScoringFunction(
        new org.matsim.core.scoring.functions.CharyparNagelMoneyScoring(
            CharyparNagelScoringParameters.getBuilder(config.planCalcScore(), config.scenario())
                .create()));
    scoringFunctionAccumulator.addScoringFunction(
        new org.matsim.core.scoring.functions.CharyparNagelAgentStuckScoring(
            CharyparNagelScoringParameters.getBuilder(config.planCalcScore(), config.scenario())
                .create()));

    return scoringFunctionAccumulator;
  }
Exemple #11
0
 private static void dropDepTimes(Population population) {
   for (Person pers : population.getPersons().values()) {
     for (Plan p : pers.getPlans()) {
       ((Activity) p.getPlanElements().get(0)).setEndTime(0);
     }
   }
 }
  @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"));
  }
Exemple #13
0
  public static final QuadTree<Person> createPersonQuadTree(Controler controler) {
    double minx = (1.0D / 0.0D);
    double miny = (1.0D / 0.0D);
    double maxx = (-1.0D / 0.0D);
    double maxy = (-1.0D / 0.0D);

    for (ActivityFacility f :
        controler.getScenario().getActivityFacilities().getFacilities().values()) {
      if (f.getCoord().getX() < minx) minx = f.getCoord().getX();
      if (f.getCoord().getY() < miny) miny = f.getCoord().getY();
      if (f.getCoord().getX() > maxx) maxx = f.getCoord().getX();
      if (f.getCoord().getY() <= maxy) continue;
      maxy = f.getCoord().getY();
    }
    minx -= 1.0D;
    miny -= 1.0D;
    maxx += 1.0D;
    maxy += 1.0D;
    QuadTree<Person> personQuadTree = new QuadTree<Person>(minx, miny, maxx, maxy);
    for (Person p : controler.getScenario().getPopulation().getPersons().values()) {
      Coord c =
          ((ActivityFacility)
                  controler
                      .getScenario()
                      .getActivityFacilities()
                      .getFacilities()
                      .get(((PlanImpl) p.getSelectedPlan()).getFirstActivity().getFacilityId()))
              .getCoord();
      personQuadTree.put(c.getX(), c.getY(), p);
    }
    log.info("PersonQuadTree has been created");
    return personQuadTree;
  }
Exemple #14
0
  private void createOneTransitTrucker(
      int i, Coord origin, Coord destination, String mode, String fromToPrefix) {
    Id<Person> personId = Id.createPersonId(fromToPrefix + i);
    Person person = scenario.getPopulation().getFactory().createPerson(personId);

    Plan plan = scenario.getPopulation().getFactory().createPlan();

    Activity cargo = scenario.getPopulation().getFactory().createActivityFromCoord("cargo", origin);
    int rand = random.nextInt(18 * 60 * 60) + 1;
    cargo.setEndTime(rand);
    plan.addActivity(cargo);

    Leg outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(outboundTrip);

    Activity cargod =
        scenario.getPopulation().getFactory().createActivityFromCoord("cargoD", destination);
    cargod.setMaximumDuration(3600);
    plan.addActivity(cargod);
    Leg inBundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(inBundTrip);

    Activity cargo2 =
        scenario.getPopulation().getFactory().createActivityFromCoord("cargo", origin);
    plan.addActivity(cargo2);

    person.addPlan(plan);
    scenario
        .getPopulation()
        .getPersonAttributes()
        .putAttribute(person.getId().toString(), "subpopulation", "noRep");
    scenario.getPopulation().addPerson(person);
  }
Exemple #15
0
  private void createOneVWTrucker(
      int i, Coord origin, Coord destination, String mode, String fromToPrefix) {
    Id<Person> personId = Id.createPersonId(fromToPrefix + i);
    Person person = scenario.getPopulation().getFactory().createPerson(personId);

    Plan plan = scenario.getPopulation().getFactory().createPlan();

    Activity source =
        scenario.getPopulation().getFactory().createActivityFromCoord("source", origin);
    double rand = random.nextDouble() * 18 * 60 * 60;
    source.setEndTime(rand);
    plan.addActivity(source);

    Leg outboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(outboundTrip);

    Activity delivery =
        scenario.getPopulation().getFactory().createActivityFromCoord("delivery", destination);
    delivery.setMaximumDuration(3600);
    plan.addActivity(delivery);

    Leg inboundTrip = scenario.getPopulation().getFactory().createLeg(mode);
    plan.addLeg(inboundTrip);
    Activity source2 =
        scenario.getPopulation().getFactory().createActivityFromCoord("source", origin);
    plan.addActivity(source2);

    person.addPlan(plan);
    scenario
        .getPopulation()
        .getPersonAttributes()
        .putAttribute(person.getId().toString(), "subpopulation", "noRep");

    scenario.getPopulation().addPerson(person);
  }
Exemple #16
0
  private static void getPersonsWithNegativeScores() {

    String plansFile = runPath + "output/output_plans.xml.gz";

    Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimPopulationReader(scenario).parse(plansFile);

    Set<Person> plansWithNegativeScores = new HashSet<Person>();

    for (Person person : scenario.getPopulation().getPersons().values()) {

      if (person.getSelectedPlan().getScore() < 0) {

        plansWithNegativeScores.add(person);
      }
    }
    BufferedWriter writer = IOUtils.getBufferedWriter(analysisPath + "negativeScores.txt");

    try {

      for (Person person : plansWithNegativeScores) {

        writer.write(person.getId().toString() + "\t" + person.getSelectedPlan().getScore());

        writer.newLine();
      }

      writer.flush();
      writer.close();

    } catch (IOException e) {

      e.printStackTrace();
    }
  }
 // does not matter which distribution is chosen here
 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);
 }
Exemple #18
0
 /**
  * copy the person and the selected plan of the person
  *
  * @param person
  * @return
  */
 public static Person copyPerson(Person person) {
   Person newPerson = PersonImpl.createPerson(person.getId());
   PlanImpl newPlan = new PlanImpl();
   newPlan.copyFrom(person.getSelectedPlan());
   newPlan.setPerson(newPerson);
   newPerson.addPlan(newPlan);
   newPerson.setSelectedPlan(newPlan);
   PersonUtils.removeUnselectedPlans(newPerson);
   return newPerson;
 }
  @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"));
  }
Exemple #20
0
 public static BasePersonImpl convertToBasePerson(Person person) {
   BasePersonImpl newPerson = new BasePersonImpl(person.getId());
   PersonUtils.setAge(newPerson, PersonUtils.getAge(person));
   PersonUtils.setCarAvail(newPerson, PersonUtils.getCarAvail(person));
   PersonUtils.setEmployed(newPerson, PersonUtils.isEmployed(person));
   PersonUtils.setLicence(newPerson, PersonUtils.getLicense(person));
   PersonUtils.setSex(newPerson, PersonUtils.getSex(person));
   for (Plan plan : person.getPlans()) if (!PersonUtils.isSelected(plan)) newPerson.addPlan(plan);
   BasePlanImpl.convertToBasePlan(newPerson, person.getSelectedPlan());
   return newPerson;
 }
  private static Person createPerson(
      final int count, final boolean joint, final Map<Id<Person>, Plan> jointPlan) {
    Id<Person> id = Id.createPersonId(count);
    Person person = PersonImpl.createPerson(id);
    PlanImpl plan = new PlanImpl(person);
    person.addPlan(plan);
    if (joint) jointPlan.put(id, plan);
    if (!plan.isSelected()) throw new RuntimeException();

    return person;
  }
  @Override
  public void notifyIterationStarts(IterationStartsEvent event) {
    int evCount = 0;
    int cvCount = 0;
    int newKeysAdded = 0;
    int existingKeyUsed = 0;
    int numberOfPlansRemovedFromHM = 0;
    HashSet<Plan> allCurrentPlans = new HashSet<Plan>();
    for (Person person : event.getServices().getScenario().getPopulation().getPersons().values()) {

      if (person.getId().toString().equalsIgnoreCase("111106347")) {
        System.out.println();
      }

      if (hasCarLeg(person.getSelectedPlan())) {
        if (!hasElectricVehicle.containsKey(person.getSelectedPlan())) {
          hasElectricVehicle.put(person.getSelectedPlan(), MatsimRandom.getRandom().nextBoolean());
          newKeysAdded++;
        } else {
          existingKeyUsed++;
        }

        if (hasElectricVehicle.get(person.getSelectedPlan())) {
          evCount++;
          personHasElectricVehicle.put(person.getId(), true);
        } else {
          cvCount++;
          personHasElectricVehicle.put(person.getId(), false);
        }

        for (Plan plan : person.getPlans()) {
          allCurrentPlans.add(plan);
        }
      }
    }

    LinkedList<Plan> removePlans = new LinkedList<Plan>();
    for (Plan plan : hasElectricVehicle.keySet()) {
      if (!allCurrentPlans.contains(plan)) {
        removePlans.add(plan);
      }
    }

    for (Plan plan1 : removePlans) {
      hasElectricVehicle.remove(plan1);
      numberOfPlansRemovedFromHM++;
    }

    log.info("iteration: " + event.getIteration());

    log.info("numberOfPlansRemovedFromHM: " + numberOfPlansRemovedFromHM);
    log.info("evCount: " + evCount);
    log.info("cvCount: " + cvCount);
    log.info("hasElectricVehicle.size(): " + hasElectricVehicle.size());
    log.info("newKeysAdded: " + newKeysAdded);
    log.info("existingKeyUsed: " + existingKeyUsed);
    log.info("");
  }
  public static Set<Coord> getCoords(Population population) {
    Set<Coord> coords = new HashSet<Coord>();

    for (Person person : population.getPersons().values()) {
      Plan plan = person.getPlans().get(0);
      Activity act = (Activity) plan.getPlanElements().get(0);
      Coord c = act.getCoord();
      coords.add(c);
    }

    return coords;
  }
 public void printResults(CongestionAnalysisHandler congestionHandler, Scenario scenario) {
   System.out.println("isCaughtCongestionEvent: " + congestionHandler.isCaughtCongestionEvent());
   System.out.println("totalDelay: " + congestionHandler.getTotalDelay());
   for (Person person : scenario.getPopulation().getPersons().values()) {
     System.out.println("Person Id : " + person.getId());
     System.out.println(
         "causedDelay: "
             + congestionHandler.getPersonId2tripNumber2causedDelay().get(person.getId()));
     System.out.println(
         "affectedDelay: "
             + congestionHandler.getPersonId2tripNumber2affectedDelay().get(person.getId()));
   }
 }
 @Override
 public void run(Person person) {
   Integer p_id = Integer.valueOf(person.getId().toString());
   Coord coord = persons.getPerson(p_id).getHousehold().getCoord();
   ActivityFacility f = this.homeFacQuadTree.get(coord.getX(), coord.getY());
   Plan plan = person.getSelectedPlan();
   for (PlanElement pe : plan.getPlanElements()) {
     if (pe instanceof ActivityImpl) {
       ActivityImpl act = (ActivityImpl) pe;
       if (H.equals(act.getType())) {
         act.setCoord(f.getCoord());
       }
     }
   }
 }
Exemple #26
0
 private void replaceSptByPtp() {
   for (Id<Person> pid : this.teleportPtUsers) {
     Person p = scenario.getPopulation().getPersons().get(pid);
     for (Plan plan : p.getPlans()) {
       for (PlanElement pe : plan.getPlanElements()) {
         if (pe instanceof Leg) {
           Leg leg = (Leg) pe;
           if (leg.getMode().equals("pt")) {
             leg.setMode("tpt");
           }
         }
       }
     }
   }
 }
Exemple #27
0
  private void replaceDoubtfulLegsByOtherMode() {
    for (Person p : scenario.getPopulation().getPersons().values()) {
      for (Plan plan : p.getPlans()) {

        Leg lastleg = null;
        Activity lastActivity = null;
        boolean personb = random.nextBoolean();
        for (PlanElement pe : plan.getPlanElements()) {
          if (pe instanceof Activity) {
            if (lastActivity == null) {
              lastActivity = (Activity) pe;
            } else {
              Coord lastCoord;
              if (lastActivity.getCoord() != null) {
                lastCoord = lastActivity.getCoord();
              } else {
                Link lastLink = scenario.getNetwork().getLinks().get(lastActivity.getLinkId());
                lastCoord = lastLink.getCoord();
              }
              Coord currentCoord;
              if (((Activity) pe).getCoord() != null) {
                currentCoord = ((Activity) pe).getCoord();
              } else {
                currentCoord =
                    scenario.getNetwork().getLinks().get(((Activity) pe).getLinkId()).getCoord();
              }

              double distance = CoordUtils.calcDistance(lastCoord, currentCoord);

              if (distance > 3000 && lastleg.getMode().equals("walk")) {
                lastleg.setMode("pt");
              } else if (distance > 20000 && lastleg.getMode().equals("bike")) {
                lastleg.setMode("pt");
              } else if (distance < 2000 && (lastleg.getMode().equals("pt"))) {
                if (personb == true) lastleg.setMode("walk");
                else lastleg.setMode("bike");
              }

              lastActivity = (Activity) pe;
            }

          } else if (pe instanceof Leg) {
            lastleg = (Leg) pe;
          }
        }
      }
    }
  }
 @Override
 public void writePerson(final Person person, final BufferedWriter out) throws IOException {
   PopulationWriterHandlerImplV5.startPerson(person, out);
   for (Plan plan : person.getPlans()) {
     PopulationWriterHandlerImplV5.startPlan(plan, out);
     // act/leg
     for (PlanElement pe : plan.getPlanElements()) {
       if (pe instanceof Activity) {
         Activity act = (Activity) pe;
         this.writeAct(act, out);
       } else if (pe instanceof Leg) {
         Leg leg = (Leg) pe;
         PopulationWriterHandlerImplV5.startLeg(leg, out);
         // route
         Route route = leg.getRoute();
         if (route != null) {
           PopulationWriterHandlerImplV5.startRoute(route, out);
           PopulationWriterHandlerImplV5.endRoute(out);
         }
         PopulationWriterHandlerImplV5.endLeg(out);
       }
     }
     PopulationWriterHandlerImplV5.endPlan(out);
   }
   PopulationWriterHandlerImplV5.endPerson(out);
   this.writeSeparator(out);
   out.flush();
 }
 private static void startPerson(final Person p, final BufferedWriter out) throws IOException {
   out.write("\t<person id=\"");
   out.write(p.getId().toString());
   out.write("\"");
   if (p != null) {
     Person person = p;
     if (PersonUtils.getSex(person) != null) {
       out.write(" sex=\"");
       out.write(PersonUtils.getSex(person));
       out.write("\"");
     }
     if (PersonUtils.getAge(person) != null) {
       out.write(" age=\"");
       out.write(Integer.toString(PersonUtils.getAge(person)));
       out.write("\"");
     }
     if (PersonUtils.getLicense(person) != null) {
       out.write(" license=\"");
       out.write(PersonUtils.getLicense(person));
       out.write("\"");
     }
     if (PersonUtils.getCarAvail(person) != null) {
       out.write(" car_avail=\"");
       out.write(PersonUtils.getCarAvail(person));
       out.write("\"");
     }
     if (PersonUtils.isEmployed(person) != null) {
       out.write(" employed=\"");
       out.write((PersonUtils.isEmployed(person) ? "yes" : "no"));
       out.write("\"");
     }
   }
   out.write(">\n");
 }
  public double getParkingWalkBeta(Person person, double activityDurationInSeconds) {
    Id personId = person.getId();
    Parser parser = null;
    if (!parkingWalkBetaCache.containsKey(personId)) {
      Parser pTmp = new Parser(parkingWalkBeta);
      PersonImpl persImpl = (PersonImpl) person;

      int isMale = 1;
      if (persImpl.getSex() != null) {
        isMale = !persImpl.getSex().contains("f") ? 1 : 0;
      }

      pTmp.setVariable("isMale", isMale);

      int age = persImpl.getAge();

      pTmp.setVariable("ageInYears", age);
      parkingWalkBetaCache.put(personId, pTmp);
    }
    parser = parkingWalkBetaCache.get(personId);

    parser.setVariable("activityDurationInSeconds", activityDurationInSeconds);

    double result = 0;

    try {
      result = parser.parse();
    } catch (SyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return result;
  }