Skip to content

faq 118390785

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

When to use AgentSource?

by Kai Nagel on 2017-10-30 07:10:34


The code example RunAgentSourceExample in matsim-code-examples says

@Override public Mobsim get() {
     final QSim qsim = QSimUtils.createDefaultQSim( scenario, events );
     qsim.addAgentSource(new AgentSource() {
 							@Override
 							public void insertAgentsIntoMobsim() {
 								// insert traveler agent:
 								final MobsimAgent ag = new MyMobsimAgent(qsim.getScenario(), qsim.getSimTimer());
 								qsim.insertAgentIntoMobsim(ag);

 								// insert vehicle:
 								final Vehicle vehicle = VehicleUtils.getFactory().createVehicle(Id.create(ag.getId(), Vehicle.class), VehicleUtils.getDefaultVehicleType());
 								final Id<Link> linkId4VehicleInsertion = Id.createLinkId(1);
 								qsim.createAndParkVehicleOnLink(vehicle, linkId4VehicleInsertion);
 							}
     });
     return qsim;
 }

However, most people seem to be inserting the agents directly:

@Override public Mobsim get() {
 						final QSim qsim = QSimUtils.createDefaultQSim( scenario, events );
	
 								// insert traveler agent:
 								final MobsimAgent ag = new MyMobsimAgent(qsim.getScenario(), qsim.getSimTimer());
 								qsim.insertAgentIntoMobsim(ag);

 								// insert vehicle:
 								final Vehicle vehicle = VehicleUtils.getFactory().createVehicle(Id.create(ag.getId(), Vehicle.class), VehicleUtils.getDefaultVehicleType());
 								final Id<Link> linkId4VehicleInsertion = Id.createLinkId(1);
 								qsim.createAndParkVehicleOnLink(vehicle, linkId4VehicleInsertion);
 						return qsim;
 }

When is the more complicated first version necessary, and why?


Comments: 0

Clone this wiki locally