10 #define VERY_FAR 100000000
13 /* generator of acyclic random networks for the shortest paths problem;
14 extended DIMACS format for output */
51 /* variables for lengths generating */
52 /* initialized by default values */
53 int l_f = 0, ll_f = 0, lm_f = 0, ln_f = 0, ls_f = 0;
54 long ll = 10000, /* upper bound of the interval */
55 lm = 0; /* lower bound of the interval */
56 double ln = 0, /* l += ln * |i-j| */
57 ls = 0; /* l += ls * |i-j|^2 */
59 /* variables for connecting path(s) */
60 int c_f = 0, cl_f = 0, ch_f = 0, c_rand = 1;
61 long cl = 1; /* length of path arc */
62 long ch; /* number of arcs in the path
65 /* variables for artifical source */
66 int s_f = 0, sl_f = 0, sm_f = 0;
67 long sl = VERY_FAR, /* upper bound of artifical arc */
68 sm, /* lower bound of artifical arc */
71 /* variables for potentials */
72 int p_f = 0, pl_f = 0, pm_f = 0, pn_f = 0, ps_f = 0,
73 pa_f = 0, pap_f = 0, pac_f = 0;
74 long pl, /* upper bound of the interval */
75 pm; /* lower bound of the interval */
76 double pn = 0, /* l += ln * |i-j| */
77 ps = 0, /* l += ls * |i-j|^2 */
78 pap = 0, /* part of nodes with alternative dustribution */
79 pac = -1; /* multiplier for alternative distribution */
81 int np; /* number of parameter parsing now */
83 #define PRINT_ARC( i, j, length )\
86 if ( p_f ) l += ( p[i] - p[j] );\
87 printf ("a %8ld %8ld %12ld\n", i, j, l );\
90 /* parsing parameters */
92 if ( argc < 2 ) goto usage;
96 strcpy ( args, argv[1] );
98 if ( ( args[0] == DASH ) && ( args[1] == 'h')
102 if ( argc < 4 ) goto usage;
104 /* first parameter - number of nodes */
106 if ( ( n = atoi ( argv[1] ) ) < 2 ) goto usage;
108 /* second parameter - number of arcs */
110 if ( ( m = atoi ( argv[2] ) ) < n ) goto usage;
112 /* third parameter - seed */
114 if ( ( seed = atoi ( argv[3] ) ) <= 0 ) goto usage;
116 /* other parameters */
118 for ( np = 4; np < argc; np ++ )
120 strcpy ( args, argv[np] );
121 if ( args[0] != DASH ) goto usage;
126 case 'l' : /* an interval for arc length */
130 case 'l': /* length of the interval */
132 ll = (long) atof ( &args[3] );
134 case 'm': /* minimal bound */
136 lm = (long ) atof ( &args[3] );
138 case 'n': /* additional length: l*|i-j| */
140 ln = atof ( &args[3] );
142 case 's': /* additional length: l*|i-j|^2 */
144 ls = atof ( &args[3] );
146 default: /* unknown switch value */
151 case 'c' : /* connecting path(s) */
155 case 'l': /* length of path arc */
156 c_rand = 0; /* fixed arc length */
158 cl = (long) atof ( &args[3] );
160 case 'h': /* number of arcs in connecting path */
162 ch = (long) atof ( &args[3] );
163 if ( ch < 1 || ch > n ) goto usage;
165 default: /* unknown switch value */
170 case 's' : /* additional source */
172 if ( strlen ( args ) > 2 )
176 case 'l': /* upper bound of art. arc */
178 sl = (long) atof ( &args[3] );
180 case 'm': /* lower bound of art. arc */
182 sm = (long) atof ( &args[3] );
184 default: /* unknown switch value */
190 case 'p' : /* potentials */
192 if ( strlen ( args ) > 2 )
196 case 'l': /* length of the interval */
198 pl = (long) atof ( &args[3] );
200 case 'm': /* minimal bound */
202 pm = (long ) atof ( &args[3] );
204 case 'n': /* additional length: l*|i-j| */
206 pn = atof ( &args[3] );
208 case 's': /* additional length: l*|i-j|^2 */
210 ps = atof ( &args[3] );
212 case 'a': /* bipolar distribution */
216 case 'p': /* % of alternative potentials */
218 pap = atof ( &args[4] );
219 if ( pap < 0 ) pap = 0;
220 if ( pap > 100 ) pap = 100;
223 case 'c': /* multiplier */
225 pac = atof ( &args[4] );
227 default: /* unknown switch value */
231 default: /* unknown switch value */
237 default : /* unknoun case */
242 /* ----- ajusting parameters ----- */
246 /* length parameters */
247 if ( ll < lm ) { lx = ll; ll = lm; lm = lx; }
249 /* potential parameters */
252 if ( ! pl_f ) pl = ll;
253 if ( ! pm_f ) pm = lm;
254 if ( pl < pm ) { lx = pl; pl = pm; pm = lx; }
257 /* path(s) parameters */
258 if ( ! ch_f ) ch = n - 1;
261 /* artifical source parameters */
264 if ( ! sm_f ) sm = sl;
265 if ( sl < sm ) { lx = sl; sl = sm; sm = lx; }
268 /*----- printing title -----*/
270 printf ("c acyclic network for shortest paths problem\n");
271 printf ("c extended DIMACS format\nc\n" );
274 /* name of the problem */
275 printf ("t ac_%ld_%ld_%ld_", n, m, seed );
286 /* printing additional information */
288 printf ("c length -> min: %ld max: %ld k1: %.2f k2: %.2f\n",
291 printf ("c path(s) -> number of arcs: %ld arc length: %ld\n",
294 printf ("c length of arcs from artifical source -> min: %ld max: %ld\n",
298 printf ("c potentials -> min: %ld max: %ld k1: %.2f k2: %.2f\n",
301 printf ("c potentials -> part of alternative distribution: %.2f k: %.2f\n",
306 printf ("p sp %8ld %8ld\nc\n", n0, m0 );
308 source = ( s_f ) ? n0 : 1;
309 printf ("n %8ld\nc\n", source );
312 if ( p_f ) /* generating potentials */
315 p = (long*) calloc ( n+2, sizeof (long) );
319 for ( i = 0; i <= n; i ++ )
321 p_t = pm + nrand ( pl );
322 if ( pn_f ) p_t += (long) ( i * pn );
323 if ( ps_f ) p_t += (long) ( i * ( i * ps ));
325 if ( rand01() < pap )
326 p_t = (long) ( p_t * pac );
333 if ( s_f ) /* additional arcs from artifical source */
339 for ( i = n; i > 1; i -- )
341 s = sm + nrand ( sl );
342 PRINT_ARC ( n0, i, s )
345 PRINT_ARC ( n0, 1, 0 )
348 /* initialize random number generator */
352 /* generating connecting path(s) */
353 for ( i = 1; i < n; i ++ )
355 if ( ( (i-1) % ch ) != 0 )
362 PRINT_ARC ( i0, i+1, cl )
365 /* generating random arcs */
368 for ( k = 1; k <= m - mc; k ++ )
377 { i0 = i; i = j; j = i0; }
380 l = lm + nrand ( ll );
381 if ( ln_f ) l += (long) ( dij * ln );
382 if ( ls_f ) l += (long) ( dij * ( dij * ls ) );
383 PRINT_ARC ( i, j, l );
389 /* ----- wrong usage ----- */
393 "\nusage: %s n m seed [ -ll#i -lm#i -cl#i -p -pl#i -pm#i ... ]\n\
394 help: %s -h\n\n", argv[0], argv[0] );
397 fprintf ( stderr, "error in parameter # %d\n\n", np );
404 if ( args[2] == 'h') goto hhelp;
407 "\n'%s' - acyclic network generator for shortest paths problem.\n\
408 Generates problems in extended DIMACS format.\n\
410 %s n m seed [ -ll#i -lm#i -cl#i -p -pl#i -pm#i ... ]\n\
413 #i - integer number #f - real number\n\
415 -ll#i - #i is the upper bound on arc lengths (default 10000)\n\
416 -lm#i - #i is the lower bound on arc lengths (default 0)\n\
417 -cl#i - #i is length of arcs in connecting path(s) (default random)\n\
418 -p - generate potentials \n\
419 -pl#i - #i is the upper bound on potentials (default ll)\n\
420 -pm#i - #i is the lower bound on potentials (default lm)\n\
422 -hh - extended help \n\n",
423 argv[0], argv[0], argv[0] );
427 /* --------- sophisticated help ------------ */
433 fout = fopen ( argv[2], "w" );
436 { fprintf ( stderr, "\nCan't open file '%s' for writing help\n\n", argv[2] );
441 "\n'%s' - acyclic network generator for shortest paths problem.\n\
442 Generates problems in extended DIMACS format.\n\
444 %s n m seed [ -ll#i -lm#i -ln#f -ls#f\n\
445 -p -pl#i -pm#i -pn#f -ps#f -pap#i -pac#f\n\
451 #i - integer number #f - real number\n\
453 Arc length parameters:\n\
454 -ll#i - #i is the upper bound on arc lengths (default 10000)\n\
455 -lm#i - #i is the lower bound on arc lengths (default 0)\n\
456 -ln#f - multipliy l(i, j) by #f * |i-j| (default 0)\n\
457 -ls#f - multipliy l(i, j) by #f * |i-j|^2 (default 0)\n\
459 Potential parameters:\n\
460 -p - generate potentials \n\
461 -pl#i - #i is the upper bound on potentials (default ll)\n\
462 -pm#i - #i is the lower bound on potentials (default lm)\n\
463 -pn#f - multiply p(i) by #f * i (default 0)\n\
464 -ps#f - multiply p(i) by #f * i^2 (default 0)\n\
465 -pap#i - percentage of alternative potential nodes (default 0)\n\
466 -pac#f - if i is alternative, multiply p(i) by #f (default -1)\n\
468 Connecting path(s) parameters:\n\
469 -cl#i - #i is length of arcs in connecting path(s) (default random)\n\
470 -ch#i - #i is length of connecting path(s) (default n-1)\n\
472 Artificial source parameters:\n\
473 -s - generate artificial source with default connecting arc lengths\n\
474 -sl#i - #i is the upper bound on art. arc lengths (default 100000000)\n\
475 -sm#i - #i is the lower bound on art. arc lengths (default sl)\n\
477 -hh file_name - save this help in the file 'file_name'\n\n",
478 argv[0], argv[0], argv[0] );