#pragma once
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4514 4820)
#endif
#include <libsumo/TraCIConstants.h>
#include <vector>
#include <limits>
#include <map>
#include <string>
#include <stdexcept>
#include <sstream>
#include <memory>
#include <cstring>
namespace libsumo {
class VariableWrapper;
}
namespace tcpip {
class Storage;
}
#ifdef LIBTRACI
#define LIBSUMO_NAMESPACE libtraci
#else
#define LIBSUMO_NAMESPACE libsumo
#endif
#define LIBSUMO_SUBSCRIPTION_API \
static void subscribe(const std::string& objectID, const std::vector<int>& varIDs = std::vector<int>({-1}), \
double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults& parameters = libsumo::TraCIResults()); \
static void unsubscribe(const std::string& objectID); \
static void subscribeContext(const std::string& objectID, int domain, double dist, const std::vector<int>& varIDs = std::vector<int>({-1}), \
double begin = libsumo::INVALID_DOUBLE_VALUE, double end = libsumo::INVALID_DOUBLE_VALUE, const libsumo::TraCIResults& parameters = libsumo::TraCIResults()); \
static void unsubscribeContext(const std::string& objectID, int domain, double dist); \
static const libsumo::SubscriptionResults getAllSubscriptionResults(); \
static const libsumo::TraCIResults getSubscriptionResults(const std::string& objectID); \
static const libsumo::ContextSubscriptionResults getAllContextSubscriptionResults(); \
static const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string& objectID); \
static void subscribeParameterWithKey(const std::string& objectID, const std::string& key, double beginTime = libsumo::INVALID_DOUBLE_VALUE, double endTime = libsumo::INVALID_DOUBLE_VALUE); \
static const int DOMAIN_ID; \
static int domainID() { return DOMAIN_ID; }
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM) \
const int CLASS::DOMAIN_ID(libsumo::CMD_GET_##DOM##_VARIABLE); \
void \
CLASS::subscribe(const std::string& objectID, const std::vector<int>& varIDs, double begin, double end, const libsumo::TraCIResults& parameters) { \
libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_VARIABLE, objectID, varIDs, begin, end, parameters); \
} \
void \
CLASS::unsubscribe(const std::string& objectID) { \
libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_VARIABLE, objectID, std::vector<int>(), libsumo::INVALID_DOUBLE_VALUE, libsumo::INVALID_DOUBLE_VALUE, libsumo::TraCIResults()); \
} \
void \
CLASS::subscribeContext(const std::string& objectID, int domain, double dist, const std::vector<int>& varIDs, double begin, double end, const TraCIResults& parameters) { \
libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_CONTEXT, objectID, varIDs, begin, end, parameters, domain, dist); \
} \
void \
CLASS::unsubscribeContext(const std::string& objectID, int domain, double dist) { \
libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_CONTEXT, objectID, std::vector<int>(), libsumo::INVALID_DOUBLE_VALUE, libsumo::INVALID_DOUBLE_VALUE, libsumo::TraCIResults(), domain, dist); \
} \
const libsumo::SubscriptionResults \
CLASS::getAllSubscriptionResults() { \
return mySubscriptionResults; \
} \
const libsumo::TraCIResults \
CLASS::getSubscriptionResults(const std::string& objectID) { \
return mySubscriptionResults[objectID]; \
} \
const libsumo::ContextSubscriptionResults \
CLASS::getAllContextSubscriptionResults() { \
return myContextSubscriptionResults; \
} \
const libsumo::SubscriptionResults \
CLASS::getContextSubscriptionResults(const std::string& objectID) { \
return myContextSubscriptionResults[objectID]; \
} \
void \
CLASS::subscribeParameterWithKey(const std::string& objectID, const std::string& key, double beginTime, double endTime) { \
libsumo::Helper::subscribe(libsumo::CMD_SUBSCRIBE_##DOM##_VARIABLE, objectID, std::vector<int>({libsumo::VAR_PARAMETER_WITH_KEY}), beginTime, endTime, libsumo::TraCIResults {{libsumo::VAR_PARAMETER_WITH_KEY, std::make_shared<libsumo::TraCIString>(key)}}); \
}
#define LIBSUMO_ID_PARAMETER_API \
static std::vector<std::string> getIDList(); \
static int getIDCount(); \
static std::string getParameter(const std::string& objectID, const std::string& key); \
static const std::pair<std::string, std::string> getParameterWithKey(const std::string& objectID, const std::string& key); \
static void setParameter(const std::string& objectID, const std::string& key, const std::string& value);
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS) \
const std::pair<std::string, std::string> \
CLASS::getParameterWithKey(const std::string& objectID, const std::string& key) { \
return std::make_pair(key, getParameter(objectID, key)); \
}
#define SWIGJAVA_CAST(CLASS) \
static std::shared_ptr<CLASS> cast(std::shared_ptr<TraCIResult> res) { \
return std::dynamic_pointer_cast<CLASS>(res); \
}
namespace libsumo {
class TraCIException : public std::runtime_error {
public:
TraCIException(std::string what)
: std::runtime_error(what) {}
};
class FatalTraCIError : public std::runtime_error {
public:
FatalTraCIError(std::string what)
: std::runtime_error(what) {}
};
struct TraCIResult {
virtual ~TraCIResult() {}
virtual std::string getString() const {
return "";
}
virtual int getType() const {
return -1;
}
};
struct TraCIPosition : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCIPosition(" << x << "," << y;
if (z != INVALID_DOUBLE_VALUE) {
os << "," << z;
}
os << ")";
return os.str();
}
int getType() const {
return z != INVALID_DOUBLE_VALUE ? POSITION_3D : POSITION_2D;
}
double x = INVALID_DOUBLE_VALUE, y = INVALID_DOUBLE_VALUE, z = INVALID_DOUBLE_VALUE;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIPosition)
#endif
};
struct TraCIRoadPosition : TraCIResult {
TraCIRoadPosition(const std::string e = "", const double p = INVALID_DOUBLE_VALUE, const int li = INVALID_INT_VALUE) : edgeID(e), pos(p), laneIndex(li) {}
std::string getString() const {
std::ostringstream os;
os << "TraCIRoadPosition(" << edgeID << "_" << laneIndex << "," << pos << ")";
return os.str();
}
int getType() const {
return POSITION_ROADMAP;
}
std::string edgeID;
double pos;
int laneIndex;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIRoadPosition)
#endif
};
struct TraCIColor : TraCIResult {
TraCIColor() : r(0), g(0), b(0), a(255) {}
TraCIColor(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
std::string getString() const {
std::ostringstream os;
os << "TraCIColor(" << r << "," << g << "," << b << "," << a << ")";
return os.str();
}
int r, g, b, a;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIColor)
#endif
};
struct TraCIPositionVector : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "[";
for (const TraCIPosition& v : value) {
os << "(" << v.x << "," << v.y << "," << v.z << ")";
}
os << "]";
return os.str();
}
std::vector<TraCIPosition> value;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIPositionVector)
#endif
};
struct TraCIInt : TraCIResult {
TraCIInt(int v = 0, int t = libsumo::TYPE_INTEGER) : value(v), traciType(t) {}
std::string getString() const {
std::ostringstream os;
os << value;
return os.str();
}
int getType() const {
return traciType;
}
int value;
int traciType;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIInt)
#endif
};
struct TraCIDouble : TraCIResult {
TraCIDouble(double v = 0.) : value(v) {}
std::string getString() const {
std::ostringstream os;
os << value;
return os.str();
}
int getType() const {
return libsumo::TYPE_DOUBLE;
}
double value;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIDouble)
#endif
};
struct TraCIString : TraCIResult {
TraCIString(std::string v = "") : value(v) {}
std::string getString() const {
return value;
}
int getType() const {
return libsumo::TYPE_STRING;
}
std::string value;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIString)
#endif
};
struct TraCIStringList : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "[";
for (std::string v : value) {
os << v << ",";
}
os << "]";
return os.str();
}
std::vector<std::string> value;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIStringList)
#endif
};
struct TraCIDoubleList : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "[";
for (double v : value) {
os << v << ",";
}
os << "]";
return os.str();
}
std::vector<double> value;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIDoubleList)
#endif
};
struct TraCIIntList : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "[";
for (int v : value) {
os << v << ",";
}
os << "]";
return os.str();
}
std::vector<int> value;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIIntList)
#endif
};
struct TraCIStringDoublePairList : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "[";
for (const auto& v : value) {
os << "(" << v.first << "," << v.second << "),";
}
os << "]";
return os.str();
}
std::vector<std::pair<std::string, double> > value;
#ifdef SWIGJAVA
SWIGJAVA_CAST(TraCIStringDoublePairList)
#endif
};
typedef std::map<int, std::shared_ptr<libsumo::TraCIResult> > TraCIResults;
typedef std::map<std::string, libsumo::TraCIResults> SubscriptionResults;
typedef std::map<std::string, libsumo::SubscriptionResults> ContextSubscriptionResults;
struct TraCIPhase {
TraCIPhase() {}
TraCIPhase(const double _duration, const std::string& _state, const double _minDur = libsumo::INVALID_DOUBLE_VALUE,
const double _maxDur = libsumo::INVALID_DOUBLE_VALUE,
const std::vector<int>& _next = std::vector<int>(),
const std::string& _name = "",
const std::string& _earlyTarget = "") :
duration(_duration), state(_state), minDur(_minDur), maxDur(_maxDur), next(_next), name(_name), earlyTarget(_earlyTarget) {}
~TraCIPhase() {}
double duration;
std::string state;
double minDur, maxDur;
std::vector<int> next;
std::string name;
std::string earlyTarget;
};
}
#ifdef SWIG
%template(TraCIPhaseVector) std::vector<std::shared_ptr<libsumo::TraCIPhase> >;
#endif
namespace libsumo {
struct TraCILogic {
TraCILogic() {}
TraCILogic(const std::string& _programID, const int _type, const int _currentPhaseIndex,
const std::vector<std::shared_ptr<libsumo::TraCIPhase> >& _phases = std::vector<std::shared_ptr<libsumo::TraCIPhase> >())
: programID(_programID), type(_type), currentPhaseIndex(_currentPhaseIndex), phases(_phases) {}
~TraCILogic() {}
std::string getString() const {
std::ostringstream os;
os << "TraCILink(" << programID << "," << type << "," << currentPhaseIndex << ")";
return os.str();
}
std::string programID;
int type;
int currentPhaseIndex;
std::vector<std::shared_ptr<libsumo::TraCIPhase> > phases;
std::map<std::string, std::string> subParameter;
};
struct TraCILogicVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCILogicVectorWrapped[";
for (const TraCILogic& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCILogic> value;
};
struct TraCILink {
TraCILink() {}
TraCILink(const std::string& _from, const std::string& _via, const std::string& _to)
: fromLane(_from), viaLane(_via), toLane(_to) {}
~TraCILink() {}
std::string getString() const {
std::ostringstream os;
os << "TraCILink(" << fromLane << "," << viaLane << "," << toLane << ")";
return os.str();
}
std::string fromLane;
std::string viaLane;
std::string toLane;
};
struct TraCILinkVectorVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCILinkVectorVectorWrapped[";
for (const std::vector<TraCILink>& v : value) {
os << "[";
for (const TraCILink& tl : v) {
os << tl.getString() << ",";
}
}
os << "]";
return os.str();
}
std::vector<std::vector<TraCILink> > value;
};
struct TraCIConnection {
TraCIConnection() {}
TraCIConnection(const std::string& _approachedLane, const bool _hasPrio, const bool _isOpen, const bool _hasFoe,
const std::string _approachedInternal, const std::string _state, const std::string _direction, const double _length)
: approachedLane(_approachedLane), hasPrio(_hasPrio), isOpen(_isOpen), hasFoe(_hasFoe),
approachedInternal(_approachedInternal), state(_state), direction(_direction), length(_length) {}
~TraCIConnection() {}
std::string getString() const {
std::ostringstream os;
os << "TraCIConnection(" << approachedLane << "," << hasPrio << "," << isOpen
<< "," << hasFoe << "," << approachedInternal << "," << state << "," << direction << "," << length << ")";
return os.str();
}
std::string approachedLane;
bool hasPrio;
bool isOpen;
bool hasFoe;
std::string approachedInternal;
std::string state;
std::string direction;
double length;
};
struct TraCIConnectionVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCIConnectionVectorWrapped[";
for (const TraCIConnection& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCIConnection> value;
};
struct TraCIVehicleData {
std::string getString() const {
std::ostringstream os;
os << "TraCIVehicleData(" << id << "," << length << "," << entryTime
<< "," << leaveTime << "," << typeID << ")";
return os.str();
}
std::string id;
double length;
double entryTime;
double leaveTime;
std::string typeID;
};
struct TraCIVehicleDataVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCIVehicleDataVectorWrapped[";
for (const TraCIVehicleData& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCIVehicleData> value;
};
struct TraCINextTLSData {
std::string getString() const {
std::ostringstream os;
os << "TraCINextTLSData(" << id << "," << tlIndex << "," << dist
<< "," << state << ")";
return os.str();
}
std::string id;
int tlIndex;
double dist;
char state;
};
struct TraCINextTLSDataVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCINextTLSDataVectorWrapped[";
for (const TraCINextTLSData& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCINextTLSData> value;
};
struct TraCINextStopData {
TraCINextStopData(const std::string& lane = "",
double startPos = INVALID_DOUBLE_VALUE,
double endPos = INVALID_DOUBLE_VALUE,
const std::string& stoppingPlaceID = "",
int stopFlags = 0,
double duration = INVALID_DOUBLE_VALUE,
double until = INVALID_DOUBLE_VALUE,
double intendedArrival = INVALID_DOUBLE_VALUE,
double arrival = INVALID_DOUBLE_VALUE,
double depart = INVALID_DOUBLE_VALUE,
const std::string& split = "",
const std::string& join = "",
const std::string& actType = "",
const std::string& tripId = "",
const std::string& line = "",
double speed = 0):
lane(lane),
startPos(startPos),
endPos(endPos),
stoppingPlaceID(stoppingPlaceID),
stopFlags(stopFlags),
duration(duration),
until(until),
intendedArrival(intendedArrival),
arrival(arrival),
depart(depart),
split(split),
join(join),
actType(actType),
tripId(tripId),
line(line),
speed(speed)
{}
std::string getString() const {
std::ostringstream os;
os << "TraCINextStopData(" << lane << "," << endPos << "," << stoppingPlaceID
<< "," << stopFlags << "," << duration << "," << until
<< "," << arrival << ")";
return os.str();
}
std::string lane;
double startPos;
double endPos;
std::string stoppingPlaceID;
int stopFlags;
double duration;
double until;
double intendedArrival;
double arrival;
double depart;
std::string split;
std::string join;
std::string actType;
std::string tripId;
std::string line;
double speed;
};
struct TraCINextStopDataVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCINextStopDataVectorWrapped[";
for (const TraCINextStopData& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCINextStopData> value;
};
struct TraCIBestLanesData {
std::string getString() const {
std::ostringstream os;
os << "TraCIBestLanesData(" << laneID << "," << length << "," << occupation
<< "," << bestLaneOffset << "," << allowsContinuation << ",[";
for (const std::string& s : continuationLanes) {
os << s << ",";
}
os << "])";
return os.str();
}
std::string laneID;
double length;
double occupation;
int bestLaneOffset;
bool allowsContinuation;
std::vector<std::string> continuationLanes;
};
struct TraCIBestLanesDataVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCIBestLanesDataVectorWrapped[";
for (const TraCIBestLanesData& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCIBestLanesData> value;
};
struct TraCIStage : TraCIResult {
public:
TraCIStage(int type = INVALID_INT_VALUE, const std::string& vType = "", const std::string& line = "", const std::string& destStop = "",
const std::vector<std::string>& edges = std::vector<std::string>(),
double travelTime = INVALID_DOUBLE_VALUE, double cost = INVALID_DOUBLE_VALUE, double length = INVALID_DOUBLE_VALUE,
const std::string& intended = "", double depart = INVALID_DOUBLE_VALUE, double departPos = INVALID_DOUBLE_VALUE,
double arrivalPos = INVALID_DOUBLE_VALUE, const std::string& description = "") :
type(type), vType(vType), line(line), destStop(destStop), edges(edges), travelTime(travelTime), cost(cost),
length(length), intended(intended), depart(depart), departPos(departPos), arrivalPos(arrivalPos), description(description) {}
int type;
std::string vType;
std::string line;
std::string destStop;
std::vector<std::string> edges;
double travelTime;
double cost;
double length;
std::string intended;
double depart;
double departPos;
double arrivalPos;
std::string description;
};
struct TraCIReservation {
TraCIReservation() {}
TraCIReservation(const std::string& id,
const std::vector<std::string>& persons,
const std::string& group,
const std::string& fromEdge,
const std::string& toEdge,
double departPos,
double arrivalPos,
double depart,
double reservationTime,
int state) :
id(id), persons(persons), group(group), fromEdge(fromEdge), toEdge(toEdge), departPos(departPos), arrivalPos(arrivalPos),
depart(depart), reservationTime(reservationTime), state(state) {}
std::string id;
std::vector<std::string> persons;
std::string group;
std::string fromEdge;
std::string toEdge;
double departPos;
double arrivalPos;
double depart;
double reservationTime;
int state;
std::string getString() const {
std::ostringstream os;
os << "TraCIReservation(id=" << id << ")";
return os.str();
}
};
struct TraCIReservationVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCIReservationVectorWrapped[";
for (const TraCIReservation& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCIReservation> value;
};
struct TraCICollision {
std::string collider;
std::string victim;
std::string colliderType;
std::string victimType;
double colliderSpeed;
double victimSpeed;
std::string type;
std::string lane;
double pos;
std::string getString() const {
std::ostringstream os;
os << "TraCICollision(collider=" << collider << ", victim=" << victim << ")";
return os.str();
}
};
struct TraCICollisionVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCICollisionVectorWrapped[";
for (const TraCICollision& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCICollision> value;
};
struct TraCISignalConstraint {
std::string signalId;
std::string tripId;
std::string foeId;
std::string foeSignal;
int limit;
int type;
bool mustWait;
bool active;
std::map<std::string, std::string> param;
std::string getString() const {
std::ostringstream os;
os << "TraCISignalConstraint(signalId=" << signalId << ", tripid=" << tripId << ", foeSignal=" << foeSignal << ", foeId=" << foeId << ")";
return os.str();
}
};
struct TraCISignalConstraintVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCISignalConstraintVectorWrapped[";
for (const TraCISignalConstraint& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCISignalConstraint> value;
};
struct TraCIJunctionFoe {
std::string foeId;
double egoDist;
double foeDist;
double egoExitDist;
double foeExitDist;
std::string egoLane;
std::string foeLane;
bool egoResponse;
bool foeResponse;
std::string getString() const {
std::ostringstream os;
os << "TraCIJunctionFoe(foeId=" << foeId << ", egoDist=" << egoDist << ", foeDist=" << foeDist << ", foeDist=" << foeDist << ")";
return os.str();
}
};
struct TraCIJunctionFoeVectorWrapped : TraCIResult {
std::string getString() const {
std::ostringstream os;
os << "TraCIJunctionFoeVectorWrapped[";
for (const TraCIJunctionFoe& v : value) {
os << v.getString() << ",";
}
os << "]";
return os.str();
}
std::vector<TraCIJunctionFoe> value;
};
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif