예제 #1
1
  @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"));
  }
예제 #2
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);
     }
   }
 }
예제 #3
0
  public static int getDepartureParkingActIndex(Plan plan, ActivityImpl activity) {
    List<PlanElement> pe = plan.getPlanElements();
    int activityIndex = pe.indexOf(activity);
    int indexOfDepartingParkingAct = -1;

    for (int i = activityIndex; i < pe.size(); i++) {
      if (pe.get(i) instanceof ActivityImpl) {
        ActivityImpl parkingAct = (ActivityImpl) plan.getPlanElements().get(i);
        if (parkingAct.getType().equalsIgnoreCase("parking")) {
          indexOfDepartingParkingAct = i;
          break;
        }
      }
    }

    // if home parking
    if (indexOfDepartingParkingAct == -1) {
      for (int i = 0; i < pe.size(); i++) {
        if (pe.get(i) instanceof ActivityImpl) {
          ActivityImpl parkingAct = (ActivityImpl) plan.getPlanElements().get(i);
          if (parkingAct.getType().equalsIgnoreCase("parking")) {
            indexOfDepartingParkingAct = i;
            break;
          }
        }
      }
    }

    if (indexOfDepartingParkingAct == -1) {
      throw new Error("plan wrong: no parking in the whole plan");
    }

    return indexOfDepartingParkingAct;
  }
  @Override
  public boolean doReplanning(MobsimAgent withinDayAgent) {

    random.setSeed(
        Integer.parseInt(withinDayAgent.getId().toString()) * this.controler.getIterationNumber());

    Plan executedPlan = WithinDayAgentUtils.getModifiablePlan(withinDayAgent);

    // If we don't have an executed plan
    if (executedPlan == null) return false;

    PlanElement currentPlanElement = WithinDayAgentUtils.getCurrentPlanElement(withinDayAgent);
    if (!(currentPlanElement instanceof Leg)) return false;
    Leg currentLeg = (Leg) currentPlanElement;
    int currentLinkIndex = WithinDayAgentUtils.getCurrentRouteLinkIdIndex(withinDayAgent);

    // new Route for current Leg
    this.microRouteCurrentLegRoute(
        currentLeg,
        executedPlan.getPerson(),
        currentLinkIndex,
        this.time,
        scenario.getNetwork(),
        tripRouter,
        random,
        executedPlan);

    // Finally reset the cached Values of the PersonAgent - they may have changed!
    WithinDayAgentUtils.resetCaches(withinDayAgent);

    return true;
  }
  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");
  }
예제 #6
0
  @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);
  }
예제 #7
0
  @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 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();
 }
예제 #9
0
  @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);
  }
  private void updateWalkTimeTmpVariables(
      String legMod,
      Id personId,
      Plan executedPlan,
      int planElementIndex,
      double valueA,
      double valueB) {

    if (isPlanElementDuringDay(personId, planElementIndex)) {
      if (legMod.equals(TransportMode.walk)) {

        Activity previousAct = (Activity) executedPlan.getPlanElements().get(planElementIndex - 1);
        Leg previousLeg = (Leg) executedPlan.getPlanElements().get(planElementIndex - 2);

        if (previousAct.getType().equalsIgnoreCase("parking")
            && previousLeg.getMode().equals(TransportMode.car)) {
          firstParkingWalkTmp.put(personId, valueA);
        }

        Activity nextAct = (Activity) executedPlan.getPlanElements().get(planElementIndex + 1);
        Leg nextLeg = (Leg) executedPlan.getPlanElements().get(planElementIndex + 2);

        if (nextAct.getType().equalsIgnoreCase("parking")
            && nextLeg.getMode().equals(TransportMode.car)) {
          secondParkingWalkTmp.put(personId, valueB);
        }
      }
    }
  }
예제 #11
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"));
  }
  private void swap(Plan plan, Activity activity1, Activity activity2) {

    int index1 = plan.getPlanElements().indexOf(activity1);

    int index2 = plan.getPlanElements().indexOf(activity2);

    plan.getPlanElements().set(index1, activity2);
    plan.getPlanElements().set(index2, activity1);
  }
예제 #13
0
  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;
  }
예제 #14
0
  /**
   * reurns null, if no parking activity found else id of first parking facility
   *
   * @param plan
   * @return
   */
  public static Id<ActivityFacility> getFirstParkingFacilityId(Plan plan) {

    for (int i = 0; i < plan.getPlanElements().size(); i++) {
      if (plan.getPlanElements().get(i) instanceof ActivityImpl) {
        ActivityImpl activity = (ActivityImpl) plan.getPlanElements().get(i);

        if (activity.getType().equalsIgnoreCase("parking")) {
          return activity.getFacilityId();
        }
      }
    }

    return null;
  }
예제 #15
0
 @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());
       }
     }
   }
 }
예제 #16
0
 private Set<Id<Person>> filterPlans(Population plans) {
   PlanCollectFromAlgorithm collector = new PlanCollectFromAlgorithm();
   RouteLinkFilter linkFilter = new RouteLinkFilter(collector);
   for (String id : this.linkIds) {
     linkFilter.addLink(Id.create(id, Link.class));
   }
   SelectedPlanFilter selectedPlanFilter = new SelectedPlanFilter(linkFilter);
   selectedPlanFilter.run(plans);
   Set<Plan> planSet = collector.getPlans();
   Set<Id<Person>> idSet = new HashSet<>(planSet.size());
   for (Plan p : planSet) {
     idSet.add(p.getPerson().getId());
   }
   return idSet;
 }
예제 #17
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");
           }
         }
       }
     }
   }
 }
예제 #18
0
 private Activity firstActivity(final Person person, final String type) {
   final Plan plan = person.getSelectedPlan();
   if (plan == null) {
     return null;
   }
   for (PlanElement element : plan.getPlanElements()) {
     if (element instanceof Activity) {
       final Activity act = (Activity) element;
       if (act.getType() != null && act.getType().startsWith(type)) {
         return act;
       }
     }
   }
   return null;
 }
예제 #19
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;
          }
        }
      }
    }
  }
예제 #20
0
 @SuppressWarnings("deprecation")
 private void computeTravelStatistics(final Person person) {
   this.totalDist = 0.0;
   this.totalTime = 0.0;
   final Plan plan = person.getSelectedPlan();
   if (plan == null) {
     return;
   }
   for (PlanElement element : plan.getPlanElements()) {
     if (element instanceof Leg) {
       final Leg leg = (Leg) element;
       this.totalTime += leg.getTravelTime();
       this.totalDist += leg.getRoute().getDistance();
     }
   }
 }
예제 #21
0
    private void handlePlans(final GroupPlans plans) {
      final Map<Id<Person>, Plan> newJointPlan = new LinkedHashMap<Id<Person>, Plan>();
      final List<Plan> newIndividualPlans = new ArrayList<Plan>();

      for (JointPlan jp : plans.getJointPlans()) {
        newIndividualPlans.addAll(jp.getIndividualPlans().values());
      }

      for (Plan p : plans.getIndividualPlans()) {
        newJointPlan.put(p.getPerson().getId(), p);
      }

      plans.clear();
      plans.addJointPlan(factory.createJointPlan(newJointPlan));
      plans.addIndividualPlans(newIndividualPlans);
    }
 private static Trip getTripWithLeg(
     final Plan plan, final Leg leg, final StageActivityTypes stages) {
   for (Trip t : TripStructureUtils.getTrips(plan, stages)) {
     if (t.getTripElements().contains(leg)) return t;
   }
   throw new RuntimeException(plan.getPlanElements() + " doesn't contain " + leg);
 }
예제 #23
0
  public static ActivityImpl getDepartureParkingAct(Plan plan, ActivityImpl activity) {
    List<PlanElement> pe = plan.getPlanElements();
    int indexOfDepartingParkingAct = getDepartureParkingActIndex(plan, activity);

    ActivityImpl departureParkingAct = (ActivityImpl) pe.get(indexOfDepartingParkingAct);
    return departureParkingAct;
  }
예제 #24
0
  /**
   * Get the arrival parking responding to this activity.
   *
   * @return
   */
  public static ActivityImpl getArrivalParkingAct(Plan plan, ActivityImpl activity) {
    List<PlanElement> pe = plan.getPlanElements();
    int indexOfArrivalParkingAct = getArrivalParkingActIndex(plan, activity);

    ActivityImpl arrivalParkingAct = (ActivityImpl) pe.get(indexOfArrivalParkingAct);
    return arrivalParkingAct;
  }
예제 #25
0
  @Override
  public void run(Plan plan) {
    PlanImpl copyPlan = new PlanImpl(person);

    for (PlanElement pe : plan.getPlanElements()) {

      if (pe instanceof Activity) {
        copyPlan.addActivity((ActivityImpl) pe);

      } else if (pe instanceof Leg) {
        LegImpl leg = (LegImpl) pe;

        LegImpl ptLeg = new LegImpl(leg);
        ptLeg.setMode(TransportMode.pt);
        ptLeg.setRoute(null);
        // -----------------------------------------------
        // WITHOUT routeSetting!! traveltime of PT can be
        // calculated automaticly!!
        // -----------------------------------------------
        copyPlan.addLeg(ptLeg);

        // Leg walkLeg = new org.matsim.core.population.LegImpl(leg);
        // walkLeg.setMode(TransportMode.walk);
        // walkLeg.setRoute(null);
        // walkPlan.addLeg(walkLeg);

        if (!leg.getMode().equals(TransportMode.car)) {
          leg.setRoute(null);
          leg.setMode(TransportMode.car);
        }
      }
    }
    copyPlans.add(copyPlan);
    // copyPlans.add(walkPlan);
  }
예제 #26
0
  public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    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[0]);

    final BufferedWriter outLinkrb = IOUtils.getBufferedWriter(args[2]);
    final BufferedWriter outLinkff = IOUtils.getBufferedWriter(args[3]);

    for (Person p : scenario.getPopulation().getPersons().values()) {
      boolean rb = false;
      boolean ff = false;
      Person pImpl = p;
      Plan plan = p.getSelectedPlan();

      for (PlanElement pe : plan.getPlanElements()) {

        if (pe instanceof Leg) {

          if (((Leg) pe).getMode().equals("cs_fix_gas") && !rb) {
            outLinkrb.write(p.getId().toString() + " ");
            outLinkrb.write(Integer.toString(PersonUtils.getAge(pImpl)) + " ");
            outLinkrb.write(PersonUtils.getSex(pImpl) + " ");
            outLinkrb.write(PersonUtils.getCarAvail(pImpl));
            outLinkrb.newLine();
            rb = true;

          } else if (((Leg) pe).getMode().equals("cs_flex_gas") && !ff) {
            outLinkff.write(p.getId().toString() + " ");
            outLinkff.write(Integer.toString(PersonUtils.getAge(pImpl)) + " ");
            outLinkff.write(PersonUtils.getSex(pImpl) + " ");
            outLinkff.write(PersonUtils.getCarAvail(pImpl));
            outLinkff.newLine();
            ff = true;
          }
        }
      }
    }
    outLinkrb.flush();
    outLinkrb.close();
    outLinkff.flush();
    outLinkff.close();
  }
예제 #27
0
 void createAgentGroupNearTransitstrops(
     Scenario scenario, double distance, String transitScheduleFile) {
   new TransitScheduleReader(scenario).readFile(transitScheduleFile);
   for (Person p : scenario.getPopulation().getPersons().values()) {
     if (scenario
             .getPopulation()
             .getPersonAttributes()
             .getAttribute(p.getId().toString(), "subpopulation")
         != null) {
       return;
     }
     ArrayList<Boolean> isIt = new ArrayList<>();
     for (Plan plan : p.getPlans()) {
       for (PlanElement pe : plan.getPlanElements()) {
         if (pe instanceof Activity) {
           boolean setAct = false;
           Coord ac = ((Activity) pe).getCoord();
           for (TransitStopFacility stop :
               scenario.getTransitSchedule().getFacilities().values()) {
             double dist = CoordUtils.calcDistance(stop.getCoord(), ac);
             if (dist <= distance) {
               setAct = true;
               break;
             }
           }
           isIt.add(setAct);
         }
       }
     }
     boolean truth = true;
     for (Boolean t : isIt) {
       if (!t) truth = false;
     }
     if (truth) {
       scenario
           .getPopulation()
           .getPersonAttributes()
           .putAttribute(p.getId().toString(), "subpopulation", "schedulePt");
     } else {
       scenario
           .getPopulation()
           .getPersonAttributes()
           .putAttribute(p.getId().toString(), "subpopulation", "teleportPt");
       this.teleportPtUsers.add(p.getId());
     }
   }
 }
예제 #28
0
    @Override
    public void run(Person person) {

      Plan selectedPlan = person.getSelectedPlan();

      ArrayList<String> modeChain = new ArrayList<String>();
      for (PlanElement pe : selectedPlan.getPlanElements()) {
        if (pe instanceof Leg) {
          Leg leg = (Leg) pe;
          modeChain.add(leg.getMode());
        }
      }
      String[] candidate = new String[modeChain.size()];
      candidate = modeChain.toArray(candidate);

      MeisterkConfigGroup meisterkConfigGroup = new MeisterkConfigGroup();

      boolean isFeasible =
          PlanAnalyzeTourModeChoiceSet.isModeChainFeasible(
              selectedPlan,
              candidate,
              meisterkConfigGroup.getChainBasedModes(),
              PlanomatConfigGroup.TripStructureAnalysisLayerOption.facility,
              this.facilities,
              this.network);

      if (!isFeasible) {

        logger.info("Agent id: " + person.getId());

        for (PlanElement pe : selectedPlan.getPlanElements()) {

          if (pe instanceof Activity) {
            Activity act = (Activity) pe;
            logger.info("\t" + act.getFacilityId());
          }

          if (pe instanceof Leg) {
            Leg leg = (Leg) pe;
            modeChain.add(leg.getMode());
            logger.info("\t" + leg.getMode());
          }
        }
        this.numInfeasiblePlans++;
      }
    }
  @Override
  public void run(Plan plan) {

    List<Trip> t = TripStructureUtils.getTrips(plan, stageActivityTypes);
    boolean ffcard = false;
    boolean owcard = false;
    int cnt = t.size();
    Person p = plan.getPerson();
    if (cnt == 0) {
      return;
    }
    int rndIdx = this.rng.nextInt(cnt);

    for (Leg l : t.get(rndIdx).getLegsOnly())
      if (l.getMode().equals("car")
          || l.getMode().equals("bike")
          || l.getMode().equals("twowaycarsharing")) return;

    if (Boolean.parseBoolean(
        ((String)
            this.scenario
                .getPopulation()
                .getPersonAttributes()
                .getAttribute(plan.getPerson().getId().toString(), "FF_CARD")))) ffcard = true;
    if (Boolean.parseBoolean(
        ((String)
            this.scenario
                .getPopulation()
                .getPersonAttributes()
                .getAttribute(plan.getPerson().getId().toString(), "OW_CARD")))) owcard = true;
    double centerX = 683217.0;
    double centerY = 247300.0;
    Coord coord = new Coord(centerX, centerY);
    if (CoordUtils.calcDistance(t.get(rndIdx).getOriginActivity().getCoord(), coord) < 10500
        && CoordUtils.calcDistance(t.get(rndIdx).getDestinationActivity().getCoord(), coord)
            < 10500) {
      // don't change the trips between the same links
      if (!t.get(rndIdx)
          .getOriginActivity()
          .getLinkId()
          .toString()
          .equals(t.get(rndIdx).getDestinationActivity().getLinkId().toString()))
        setRandomTripMode(t.get(rndIdx), plan, ffcard, owcard);
      else return;
    } else return;
  }
예제 #30
0
  private String enrichPlanBySingleLegAndActivity(
      Coord lastActivityCoord, Plan plan, String oldmode, int maxDur, boolean canChangeMode) {
    String mode = oldmode;
    Coord nextDestination;
    String nextActivity;
    double duration;
    double r = random.nextDouble();
    if (r < 0.25) {
      nextActivity = "private";
      nextDestination = findClosestCoordFromMapRandomized(lastActivityCoord, residential, 20);
      duration = 600 + random.nextInt(maxDur);
    } else if (r < 0.5) {
      nextActivity = "leisure";
      nextDestination = findClosestCoordFromMapRandomized(lastActivityCoord, schools, 5);
      duration = 600 + random.nextInt(maxDur);

    } else {
      nextActivity = "shopping";
      nextDestination = findClosestCoordFromMapRandomized(lastActivityCoord, retail, 10);
      duration = 600 + random.nextInt(maxDur);
    }
    Activity next =
        scenario
            .getPopulation()
            .getFactory()
            .createActivityFromCoord(nextActivity, nextDestination);
    next.setMaximumDuration(duration);
    double distance = CoordUtils.calcDistance(nextDestination, lastActivityCoord);
    if (canChangeMode) {
      if (distance < 500) {
        mode = "walk";

      } else if (distance < 3000) {
        if (random.nextBoolean()) mode = "car";
        else if (random.nextBoolean()) mode = "bike";
        else mode = "pt";
      } else {
        if (random.nextBoolean()) mode = "car";
        else mode = "pt";
      }
    }
    plan.addLeg(scenario.getPopulation().getFactory().createLeg(mode));
    plan.addActivity(next);
    return mode;
  }