本文整理汇总了C++中MutableContainer类的典型用法代码示例。如果您正苦于以下问题:C++ MutableContainer类的具体用法?C++ MutableContainer怎么用?C++ MutableContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutableContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
//=================================================================
bool BiconnectedTest::compute(const tlp::Graph* graph) {
if(graph->numberOfNodes() == 0) {
return true;
}
if (resultsBuffer.find(graph)!=resultsBuffer.end())
return resultsBuffer[graph];
MutableContainer<bool> mark;
mark.setAll(false);
MutableContainer<unsigned int> low;
MutableContainer<unsigned int> dfsNumber;
MutableContainer<node> supergraph;
unsigned int count = 1;
bool result = false;
Iterator<node> *it=graph->getNodes();
if (it->hasNext())
result=(biconnectedTest(graph,it->next(),mark,low,dfsNumber,supergraph,count));
delete it;
if (count!=graph->numberOfNodes()+1) {
result=false;
} //connected test
resultsBuffer[graph]=result;
graph->addListener(this);
return result;
}
示例2: sortNodesIncreasingOrder
/*
* Returns in sortedNodes the nodes n of g sorted in increasing
* order by value[n].
* Precondition:
* - value[n] <= numberOfNodes for all nodes n of g, where n is
* the number of
* nodes in g
*/
void PlanarityTestImpl::sortNodesIncreasingOrder(Graph *g, MutableContainer<int> &value,
vector<node> &sortedNodes) {
// Counting sort;
int numberOfNodes = g->numberOfNodes();
// array<int, numberOfNodes + 1> c;
vector<int> c(numberOfNodes + 1);
for (int i = 1; i <= numberOfNodes; ++i)
c[i] = 0;
// array<node, numberOfNodes + 1> a;
vector<node> a(numberOfNodes + 1);
int j = 0;
// forall_nodes(n, g)
for (auto n : g->nodes()) {
a[++j] = n;
}
for (int i = 1; i <= numberOfNodes; ++i) {
unsigned int tmp = value.get(a[i].id);
++c[tmp];
}
for (int i = 2; i <= numberOfNodes; ++i)
c[i] += c[i - 1];
for (int i = numberOfNodes; i > 0; i--) {
sortedNodes[c[value.get(a[i].id)]] = a[i];
c[value.get(a[i].id)]--;
}
}
示例3: getDist
unsigned int getDist(Graph *g, node n1, node n2) {
vector<node> nextNodes;
TLP_HASH_MAP<node, unsigned int> nodeDepth;
MutableContainer<bool> alreadyTreated;
bool found = false;
alreadyTreated.setAll(false);
nextNodes.push_back(n1);
nodeDepth[n1] = 0;
alreadyTreated.set(n1.id, true);
for (unsigned int i = 0; !found && i < nextNodes.size(); ++i) {
node current = nextNodes[i];
for (auto v : g->getInOutNodes(current)) {
if (alreadyTreated.get(v.id))
continue;
alreadyTreated.set(v.id, true);
nextNodes.push_back(v);
nodeDepth[v] = nodeDepth[current] + 1;
if (v == n2) {
found = true;
break;
}
}
}
return nodeDepth[n2];
}
示例4: posDFS
//=================================================================
list<edge> posDFS(Graph *sG, MutableContainer<int> &dfsPos) {
list<edge> dfsEdges;
MutableContainer<int> dfsPre;
dfsPre.setAll(0);
unsigned int preCount = 0;
unsigned int postCount = 0;
for (auto n : sG->nodes()) {
if (dfsPre.get(n.id) == 0)
dfsAux(sG, n, dfsPre, dfsPos, dfsEdges, preCount, postCount);
}
return dfsEdges;
}
示例5: dfsAux
//=================================================================
static void dfsAux(Graph *sG, node n, MutableContainer<int> &dfsPre, MutableContainer<int> &dfsPos,
list<edge> &dfsEdges, unsigned int &preCount, unsigned int &postCount) {
dfsPre.set(n.id, ++preCount);
for (auto e : sG->getOutEdges(n)) {
node target = sG->target(e);
if (dfsPre.get(target.id) == 0) {
dfsEdges.push_back(e);
dfsAux(sG, target, dfsPre, dfsPos, dfsEdges, preCount, postCount);
}
}
dfsPos.set(n.id, ++postCount);
}
示例6: isFreeTree
// Determines if the given graph is topologically a tree
bool TreeTest::isFreeTree(const Graph *graph, node curRoot) {
// do a dfs traversal from curRoot;
MutableContainer<bool> visited;
visited.setAll(false);
stack<dfsFreeTreeStruct> dfsLevels;
dfsFreeTreeStruct curParams(curRoot, curRoot, graph->getInOutNodes(curRoot));
dfsLevels.push(curParams);
while (!dfsLevels.empty()) {
curParams = dfsLevels.top();
curRoot = curParams.curRoot;
node cameFrom = curParams.cameFrom;
Iterator<node> *neighbours = curParams.neighbours;
// set neighbours member to nullptr
// to avoid twice deletion on exit
curParams.neighbours = nullptr;
if (!neighbours->hasNext()) {
dfsLevels.pop();
} else {
visited.set(curRoot.id, true);
// loop on remaining neighbours
while (neighbours->hasNext()) {
node curNode = neighbours->next();
// check self loop
if (curNode == curRoot) {
return false;
}
if (curNode != cameFrom) {
if (visited.get(curNode.id)) {
return false;
}
// go deeper in the dfs exploration
curParams.curRoot = curNode;
curParams.cameFrom = curRoot;
curParams.neighbours = graph->getInOutNodes(curNode);
dfsLevels.push(curParams);
break;
}
}
}
}
return true;
} // end isFreeTree
示例7: initGlyphList
//====================================================
void EdgeExtremityGlyphManager::initGlyphList(Graph **graph,
GlGraphInputData* glGraphInputData, MutableContainer<
EdgeExtremityGlyph *>& glyphs) {
GlyphContext gc = GlyphContext(graph,
glGraphInputData);
glyphs.setAll(0);
static std::list<std::string> plugins = PluginLister::instance()->availablePlugins<EdgeExtremityGlyph>();
for(std::list<std::string>::const_iterator it = plugins.begin(); it != plugins.end(); ++it) {
string glyphName = *it;
EdgeExtremityGlyph *newGlyph = PluginLister::instance()->getPluginObject<EdgeExtremityGlyph>(glyphName, &gc);
glyphs.set(PluginLister::pluginInformation(glyphName).id(), newGlyph);
}
}
示例8: clearGlyphList
void EdgeExtremityGlyphManager::clearGlyphList(Graph **, GlGraphInputData*, MutableContainer<EdgeExtremityGlyph *>& glyphs) {
static std::list<std::string> plugins = PluginLister::instance()->availablePlugins<EdgeExtremityGlyph>();
for(std::list<std::string>::const_iterator it = plugins.begin(); it != plugins.end(); ++it) {
string glyphName = *it;
delete glyphs.get(PluginLister::pluginInformation(glyphName).id());
}
}
示例9: posDFS
//=================================================================
list<edge> posDFS(Graph *sG,
MutableContainer<int> &dfsPos) {
list<edge> dfsEdges;
MutableContainer<int> dfsPre;
dfsPre.setAll(0);
preCount = postCount = 1;
StableIterator<node> it(sG->getNodes());
while (it.hasNext()) {
node n = it.next();
if (dfsPre.get(n.id) == 0)
dfsAux(sG, n, dfsPre, dfsPos, dfsEdges);
}
return dfsEdges;
}
示例10: dfsAux
void dfsAux(Graph *sG, node n,
MutableContainer<int>& dfsPre,
MutableContainer<int>& dfsPos,
list<edge>& dfsEdges) {
dfsPre.set(n.id, preCount++);
StableIterator<edge> it(sG->getOutEdges(n));
while (it.hasNext()) {
edge e = it.next();
node target = sG->target(e);
if (dfsPre.get(target.id) == 0) {
dfsEdges.push_back(e);
dfsAux(sG, target, dfsPre, dfsPos, dfsEdges);
}
}
dfsPos.set(n.id, postCount++);
}
示例11: itemize
PosibErr<void> itemize (ParmString s, MutableContainer & d) {
ItemizeTokenizer els(s);
ItemizeItem li;
while (li = els.next(), li.name != 0) {
switch (li.action) {
case '+':
RET_ON_ERR(d.add(li.name));
break;
case '-':
RET_ON_ERR(d.remove(li.name));
break;
case '!':
RET_ON_ERR(d.clear());
break;
default:
abort();
}
}
return no_err;
}
示例12: setEdgeOrder
/**
* \brief Set the ordering of edges around n according to their order in v.
*/
void GraphStorage::setEdgeOrder(const node n, const std::vector<edge> &v ) {
if (v.empty()) return;
MutableContainer<int> isEle;
isEle.setAll(0);
for (std::vector<edge>::const_iterator it=v.begin(); it!=v.end(); ++it) {
isEle.add(it->id, 1);
}
std::vector<edge>::const_iterator it2=v.begin();
EdgeVector& currentOrder = nodes[n.id].edges;
for (unsigned int i=0; i<currentOrder.size(); ++i) {
if ( isEle.get(currentOrder[i].id)>0 ) {
isEle.add(currentOrder[i].id, -1);
currentOrder[i] = *it2;
++it2;
}
}
}
示例13: lcaBetween
//=================================================================
node PlanarityTestImpl::lcaBetween(node n1,
node n2,
const MutableContainer<node> &p) {
if (isCNode(n1)) {
node n = activeCNodeOf(false, n1);
n1 = p.get(n.id);
}
if (isCNode(n2)) {
node n = activeCNodeOf(false, n2);
n2 = p.get(n.id);
}
if (dfsPosNum.get(n1.id) > dfsPosNum.get(n2.id))
swapNode(n1, n2);
list<node> nl;
while (dfsPosNum.get(n1.id) < dfsPosNum.get(n2.id)) {
nl.push_front(n1);
n1 = p.get(n1.id);
}
node u = NULL_NODE;
if (nl.size() > 0) {
u = nl.front();
nl.pop_front();
}
while (n2 != u && n2 != n1 && dfsPosNum.get(n2.id) < dfsPosNum.get(n1.id)) {
nl.push_front(n2);
n2 = p.get(n2.id);
}
if (n2 == u || n2 == n1)
return n2;
return nl.front();
}
示例14: sortNodesIncreasingOrder
/*
* Returns in sortedNodes the nodes n of g sorted in increasing
* order by value[n].
* Precondition:
* - value[n] <= numberOfNodes for all nodes n of g, where n is
* the number of
* nodes in g
*/
void PlanarityTestImpl::sortNodesIncreasingOrder(Graph *g, MutableContainer<int> &value,
vector<node> &sortedNodes) {
// Counting sort;
int numberOfNodes = g->numberOfNodes();
//array<int, numberOfNodes + 1> c;
vector<int> c(numberOfNodes + 1);
for (int i = 1 ; i <= numberOfNodes ; i++)
c[i] = 0;
//array<node, numberOfNodes + 1> a;
vector<node> a(numberOfNodes + 1);
int j = 0;
node n;
// forall_nodes(n, g)
Iterator<node> *it = g->getNodes();
while (it->hasNext()) {
//a[++j] = n;
a[++j] = it->next();
}
delete it;
for (int i = 1 ; i <= numberOfNodes ; i++) {
unsigned int tmp = value.get(a[i].id);
c[tmp]++;
}
for (int i = 2 ; i <= numberOfNodes ; i++)
c[i] += c[i-1];
for (int i = numberOfNodes ; i > 0 ; i--) {
sortedNodes[c[value.get(a[i].id)]] = a[i];
c[value.get(a[i].id)]--;
}
}
示例15: run
bool run() {
result->setAllNodeValue(0.0);
result->setAllEdgeValue(0.0);
bool directed = false;
bool norm = false;
if ( dataSet!=NULL ) {
dataSet->get("directed",directed);
dataSet->get("norm", norm);
}
//Metric is 0 in this case
if(graph->numberOfNodes()<=2) return true;
Iterator<node> *it = graph->getNodes();
unsigned int count = 0;
while(it->hasNext()) {
if (pluginProgress->progress(count++,graph->numberOfNodes())!=TLP_CONTINUE) break;
node s = it->next();
stack<node> S;
TLP_HASH_MAP<node, list<node> > P;
MutableContainer<int> sigma;
sigma.setAll(0);
sigma.set(s.id,1);
MutableContainer<int> d;
d.setAll(-1);
d.set(s.id, 0);
queue<node> Q;
Q.push(s);
while(!Q.empty()) {
node v = Q.front();
Q.pop();
S.push(v);
Iterator<node> *it2;
if (directed)
it2 = graph->getOutNodes(v);
else
it2 = graph->getInOutNodes(v);
while (it2->hasNext()) {
node w = it2->next();
if (d.get(w.id)<0) {
Q.push(w);
d.set(w.id, d.get(v.id)+1);
}
if (d.get(w.id) == d.get(v.id)+1) {
sigma.add(w.id, sigma.get(v.id));
P[w].push_back(v);
}
}
delete it2;
}
MutableContainer<double> delta;
delta.setAll(0.0);
while(!S.empty()) {
node w = S.top();
S.pop();
list<node>::const_iterator itn = P[w].begin();
for (; itn!=P[w].end(); ++itn) {
node v = *itn;
delta.add(v.id, (double(sigma.get(v.id)) / double(sigma.get(w.id)) * (1.0 + delta.get(w.id))));
edge e = graph->existEdge(v,w,directed);
if(e.isValid())
result->setEdgeValue(e, result->getEdgeValue(e) + double(sigma.get(v.id)) / double(sigma.get(w.id)) * (1.0 + delta.get(w.id)));
}
if (w != s) result->setNodeValue(w, result->getNodeValue(w) + delta.get(w.id));
}
}
delete it;
//Normalization
if(norm || !directed) {
double n = graph->numberOfNodes();
it = graph->getNodes();
while(it->hasNext()) {
node s = it->next();
//In the undirected case, the metric must be divided by two, then
if(norm)
result->setNodeValue(s,result->getNodeValue(s)/((n-1.0)*(n-2.0)));
if(!directed)
result->setNodeValue(s,result->getNodeValue(s)/2.0);
}
delete it;
//.........这里部分代码省略.........