Skip to content

Commit

Permalink
Fix MATSim simulation by adding fake agent to enforce scheduler to run
Browse files Browse the repository at this point in the history
  • Loading branch information
vladamatena committed Mar 19, 2015
1 parent aac7487 commit a39e587
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions jdeeco-matsim-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target/
/.classpath
/logs/
/matsim/
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
import java.util.List;
import java.util.Map;

import org.matsim.core.basic.v01.IdImpl;
import org.matsim.core.utils.geometry.CoordImpl;

import cz.cuni.mff.d3s.deeco.runtime.DEECoContainer;
import cz.cuni.mff.d3s.deeco.runtime.DEECoPlugin;
import cz.cuni.mff.d3s.deeco.timer.CurrentTimeProvider;
import cz.cuni.mff.d3s.deeco.timer.SimulationTimer;
import cz.cuni.mff.d3s.deeco.timer.TimerEventListener;
import cz.cuni.mff.d3s.jdeeco.matsim.old.matsim.DefaultMATSimExtractor;
import cz.cuni.mff.d3s.jdeeco.matsim.old.matsim.DefaultMATSimUpdater;
import cz.cuni.mff.d3s.jdeeco.matsim.old.matsim.JDEECoAgent;
import cz.cuni.mff.d3s.jdeeco.matsim.old.matsim.JDEECoAgentSource;
import cz.cuni.mff.d3s.jdeeco.matsim.old.matsim.MATSimRouter;
import cz.cuni.mff.d3s.jdeeco.matsim.old.roadtrains.MATSimDataProviderReceiver;
import cz.cuni.mff.d3s.jdeeco.matsim.old.simulation.DirectKnowledgeDataHandler;
import cz.cuni.mff.d3s.jdeeco.matsim.old.simulation.DirectSimulationHost;
Expand All @@ -29,7 +34,7 @@ public class MATSimSimulation implements DEECoPlugin {
class TimerProvider implements SimulationTimer {
@Override
public void notifyAt(long time, TimerEventListener listener, DEECoContainer node) {
System.out.println("NOTIFY AT CALLED FOR: " + time + " NODE:" + node.getId());
// System.out.println("NOTIFY AT CALLED FOR: " + time + " NODE:" + node.getId());
MATSimSimulation.this.oldSimulation.callAt(time, String.valueOf(node.getId()));
hosts.get(node.getId()).listener = listener;
}
Expand All @@ -55,7 +60,7 @@ public Host(String id, CurrentTimeProvider timeProvider, NetworkDataHandler hand

@Override
public void at(double absoluteTime) {
System.out.println("CALLBACK CALLED AT: " + getCurrentMilliseconds() + " NODE: " + getHostId());
// System.out.println("CALLBACK CALLED AT: " + getCurrentMilliseconds() + " NODE: " + getHostId());
listener.at(getCurrentMilliseconds());
}

Expand All @@ -81,6 +86,14 @@ public MATSimSimulation(String matsimConfig) {
networkHandler,
Arrays.asList(agentSource),
matsimConfig);

MATSimRouter router = new MATSimRouter(
oldSimulation.getControler(),
oldSimulation.getTravelTime(),
10 /* TODO: FAKE VALUE */);

// TODO: Add fake agent to make simulation run
agentSource.addAgent(new JDEECoAgent(new IdImpl(99), router.findNearestLink(new CoordImpl(0.0d, 0.0d)).getId()));
}

public SimulationTimer getTimer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.cuni.mff.d3s.jdeeco.matsim.demo.convoy;


import java.util.List;

import cz.cuni.mff.d3s.deeco.annotations.Ensemble;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static void map(
@Out("member.leaderPosition") ParamHolder<Waypoint> fLeaderPosition,
@In("coord.position") Waypoint lPosition) {

System.out.println("membership: "+ memberId + " " + coordId);
System.out.println("exchange: "+ memberId + " " + coordId);

fLeaderPosition.value = lPosition;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.cuni.mff.d3s.jdeeco.matsim.demo.convoy;


import cz.cuni.mff.d3s.deeco.annotations.Component;
import cz.cuni.mff.d3s.deeco.annotations.In;
import cz.cuni.mff.d3s.deeco.annotations.InOut;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cz.cuni.mff.d3s.jdeeco.matsim.demo.convoy;



import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import cz.cuni.mff.d3s.deeco.annotations.Component;
Expand All @@ -25,14 +27,14 @@ public class Leader {
public Waypoint position;

public Leader() {
path = Arrays.asList(
path = new LinkedList<Waypoint>(Arrays.asList(
new Waypoint(3, 1),
new Waypoint(2, 1),
new Waypoint(1, 1),
new Waypoint(1, 2),
new Waypoint(1, 3),
new Waypoint(1, 4),
new Waypoint(1, 5));
new Waypoint(1, 5)));

name = "L";
id = "Leader1";
Expand All @@ -48,7 +50,7 @@ public static void moveProcess(
) {

if (!path.value.isEmpty() && me.value.equals(path.value.get(0))) {
path.value = path.value.subList(1, path.value.size());
path.value = new LinkedList<Waypoint>(path.value.subList(1, path.value.size()));
}

if (!path.value.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package cz.cuni.mff.d3s.jdeeco.matsim.demo.convoy;

import java.io.Serializable;



/**
* Represents a position in a 2D plane.
*
* @author Jaroslav Keznikl <keznikl@d3s.mff.cuni.cz>
*
*/
public class Waypoint {
@SuppressWarnings("serial")
public class Waypoint implements Serializable {
public Waypoint() {
}

Expand Down

0 comments on commit a39e587

Please sign in to comment.