Skip to content

Commit

Permalink
Refactor MatSim plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
vladamatena committed Apr 10, 2015
1 parent a9e6567 commit 6f1d1ef
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public MATSimDataProviderReceiver(List<String> linksToDisable) {
}

// Here we return next links ids for MATSim agents
@Override
public Map<Id, MATSimInput> getMATSimData() {
Map<Id, MATSimInput> result = new HashMap<Id, MATSimInput>();
for (Map.Entry<Id, MATSimInput> entry : inputs.entrySet()) {
Expand All @@ -46,8 +47,8 @@ public Map<Id, MATSimInput> getMATSimData() {
}

// Here we update sensors
public void setMATSimData(Object data) {
Map<Id, MATSimOutput> map = (Map<Id, MATSimOutput>) data;
@Override
public void setMATSimData(Map<Id, MATSimOutput> map) {
outputs.clear();
outputs.putAll(map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import cz.cuni.mff.d3s.jdeeco.matsim.simulation.MATSimPreloadingControler;
import cz.cuni.mff.d3s.jdeeco.matsim.simulation.MATSimRouter;
import cz.cuni.mff.d3s.jdeeco.matsim.simulation.MATSimSimulationStepListener;
import cz.cuni.mff.d3s.jdeeco.matsim.simulation.Simulation;

/**
* Plug-in providing MATSim simulation
Expand All @@ -55,16 +56,16 @@
public class MATSimSimulation implements DEECoPlugin {
private final TreeSet<Callback> callbacks;

class TimerProvider implements SimulationTimer, MATSimSimulationStepListener {
class TimerProvider extends Simulation implements SimulationTimer, MATSimSimulationStepListener {
@Override
public void notifyAt(long time, TimerEventListener listener, DEECoContainer node) {
// System.out.println("NOTIFY AT CALLED FOR: " + time + " NODE:" + node.getId());
// MATSimSimulation.this.oldSimulation.callAt(time, String.valueOf(node.getId()));
callAt(time, String.valueOf(node.getId()));

MATSimSimulation.this.getHost(String.valueOf(node.getId())).listener = listener;
}

@Override
public synchronized void callAt(long absoluteTime, String hostId) {
Callback callback = hostIdToCallback.remove(hostId);
if (callback != null) {
Expand Down Expand Up @@ -108,10 +109,6 @@ public void at(double seconds, Mobsim mobsim) {
host.at(millisecondsToSeconds(currentMilliseconds));
}
}

private double millisecondsToSeconds(long milliseconds) {
return ((double) (milliseconds)) / 1000;
}
}

public class Host extends AbstractHost {
Expand Down Expand Up @@ -265,16 +262,12 @@ public void notifyStartup(StartupEvent event) {
}
}

this.simulationStep = secondsToMilliseconds(step);
currentMilliseconds = secondsToMilliseconds(controler.getConfig().getQSimConfigGroup().getStartTime());
this.simulationStep = TimerProvider.secondsToMilliseconds(step);
currentMilliseconds = TimerProvider.secondsToMilliseconds(controler.getConfig().getQSimConfigGroup().getStartTime());

router = new MATSimRouter(controler, travelTime, 10 /* TODO: FAKE VALUE */);
}

private long secondsToMilliseconds(double seconds) {
return (long) (seconds * 1000);
}

private void addHost(String id, cz.cuni.mff.d3s.jdeeco.matsim.plugin.MATSimSimulation.Host host) {
hosts.put(id, host);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class DefaultMATSimExtractor implements MATSimExtractor {

@Override
public Object extractFromMATSim(Collection<JDEECoAgent> agents,
public Map<Id, MATSimOutput> extractFromMATSim(Collection<JDEECoAgent> agents,
Mobsim mobsim) {
Map<Id, MATSimOutput> map = new HashMap<Id, MATSimOutput>();
MATSimOutput matSimOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
*
*/
public interface MATSimDataProvider {
public Map<Id, ?> getMATSimData();
public Map<Id, MATSimInput> getMATSimData();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cz.cuni.mff.d3s.jdeeco.matsim.simulation;

import java.util.Map;

import org.matsim.api.core.v01.Id;


/**
* Interface for MATSim data retrieval. This data comes from MATSim side.
Expand All @@ -8,5 +12,5 @@
*
*/
public interface MATSimDataReceiver {
public void setMATSimData(Object data);
public void setMATSimData(Map<Id, MATSimOutput> data);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cz.cuni.mff.d3s.jdeeco.matsim.simulation;

import java.util.Collection;
import java.util.Map;

import org.matsim.api.core.v01.Id;
import org.matsim.core.mobsim.framework.Mobsim;

public interface MATSimExtractor {
public Object extractFromMATSim(Collection<JDEECoAgent> agents, Mobsim mobsim);
public Map<Id, MATSimOutput> extractFromMATSim(Collection<JDEECoAgent> agents, Mobsim mobsim);
}

This file was deleted.

This file was deleted.

0 comments on commit 6f1d1ef

Please sign in to comment.