COIN-OR::LEMON - Graph Library

Changeset 2402:da8eb8f4ea41 in lemon-0.x for tools


Ignore:
Timestamp:
03/12/07 14:26:56 (17 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3233
Message:

An improved version of ArgParser?: You don't need to give an explicit storage
for each option.
TODO: Documentation must be updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/lgf-gen.cc

    r2391 r2402  
    3030#include <algorithm>
    3131#include <lemon/unionfind.h>
     32#include <lemon/time_measure.h>
    3233
    3334using namespace lemon;
     
    3738UGRAPH_TYPEDEFS(ListUGraph);
    3839
     40bool progress=true;
     41
    3942int N;
    40 int girth;
     43// int girth;
    4144
    4245ListUGraph g;
     
    235238
    236239void minTree() {
     240  int en=0;
     241  int pr=0;
    237242  std::vector<Pedge> pedges;
     243  Timer T;
     244  std::cout << T.realTime() << "s: Setting up the edges...\n";
    238245  for(NodeIt n(g);n!=INVALID;++n)
    239     for(NodeIt m=++(NodeIt(n));m!=INVALID;++m)
    240       {
    241         Pedge p;
    242         p.a=n;
    243         p.b=m;
    244         p.len=(coords[m]-coords[n]).normSquare();
    245         pedges.push_back(p);
    246       }
     246    {
     247      for(NodeIt m=++(NodeIt(n));m!=INVALID;++m)
     248        {
     249          Pedge p;
     250          p.a=n;
     251          p.b=m;
     252          p.len=(coords[m]-coords[n]).normSquare();
     253          pedges.push_back(p);
     254        }
     255      en++;
     256      if(progress && en>=pr*double(N)/100)
     257        {
     258          std::cout << pr << "%  \r" << std::flush;
     259          pr++;
     260        }
     261    }
     262  std::cout << T.realTime() << "s: Sorting the edges...\n";
    247263  std::sort(pedges.begin(),pedges.end(),pedgeLess);
     264  std::cout << T.realTime() << "s: Creating the tree...\n";
    248265  ListUGraph::NodeMap<int> comp(g);
    249266  UnionFind<ListUGraph::NodeMap<int> > uf(comp);
    250267  for (NodeIt it(g); it != INVALID; ++it)
    251     uf.insert(it);
    252 
    253   int en=0;
     268    uf.insert(it); 
    254269  for(std::vector<Pedge>::iterator pi=pedges.begin();pi!=pedges.end();++pi)
    255270    {
    256271      if ( uf.join(pi->a,pi->b) ) {
    257272        g.addEdge(pi->a,pi->b);
    258         en++;
    259         if(en>=N-1) return;
    260       }
    261     }
     273        if(en>=N-1)
     274          break;
     275      }
     276    }
     277  std::cout << T.realTime() << "s: Done\n";
    262278}
    263279
     
    268284  ArgParser ap(argc,argv);
    269285
    270   bool eps;
     286//   bool eps;
    271287  bool disc_d, square_d, gauss_d;
    272   bool tsp_a,two_a,tree_a;
     288//   bool tsp_a,two_a,tree_a;
    273289  int num_of_cities=1;
    274290  double area=1;
    275291  N=100;
    276   girth=10;
     292//   girth=10;
    277293  std::string ndist("disc");
    278   ap.option("n", "Number of nodes (default is 100)", N)
    279     .option("g", "Girth parameter (default is 10)", girth)
    280     .option("cities", "Number of cities (default is 1)", num_of_cities)
    281     .option("area", "Full relative area of the cities (default is 1)", area)
    282     .option("disc", "Nodes are evenly distributed on a unit disc (default)",disc_d)
     294  ap.refOption("n", "Number of nodes (default is 100)", N)
     295    .intOption("g", "Girth parameter (default is 10)", 10)
     296    .refOption("cities", "Number of cities (default is 1)", num_of_cities)
     297    .refOption("area", "Full relative area of the cities (default is 1)", area)
     298    .refOption("disc", "Nodes are evenly distributed on a unit disc (default)",disc_d)
    283299    .optionGroup("dist", "disc")
    284     .option("square", "Nodes are evenly distributed on a unit square", square_d)
     300    .refOption("square", "Nodes are evenly distributed on a unit square", square_d)
    285301    .optionGroup("dist", "square")
    286     .option("gauss",
     302    .refOption("gauss",
    287303            "Nodes are located according to a two-dim gauss distribution",
    288304            gauss_d)
     
    290306//     .mandatoryGroup("dist")
    291307    .onlyOneGroup("dist")
    292     .option("eps", "Also generate .eps output (prefix.eps)",eps)
    293     .option("2con", "Create a two connected planar graph",two_a)
     308    .boolOption("eps", "Also generate .eps output (prefix.eps)")
     309    .boolOption("2con", "Create a two connected planar graph")
    294310    .optionGroup("alg","2con")
    295     .option("tree", "Create a min. cost spanning tree",tree_a)
     311    .boolOption("tree", "Create a min. cost spanning tree")
    296312    .optionGroup("alg","tree")
    297     .option("tsp", "Create a TSP tour",tsp_a)
     313    .boolOption("tsp", "Create a TSP tour")
    298314    .optionGroup("alg","tsp")
    299315    .onlyOneGroup("alg")
     
    353369    }
    354370 
    355   if(tsp_a) {
     371  if(ap["tsp"]) {
    356372    tsp();
    357373    std::cout << "#2-opt improvements: " << tsp_impr_num << std::endl;
    358374  }
    359   else if(two_a) {
     375  else if(ap["2con"]) {
    360376    std::cout << "Make triangles\n";
    361377    //   triangle();
    362     sparseTriangle(girth);
     378    sparseTriangle(ap["g"]);
    363379    std::cout << "Make it sparser\n";
    364     sparse2(girth);
     380    sparse2(ap["g"]);
    365381  }
    366   else if(tree_a) {
     382  else if(ap["tree"]) {
    367383    minTree();
    368384  }
     
    375391    tlen+=sqrt((coords[g.source(e)]-coords[g.target(e)]).normSquare());
    376392  std::cout << "Total edge length  : " << tlen << std::endl;
    377   if(eps)
     393  if(ap["eps"])
    378394    graphToEps(g,prefix+".eps").
    379395      scale(600).nodeScale(.2).edgeWidthScale(.001).preScale(false).
Note: See TracChangeset for help on using the changeset viewer.