@Override
    public void notifyMobsimInitialized(final MobsimInitializedEvent e) {
      assertEquals(
          100, this.arp.getActivityPerformingAgents().size()); // all agents perform an activity
      assertEquals(0, this.arp.getActivityEndingAgents(0.0).size()); // no agent ends an activity

      QSim sim = (QSim) e.getQueueSimulation();
      for (MobsimAgent agent : sim.getAgents()) this.agents.put(agent.getId(), agent);
    }
  @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;
  }
Example #3
0
 public static final void resetCaches(MobsimAgent agent) {
   if (agent instanceof PersonDriverAgentImpl) {
     ((PersonDriverAgentImpl) agent).resetCaches();
   } else {
     throw new RuntimeException(
         "Sorry, agent is from type "
             + agent.getClass().toString()
             + " which does not support resetCaches(...). Aborting!");
   }
 }
Example #4
0
 public static final Integer getCurrentRouteLinkIdIndex(MobsimAgent agent) {
   if (agent instanceof PersonDriverAgentImpl) {
     return ((PersonDriverAgentImpl) agent).getCurrentLinkIndex();
   } else {
     throw new RuntimeException(
         "Sorry, agent is from type "
             + agent.getClass().toString()
             + " which does not support getCurrentRouteLinkIdIndex(...). Aborting!");
   }
 }
Example #5
0
 public static final PlanElement getCurrentPlanElement(MobsimAgent agent) {
   if (agent instanceof PersonDriverAgentImpl) {
     return getModifiablePlan(agent).getPlanElements().get(getCurrentPlanElementIndex(agent));
   } else {
     throw new RuntimeException(
         "Sorry, agent is from type "
             + agent.getClass().toString()
             + " which does not support getCurrentPlanElement(...). Aborting!");
   }
 }
Example #6
0
 public static final Leg getModifiableCurrentLeg(MobsimAgent agent) {
   if (agent instanceof PersonDriverAgentImpl) {
     PlanElement currentPlanElement = getCurrentPlanElement(agent);
     if (!(currentPlanElement instanceof Leg)) {
       return null;
     }
     return (Leg) currentPlanElement;
   } else {
     throw new RuntimeException(
         "Sorry, agent is from type "
             + agent.getClass().toString()
             + " which does not support getCurrentLeg(...). Aborting!");
   }
 }
Example #7
0
  private void moveVehicleFromInlinkToAbort(
      final QVehicle veh, final QInternalI fromLane, final double now) {
    fromLane.popFirstVehicle();

    // first treat the passengers:
    for (PassengerAgent pp : veh.getPassengers()) {
      if (pp instanceof MobsimAgent) {
        ((MobsimAgent) pp).setStateToAbort(now);
        network.simEngine.internalInterface.arrangeNextAgentState((MobsimAgent) pp);
      } else if (wrnCnt < 1) {
        wrnCnt++;
        log.warn(
            "encountering PassengerAgent that cannot be cast into a MobsimAgent; cannot say if this is a problem");
        log.warn(Gbl.ONLYONCE);
      }
    }

    // now treat the driver:
    veh.getDriver().setStateToAbort(now);
    network.simEngine.internalInterface.arrangeNextAgentState(veh.getDriver());
  }
    @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
      }
    }