本文整理汇总了C++中NBEdge::mayBeTLSControlled方法的典型用法代码示例。如果您正苦于以下问题:C++ NBEdge::mayBeTLSControlled方法的具体用法?C++ NBEdge::mayBeTLSControlled怎么用?C++ NBEdge::mayBeTLSControlled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBEdge
的用法示例。
在下文中一共展示了NBEdge::mayBeTLSControlled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessError
void
NBTrafficLightDefinition::collectAllLinks() {
myControlledLinks.clear();
int tlIndex = 0;
// build the list of links which are controled by the traffic light
for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
NBEdge* incoming = *i;
unsigned int noLanes = incoming->getNumLanes();
for (unsigned int j = 0; j < noLanes; j++) {
std::vector<NBEdge::Connection> connected = incoming->getConnectionsFromLane(j);
for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
const NBEdge::Connection& el = *k;
if (incoming->mayBeTLSControlled(el.fromLane, el.toEdge, el.toLane)) {
if (el.toEdge != 0 && el.toLane >= (int) el.toEdge->getNumLanes()) {
throw ProcessError("Connection '" + incoming->getID() + "_" + toString(j) + "->" + el.toEdge->getID() + "_" + toString(el.toLane) + "' yields in a not existing lane.");
}
if (incoming->getToNode()->getType() != NODETYPE_RAIL_CROSSING || !isRailway(incoming->getPermissions())) {
myControlledLinks.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, tlIndex++));
} else {
myControlledLinks.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, -1));
}
}
}
}
}
}
示例2: while
std::set<NBEdge*>
NBTrafficLightDefinition::collectReachable(EdgeVector outer, const EdgeVector& within, bool checkControlled) {
std::set<NBEdge*> reachable;
while (outer.size() > 0) {
NBEdge* from = outer.back();
outer.pop_back();
std::vector<NBEdge::Connection>& cons = from->getConnections();
for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
NBEdge* to = (*k).toEdge;
if (reachable.count(to) == 0 &&
(find(within.begin(), within.end(), to) != within.end()) &&
(!checkControlled || from->mayBeTLSControlled((*k).fromLane, to, (*k).toLane))) {
reachable.insert(to);
outer.push_back(to);
}
}
}
return reachable;
}
示例3: ProcessError
void
NBOwnTLDef::collectLinks() throw(ProcessError) {
// build the list of links which are controled by the traffic light
for (EdgeVector::iterator i=myIncomingEdges.begin(); i!=myIncomingEdges.end(); i++) {
NBEdge *incoming = *i;
unsigned int noLanes = incoming->getNoLanes();
for (unsigned int j=0; j<noLanes; j++) {
std::vector<NBEdge::Connection> connected = incoming->getConnectionsFromLane(j);
for (std::vector<NBEdge::Connection>::iterator k=connected.begin(); k!=connected.end(); k++) {
const NBEdge::Connection &el = *k;
if (incoming->mayBeTLSControlled(el.fromLane, el.toEdge, el.toLane)) {
if (el.toEdge!=0&&el.toLane>=(int) el.toEdge->getNoLanes()) {
throw ProcessError("Connection '" + incoming->getID() + "_" + toString(j) + "->" + el.toEdge->getID() + "_" + toString(el.toLane) + "' yields in a not existing lane.");
}
myControlledLinks.push_back(NBConnection(incoming, j, el.toEdge, el.toLane));
}
}
}
}
}
示例4: state
NBTrafficLightLogic*
NBOwnTLDef::myCompute(const NBEdgeCont&,
unsigned int brakingTimeSeconds) {
const SUMOTime brakingTime = TIME2STEPS(brakingTimeSeconds);
const SUMOTime leftTurnTime = TIME2STEPS(6); // make configurable ?
// build complete lists first
const EdgeVector& incoming = getIncomingEdges();
EdgeVector fromEdges, toEdges;
std::vector<bool> isLeftMoverV, isTurnaround;
unsigned int noLanesAll = 0;
unsigned int noLinksAll = 0;
for (unsigned int i1 = 0; i1 < incoming.size(); i1++) {
unsigned int noLanes = incoming[i1]->getNumLanes();
noLanesAll += noLanes;
for (unsigned int i2 = 0; i2 < noLanes; i2++) {
NBEdge* fromEdge = incoming[i1];
std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
noLinksAll += (unsigned int) approached.size();
for (unsigned int i3 = 0; i3 < approached.size(); i3++) {
if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
--noLinksAll;
continue;
}
assert(i3 < approached.size());
NBEdge* toEdge = approached[i3].toEdge;
fromEdges.push_back(fromEdge);
//myFromLanes.push_back(i2);
toEdges.push_back(toEdge);
if (toEdge != 0) {
isLeftMoverV.push_back(
isLeftMover(fromEdge, toEdge)
||
fromEdge->isTurningDirectionAt(fromEdge->getToNode(), toEdge));
isTurnaround.push_back(
fromEdge->isTurningDirectionAt(
fromEdge->getToNode(), toEdge));
} else {
isLeftMoverV.push_back(true);
isTurnaround.push_back(true);
}
}
}
}
NBTrafficLightLogic* logic = new NBTrafficLightLogic(getID(), getProgramID(), noLinksAll, myOffset, myType);
EdgeVector toProc = incoming;
const SUMOTime greenTime = TIME2STEPS(OptionsCont::getOptions().getInt("tls.green.time"));
// build all phases
while (toProc.size() > 0) {
std::pair<NBEdge*, NBEdge*> chosen;
if (incoming.size() == 2) {
chosen = std::pair<NBEdge*, NBEdge*>(toProc[0], static_cast<NBEdge*>(0));
toProc.erase(toProc.begin());
} else {
chosen = getBestPair(toProc);
}
unsigned int pos = 0;
std::string state((size_t) noLinksAll, 'o');
// plain straight movers
for (unsigned int i1 = 0; i1 < (unsigned int) incoming.size(); ++i1) {
NBEdge* fromEdge = incoming[i1];
const bool inChosen = fromEdge == chosen.first || fromEdge == chosen.second; //chosen.find(fromEdge)!=chosen.end();
const unsigned int numLanes = fromEdge->getNumLanes();
for (unsigned int i2 = 0; i2 < numLanes; i2++) {
std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
for (unsigned int i3 = 0; i3 < approached.size(); ++i3) {
if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
continue;
}
if (inChosen) {
state[pos] = 'G';
} else {
state[pos] = 'r';
}
++pos;
}
}
}
// correct behaviour for those that are not in chosen, but may drive, though
for (unsigned int i1 = 0; i1 < pos; ++i1) {
if (state[i1] == 'G') {
continue;
}
bool isForbidden = false;
for (unsigned int i2 = 0; i2 < pos && !isForbidden; ++i2) {
if (state[i2] == 'G' && !isTurnaround[i2] &&
(forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1], true) || forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2], true))) {
isForbidden = true;
}
}
if (!isForbidden) {
state[i1] = 'G';
}
}
// correct behaviour for those that have to wait (mainly left-mover)
bool haveForbiddenLeftMover = false;
for (unsigned int i1 = 0; i1 < pos; ++i1) {
if (state[i1] != 'G') {
continue;
//.........这里部分代码省略.........
示例5: state
NBTrafficLightLogic *
NBOwnTLDef::myCompute(const NBEdgeCont &,
unsigned int brakingTime) throw() {
// build complete lists first
const EdgeVector &incoming = getIncomingEdges();
std::vector<NBEdge*> fromEdges, toEdges;
std::vector<bool> isLeftMoverV, isTurnaround;
unsigned int noLanesAll = 0;
unsigned int noLinksAll = 0;
for (unsigned int i1=0; i1<incoming.size(); i1++) {
unsigned int noLanes = incoming[i1]->getNoLanes();
noLanesAll += noLanes;
for (unsigned int i2=0; i2<noLanes; i2++) {
NBEdge *fromEdge = incoming[i1];
std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
noLinksAll += (unsigned int) approached.size();
for (unsigned int i3=0; i3<approached.size(); i3++) {
if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
--noLinksAll;
continue;
}
assert(i3<approached.size());
NBEdge *toEdge = approached[i3].toEdge;
fromEdges.push_back(fromEdge);
//myFromLanes.push_back(i2);
toEdges.push_back(toEdge);
if (toEdge!=0) {
isLeftMoverV.push_back(
isLeftMover(fromEdge, toEdge)
||
fromEdge->isTurningDirectionAt(fromEdge->getToNode(), toEdge));
isTurnaround.push_back(
fromEdge->isTurningDirectionAt(
fromEdge->getToNode(), toEdge));
} else {
isLeftMoverV.push_back(true);
isTurnaround.push_back(true);
}
}
}
}
NBTrafficLightLogic *logic = new NBTrafficLightLogic(getID(), "0", noLinksAll);
std::vector<NBEdge*> toProc = incoming;
// build all phases
while (toProc.size()>0) {
std::pair<NBEdge*, NBEdge*> chosen;
if (incoming.size()==2) {
chosen = std::pair<NBEdge*, NBEdge*>(toProc[0], static_cast<NBEdge*>(0));
toProc.erase(toProc.begin());
} else {
chosen = getBestPair(toProc);
}
unsigned int pos = 0;
unsigned int duration = 31;
if (OptionsCont::getOptions().isSet("traffic-light-green")) {
duration = OptionsCont::getOptions().getInt("traffic-light-green");
}
std::string state((size_t) noLinksAll, 'o');
// plain straight movers
for (unsigned int i1=0; i1<(unsigned int) incoming.size(); ++i1) {
NBEdge *fromEdge = incoming[i1];
bool inChosen = fromEdge==chosen.first||fromEdge==chosen.second;//chosen.find(fromEdge)!=chosen.end();
unsigned int noLanes = fromEdge->getNoLanes();
for (unsigned int i2=0; i2<noLanes; i2++) {
std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
for (unsigned int i3=0; i3<approached.size(); ++i3) {
if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
continue;
}
if (inChosen) {
state[pos] = 'G';
} else {
state[pos] = 'r';
}
++pos;
}
}
}
// correct behaviour for those that are not in chosen, but may drive, though
for (unsigned int i1=0; i1<pos; ++i1) {
if (state[i1]=='G') {
continue;
}
bool isForbidden = false;
for (unsigned int i2=0; i2<pos&&!isForbidden; ++i2) {
if (state[i2]=='G'&&!isTurnaround[i2]&&
(forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1], true)||forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2], true))) {
isForbidden = true;
}
}
if (!isForbidden) {
state[i1] = 'G';
}
}
// correct behaviour for those that have to wait (mainly left-mover)
bool haveForbiddenLeftMover = false;
for (unsigned int i1=0; i1<pos; ++i1) {
if (state[i1]!='G') {
//.........这里部分代码省略.........