/// update - Recompute Value from Bias and Links. Return true when node /// preference changes. bool update(const Node nodes[]) { // Compute the weighted sum of inputs. BlockFrequency SumN = BiasN; BlockFrequency SumP = BiasP; for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I) { if (nodes[I->second].Value == -1) SumN += I->first; else if (nodes[I->second].Value == 1) SumP += I->first; } // Each weighted sum is going to be less than the total frequency of the // bundle. Ideally, we should simply set Value = sign(SumP - SumN), but we // will add a dead zone around 0 for two reasons: // // 1. It avoids arbitrary bias when all links are 0 as is possible during // initial iterations. // 2. It helps tame rounding errors when the links nominally sum to 0. // bool Before = preferReg(); if (SumN >= SumP + Threshold) Value = -1; else if (SumP >= SumN + Threshold) Value = 1; else Value = 0; return Before != preferReg(); }
/// addLink - Add a link to bundle b with weight w. /// out=0 for an ingoing link, and 1 for an outgoing link. void addLink(unsigned b, float w, bool out) { // Normalize w relative to all connected blocks from that direction. w /= Frequency[out]; // There can be multiple links to the same bundle, add them up. for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I) if (I->second == b) { I->first += w; return; } // This must be the first link to b. Links.push_back(std::make_pair(w, b)); }
/// addLink - Add a link to bundle b with weight w. void addLink(unsigned b, BlockFrequency w) { // Update cached sum. SumLinkWeights += w; // There can be multiple links to the same bundle, add them up. for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I) if (I->second == b) { I->first += w; return; } // This must be the first link to b. Links.push_back(std::make_pair(w, b)); }
/// update - Recompute Value from Bias and Links. Return true when node /// preference changes. bool update(const Node nodes[]) { // Compute the weighted sum of inputs. float Sum = Bias; for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I) Sum += I->first * nodes[I->second].Value; // The weighted sum is going to be in the range [-2;2]. Ideally, we should // simply set Value = sign(Sum), but we will add a dead zone around 0 for // two reasons: // 1. It avoids arbitrary bias when all links are 0 as is possible during // initial iterations. // 2. It helps tame rounding errors when the links nominally sum to 0. const float Thres = 1e-4f; bool Before = preferReg(); if (Sum < -Thres) Value = -1; else if (Sum > Thres) Value = 1; else Value = 0; return Before != preferReg(); }
bool ScaffoldLayoutVisitor::visit(ScaffoldGraph* pGraph, ScaffoldVertex* pVertex) { // Never re-classify repeats if(pVertex->getClassification() == SVC_REPEAT) return false; for(size_t idx = 0; idx < ED_COUNT; idx++) { EdgeDir dir = EDGE_DIRECTIONS[idx]; ScaffoldEdgePtrVector edgeVec = pVertex->getEdges(dir); if(edgeVec.size() <= 1) continue; ScaffoldGroup group(pVertex, 100); for(size_t i = 0; i < edgeVec.size(); ++i) group.addLink(edgeVec[i]->getLink(), edgeVec[i]->getEnd()); group.computeBestOrdering(); int longestOverlap = group.calculateLongestOverlap(); if(longestOverlap > 150) { std::cout << "cannot scaffold from " << pVertex->getID() << " OL: " << longestOverlap << "\n"; continue; } // Calculate the ordered set of links that would make up this scaffold std::cout << "Computing layout for " << pVertex->getID() << "\n"; LinkVector linearLinks; group.getLinearLinks(linearLinks); std::cout << "Linearized links:\n"; // Iterate through the linearized links and see if they are sane bool allResolved = true; ScaffoldVertex* pCurrStartVertex = pVertex; for(size_t i = 0; i < linearLinks.size(); ++i) { std::cout << "\t" << linearLinks[i] << "\n"; // Does a real link exist between the two vertices that are predicted to be linked? ScaffoldEdge* pRealEdge = pCurrStartVertex->findEdgeTo(linearLinks[i].endpointID, linearLinks[i].getDir(), linearLinks[i].getComp()); if(pRealEdge != NULL) { std::cout << "\t\tresolved:" << pRealEdge->getLink() << "\n"; } else { pCurrStartVertex->setClassification(SVC_REPEAT); allResolved = false; std::cout << "\t\tnotfound\n"; } ScaffoldVertex* pCurrEndVertex = pGraph->getVertex(linearLinks[i].endpointID); assert(pCurrEndVertex != NULL); pCurrStartVertex = pCurrEndVertex; } group.getSecondaryLinks(); if(allResolved) { // Removed all the edges for current vertex except for the first std::string firstID = linearLinks[0].endpointID; for(size_t i = 0; i < edgeVec.size(); ++i) { if(edgeVec[i]->getEndID() == firstID) { edgeVec[i]->setColor(GC_BLACK); edgeVec[i]->getTwin()->setColor(GC_BLACK); } } } } return false; }
/// clear - Reset per-query data, but preserve frequencies that only depend on // the CFG. void clear() { Bias = Value = 0; Links.clear(); }
void MSSOTLTrafficLightLogic::init(NLDetectorBuilder& nb) throw(ProcessError) { MSTrafficLightLogic::init(nb); if (isDecayThresholdActivated()) { decayThreshold = 1; } if (sensorsSelfBuilt) { //Building SOTLSensors switch (SENSORS_TYPE) { case SENSORS_TYPE_E1: assert(0); // Throw exception because TLS can only handle E2 sensors case SENSORS_TYPE_E2: //Adding Sensors to the ingoing Lanes LaneVectorVector lvv = getLaneVectors(); DBG( WRITE_MESSAGE("Listing lanes for TLS " + getID()); for (unsigned int i = 0; i < lvv.size(); i++) { LaneVector lv = lvv[i]; for (unsigned int j = 0; j < lv.size(); j++) { MSLane* lane = lv[j]; WRITE_MESSAGE(lane ->getID()); } } ) mySensors = new MSSOTLE2Sensors(myID, &(getPhases())); ((MSSOTLE2Sensors*)mySensors)->buildSensors(myLanes, nb, getInputSensorsLength()); mySensors->stepChanged(getCurrentPhaseIndex()); if (getParameter("USE_VEHICLE_TYPES_WEIGHTS", "0") == "1") { ((MSSOTLE2Sensors*) mySensors)->setVehicleWeigths(getParameter("VEHICLE_TYPES_WEIGHTS", "")); } //threshold speed param for tuning with irace ((MSSOTLE2Sensors*)mySensors)->setSpeedThresholdParam(getSpeedThreshold()); myCountSensors = new MSSOTLE2Sensors(myID + "Count", &(getPhases())); myCountSensors->buildCountSensors(myLanes, nb); myCountSensors->stepChanged(getCurrentPhaseIndex()); //Adding Sensors to the outgoing Lanes LinkVectorVector myLinks = getLinks(); DBG( WRITE_MESSAGE("Listing output lanes"); for (unsigned int i = 0; i < myLinks.size(); i++) { LinkVector oneLink = getLinksAt(i); for (unsigned int j = 0; j < oneLink.size(); j++) { MSLane* lane = oneLink[j]->getLane(); WRITE_MESSAGE(lane ->getID()); } } ) LaneVectorVector myLaneVector; LaneVector outLanes; LinkVectorVector myoutLinks = getLinks(); for (unsigned int i = 0; i < myLinks.size(); i++) { LinkVector oneLink = getLinksAt(i); for (unsigned int j = 0; j < oneLink.size(); j++) { MSLane* lane = oneLink[j]->getLane(); outLanes.push_back(lane); } } if (outLanes.size() > 0) { myLaneVector.push_back(outLanes); } if (myLaneVector.size() > 0) { ((MSSOTLE2Sensors*)mySensors)->buildOutSensors(myLaneVector, nb, getOutputSensorsLength()); myCountSensors->buildCountOutSensors(myLaneVector, nb); } }
/// clear - Reset per-query data, but preserve frequencies that only depend on // the CFG. void clear() { BiasN = BiasP = Value = 0; SumLinkWeights = Threshold; Links.clear(); }