Command line parameter support for netgen
authorAlpar Juttner <alpar@cs.elte.hu>
Thu, 17 Mar 2011 18:28:37 +0100
changeset 779d9c9f6c446
parent 6 a3ef33a8694a
child 8 3c30bd0f9ccc
Command line parameter support for netgen
generators/netgen/CMakeLists.txt
generators/netgen/main.cc
generators/netgen/main.h
generators/netgen/netgen.c
     1.1 --- a/generators/netgen/CMakeLists.txt	Fri Nov 26 19:23:47 2010 +0100
     1.2 +++ b/generators/netgen/CMakeLists.txt	Thu Mar 17 18:28:37 2011 +0100
     1.3 @@ -8,7 +8,11 @@
     1.4  )
     1.5  
     1.6  ADD_EXECUTABLE(netgen
     1.7 -        netgen.c index.c random.c
     1.8 +  main.cc netgen.c index.c random.c
     1.9  )
    1.10  
    1.11 -SET_TARGET_PROPERTIES(netgen PROPERTIES COMPILE_DEFINITIONS "DIMACS")
    1.12 \ No newline at end of file
    1.13 +SET_TARGET_PROPERTIES(netgen PROPERTIES COMPILE_DEFINITIONS "DIMACS")
    1.14 +
    1.15 +TARGET_LINK_LIBRARIES(netgen
    1.16 +  lemon
    1.17 +)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/generators/netgen/main.cc	Thu Mar 17 18:28:37 2011 +0100
     2.3 @@ -0,0 +1,51 @@
     2.4 +#include <lemon/arg_parser.h>
     2.5 +#include "main.h"
     2.6 +
     2.7 +int main(int argc, char **argv)
     2.8 +{
     2.9 +  int seed=1;
    2.10 +  int problem=0;
    2.11 +  int parms[PROBLEM_PARMS];
    2.12 +  
    2.13 +  lemon::ArgParser ap(argc,argv);
    2.14 +  ap.refOption("seed","Random seed (default: 1)",seed)
    2.15 +    .refOption("problem","Problem type (default: 0)",problem)
    2.16 +    .refOption("nodes","Number of nodes (default: 10)",NODES)
    2.17 +    .refOption("sources","Source nodes (default: 3)",SOURCES)
    2.18 +    .refOption("sinks","Sink nodes (default: 3)",SINKS)
    2.19 +    .refOption("density","Number of arcs (default: 30)",DENSITY)
    2.20 +    .refOption("mincost","Minimum arc cost (default: 10)",MINCOST)
    2.21 +    .refOption("maxcost","Maximum arc cost (default: 99)",MAXCOST)
    2.22 +    .refOption("supply","Total supply (default: 1000)",SUPPLY)
    2.23 +    .refOption("tsources","Transshipment sources (default: 0)",TSOURCES)
    2.24 +    .refOption("tsinks","Transshipment sinks (default: 0)",TSINKS)
    2.25 +    .refOption("hicost",
    2.26 +               "Percent of skeleton arcs given maximum cost (default: 0)",
    2.27 +               HICOST)
    2.28 +    .refOption("capacitated","Percent of arcs to be capacitated (default: 100)",
    2.29 +               CAPACITATED)
    2.30 +    .refOption("mincap","Minimum arc capacity (default: 100)",MINCAP)
    2.31 +    .refOption("maxcap","Maximum arc capacity (default: 1000)",MAXCAP);
    2.32 +
    2.33 +  NODES=10;
    2.34 +  SOURCES=3;
    2.35 +  SINKS=3;
    2.36 +  DENSITY=30;
    2.37 +  MINCOST=10;
    2.38 +  MAXCOST=99;
    2.39 +  SUPPLY=1000;
    2.40 +  TSOURCES=0;
    2.41 +  TSINKS=0;
    2.42 +  HICOST=0;
    2.43 +  CAPACITATED=100;
    2.44 +  MINCAP=100;
    2.45 +  MAXCAP=1000;
    2.46 +
    2.47 +  ap.run();
    2.48 +  
    2.49 +  long lparms[PROBLEM_PARMS];
    2.50 +  for(int i=0;i<PROBLEM_PARMS;i++) lparms[i]=parms[i];
    2.51 +
    2.52 +  return orig_main(seed,problem,lparms);  
    2.53 +}
    2.54 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/generators/netgen/main.h	Thu Mar 17 18:28:37 2011 +0100
     3.3 @@ -0,0 +1,30 @@
     3.4 +#ifndef NETGEN_MAIN_H
     3.5 +#define NETGEN_MAIN_H
     3.6 +
     3.7 +#ifdef __cplusplus
     3.8 +extern "C" {
     3.9 +#endif
    3.10 +
    3.11 +#define PROBLEM_PARMS 13		/* aliases for generation parameters */
    3.12 +#define NODES	    parms[0]		/* number of nodes */
    3.13 +#define SOURCES     parms[1]		/* number of sources (including transshipment) */
    3.14 +#define SINKS	    parms[2]		/* number of sinks (including transshipment) */
    3.15 +#define DENSITY     parms[3]		/* number of (requested) arcs */
    3.16 +#define MINCOST     parms[4]		/* minimum cost of arcs */
    3.17 +#define MAXCOST     parms[5]		/* maximum cost of arcs */
    3.18 +#define SUPPLY	    parms[6]		/* total supply */
    3.19 +#define TSOURCES    parms[7]		/* transshipment sources */
    3.20 +#define TSINKS	    parms[8]		/* transshipment sinks */
    3.21 +#define HICOST	    parms[9]		/* percent of skeleton arcs given maximum cost */
    3.22 +#define CAPACITATED parms[10]		/* percent of arcs to be capacitated */
    3.23 +#define MINCAP	    parms[11]		/* minimum capacity for capacitated arcs */
    3.24 +#define MAXCAP	    parms[12]		/* maximum capacity for capacitated arcs */
    3.25 +
    3.26 +  int orig_main(long seed,long problem,long *parms);
    3.27 +
    3.28 +#ifdef __cplusplus
    3.29 +}
    3.30 +#endif
    3.31 +
    3.32 +
    3.33 +#endif
     4.1 --- a/generators/netgen/netgen.c	Fri Nov 26 19:23:47 2010 +0100
     4.2 +++ b/generators/netgen/netgen.c	Thu Mar 17 18:28:37 2011 +0100
     4.3 @@ -85,21 +85,7 @@
     4.4  #define ALLOCATE_NETWORK
     4.5  #include "netgen.h"
     4.6  
     4.7 -#define PROBLEM_PARMS 13		/* aliases for generation parameters */
     4.8 -#define NODES	    parms[0]		/* number of nodes */
     4.9 -#define SOURCES     parms[1]		/* number of sources (including transshipment) */
    4.10 -#define SINKS	    parms[2]		/* number of sinks (including transshipment) */
    4.11 -#define DENSITY     parms[3]		/* number of (requested) arcs */
    4.12 -#define MINCOST     parms[4]		/* minimum cost of arcs */
    4.13 -#define MAXCOST     parms[5]		/* maximum cost of arcs */
    4.14 -#define SUPPLY	    parms[6]		/* total supply */
    4.15 -#define TSOURCES    parms[7]		/* transshipment sources */
    4.16 -#define TSINKS	    parms[8]		/* transshipment sinks */
    4.17 -#define HICOST	    parms[9]		/* percent of skeleton arcs given maximum cost */
    4.18 -#define CAPACITATED parms[10]		/* percent of arcs to be capacitated */
    4.19 -#define MINCAP	    parms[11]		/* minimum capacity for capacitated arcs */
    4.20 -#define MAXCAP	    parms[12]		/* maximum capacity for capacitated arcs */
    4.21 -
    4.22 +#include "main.h"
    4.23  
    4.24  /*** Private interfaces */
    4.25  
    4.26 @@ -485,23 +471,13 @@
    4.27  			exit(0);						\
    4.28  		}
    4.29  
    4.30 -int main()
    4.31 +int orig_main(long seed,long problem,long *parms)
    4.32  {
    4.33 -  long seed;
    4.34 -  long problem;
    4.35 -  long parms[PROBLEM_PARMS];
    4.36    long arcs;
    4.37    int i;
    4.38  
    4.39  /*** Read problem parameters and generate networks */
    4.40 -
    4.41 -  while (1) {
    4.42 -    READ(seed);
    4.43 -    if (seed <= 0) exit(0);
    4.44 -    READ(problem);
    4.45 -    if (problem <= 0) exit(0);
    4.46 -    for (i = 0; i < PROBLEM_PARMS; i++)
    4.47 -      READ(parms[i]);
    4.48 +  {
    4.49      printf("c NETGEN flow network generator (C version)\n");
    4.50      printf("c  Problem %2ld input parameters\n", problem);
    4.51      printf("c  ---------------------------\n");