agentsoz / bdi-abm-integration

BDI ABM Integration
GNU Lesser General Public License v3.0
8 stars 13 forks source link

Getting the total distance of a trip from Matsim #81

Closed oemer95 closed 8 months ago

oemer95 commented 8 months ago

Hi there, I want to get some additional information from Matsim using the Event Listeners provided in the integration bdi-matsim, where events like PersonArrivalEvent are handled in the classes EventsMonitorRegistry and ActionHandlerForPerceive. Especially, I want the total distance of a trip (containing all legs driven on from a start to an end position).

What I did so far:

Working with the ees repository, I found out that ees/matsim/EvacAgent.java contains the method notifyMoveOverNode, which processes the legs in the Matsim network. In that method, I added a total counter as follows:

public final void notifyMoveOverNode(Id<Link> newLinkId) {
    driverAgentDelegate.notifyMoveOverNode(newLinkId);
    Link link = network.getLinks().get(newLinkId);
    double now = simTimer.getTimeOfDay();
    //added 
    if(link != null){
        totalLinkLengthTraveled += link.getLength();
    }
    this.expectedLinkLeaveTime = link.getLength()/link.getFreespeed(now);
}

Now I want to extend the Matsim Event PersonArrivalEvent which occurs, when a trip is finished. I want to add totalLinkLengthTraveled to the Event by extending PersonArrivalEvent. Then I want to add params in ActionHandlerForPerceive in the block PerceptList.ARRIVED to Object[] params = {currentLinkId, totalLinkLengthTraveled}:


case PerceptList.ARRIVED:
                (...)
        if (model.getAgentManager().getAgentsPerformingBdiDriveTo().containsKey(agentID)
        && model.getAgentManager().getAgentsPerformingBdiDriveTo().get(agentID).equals(currentLinkId)) {
            model.getAgentManager().getAgentsPerformingBdiDriveTo().remove(agentID);
            Object[] params = {currentLinkId};
            ActionContent ac = new ActionContent(params, ActionContent.State.PASSED, ActionList.DRIVETO);
            model.getAgentManager().getAgentDataContainerV2().putAction(agent.getAgentID(), ActionList.DRIVETO, ac);
        }
            return false; // do not unregister
        }
    }
);
break;

Is this the right solution or are there other possibilities to get the total distance driven of a single trip?