Esempio n. 1
0
/**
 *  \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;
    }
  }
}
Esempio n. 2
0
  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;
  }
    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;

            Iterator<edge> *itE = graph->getEdges();

            while(itE->hasNext()) {
                edge e = itE->next();

                if(norm)
                    result->setEdgeValue(e,4.0*result->getEdgeValue(e)/(n*n));

                if(!directed)
                    result->setEdgeValue(e,result->getEdgeValue(e)/(2.0));
            }

            delete itE;
        }


        return pluginProgress->state()!=TLP_CANCEL;
    }
Esempio n. 4
0
/*
 * Algebric criteria to check the plane map...
 */
bool PlanarityTestImpl::isPlanarEmbedding(Graph *sG) {
  int n = sG->numberOfNodes();

  if (n == 1)
    return true;

  int m = sG->numberOfEdges();
  unsigned int count = 0;
  MutableContainer<char> considered;
  MutableContainer<bool> sens;
  considered.setAll(0);
  sens.setAll(false);
  int fc = 0;

  //  displayMap(sG);
  for (int k=0; k<2; ++k) {
    Iterator<edge> *it = sG->getEdges();

    while (it->hasNext()) {
      edge e = it->next();

      if (considered.get(e.id)<2) {
        count = 0;
        //      cerr << "Face : " << fc << " start edge:" << e.id << endl;
        edge e1 = e;
        node n, n_tmp;

        if (sens.get(e.id))
          n = sG->target(e1);
        else
          n = sG->source(e1);

        //      cerr << "-(" << e1.id << ")->" << n.id << flush;
        n_tmp = n;

        do {
          considered.add(e1.id, 1);
          EdgeMapIterator it(sG, e1, n);
          e1 = it.next();
          n = sG->opposite(e1,n);

          if (sG->source(e1) == n)
            sens.set(e1.id,true);

          //  cerr << "-(" << e1.id << ")->" << n.id << flush;
          ++count;

          if (count > sG->numberOfEdges() +1) break;
        }
        while ((e1 != e)||(n != n_tmp));

        fc++;
        //  cerr << endl;
      }
    }

    delete it;
  }

  if (fc != m - n + 2) {
    //cerr << __PRETTY_FUNCTION__ << " : not ok :( nb faces :" << fc << "!=" << m - n +2 << endl;
    return false;
  }

  return true;
}