]>
git.proxmox.com Git - mirror_frr.git/blob - isisd/topology/spgrid.c
18 #define VERY_FAR 100000000
20 #define DOUBLE_CYCLE 0
27 #define NODE( x, y ) (x*Y + y + 1)
29 const char *graph_type
[] = {
39 long X
, /* horizontal size of grid */
40 Y
; /* vertical size of grid */
45 dl
, dx
, xn
, yn
, count
,
72 /* initialized by default values */
74 /* variables for generating one layer */
76 /* variables for generating spanning graph */
77 int c_f
= 0, cw_f
= 0, cm_f
= 0, cl_f
= 0;
79 int cw
= DOUBLE_CYCLE
; /* type of spanning graph */
80 long cm
= 0, /* lower bound of the interval */
81 cl
= 100; /* upper bound of the interval */
83 /* variables for generating additional arcs */
84 int a_f
= 0, ax_f
= 0, am_f
= 0, al_f
= 0;
86 long ax
= 0, /* number of additional arcs */
87 am
= 0, /* lower bound of the interval */
88 al
= 100; /* upper bound of the interval */
90 /* variables for inter-layer arcs */
91 int i_f
= 0, ip_f
= 0, ix_f
= 0, ih_f
= 0,
92 im_f
= 0, il_f
= 0, in_f
= 0, is_f
= 0;
94 int ip
= NO
; /* to mess or not to mess */
95 long ix
= 1, /* number of interlayered arcs in a NODE */
96 ih
= 1, /* step between two layeres */
97 il
= 10000, /* upper bound of the interval */
98 im
= 1000; /* lower bound of the interval */
99 double in
= 1, /* l *= in * |x1-x2| */
100 is
= 0; /* l *= is * |x1-x2|^2 */
102 /* variables for artifical source */
103 int s_f
= 0, sl_f
= 0, sm_f
= 0;
104 long sl
= VERY_FAR
, /* upper bound of artifical arc */
105 sm
, /* lower bound of artifical arc */
108 /* variables for potentials */
109 int p_f
= 0, pl_f
= 0, pm_f
= 0, pn_f
= 0, ps_f
= 0;
111 long pl
, /* upper bound of the interval */
112 pm
; /* lower bound of the interval */
113 double pn
= 0, /* p += ln * (x+1) */
114 ps
= 0; /* p += ls * (x+1)^2 */
116 int np
; /* number of parameter parsing now */
120 free_arc (void *val
) {
125 print_arc (struct vty
*vty
, struct list
*topology
, long i
, long j
, long length
)
130 if ( p_f
) l
+= ( p
[i
] - p
[j
] );
131 // vty_out (vty,"a %8ld %8ld %12ld%s", i, j, l ,VTY_NEWLINE);
132 myarc
= malloc (sizeof(struct arc
));
133 myarc
->from_node
= i
;
136 topology
->del
= free_arc
;
137 listnode_add (topology
, myarc
);
142 help (struct vty
*vty
) {
143 // if ( args[2] == 'h') hhelp (vty);
144 vty_out (vty
,"grid network generator for shortest paths problem.%s",VTY_NEWLINE
);
145 vty_out (vty
,"Generates problems in extended DIMACS format.%s",VTY_NEWLINE
);
146 vty_out (vty
,"X Y seed [ -cl#i -cm#i -c{c|d|p} -ip -il#i -im#i -p -pl#i -pm#i... ]%s",VTY_NEWLINE
);
147 vty_out (vty
,"#i - integer number%s",VTY_NEWLINE
);
148 vty_out (vty
,"-cl#i - #i is the upper bound on layer arc lengths (default 100)%s",VTY_NEWLINE
);
149 vty_out (vty
,"-cm#i - #i is the lower bound on layer arc lengths (default 0)%s",VTY_NEWLINE
);
150 vty_out (vty
,"-c#t - #t is the type of connecting graph: { c | d | p }%s",VTY_NEWLINE
);
151 vty_out (vty
," c - cycle, d - double cycle, p - path (default d)%s",VTY_NEWLINE
);
152 vty_out (vty
,"-ip - shuffle inter-layer arcs (default NO)%s",VTY_NEWLINE
);
153 vty_out (vty
,"-il#i - #i is the upper bound on inter-layer arc lengths (default 10000)%s",VTY_NEWLINE
);
154 vty_out (vty
,"-im#i - #i is the lower bound on inter-layer arc lengths (default 1000)%s",VTY_NEWLINE
);
155 vty_out (vty
,"-p - generate potentials%s",VTY_NEWLINE
);
156 vty_out (vty
,"-pl#i - #i is the upper bound on potentials (default il)%s",VTY_NEWLINE
);
157 vty_out (vty
,"-pm#i - #i is the lower bound on potentials (default im)%s",VTY_NEWLINE
);
158 vty_out (vty
,"%s",VTY_NEWLINE
);
159 vty_out (vty
,"-hh - extended help%s",VTY_NEWLINE
);
162 /* --------- sophisticated help ------------ */
164 hhelp (struct vty
*vty
) {
167 "\n'%s' - grid network generator for shortest paths problem.\n\
168 Generates problems in extended DIMACS format.\n\
170 %s X Y seed [ -cl#i -cm#i -c{c|d|p}\n\
172 -ip -il#i -im#i -in#i -is#i -ix#i -ih#i\n\
173 -p -pl#i -pm#i -pn#f -ps#f\n\
178 #i - integer number #f - real number\n\
180 Parameters of connecting arcs within one layer:\n\
181 -cl#i - #i is the upper bound on arc lengths (default 100)\n\
182 -cm#i - #i is the lower bound on arc lengths (default 0)\n\
183 -c#t - #t is the type of connecting graph: { c | d | p }\n\
184 c - cycle, d - double cycle, p - path (default d)\n\
186 Parameters of additional arcs within one layer:\n\
187 -ax#i - #i is the number of additional arcs (default 0)\n\
188 -al#i - #i is the upper bound on arc lengths (default 100)\n\
189 -am#i - #i is the lower bound on arc lengths (default 0)\n\
191 Interlayerd arc parameters:\n\
192 -ip - shuffle inter-layer arcs (default NO)\n\
193 -il#i - #i is the upper bound on arc lengths (default 10000)\n\
194 -im#i - #i is the lower bound on arc lengths (default 1000)\n\
195 -in#f - multiply l(i, j) by #f * x(j)-x(i) (default 1)\n\
196 if #f=0 - don't multiply\n\
197 -is#f - multiply l(i, j) by #f * (x(j)-x(i))^2 (default NO)\n\
198 -ix#i - #i - is the number of arcs from a node (default 1)\n\
199 -ih#i - #i - is the step between connected layers (default 1)\n\
201 Potential parameters:\n\
202 -p - generate potentials \n\
203 -pl#i - #i is the upper bound on potentials (default ll)\n\
204 -pm#i - #i is the lower bound on potentials (default lm)\n\
205 -pn#f - multiply p(i) by #f * x(i) (default NO)\n\
206 -ps#f - multiply p(i) by #f * x(i)^2 (default NO)\n\
209 " Artificial source parameters:\n\
210 -s - generate artificial source with default connecting arc lengths\n\
211 -sl#i - #i is the upper bound on art. arc lengths (default 100000000)\n\
212 -sm#i - #i is the lower bound on art. arc lengths (default sl)\n\"
216 /* ----- wrong usage ----- */
218 usage (struct vty
*vty
) {
219 vty_out (vty
,"usage: X Y seed [-ll#i -lm#i -cl#i -p -pl#i -pm#i ...]%s",VTY_NEWLINE
);
220 vty_out (vty
,"help: -h or -hh%s",VTY_NEWLINE
);
223 zlog_err ("error in parameter # %d\n\n", np
);
227 /* parsing parameters */
228 /* checks the validity of incoming parameters */
230 spgrid_check_params ( struct vty
*vty
, int argc
, const char **argv
)
232 /* initialized by default values */
235 /* variables for generating one layer */
237 /* variables for generating spanning graph */
243 cw
= PATH
; /* type of spanning graph */
244 cm
= 0; /* lower bound of the interval */
245 cl
= 63; /* upper bound of the interval */
247 /* variables for generating additional arcs */
253 ax
= 0; /* number of additional arcs */
254 am
= 0; /* lower bound of the interval */
255 al
= 63; /* upper bound of the interval */
257 /* variables for inter-layer arcs */
267 ip
= NO
; /* to mess or not to mess */
268 ix
= 1; /* number of interlayered arcs in a NODE */
269 ih
= 1; /* step between two layeres */
270 il
= 63; //was 10000; /* upper bound of the interval */
271 im
= 0; //was 1000; /* lower bound of the interval */
272 in
= 1; /* l *= in * |x1-x2| */
273 is
= 0; /* l *= is * |x1-x2|^2 */
275 /* variables for artifical source */
279 sl
= VERY_FAR
; /* upper bound of artifical arc */
281 /* variables for potentials */
288 pn
= 0; /* p += ln * (x+1) */
289 ps
= 0; /* p += ls * (x+1)^2 */
299 strcpy ( args
, argv
[0] );
301 if ((args
[0] == DASH
) && (args
[1] == 'h'))
309 /* first parameter - horizontal size */
311 if ( ( X
= atoi ( argv
[0] ) ) < 1 ) {
316 /* second parameter - vertical size */
318 if ( ( Y
= atoi ( argv
[1] ) ) < 1 ) {
323 /* third parameter - seed */
325 if ( ( seed
= atoi ( argv
[2] ) ) <= 0 ) {
330 /* other parameters */
331 for ( np
= 3; np
< argc
; np
++ ) {
332 strcpy ( args
, argv
[np
] );
333 if ( args
[0] != DASH
) {
339 case 'c' : /* spanning graph in one layer */
342 case 'l': /* upper bound of the interval */
344 cl
= atol ( &args
[3] );
346 case 'm': /* lower bound */
348 cm
= atol ( &args
[3] );
350 case 'c': /* type - cycle */
354 case 'd': /* type - double cycle */
358 case 'p': /* type - path */
363 default: /* unknown switch value */
369 case 'a' : /* additional arcs in one layer */
373 case 'l': /* upper bound of the interval */
375 al
= atol ( &args
[3] );
377 case 'm': /* lower bound */
379 am
= atol ( &args
[3] );
381 case 'x': /* number of additional arcs */
383 ax
= atol ( &args
[3] );
391 default: /* unknown switch value */
400 case 'i' : /* interlayered arcs */
405 case 'l': /* upper bound */
407 il
= atol ( &args
[3] );
409 case 'm': /* lower bound */
411 im
= atol ( &args
[3] );
413 case 'n': /* additional length: l *= in*|i1-i2| */
415 in
= atof ( &args
[3] );
417 case 's': /* additional length: l *= is*|i1-i2|^2 */
419 is
= atof ( &args
[3] );
421 case 'p': /* mess interlayered arcs */
425 case 'x': /* number of interlayered arcs */
427 ix
= atof ( &args
[3] );
433 case 'h': /* step between two layeres */
435 ih
= atof ( &args
[3] );
441 default: /* unknown switch value */
447 case 's' : /* additional source */
449 if ( strlen ( args
) > 2 )
453 case 'l': /* upper bound of art. arc */
455 sl
= atol ( &args
[3] );
457 case 'm': /* lower bound of art. arc */
459 sm
= atol ( &args
[3] );
461 default: /* unknown switch value */
468 case 'p' : /* potentials */
470 if ( strlen ( args
) > 2 )
474 case 'l': /* upper bound */
476 pl
= atol ( &args
[3] );
478 case 'm': /* lower bound */
480 pm
= atol ( &args
[3] );
482 case 'n': /* additional: p *= pn*(x+1) */
484 pn
= atof ( &args
[3] );
486 case 's': /* additional: p = ps* (x+1)^2 */
488 ps
= atof ( &args
[3] );
490 default: /* unknown switch value */
497 default: /* unknoun case */
508 /* generator of layered networks for the shortest paths problem;
509 extended DIMACS format for output */
511 gen_spgrid_topology (struct vty
*vty
, struct list
*topology
)
513 /* ----- ajusting parameters ----- */
516 if ( cl
< cm
) { lx
= cl
; cl
= cm
; cm
= lx
; }
518 /* additional arcs */
519 if ( al
< am
) { lx
= al
; al
= am
; am
= lx
; }
521 /* interlayered arcs */
522 if ( il
< im
) { lx
= il
; il
= im
; im
= lx
; }
524 /* potential parameters */
527 if ( ! pl_f
) pl
= il
;
528 if ( ! pm_f
) pm
= im
;
529 if ( pl
< pm
) { lx
= pl
; pl
= pm
; pm
= lx
; }
532 /* number of nodes and arcs */
534 n
= (double)X
*(double)Y
+ 1;
536 m
= (double)Y
; /* arcs from source */
550 m
+= (double)X
* (double)mc
; /* spanning arcs */
551 m
+= (double)X
* (double)ax
; /* additional arcs */
553 /* interlayered arcs */
554 for ( x
= 0; x
< X
; x
++ )
556 dl
= ( ( X
- x
- 1 ) + ( ih
- 1 ) ) / ih
;
557 if ( dl
> ix
) dl
= ix
;
558 m
+= (double)Y
* (double)dl
;
561 /* artifical source parameters */
564 if ( ! sm_f
) sm
= sl
;
565 if ( sl
< sm
) { lx
= sl
; sl
= sm
; sm
= lx
; }
568 if ( n
>= (double)LONG_MAX
|| m
>= (double)LONG_MAX
)
570 zlog_err ("Too large problem. It can't be generated\n");
575 n0
= (long)n
; m0
= (long)m
;
579 mess
= (long*) calloc ( Y
, sizeof ( long ) );
582 zlog_info ("Generating topology for ISIS");
584 source
= ( s_f
) ? n0
-1 : n0
;
586 if ( p_f
) /* generating potentials */ {
587 p
= (long*) calloc ( n0
+1, sizeof (long) );
592 for ( x
= 0; x
< X
; x
++ )
593 for ( y
= 0; y
< Y
; y
++ ) {
594 p_t
= pm
+ nrand ( pl
);
595 if ( pn_f
) p_t
*= (long) ( (1 + x
) * pn
);
596 if ( ps_f
) p_t
*= (long) ( (1 + x
) * ( (1 + x
) * ps
));
598 p
[ NODE ( x
, y
) ] = p_t
;
601 if ( s_f
) p
[n0
-1] = 0;
604 if ( s_f
) /* additional arcs from artifical source */
610 for ( x
= X
- 1; x
>= 0; x
-- )
611 for ( y
= Y
- 1; y
>= 0; y
-- )
614 s
= sm
+ nrand ( sl
);
615 print_arc (vty
, topology
, n0
, i
, s
);
618 print_arc (vty
, topology
, n0
, n0
-1, 0 );
622 /* ----- generating arcs within layers ----- */
628 for ( x
= 0; x
< X
; x
++ )
630 /* generating arcs within one layer */
631 for ( y
= 0; y
< Y
-1; y
++ )
633 /* generating spanning graph */
636 l
= cm
+ nrand ( cl
);
637 print_arc (vty
, topology
, i
, j
, l
);
639 if ( cw
== DOUBLE_CYCLE
)
641 l
= cm
+ nrand ( cl
);
642 print_arc (vty
, topology
, j
, i
, l
);
650 l
= cm
+ nrand ( cl
);
651 print_arc (vty
, topology
, i
, j
, l
);
653 if ( cw
== DOUBLE_CYCLE
)
655 l
= cm
+ nrand ( cl
);
656 print_arc (vty
, topology
, j
, i
, l
);
660 /* generating additional arcs */
662 for ( k
= ax
; k
> 0; k
-- )
670 l
= am
+ nrand ( al
);
671 print_arc (vty
, topology
, i
, j
, l
);
675 /* ----- generating interlayered arcs ------ */
679 /* arcs from the source */
681 for ( y
= 0; y
< Y
; y
++ )
683 l
= im
+ nrand ( il
);
685 print_arc (vty
, topology
, source
, i
, l
);
688 for ( x
= 0; x
< X
-1; x
++ )
690 /* generating arcs from one layer */
691 for ( count
= 0, xn
= x
+ 1;
692 count
< ix
&& xn
< X
;
696 for ( y
= 0; y
< Y
; y
++ )
699 for ( y
= 0; y
< Y
; y
++ )
707 mess
[ yp
] = mess
[ Y
- y
- 1 ];
712 l
= im
+ nrand ( il
);
714 l
*= (long) ( in
* dx
);
716 l
*= (long) ( ( is
* dx
) * dx
);
717 print_arc (vty
, topology
, i
, j
, l
);