test/graph_utils_test.cc
changeset 209 765619b7cbb2
parent 171 02f4d5d9bfd7
child 210 81cfc04531e8
equal deleted inserted replaced
1:5714295bdb46 2:1e2cee98e1f6
     1 /* -*- C++ -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2008
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
   138 
   138 
   139 template <class Digraph>
   139 template <class Digraph>
   140 void checkDeg()
   140 void checkDeg()
   141 {
   141 {
   142   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
   142   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
   143   
   143 
   144   const int nodeNum = 10;
   144   const int nodeNum = 10;
   145   const int arcNum = 100;
   145   const int arcNum = 100;
   146   Digraph digraph;
   146   Digraph digraph;
   147   InDegMap<Digraph> inDeg(digraph);
   147   InDegMap<Digraph> inDeg(digraph);
   148   OutDegMap<Digraph> outDeg(digraph);
   148   OutDegMap<Digraph> outDeg(digraph);
   153   std::vector<Arc> arcs(arcNum);
   153   std::vector<Arc> arcs(arcNum);
   154   for (int i = 0; i < arcNum; ++i) {
   154   for (int i = 0; i < arcNum; ++i) {
   155     arcs[i] = digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]);
   155     arcs[i] = digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]);
   156   }
   156   }
   157   for (int i = 0; i < nodeNum; ++i) {
   157   for (int i = 0; i < nodeNum; ++i) {
   158     check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), 
   158     check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]),
   159           "Wrong in degree map");
   159           "Wrong in degree map");
   160   }
   160   }
   161   for (int i = 0; i < nodeNum; ++i) {
   161   for (int i = 0; i < nodeNum; ++i) {
   162     check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), 
   162     check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]),
   163           "Wrong out degree map");
   163           "Wrong out degree map");
   164   }
   164   }
   165 }
   165 }
   166 
   166 
   167 template <class Digraph>
   167 template <class Digraph>
   170   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
   170   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
   171 
   171 
   172   Digraph g;
   172   Digraph g;
   173   Node n1=g.addNode();
   173   Node n1=g.addNode();
   174   Node n2=g.addNode();
   174   Node n2=g.addNode();
   175   
   175 
   176   InDegMap<Digraph> ind(g);
   176   InDegMap<Digraph> ind(g);
   177   
   177 
   178   g.addArc(n1,n2);
   178   g.addArc(n1,n2);
   179   
   179 
   180   typename Digraph::Snapshot snap(g);
   180   typename Digraph::Snapshot snap(g);
   181   
   181 
   182   OutDegMap<Digraph> outd(g);
   182   OutDegMap<Digraph> outd(g);
   183   
   183 
   184   check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
   184   check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
   185   check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
   185   check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
   186 
   186 
   187   g.addArc(n1,n2);
   187   g.addArc(n1,n2);
   188   g.addArc(n2,n1);
   188   g.addArc(n2,n1);