Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a comment; make handleDeparture and handleActivity such that they… #3530

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions matsim/src/main/java/org/matsim/core/mobsim/qsim/QSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,35 @@ private void arrangeNextAgentAction(final MobsimAgent agent) {
}

private void arrangeAgentActivity(final MobsimAgent agent) {
ActivityHandler responsible = null;
ActivityEngine activityEngine = null;
for (ActivityHandler activityHandler : this.activityHandlers) {
if (activityHandler.handleActivity(agent)) {
return;
if ( activityHandler instanceof ActivityEngine ) {
// seems that only exactly one activity engine is allowed. We use that as a fallback.
activityEngine = (ActivityEngine) activityHandler;
} else if ( activityHandler.handleActivity(agent) ) {
// if we are here, then the activity was already handled.
if ( responsible==null ){
responsible = activityHandler;
} else {
// in this case, the activity was handled twice.
StringBuilder strb = new StringBuilder();
strb.append( "more than one activity handler feels reponsible for agent=" ).append( agent );
strb.append( ". activityHandler1=" ).append( responsible ).append( "; activityHandler2=" ).append( activityHandler );
log.fatal( strb.toString() );
throw new RuntimeException( strb.toString() );
}
}
}
if ( responsible==null && activityEngine!=null ) {
// only if the activity has not been handled yet we call the activity engine.
activityEngine.handleActivity( agent );
} else {
StringBuilder strb = new StringBuilder();
strb.append( "There is no ActivityHandler that wants to handle the agent, and also no ActivityEngine." );
log.fatal( strb.toString() );
throw new RuntimeException( strb.toString() );
}
}

/**
Expand All @@ -506,13 +530,24 @@ private void arrangeAgentDeparture(final MobsimAgent agent) {

events.processEvent(new PersonDepartureEvent(now, agent.getId(), linkId, agent.getMode(), routingMode));

DepartureHandler responsible = null;
for (DepartureHandler departureHandler : this.departureHandlers) {
if (departureHandler.handleDeparture(now, agent, linkId)) {
return;
if (departureHandler.handleDeparture(now, agent, linkId) ) {
if ( responsible==null ){
responsible = departureHandler;
} else {
StringBuilder strb = new StringBuilder();
strb.append( "More than one departure handler feels responsible for agent=" ).append( agent ).append( "; dpHandler1=" )
.append( responsible ).append( "; dpHandler2=" ).append( departureHandler );
log.fatal( strb.toString() );
throw new RuntimeException( strb.toString() );
}
}
}
log.warn("no departure handler wanted to handle the departure of agent " + agent.getId());
// yy my intuition is that this should be followed by setting the agent state to abort. kai, nov'14
if ( responsible==null ){
log.warn( "no departure handler wanted to handle the departure of agent " + agent.getId() );
// yy my intuition is that this should be followed by setting the agent state to abort. kai, nov'14
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
package org.matsim.core.mobsim.qsim.interfaces;

import org.matsim.core.mobsim.framework.MobsimAgent;
import org.matsim.core.mobsim.qsim.QSimProvider;
import org.matsim.core.mobsim.qsim.components.QSimComponent;

/**
* {@link QSimComponent}s of type {@link ActivityHandler} are added into a specific registry in {@link QSimProvider#get()}. This registry is later used in {@link org.matsim.core.mobsim.qsim.QSim#arrangeAgentActivity(MobsimAgent)} (not public, therefore cannot be referenced from javadoc).
*/
public interface ActivityHandler extends QSimComponent {

boolean handleActivity(MobsimAgent agent);
Expand Down
Loading