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

Ignore:
Timestamp:
03/12/07 14:26:56 (17 years ago)
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

Unmodified
Removed
• ## tools/lgf-gen.cc

 r2391 #include #include #include using namespace lemon; UGRAPH_TYPEDEFS(ListUGraph); bool progress=true; int N; int girth; // int girth; ListUGraph g; void minTree() { int en=0; int pr=0; std::vector pedges; Timer T; std::cout << T.realTime() << "s: Setting up the edges...\n"; for(NodeIt n(g);n!=INVALID;++n) for(NodeIt m=++(NodeIt(n));m!=INVALID;++m) { Pedge p; p.a=n; p.b=m; p.len=(coords[m]-coords[n]).normSquare(); pedges.push_back(p); } { for(NodeIt m=++(NodeIt(n));m!=INVALID;++m) { Pedge p; p.a=n; p.b=m; p.len=(coords[m]-coords[n]).normSquare(); pedges.push_back(p); } en++; if(progress && en>=pr*double(N)/100) { std::cout << pr << "%  \r" << std::flush; pr++; } } std::cout << T.realTime() << "s: Sorting the edges...\n"; std::sort(pedges.begin(),pedges.end(),pedgeLess); std::cout << T.realTime() << "s: Creating the tree...\n"; ListUGraph::NodeMap comp(g); UnionFind > uf(comp); for (NodeIt it(g); it != INVALID; ++it) uf.insert(it); int en=0; uf.insert(it); for(std::vector::iterator pi=pedges.begin();pi!=pedges.end();++pi) { if ( uf.join(pi->a,pi->b) ) { g.addEdge(pi->a,pi->b); en++; if(en>=N-1) return; } } if(en>=N-1) break; } } std::cout << T.realTime() << "s: Done\n"; } ArgParser ap(argc,argv); bool eps; //   bool eps; bool disc_d, square_d, gauss_d; bool tsp_a,two_a,tree_a; //   bool tsp_a,two_a,tree_a; int num_of_cities=1; double area=1; N=100; girth=10; //   girth=10; std::string ndist("disc"); ap.option("n", "Number of nodes (default is 100)", N) .option("g", "Girth parameter (default is 10)", girth) .option("cities", "Number of cities (default is 1)", num_of_cities) .option("area", "Full relative area of the cities (default is 1)", area) .option("disc", "Nodes are evenly distributed on a unit disc (default)",disc_d) ap.refOption("n", "Number of nodes (default is 100)", N) .intOption("g", "Girth parameter (default is 10)", 10) .refOption("cities", "Number of cities (default is 1)", num_of_cities) .refOption("area", "Full relative area of the cities (default is 1)", area) .refOption("disc", "Nodes are evenly distributed on a unit disc (default)",disc_d) .optionGroup("dist", "disc") .option("square", "Nodes are evenly distributed on a unit square", square_d) .refOption("square", "Nodes are evenly distributed on a unit square", square_d) .optionGroup("dist", "square") .option("gauss", .refOption("gauss", "Nodes are located according to a two-dim gauss distribution", gauss_d) //     .mandatoryGroup("dist") .onlyOneGroup("dist") .option("eps", "Also generate .eps output (prefix.eps)",eps) .option("2con", "Create a two connected planar graph",two_a) .boolOption("eps", "Also generate .eps output (prefix.eps)") .boolOption("2con", "Create a two connected planar graph") .optionGroup("alg","2con") .option("tree", "Create a min. cost spanning tree",tree_a) .boolOption("tree", "Create a min. cost spanning tree") .optionGroup("alg","tree") .option("tsp", "Create a TSP tour",tsp_a) .boolOption("tsp", "Create a TSP tour") .optionGroup("alg","tsp") .onlyOneGroup("alg") } if(tsp_a) { if(ap["tsp"]) { tsp(); std::cout << "#2-opt improvements: " << tsp_impr_num << std::endl; } else if(two_a) { else if(ap["2con"]) { std::cout << "Make triangles\n"; //   triangle(); sparseTriangle(girth); sparseTriangle(ap["g"]); std::cout << "Make it sparser\n"; sparse2(girth); sparse2(ap["g"]); } else if(tree_a) { else if(ap["tree"]) { minTree(); } tlen+=sqrt((coords[g.source(e)]-coords[g.target(e)]).normSquare()); std::cout << "Total edge length  : " << tlen << std::endl; if(eps) if(ap["eps"]) graphToEps(g,prefix+".eps"). scale(600).nodeScale(.2).edgeWidthScale(.001).preScale(false).
Note: See TracChangeset for help on using the changeset viewer.