int edmondsKarp(int n, int m, int s, int t) { read(m); int ansFlow = 0; while(1) { for (int i = 0; i < n; i++) d[i] = INF, maxFlow[i] = 0; int head = 0, tail = 0; q[tail++] = s; d[s] = 0; maxFlow[s] = INF; while (tail - head > 0) { int v = q[head++]; for (int edge : g[v]) { auto &e = edges[edge]; if (d[e.u] > d[v] + 1 && e.c - e.f > 0) { d[e.u] = d[v] + 1; maxFlow[e.u] = min(maxFlow[e.v], e.c - e.f); q[tail++] = e.u; pr[e.u] = edge; } } } if (d[t] == INF) break; for (int u = t; u != s; u = edges[pr[u]].v) addFlow(pr[u], maxFlow[t]); ansFlow += maxFlow[t]; } return ansFlow; }
void SimpleController::onPacketIn(Channel *channel, const PacketIn *msg) { const EnetFrame *frame = Interpret_cast<EnetFrame>(msg->enetFrame().data()); if (msg->enetFrame().size() < 14) return; UInt32 inPort = msg->inPort(); UInt32 outPort; // Update forwarding table. if (!frame->src.isMulticast()) { fwdTable_[frame->src] = inPort; } if (frame->dst.isMulticast()) { flood(channel, msg); } else if (!lookupPort(frame->dst, &outPort)) { flood(channel, msg); } else if (outPort == inPort) { drop(channel, msg, frame, 10); } else { addFlow(channel, msg, frame, outPort); } }
void RODFDetectorFlows::mesoJoin(const std::string& nid, const std::vector<std::string>& oldids) { for (std::vector<std::string>::const_iterator i = oldids.begin(); i != oldids.end(); ++i) { if (!knows(*i)) { continue; } std::vector<FlowDef>& flows = myFastAccessFlows[*i]; size_t index = 0; for (SUMOTime t = myBeginTime; t != myEndTime; t += myStepOffset) { addFlow(nid, t, flows[index++]); // !!! } myFastAccessFlows.erase(*i); } }
/** Read one edge from an input stream and add it to this Wflograph. * @param in is an open input stream * @return true on success, else false */ bool Wflograph::readEdge(istream& in) { vertex u, v; flow capp, ff; floCost fc; if (Util::readNext(in,'(') == 0 || !Util::readNode(in,u,N) || Util::readNext(in,',') == 0 || !Util::readNode(in,v,N) || Util::readNext(in,',') == 0 || !Util::readNum(in,capp) || Util::readNext(in,',') == 0 || !Util::readNum(in,fc) || Util::readNext(in,',') == 0 || !Util::readNum(in,ff) || Util::readNext(in,')') == 0) return false; if (u < 1 || u > n() || v < 1 || v > n()) return false; edge e = join(u,v); setCapacity(e,capp); setCost(e,fc); addFlow(u,e,ff); return true; }
LeaderboardDialog::LeaderboardDialog( GuiFactory* factory ) : GeneralDialogBox(factory,factory->getLanguageManager(),factory->getGuiColorManager(),factory->getFontManager()) { m_container = addFlow(); m_container->setResizeRowToWidth(true); setOkText("close"); m_columnList.push_back("leaderboard.rating"); m_columnList.push_back("leaderboard.coins"); m_columnList.push_back("leaderboard.games.completed"); m_columnList.push_back("leaderboard.games.substituted"); m_columnList.push_back("leaderboard.games.abandoned"); m_drop = getFactory()->createDropDown(); m_drop->addSelectionListener(this); for(int i = 0; i < m_columnList.size(); i++) { m_drop->addItem(getFactory()->getLanguageManager()->getElement(m_columnList[i])); } m_drop->resizeToContents(); m_drop->setSelectedIndex(0); m_selColumn = m_columnList[m_drop->getSelectedIndex()]; m_parentWidgets.push_back(m_drop); }
void NMGMeasureListWidget::addPacketsFileInformation(NMGTestFileData& data, const QString& fileName) { QString filteredFile = fileName.mid(fileName.lastIndexOf("/")+1); QString testName = data.getMetadata()->getTestName(); NMGFlowOrientedResultData* result; result = (NMGFlowOrientedResultData*)data.getResultData(); if(result) { // Test addTest(fileName, QStringList() << filteredFile << testName); QMap<int,NMGFlowData*>::const_iterator it; for (it = result->constBegin(); it != result->constEnd(); it++) { // we must read flows info NMGFlowData* flow = it.value(); // we must read extra information located into metadata readFlowMetadataInfo(flow, data.getMetadata()->getUncommonElement(TAG_CONF_MGEN)); QStringList flowRow; // Flow id flowRow << QString::number(flow->getFlowId()); // Flow name flowRow << flow->getFlowName(); // Source QString infoIP = (flow->getSourceAddress().isEmpty() ? tr(NOT_AVAILABLE) : flow->getSourceAddress()); infoIP.append("/").append(flow->getSourcePort() < 0 ? tr(NOT_AVAILABLE) : QString::number(flow->getSourcePort())); flowRow << infoIP; // Destination infoIP = (flow->getDestinationAddress().isEmpty() ? tr(NOT_AVAILABLE) : flow->getDestinationAddress()); infoIP.append("/").append(flow->getDestinationPort() < 0 ? tr(NOT_AVAILABLE) : QString::number(flow->getDestinationPort())); flowRow << infoIP; // Duration flowRow << (flow->getElapsedTimeInMiliSeconds() < 0 ? tr(NOT_AVAILABLE) : simplifyTime(flow->getElapsedTimeInMiliSeconds(), NMGMeasureListWidget::MILISECS)); // Packet Rate flowRow << (flow->getPacketRate() < 0 ? tr(NOT_AVAILABLE) : QString::number(flow->getPacketRate())); // Packet Size flowRow << (flow->getPacketSize() < 0 ? tr(NOT_AVAILABLE) : QString::number(flow->getPacketSize())); // Pattern flowRow << (flow->getPattern().isEmpty() ? tr(NOT_AVAILABLE) : flow->getPattern()); addFlow(QString::number(flow->getFlowId()), flowRow); } } }