9 #define VERY_FAR 100000000
12 /* generator of acyclic random networks for the shortest paths problem;
13 extended DIMACS format for output */
50 /* variables for lengths generating */
51 /* initialized by default values */
52 int l_f
= 0, ll_f
= 0, lm_f
= 0, ln_f
= 0, ls_f
= 0;
53 long ll
= 10000, /* upper bound of the interval */
54 lm
= 0; /* lower bound of the interval */
55 double ln
= 0, /* l += ln * |i-j| */
56 ls
= 0; /* l += ls * |i-j|^2 */
58 /* variables for connecting path(s) */
59 int c_f
= 0, cl_f
= 0, ch_f
= 0, c_rand
= 1;
60 long cl
= 1; /* length of path arc */
61 long ch
; /* number of arcs in the path
64 /* variables for artifical source */
65 int s_f
= 0, sl_f
= 0, sm_f
= 0;
66 long sl
= VERY_FAR
, /* upper bound of artifical arc */
67 sm
, /* lower bound of artifical arc */
70 /* variables for potentials */
71 int p_f
= 0, pl_f
= 0, pm_f
= 0, pn_f
= 0, ps_f
= 0,
72 pa_f
= 0, pap_f
= 0, pac_f
= 0;
73 long pl
, /* upper bound of the interval */
74 pm
; /* lower bound of the interval */
75 double pn
= 0, /* l += ln * |i-j| */
76 ps
= 0, /* l += ls * |i-j|^2 */
77 pap
= 0, /* part of nodes with alternative dustribution */
78 pac
= -1; /* multiplier for alternative distribution */
80 int np
; /* number of parameter parsing now */
82 #define PRINT_ARC( i, j, length )\
85 if ( p_f ) l += ( p[i] - p[j] );\
86 printf ("a %8ld %8ld %12ld\n", i, j, l );\
89 /* parsing parameters */
91 if ( argc
< 2 ) goto usage
;
95 strcpy ( args
, argv
[1] );
97 if ( ( args
[0] == DASH
) && ( args
[1] == 'h')
101 if ( argc
< 4 ) goto usage
;
103 /* first parameter - number of nodes */
105 if ( ( n
= atoi ( argv
[1] ) ) < 2 ) goto usage
;
107 /* second parameter - number of arcs */
109 if ( ( m
= atoi ( argv
[2] ) ) < n
) goto usage
;
111 /* third parameter - seed */
113 if ( ( seed
= atoi ( argv
[3] ) ) <= 0 ) goto usage
;
115 /* other parameters */
117 for ( np
= 4; np
< argc
; np
++ )
119 strcpy ( args
, argv
[np
] );
120 if ( args
[0] != DASH
) goto usage
;
125 case 'l' : /* an interval for arc length */
129 case 'l': /* length of the interval */
131 ll
= (long) atof ( &args
[3] );
133 case 'm': /* minimal bound */
135 lm
= (long ) atof ( &args
[3] );
137 case 'n': /* additional length: l*|i-j| */
139 ln
= atof ( &args
[3] );
141 case 's': /* additional length: l*|i-j|^2 */
143 ls
= atof ( &args
[3] );
145 default: /* unknown switch value */
150 case 'c' : /* connecting path(s) */
154 case 'l': /* length of path arc */
155 c_rand
= 0; /* fixed arc length */
157 cl
= (long) atof ( &args
[3] );
159 case 'h': /* number of arcs in connecting path */
161 ch
= (long) atof ( &args
[3] );
162 if ( ch
< 1 || ch
> n
) goto usage
;
164 default: /* unknown switch value */
169 case 's' : /* additional source */
171 if ( strlen ( args
) > 2 )
175 case 'l': /* upper bound of art. arc */
177 sl
= (long) atof ( &args
[3] );
179 case 'm': /* lower bound of art. arc */
181 sm
= (long) atof ( &args
[3] );
183 default: /* unknown switch value */
189 case 'p' : /* potentials */
191 if ( strlen ( args
) > 2 )
195 case 'l': /* length of the interval */
197 pl
= (long) atof ( &args
[3] );
199 case 'm': /* minimal bound */
201 pm
= (long ) atof ( &args
[3] );
203 case 'n': /* additional length: l*|i-j| */
205 pn
= atof ( &args
[3] );
207 case 's': /* additional length: l*|i-j|^2 */
209 ps
= atof ( &args
[3] );
211 case 'a': /* bipolar distribution */
215 case 'p': /* % of alternative potentials */
217 pap
= atof ( &args
[4] );
218 if ( pap
< 0 ) pap
= 0;
219 if ( pap
> 100 ) pap
= 100;
222 case 'c': /* multiplier */
224 pac
= atof ( &args
[4] );
226 default: /* unknown switch value */
230 default: /* unknown switch value */
236 default : /* unknoun case */
241 /* ----- ajusting parameters ----- */
245 /* length parameters */
246 if ( ll
< lm
) { lx
= ll
; ll
= lm
; lm
= lx
; }
248 /* potential parameters */
251 if ( ! pl_f
) pl
= ll
;
252 if ( ! pm_f
) pm
= lm
;
253 if ( pl
< pm
) { lx
= pl
; pl
= pm
; pm
= lx
; }
256 /* path(s) parameters */
257 if ( ! ch_f
) ch
= n
- 1;
260 /* artifical source parameters */
263 if ( ! sm_f
) sm
= sl
;
264 if ( sl
< sm
) { lx
= sl
; sl
= sm
; sm
= lx
; }
267 /*----- printing title -----*/
269 printf ("c acyclic network for shortest paths problem\n");
270 printf ("c extended DIMACS format\nc\n" );
273 /* name of the problem */
274 printf ("t ac_%ld_%ld_%ld_", n
, m
, seed
);
285 /* printing additional information */
287 printf ("c length -> min: %ld max: %ld k1: %.2f k2: %.2f\n",
290 printf ("c path(s) -> number of arcs: %ld arc length: %ld\n",
293 printf ("c length of arcs from artifical source -> min: %ld max: %ld\n",
297 printf ("c potentials -> min: %ld max: %ld k1: %.2f k2: %.2f\n",
300 printf ("c potentials -> part of alternative distribution: %.2f k: %.2f\n",
305 printf ("p sp %8ld %8ld\nc\n", n0
, m0
);
307 source
= ( s_f
) ? n0
: 1;
308 printf ("n %8ld\nc\n", source
);
311 if ( p_f
) /* generating potentials */
314 p
= (long*) calloc ( n
+2, sizeof (long) );
318 for ( i
= 0; i
<= n
; i
++ )
320 p_t
= pm
+ nrand ( pl
);
321 if ( pn_f
) p_t
+= (long) ( i
* pn
);
322 if ( ps_f
) p_t
+= (long) ( i
* ( i
* ps
));
324 if ( rand01() < pap
)
325 p_t
= (long) ( p_t
* pac
);
332 if ( s_f
) /* additional arcs from artifical source */
338 for ( i
= n
; i
> 1; i
-- )
340 s
= sm
+ nrand ( sl
);
341 PRINT_ARC ( n0
, i
, s
)
344 PRINT_ARC ( n0
, 1, 0 )
347 /* initialize random number generator */
351 /* generating connecting path(s) */
352 for ( i
= 1; i
< n
; i
++ )
354 if ( ( (i
-1) % ch
) != 0 )
361 PRINT_ARC ( i0
, i
+1, cl
)
364 /* generating random arcs */
367 for ( k
= 1; k
<= m
- mc
; k
++ )
376 { i0
= i
; i
= j
; j
= i0
; }
379 l
= lm
+ nrand ( ll
);
380 if ( ln_f
) l
+= (long) ( dij
* ln
);
381 if ( ls_f
) l
+= (long) ( dij
* ( dij
* ls
) );
382 PRINT_ARC ( i
, j
, l
);
388 /* ----- wrong usage ----- */
392 "\nusage: %s n m seed [ -ll#i -lm#i -cl#i -p -pl#i -pm#i ... ]\n\
393 help: %s -h\n\n", argv
[0], argv
[0] );
396 fprintf ( stderr
, "error in parameter # %d\n\n", np
);
403 if ( args
[2] == 'h') goto hhelp
;
406 "\n'%s' - acyclic network generator for shortest paths problem.\n\
407 Generates problems in extended DIMACS format.\n\
409 %s n m seed [ -ll#i -lm#i -cl#i -p -pl#i -pm#i ... ]\n\
412 #i - integer number #f - real number\n\
414 -ll#i - #i is the upper bound on arc lengths (default 10000)\n\
415 -lm#i - #i is the lower bound on arc lengths (default 0)\n\
416 -cl#i - #i is length of arcs in connecting path(s) (default random)\n\
417 -p - generate potentials \n\
418 -pl#i - #i is the upper bound on potentials (default ll)\n\
419 -pm#i - #i is the lower bound on potentials (default lm)\n\
421 -hh - extended help \n\n",
422 argv
[0], argv
[0], argv
[0] );
426 /* --------- sophisticated help ------------ */
432 fout
= fopen ( argv
[2], "w" );
435 { fprintf ( stderr
, "\nCan't open file '%s' for writing help\n\n", argv
[2] );
440 "\n'%s' - acyclic network generator for shortest paths problem.\n\
441 Generates problems in extended DIMACS format.\n\
443 %s n m seed [ -ll#i -lm#i -ln#f -ls#f\n\
444 -p -pl#i -pm#i -pn#f -ps#f -pap#i -pac#f\n\
450 #i - integer number #f - real number\n\
452 Arc length parameters:\n\
453 -ll#i - #i is the upper bound on arc lengths (default 10000)\n\
454 -lm#i - #i is the lower bound on arc lengths (default 0)\n\
455 -ln#f - multipliy l(i, j) by #f * |i-j| (default 0)\n\
456 -ls#f - multipliy l(i, j) by #f * |i-j|^2 (default 0)\n\
458 Potential parameters:\n\
459 -p - generate potentials \n\
460 -pl#i - #i is the upper bound on potentials (default ll)\n\
461 -pm#i - #i is the lower bound on potentials (default lm)\n\
462 -pn#f - multiply p(i) by #f * i (default 0)\n\
463 -ps#f - multiply p(i) by #f * i^2 (default 0)\n\
464 -pap#i - percentage of alternative potential nodes (default 0)\n\
465 -pac#f - if i is alternative, multiply p(i) by #f (default -1)\n\
467 Connecting path(s) parameters:\n\
468 -cl#i - #i is length of arcs in connecting path(s) (default random)\n\
469 -ch#i - #i is length of connecting path(s) (default n-1)\n\
471 Artificial source parameters:\n\
472 -s - generate artificial source with default connecting arc lengths\n\
473 -sl#i - #i is the upper bound on art. arc lengths (default 100000000)\n\
474 -sm#i - #i is the lower bound on art. arc lengths (default sl)\n\
476 -hh file_name - save this help in the file 'file_name'\n\n",
477 argv
[0], argv
[0], argv
[0] );