本文整理汇总了C++中NBTrafficLightLogicCont类的典型用法代码示例。如果您正苦于以下问题:C++ NBTrafficLightLogicCont类的具体用法?C++ NBTrafficLightLogicCont怎么用?C++ NBTrafficLightLogicCont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NBTrafficLightLogicCont类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NBLoadedTLDef
void
NIVisumTL::build(NBEdgeCont& ec, NBTrafficLightLogicCont& tlc) {
for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
NBNode* node = (*ni);
TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type"));
NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
tlc.insert(def);
def->setCycleDuration((unsigned int) myCycleTime);
// signalgroups
for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
std::string groupName = (*gi).first;
NIVisumTL::SignalGroup& SG = *(*gi).second;
def->addSignalGroup(groupName);
def->addToSignalGroup(groupName, SG.connections());
// phases
SUMOTime yellowTime = -1;
if (myPhaseDefined) {
for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
NIVisumTL::Phase& PH = *(*pi).second;
def->addSignalGroupPhaseBegin(groupName, PH.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
def->addSignalGroupPhaseBegin(groupName, PH.getEndTime(), NBTrafficLightDefinition::TLCOLOR_RED);
yellowTime = MAX2(PH.getYellowTime(), yellowTime);
};
} else {
def->addSignalGroupPhaseBegin(groupName, SG.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
def->addSignalGroupPhaseBegin(groupName, SG.getEndTime(), NBTrafficLightDefinition::TLCOLOR_RED);
yellowTime = MAX2(SG.getYellowTime(), yellowTime);
}
// yellowTime can be -1 if not given in the input; it will be "patched" later
def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
}
}
}
示例2: writeSUMOTime
void
NWWriter_SUMO::writeTrafficLights(OutputDevice& into, const NBTrafficLightLogicCont& tllCont) {
std::vector<NBTrafficLightLogic*> logics = tllCont.getComputed();
for (std::vector<NBTrafficLightLogic*>::iterator it = logics.begin(); it != logics.end(); it++) {
into.openTag(SUMO_TAG_TLLOGIC);
into.writeAttr(SUMO_ATTR_ID, (*it)->getID());
into.writeAttr(SUMO_ATTR_TYPE, (*it)->getType());
into.writeAttr(SUMO_ATTR_PROGRAMID, (*it)->getProgramID());
into.writeAttr(SUMO_ATTR_OFFSET, writeSUMOTime((*it)->getOffset()));
// write params
const std::map<std::string, std::string>& params = (*it)->getMap();
for (std::map<std::string, std::string>::const_iterator i = params.begin(); i != params.end(); ++i) {
into.openTag(SUMO_TAG_PARAM);
into.writeAttr(SUMO_ATTR_KEY, (*i).first);
into.writeAttr(SUMO_ATTR_VALUE, (*i).second);
into.closeTag();
}
// write the phases
const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = (*it)->getPhases();
for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator j = phases.begin(); j != phases.end(); ++j) {
into.openTag(SUMO_TAG_PHASE);
into.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(j->duration));
into.writeAttr(SUMO_ATTR_STATE, j->state);
into.closeTag();
}
into.closeTag();
}
if (logics.size() > 0) {
into.lf();
}
}
示例3: generateNodeClusters
void
NBNodeCont::joinTLS(NBTrafficLightLogicCont& tlc, SUMOReal maxdist) {
std::vector<std::set<NBNode*> > cands;
generateNodeClusters(maxdist, cands);
unsigned int index = 0;
for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
std::set<NBNode*>& c = (*i);
for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
if (!(*j)->isTLControlled()) {
c.erase(j++);
} else {
++j;
}
}
if (c.size() < 2) {
continue;
}
// figure out type of the joined TLS
Position dummyPos;
bool dummySetTL;
std::string dummyId;
TrafficLightType type;
analyzeCluster(c, dummyId, dummyPos, dummySetTL, type);
for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); ++j) {
std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
(*j)->removeTrafficLights();
for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
tlc.removeFully((*j)->getID());
}
}
std::string id = "joinedS_" + toString(index++);
std::vector<NBNode*> nodes;
for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); j++) {
nodes.push_back(*j);
}
NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, nodes, 0, type);
if (!tlc.insert(tlDef)) {
// actually, nothing should fail here
WRITE_WARNING("Could not build a joined tls.");
delete tlDef;
return;
}
}
}
示例4: NBLoadedTLDef
bool
NIVissimTL::dict_SetSignals(NBTrafficLightLogicCont& tlc,
NBEdgeCont& ec) {
size_t ref = 0;
size_t ref_groups = 0;
size_t ref_signals = 0;
size_t no_signals = 0;
size_t no_groups = 0;
for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
NIVissimTL* tl = (*i).second;
/* if(tl->myType!="festzeit") {
cout << " Warning: The traffic light '" << tl->myID
<< "' could not be assigned to a node." << endl;
ref++;
continue;
}*/
std::string id = toString<int>(tl->myID);
TrafficLightType type = ((tl->getType() == "festzeit" || tl->getType() == "festzeit_fake") ?
TLTYPE_STATIC : TLTYPE_ACTUATED);
NBLoadedTLDef* def = new NBLoadedTLDef(id, 0, type);
if (!tlc.insert(def)) {
WRITE_ERROR("Error on adding a traffic light\n Must be a multiple id ('" + id + "')");
continue;
}
def->setCycleDuration((unsigned int) tl->myAbsDuration);
// add each group to the node's container
SGroupDictType sgs = NIVissimTLSignalGroup::getGroupsFor(tl->getID());
for (SGroupDictType::const_iterator j = sgs.begin(); j != sgs.end(); j++) {
if (!(*j).second->addTo(def)) {
WRITE_WARNING("The signal group '" + toString<int>((*j).first) + "' could not be assigned to tl '" + toString<int>(tl->myID) + "'.");
ref_groups++;
}
no_groups++;
}
// add the signal group signals to the node
SSignalDictType signals = NIVissimTLSignal::getSignalsFor(tl->getID());
for (SSignalDictType::const_iterator k = signals.begin(); k != signals.end(); k++) {
if (!(*k).second->addTo(ec, def)) {
WRITE_WARNING("The signal '" + toString<int>((*k).first) + "' could not be assigned to tl '" + toString<int>(tl->myID) + "'.");
ref_signals++;
}
no_signals++;
}
}
if (ref != 0) {
WRITE_WARNING("Could not set " + toString<size_t>(ref) + " of " + toString<size_t>(myDict.size()) + " traffic lights.");
}
if (ref_groups != 0) {
WRITE_WARNING("Could not set " + toString<size_t>(ref_groups) + " of " + toString<size_t>(no_groups) + " groups.");
}
if (ref_signals != 0) {
WRITE_WARNING("Could not set " + toString<size_t>(ref_signals) + " of " + toString<size_t>(no_signals) + " signals.");
}
return true;
}
示例5: NBOwnTLDef
void
NBNodeCont::setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc,
TrafficLightType type, std::string id) {
if (id == "") {
id = node->getID();
}
NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, node, 0, type);
if (!tlc.insert(tlDef)) {
// actually, nothing should fail here
WRITE_WARNING("Building a tl-logic for node '" + id + "' twice is not possible.");
delete tlDef;
return;
}
}
示例6: erase
unsigned int
NBNodeCont::removeUnwishedNodes(NBDistrictCont& dc, NBEdgeCont& ec,
NBJoinedEdgesMap& je, NBTrafficLightLogicCont& tlc,
bool removeGeometryNodes) {
unsigned int no = 0;
std::vector<NBNode*> toRemove;
for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
NBNode* current = (*i).second;
bool remove = false;
std::vector<std::pair<NBEdge*, NBEdge*> > toJoin;
// check for completely empty nodes
if (current->getOutgoingEdges().size() == 0 && current->getIncomingEdges().size() == 0) {
// remove if empty
remove = true;
}
// check for nodes which are only geometry nodes
if (removeGeometryNodes) {
if ((current->getOutgoingEdges().size() == 1 && current->getIncomingEdges().size() == 1)
||
(current->getOutgoingEdges().size() == 2 && current->getIncomingEdges().size() == 2)) {
// ok, one in, one out or two in, two out
// -> ask the node whether to join
remove = current->checkIsRemovable();
if (remove) {
toJoin = current->getEdgesToJoin();
}
}
}
// remove the node and join the geometries when wished
if (!remove) {
continue;
}
for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
NBEdge* begin = (*j).first;
NBEdge* continuation = (*j).second;
begin->append(continuation);
continuation->getToNode()->replaceIncoming(continuation, begin, 0);
tlc.replaceRemoved(continuation, -1, begin, -1);
je.appended(begin->getID(), continuation->getID());
ec.erase(dc, continuation);
}
toRemove.push_back(current);
no++;
}
// erase all
for (std::vector<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
erase(*j);
}
return no;
}
示例7:
void
NBNodeCont::discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike) {
for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
NBNode* node = i->second;
if (!geometryLike || node->geometryLike()) {
// make a copy of tldefs
const std::set<NBTrafficLightDefinition*> tldefs = node->getControllingTLS();
for (std::set<NBTrafficLightDefinition*>::const_iterator it = tldefs.begin(); it != tldefs.end(); ++it) {
NBTrafficLightDefinition* tlDef = *it;
node->removeTrafficLight(tlDef);
tlc.extract(tlDef);
}
node->reinit(node->getPosition(), NODETYPE_UNKNOWN);
}
}
}
示例8: sort
void
NBEdgeCont::joinSameNodeConnectingEdges(NBDistrictCont& dc,
NBTrafficLightLogicCont& tlc,
EdgeVector edges) {
// !!! Attention!
// No merging of the geometry to come is being done
// The connections are moved from one edge to another within
// the replacement where the edge is a node's incoming edge.
// count the number of lanes, the speed and the id
unsigned int nolanes = 0;
SUMOReal speed = 0;
int priority = 0;
std::string id;
sort(edges.begin(), edges.end(), NBContHelper::same_connection_edge_sorter());
// retrieve the connected nodes
NBEdge* tpledge = *(edges.begin());
NBNode* from = tpledge->getFromNode();
NBNode* to = tpledge->getToNode();
EdgeVector::const_iterator i;
for (i = edges.begin(); i != edges.end(); i++) {
// some assertions
assert((*i)->getFromNode() == from);
assert((*i)->getToNode() == to);
// ad the number of lanes the current edge has
nolanes += (*i)->getNumLanes();
// build the id
if (i != edges.begin()) {
id += "+";
}
id += (*i)->getID();
// compute the speed
speed += (*i)->getSpeed();
// build the priority
priority = MAX2(priority, (*i)->getPriority());
}
speed /= edges.size();
// build the new edge
// @bug new edge does not know about allowed vclass of old edges
// @bug both the width and the offset are not regarded
NBEdge* newEdge = new NBEdge(id, from, to, "", speed, nolanes, priority,
NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET,
tpledge->getStreetName(), tpledge->myLaneSpreadFunction);
insert(newEdge, true);
// replace old edge by current within the nodes
// and delete the old
from->replaceOutgoing(edges, newEdge);
to->replaceIncoming(edges, newEdge);
// patch connections
// add edge2edge-information
for (i = edges.begin(); i != edges.end(); i++) {
EdgeVector ev = (*i)->getConnectedEdges();
for (EdgeVector::iterator j = ev.begin(); j != ev.end(); j++) {
newEdge->addEdge2EdgeConnection(*j);
}
}
// move lane2lane-connections
unsigned int currLane = 0;
for (i = edges.begin(); i != edges.end(); i++) {
newEdge->moveOutgoingConnectionsFrom(*i, currLane);
currLane += (*i)->getNumLanes();
}
// patch tl-information
currLane = 0;
for (i = edges.begin(); i != edges.end(); i++) {
unsigned int noLanes = (*i)->getNumLanes();
for (unsigned int j = 0; j < noLanes; j++, currLane++) {
// replace in traffic lights
tlc.replaceRemoved(*i, j, newEdge, currLane);
}
}
// delete joined edges
for (i = edges.begin(); i != edges.end(); i++) {
erase(dc, *i);
}
}
示例9: ProcessError
void
NBNodeCont::guessTLs(OptionsCont& oc, NBTrafficLightLogicCont& tlc) {
// build list of definitely not tls-controlled junctions
std::vector<NBNode*> ncontrolled;
if (oc.isSet("tls.unset")) {
std::vector<std::string> notTLControlledNodes = oc.getStringVector("tls.unset");
for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
NBNode* n = NBNodeCont::retrieve(*i);
if (n == 0) {
throw ProcessError(" The node '" + *i + "' to set as not-controlled is not known.");
}
std::set<NBTrafficLightDefinition*> tls = n->getControllingTLS();
for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
(*j)->removeNode(n);
}
n->removeTrafficLights();
ncontrolled.push_back(n);
}
}
TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type"));
// loop#1 checking whether the node shall be tls controlled,
// because it is assigned to a district
if (oc.exists("tls.taz-nodes") && oc.getBool("tls.taz-nodes")) {
for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
NBNode* cur = (*i).second;
if (cur->isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
setAsTLControlled(cur, tlc, type);
}
}
}
// maybe no tls shall be guessed
if (!oc.getBool("tls.guess")) {
return;
}
// guess joined tls first, if wished
if (oc.getBool("tls.join")) {
// get node clusters
std::vector<std::set<NBNode*> > cands;
generateNodeClusters(oc.getFloat("tls.join-dist"), cands);
// check these candidates (clusters) whether they should be controlled by a tls
for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
std::set<NBNode*>& c = (*i);
// regard only junctions which are not yet controlled and are not
// forbidden to be controlled
for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
c.erase(j++);
} else {
++j;
}
}
// check whether the cluster should be controlled
if (!shouldBeTLSControlled(c)) {
i = cands.erase(i);
} else {
++i;
}
}
// cands now only contain sets of junctions that shall be joined into being tls-controlled
unsigned int index = 0;
for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
std::vector<NBNode*> nodes;
for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
nodes.push_back(*j);
}
std::string id = "joinedG_" + toString(index++);
NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, nodes, 0, type);
if (!tlc.insert(tlDef)) {
// actually, nothing should fail here
WRITE_WARNING("Could not build guessed, joined tls");
delete tlDef;
return;
}
}
}
// guess tls
for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
NBNode* cur = (*i).second;
// do nothing if already is tl-controlled
if (cur->isTLControlled()) {
continue;
}
// do nothing if in the list of explicit non-controlled junctions
if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
continue;
}
std::set<NBNode*> c;
c.insert(cur);
if (!shouldBeTLSControlled(c) || cur->getIncomingEdges().size() < 3) {
continue;
}
setAsTLControlled((*i).second, tlc, type);
}
}