Skip to content

Commit

Permalink
Deploy ensamble in MATSim example
Browse files Browse the repository at this point in the history
  • Loading branch information
vladamatena committed Mar 20, 2015
1 parent f704d68 commit 8891f9a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 260 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cz.cuni.mff.d3s.jdeeco.matsim.demo.convoy;


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

import cz.cuni.mff.d3s.deeco.annotations.Ensemble;
import cz.cuni.mff.d3s.deeco.annotations.In;
import cz.cuni.mff.d3s.deeco.annotations.KnowledgeExchange;
import cz.cuni.mff.d3s.deeco.annotations.Membership;
import cz.cuni.mff.d3s.deeco.annotations.Out;
import cz.cuni.mff.d3s.deeco.annotations.PeriodicScheduling;
import cz.cuni.mff.d3s.deeco.task.ParamHolder;


@Ensemble
@PeriodicScheduling(period=500)
public class OtherVehicleEnsemble {

@Membership
public static boolean membership(
@In("member.id") String memberId,
@In("coord.id") String coordId) {
// System.out.println("membership: "+ memberId + " " + coordId);
return !(memberId.equals(coordId));
}

@KnowledgeExchange
public static void map(
@In("member.currentLink") Id memberLink,
@Out("coord.otherVehicleLink") ParamHolder<Id> coordOtherLink,
@In("member.id") String memberId,
@In("coord.id") String coordId) {
// System.out.println("exchange: "+ memberId + " " + coordId);
coordOtherLink.value = memberLink;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class Vehicle {
*/
public Coord position;

public Id otherVehicleLink;

/**
* Position of the destination
*/
Expand Down Expand Up @@ -95,27 +97,32 @@ public Vehicle(String id, Coord dst, MATSimVehicle vehiclePlugin) {
@PeriodicScheduling(period = 5000, order = 10)
public static void reportStatus(
@In("id") String id,
@In("currentLinkSensor") Sensor<Id> currentLinkSensor,
@In("currentLink") Id currentLink,
@In("position") Coord position,
@In("dstLinkId") Id dstLinkId,
@In("route") List<Id> route,
@In("clock") CurrentTimeProvider clock,
@In("router") MATSimRouter router,
@In("speed") Double speed) {
@In("speed") Double speed,
@In("otherVehicleLink") Id otherVehicleLink) {

Log.d("Entry [" + id + "]:reportStatus");

Id currentLinkId = currentLinkSensor.read();
Coord currentPos = router.findLinkById(currentLinkId).getCoord();

System.out.format("[%s] %s, pos: %s (%.0f, %.0f), dst: %s, speed: %.0f\n",
System.out.format("%s %s, pos: %s, dst: %s, speed: %.0f, otherPos: %s%n",
formatTime(clock.getCurrentMilliseconds()),
id,
currentLinkId.toString(),
currentPos.getX(),
currentPos.getY(),
printPos(currentLink, router),
dstLinkId.toString(),
speed);
speed,
printPos(otherVehicleLink, router));
}

private static String printPos(Id linkId, MATSimRouter router) {
if(linkId == null) {
return "UNKNOWN";
}
Coord coord = router.findLinkById(linkId).getCoord();
return String.format("%s (%.0f, %.0f)", linkId.toString(), coord.getX(), coord.getY());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ public void testTravel() throws AnnotationProcessorException, InterruptedExcepti
DEECoNode nodeA = realm.createNode(42, agentA); // DEECO node with Id and agent as plug-in
Vehicle vehicleA = new Vehicle("Vehicle A", new CoordImpl(100000, 100000), agentA); // DEECO component controlling the vehicle
nodeA.deployComponent(vehicleA);
nodeA.deployEnsemble(OtherVehicleEnsemble.class);

// Node hosting vehicle B
MATSimVehicle agentB = new MATSimVehicle(new CoordImpl(0, 100000)); // MATSim agent with start position
DEECoNode nodeB = realm.createNode(45, agentB); // DEECO node with Id and agent as plug-in
Vehicle vehicleB = new Vehicle("Vehicle B", new CoordImpl(0, 100000), agentB); // DEECO component controlling the vehicle
nodeB.deployComponent(vehicleB);
nodeB.deployEnsemble(OtherVehicleEnsemble.class);

// Simulate for specified time
realm.start(600000);
Expand Down

This file was deleted.

0 comments on commit 8891f9a

Please sign in to comment.