Skip to content

Commit

Permalink
added traci support for new ride attributes refs #3948
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Mar 28, 2018
1 parent 75c89cc commit 0b3e236
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/libsumo/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ Simulation::findIntermodalRoute(const std::string& from, const std::string& to,
result.back().edges.push_back(e->getID());
}
result.back().travelTime = result.back().cost = it->cost;
result.back().intended = it->intended;
result.back().depart = it->depart;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/libsumo/TraCIDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct TraCIBestLanesData {
class TraCIStage {
public:
TraCIStage() {} // only to make swig happy
TraCIStage(int _type) : type(_type) {}
TraCIStage(int _type) : type(_type), depart(-1) {}
/// @brief The type of stage (walking, driving, ...)
int type;
/// @brief The line or the id of the vehicle type
Expand All @@ -218,6 +218,10 @@ class TraCIStage {
double travelTime;
/// @brief effort needed
double cost;
/// @brief id of the intended vehicle for public transport ride
std::string intended;
/// @brief intended depart time for public transport ride or -1
double depart;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/router/ROPerson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ROPerson::Ride::saveAsXML(OutputDevice& os, const bool extended) const {
os.writeAttr(SUMO_ATTR_BUS_STOP, destStop);
}
os.writeAttr(SUMO_ATTR_LINES, lines);
if (intended != "") {
if (intended != "" && intended != lines) {
os.writeAttr(SUMO_ATTR_INTENDED, intended);
}
if (depart >= 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/traci-server/TraCIServerAPI_Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ TraCIServerAPI_Simulation::writeStage(tcpip::Storage& outputStorage, const libsu
outputStorage.writeDouble(stage.travelTime);
outputStorage.writeUnsignedByte(TYPE_DOUBLE);
outputStorage.writeDouble(stage.cost);
outputStorage.writeUnsignedByte(TYPE_STRING);
outputStorage.writeString(stage.intended);
outputStorage.writeUnsignedByte(TYPE_DOUBLE);
outputStorage.writeDouble(stage.depart);
}


Expand Down
3 changes: 2 additions & 1 deletion src/utils/vehicle/IntermodalRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class IntermodalRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> >

public:
struct TripItem {
TripItem(const std::string& _line = "") : line(_line), cost(0.) {}
TripItem(const std::string& _line = "") :
line(_line), intended(_line), depart(-1), cost(0.) {}
std::string line;
std::string destStop;
std::string intended; // intended public transport vehicle id
Expand Down
8 changes: 4 additions & 4 deletions tests/complex/traci/pythonApi/simulation/output.complex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Loading configuration... done.
Could not connect to TraCI server at localhost:52945 [Errno 111] Connection refused
Could not connect to TraCI server at localhost:44067 [Errno 111] Connection refused
Retrying in 1 seconds
{114: ['horiz', 'horiz1'], 116: []}
step 0
Expand Down Expand Up @@ -56,9 +56,9 @@ getParameter 0.00
getParameter parkingArea.capacity 6
getParameter parkingArea.occupancy 0
getBusStopWaiting 0
findRoute Stage(stageType=3, line='', destStop='', edges=['o', '2o'], travelTime=738.4, cost=738.4)
findRoute with routing mode Stage(stageType=3, line='', destStop='', edges=['o', '2o'], travelTime=0.0, cost=0.0)
findIntermodalRoute [Stage(stageType=2, line='', destStop='', edges=['o', '2o'], travelTime=3694.9536, cost=3694.9536)]
findRoute Stage(stageType=3, line='', destStop='', edges=['o', '2o'], travelTime=738.4, cost=738.4, intended='', depart=-1.0)
findRoute with routing mode Stage(stageType=3, line='', destStop='', edges=['o', '2o'], travelTime=0.0, cost=0.0, intended='', depart=-1.0)
findIntermodalRoute [Stage(stageType=2, line='', destStop='', edges=['o', '2o'], travelTime=3694.9536, cost=3694.9536, intended='', depart=-1.0)]
step 0
{114: [], 116: []}
step 1
Expand Down
8 changes: 6 additions & 2 deletions tools/traci/_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .domain import Domain
from .storage import Storage

Stage = collections.namedtuple('Stage', ['stageType', 'line', 'destStop', 'edges', 'travelTime', 'cost'])
Stage = collections.namedtuple('Stage', ['stageType', 'line', 'destStop', 'edges', 'travelTime', 'cost', 'intended', 'depart'])

def _readStage(result):
# compound size and type
Expand All @@ -33,7 +33,11 @@ def _readStage(result):
result.read("!B") # Type
edges = result.readStringList()
_, travelTime, _, cost = result.read("!BdBd")
return Stage(stageType, line, destStop, edges, travelTime, cost)
result.read("!B") # Type
intended = result.readString()
result.read("!B") # Type
depart = result.readDouble()
return Stage(stageType, line, destStop, edges, travelTime, cost, intended, depart)

_RETURN_VALUE_FUNC = {tc.VAR_TIME_STEP: Storage.readInt,
tc.VAR_LOADED_VEHICLES_NUMBER: Storage.readInt,
Expand Down

0 comments on commit 0b3e236

Please sign in to comment.