diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/SimulationStepListener.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/SimulationStepListener.java index e6208c565..2973e3a6a 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/SimulationStepListener.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/SimulationStepListener.java @@ -3,7 +3,6 @@ */ package cz.cuni.mff.d3s.deeco.simulation; -import cz.cuni.mff.d3s.deeco.simulation.task.SimulationStepTask; /** * Listener interface for time events triggered by a simulation. @@ -19,5 +18,5 @@ public interface SimulationStepListener { * @param time * current simulation time */ - void at(long time, SimulationStepTask task); + void at(long time, Object trigerO); } diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/DefaultMATSimExtractor.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/DefaultMATSimExtractor.java new file mode 100644 index 000000000..6f38f5bff --- /dev/null +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/DefaultMATSimExtractor.java @@ -0,0 +1,25 @@ +package cz.cuni.mff.d3s.deeco.simulation.matsim; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.matsim.api.core.v01.Id; +import org.matsim.core.mobsim.framework.Mobsim; + +public class DefaultMATSimExtractor implements MATSimExtractor { + + @Override + public Object extractFromMATSim(Collection agents, + Mobsim mobsim) { + Map map = new HashMap(); + MATSimOutput matSimOutput; + for (JDEECoAgent agent : agents) { + matSimOutput = new MATSimOutput(agent.getCurrentLinkId(), + agent.getState()); + map.put(agent.getId(), matSimOutput); + } + return map; + } + +} diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/DefaultMATSimUpdater.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/DefaultMATSimUpdater.java new file mode 100644 index 000000000..5ca926817 --- /dev/null +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/DefaultMATSimUpdater.java @@ -0,0 +1,21 @@ +package cz.cuni.mff.d3s.deeco.simulation.matsim; + +import java.util.Collection; +import java.util.Map; + +public class DefaultMATSimUpdater implements MATSimUpdater { + + @SuppressWarnings("unchecked") + @Override + public void updateJDEECoAgents(Object input, Collection agents) { + if (input != null && input instanceof Map) { + Map map = (Map) input; + for (JDEECoAgent agent: agents) { + if (map.containsKey(agent.getId())) { + agent.setRoute(((MATSimInput) map.get(agent.getId())).route); + } + } + } + } + +} diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoAgent.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoAgent.java index fdc08ada0..fa5ddceb1 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoAgent.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoAgent.java @@ -2,17 +2,13 @@ import java.util.List; -import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.network.Link; import org.matsim.core.api.experimental.events.AgentArrivalEvent; import org.matsim.core.basic.v01.IdImpl; import org.matsim.core.mobsim.framework.MobsimDriverAgent; import org.matsim.core.mobsim.qsim.interfaces.MobsimVehicle; import org.matsim.core.mobsim.qsim.interfaces.Netsim; -import org.matsim.core.mobsim.qsim.qnetsimengine.QVehicle; -import org.matsim.core.utils.geometry.CoordImpl; /** * JDEECo agent implementation. The agent is used by the @@ -98,7 +94,25 @@ public void notifyArrivalOnLinkByNonNetworkMode(Id linkId) { } public void setRoute(List route) { - this.route = route; + int index = route.indexOf(currentLinkId); + if (index < 0) { + this.route = route; + } else { + boolean isPartOf = true; + int nextIndex; + for (Id lId: this.route) { + nextIndex = route.indexOf(lId); + if (index + 1 == nextIndex) { + index = nextIndex; + } else { + isPartOf = false; + break; + } + } + if (!isPartOf) { + this.route = route; + } + } } public Id getCurrentLinkId() { @@ -122,7 +136,16 @@ public Id chooseNextLinkId() { if (route == null || route.isEmpty()) { return null; } else { - return route.remove(0); + Id result = route.remove(0); + if (result.equals(currentLinkId)) { + if (route.isEmpty()) { + return null; + } else { + return route.remove(0); + } + } else { + return result; + } } } @@ -138,39 +161,6 @@ public MobsimVehicle getVehicle() { return this.vehicle; } - // This method should not be used because in case of traffic jam, it gives completely off results. It acts if the road was empty and - // then waits minutes at the end of the link - @Deprecated - public Coord estimatePosition(double now) { - if (state.equals(State.ACTIVITY) && currentLinkId != null) { - return simulation.getScenario().getNetwork().getLinks() - .get(currentLinkId).getToNode().getCoord(); - } - if (vehicle != null) { - QVehicle qVehicle = (QVehicle) vehicle; - Link link = qVehicle.getCurrentLink(); - double time = qVehicle.getEarliestLinkExitTime() - now; - if (time <= 0) { - return qVehicle.getCurrentLink().getToNode().getCoord(); - } - - // XXX: Since the time is used, it's not necessary to use the velocity, as the velocity is constant!!! This is an overkill! - double velocity = (link.getFreespeed() > qVehicle - .getMaximumVelocity()) ? qVehicle.getMaximumVelocity() - : link.getFreespeed(); - double remainingDistance = velocity * time; - double distanceDriven = link.getLength() - remainingDistance; - Coord from = link.getFromNode().getCoord(); - Coord to = link.getToNode().getCoord(); - double estX = ((distanceDriven * (to.getX() - from.getX())) / link - .getLength()) + from.getX(); - double estY = ((distanceDriven * (to.getY() - from.getY())) / link - .getLength()) + from.getY(); - return new CoordImpl(estX, estY); - } - return null; - } - public void notifyMoveOverNode(Id newLinkId) { this.currentLinkId = newLinkId; } diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoWithinDayMobsimListener.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoWithinDayMobsimListener.java index 76c7565ef..ee926c0f7 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoWithinDayMobsimListener.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/JDEECoWithinDayMobsimListener.java @@ -1,12 +1,10 @@ package cz.cuni.mff.d3s.deeco.simulation.matsim; -import java.util.HashMap; +import java.util.Collection; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.concurrent.Exchanger; -import org.matsim.api.core.v01.Id; import org.matsim.core.mobsim.framework.events.MobsimBeforeSimStepEvent; import org.matsim.core.mobsim.framework.listeners.MobsimBeforeSimStepListener; @@ -26,22 +24,26 @@ public class JDEECoWithinDayMobsimListener implements MobsimBeforeSimStepListener { - private final Exchanger> exchanger; + private final Exchanger exchanger; private final List agentProviders; private final SimulationStepListener stepListener; + private final MATSimUpdater updater; + private final MATSimExtractor extractor; - protected JDEECoWithinDayMobsimListener(Exchanger> exchanger, SimulationStepListener stepListener) { + protected JDEECoWithinDayMobsimListener(Exchanger exchanger, SimulationStepListener stepListener, MATSimUpdater updater, MATSimExtractor extractor) { this.exchanger = exchanger; this.agentProviders = new LinkedList(); this.stepListener = stepListener; + this.updater = updater; + this.extractor = extractor; } - public JDEECoWithinDayMobsimListener(Exchanger> exchanger) { - this(exchanger, null); + public JDEECoWithinDayMobsimListener(Exchanger exchanger, MATSimUpdater updater, MATSimExtractor extractor) { + this(exchanger, null, updater, extractor); } - public JDEECoWithinDayMobsimListener(SimulationStepListener stepListener) { - this(null, stepListener); + public JDEECoWithinDayMobsimListener(SimulationStepListener stepListener, MATSimUpdater updater, MATSimExtractor extractor) { + this(null, stepListener, updater, extractor); } public void registerAgentProvider(JDEECoAgentProvider agentProvider) { @@ -49,55 +51,30 @@ public void registerAgentProvider(JDEECoAgentProvider agentProvider) { agentProviders.add(agentProvider); } } - - public Map getOutputs(double currentSeconds) { - Map matSimOutputs = new HashMap(); - - // Get agents current positions and jDEECoAgents - MATSimOutput matSimOutput; - for (JDEECoAgentProvider agentProvider : agentProviders) { - for (JDEECoAgent agent : agentProvider.getAgents()) { - matSimOutput = new MATSimOutput(agent.getCurrentLinkId(), - agent.estimatePosition(currentSeconds), agent.getState()); - matSimOutputs.put(agent.getId(), matSimOutput); - } - } - return matSimOutputs; + + public void updateJDEECoAgents(Object input) { + updater.updateJDEECoAgents(input, getAllJDEECoAgents()); } - public void setInputs(Map matSimInputs) { - if (matSimInputs != null && !matSimInputs.isEmpty()) { - MATSimInput mData; - for (JDEECoAgentProvider agentProvider : agentProviders) { - for (JDEECoAgent agent : agentProvider.getAgents()) { - if (matSimInputs.containsKey(agent.getId())) { - mData = (MATSimInput) matSimInputs.get(agent.getId()); - agent.setRoute(mData.route); - } - } - } + public Collection getAllJDEECoAgents() { + List agents = new LinkedList<>(); + for (JDEECoAgentProvider agentProvider : agentProviders) { + agents.addAll(agentProvider.getAgents()); } + return agents; } @SuppressWarnings("rawtypes") public void notifyMobsimBeforeSimStep(MobsimBeforeSimStepEvent event) { if (exchanger != null) { try { - Map matSimOutputs = getOutputs(event - .getSimulationTime()); - // Exchange data (Rendezvous) - Map matSimInputs = exchanger.exchange(matSimOutputs); - // Log.w("MATSim After data exchange at " + - // event.getSimulationTime() + " " + remainingExchanges ); - - // Update jDEECo agents next link id - setInputs(matSimInputs); + updateJDEECoAgents(exchanger.exchange(extractor.extractFromMATSim(getAllJDEECoAgents(), event.getQueueSimulation()))); } catch (Exception e) { Log.e("jDEECoWithinDayMobsimListener: ", e); } } if (stepListener != null) { - stepListener.at(Math.round(event.getSimulationTime()), null); + stepListener.at(Math.round(event.getSimulationTime()), event.getQueueSimulation()); } } diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimDataReceiver.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimDataReceiver.java index c7af6588c..c8485854e 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimDataReceiver.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimDataReceiver.java @@ -1,8 +1,5 @@ package cz.cuni.mff.d3s.deeco.simulation.matsim; -import java.util.Map; - -import org.matsim.api.core.v01.Id; /** * Interface for MATSim data retrieval. This data comes from MATSim side. @@ -11,5 +8,5 @@ * */ public interface MATSimDataReceiver { - public void setMATSimData(Map data); + public void setMATSimData(Object data); } diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimExtractor.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimExtractor.java new file mode 100644 index 000000000..ab6a9828d --- /dev/null +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimExtractor.java @@ -0,0 +1,9 @@ +package cz.cuni.mff.d3s.deeco.simulation.matsim; + +import java.util.Collection; + +import org.matsim.core.mobsim.framework.Mobsim; + +public interface MATSimExtractor { + public Object extractFromMATSim(Collection agents, Mobsim mobsim); +} diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimInput.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimInput.java index 8de54e185..647bfad77 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimInput.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimInput.java @@ -16,7 +16,11 @@ public class MATSimInput { public MATSimInput clone() { MATSimInput result = new MATSimInput(); - result.route = new LinkedList(route); + if (route == null) { + result.route = null; + } else { + result.route = new LinkedList(route); + } return result; } } diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOMNetSimulation.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOMNetSimulation.java index 46675ede8..fe32dce70 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOMNetSimulation.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOMNetSimulation.java @@ -2,11 +2,9 @@ import java.util.Collection; import java.util.HashSet; -import java.util.Map; import java.util.Set; import java.util.concurrent.Exchanger; -import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.TransportMode; import org.matsim.core.controler.events.StartupEvent; import org.matsim.core.controler.listener.StartupListener; @@ -30,7 +28,7 @@ public class MATSimOMNetSimulation extends OMNetSimulation implements SimulationStepListener, MATSimTimeProvider { private static final int MILLIS_IN_SECOND = 1000; - private final Exchanger> exchanger; + private final Exchanger exchanger; private final MATSimDataProvider matSimProvider; private final MATSimDataReceiver matSimReceiver; private final MATSimPreloadingControler controler; @@ -44,7 +42,7 @@ public class MATSimOMNetSimulation extends OMNetSimulation implements public MATSimOMNetSimulation(NetworkProvider np, MATSimDataReceiver matSimReceiver, - MATSimDataProvider matSimProvider, + MATSimDataProvider matSimProvider, MATSimUpdater updater, MATSimExtractor extractor, final Collection agentSources, String matSimConf) { super(np); @@ -64,8 +62,8 @@ public MATSimOMNetSimulation(NetworkProvider np, + " matsimEndTime: " + end); this.remainingExchanges = Math.round((end - start) / step) + 1; - this.exchanger = new Exchanger>(); - this.listener = new JDEECoWithinDayMobsimListener(exchanger); + this.exchanger = new Exchanger(); + this.listener = new JDEECoWithinDayMobsimListener(exchanger, updater, extractor); this.matSimProvider = matSimProvider; this.matSimReceiver = matSimReceiver; @@ -103,10 +101,10 @@ public void notifyStartup(StartupEvent event) { } public MATSimOMNetSimulation(MATSimDataReceiver matSimReceiver, - MATSimDataProvider matSimProvider, + MATSimDataProvider matSimProvider, MATSimUpdater updater, MATSimExtractor extractor, final Collection agentSources, String matSimConf) { - this(null, matSimReceiver, matSimProvider, agentSources, matSimConf); + this(null, matSimReceiver, matSimProvider, updater, extractor, agentSources, matSimConf); } public double getDuration() { @@ -117,7 +115,7 @@ public double getDuration() { return end - start; } - public void at(long time, SimulationStepTask task) { + public void at(long time, Object triger) { try { if (matSimThread == null) { matSimThread = new Thread(new Runnable() { @@ -131,13 +129,10 @@ public void run() { matSimThread.start(); } if (matSimThread.isAlive() && this.remainingExchanges > 0) { - // long currentTime = getCurrentTime(); - // long matsimTime = getMATSimTime(); - matSimReceiver.setMATSimData((Map)exchanger.exchange(matSimProvider + matSimReceiver.setMATSimData(exchanger.exchange(matSimProvider .getMATSimData())); this.remainingExchanges--; - // Log.w("jDEECo After data exchange at " + currentTime - // + " MATSim time: " + matsimTime + " " + remainingExchanges); + SimulationStepTask task = (SimulationStepTask) triger; task.scheduleNextExecutionAfter(simulationStep); } } catch (InterruptedException e) { diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOutput.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOutput.java index 4b1d87aa1..bbdc67ae5 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOutput.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimOutput.java @@ -1,6 +1,7 @@ package cz.cuni.mff.d3s.deeco.simulation.matsim; -import org.matsim.api.core.v01.Coord; +import java.util.List; + import org.matsim.api.core.v01.Id; import org.matsim.core.mobsim.framework.MobsimAgent.State; @@ -12,12 +13,10 @@ */ public class MATSimOutput { public Id currentLinkId; - public Coord estPosition; public State state; - public MATSimOutput(Id currentLinkId, Coord estPostion, State state) { + public MATSimOutput(Id currentLinkId, State state) { this.currentLinkId = currentLinkId; - this.estPosition = estPostion; this.state = state; } diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimRouter.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimRouter.java index 2ec97dca6..4dcb15b63 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimRouter.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimRouter.java @@ -1,5 +1,6 @@ package cz.cuni.mff.d3s.deeco.simulation.matsim; +import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -8,11 +9,13 @@ import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Node; import org.matsim.api.core.v01.population.Leg; import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.api.experimental.facilities.Facility; import org.matsim.core.config.Config; import org.matsim.core.controler.Controler; +import org.matsim.core.network.NetworkImpl; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.router.TripRouter; import org.matsim.core.router.TripRouterFactory; @@ -43,21 +46,6 @@ public MATSimRouter(Controler controler, TravelTime travelTime) { this.controler = controler; } - /* - * XXX possibly remove - - public String routeRandomly(Id currentLinkId) { - Link currentLink = controler.getScenario().getNetwork().getLinks() - .get(currentLinkId); - if (currentLink == null) - return null; - Object[] outLinks = currentLink.getToNode().getOutLinks().keySet() - .toArray(); - int idx = MatsimRandom.getRandom().nextInt(outLinks.length); - return outLinks[idx].toString(); - } - */ - public Link findLinkById(Id id) { return controler.getNetwork().getLinks().get(id); } @@ -93,6 +81,26 @@ public List route(Link linkFrom, Link linkTo) { route.add(linkTo.getId()); return route; } + + public Link findNearestLink(Coord coord) { + return ((NetworkImpl)controler.getNetwork()).getNearestLink(coord); + } + + public Link findNearestLinkRight(Coord coord) { + return ((NetworkImpl)controler.getNetwork()).getNearestRightEntryLink(coord); + } + + public Link findNearestLinkExactly(Coord coord) { + return ((NetworkImpl)controler.getNetwork()).getNearestLinkExactly(coord); + } + + public Node findNearestNode(Coord coord) { + return ((NetworkImpl)controler.getNetwork()).getNearestNode(coord); + } + + public Collection getNearestNodes(Coord coord, double distance) { + return ((NetworkImpl)controler.getNetwork()).getNearestNodes(coord, distance); + } public List route(Id from, Id to) { Link fromLink = controler.getNetwork().getLinks().get(from); @@ -160,14 +168,14 @@ public WithinDayTripRouterFactory(Controler controler, public TripRouter createTripRouter() { Config config = controler.getConfig(); - TransitRouterFactory trf = new TransitRouterImplFactory(controler - .getScenario().getTransitSchedule(), - new TransitRouterConfig(config.planCalcScore(), config - .plansCalcRoute(), config.transitRouter(), config - .vspExperimental())); +// TransitRouterFactory trf = new TransitRouterImplFactory(controler +// .getScenario().getTransitSchedule(), +// new TransitRouterConfig(config.planCalcScore(), config +// .plansCalcRoute(), config.transitRouter(), config +// .vspExperimental())); return new TripRouterFactoryImpl(controler.getScenario(), controler.getTravelDisutilityFactory(), travelTime, - new DijkstraFactory(), trf).createTripRouter(); + new DijkstraFactory(), null).createTripRouter(); } } diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimSimulation.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimSimulation.java index dafb4fd00..11ca1ee42 100644 --- a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimSimulation.java +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimSimulation.java @@ -11,6 +11,7 @@ import org.matsim.core.controler.Controler; import org.matsim.core.controler.events.StartupEvent; import org.matsim.core.controler.listener.StartupListener; +import org.matsim.core.mobsim.framework.Mobsim; import org.matsim.core.router.util.TravelTime; import org.matsim.withinday.trafficmonitoring.TravelTimeCollector; import org.matsim.withinday.trafficmonitoring.TravelTimeCollectorFactory; @@ -20,7 +21,6 @@ import cz.cuni.mff.d3s.deeco.simulation.DirectSimulationHost; import cz.cuni.mff.d3s.deeco.simulation.Simulation; import cz.cuni.mff.d3s.deeco.simulation.SimulationStepListener; -import cz.cuni.mff.d3s.deeco.simulation.task.SimulationStepTask; public class MATSimSimulation extends Simulation implements SimulationStepListener, MATSimTimeProvider { @@ -37,11 +37,12 @@ public class MATSimSimulation extends Simulation implements private final MATSimDataProvider matSimProvider; private final MATSimDataReceiver matSimReceiver; private final Map hosts; + private final MATSimExtractor extractor; private final DirectKnowledgeDataHandler knowledgeDataHandler; public MATSimSimulation(MATSimDataReceiver matSimReceiver, - MATSimDataProvider matSimProvider, + MATSimDataProvider matSimProvider, MATSimUpdater updater, MATSimExtractor extractor, final Collection agentSources, String matSimConf) { this.knowledgeDataHandler = new DirectKnowledgeDataHandler(); @@ -62,7 +63,8 @@ public MATSimSimulation(MATSimDataReceiver matSimReceiver, .getTimeStepSize(); Log.i("Starting simulation: matsimStartTime: " + start + " matsimEndTime: " + end); - this.listener = new JDEECoWithinDayMobsimListener(this); + this.extractor = extractor; + this.listener = new JDEECoWithinDayMobsimListener(this, updater, extractor); this.matSimProvider = matSimProvider; this.matSimReceiver = matSimReceiver; @@ -141,11 +143,12 @@ public synchronized void callAt(long absoluteTime, String hostId) { } @Override - public void at(long seconds, SimulationStepTask task) { + public void at(long seconds, Object triger) { + Mobsim mobsim = (Mobsim) triger; // Exchange data with MATSim long milliseconds = secondsToMilliseconds(seconds); - matSimReceiver.setMATSimData(listener.getOutputs(seconds)); - listener.setInputs(matSimProvider.getMATSimData()); + matSimReceiver.setMATSimData(extractor.extractFromMATSim(listener.getAllJDEECoAgents(), mobsim)); + listener.updateJDEECoAgents(matSimProvider.getMATSimData()); // Add callback for the MATSim step callAt(milliseconds + simulationStep, SIMULATION_CALLBACK); DirectSimulationHost host; diff --git a/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimUpdater.java b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimUpdater.java new file mode 100644 index 000000000..5c63f650e --- /dev/null +++ b/jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/matsim/MATSimUpdater.java @@ -0,0 +1,7 @@ +package cz.cuni.mff.d3s.deeco.simulation.matsim; + +import java.util.Collection; + +public interface MATSimUpdater { + public void updateJDEECoAgents(Object input, Collection agents); +}