Hello Jakob,
thanks for clarifying this. It would be nice to be able to set the index
via NETEDIT. And/or to set a custom string field per connection, which
could be referenced in a TraCI call. I'd be happy to implement the
latter, but I'd need some pointers on where to begin.
Is it possible now to set tl index via an additionals file, or only when
not using NETEDIT, but building the xml data by hand? From the docs, I
am assuming the latter.
I attached a patch with the code I wrote, that implements setting a
single tl phase directly via TraCI. It looks at either the id of the
lane, or the id of the edge. The function expects a single string,
containing both an id and a state as a single char, seperated by a
space, ie. "sg1 G". Nicer might be to have two arguments, but I did not
know how to implement that.
Attached a network that if run with SUMO-GUI r25299, causes the
mentioned failure when ran with the debug version.
Also note, that the detectors (actually unused now, cause TraCI is
decoupled) are in a somewhat different place when viewed with SUMO-GUI
r26299, than when edited with NETEDIT 0.30.
That may be related to the fact that in the svn version of NETEDIT, it
seems not possible to save detectors? See screenshot of a dialog that
appears while trying to save the additionals file that was made with
version 0.30.
I am not aware of force moving vehicles. The trips have been generated
with od2trips, based on an od matrix.
Kind regards,
Menno
Op 23-7-2017 om 20:58 schreef Menno van der Woude:
Hello Jakob,
thanks for clarifying this. It would be nice to be able to set the index
via NETEDIT. And/or to set a custom string field per connection, which
could be referenced in a TraCI call. I'd be happy to implement the
latter, but I'd need some pointers on where to begin.
Is it possible now to set tl index via an additionals file, or only when
not using NETEDIT, but building the xml data by hand? From the docs, I
am assuming the latter.
I attached a patch with the code I wrote, that implements setting a
single tl phase directly via TraCI. It looks at either the id of the
lane, or the id of the edge. The function expects a single string,
containing both an id and a state as a single char, seperated by a
space, ie. "sg1 G". Nicer might be to have two arguments, but I did not
know how to implement that.
Attached a network that if run with SUMO-GUI r25299, causes the
mentioned failure when ran with the debug version.
Also note, that the detectors (actually unused now, cause TraCI is
decoupled) are in a somewhat different place when viewed with SUMO-GUI
r26299, than when edited with NETEDIT 0.30.
That may be related to the fact that in the svn version of NETEDIT, it
seems not possible to save detectors? See screenshot of a dialog that
appears while trying to save the additionals file that was made with
version 0.30.
I am not aware of force moving vehicles. The trips have been generated
with od2trips, based on an od matrix.
Kind regards,
Menno
Index: microsim/traffic_lights/MSTLLogicControl.cpp
===================================================================
--- microsim/traffic_lights/MSTLLogicControl.cpp (revision 25299)
+++ microsim/traffic_lights/MSTLLogicControl.cpp (working copy)
@@ -175,7 +175,60 @@
}
}
+void
+MSTLLogicControl::TLSLogicVariants::setSingleStateInstantiatingOnline(MSTLLogicControl&
tlc, const std::string& id,
+ const std::string& state) {
+ // build only once...
+ MSTrafficLightLogic* logic = getLogic("online");
+ if (logic == 0) {
+ std::string oldstate = getActive()->getCurrentPhaseDef().getState();
+ MSPhaseDefinition* phase = new MSPhaseDefinition(DELTA_T, oldstate);
+ std::vector<MSPhaseDefinition*> phases;
+ phases.push_back(phase);
+ logic = new MSSimpleTrafficLightLogic(tlc, myCurrentProgram->getID(),
"online", phases, 0,
+ MSNet::getInstance()->getCurrentTimeStep() + DELTA_T,
+ std::map<std::string, std::string>());
+ addLogic("online", logic, true, true);
+ }
+ else {
+ std::string newstate;
+ const MSTrafficLightLogic::LinkVectorVector& links =
getActive()->getLinks();
+ const MSTrafficLightLogic::LaneVectorVector& lanes =
getActive()->getLaneVectors();
+ std::string oldstate = getActive()->getCurrentPhaseDef().getState();
+ int no = (int)lanes.size();
+ int tot = 0;
+ for (int i = 0; i < no; ++i)
+ {
+ const MSTrafficLightLogic::LaneVector& llanes = lanes[i];
+ const MSTrafficLightLogic::LinkVector& llinks = links[i];
+ int no2 = (int)llanes.size();
+ for (int j = 0; j < no2; ++j)
+ {
+ MSLink* link = llinks[j];
+ const MSLane* lane = link->getLaneBefore();
+ const std::string eid = lane->getEdge().getID();
+ const std::string lid = lane->getID();
+ if (eid == id && lid.substr(0, eid.size()) ==
id || lid == id)
+ {
+ newstate += state.at(0);
+ }
+ else
+ {
+ newstate += oldstate.at(tot);
+ }
+ ++tot;
+ }
+
+ }
+
+ MSPhaseDefinition nphase(DELTA_T, newstate);
+ *(dynamic_cast<MSSimpleTrafficLightLogic*>(logic)->getPhases()[0]) =
nphase;
+ switchTo(tlc, "online");
+ }
+}
+
+
void
MSTLLogicControl::TLSLogicVariants::addSwitchCommand(OnSwitchAction* c) {
mySwitchActions.push_back(c);
Index: microsim/traffic_lights/MSTLLogicControl.h
===================================================================
--- microsim/traffic_lights/MSTLLogicControl.h (revision 25299)
+++ microsim/traffic_lights/MSTLLogicControl.h (working copy)
@@ -39,13 +39,16 @@
#include <utils/xml/SUMOXMLDefinitions.h>
#include <utils/common/Command.h>
+#include "../MSLink.h"
+#include "../MSLane.h"
+#include "../MSEdge.h"
// ===========================================================================
// class declarations
// ===========================================================================
class MSTrafficLightLogic;
-class MSLink;
-class MSLane;
+//class MSLink;
+//class MSLane;
class MSPhaseDefinition;
@@ -139,7 +142,12 @@
void setStateInstantiatingOnline(MSTLLogicControl& tlc,
const std::string& state);
+ /* @brief retrieves state for the special program "online" and sets
state of links connected to lane id
+ * this program is instantiated only once */
+ void setSingleStateInstantiatingOnline(MSTLLogicControl& tlc, const
std::string& id,
+ const std::string& state);
+
void executeOnSwitchActions() const;
void addLink(MSLink* link, MSLane* lane, int pos);
Index: traci-server/TraCIConstants.h
===================================================================
--- traci-server/TraCIConstants.h (revision 25299)
+++ traci-server/TraCIConstants.h (working copy)
@@ -486,6 +486,9 @@
// traffic light states, encoded as rRgGyYoO tuple (get: traffic lights)
#define TL_RED_YELLOW_GREEN_STATE 0x20
+// traffic light states, encoded as rRgGyYoO char
+#define TL_RED_YELLOW_GREEN_SINGLESTATE 0x21
+
// index of the phase (set: traffic lights)
#define TL_PHASE_INDEX 0x22
Index: traci-server/TraCIServerAPI_TLS.cpp
===================================================================
--- traci-server/TraCIServerAPI_TLS.cpp (revision 25299)
+++ traci-server/TraCIServerAPI_TLS.cpp (working copy)
@@ -289,7 +289,7 @@
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != TL_PHASE_INDEX && variable != TL_PROGRAM && variable !=
TL_PHASE_DURATION
- && variable != TL_RED_YELLOW_GREEN_STATE && variable !=
TL_COMPLETE_PROGRAM_RYG
+ && variable != TL_RED_YELLOW_GREEN_STATE && variable !=
TL_RED_YELLOW_GREEN_SINGLESTATE && variable != TL_COMPLETE_PROGRAM_RYG
&& variable != VAR_PARAMETER) {
return server.writeErrorStatusCmd(CMD_SET_TL_VARIABLE, "Change TLS
State: unsupported variable " + toHex(variable, 2) + " specified",
outputStorage);
}
@@ -343,6 +343,19 @@
vars.setStateInstantiatingOnline(tlsControl, state);
}
break;
+ case TL_RED_YELLOW_GREEN_SINGLESTATE:{
+ std::string state;
+ if (!server.readTypeCheckingString(inputStorage, state)) {
+ return server.writeErrorStatusCmd(CMD_SET_TL_VARIABLE, "The
phase must be given as a string.", outputStorage);
+ }
+ std::stringstream ss(state); // Insert the string into a stream
+ std::string buf;
+ std::vector<std::string> tokens; // Create vector to hold our words
+ while (ss >> buf)
+ tokens.push_back(buf);
+ vars.setSingleStateInstantiatingOnline(tlsControl, tokens[0],
tokens[1]);
+ }
+ break;
case TL_COMPLETE_PROGRAM_RYG: {
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_SET_TL_VARIABLE, "A
compound object is needed for setting a new program.", outputStorage);
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
sumo-devel mailing list
sumo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sumo-devel