@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;
  }
Ejemplo n.º 2
0
    @Override
    public void notifyMobsimBeforeSimStep(final MobsimBeforeSimStepEvent e) {
      if (e.getSimulationTime() == t1) {
        assertEquals(
            100,
            this.arp
                .getActivityPerformingAgents()
                .size()); // all agents perform an activity before the time step
        assertEquals(
            1,
            this.arp
                .getActivityEndingAgents(e.getSimulationTime())
                .size()); // one agent ends an activity
      }

      if (e.getSimulationTime() == t2) {
        assertEquals(
            99,
            this.arp
                .getActivityPerformingAgents()
                .size()); // 99 agents perform an activity before the time step
        assertEquals(
            1,
            this.arp
                .getActivityEndingAgents(e.getSimulationTime())
                .size()); // one agent ends an activity
      }

      if (e.getSimulationTime() == t3) {
        assertEquals(
            98,
            this.arp
                .getActivityPerformingAgents()
                .size()); // 98 agents perform an activity before the time step
        assertEquals(
            1,
            this.arp
                .getActivityEndingAgents(e.getSimulationTime())
                .size()); // one agent ends an activity
      }

      if (e.getSimulationTime() == t4) {
        assertEquals(
            97,
            this.arp
                .getActivityPerformingAgents()
                .size()); // 97 agents perform an activity before the time step
        assertEquals(
            97,
            this.arp
                .getActivityEndingAgents(e.getSimulationTime())
                .size()); // 97 agents end an activity

        // now reschedule the activity end time of an agent
        MobsimAgent agent = this.agents.get(Id.create("40", Person.class));
        Activity currentActivity = (Activity) WithinDayAgentUtils.getCurrentPlanElement(agent);
        currentActivity.setEndTime(e.getSimulationTime() + 60);
        WithinDayAgentUtils.resetCaches(agent);
        this.withinDayEngine.getActivityRescheduler().rescheduleActivityEnd(agent);
        ((QSim) e.getQueueSimulation())
            .getEventsManager()
            .processEvent(
                new ReplanningEvent(e.getSimulationTime(), agent.getId(), "ActivityRescheduler"));

        // reschedule a second time to check what happens if the agent is replanned multiple times
        // in one time step
        currentActivity.setEndTime(e.getSimulationTime() + 120);
        WithinDayAgentUtils.resetCaches(agent);
        this.withinDayEngine.getActivityRescheduler().rescheduleActivityEnd(agent);
        ((QSim) e.getQueueSimulation())
            .getEventsManager()
            .processEvent(
                new ReplanningEvent(e.getSimulationTime(), agent.getId(), "ActivityRescheduler"));
      }

      if (e.getSimulationTime() == t5) {
        assertEquals(
            1,
            this.arp
                .getActivityPerformingAgents()
                .size()); // one agent performs an activity before the time step
        assertEquals(
            0,
            this.arp
                .getActivityEndingAgents(e.getSimulationTime())
                .size()); // no agent ends an activity
      }

      if (e.getSimulationTime() == t6) {
        assertEquals(
            1,
            this.arp
                .getActivityPerformingAgents()
                .size()); // one agent performs an activity before the time step
        assertEquals(
            1,
            this.arp
                .getActivityEndingAgents(e.getSimulationTime())
                .size()); // one agent ends an activity
      }
    }