0
64
6
21
1
23
20
4
25
17
17
20
4
2
20
39
27
55
55
30
4
1
1
23
19
73
73
26
68
6
48
78
59
180
158
9
11
15
15
10
10
40
21
2
2
50
50
31
31
49
10
44
9
117
17
10
10
21
15
| 1 |
%!PS-Adobe-3.0 EPSF-3.0 |
|
| 2 |
%%BoundingBox: 15 18 829 570 |
|
| 3 |
%%HiResBoundingBox: 15.1913 18.4493 828.078 569.438 |
|
| 4 |
%%Creator: Karbon14 EPS Exportfilter 0.5 |
|
| 5 |
%%CreationDate: (04/15/06 15:20:26) |
|
| 6 |
%%For: (Balazs Dezso) () |
|
| 7 |
%%Title: () |
|
| 8 |
|
|
| 9 |
/N {newpath} def
|
|
| 10 |
/C {closepath} def
|
|
| 11 |
/m {moveto} def
|
|
| 12 |
/c {curveto} def
|
|
| 13 |
/l {lineto} def
|
|
| 14 |
/s {stroke} def
|
|
| 15 |
/f {fill} def
|
|
| 16 |
/w {setlinewidth} def
|
|
| 17 |
/d {setdash} def
|
|
| 18 |
/r {setrgbcolor} def
|
|
| 19 |
/S {gsave} def
|
|
| 20 |
/R {grestore} def
|
|
| 21 |
|
|
| 22 |
N |
|
| 23 |
251.402 32.047 m |
|
| 24 |
532.945 293.946 814.484 555.844 814.484 555.844 c |
|
| 25 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 26 |
|
|
| 27 |
N |
|
| 28 |
749.012 32.047 m |
|
| 29 |
742.465 293.946 735.918 555.844 735.918 555.844 c |
|
| 30 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 31 |
|
|
| 32 |
N |
|
| 33 |
539.492 32.047 m |
|
| 34 |
637.703 293.946 735.918 555.844 735.918 555.844 c |
|
| 35 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 36 |
|
|
| 37 |
N |
|
| 38 |
172.832 32.047 m |
|
| 39 |
454.375 293.946 735.918 555.844 735.918 555.844 c |
|
| 40 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 41 |
|
|
| 42 |
N |
|
| 43 |
107.355 32.047 m |
|
| 44 |
421.637 293.946 735.918 555.844 735.918 555.844 c |
|
| 45 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 46 |
|
|
| 47 |
N |
|
| 48 |
644.25 555.844 m |
|
| 49 |
696.633 293.946 749.012 32.047 749.012 32.047 c |
|
| 50 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 51 |
|
|
| 52 |
N |
|
| 53 |
474.016 555.844 m |
|
| 54 |
611.516 293.946 749.012 32.047 749.012 32.047 c |
|
| 55 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 56 |
|
|
| 57 |
N |
|
| 58 |
683.535 32.047 m |
|
| 59 |
663.894 293.946 644.25 555.844 644.25 555.844 c |
|
| 60 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 61 |
|
|
| 62 |
N |
|
| 63 |
120.453 555.844 m |
|
| 64 |
401.992 293.946 683.535 32.047 683.535 32.047 c |
|
| 65 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 66 |
|
|
| 67 |
N |
|
| 68 |
28.7853 555.844 m |
|
| 69 |
356.16 293.946 683.535 32.047 683.535 32.047 c |
|
| 70 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 71 |
|
|
| 72 |
N |
|
| 73 |
539.492 32.047 m |
|
| 74 |
546.039 293.946 552.586 555.844 552.586 555.844 c |
|
| 75 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 76 |
|
|
| 77 |
N |
|
| 78 |
316.875 32.047 m |
|
| 79 |
349.613 293.946 382.351 555.844 382.351 555.844 c |
|
| 80 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 81 |
|
|
| 82 |
N |
|
| 83 |
107.355 32.047 m |
|
| 84 |
244.855 293.946 382.351 555.844 382.351 555.844 c |
|
| 85 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 86 |
|
|
| 87 |
N |
|
| 88 |
290.687 555.844 m |
|
| 89 |
375.805 293.946 460.922 32.047 460.922 32.047 c |
|
| 90 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 91 |
|
|
| 92 |
N |
|
| 93 |
120.453 555.844 m |
|
| 94 |
290.687 293.946 460.922 32.047 460.922 32.047 c |
|
| 95 |
[] 0 d 0 0 0 r 1.96407 w s |
|
| 96 |
|
|
| 97 |
N |
|
| 98 |
172.832 32.047 m |
|
| 99 |
146.64 293.946 120.453 555.844 120.453 555.844 c |
|
| 100 |
[] 0 d 1 0 0 r 3.92814 w s |
|
| 101 |
|
|
| 102 |
N |
|
| 103 |
15.6913 555.844 m |
|
| 104 |
15.6913 555.844 l |
|
| 105 |
15.6913 548.614 21.5553 542.75 28.7853 542.75 c |
|
| 106 |
36.0163 542.75 41.8833 548.614 41.8833 555.844 c |
|
| 107 |
41.8833 563.075 36.0163 568.938 28.7853 568.938 c |
|
| 108 |
21.5553 568.938 15.6913 563.075 15.6913 555.844 c |
|
| 109 |
15.6913 555.844 l |
|
| 110 |
C |
|
| 111 |
S 0 0 0 r f R |
|
| 112 |
|
|
| 113 |
N |
|
| 114 |
16.8833 555.844 m |
|
| 115 |
16.8833 555.844 l |
|
| 116 |
16.8833 549.27 22.2113 543.942 28.7853 543.942 c |
|
| 117 |
35.3593 543.942 40.6913 549.27 40.6913 555.844 c |
|
| 118 |
40.6913 562.418 35.3593 567.747 28.7853 567.747 c |
|
| 119 |
22.2113 567.747 16.8833 562.418 16.8833 555.844 c |
|
| 120 |
16.8833 555.844 l |
|
| 121 |
C |
|
| 122 |
S 1 0.5 1 r f R |
|
| 123 |
|
|
| 124 |
N |
|
| 125 |
107.355 555.844 m |
|
| 126 |
107.355 555.844 l |
|
| 127 |
107.355 548.614 113.223 542.75 120.453 542.75 c |
|
| 128 |
127.683 542.75 133.547 548.614 133.547 555.844 c |
|
| 129 |
133.547 563.075 127.683 568.938 120.453 568.938 c |
|
| 130 |
113.223 568.938 107.355 563.075 107.355 555.844 c |
|
| 131 |
107.355 555.844 l |
|
| 132 |
C |
|
| 133 |
S 0 0 0 r f R |
|
| 134 |
|
|
| 135 |
N |
|
| 136 |
108.547 555.844 m |
|
| 137 |
108.547 555.844 l |
|
| 138 |
108.547 549.27 113.879 543.942 120.453 543.942 c |
|
| 139 |
127.027 543.942 132.355 549.27 132.355 555.844 c |
|
| 140 |
132.355 562.418 127.027 567.747 120.453 567.747 c |
|
| 141 |
113.879 567.747 108.547 562.418 108.547 555.844 c |
|
| 142 |
108.547 555.844 l |
|
| 143 |
C |
|
| 144 |
S 1 0 1 r f R |
|
| 145 |
|
|
| 146 |
N |
|
| 147 |
199.019 555.844 m |
|
| 148 |
199.019 555.844 l |
|
| 149 |
199.019 548.614 204.887 542.75 212.117 542.75 c |
|
| 150 |
219.348 542.75 225.211 548.614 225.211 555.844 c |
|
| 151 |
225.211 563.075 219.348 568.938 212.117 568.938 c |
|
| 152 |
204.887 568.938 199.019 563.075 199.019 555.844 c |
|
| 153 |
199.019 555.844 l |
|
| 154 |
C |
|
| 155 |
S 0 0 0 r f R |
|
| 156 |
|
|
| 157 |
N |
|
| 158 |
200.211 555.844 m |
|
| 159 |
200.211 555.844 l |
|
| 160 |
200.211 549.27 205.543 543.942 212.117 543.942 c |
|
| 161 |
218.691 543.942 224.019 549.27 224.019 555.844 c |
|
| 162 |
224.019 562.418 218.691 567.747 212.117 567.747 c |
|
| 163 |
205.543 567.747 200.211 562.418 200.211 555.844 c |
|
| 164 |
200.211 555.844 l |
|
| 165 |
C |
|
| 166 |
S 1 0.5 1 r f R |
|
| 167 |
|
|
| 168 |
N |
|
| 169 |
277.59 555.844 m |
|
| 170 |
277.59 555.844 l |
|
| 171 |
277.59 548.614 283.457 542.75 290.687 542.75 c |
|
| 172 |
297.918 542.75 303.781 548.614 303.781 555.844 c |
|
| 173 |
303.781 563.075 297.918 568.938 290.687 568.938 c |
|
| 174 |
283.457 568.938 277.59 563.075 277.59 555.844 c |
|
| 175 |
277.59 555.844 l |
|
| 176 |
C |
|
| 177 |
S 0 0 0 r f R |
|
| 178 |
|
|
| 179 |
N |
|
| 180 |
278.781 555.844 m |
|
| 181 |
278.781 555.844 l |
|
| 182 |
278.781 549.27 284.113 543.942 290.687 543.942 c |
|
| 183 |
297.262 543.942 302.59 549.27 302.59 555.844 c |
|
| 184 |
302.59 562.418 297.262 567.747 290.687 567.747 c |
|
| 185 |
284.113 567.747 278.781 562.418 278.781 555.844 c |
|
| 186 |
278.781 555.844 l |
|
| 187 |
C |
|
| 188 |
S 1 0 1 r f R |
|
| 189 |
|
|
| 190 |
N |
|
| 191 |
369.258 555.844 m |
|
| 192 |
369.258 555.844 l |
|
| 193 |
369.258 548.614 375.121 542.75 382.351 542.75 c |
|
| 194 |
389.582 542.75 395.445 548.614 395.445 555.844 c |
|
| 195 |
395.445 563.075 389.582 568.938 382.351 568.938 c |
|
| 196 |
375.121 568.938 369.258 563.075 369.258 555.844 c |
|
| 197 |
369.258 555.844 l |
|
| 198 |
C |
|
| 199 |
S 0 0 0 r f R |
|
| 200 |
|
|
| 201 |
N |
|
| 202 |
370.445 555.844 m |
|
| 203 |
370.445 555.844 l |
|
| 204 |
370.445 549.27 375.777 543.942 382.351 543.942 c |
|
| 205 |
388.926 543.942 394.258 549.27 394.258 555.844 c |
|
| 206 |
394.258 562.418 388.926 567.747 382.351 567.747 c |
|
| 207 |
375.777 567.747 370.445 562.418 370.445 555.844 c |
|
| 208 |
370.445 555.844 l |
|
| 209 |
C |
|
| 210 |
S 1 0 1 r f R |
|
| 211 |
|
|
| 212 |
N |
|
| 213 |
460.922 555.844 m |
|
| 214 |
460.922 555.844 l |
|
| 215 |
460.922 548.614 466.785 542.75 474.016 542.75 c |
|
| 216 |
481.246 542.75 487.109 548.614 487.109 555.844 c |
|
| 217 |
487.109 563.075 481.246 568.938 474.016 568.938 c |
|
| 218 |
466.785 568.938 460.922 563.075 460.922 555.844 c |
|
| 219 |
460.922 555.844 l |
|
| 220 |
C |
|
| 221 |
S 0 0 0 r f R |
|
| 222 |
|
|
| 223 |
N |
|
| 224 |
462.113 555.844 m |
|
| 225 |
462.113 555.844 l |
|
| 226 |
462.113 549.27 467.441 543.942 474.016 543.942 c |
|
| 227 |
480.59 543.942 485.922 549.27 485.922 555.844 c |
|
| 228 |
485.922 562.418 480.59 567.747 474.016 567.747 c |
|
| 229 |
467.441 567.747 462.113 562.418 462.113 555.844 c |
|
| 230 |
462.113 555.844 l |
|
| 231 |
C |
|
| 232 |
S 1 0.5 1 r f R |
|
| 233 |
|
|
| 234 |
N |
|
| 235 |
539.492 555.844 m |
|
| 236 |
539.492 555.844 l |
|
| 237 |
539.492 548.614 545.355 542.75 552.586 542.75 c |
|
| 238 |
559.816 542.75 565.68 548.614 565.68 555.844 c |
|
| 239 |
565.68 563.075 559.816 568.938 552.586 568.938 c |
|
| 240 |
545.355 568.938 539.492 563.075 539.492 555.844 c |
|
| 241 |
539.492 555.844 l |
|
| 242 |
C |
|
| 243 |
S 0 0 0 r f R |
|
| 244 |
|
|
| 245 |
N |
|
| 246 |
540.683 555.844 m |
|
| 247 |
540.683 555.844 l |
|
| 248 |
540.683 549.27 546.012 543.942 552.586 543.942 c |
|
| 249 |
559.16 543.942 564.492 549.27 564.492 555.844 c |
|
| 250 |
564.492 562.418 559.16 567.747 552.586 567.747 c |
|
| 251 |
546.012 567.747 540.683 562.418 540.683 555.844 c |
|
| 252 |
540.683 555.844 l |
|
| 253 |
C |
|
| 254 |
S 1 0 1 r f R |
|
| 255 |
|
|
| 256 |
N |
|
| 257 |
631.156 555.844 m |
|
| 258 |
631.156 555.844 l |
|
| 259 |
631.156 548.614 637.019 542.75 644.25 542.75 c |
|
| 260 |
651.48 542.75 657.348 548.614 657.348 555.844 c |
|
| 261 |
657.348 563.075 651.48 568.938 644.25 568.938 c |
|
| 262 |
637.019 568.938 631.156 563.075 631.156 555.844 c |
|
| 263 |
631.156 555.844 l |
|
| 264 |
C |
|
| 265 |
S 0 0 0 r f R |
|
| 266 |
|
|
| 267 |
N |
|
| 268 |
632.348 555.844 m |
|
| 269 |
632.348 555.844 l |
|
| 270 |
632.348 549.27 637.676 543.942 644.25 543.942 c |
|
| 271 |
650.824 543.942 656.156 549.27 656.156 555.844 c |
|
| 272 |
656.156 562.418 650.824 567.747 644.25 567.747 c |
|
| 273 |
637.676 567.747 632.348 562.418 632.348 555.844 c |
|
| 274 |
632.348 555.844 l |
|
| 275 |
C |
|
| 276 |
S 1 0.5 1 r f R |
|
| 277 |
|
|
| 278 |
N |
|
| 279 |
722.82 555.844 m |
|
| 280 |
722.82 555.844 l |
|
| 281 |
722.82 548.614 728.687 542.75 735.918 542.75 c |
|
| 282 |
743.149 542.75 749.012 548.614 749.012 555.844 c |
|
| 283 |
749.012 563.075 743.149 568.938 735.918 568.938 c |
|
| 284 |
728.687 568.938 722.82 563.075 722.82 555.844 c |
|
| 285 |
722.82 555.844 l |
|
| 286 |
C |
|
| 287 |
S 0 0 0 r f R |
|
| 288 |
|
|
| 289 |
N |
|
| 290 |
724.012 555.844 m |
|
| 291 |
724.012 555.844 l |
|
| 292 |
724.012 549.27 729.344 543.942 735.918 543.942 c |
|
| 293 |
742.492 543.942 747.82 549.27 747.82 555.844 c |
|
| 294 |
747.82 562.418 742.492 567.747 735.918 567.747 c |
|
| 295 |
729.344 567.747 724.012 562.418 724.012 555.844 c |
|
| 296 |
724.012 555.844 l |
|
| 297 |
C |
|
| 298 |
S 1 0 1 r f R |
|
| 299 |
|
|
| 300 |
N |
|
| 301 |
801.391 555.844 m |
|
| 302 |
801.391 555.844 l |
|
| 303 |
801.391 548.614 807.254 542.75 814.484 542.75 c |
|
| 304 |
821.715 542.75 827.578 548.614 827.578 555.844 c |
|
| 305 |
827.578 563.075 821.715 568.938 814.484 568.938 c |
|
| 306 |
807.254 568.938 801.391 563.075 801.391 555.844 c |
|
| 307 |
801.391 555.844 l |
|
| 308 |
C |
|
| 309 |
S 0 0 0 r f R |
|
| 310 |
|
|
| 311 |
N |
|
| 312 |
802.582 555.844 m |
|
| 313 |
802.582 555.844 l |
|
| 314 |
802.582 549.27 807.91 543.942 814.484 543.942 c |
|
| 315 |
821.059 543.942 826.387 549.27 826.387 555.844 c |
|
| 316 |
826.387 562.418 821.059 567.747 814.484 567.747 c |
|
| 317 |
807.91 567.747 802.582 562.418 802.582 555.844 c |
|
| 318 |
802.582 555.844 l |
|
| 319 |
C |
|
| 320 |
S 1 0 1 r f R |
|
| 321 |
|
|
| 322 |
N |
|
| 323 |
15.6913 32.047 m |
|
| 324 |
15.6913 32.047 l |
|
| 325 |
15.6913 24.8165 21.5553 18.9493 28.7853 18.9493 c |
|
| 326 |
36.0163 18.9493 41.8833 24.8165 41.8833 32.047 c |
|
| 327 |
41.8833 39.2775 36.0163 45.1407 28.7853 45.1407 c |
|
| 328 |
21.5553 45.1407 15.6913 39.2775 15.6913 32.047 c |
|
| 329 |
15.6913 32.047 l |
|
| 330 |
C |
|
| 331 |
S 0 0 0 r f R |
|
| 332 |
|
|
| 333 |
N |
|
| 334 |
16.8833 32.047 m |
|
| 335 |
16.8833 32.047 l |
|
| 336 |
16.8833 25.4728 22.2113 20.1407 28.7853 20.1407 c |
|
| 337 |
35.3593 20.1407 40.6913 25.4728 40.6913 32.047 c |
|
| 338 |
40.6913 38.6212 35.3593 43.9493 28.7853 43.9493 c |
|
| 339 |
22.2113 43.9493 16.8833 38.6212 16.8833 32.047 c |
|
| 340 |
16.8833 32.047 l |
|
| 341 |
C |
|
| 342 |
S 0.5 0.5 1 r f R |
|
| 343 |
|
|
| 344 |
N |
|
| 345 |
94.2623 32.047 m |
|
| 346 |
94.2623 32.047 l |
|
| 347 |
94.2623 24.8165 100.125 18.9493 107.355 18.9493 c |
|
| 348 |
114.586 18.9493 120.453 24.8165 120.453 32.047 c |
|
| 349 |
120.453 39.2775 114.586 45.1407 107.355 45.1407 c |
|
| 350 |
100.125 45.1407 94.2623 39.2775 94.2623 32.047 c |
|
| 351 |
94.2623 32.047 l |
|
| 352 |
C |
|
| 353 |
S 0 0 0 r f R |
|
| 354 |
|
|
| 355 |
N |
|
| 356 |
95.4533 32.047 m |
|
| 357 |
95.4533 32.047 l |
|
| 358 |
95.4533 25.4728 100.781 20.1407 107.355 20.1407 c |
|
| 359 |
113.93 20.1407 119.262 25.4728 119.262 32.047 c |
|
| 360 |
119.262 38.6212 113.93 43.9493 107.355 43.9493 c |
|
| 361 |
100.781 43.9493 95.4533 38.6212 95.4533 32.047 c |
|
| 362 |
95.4533 32.047 l |
|
| 363 |
C |
|
| 364 |
S 0.5 0.5 1 r f R |
|
| 365 |
|
|
| 366 |
N |
|
| 367 |
159.734 32.047 m |
|
| 368 |
159.734 32.047 l |
|
| 369 |
159.734 24.8165 165.601 18.9493 172.832 18.9493 c |
|
| 370 |
180.062 18.9493 185.926 24.8165 185.926 32.047 c |
|
| 371 |
185.926 39.2775 180.062 45.1407 172.832 45.1407 c |
|
| 372 |
165.601 45.1407 159.734 39.2775 159.734 32.047 c |
|
| 373 |
159.734 32.047 l |
|
| 374 |
C |
|
| 375 |
S 0 0 0 r f R |
|
| 376 |
|
|
| 377 |
N |
|
| 378 |
160.926 32.047 m |
|
| 379 |
160.926 32.047 l |
|
| 380 |
160.926 25.4728 166.258 20.1407 172.832 20.1407 c |
|
| 381 |
179.406 20.1407 184.734 25.4728 184.734 32.047 c |
|
| 382 |
184.734 38.6212 179.406 43.9493 172.832 43.9493 c |
|
| 383 |
166.258 43.9493 160.926 38.6212 160.926 32.047 c |
|
| 384 |
160.926 32.047 l |
|
| 385 |
C |
|
| 386 |
S 0.5 0.5 1 r f R |
|
| 387 |
|
|
| 388 |
N |
|
| 389 |
238.305 32.047 m |
|
| 390 |
238.305 32.047 l |
|
| 391 |
238.305 24.8165 244.172 18.9493 251.402 18.9493 c |
|
| 392 |
258.633 18.9493 264.496 24.8165 264.496 32.047 c |
|
| 393 |
264.496 39.2775 258.633 45.1407 251.402 45.1407 c |
|
| 394 |
244.172 45.1407 238.305 39.2775 238.305 32.047 c |
|
| 395 |
238.305 32.047 l |
|
| 396 |
C |
|
| 397 |
S 0 0 0 r f R |
|
| 398 |
|
|
| 399 |
N |
|
| 400 |
239.496 32.047 m |
|
| 401 |
239.496 32.047 l |
|
| 402 |
239.496 25.4728 244.828 20.1407 251.402 20.1407 c |
|
| 403 |
257.976 20.1407 263.305 25.4728 263.305 32.047 c |
|
| 404 |
263.305 38.6212 257.976 43.9493 251.402 43.9493 c |
|
| 405 |
244.828 43.9493 239.496 38.6212 239.496 32.047 c |
|
| 406 |
239.496 32.047 l |
|
| 407 |
C |
|
| 408 |
S 0.5 0.5 1 r f R |
|
| 409 |
|
|
| 410 |
N |
|
| 411 |
303.781 32.047 m |
|
| 412 |
303.781 32.047 l |
|
| 413 |
303.781 24.8165 309.644 18.9493 316.875 18.9493 c |
|
| 414 |
324.105 18.9493 329.973 24.8165 329.973 32.047 c |
|
| 415 |
329.973 39.2775 324.105 45.1407 316.875 45.1407 c |
|
| 416 |
309.644 45.1407 303.781 39.2775 303.781 32.047 c |
|
| 417 |
303.781 32.047 l |
|
| 418 |
C |
|
| 419 |
S 0 0 0 r f R |
|
| 420 |
|
|
| 421 |
N |
|
| 422 |
304.973 32.047 m |
|
| 423 |
304.973 32.047 l |
|
| 424 |
304.973 25.4728 310.301 20.1407 316.875 20.1407 c |
|
| 425 |
323.449 20.1407 328.781 25.4728 328.781 32.047 c |
|
| 426 |
328.781 38.6212 323.449 43.9493 316.875 43.9493 c |
|
| 427 |
310.301 43.9493 304.973 38.6212 304.973 32.047 c |
|
| 428 |
304.973 32.047 l |
|
| 429 |
C |
|
| 430 |
S 0.5 0.5 1 r f R |
|
| 431 |
|
|
| 432 |
N |
|
| 433 |
382.351 32.047 m |
|
| 434 |
382.351 32.047 l |
|
| 435 |
382.351 24.8165 388.215 18.9493 395.445 18.9493 c |
|
| 436 |
402.676 18.9493 408.543 24.8165 408.543 32.047 c |
|
| 437 |
408.543 39.2775 402.676 45.1407 395.445 45.1407 c |
|
| 438 |
388.215 45.1407 382.351 39.2775 382.351 32.047 c |
|
| 439 |
382.351 32.047 l |
|
| 440 |
C |
|
| 441 |
S 0 0 0 r f R |
|
| 442 |
|
|
| 443 |
N |
|
| 444 |
383.543 32.047 m |
|
| 445 |
383.543 32.047 l |
|
| 446 |
383.543 25.4728 388.871 20.1407 395.445 20.1407 c |
|
| 447 |
402.019 20.1407 407.351 25.4728 407.351 32.047 c |
|
| 448 |
407.351 38.6212 402.019 43.9493 395.445 43.9493 c |
|
| 449 |
388.871 43.9493 383.543 38.6212 383.543 32.047 c |
|
| 450 |
383.543 32.047 l |
|
| 451 |
C |
|
| 452 |
S 0.5 0.5 1 r f R |
|
| 453 |
|
|
| 454 |
N |
|
| 455 |
447.828 32.047 m |
|
| 456 |
447.828 32.047 l |
|
| 457 |
447.828 24.8165 453.691 18.9493 460.922 18.9493 c |
|
| 458 |
468.152 18.9493 474.016 24.8165 474.016 32.047 c |
|
| 459 |
474.016 39.2775 468.152 45.1407 460.922 45.1407 c |
|
| 460 |
453.691 45.1407 447.828 39.2775 447.828 32.047 c |
|
| 461 |
447.828 32.047 l |
|
| 462 |
C |
|
| 463 |
S 0 0 0 r f R |
|
| 464 |
|
|
| 465 |
N |
|
| 466 |
449.016 32.047 m |
|
| 467 |
449.016 32.047 l |
|
| 468 |
449.016 25.4728 454.348 20.1407 460.922 20.1407 c |
|
| 469 |
467.496 20.1407 472.824 25.4728 472.824 32.047 c |
|
| 470 |
472.824 38.6212 467.496 43.9493 460.922 43.9493 c |
|
| 471 |
454.348 43.9493 449.016 38.6212 449.016 32.047 c |
|
| 472 |
449.016 32.047 l |
|
| 473 |
C |
|
| 474 |
S 0.5 0.5 1 r f R |
|
| 475 |
|
|
| 476 |
N |
|
| 477 |
526.394 32.047 m |
|
| 478 |
526.394 32.047 l |
|
| 479 |
526.394 24.8165 532.262 18.9493 539.492 18.9493 c |
|
| 480 |
546.723 18.9493 552.586 24.8165 552.586 32.047 c |
|
| 481 |
552.586 39.2775 546.723 45.1407 539.492 45.1407 c |
|
| 482 |
532.262 45.1407 526.394 39.2775 526.394 32.047 c |
|
| 483 |
526.394 32.047 l |
|
| 484 |
C |
|
| 485 |
S 0 0 0 r f R |
|
| 486 |
|
|
| 487 |
N |
|
| 488 |
527.586 32.047 m |
|
| 489 |
527.586 32.047 l |
|
| 490 |
527.586 25.4728 532.918 20.1407 539.492 20.1407 c |
|
| 491 |
546.066 20.1407 551.394 25.4728 551.394 32.047 c |
|
| 492 |
551.394 38.6212 546.066 43.9493 539.492 43.9493 c |
|
| 493 |
532.918 43.9493 527.586 38.6212 527.586 32.047 c |
|
| 494 |
527.586 32.047 l |
|
| 495 |
C |
|
| 496 |
S 0.5 0.5 1 r f R |
|
| 497 |
|
|
| 498 |
N |
|
| 499 |
591.871 32.047 m |
|
| 500 |
591.871 32.047 l |
|
| 501 |
591.871 24.8165 597.734 18.9493 604.965 18.9493 c |
|
| 502 |
612.195 18.9493 618.062 24.8165 618.062 32.047 c |
|
| 503 |
618.062 39.2775 612.195 45.1407 604.965 45.1407 c |
|
| 504 |
597.734 45.1407 591.871 39.2775 591.871 32.047 c |
|
| 505 |
591.871 32.047 l |
|
| 506 |
C |
|
| 507 |
S 0 0 0 r f R |
|
| 508 |
|
|
| 509 |
N |
|
| 510 |
593.062 32.047 m |
|
| 511 |
593.062 32.047 l |
|
| 512 |
593.062 25.4728 598.39 20.1407 604.965 20.1407 c |
|
| 513 |
611.539 20.1407 616.871 25.4728 616.871 32.047 c |
|
| 514 |
616.871 38.6212 611.539 43.9493 604.965 43.9493 c |
|
| 515 |
598.39 43.9493 593.062 38.6212 593.062 32.047 c |
|
| 516 |
593.062 32.047 l |
|
| 517 |
C |
|
| 518 |
S 0.5 0.5 1 r f R |
|
| 519 |
|
|
| 520 |
N |
|
| 521 |
670.441 32.047 m |
|
| 522 |
670.441 32.047 l |
|
| 523 |
670.441 24.8165 676.305 18.9493 683.535 18.9493 c |
|
| 524 |
690.766 18.9493 696.633 24.8165 696.633 32.047 c |
|
| 525 |
696.633 39.2775 690.766 45.1407 683.535 45.1407 c |
|
| 526 |
676.305 45.1407 670.441 39.2775 670.441 32.047 c |
|
| 527 |
670.441 32.047 l |
|
| 528 |
C |
|
| 529 |
S 0 0 0 r f R |
|
| 530 |
|
|
| 531 |
N |
|
| 532 |
671.633 32.047 m |
|
| 533 |
671.633 32.047 l |
|
| 534 |
671.633 25.4728 676.961 20.1407 683.535 20.1407 c |
|
| 535 |
690.109 20.1407 695.441 25.4728 695.441 32.047 c |
|
| 536 |
695.441 38.6212 690.109 43.9493 683.535 43.9493 c |
|
| 537 |
676.961 43.9493 671.633 38.6212 671.633 32.047 c |
|
| 538 |
671.633 32.047 l |
|
| 539 |
C |
|
| 540 |
S 0 0 1 r f R |
|
| 541 |
|
|
| 542 |
N |
|
| 543 |
735.918 32.047 m |
|
| 544 |
735.918 32.047 l |
|
| 545 |
735.918 24.8165 741.781 18.9493 749.012 18.9493 c |
|
| 546 |
756.242 18.9493 762.106 24.8165 762.106 32.047 c |
|
| 547 |
762.106 39.2775 756.242 45.1407 749.012 45.1407 c |
|
| 548 |
741.781 45.1407 735.918 39.2775 735.918 32.047 c |
|
| 549 |
735.918 32.047 l |
|
| 550 |
C |
|
| 551 |
S 0 0 0 r f R |
|
| 552 |
|
|
| 553 |
N |
|
| 554 |
737.105 32.047 m |
|
| 555 |
737.105 32.047 l |
|
| 556 |
737.105 25.4728 742.437 20.1407 749.012 20.1407 c |
|
| 557 |
755.586 20.1407 760.914 25.4728 760.914 32.047 c |
|
| 558 |
760.914 38.6212 755.586 43.9493 749.012 43.9493 c |
|
| 559 |
742.437 43.9493 737.105 38.6212 737.105 32.047 c |
|
| 560 |
737.105 32.047 l |
|
| 561 |
C |
|
| 562 |
S 0 0 1 r f R |
|
| 563 |
|
|
| 564 |
N |
|
| 565 |
801.391 32.047 m |
|
| 566 |
801.391 32.047 l |
|
| 567 |
801.391 24.8165 807.254 18.9493 814.484 18.9493 c |
|
| 568 |
821.715 18.9493 827.578 24.8165 827.578 32.047 c |
|
| 569 |
827.578 39.2775 821.715 45.1407 814.484 45.1407 c |
|
| 570 |
807.254 45.1407 801.391 39.2775 801.391 32.047 c |
|
| 571 |
801.391 32.047 l |
|
| 572 |
C |
|
| 573 |
S 0 0 0 r f R |
|
| 574 |
|
|
| 575 |
N |
|
| 576 |
802.582 32.047 m |
|
| 577 |
802.582 32.047 l |
|
| 578 |
802.582 25.4728 807.91 20.1407 814.484 20.1407 c |
|
| 579 |
821.059 20.1407 826.387 25.4728 826.387 32.047 c |
|
| 580 |
826.387 38.6212 821.059 43.9493 814.484 43.9493 c |
|
| 581 |
807.91 43.9493 802.582 38.6212 802.582 32.047 c |
|
| 582 |
802.582 32.047 l |
|
| 583 |
C |
|
| 584 |
S 0.5 0.5 1 r f R |
|
| 585 |
|
|
| 586 |
%%EOF |
| 1 |
%!PS-Adobe-2.0 EPSF-2.0 |
|
| 2 |
%%Creator: LEMON, graphToEps() |
|
| 3 |
%%CreationDate: Tue Nov 15 16:51:43 2005 |
|
| 4 |
%%BoundingBox: 0 0 842 596 |
|
| 5 |
%%EndComments |
|
| 6 |
/lb { setlinewidth setrgbcolor newpath moveto
|
|
| 7 |
4 2 roll 1 index 1 index curveto stroke } bind def |
|
| 8 |
/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
|
|
| 9 |
/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
|
|
| 10 |
/sq { newpath 2 index 1 index add 2 index 2 index add moveto
|
|
| 11 |
2 index 1 index sub 2 index 2 index add lineto |
|
| 12 |
2 index 1 index sub 2 index 2 index sub lineto |
|
| 13 |
2 index 1 index add 2 index 2 index sub lineto |
|
| 14 |
closepath pop pop pop} bind def |
|
| 15 |
/di { newpath 2 index 1 index add 2 index moveto
|
|
| 16 |
2 index 2 index 2 index add lineto |
|
| 17 |
2 index 1 index sub 2 index lineto |
|
| 18 |
2 index 2 index 2 index sub lineto |
|
| 19 |
closepath pop pop pop} bind def |
|
| 20 |
/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
|
|
| 21 |
setrgbcolor 1.1 div c fill |
|
| 22 |
} bind def |
|
| 23 |
/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
|
|
| 24 |
setrgbcolor 1.1 div sq fill |
|
| 25 |
} bind def |
|
| 26 |
/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
|
|
| 27 |
setrgbcolor 1.1 div di fill |
|
| 28 |
} bind def |
|
| 29 |
/arrl 1 def |
|
| 30 |
/arrw 0.3 def |
|
| 31 |
/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
|
|
| 32 |
/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
|
|
| 33 |
/w exch def /len exch def |
|
| 34 |
newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto |
|
| 35 |
len w sub arrl sub dx dy lrl |
|
| 36 |
arrw dy dx neg lrl |
|
| 37 |
dx arrl w add mul dy w 2 div arrw add mul sub |
|
| 38 |
dy arrl w add mul dx w 2 div arrw add mul add rlineto |
|
| 39 |
dx arrl w add mul neg dy w 2 div arrw add mul sub |
|
| 40 |
dy arrl w add mul neg dx w 2 div arrw add mul add rlineto |
|
| 41 |
arrw dy dx neg lrl |
|
| 42 |
len w sub arrl sub neg dx dy lrl |
|
| 43 |
closepath fill } bind def |
|
| 44 |
/cshow { 2 index 2 index moveto dup stringwidth pop
|
|
| 45 |
neg 2 div fosi .35 mul neg rmoveto show pop pop} def |
|
| 46 |
|
|
| 47 |
gsave |
|
| 48 |
90 rotate |
|
| 49 |
0 -842 translate |
|
| 50 |
71.6378 15 translate |
|
| 51 |
0.389093 dup scale |
|
| 52 |
90 rotate |
|
| 53 |
1197.47 -613.138 translate |
|
| 54 |
%Edges: |
|
| 55 |
gsave |
|
| 56 |
513.857 -446.322 296.569 -487.43 79.2808 -528.539 0 0 0 2 lb |
|
| 57 |
513.857 -446.322 575.52 -315.655 637.183 -184.989 0 0 0 2 lb |
|
| 58 |
393.468 566.711 494.771 434.577 596.074 302.442 0 0 0 2 lb |
|
| 59 |
393.468 566.711 155.625 579.925 -82.2171 593.138 0 0 0 2 lb |
|
| 60 |
393.468 566.711 251.056 450.726 108.644 334.741 0 0 0 2 lb |
|
| 61 |
869.153 52.8539 732.613 177.648 596.074 302.442 0 0 0 2 lb |
|
| 62 |
869.153 52.8539 753.168 -66.0676 637.183 -184.989 0 0 0 2 lb |
|
| 63 |
-82.2171 593.138 -91.0261 346.487 -99.8351 99.8351 0 0 0 2 lb |
|
| 64 |
-663.61 546.157 -753.168 394.936 -842.726 243.715 0 0 0 2 lb |
|
| 65 |
-663.61 546.157 -574.052 437.513 -484.494 328.869 0 0 0 2 lb |
|
| 66 |
-1077.63 161.498 -960.178 202.606 -842.726 243.715 0 0 0 2 lb |
|
| 67 |
-1077.63 161.498 -968.987 66.0674 -860.344 -29.3633 0 0 0 2 lb |
|
| 68 |
-1177.47 -234.906 -1029.18 -381.722 -880.898 -528.539 0 0 0 2 lb |
|
| 69 |
-1177.47 -234.906 -1018.91 -132.135 -860.344 -29.3633 0 0 0 2 lb |
|
| 70 |
-880.898 -528.539 -744.359 -387.595 -607.82 -246.651 0 0 0 2 lb |
|
| 71 |
-499.175 -499.175 -355.295 -475.685 -211.415 -452.194 0 0 0 2 lb |
|
| 72 |
-499.175 -499.175 -553.498 -372.913 -607.82 -246.651 0 0 0 2 lb |
|
| 73 |
-499.175 -499.175 -386.587 -315.087 -274 -131 0 0 0 2 lb |
|
| 74 |
79.2808 -528.539 -66.0671 -490.366 -211.415 -452.194 0 0 0 2 lb |
|
| 75 |
637.183 -184.989 421.363 -253.993 205.543 -322.996 0 0 0 2 lb |
|
| 76 |
205.543 -322.996 162.966 -226.097 120.389 -129.198 0 0 0 2 lb |
|
| 77 |
399.34 88.0898 259.865 -20.5541 120.389 -129.198 0 0 0 2 lb |
|
| 78 |
399.34 88.0898 253.992 211.415 108.644 334.741 0 0 0 2 lb |
|
| 79 |
-842.726 243.715 -471.281 171.775 -99.8351 99.8351 0 0 0 2 lb |
|
| 80 |
-842.726 243.715 -558.363 56.3575 -274 -131 0 0 0 2 lb |
|
| 81 |
-860.344 -29.3633 -734.082 -138.007 -607.82 -246.651 0 0 0 2 lb |
|
| 82 |
-211.415 -452.194 -45.513 -290.696 120.389 -129.198 0 0 0 2 lb |
|
| 83 |
-99.8351 99.8351 4.40445 217.288 108.644 334.741 0 0 0 2 lb |
|
| 84 |
-99.8351 99.8351 -292.165 214.352 -484.494 328.869 0 0 0 2 lb |
|
| 85 |
120.389 -129.198 -76.8055 -130.099 -274 -131 0 0 0 2 lb |
|
| 86 |
grestore |
|
| 87 |
%Nodes: |
|
| 88 |
gsave |
|
| 89 |
-274 -131 20 1 0 0 nc |
|
| 90 |
-607.82 -246.651 20 1 0 0 nc |
|
| 91 |
-484.494 328.869 20 0 0 1 nc |
|
| 92 |
108.644 334.741 20 0 0 1 nc |
|
| 93 |
120.389 -129.198 20 0 0 1 nc |
|
| 94 |
-99.8351 99.8351 20 1 0 0 nc |
|
| 95 |
-211.415 -452.194 20 1 0 0 nc |
|
| 96 |
-860.344 -29.3633 20 0 0 1 nc |
|
| 97 |
-842.726 243.715 20 0 0 1 nc |
|
| 98 |
399.34 88.0898 20 1 0 0 nc |
|
| 99 |
205.543 -322.996 20 1 0 0 nc |
|
| 100 |
637.183 -184.989 20 0 0 1 nc |
|
| 101 |
79.2808 -528.539 20 0 0 1 nc |
|
| 102 |
-499.175 -499.175 20 0 0 1 nc |
|
| 103 |
-880.898 -528.539 20 0 0 1 nc |
|
| 104 |
-1177.47 -234.906 20 1 0 0 nc |
|
| 105 |
-1077.63 161.498 20 1 0 0 nc |
|
| 106 |
-663.61 546.157 20 1 0 0 nc |
|
| 107 |
-82.2171 593.138 20 0 0 1 nc |
|
| 108 |
596.074 302.442 20 0 0 1 nc |
|
| 109 |
869.153 52.8539 20 1 0 0 nc |
|
| 110 |
393.468 566.711 20 1 0 0 nc |
|
| 111 |
513.857 -446.322 20 1 0 0 nc |
|
| 112 |
grestore |
|
| 113 |
grestore |
|
| 114 |
showpage |
| 1 |
%!PS-Adobe-2.0 EPSF-2.0 |
|
| 2 |
%%Creator: LEMON, graphToEps() |
|
| 3 |
%%CreationDate: Fri Nov 4 13:47:12 2005 |
|
| 4 |
%%BoundingBox: 0 0 842 596 |
|
| 5 |
%%EndComments |
|
| 6 |
/lb { setlinewidth setrgbcolor newpath moveto
|
|
| 7 |
4 2 roll 1 index 1 index curveto stroke } bind def |
|
| 8 |
/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
|
|
| 9 |
/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
|
|
| 10 |
/sq { newpath 2 index 1 index add 2 index 2 index add moveto
|
|
| 11 |
2 index 1 index sub 2 index 2 index add lineto |
|
| 12 |
2 index 1 index sub 2 index 2 index sub lineto |
|
| 13 |
2 index 1 index add 2 index 2 index sub lineto |
|
| 14 |
closepath pop pop pop} bind def |
|
| 15 |
/di { newpath 2 index 1 index add 2 index moveto
|
|
| 16 |
2 index 2 index 2 index add lineto |
|
| 17 |
2 index 1 index sub 2 index lineto |
|
| 18 |
2 index 2 index 2 index sub lineto |
|
| 19 |
closepath pop pop pop} bind def |
|
| 20 |
/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
|
|
| 21 |
setrgbcolor 1.1 div c fill |
|
| 22 |
} bind def |
|
| 23 |
/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
|
|
| 24 |
setrgbcolor 1.1 div sq fill |
|
| 25 |
} bind def |
|
| 26 |
/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
|
|
| 27 |
setrgbcolor 1.1 div di fill |
|
| 28 |
} bind def |
|
| 29 |
/arrl 1 def |
|
| 30 |
/arrw 0.3 def |
|
| 31 |
/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
|
|
| 32 |
/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
|
|
| 33 |
/w exch def /len exch def |
|
| 34 |
newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto |
|
| 35 |
len w sub arrl sub dx dy lrl |
|
| 36 |
arrw dy dx neg lrl |
|
| 37 |
dx arrl w add mul dy w 2 div arrw add mul sub |
|
| 38 |
dy arrl w add mul dx w 2 div arrw add mul add rlineto |
|
| 39 |
dx arrl w add mul neg dy w 2 div arrw add mul sub |
|
| 40 |
dy arrl w add mul neg dx w 2 div arrw add mul add rlineto |
|
| 41 |
arrw dy dx neg lrl |
|
| 42 |
len w sub arrl sub neg dx dy lrl |
|
| 43 |
closepath fill } bind def |
|
| 44 |
/cshow { 2 index 2 index moveto dup stringwidth pop
|
|
| 45 |
neg 2 div fosi .35 mul neg rmoveto show pop pop} def |
|
| 46 |
|
|
| 47 |
gsave |
|
| 48 |
90 rotate |
|
| 49 |
0 -842 translate |
|
| 50 |
71.0944 15 translate |
|
| 51 |
0.434694 dup scale |
|
| 52 |
90 rotate |
|
| 53 |
860.856 -588.349 translate |
|
| 54 |
%Edges: |
|
| 55 |
gsave |
|
| 56 |
574.035 177.301 622.149 225.748 670.264 274.195 0 0 0 2 lb |
|
| 57 |
694.579 115.483 682.421 194.839 670.264 274.195 0 0 0 2 lb |
|
| 58 |
280.402 10.3938 246.402 -6.60595 212.403 -23.6057 0 0 0 2 lb |
|
| 59 |
280.402 10.3938 283.493 -18.9695 286.584 -48.3327 0 0 0 2 lb |
|
| 60 |
212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 0 0 0 2 lb |
|
| 61 |
286.584 -48.3327 326.765 -79.2414 366.947 -110.15 0 0 0 2 lb |
|
| 62 |
286.584 -48.3327 278.857 -111.695 271.13 -175.058 0 0 0 2 lb |
|
| 63 |
438.037 -88.514 417.946 -142.604 397.855 -196.694 0 0 0 2 lb |
|
| 64 |
438.037 -88.514 402.492 -99.332 366.947 -110.15 0 0 0 2 lb |
|
| 65 |
397.855 -196.694 382.401 -153.422 366.947 -110.15 0 0 0 2 lb |
|
| 66 |
366.947 -110.15 319.038 -142.604 271.13 -175.058 0 0 0 2 lb |
|
| 67 |
271.13 -175.058 274.221 -213.694 277.311 -252.33 0 0 0 2 lb |
|
| 68 |
271.13 -175.058 238.675 -190.512 206.221 -205.967 0 0 0 2 lb |
|
| 69 |
277.311 -252.33 241.766 -229.149 206.221 -205.967 0 0 0 2 lb |
|
| 70 |
-840.856 -246.718 -804.351 -66.7145 -767.847 113.289 0 0 0 2 lb |
|
| 71 |
-579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 0 2 lb |
|
| 72 |
-579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 0 2 lb |
|
| 73 |
-767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 0 2 lb |
|
| 74 |
906.312 201.403 946.592 42.798 986.873 -115.807 0 0 0 2 lb |
|
| 75 |
906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0 0 2 lb |
|
| 76 |
986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0 0 2 lb |
|
| 77 |
-470.779 158.605 -390.218 50.3508 -309.657 -57.9033 0 0 0 2 lb |
|
| 78 |
422.945 521.129 208.955 541.269 -5.03507 561.41 0 0 0 2 lb |
|
| 79 |
422.945 521.129 376.371 417.911 329.797 314.692 0 0 0 2 lb |
|
| 80 |
422.945 521.129 474.554 276.928 526.164 32.7279 0 0 0 2 lb |
|
| 81 |
-5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0 0 0 2 lb |
|
| 82 |
329.797 314.692 130.912 317.209 -67.9734 319.727 0 0 0 2 lb |
|
| 83 |
-67.9734 319.727 229.095 176.227 526.164 32.7279 0 0 0 2 lb |
|
| 84 |
762.812 -17.6227 644.488 7.5526 526.164 32.7279 0 0 0 2 lb |
|
| 85 |
762.812 -17.6227 746.448 -162.381 730.084 -307.139 0 0 0 2 lb |
|
| 86 |
526.164 32.7279 470.779 -128.394 415.393 -289.516 0 0 0 2 lb |
|
| 87 |
730.084 -307.139 572.738 -298.327 415.393 -289.516 0 0 0 2 lb |
|
| 88 |
415.393 -289.516 173.71 -318.468 -67.9734 -347.42 0 0 0 2 lb |
|
| 89 |
-67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0 0 0 2 lb |
|
| 90 |
-67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0 0 0 2 lb |
|
| 91 |
-309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0 0 0 2 lb |
|
| 92 |
-323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0 0 0 2 lb |
|
| 93 |
-26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 0 0 0 2 lb |
|
| 94 |
-26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 0 0 0 2 lb |
|
| 95 |
-26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 0 0 0 2 lb |
|
| 96 |
-26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 0 0 0 2 lb |
|
| 97 |
116.407 -173.66 158.808 -67.6589 201.208 38.3422 0 0 0 2 lb |
|
| 98 |
-262.548 107.243 -137.997 120.493 -13.4452 133.743 0 0 0 2 lb |
|
| 99 |
-262.548 107.243 -221.472 176.144 -180.397 245.045 0 0 0 2 lb |
|
| 100 |
-13.4452 133.743 -96.9211 189.394 -180.397 245.045 0 0 0 2 lb |
|
| 101 |
-180.397 245.045 -142.256 345.099 -132.697 451.748 0 0 0 2 lb |
|
| 102 |
-180.397 245.045 -170.838 351.694 -132.697 451.748 0 0 0 2 lb |
|
| 103 |
-416.25 345.746 -274.474 398.747 -132.697 451.748 0 0 0 2 lb |
|
| 104 |
-416.25 345.746 -393.725 457.048 -371.2 568.349 0 0 0 2 lb |
|
| 105 |
-132.697 451.748 -251.948 510.048 -371.2 568.349 0 0 0 2 lb |
|
| 106 |
670.264 274.195 629.188 409.347 588.113 544.499 0 0 0 2 lb |
|
| 107 |
670.264 274.195 797.466 341.771 924.667 409.347 0 0 0 2 lb |
|
| 108 |
588.113 544.499 756.39 476.923 924.667 409.347 0 0 0 2 lb |
|
| 109 |
-689.204 -237.261 -614.799 -102.648 -567.302 43.6423 0 0 0 2 lb |
|
| 110 |
-689.204 -237.261 -641.707 -90.9706 -567.302 43.6423 0 0 0 2 lb |
|
| 111 |
grestore |
|
| 112 |
%Nodes: |
|
| 113 |
gsave |
|
| 114 |
-567.302 43.6423 20 0 0 0 nc |
|
| 115 |
-689.204 -237.261 20 0 0 0 nc |
|
| 116 |
924.667 409.347 20 1 0 0 nc |
|
| 117 |
588.113 544.499 20 1 0 0 nc |
|
| 118 |
670.264 274.195 20 1 0 0 nc |
|
| 119 |
-371.2 568.349 20 0 1 0 nc |
|
| 120 |
-132.697 451.748 20 0 1 0 nc |
|
| 121 |
-416.25 345.746 20 0 1 0 nc |
|
| 122 |
-180.397 245.045 20 0 1 0 nc |
|
| 123 |
-13.4452 133.743 20 0 1 0 nc |
|
| 124 |
-262.548 107.243 20 0 1 0 nc |
|
| 125 |
201.208 38.3422 20 0 1 0 nc |
|
| 126 |
116.407 -173.66 20 0 1 0 nc |
|
| 127 |
-26.6953 -19.9585 20 0 1 0 nc |
|
| 128 |
-539.894 -262.64 20 0 0 1 nc |
|
| 129 |
-323.543 -433.964 20 0 0 1 nc |
|
| 130 |
-309.657 -57.9033 20 0 0 1 nc |
|
| 131 |
-67.9734 -347.42 20 0 0 1 nc |
|
| 132 |
415.393 -289.516 20 0 0 1 nc |
|
| 133 |
730.084 -307.139 20 0 0 1 nc |
|
| 134 |
526.164 32.7279 20 0 0 1 nc |
|
| 135 |
762.812 -17.6227 20 0 0 1 nc |
|
| 136 |
-67.9734 319.727 20 0 0 1 nc |
|
| 137 |
329.797 314.692 20 0 0 1 nc |
|
| 138 |
-5.03507 561.41 20 0 0 1 nc |
|
| 139 |
422.945 521.129 20 0 0 1 nc |
|
| 140 |
-470.779 158.605 20 0 0 1 nc |
|
| 141 |
986.873 -115.807 20 0 0 1 nc |
|
| 142 |
906.312 201.403 20 0 0 1 nc |
|
| 143 |
-767.847 113.289 20 0 0 1 nc |
|
| 144 |
-579.033 445.603 20 0 0 1 nc |
|
| 145 |
-840.856 -246.718 20 0 0 1 nc |
|
| 146 |
206.221 -205.967 20 1 1 0 nc |
|
| 147 |
277.311 -252.33 20 1 1 0 nc |
|
| 148 |
271.13 -175.058 20 1 1 0 nc |
|
| 149 |
366.947 -110.15 20 1 1 0 nc |
|
| 150 |
397.855 -196.694 20 1 1 0 nc |
|
| 151 |
438.037 -88.514 20 1 1 0 nc |
|
| 152 |
286.584 -48.3327 20 1 1 0 nc |
|
| 153 |
212.403 -23.6057 20 1 1 0 nc |
|
| 154 |
280.402 10.3938 20 1 1 0 nc |
|
| 155 |
694.579 115.483 20 1 0 0 nc |
|
| 156 |
574.035 177.301 20 1 0 0 nc |
|
| 157 |
grestore |
|
| 158 |
grestore |
|
| 159 |
showpage |
| 1 |
%!PS-Adobe-2.0 EPSF-2.0 |
|
| 2 |
%%Creator: LEMON, graphToEps() |
|
| 3 |
%%CreationDate: Fri Nov 4 13:47:12 2005 |
|
| 4 |
%%BoundingBox: 0 0 842 596 |
|
| 5 |
%%EndComments |
|
| 6 |
/lb { setlinewidth setrgbcolor newpath moveto
|
|
| 7 |
4 2 roll 1 index 1 index curveto stroke } bind def |
|
| 8 |
/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
|
|
| 9 |
/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
|
|
| 10 |
/sq { newpath 2 index 1 index add 2 index 2 index add moveto
|
|
| 11 |
2 index 1 index sub 2 index 2 index add lineto |
|
| 12 |
2 index 1 index sub 2 index 2 index sub lineto |
|
| 13 |
2 index 1 index add 2 index 2 index sub lineto |
|
| 14 |
closepath pop pop pop} bind def |
|
| 15 |
/di { newpath 2 index 1 index add 2 index moveto
|
|
| 16 |
2 index 2 index 2 index add lineto |
|
| 17 |
2 index 1 index sub 2 index lineto |
|
| 18 |
2 index 2 index 2 index sub lineto |
|
| 19 |
closepath pop pop pop} bind def |
|
| 20 |
/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
|
|
| 21 |
setrgbcolor 1.1 div c fill |
|
| 22 |
} bind def |
|
| 23 |
/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
|
|
| 24 |
setrgbcolor 1.1 div sq fill |
|
| 25 |
} bind def |
|
| 26 |
/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
|
|
| 27 |
setrgbcolor 1.1 div di fill |
|
| 28 |
} bind def |
|
| 29 |
/arrl 1 def |
|
| 30 |
/arrw 0.3 def |
|
| 31 |
/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
|
|
| 32 |
/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
|
|
| 33 |
/w exch def /len exch def |
|
| 34 |
newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto |
|
| 35 |
len w sub arrl sub dx dy lrl |
|
| 36 |
arrw dy dx neg lrl |
|
| 37 |
dx arrl w add mul dy w 2 div arrw add mul sub |
|
| 38 |
dy arrl w add mul dx w 2 div arrw add mul add rlineto |
|
| 39 |
dx arrl w add mul neg dy w 2 div arrw add mul sub |
|
| 40 |
dy arrl w add mul neg dx w 2 div arrw add mul add rlineto |
|
| 41 |
arrw dy dx neg lrl |
|
| 42 |
len w sub arrl sub neg dx dy lrl |
|
| 43 |
closepath fill } bind def |
|
| 44 |
/cshow { 2 index 2 index moveto dup stringwidth pop
|
|
| 45 |
neg 2 div fosi .35 mul neg rmoveto show pop pop} def |
|
| 46 |
|
|
| 47 |
gsave |
|
| 48 |
90 rotate |
|
| 49 |
0 -842 translate |
|
| 50 |
71.0944 15 translate |
|
| 51 |
0.434694 dup scale |
|
| 52 |
90 rotate |
|
| 53 |
860.856 -588.349 translate |
|
| 54 |
%Edges: |
|
| 55 |
gsave |
|
| 56 |
574.035 177.301 622.149 225.748 670.264 274.195 1 0 0 2 lb |
|
| 57 |
694.579 115.483 682.421 194.839 670.264 274.195 1 0 0 2 lb |
|
| 58 |
280.402 10.3938 246.402 -6.60595 212.403 -23.6057 0 0 1 2 lb |
|
| 59 |
280.402 10.3938 283.493 -18.9695 286.584 -48.3327 0 0 1 2 lb |
|
| 60 |
212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 0 0 1 2 lb |
|
| 61 |
286.584 -48.3327 326.765 -79.2414 366.947 -110.15 0 0 1 2 lb |
|
| 62 |
286.584 -48.3327 278.857 -111.695 271.13 -175.058 0 0 1 2 lb |
|
| 63 |
438.037 -88.514 417.946 -142.604 397.855 -196.694 0 0 1 2 lb |
|
| 64 |
438.037 -88.514 402.492 -99.332 366.947 -110.15 0 0 1 2 lb |
|
| 65 |
397.855 -196.694 382.401 -153.422 366.947 -110.15 0 0 1 2 lb |
|
| 66 |
366.947 -110.15 319.038 -142.604 271.13 -175.058 0 0 1 2 lb |
|
| 67 |
271.13 -175.058 274.221 -213.694 277.311 -252.33 0 0 1 2 lb |
|
| 68 |
271.13 -175.058 238.675 -190.512 206.221 -205.967 0 0 1 2 lb |
|
| 69 |
277.311 -252.33 241.766 -229.149 206.221 -205.967 0 0 1 2 lb |
|
| 70 |
-840.856 -246.718 -804.351 -66.7145 -767.847 113.289 1 0 0 2 lb |
|
| 71 |
-579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 1 2 lb |
|
| 72 |
-579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 1 2 lb |
|
| 73 |
-767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 1 2 lb |
|
| 74 |
906.312 201.403 946.592 42.798 986.873 -115.807 0 0 1 2 lb |
|
| 75 |
906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0 1 2 lb |
|
| 76 |
986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0 1 2 lb |
|
| 77 |
-470.779 158.605 -390.218 50.3508 -309.657 -57.9033 1 0 0 2 lb |
|
| 78 |
422.945 521.129 208.955 541.269 -5.03507 561.41 0 0 1 2 lb |
|
| 79 |
422.945 521.129 376.371 417.911 329.797 314.692 0 0 1 2 lb |
|
| 80 |
422.945 521.129 474.554 276.928 526.164 32.7279 0 0 1 2 lb |
|
| 81 |
-5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0 0 1 2 lb |
|
| 82 |
329.797 314.692 130.912 317.209 -67.9734 319.727 0 0 1 2 lb |
|
| 83 |
-67.9734 319.727 229.095 176.227 526.164 32.7279 0 0 1 2 lb |
|
| 84 |
762.812 -17.6227 644.488 7.5526 526.164 32.7279 0 0 1 2 lb |
|
| 85 |
762.812 -17.6227 746.448 -162.381 730.084 -307.139 0 0 1 2 lb |
|
| 86 |
526.164 32.7279 470.779 -128.394 415.393 -289.516 0 0 1 2 lb |
|
| 87 |
730.084 -307.139 572.738 -298.327 415.393 -289.516 0 0 1 2 lb |
|
| 88 |
415.393 -289.516 173.71 -318.468 -67.9734 -347.42 1 0 0 2 lb |
|
| 89 |
-67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0 0 1 2 lb |
|
| 90 |
-67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0 0 1 2 lb |
|
| 91 |
-309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0 0 1 2 lb |
|
| 92 |
-323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0 0 1 2 lb |
|
| 93 |
-26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 0 0 1 2 lb |
|
| 94 |
-26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 0 0 1 2 lb |
|
| 95 |
-26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 0 0 1 2 lb |
|
| 96 |
-26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 0 0 1 2 lb |
|
| 97 |
116.407 -173.66 158.808 -67.6589 201.208 38.3422 0 0 1 2 lb |
|
| 98 |
-262.548 107.243 -137.997 120.493 -13.4452 133.743 0 0 1 2 lb |
|
| 99 |
-262.548 107.243 -221.472 176.144 -180.397 245.045 0 0 1 2 lb |
|
| 100 |
-13.4452 133.743 -96.9211 189.394 -180.397 245.045 0 0 1 2 lb |
|
| 101 |
-180.397 245.045 -142.256 345.099 -132.697 451.748 0 0 1 2 lb |
|
| 102 |
-180.397 245.045 -170.838 351.694 -132.697 451.748 0 0 1 2 lb |
|
| 103 |
-416.25 345.746 -274.474 398.747 -132.697 451.748 0 0 1 2 lb |
|
| 104 |
-416.25 345.746 -393.725 457.048 -371.2 568.349 0 0 1 2 lb |
|
| 105 |
-132.697 451.748 -251.948 510.048 -371.2 568.349 0 0 1 2 lb |
|
| 106 |
670.264 274.195 629.188 409.347 588.113 544.499 0 0 1 2 lb |
|
| 107 |
670.264 274.195 797.466 341.771 924.667 409.347 0 0 1 2 lb |
|
| 108 |
588.113 544.499 756.39 476.923 924.667 409.347 0 0 1 2 lb |
|
| 109 |
-689.204 -237.261 -614.799 -102.648 -567.302 43.6423 0 0 1 2 lb |
|
| 110 |
-689.204 -237.261 -641.707 -90.9706 -567.302 43.6423 0 0 1 2 lb |
|
| 111 |
grestore |
|
| 112 |
%Nodes: |
|
| 113 |
gsave |
|
| 114 |
-567.302 43.6423 20 0 0 0 nc |
|
| 115 |
-689.204 -237.261 20 0 0 0 nc |
|
| 116 |
924.667 409.347 20 0 0 1 nc |
|
| 117 |
588.113 544.499 20 0 0 1 nc |
|
| 118 |
670.264 274.195 20 0 0 1 nc |
|
| 119 |
-371.2 568.349 20 1 1 0 nc |
|
| 120 |
-132.697 451.748 20 1 1 0 nc |
|
| 121 |
-416.25 345.746 20 1 1 0 nc |
|
| 122 |
-180.397 245.045 20 1 1 0 nc |
|
| 123 |
-13.4452 133.743 20 1 1 0 nc |
|
| 124 |
-262.548 107.243 20 1 1 0 nc |
|
| 125 |
201.208 38.3422 20 1 1 0 nc |
|
| 126 |
116.407 -173.66 20 1 1 0 nc |
|
| 127 |
-26.6953 -19.9585 20 1 1 0 nc |
|
| 128 |
-539.894 -262.64 20 0 0.5 0 nc |
|
| 129 |
-323.543 -433.964 20 0 0.5 0 nc |
|
| 130 |
-309.657 -57.9033 20 0 0.5 0 nc |
|
| 131 |
-67.9734 -347.42 20 0 0.5 0 nc |
|
| 132 |
415.393 -289.516 20 0.5 0 0 nc |
|
| 133 |
730.084 -307.139 20 0.5 0 0 nc |
|
| 134 |
526.164 32.7279 20 0.5 0 0 nc |
|
| 135 |
762.812 -17.6227 20 0.5 0 0 nc |
|
| 136 |
-67.9734 319.727 20 0.5 0 0 nc |
|
| 137 |
329.797 314.692 20 0.5 0 0 nc |
|
| 138 |
-5.03507 561.41 20 0.5 0 0 nc |
|
| 139 |
422.945 521.129 20 0.5 0 0 nc |
|
| 140 |
-470.779 158.605 20 0 1 1 nc |
|
| 141 |
986.873 -115.807 20 0.5 0 0 nc |
|
| 142 |
906.312 201.403 20 0.5 0 0 nc |
|
| 143 |
-767.847 113.289 20 0 1 1 nc |
|
| 144 |
-579.033 445.603 20 0 1 1 nc |
|
| 145 |
-840.856 -246.718 20 1 0 1 nc |
|
| 146 |
206.221 -205.967 20 0 0 0.5 nc |
|
| 147 |
277.311 -252.33 20 0 0 0.5 nc |
|
| 148 |
271.13 -175.058 20 0 0 0.5 nc |
|
| 149 |
366.947 -110.15 20 0 0 0.5 nc |
|
| 150 |
397.855 -196.694 20 0 0 0.5 nc |
|
| 151 |
438.037 -88.514 20 0 0 0.5 nc |
|
| 152 |
286.584 -48.3327 20 0 0 0.5 nc |
|
| 153 |
212.403 -23.6057 20 0 0 0.5 nc |
|
| 154 |
280.402 10.3938 20 0 0 0.5 nc |
|
| 155 |
694.579 115.483 20 1 0 0 nc |
|
| 156 |
574.035 177.301 20 0 1 0 nc |
|
| 157 |
grestore |
|
| 158 |
grestore |
|
| 159 |
showpage |
| 1 |
%!PS-Adobe-2.0 EPSF-2.0 |
|
| 2 |
%%Creator: LEMON, graphToEps() |
|
| 3 |
%%CreationDate: Fri Nov 4 13:47:12 2005 |
|
| 4 |
%%BoundingBox: 0 0 842 596 |
|
| 5 |
%%EndComments |
|
| 6 |
/lb { setlinewidth setrgbcolor newpath moveto
|
|
| 7 |
4 2 roll 1 index 1 index curveto stroke } bind def |
|
| 8 |
/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
|
|
| 9 |
/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
|
|
| 10 |
/sq { newpath 2 index 1 index add 2 index 2 index add moveto
|
|
| 11 |
2 index 1 index sub 2 index 2 index add lineto |
|
| 12 |
2 index 1 index sub 2 index 2 index sub lineto |
|
| 13 |
2 index 1 index add 2 index 2 index sub lineto |
|
| 14 |
closepath pop pop pop} bind def |
|
| 15 |
/di { newpath 2 index 1 index add 2 index moveto
|
|
| 16 |
2 index 2 index 2 index add lineto |
|
| 17 |
2 index 1 index sub 2 index lineto |
|
| 18 |
2 index 2 index 2 index sub lineto |
|
| 19 |
closepath pop pop pop} bind def |
|
| 20 |
/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
|
|
| 21 |
setrgbcolor 1.1 div c fill |
|
| 22 |
} bind def |
|
| 23 |
/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
|
|
| 24 |
setrgbcolor 1.1 div sq fill |
|
| 25 |
} bind def |
|
| 26 |
/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
|
|
| 27 |
setrgbcolor 1.1 div di fill |
|
| 28 |
} bind def |
|
| 29 |
/arrl 1 def |
|
| 30 |
/arrw 0.3 def |
|
| 31 |
/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
|
|
| 32 |
/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
|
|
| 33 |
/w exch def /len exch def |
|
| 34 |
newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto |
|
| 35 |
len w sub arrl sub dx dy lrl |
|
| 36 |
arrw dy dx neg lrl |
|
| 37 |
dx arrl w add mul dy w 2 div arrw add mul sub |
|
| 38 |
dy arrl w add mul dx w 2 div arrw add mul add rlineto |
|
| 39 |
dx arrl w add mul neg dy w 2 div arrw add mul sub |
|
| 40 |
dy arrl w add mul neg dx w 2 div arrw add mul add rlineto |
|
| 41 |
arrw dy dx neg lrl |
|
| 42 |
len w sub arrl sub neg dx dy lrl |
|
| 43 |
closepath fill } bind def |
|
| 44 |
/cshow { 2 index 2 index moveto dup stringwidth pop
|
|
| 45 |
neg 2 div fosi .35 mul neg rmoveto show pop pop} def |
|
| 46 |
|
|
| 47 |
gsave |
|
| 48 |
90 rotate |
|
| 49 |
0 -842 translate |
|
| 50 |
71.0944 15 translate |
|
| 51 |
0.434694 dup scale |
|
| 52 |
90 rotate |
|
| 53 |
860.856 -588.349 translate |
|
| 54 |
%Edges: |
|
| 55 |
gsave |
|
| 56 |
574.035 177.301 622.149 225.748 670.264 274.195 0 1 0 5 lb |
|
| 57 |
694.579 115.483 682.421 194.839 670.264 274.195 1 0 0 5 lb |
|
| 58 |
280.402 10.3938 246.402 -6.60595 212.403 -23.6057 1 1 0.5 5 lb |
|
| 59 |
280.402 10.3938 283.493 -18.9695 286.584 -48.3327 1 1 0.5 5 lb |
|
| 60 |
212.403 -23.6057 249.493 -35.9692 286.584 -48.3327 1 1 0.5 5 lb |
|
| 61 |
286.584 -48.3327 326.765 -79.2414 366.947 -110.15 1 0.5 1 5 lb |
|
| 62 |
286.584 -48.3327 278.857 -111.695 271.13 -175.058 1 0.5 1 5 lb |
|
| 63 |
438.037 -88.514 417.946 -142.604 397.855 -196.694 0.5 0.5 1 5 lb |
|
| 64 |
438.037 -88.514 402.492 -99.332 366.947 -110.15 0.5 0.5 1 5 lb |
|
| 65 |
397.855 -196.694 382.401 -153.422 366.947 -110.15 0.5 0.5 1 5 lb |
|
| 66 |
366.947 -110.15 319.038 -142.604 271.13 -175.058 1 0.5 1 5 lb |
|
| 67 |
271.13 -175.058 274.221 -213.694 277.311 -252.33 0.5 1 1 5 lb |
|
| 68 |
271.13 -175.058 238.675 -190.512 206.221 -205.967 0.5 1 1 5 lb |
|
| 69 |
277.311 -252.33 241.766 -229.149 206.221 -205.967 0.5 1 1 5 lb |
|
| 70 |
-840.856 -246.718 -804.351 -66.7145 -767.847 113.289 0 0.5 0 5 lb |
|
| 71 |
-579.033 445.603 -673.44 279.446 -767.847 113.289 0 0 0.5 5 lb |
|
| 72 |
-579.033 445.603 -524.906 302.104 -470.779 158.605 0 0 0.5 5 lb |
|
| 73 |
-767.847 113.289 -619.313 135.947 -470.779 158.605 0 0 0.5 5 lb |
|
| 74 |
906.312 201.403 946.592 42.798 986.873 -115.807 0 0.5 0.5 5 lb |
|
| 75 |
906.312 201.403 834.562 91.8901 762.812 -17.6227 0 0.5 0.5 5 lb |
|
| 76 |
986.873 -115.807 874.842 -66.7148 762.812 -17.6227 0 0.5 0.5 5 lb |
|
| 77 |
-470.779 158.605 -390.218 50.3508 -309.657 -57.9033 0.5 0.5 0 5 lb |
|
| 78 |
422.945 521.129 208.955 541.269 -5.03507 561.41 0.5 0 0.5 5 lb |
|
| 79 |
422.945 521.129 376.371 417.911 329.797 314.692 0.5 0 0.5 5 lb |
|
| 80 |
422.945 521.129 474.554 276.928 526.164 32.7279 0.5 0 0.5 5 lb |
|
| 81 |
-5.03507 561.41 -36.5042 440.568 -67.9734 319.727 0.5 0 0.5 5 lb |
|
| 82 |
329.797 314.692 130.912 317.209 -67.9734 319.727 0.5 0 0.5 5 lb |
|
| 83 |
-67.9734 319.727 229.095 176.227 526.164 32.7279 0.5 0 0.5 5 lb |
|
| 84 |
762.812 -17.6227 644.488 7.5526 526.164 32.7279 0.5 0.5 0.5 5 lb |
|
| 85 |
762.812 -17.6227 746.448 -162.381 730.084 -307.139 0.5 0.5 0.5 5 lb |
|
| 86 |
526.164 32.7279 470.779 -128.394 415.393 -289.516 0.5 0.5 0.5 5 lb |
|
| 87 |
730.084 -307.139 572.738 -298.327 415.393 -289.516 0.5 0.5 0.5 5 lb |
|
| 88 |
415.393 -289.516 173.71 -318.468 -67.9734 -347.42 1 0.5 0.5 5 lb |
|
| 89 |
-67.9734 -347.42 -188.815 -202.662 -309.657 -57.9033 0.5 1 0.5 5 lb |
|
| 90 |
-67.9734 -347.42 -195.758 -390.692 -323.543 -433.964 0.5 1 0.5 5 lb |
|
| 91 |
-309.657 -57.9033 -424.775 -160.272 -539.894 -262.64 0.5 1 0.5 5 lb |
|
| 92 |
-323.543 -433.964 -431.719 -348.302 -539.894 -262.64 0.5 1 0.5 5 lb |
|
| 93 |
-26.6953 -19.9585 44.8558 -96.8093 116.407 -173.66 1 1 0 5 lb |
|
| 94 |
-26.6953 -19.9585 87.2563 9.19185 201.208 38.3422 1 1 0 5 lb |
|
| 95 |
-26.6953 -19.9585 -144.622 43.6422 -262.548 107.243 1 0 1 5 lb |
|
| 96 |
-26.6953 -19.9585 -20.0703 56.8923 -13.4452 133.743 1 0 1 5 lb |
|
| 97 |
116.407 -173.66 158.808 -67.6589 201.208 38.3422 1 1 0 5 lb |
|
| 98 |
-262.548 107.243 -137.997 120.493 -13.4452 133.743 1 0 1 5 lb |
|
| 99 |
-262.548 107.243 -221.472 176.144 -180.397 245.045 1 0 1 5 lb |
|
| 100 |
-13.4452 133.743 -96.9211 189.394 -180.397 245.045 1 0 1 5 lb |
|
| 101 |
-180.397 245.045 -140.307 344.649 -132.697 451.748 0 1 1 5 lb |
|
| 102 |
-180.397 245.045 -172.787 352.144 -132.697 451.748 0 1 1 5 lb |
|
| 103 |
-416.25 345.746 -274.474 398.747 -132.697 451.748 0.5 0 0 5 lb |
|
| 104 |
-416.25 345.746 -393.725 457.048 -371.2 568.349 0.5 0 0 5 lb |
|
| 105 |
-132.697 451.748 -251.948 510.048 -371.2 568.349 0.5 0 0 5 lb |
|
| 106 |
670.264 274.195 629.188 409.347 588.113 544.499 0 0 1 5 lb |
|
| 107 |
670.264 274.195 797.466 341.771 924.667 409.347 0 0 1 5 lb |
|
| 108 |
588.113 544.499 756.39 476.923 924.667 409.347 0 0 1 5 lb |
|
| 109 |
-689.204 -237.261 -612.964 -103.444 -567.302 43.6423 0 0 0 5 lb |
|
| 110 |
-689.204 -237.261 -643.542 -90.1744 -567.302 43.6423 0 0 0 5 lb |
|
| 111 |
grestore |
|
| 112 |
%Nodes: |
|
| 113 |
gsave |
|
| 114 |
-567.302 43.6423 20 0 0 1 nc |
|
| 115 |
-689.204 -237.261 20 0 0 1 nc |
|
| 116 |
924.667 409.347 20 0 0 1 nc |
|
| 117 |
588.113 544.499 20 0 0 1 nc |
|
| 118 |
670.264 274.195 20 1 0 0 nc |
|
| 119 |
-371.2 568.349 20 0 0 1 nc |
|
| 120 |
-132.697 451.748 20 1 0 0 nc |
|
| 121 |
-416.25 345.746 20 0 0 1 nc |
|
| 122 |
-180.397 245.045 20 1 0 0 nc |
|
| 123 |
-13.4452 133.743 20 0 0 1 nc |
|
| 124 |
-262.548 107.243 20 0 0 1 nc |
|
| 125 |
201.208 38.3422 20 0 0 1 nc |
|
| 126 |
116.407 -173.66 20 0 0 1 nc |
|
| 127 |
-26.6953 -19.9585 20 1 0 0 nc |
|
| 128 |
-539.894 -262.64 20 0 0 1 nc |
|
| 129 |
-323.543 -433.964 20 0 0 1 nc |
|
| 130 |
-309.657 -57.9033 20 1 0 0 nc |
|
| 131 |
-67.9734 -347.42 20 1 0 0 nc |
|
| 132 |
415.393 -289.516 20 1 0 0 nc |
|
| 133 |
730.084 -307.139 20 0 0 1 nc |
|
| 134 |
526.164 32.7279 20 1 0 0 nc |
|
| 135 |
762.812 -17.6227 20 1 0 0 nc |
|
| 136 |
-67.9734 319.727 20 0 0 1 nc |
|
| 137 |
329.797 314.692 20 0 0 1 nc |
|
| 138 |
-5.03507 561.41 20 0 0 1 nc |
|
| 139 |
422.945 521.129 20 0 0 1 nc |
|
| 140 |
-470.779 158.605 20 1 0 0 nc |
|
| 141 |
986.873 -115.807 20 0 0 1 nc |
|
| 142 |
906.312 201.403 20 0 0 1 nc |
|
| 143 |
-767.847 113.289 20 1 0 0 nc |
|
| 144 |
-579.033 445.603 20 0 0 1 nc |
|
| 145 |
-840.856 -246.718 20 0 0 1 nc |
|
| 146 |
206.221 -205.967 20 0 0 1 nc |
|
| 147 |
277.311 -252.33 20 0 0 1 nc |
|
| 148 |
271.13 -175.058 20 1 0 0 nc |
|
| 149 |
366.947 -110.15 20 1 0 0 nc |
|
| 150 |
397.855 -196.694 20 0 0 1 nc |
|
| 151 |
438.037 -88.514 20 0 0 1 nc |
|
| 152 |
286.584 -48.3327 20 1 0 0 nc |
|
| 153 |
212.403 -23.6057 20 0 0 1 nc |
|
| 154 |
280.402 10.3938 20 0 0 1 nc |
|
| 155 |
694.579 115.483 20 0 0 1 nc |
|
| 156 |
574.035 177.301 20 0 0 1 nc |
|
| 157 |
grestore |
|
| 158 |
grestore |
|
| 159 |
showpage |
| 1 |
%!PS-Adobe-2.0 EPSF-2.0 |
|
| 2 |
%%Creator: LEMON, graphToEps() |
|
| 3 |
%%CreationDate: Fri Nov 4 13:47:12 2005 |
|
| 4 |
%%BoundingBox: 0 0 842 596 |
|
| 5 |
%%EndComments |
|
| 6 |
/lb { setlinewidth setrgbcolor newpath moveto
|
|
| 7 |
4 2 roll 1 index 1 index curveto stroke } bind def |
|
| 8 |
/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
|
|
| 9 |
/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
|
|
| 10 |
/sq { newpath 2 index 1 index add 2 index 2 index add moveto
|
|
| 11 |
2 index 1 index sub 2 index 2 index add lineto |
|
| 12 |
2 index 1 index sub 2 index 2 index sub lineto |
|
| 13 |
2 index 1 index add 2 index 2 index sub lineto |
|
| 14 |
closepath pop pop pop} bind def |
|
| 15 |
/di { newpath 2 index 1 index add 2 index moveto
|
|
| 16 |
2 index 2 index 2 index add lineto |
|
| 17 |
2 index 1 index sub 2 index lineto |
|
| 18 |
2 index 2 index 2 index sub lineto |
|
| 19 |
closepath pop pop pop} bind def |
|
| 20 |
/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
|
|
| 21 |
setrgbcolor 1.1 div c fill |
|
| 22 |
} bind def |
|
| 23 |
/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
|
|
| 24 |
setrgbcolor 1.1 div sq fill |
|
| 25 |
} bind def |
|
| 26 |
/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
|
|
| 27 |
setrgbcolor 1.1 div di fill |
|
| 28 |
} bind def |
|
| 29 |
/arrl 10 def |
|
| 30 |
/arrw 3 def |
|
| 31 |
/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
|
|
| 32 |
/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
|
|
| 33 |
/w exch def /len exch def |
|
| 34 |
newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto |
|
| 35 |
len w sub arrl sub dx dy lrl |
|
| 36 |
arrw dy dx neg lrl |
|
| 37 |
dx arrl w add mul dy w 2 div arrw add mul sub |
|
| 38 |
dy arrl w add mul dx w 2 div arrw add mul add rlineto |
|
| 39 |
dx arrl w add mul neg dy w 2 div arrw add mul sub |
|
| 40 |
dy arrl w add mul neg dx w 2 div arrw add mul add rlineto |
|
| 41 |
arrw dy dx neg lrl |
|
| 42 |
len w sub arrl sub neg dx dy lrl |
|
| 43 |
closepath fill } bind def |
|
| 44 |
/cshow { 2 index 2 index moveto dup stringwidth pop
|
|
| 45 |
neg 2 div fosi .35 mul neg rmoveto show pop pop} def |
|
| 46 |
|
|
| 47 |
gsave |
|
| 48 |
90 rotate |
|
| 49 |
0 -842 translate |
|
| 50 |
77.1122 15 translate |
|
| 51 |
0.585745 dup scale |
|
| 52 |
90 rotate |
|
| 53 |
695.963 -397.916 translate |
|
| 54 |
%Edges: |
|
| 55 |
gsave |
|
| 56 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 57 |
218.178 27.2723 moveto |
|
| 58 |
192.373 -40.1551 188.622 -49.9556 169.228 -100.631 curveto stroke |
|
| 59 |
newpath 164.939 -111.838 moveto 165.492 -99.2013 lineto 172.964 -102.061 lineto closepath fill |
|
| 60 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 61 |
44.8044 15.5841 moveto |
|
| 62 |
119.293 20.6059 129.775 21.3125 186.25 25.1199 curveto stroke |
|
| 63 |
newpath 198.223 25.927 moveto 186.519 21.1289 lineto 185.981 29.1108 lineto closepath fill |
|
| 64 |
2 setlinewidth 1 0 0 setrgbcolor newpath |
|
| 65 |
218.178 27.2723 moveto |
|
| 66 |
285.395 -87.4449 290.763 -96.6058 348.102 -194.464 curveto stroke |
|
| 67 |
newpath 354.169 -204.818 moveto 344.651 -196.487 lineto 351.554 -192.442 lineto closepath fill |
|
| 68 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 69 |
157.79 -130.517 moveto |
|
| 70 |
108.71 -67.0521 102.27 -58.7243 64.3804 -9.72954 curveto stroke |
|
| 71 |
newpath 57.0394 -0.236898 moveto 67.5446 -7.28254 lineto 61.2162 -12.1765 lineto closepath fill |
|
| 72 |
2 setlinewidth 1 0 0 setrgbcolor newpath |
|
| 73 |
-105.193 -261.035 moveto |
|
| 74 |
-35.6576 -132.801 -30.5923 -123.459 29.5506 -12.5464 curveto stroke |
|
| 75 |
newpath 35.2708 -1.99743 moveto 33.0669 -14.4531 lineto 26.0343 -10.6397 lineto closepath fill |
|
| 76 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 77 |
-465.576 -42.8564 moveto |
|
| 78 |
-559.078 -25.5413 -569.47 -23.6169 -644.498 -9.72286 curveto stroke |
|
| 79 |
newpath -656.297 -7.5378 moveto -643.77 -5.78973 lineto -645.226 -13.656 lineto closepath fill |
|
| 80 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 81 |
-574.666 -153.893 moveto |
|
| 82 |
-528.842 -107.252 -521.515 -99.794 -488.002 -65.683 curveto stroke |
|
| 83 |
newpath -479.592 -57.123 moveto -485.149 -68.4863 lineto -490.856 -62.8797 lineto closepath fill |
|
| 84 |
2 setlinewidth 1 0 0 setrgbcolor newpath |
|
| 85 |
-490.901 120.777 moveto |
|
| 86 |
-480.122 51.1328 -478.519 40.7713 -470.47 -11.2329 curveto stroke |
|
| 87 |
newpath -468.635 -23.0917 moveto -474.423 -11.8447 lineto -466.517 -10.6212 lineto closepath fill |
|
| 88 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 89 |
-675.963 -3.89604 moveto |
|
| 90 |
-632.116 -68.8235 -626.228 -77.5422 -592.575 -127.374 curveto stroke |
|
| 91 |
newpath -585.859 -137.319 moveto -595.89 -129.612 lineto -589.26 -125.135 lineto closepath fill |
|
| 92 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 93 |
-490.901 120.777 moveto |
|
| 94 |
-435.445 215.844 -430.107 224.995 -384.3 303.522 curveto stroke |
|
| 95 |
newpath -378.253 313.887 moveto -380.845 301.507 lineto -387.755 305.537 lineto closepath fill |
|
| 96 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 97 |
-266.879 114.933 moveto |
|
| 98 |
-367.067 117.547 -377.642 117.822 -458.912 119.943 curveto stroke |
|
| 99 |
newpath -470.908 120.255 moveto -458.807 123.941 lineto -459.016 115.944 lineto closepath fill |
|
| 100 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 101 |
-368.176 331.163 moveto |
|
| 102 |
-322.511 233.685 -318.018 224.095 -280.454 143.911 curveto stroke |
|
| 103 |
newpath -275.364 133.044 moveto -284.076 142.214 lineto -276.832 145.608 lineto closepath fill |
|
| 104 |
2 setlinewidth 1 0 0 setrgbcolor newpath |
|
| 105 |
-266.879 114.933 moveto |
|
| 106 |
-224.004 235.52 -220.448 245.52 -184.094 347.765 curveto stroke |
|
| 107 |
newpath -180.074 359.072 moveto -180.325 346.425 lineto -187.863 349.105 lineto closepath fill |
|
| 108 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 109 |
-251.294 -335.059 moveto |
|
| 110 |
-189.25 -303.624 -179.902 -298.887 -133.738 -275.498 curveto stroke |
|
| 111 |
newpath -123.034 -270.074 moveto -131.93 -279.066 lineto -135.546 -271.93 lineto closepath fill |
|
| 112 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 113 |
-389.604 -136.361 moveto |
|
| 114 |
-327.15 -226.083 -321.098 -234.777 -269.576 -308.795 curveto stroke |
|
| 115 |
newpath -262.72 -318.644 moveto -272.859 -311.081 lineto -266.293 -306.51 lineto closepath fill |
|
| 116 |
2 setlinewidth 1 0 0 setrgbcolor newpath |
|
| 117 |
5.84406 175.322 moveto |
|
| 118 |
-76.0754 267.926 -83.1051 275.873 -152.172 353.948 curveto stroke |
|
| 119 |
newpath -160.122 362.936 moveto -149.176 356.598 lineto -155.168 351.298 lineto closepath fill |
|
| 120 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 121 |
169.478 311.683 moveto |
|
| 122 |
96.8003 251.119 88.6819 244.353 30.4273 195.808 curveto stroke |
|
| 123 |
newpath 21.2086 188.126 moveto 27.8666 198.881 lineto 32.988 192.735 lineto closepath fill |
|
| 124 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 125 |
342.851 111.037 moveto |
|
| 126 |
263.766 202.563 256.831 210.589 190.4 287.47 curveto stroke |
|
| 127 |
newpath 182.554 296.55 moveto 193.427 290.085 lineto 187.373 284.855 lineto closepath fill |
|
| 128 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 129 |
5.84406 175.322 moveto |
|
| 130 |
163.16 145.314 173.605 143.321 311.418 117.033 curveto stroke |
|
| 131 |
newpath 323.205 114.784 moveto 310.668 113.104 lineto 312.167 120.962 lineto closepath fill |
|
| 132 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 133 |
342.851 111.037 moveto |
|
| 134 |
497.255 2.58683 505.964 -3.53033 643.932 -100.436 curveto stroke |
|
| 135 |
newpath 653.752 -107.334 moveto 641.633 -103.71 lineto 646.231 -97.163 lineto closepath fill |
|
| 136 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 137 |
364.28 -222.074 moveto |
|
| 138 |
354.298 -66.9063 353.616 -56.2971 344.905 79.1029 curveto stroke |
|
| 139 |
newpath 344.135 91.0781 moveto 348.897 79.3597 lineto 340.914 78.8461 lineto closepath fill |
|
| 140 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 141 |
670.118 -118.829 moveto |
|
| 142 |
528.037 -166.793 517.967 -170.192 394.599 -211.839 curveto stroke |
|
| 143 |
newpath 383.229 -215.677 moveto 393.32 -208.049 lineto 395.878 -215.629 lineto closepath fill |
|
| 144 |
2 setlinewidth 1 0 0 setrgbcolor newpath |
|
| 145 |
-105.193 -261.035 moveto |
|
| 146 |
118.401 -242.479 129.015 -241.598 332.39 -224.721 curveto stroke |
|
| 147 |
newpath 344.348 -223.728 moveto 332.72 -228.707 lineto 332.059 -220.734 lineto closepath fill |
|
| 148 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 149 |
-105.193 -261.035 moveto |
|
| 150 |
-160.867 -161.176 -166.028 -151.918 -212.336 -68.858 curveto stroke |
|
| 151 |
newpath -218.179 -58.3769 moveto -208.842 -66.9102 lineto -215.829 -70.8058 lineto closepath fill |
|
| 152 |
2 setlinewidth 0 0 1 setrgbcolor newpath |
|
| 153 |
-227.918 -40.9084 moveto |
|
| 154 |
-298.35 -82.4884 -307.42 -87.8432 -362.048 -120.093 curveto stroke |
|
| 155 |
newpath -372.381 -126.193 moveto -364.081 -116.648 lineto -360.014 -123.537 lineto closepath fill |
|
| 156 |
grestore |
|
| 157 |
%Nodes: |
|
| 158 |
gsave |
|
| 159 |
-389.604 -136.361 20 0 1 0 nc |
|
| 160 |
-227.918 -40.9084 20 0 1 0 nc |
|
| 161 |
-105.193 -261.035 20 0 1 0 nc |
|
| 162 |
364.28 -222.074 20 1 1 0 nc |
|
| 163 |
670.118 -118.829 20 1 1 0 nc |
|
| 164 |
342.851 111.037 20 1 1 0 nc |
|
| 165 |
5.84406 175.322 20 1 1 0 nc |
|
| 166 |
169.478 311.683 20 1 1 0 nc |
|
| 167 |
-173.374 377.916 20 1 0 1 nc |
|
| 168 |
-251.294 -335.059 20 0 1 0 nc |
|
| 169 |
-266.879 114.933 20 0 0 0 nc |
|
| 170 |
-368.176 331.163 20 0 0 0 nc |
|
| 171 |
-490.901 120.777 20 0 0 0 nc |
|
| 172 |
-574.666 -153.893 20 1 0 0 nc |
|
| 173 |
-675.963 -3.89604 20 1 0 0 nc |
|
| 174 |
-465.576 -42.8564 20 1 0 0 nc |
|
| 175 |
44.8044 15.5841 20 0 0 1 nc |
|
| 176 |
157.79 -130.517 20 0 0 1 nc |
|
| 177 |
218.178 27.2723 20 0 0 1 nc |
|
| 178 |
grestore |
|
| 179 |
grestore |
|
| 180 |
showpage |
| 1 | 1 |
SET(PACKAGE_NAME ${PROJECT_NAME})
|
| 2 | 2 |
SET(PACKAGE_VERSION ${PROJECT_VERSION})
|
| 3 | 3 |
SET(abs_top_srcdir ${PROJECT_SOURCE_DIR})
|
| 4 | 4 |
SET(abs_top_builddir ${PROJECT_BINARY_DIR})
|
| 5 | 5 |
|
| 6 | 6 |
CONFIGURE_FILE( |
| 7 | 7 |
${PROJECT_SOURCE_DIR}/doc/Doxyfile.in
|
| 8 | 8 |
${PROJECT_BINARY_DIR}/doc/Doxyfile
|
| 9 | 9 |
@ONLY) |
| 10 | 10 |
|
| 11 | 11 |
IF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE) |
| 12 | 12 |
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/)
|
| 13 | 13 |
IF(UNIX) |
| 14 | 14 |
ADD_CUSTOM_TARGET(html |
| 15 | 15 |
COMMAND rm -rf gen-images |
| 16 | 16 |
COMMAND mkdir gen-images |
| 17 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/bipartite_matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_matching.eps
|
|
| 18 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/bipartite_partitions.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_partitions.eps
|
|
| 19 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/connected_components.eps
|
|
| 20 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps
|
|
| 17 | 21 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps
|
| 22 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps
|
|
| 18 | 23 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps
|
| 19 | 24 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps
|
| 20 | 25 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps
|
| 21 | 26 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps
|
| 22 | 27 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
|
| 28 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps
|
|
| 23 | 29 |
COMMAND rm -rf html |
| 24 | 30 |
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
|
| 25 | 31 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
| 26 | 32 |
ELSEIF(WIN32) |
| 27 | 33 |
ADD_CUSTOM_TARGET(html |
| 28 | 34 |
COMMAND if exist gen-images rmdir /s /q gen-images |
| 29 | 35 |
COMMAND mkdir gen-images |
| 36 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/bipartite_matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_matching.eps
|
|
| 37 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/bipartite_partitions.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_partitions.eps
|
|
| 38 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/connected_components.eps
|
|
| 39 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps
|
|
| 40 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps
|
|
| 41 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps
|
|
| 30 | 42 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps
|
| 31 | 43 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps
|
| 32 | 44 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps
|
| 33 | 45 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps
|
| 34 | 46 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
|
| 47 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps
|
|
| 35 | 48 |
COMMAND if exist html rmdir /s /q html |
| 36 | 49 |
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
|
| 37 | 50 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
| 38 | 51 |
ENDIF(UNIX) |
| 39 | 52 |
INSTALL( |
| 40 | 53 |
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
|
| 41 | 54 |
DESTINATION share/doc |
| 42 | 55 |
COMPONENT html_documentation) |
| 43 | 56 |
ENDIF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE) |
| 1 | 1 |
EXTRA_DIST += \ |
| 2 | 2 |
doc/Doxyfile.in \ |
| 3 | 3 |
doc/DoxygenLayout.xml \ |
| 4 | 4 |
doc/coding_style.dox \ |
| 5 | 5 |
doc/dirs.dox \ |
| 6 | 6 |
doc/groups.dox \ |
| 7 | 7 |
doc/lgf.dox \ |
| 8 | 8 |
doc/license.dox \ |
| 9 | 9 |
doc/mainpage.dox \ |
| 10 | 10 |
doc/migration.dox \ |
| 11 | 11 |
doc/named-param.dox \ |
| 12 | 12 |
doc/namespaces.dox \ |
| 13 | 13 |
doc/html \ |
| 14 | 14 |
doc/CMakeLists.txt |
| 15 | 15 |
|
| 16 | 16 |
DOC_EPS_IMAGES18 = \ |
| 17 | 17 |
grid_graph.eps \ |
| 18 | 18 |
nodeshape_0.eps \ |
| 19 | 19 |
nodeshape_1.eps \ |
| 20 | 20 |
nodeshape_2.eps \ |
| 21 | 21 |
nodeshape_3.eps \ |
| 22 | 22 |
nodeshape_4.eps |
| 23 | 23 |
|
| 24 |
DOC_EPS_IMAGES27 = \ |
|
| 25 |
bipartite_matching.eps \ |
|
| 26 |
bipartite_partitions.eps \ |
|
| 27 |
connected_components.eps \ |
|
| 28 |
edge_biconnected_components.eps \ |
|
| 29 |
node_biconnected_components.eps \ |
|
| 30 |
strongly_connected_components.eps |
|
| 31 |
|
|
| 24 | 32 |
DOC_EPS_IMAGES = \ |
| 25 |
$(DOC_EPS_IMAGES18) |
|
| 33 |
$(DOC_EPS_IMAGES18) \ |
|
| 34 |
$(DOC_EPS_IMAGES27) |
|
| 26 | 35 |
|
| 27 | 36 |
DOC_PNG_IMAGES = \ |
| 28 | 37 |
$(DOC_EPS_IMAGES:%.eps=doc/gen-images/%.png) |
| 29 | 38 |
|
| 30 | 39 |
EXTRA_DIST += $(DOC_EPS_IMAGES:%=doc/images/%) |
| 31 | 40 |
|
| 32 | 41 |
doc/html: |
| 33 | 42 |
$(MAKE) $(AM_MAKEFLAGS) html |
| 34 | 43 |
|
| 35 | 44 |
GS_COMMAND=gs -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 |
| 36 | 45 |
|
| 37 | 46 |
$(DOC_EPS_IMAGES18:%.eps=doc/gen-images/%.png): doc/gen-images/%.png: doc/images/%.eps |
| 38 | 47 |
-mkdir doc/gen-images |
| 39 | 48 |
if test ${gs_found} = yes; then \
|
| 40 | 49 |
$(GS_COMMAND) -sDEVICE=pngalpha -r18 -sOutputFile=$@ $<; \ |
| 41 | 50 |
else \ |
| 42 | 51 |
echo; \ |
| 43 | 52 |
echo "Ghostscript not found."; \ |
| 44 | 53 |
echo; \ |
| 45 | 54 |
exit 1; \ |
| 46 | 55 |
fi |
| 47 | 56 |
|
| 57 |
$(DOC_EPS_IMAGES27:%.eps=doc/gen-images/%.png): doc/gen-images/%.png: doc/images/%.eps |
|
| 58 |
-mkdir doc/gen-images |
|
| 59 |
if test ${gs_found} = yes; then \
|
|
| 60 |
$(GS_COMMAND) -sDEVICE=pngalpha -r27 -sOutputFile=$@ $<; \ |
|
| 61 |
else \ |
|
| 62 |
echo; \ |
|
| 63 |
echo "Ghostscript not found."; \ |
|
| 64 |
echo; \ |
|
| 65 |
exit 1; \ |
|
| 66 |
fi |
|
| 67 |
|
|
| 48 | 68 |
html-local: $(DOC_PNG_IMAGES) |
| 49 | 69 |
if test ${doxygen_found} = yes; then \
|
| 50 | 70 |
cd doc; \ |
| 51 | 71 |
doxygen Doxyfile; \ |
| 52 | 72 |
cd ..; \ |
| 53 | 73 |
else \ |
| 54 | 74 |
echo; \ |
| 55 | 75 |
echo "Doxygen not found."; \ |
| 56 | 76 |
echo; \ |
| 57 | 77 |
exit 1; \ |
| 58 | 78 |
fi |
| 59 | 79 |
|
| 60 | 80 |
clean-local: |
| 61 | 81 |
-rm -rf doc/html |
| 62 | 82 |
-rm -f doc/doxygen.log |
| 63 | 83 |
-rm -f $(DOC_PNG_IMAGES) |
| 64 | 84 |
-rm -rf doc/gen-images |
| 65 | 85 |
|
| 66 | 86 |
update-external-tags: |
| 67 | 87 |
wget -O doc/libstdc++.tag.tmp http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/libstdc++.tag && \ |
| 68 | 88 |
mv doc/libstdc++.tag.tmp doc/libstdc++.tag || \ |
| 69 | 89 |
rm doc/libstdc++.tag.tmp |
| 70 | 90 |
|
| 71 | 91 |
install-html-local: doc/html |
| 72 | 92 |
@$(NORMAL_INSTALL) |
| 73 | 93 |
$(mkinstalldirs) $(DESTDIR)$(htmldir)/docs |
| 74 | 94 |
for p in doc/html/*.{html,css,png,map,gif,tag} ; do \
|
| 75 | 95 |
f="`echo $$p | sed -e 's|^.*/||'`"; \ |
| 76 | 96 |
echo " $(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/docs/$$f"; \ |
| 77 | 97 |
$(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/docs/$$f; \ |
| 78 | 98 |
done |
| 79 | 99 |
|
| 80 | 100 |
uninstall-local: |
| 81 | 101 |
@$(NORMAL_UNINSTALL) |
| 82 | 102 |
for p in doc/html/*.{html,css,png,map,gif,tag} ; do \
|
| 83 | 103 |
f="`echo $$p | sed -e 's|^.*/||'`"; \ |
| 84 | 104 |
echo " rm -f $(DESTDIR)$(htmldir)/docs/$$f"; \ |
| 85 | 105 |
rm -f $(DESTDIR)$(htmldir)/docs/$$f; \ |
| 86 | 106 |
done |
| 87 | 107 |
|
| 88 | 108 |
.PHONY: update-external-tags |
| ... | ... |
@@ -362,97 +362,97 @@ |
| 362 | 362 |
the following optimization problem. |
| 363 | 363 |
|
| 364 | 364 |
\f[ \min\sum_{a\in A} f(a) cost(a) \f]
|
| 365 | 365 |
\f[ \sum_{a\in\delta_{out}(v)} f(a) - \sum_{a\in\delta_{in}(v)} f(a) =
|
| 366 | 366 |
supply(v) \qquad \forall v\in V \f] |
| 367 | 367 |
\f[ lower(a) \leq f(a) \leq upper(a) \qquad \forall a\in A \f] |
| 368 | 368 |
|
| 369 | 369 |
LEMON contains several algorithms for solving minimum cost flow problems: |
| 370 | 370 |
- \ref CycleCanceling Cycle-canceling algorithms. |
| 371 | 371 |
- \ref CapacityScaling Successive shortest path algorithm with optional |
| 372 | 372 |
capacity scaling. |
| 373 | 373 |
- \ref CostScaling Push-relabel and augment-relabel algorithms based on |
| 374 | 374 |
cost scaling. |
| 375 | 375 |
- \ref NetworkSimplex Primal network simplex algorithm with various |
| 376 | 376 |
pivot strategies. |
| 377 | 377 |
*/ |
| 378 | 378 |
|
| 379 | 379 |
/** |
| 380 | 380 |
@defgroup min_cut Minimum Cut Algorithms |
| 381 | 381 |
@ingroup algs |
| 382 | 382 |
|
| 383 | 383 |
\brief Algorithms for finding minimum cut in graphs. |
| 384 | 384 |
|
| 385 | 385 |
This group contains the algorithms for finding minimum cut in graphs. |
| 386 | 386 |
|
| 387 | 387 |
The \e minimum \e cut \e problem is to find a non-empty and non-complete |
| 388 | 388 |
\f$X\f$ subset of the nodes with minimum overall capacity on |
| 389 | 389 |
outgoing arcs. Formally, there is a \f$G=(V,A)\f$ digraph, a |
| 390 | 390 |
\f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum
|
| 391 | 391 |
cut is the \f$X\f$ solution of the next optimization problem: |
| 392 | 392 |
|
| 393 | 393 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
|
| 394 | 394 |
\sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
|
| 395 | 395 |
|
| 396 | 396 |
LEMON contains several algorithms related to minimum cut problems: |
| 397 | 397 |
|
| 398 | 398 |
- \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut |
| 399 | 399 |
in directed graphs. |
| 400 | 400 |
- \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for |
| 401 | 401 |
calculating minimum cut in undirected graphs. |
| 402 | 402 |
- \ref GomoryHu "Gomory-Hu tree computation" for calculating |
| 403 | 403 |
all-pairs minimum cut in undirected graphs. |
| 404 | 404 |
|
| 405 | 405 |
If you want to find minimum cut just between two distinict nodes, |
| 406 | 406 |
see the \ref max_flow "maximum flow problem". |
| 407 | 407 |
*/ |
| 408 | 408 |
|
| 409 | 409 |
/** |
| 410 |
@defgroup |
|
| 410 |
@defgroup graph_properties Connectivity and Other Graph Properties |
|
| 411 | 411 |
@ingroup algs |
| 412 | 412 |
\brief Algorithms for discovering the graph properties |
| 413 | 413 |
|
| 414 | 414 |
This group contains the algorithms for discovering the graph properties |
| 415 | 415 |
like connectivity, bipartiteness, euler property, simplicity etc. |
| 416 | 416 |
|
| 417 | 417 |
\image html edge_biconnected_components.png |
| 418 | 418 |
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
| 419 | 419 |
*/ |
| 420 | 420 |
|
| 421 | 421 |
/** |
| 422 | 422 |
@defgroup planar Planarity Embedding and Drawing |
| 423 | 423 |
@ingroup algs |
| 424 | 424 |
\brief Algorithms for planarity checking, embedding and drawing |
| 425 | 425 |
|
| 426 | 426 |
This group contains the algorithms for planarity checking, |
| 427 | 427 |
embedding and drawing. |
| 428 | 428 |
|
| 429 | 429 |
\image html planar.png |
| 430 | 430 |
\image latex planar.eps "Plane graph" width=\textwidth |
| 431 | 431 |
*/ |
| 432 | 432 |
|
| 433 | 433 |
/** |
| 434 | 434 |
@defgroup matching Matching Algorithms |
| 435 | 435 |
@ingroup algs |
| 436 | 436 |
\brief Algorithms for finding matchings in graphs and bipartite graphs. |
| 437 | 437 |
|
| 438 | 438 |
This group contains algorithm objects and functions to calculate |
| 439 | 439 |
matchings in graphs and bipartite graphs. The general matching problem is |
| 440 | 440 |
finding a subset of the arcs which does not shares common endpoints. |
| 441 | 441 |
|
| 442 | 442 |
There are several different algorithms for calculate matchings in |
| 443 | 443 |
graphs. The matching problems in bipartite graphs are generally |
| 444 | 444 |
easier than in general graphs. The goal of the matching optimization |
| 445 | 445 |
can be finding maximum cardinality, maximum weight or minimum cost |
| 446 | 446 |
matching. The search can be constrained to find perfect or |
| 447 | 447 |
maximum cardinality matching. |
| 448 | 448 |
|
| 449 | 449 |
The matching algorithms implemented in LEMON: |
| 450 | 450 |
- \ref MaxBipartiteMatching Hopcroft-Karp augmenting path algorithm |
| 451 | 451 |
for calculating maximum cardinality matching in bipartite graphs. |
| 452 | 452 |
- \ref PrBipartiteMatching Push-relabel algorithm |
| 453 | 453 |
for calculating maximum cardinality matching in bipartite graphs. |
| 454 | 454 |
- \ref MaxWeightedBipartiteMatching |
| 455 | 455 |
Successive shortest path algorithm for calculating maximum weighted |
| 456 | 456 |
matching and maximum weighted bipartite matching in bipartite graphs. |
| 457 | 457 |
- \ref MinCostMaxBipartiteMatching |
| 458 | 458 |
Successive shortest path algorithm for calculating minimum cost maximum |
| ... | ... |
@@ -2147,96 +2147,99 @@ |
| 2147 | 2147 |
: Parent(adaptor) {}
|
| 2148 | 2148 |
|
| 2149 | 2149 |
ArcMap(const UndirectorBase<DGR>& adaptor, const V& value) |
| 2150 | 2150 |
: Parent(adaptor, value) {}
|
| 2151 | 2151 |
|
| 2152 | 2152 |
private: |
| 2153 | 2153 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 2154 | 2154 |
return operator=<ArcMap>(cmap); |
| 2155 | 2155 |
} |
| 2156 | 2156 |
|
| 2157 | 2157 |
template <typename CMap> |
| 2158 | 2158 |
ArcMap& operator=(const CMap& cmap) {
|
| 2159 | 2159 |
Parent::operator=(cmap); |
| 2160 | 2160 |
return *this; |
| 2161 | 2161 |
} |
| 2162 | 2162 |
}; |
| 2163 | 2163 |
|
| 2164 | 2164 |
template <typename V> |
| 2165 | 2165 |
class EdgeMap : public Digraph::template ArcMap<V> {
|
| 2166 | 2166 |
public: |
| 2167 | 2167 |
|
| 2168 | 2168 |
typedef V Value; |
| 2169 | 2169 |
typedef typename Digraph::template ArcMap<V> Parent; |
| 2170 | 2170 |
|
| 2171 | 2171 |
explicit EdgeMap(const UndirectorBase<DGR>& adaptor) |
| 2172 | 2172 |
: Parent(*adaptor._digraph) {}
|
| 2173 | 2173 |
|
| 2174 | 2174 |
EdgeMap(const UndirectorBase<DGR>& adaptor, const V& value) |
| 2175 | 2175 |
: Parent(*adaptor._digraph, value) {}
|
| 2176 | 2176 |
|
| 2177 | 2177 |
private: |
| 2178 | 2178 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 2179 | 2179 |
return operator=<EdgeMap>(cmap); |
| 2180 | 2180 |
} |
| 2181 | 2181 |
|
| 2182 | 2182 |
template <typename CMap> |
| 2183 | 2183 |
EdgeMap& operator=(const CMap& cmap) {
|
| 2184 | 2184 |
Parent::operator=(cmap); |
| 2185 | 2185 |
return *this; |
| 2186 | 2186 |
} |
| 2187 | 2187 |
|
| 2188 | 2188 |
}; |
| 2189 | 2189 |
|
| 2190 | 2190 |
typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier; |
| 2191 | 2191 |
NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
|
| 2192 | 2192 |
|
| 2193 | 2193 |
typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier; |
| 2194 | 2194 |
EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); }
|
| 2195 |
|
|
| 2196 |
typedef EdgeNotifier ArcNotifier; |
|
| 2197 |
ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); }
|
|
| 2195 | 2198 |
|
| 2196 | 2199 |
protected: |
| 2197 | 2200 |
|
| 2198 | 2201 |
UndirectorBase() : _digraph(0) {}
|
| 2199 | 2202 |
|
| 2200 | 2203 |
DGR* _digraph; |
| 2201 | 2204 |
|
| 2202 | 2205 |
void initialize(DGR& digraph) {
|
| 2203 | 2206 |
_digraph = &digraph; |
| 2204 | 2207 |
} |
| 2205 | 2208 |
|
| 2206 | 2209 |
}; |
| 2207 | 2210 |
|
| 2208 | 2211 |
/// \ingroup graph_adaptors |
| 2209 | 2212 |
/// |
| 2210 | 2213 |
/// \brief Adaptor class for viewing a digraph as an undirected graph. |
| 2211 | 2214 |
/// |
| 2212 | 2215 |
/// Undirector adaptor can be used for viewing a digraph as an undirected |
| 2213 | 2216 |
/// graph. All arcs of the underlying digraph are showed in the |
| 2214 | 2217 |
/// adaptor as an edge (and also as a pair of arcs, of course). |
| 2215 | 2218 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept. |
| 2216 | 2219 |
/// |
| 2217 | 2220 |
/// The adapted digraph can also be modified through this adaptor |
| 2218 | 2221 |
/// by adding or removing nodes or edges, unless the \c GR template |
| 2219 | 2222 |
/// parameter is set to be \c const. |
| 2220 | 2223 |
/// |
| 2221 | 2224 |
/// \tparam DGR The type of the adapted digraph. |
| 2222 | 2225 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 2223 | 2226 |
/// It can also be specified to be \c const. |
| 2224 | 2227 |
/// |
| 2225 | 2228 |
/// \note The \c Node type of this adaptor and the adapted digraph are |
| 2226 | 2229 |
/// convertible to each other, moreover the \c Edge type of the adaptor |
| 2227 | 2230 |
/// and the \c Arc type of the adapted digraph are also convertible to |
| 2228 | 2231 |
/// each other. |
| 2229 | 2232 |
/// (Thus the \c Arc type of the adaptor is convertible to the \c Arc type |
| 2230 | 2233 |
/// of the adapted digraph.) |
| 2231 | 2234 |
template<typename DGR> |
| 2232 | 2235 |
#ifdef DOXYGEN |
| 2233 | 2236 |
class Undirector {
|
| 2234 | 2237 |
#else |
| 2235 | 2238 |
class Undirector : |
| 2236 | 2239 |
public GraphAdaptorExtender<UndirectorBase<DGR> > {
|
| 2237 | 2240 |
#endif |
| 2238 | 2241 |
public: |
| 2239 | 2242 |
/// The type of the adapted digraph. |
| 2240 | 2243 |
typedef DGR Digraph; |
| 2241 | 2244 |
typedef GraphAdaptorExtender<UndirectorBase<DGR> > Parent; |
| 2242 | 2245 |
protected: |
| ... | ... |
@@ -28,99 +28,99 @@ |
| 28 | 28 |
#include <functional> |
| 29 | 29 |
|
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
|
| 32 | 32 |
///\ingroup auxdat |
| 33 | 33 |
/// |
| 34 | 34 |
///\brief A Binary Heap implementation. |
| 35 | 35 |
/// |
| 36 | 36 |
///This class implements the \e binary \e heap data structure. |
| 37 | 37 |
/// |
| 38 | 38 |
///A \e heap is a data structure for storing items with specified values |
| 39 | 39 |
///called \e priorities in such a way that finding the item with minimum |
| 40 | 40 |
///priority is efficient. \c Comp specifies the ordering of the priorities. |
| 41 | 41 |
///In a heap one can change the priority of an item, add or erase an |
| 42 | 42 |
///item, etc. |
| 43 | 43 |
/// |
| 44 | 44 |
///\tparam PR Type of the priority of the items. |
| 45 | 45 |
///\tparam IM A read and writable item map with int values, used internally |
| 46 | 46 |
///to handle the cross references. |
| 47 | 47 |
///\tparam Comp A functor class for the ordering of the priorities. |
| 48 | 48 |
///The default is \c std::less<PR>. |
| 49 | 49 |
/// |
| 50 | 50 |
///\sa FibHeap |
| 51 | 51 |
///\sa Dijkstra |
| 52 | 52 |
template <typename PR, typename IM, typename Comp = std::less<PR> > |
| 53 | 53 |
class BinHeap {
|
| 54 | 54 |
|
| 55 | 55 |
public: |
| 56 | 56 |
///\e |
| 57 | 57 |
typedef IM ItemIntMap; |
| 58 | 58 |
///\e |
| 59 | 59 |
typedef PR Prio; |
| 60 | 60 |
///\e |
| 61 | 61 |
typedef typename ItemIntMap::Key Item; |
| 62 | 62 |
///\e |
| 63 | 63 |
typedef std::pair<Item,Prio> Pair; |
| 64 | 64 |
///\e |
| 65 | 65 |
typedef Comp Compare; |
| 66 | 66 |
|
| 67 | 67 |
/// \brief Type to represent the items states. |
| 68 | 68 |
/// |
| 69 | 69 |
/// Each Item element have a state associated to it. It may be "in heap", |
| 70 | 70 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
| 71 | 71 |
/// heap's point of view, but may be useful to the user. |
| 72 | 72 |
/// |
| 73 | 73 |
/// The item-int map must be initialized in such way that it assigns |
| 74 | 74 |
/// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap. |
| 75 | 75 |
enum State {
|
| 76 |
IN_HEAP = 0, ///< \e |
|
| 77 |
PRE_HEAP = -1, ///< \e |
|
| 78 |
|
|
| 76 |
IN_HEAP = 0, ///< = 0. |
|
| 77 |
PRE_HEAP = -1, ///< = -1. |
|
| 78 |
POST_HEAP = -2 ///< = -2. |
|
| 79 | 79 |
}; |
| 80 | 80 |
|
| 81 | 81 |
private: |
| 82 | 82 |
std::vector<Pair> _data; |
| 83 | 83 |
Compare _comp; |
| 84 | 84 |
ItemIntMap &_iim; |
| 85 | 85 |
|
| 86 | 86 |
public: |
| 87 | 87 |
/// \brief The constructor. |
| 88 | 88 |
/// |
| 89 | 89 |
/// The constructor. |
| 90 | 90 |
/// \param map should be given to the constructor, since it is used |
| 91 | 91 |
/// internally to handle the cross references. The value of the map |
| 92 | 92 |
/// must be \c PRE_HEAP (<tt>-1</tt>) for every item. |
| 93 | 93 |
explicit BinHeap(ItemIntMap &map) : _iim(map) {}
|
| 94 | 94 |
|
| 95 | 95 |
/// \brief The constructor. |
| 96 | 96 |
/// |
| 97 | 97 |
/// The constructor. |
| 98 | 98 |
/// \param map should be given to the constructor, since it is used |
| 99 | 99 |
/// internally to handle the cross references. The value of the map |
| 100 | 100 |
/// should be PRE_HEAP (-1) for each element. |
| 101 | 101 |
/// |
| 102 | 102 |
/// \param comp The comparator function object. |
| 103 | 103 |
BinHeap(ItemIntMap &map, const Compare &comp) |
| 104 | 104 |
: _iim(map), _comp(comp) {}
|
| 105 | 105 |
|
| 106 | 106 |
|
| 107 | 107 |
/// The number of items stored in the heap. |
| 108 | 108 |
/// |
| 109 | 109 |
/// \brief Returns the number of items stored in the heap. |
| 110 | 110 |
int size() const { return _data.size(); }
|
| 111 | 111 |
|
| 112 | 112 |
/// \brief Checks if the heap stores no items. |
| 113 | 113 |
/// |
| 114 | 114 |
/// Returns \c true if and only if the heap stores no items. |
| 115 | 115 |
bool empty() const { return _data.empty(); }
|
| 116 | 116 |
|
| 117 | 117 |
/// \brief Make empty this heap. |
| 118 | 118 |
/// |
| 119 | 119 |
/// Make empty this heap. It does not change the cross reference map. |
| 120 | 120 |
/// If you want to reuse what is not surely empty you should first clear |
| 121 | 121 |
/// the heap and after that you should set the cross reference map for |
| 122 | 122 |
/// each item to \c PRE_HEAP. |
| 123 | 123 |
void clear() {
|
| 124 | 124 |
_data.clear(); |
| 125 | 125 |
} |
| 126 | 126 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/core.h> |
| 23 | 23 |
#include <lemon/error.h> |
| 24 | 24 |
|
| 25 |
#include <lemon/bits/default_map.h> |
|
| 26 |
|
|
| 27 | 25 |
namespace lemon {
|
| 28 | 26 |
|
| 29 | 27 |
template <typename _Digraph> |
| 30 | 28 |
class DigraphAdaptorExtender : public _Digraph {
|
| 31 | 29 |
public: |
| 32 | 30 |
|
| 33 | 31 |
typedef _Digraph Parent; |
| 34 | 32 |
typedef _Digraph Digraph; |
| 35 | 33 |
typedef DigraphAdaptorExtender Adaptor; |
| 36 | 34 |
|
| 37 | 35 |
// Base extensions |
| 38 | 36 |
|
| 39 | 37 |
typedef typename Parent::Node Node; |
| 40 | 38 |
typedef typename Parent::Arc Arc; |
| 41 | 39 |
|
| 42 | 40 |
int maxId(Node) const {
|
| 43 | 41 |
return Parent::maxNodeId(); |
| 44 | 42 |
} |
| 45 | 43 |
|
| 46 | 44 |
int maxId(Arc) const {
|
| 47 | 45 |
return Parent::maxArcId(); |
| 48 | 46 |
} |
| 49 | 47 |
|
| 50 | 48 |
Node fromId(int id, Node) const {
|
| 51 | 49 |
return Parent::nodeFromId(id); |
| 52 | 50 |
} |
| 53 | 51 |
|
| 54 | 52 |
Arc fromId(int id, Arc) const {
|
| 55 | 53 |
return Parent::arcFromId(id); |
| 56 | 54 |
} |
| 57 | 55 |
|
| 58 | 56 |
Node oppositeNode(const Node &n, const Arc &e) const {
|
| 59 | 57 |
if (n == Parent::source(e)) |
| 60 | 58 |
return Parent::target(e); |
| 61 | 59 |
else if(n==Parent::target(e)) |
| 62 | 60 |
return Parent::source(e); |
| 63 | 61 |
else |
| 64 | 62 |
return INVALID; |
| 65 | 63 |
} |
| 66 | 64 |
|
| 67 | 65 |
class NodeIt : public Node {
|
| 68 | 66 |
const Adaptor* _adaptor; |
| 69 | 67 |
public: |
| 70 | 68 |
|
| 71 | 69 |
NodeIt() {}
|
| 72 | 70 |
|
| 73 | 71 |
NodeIt(Invalid i) : Node(i) { }
|
| 74 | 72 |
| ... | ... |
@@ -2,96 +2,98 @@ |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_MAP_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_MAP_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iterator> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/bits/traits.h> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/concept_check.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
//\file |
| 30 | 30 |
//\brief Extenders for iterable maps. |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
// \ingroup graphbits |
| 35 | 35 |
// |
| 36 | 36 |
// \brief Extender for maps |
| 37 | 37 |
template <typename _Map> |
| 38 | 38 |
class MapExtender : public _Map {
|
| 39 | 39 |
public: |
| 40 | 40 |
|
| 41 | 41 |
typedef _Map Parent; |
| 42 | 42 |
typedef MapExtender Map; |
| 43 | 43 |
|
| 44 | 44 |
|
| 45 | 45 |
typedef typename Parent::Graph Graph; |
| 46 | 46 |
typedef typename Parent::Key Item; |
| 47 | 47 |
|
| 48 | 48 |
typedef typename Parent::Key Key; |
| 49 | 49 |
typedef typename Parent::Value Value; |
| 50 |
typedef typename Parent::Reference Reference; |
|
| 51 |
typedef typename Parent::ConstReference ConstReference; |
|
| 50 | 52 |
|
| 51 | 53 |
class MapIt; |
| 52 | 54 |
class ConstMapIt; |
| 53 | 55 |
|
| 54 | 56 |
friend class MapIt; |
| 55 | 57 |
friend class ConstMapIt; |
| 56 | 58 |
|
| 57 | 59 |
public: |
| 58 | 60 |
|
| 59 | 61 |
MapExtender(const Graph& graph) |
| 60 | 62 |
: Parent(graph) {}
|
| 61 | 63 |
|
| 62 | 64 |
MapExtender(const Graph& graph, const Value& value) |
| 63 | 65 |
: Parent(graph, value) {}
|
| 64 | 66 |
|
| 65 | 67 |
private: |
| 66 | 68 |
MapExtender& operator=(const MapExtender& cmap) {
|
| 67 | 69 |
return operator=<MapExtender>(cmap); |
| 68 | 70 |
} |
| 69 | 71 |
|
| 70 | 72 |
template <typename CMap> |
| 71 | 73 |
MapExtender& operator=(const CMap& cmap) {
|
| 72 | 74 |
Parent::operator=(cmap); |
| 73 | 75 |
return *this; |
| 74 | 76 |
} |
| 75 | 77 |
|
| 76 | 78 |
public: |
| 77 | 79 |
class MapIt : public Item {
|
| 78 | 80 |
public: |
| 79 | 81 |
|
| 80 | 82 |
typedef Item Parent; |
| 81 | 83 |
typedef typename Map::Value Value; |
| 82 | 84 |
|
| 83 | 85 |
MapIt() {}
|
| 84 | 86 |
|
| 85 | 87 |
MapIt(Invalid i) : Parent(i) { }
|
| 86 | 88 |
|
| 87 | 89 |
explicit MapIt(Map& _map) : map(_map) {
|
| 88 | 90 |
map.notifier()->first(*this); |
| 89 | 91 |
} |
| 90 | 92 |
|
| 91 | 93 |
MapIt(const Map& _map, const Item& item) |
| 92 | 94 |
: Parent(item), map(_map) {}
|
| 93 | 95 |
|
| 94 | 96 |
MapIt& operator++() {
|
| 95 | 97 |
map.notifier()->next(*this); |
| 96 | 98 |
return *this; |
| 97 | 99 |
} |
| ... | ... |
@@ -142,96 +144,98 @@ |
| 142 | 144 |
|
| 143 | 145 |
protected: |
| 144 | 146 |
const Map& map; |
| 145 | 147 |
}; |
| 146 | 148 |
|
| 147 | 149 |
class ItemIt : public Item {
|
| 148 | 150 |
public: |
| 149 | 151 |
|
| 150 | 152 |
typedef Item Parent; |
| 151 | 153 |
|
| 152 | 154 |
ItemIt() {}
|
| 153 | 155 |
|
| 154 | 156 |
ItemIt(Invalid i) : Parent(i) { }
|
| 155 | 157 |
|
| 156 | 158 |
explicit ItemIt(Map& _map) : map(_map) {
|
| 157 | 159 |
map.notifier()->first(*this); |
| 158 | 160 |
} |
| 159 | 161 |
|
| 160 | 162 |
ItemIt(const Map& _map, const Item& item) |
| 161 | 163 |
: Parent(item), map(_map) {}
|
| 162 | 164 |
|
| 163 | 165 |
ItemIt& operator++() {
|
| 164 | 166 |
map.notifier()->next(*this); |
| 165 | 167 |
return *this; |
| 166 | 168 |
} |
| 167 | 169 |
|
| 168 | 170 |
protected: |
| 169 | 171 |
const Map& map; |
| 170 | 172 |
|
| 171 | 173 |
}; |
| 172 | 174 |
}; |
| 173 | 175 |
|
| 174 | 176 |
// \ingroup graphbits |
| 175 | 177 |
// |
| 176 | 178 |
// \brief Extender for maps which use a subset of the items. |
| 177 | 179 |
template <typename _Graph, typename _Map> |
| 178 | 180 |
class SubMapExtender : public _Map {
|
| 179 | 181 |
public: |
| 180 | 182 |
|
| 181 | 183 |
typedef _Map Parent; |
| 182 | 184 |
typedef SubMapExtender Map; |
| 183 | 185 |
|
| 184 | 186 |
typedef _Graph Graph; |
| 185 | 187 |
|
| 186 | 188 |
typedef typename Parent::Key Item; |
| 187 | 189 |
|
| 188 | 190 |
typedef typename Parent::Key Key; |
| 189 | 191 |
typedef typename Parent::Value Value; |
| 192 |
typedef typename Parent::Reference Reference; |
|
| 193 |
typedef typename Parent::ConstReference ConstReference; |
|
| 190 | 194 |
|
| 191 | 195 |
class MapIt; |
| 192 | 196 |
class ConstMapIt; |
| 193 | 197 |
|
| 194 | 198 |
friend class MapIt; |
| 195 | 199 |
friend class ConstMapIt; |
| 196 | 200 |
|
| 197 | 201 |
public: |
| 198 | 202 |
|
| 199 | 203 |
SubMapExtender(const Graph& _graph) |
| 200 | 204 |
: Parent(_graph), graph(_graph) {}
|
| 201 | 205 |
|
| 202 | 206 |
SubMapExtender(const Graph& _graph, const Value& _value) |
| 203 | 207 |
: Parent(_graph, _value), graph(_graph) {}
|
| 204 | 208 |
|
| 205 | 209 |
private: |
| 206 | 210 |
SubMapExtender& operator=(const SubMapExtender& cmap) {
|
| 207 | 211 |
return operator=<MapExtender>(cmap); |
| 208 | 212 |
} |
| 209 | 213 |
|
| 210 | 214 |
template <typename CMap> |
| 211 | 215 |
SubMapExtender& operator=(const CMap& cmap) {
|
| 212 | 216 |
checkConcept<concepts::ReadMap<Key, Value>, CMap>(); |
| 213 | 217 |
Item it; |
| 214 | 218 |
for (graph.first(it); it != INVALID; graph.next(it)) {
|
| 215 | 219 |
Parent::set(it, cmap[it]); |
| 216 | 220 |
} |
| 217 | 221 |
return *this; |
| 218 | 222 |
} |
| 219 | 223 |
|
| 220 | 224 |
public: |
| 221 | 225 |
class MapIt : public Item {
|
| 222 | 226 |
public: |
| 223 | 227 |
|
| 224 | 228 |
typedef Item Parent; |
| 225 | 229 |
typedef typename Map::Value Value; |
| 226 | 230 |
|
| 227 | 231 |
MapIt() {}
|
| 228 | 232 |
|
| 229 | 233 |
MapIt(Invalid i) : Parent(i) { }
|
| 230 | 234 |
|
| 231 | 235 |
explicit MapIt(Map& _map) : map(_map) {
|
| 232 | 236 |
map.graph.first(*this); |
| 233 | 237 |
} |
| 234 | 238 |
|
| 235 | 239 |
MapIt(const Map& _map, const Item& item) |
| 236 | 240 |
: Parent(item), map(_map) {}
|
| 237 | 241 |
| ... | ... |
@@ -10,102 +10,105 @@ |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\file |
| 20 | 20 |
///\brief Implementation of the CBC MIP solver interface. |
| 21 | 21 |
|
| 22 | 22 |
#include "cbc.h" |
| 23 | 23 |
|
| 24 | 24 |
#include <coin/CoinModel.hpp> |
| 25 | 25 |
#include <coin/CbcModel.hpp> |
| 26 | 26 |
#include <coin/OsiSolverInterface.hpp> |
| 27 | 27 |
|
| 28 | 28 |
#ifdef COIN_HAS_CLP |
| 29 | 29 |
#include "coin/OsiClpSolverInterface.hpp" |
| 30 | 30 |
#endif |
| 31 | 31 |
#ifdef COIN_HAS_OSL |
| 32 | 32 |
#include "coin/OsiOslSolverInterface.hpp" |
| 33 | 33 |
#endif |
| 34 | 34 |
|
| 35 | 35 |
#include "coin/CbcCutGenerator.hpp" |
| 36 | 36 |
#include "coin/CbcHeuristicLocal.hpp" |
| 37 | 37 |
#include "coin/CbcHeuristicGreedy.hpp" |
| 38 | 38 |
#include "coin/CbcHeuristicFPump.hpp" |
| 39 | 39 |
#include "coin/CbcHeuristicRINS.hpp" |
| 40 | 40 |
|
| 41 | 41 |
#include "coin/CglGomory.hpp" |
| 42 | 42 |
#include "coin/CglProbing.hpp" |
| 43 | 43 |
#include "coin/CglKnapsackCover.hpp" |
| 44 | 44 |
#include "coin/CglOddHole.hpp" |
| 45 | 45 |
#include "coin/CglClique.hpp" |
| 46 | 46 |
#include "coin/CglFlowCover.hpp" |
| 47 | 47 |
#include "coin/CglMixedIntegerRounding.hpp" |
| 48 | 48 |
|
| 49 | 49 |
#include "coin/CbcHeuristic.hpp" |
| 50 | 50 |
|
| 51 | 51 |
namespace lemon {
|
| 52 | 52 |
|
| 53 | 53 |
CbcMip::CbcMip() {
|
| 54 | 54 |
_prob = new CoinModel(); |
| 55 | 55 |
_prob->setProblemName("LEMON");
|
| 56 | 56 |
_osi_solver = 0; |
| 57 | 57 |
_cbc_model = 0; |
| 58 |
messageLevel(MESSAGE_NOTHING); |
|
| 58 | 59 |
} |
| 59 | 60 |
|
| 60 | 61 |
CbcMip::CbcMip(const CbcMip& other) {
|
| 61 | 62 |
_prob = new CoinModel(*other._prob); |
| 63 |
_prob->setProblemName("LEMON");
|
|
| 62 | 64 |
_osi_solver = 0; |
| 63 | 65 |
_cbc_model = 0; |
| 66 |
messageLevel(MESSAGE_NOTHING); |
|
| 64 | 67 |
} |
| 65 | 68 |
|
| 66 | 69 |
CbcMip::~CbcMip() {
|
| 67 | 70 |
delete _prob; |
| 68 | 71 |
if (_osi_solver) delete _osi_solver; |
| 69 | 72 |
if (_cbc_model) delete _cbc_model; |
| 70 | 73 |
} |
| 71 | 74 |
|
| 72 | 75 |
const char* CbcMip::_solverName() const { return "CbcMip"; }
|
| 73 | 76 |
|
| 74 | 77 |
int CbcMip::_addCol() {
|
| 75 | 78 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false); |
| 76 | 79 |
return _prob->numberColumns() - 1; |
| 77 | 80 |
} |
| 78 | 81 |
|
| 79 | 82 |
CbcMip* CbcMip::newSolver() const {
|
| 80 | 83 |
CbcMip* newlp = new CbcMip; |
| 81 | 84 |
return newlp; |
| 82 | 85 |
} |
| 83 | 86 |
|
| 84 | 87 |
CbcMip* CbcMip::cloneSolver() const {
|
| 85 | 88 |
CbcMip* copylp = new CbcMip(*this); |
| 86 | 89 |
return copylp; |
| 87 | 90 |
} |
| 88 | 91 |
|
| 89 | 92 |
int CbcMip::_addRow() {
|
| 90 | 93 |
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); |
| 91 | 94 |
return _prob->numberRows() - 1; |
| 92 | 95 |
} |
| 93 | 96 |
|
| 94 | 97 |
|
| 95 | 98 |
void CbcMip::_eraseCol(int i) {
|
| 96 | 99 |
_prob->deleteColumn(i); |
| 97 | 100 |
} |
| 98 | 101 |
|
| 99 | 102 |
void CbcMip::_eraseRow(int i) {
|
| 100 | 103 |
_prob->deleteRow(i); |
| 101 | 104 |
} |
| 102 | 105 |
|
| 103 | 106 |
void CbcMip::_eraseColId(int i) {
|
| 104 | 107 |
cols.eraseIndex(i); |
| 105 | 108 |
} |
| 106 | 109 |
|
| 107 | 110 |
void CbcMip::_eraseRowId(int i) {
|
| 108 | 111 |
rows.eraseIndex(i); |
| 109 | 112 |
} |
| 110 | 113 |
|
| 111 | 114 |
void CbcMip::_getColName(int c, std::string& name) const {
|
| ... | ... |
@@ -225,114 +228,98 @@ |
| 225 | 228 |
int num = _prob->numberColumns(); |
| 226 | 229 |
for (int i = 0; i < num; ++i) {
|
| 227 | 230 |
_prob->setColumnObjective(i, 0.0); |
| 228 | 231 |
} |
| 229 | 232 |
for (ExprIterator it = b; it != e; ++it) {
|
| 230 | 233 |
_prob->setColumnObjective(it->first, it->second); |
| 231 | 234 |
} |
| 232 | 235 |
} |
| 233 | 236 |
|
| 234 | 237 |
void CbcMip::_getObjCoeffs(InsertIterator b) const {
|
| 235 | 238 |
int num = _prob->numberColumns(); |
| 236 | 239 |
for (int i = 0; i < num; ++i) {
|
| 237 | 240 |
Value coef = _prob->getColumnObjective(i); |
| 238 | 241 |
if (coef != 0.0) {
|
| 239 | 242 |
*b = std::make_pair(i, coef); |
| 240 | 243 |
++b; |
| 241 | 244 |
} |
| 242 | 245 |
} |
| 243 | 246 |
} |
| 244 | 247 |
|
| 245 | 248 |
void CbcMip::_setObjCoeff(int i, Value obj_coef) {
|
| 246 | 249 |
_prob->setColumnObjective(i, obj_coef); |
| 247 | 250 |
} |
| 248 | 251 |
|
| 249 | 252 |
CbcMip::Value CbcMip::_getObjCoeff(int i) const {
|
| 250 | 253 |
return _prob->getColumnObjective(i); |
| 251 | 254 |
} |
| 252 | 255 |
|
| 253 | 256 |
CbcMip::SolveExitStatus CbcMip::_solve() {
|
| 254 | 257 |
|
| 255 | 258 |
if (_osi_solver) {
|
| 256 | 259 |
delete _osi_solver; |
| 257 | 260 |
} |
| 258 | 261 |
#ifdef COIN_HAS_CLP |
| 259 | 262 |
_osi_solver = new OsiClpSolverInterface(); |
| 260 | 263 |
#elif COIN_HAS_OSL |
| 261 | 264 |
_osi_solver = new OsiOslSolverInterface(); |
| 262 | 265 |
#else |
| 263 | 266 |
#error Cannot instantiate Osi solver |
| 264 | 267 |
#endif |
| 265 | 268 |
|
| 266 | 269 |
_osi_solver->loadFromCoinModel(*_prob); |
| 267 | 270 |
|
| 268 | 271 |
if (_cbc_model) {
|
| 269 | 272 |
delete _cbc_model; |
| 270 | 273 |
} |
| 271 | 274 |
_cbc_model= new CbcModel(*_osi_solver); |
| 272 | 275 |
|
| 273 |
switch (_message_level) {
|
|
| 274 |
case MESSAGE_NO_OUTPUT: |
|
| 275 |
_osi_solver->messageHandler()->setLogLevel(0); |
|
| 276 |
_cbc_model->setLogLevel(0); |
|
| 277 |
break; |
|
| 278 |
case MESSAGE_ERROR_MESSAGE: |
|
| 279 |
_osi_solver->messageHandler()->setLogLevel(1); |
|
| 280 |
_cbc_model->setLogLevel(1); |
|
| 281 |
break; |
|
| 282 |
case MESSAGE_NORMAL_OUTPUT: |
|
| 283 |
_osi_solver->messageHandler()->setLogLevel(2); |
|
| 284 |
_cbc_model->setLogLevel(2); |
|
| 285 |
break; |
|
| 286 |
case MESSAGE_FULL_OUTPUT: |
|
| 287 |
_osi_solver->messageHandler()->setLogLevel(3); |
|
| 288 |
_cbc_model->setLogLevel(3); |
|
| 289 |
break; |
|
| 290 |
} |
|
| 276 |
_osi_solver->messageHandler()->setLogLevel(_message_level); |
|
| 277 |
_cbc_model->setLogLevel(_message_level); |
|
| 291 | 278 |
|
| 292 | 279 |
_cbc_model->initialSolve(); |
| 293 | 280 |
_cbc_model->solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry); |
| 294 | 281 |
|
| 295 | 282 |
if (!_cbc_model->isInitialSolveAbandoned() && |
| 296 | 283 |
_cbc_model->isInitialSolveProvenOptimal() && |
| 297 | 284 |
!_cbc_model->isInitialSolveProvenPrimalInfeasible() && |
| 298 | 285 |
!_cbc_model->isInitialSolveProvenDualInfeasible()) {
|
| 299 | 286 |
|
| 300 | 287 |
CglProbing generator1; |
| 301 | 288 |
generator1.setUsingObjective(true); |
| 302 | 289 |
generator1.setMaxPass(3); |
| 303 | 290 |
generator1.setMaxProbe(100); |
| 304 | 291 |
generator1.setMaxLook(50); |
| 305 | 292 |
generator1.setRowCuts(3); |
| 306 | 293 |
_cbc_model->addCutGenerator(&generator1, -1, "Probing"); |
| 307 | 294 |
|
| 308 | 295 |
CglGomory generator2; |
| 309 | 296 |
generator2.setLimit(300); |
| 310 | 297 |
_cbc_model->addCutGenerator(&generator2, -1, "Gomory"); |
| 311 | 298 |
|
| 312 | 299 |
CglKnapsackCover generator3; |
| 313 | 300 |
_cbc_model->addCutGenerator(&generator3, -1, "Knapsack"); |
| 314 | 301 |
|
| 315 | 302 |
CglOddHole generator4; |
| 316 | 303 |
generator4.setMinimumViolation(0.005); |
| 317 | 304 |
generator4.setMinimumViolationPer(0.00002); |
| 318 | 305 |
generator4.setMaximumEntries(200); |
| 319 | 306 |
_cbc_model->addCutGenerator(&generator4, -1, "OddHole"); |
| 320 | 307 |
|
| 321 | 308 |
CglClique generator5; |
| 322 | 309 |
generator5.setStarCliqueReport(false); |
| 323 | 310 |
generator5.setRowCliqueReport(false); |
| 324 | 311 |
_cbc_model->addCutGenerator(&generator5, -1, "Clique"); |
| 325 | 312 |
|
| 326 | 313 |
CglMixedIntegerRounding mixedGen; |
| 327 | 314 |
_cbc_model->addCutGenerator(&mixedGen, -1, "MixedIntegerRounding"); |
| 328 | 315 |
|
| 329 | 316 |
CglFlowCover flowGen; |
| 330 | 317 |
_cbc_model->addCutGenerator(&flowGen, -1, "FlowCover"); |
| 331 | 318 |
|
| 332 | 319 |
#ifdef COIN_HAS_CLP |
| 333 | 320 |
OsiClpSolverInterface* osiclp = |
| 334 | 321 |
dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver()); |
| 335 | 322 |
if (osiclp->getNumRows() < 300 && osiclp->getNumCols() < 500) {
|
| 336 | 323 |
osiclp->setupForRepeatedUse(2, 0); |
| 337 | 324 |
} |
| 338 | 325 |
#endif |
| ... | ... |
@@ -408,53 +395,69 @@ |
| 408 | 395 |
break; |
| 409 | 396 |
} |
| 410 | 397 |
} |
| 411 | 398 |
|
| 412 | 399 |
CbcMip::Sense CbcMip::_getSense() const {
|
| 413 | 400 |
if (_prob->optimizationDirection() > 0.0) {
|
| 414 | 401 |
return MIN; |
| 415 | 402 |
} else if (_prob->optimizationDirection() < 0.0) {
|
| 416 | 403 |
return MAX; |
| 417 | 404 |
} else {
|
| 418 | 405 |
LEMON_ASSERT(false, "Wrong sense"); |
| 419 | 406 |
return CbcMip::Sense(); |
| 420 | 407 |
} |
| 421 | 408 |
} |
| 422 | 409 |
|
| 423 | 410 |
void CbcMip::_setColType(int i, CbcMip::ColTypes col_type) {
|
| 424 | 411 |
switch (col_type){
|
| 425 | 412 |
case INTEGER: |
| 426 | 413 |
_prob->setInteger(i); |
| 427 | 414 |
break; |
| 428 | 415 |
case REAL: |
| 429 | 416 |
_prob->setContinuous(i); |
| 430 | 417 |
break; |
| 431 | 418 |
default:; |
| 432 | 419 |
LEMON_ASSERT(false, "Wrong sense"); |
| 433 | 420 |
} |
| 434 | 421 |
} |
| 435 | 422 |
|
| 436 | 423 |
CbcMip::ColTypes CbcMip::_getColType(int i) const {
|
| 437 | 424 |
return _prob->getColumnIsInteger(i) ? INTEGER : REAL; |
| 438 | 425 |
} |
| 439 | 426 |
|
| 440 | 427 |
void CbcMip::_clear() {
|
| 441 | 428 |
delete _prob; |
| 442 | 429 |
if (_osi_solver) {
|
| 443 | 430 |
delete _osi_solver; |
| 444 | 431 |
_osi_solver = 0; |
| 445 | 432 |
} |
| 446 | 433 |
if (_cbc_model) {
|
| 447 | 434 |
delete _cbc_model; |
| 448 | 435 |
_cbc_model = 0; |
| 449 | 436 |
} |
| 450 | 437 |
|
| 451 | 438 |
_prob = new CoinModel(); |
| 452 | 439 |
rows.clear(); |
| 453 | 440 |
cols.clear(); |
| 454 | 441 |
} |
| 455 | 442 |
|
| 456 |
void CbcMip::messageLevel(MessageLevel m) {
|
|
| 457 |
_message_level = m; |
|
| 443 |
void CbcMip::_messageLevel(MessageLevel level) {
|
|
| 444 |
switch (level) {
|
|
| 445 |
case MESSAGE_NOTHING: |
|
| 446 |
_message_level = 0; |
|
| 447 |
break; |
|
| 448 |
case MESSAGE_ERROR: |
|
| 449 |
_message_level = 1; |
|
| 450 |
break; |
|
| 451 |
case MESSAGE_WARNING: |
|
| 452 |
_message_level = 1; |
|
| 453 |
break; |
|
| 454 |
case MESSAGE_NORMAL: |
|
| 455 |
_message_level = 2; |
|
| 456 |
break; |
|
| 457 |
case MESSAGE_VERBOSE: |
|
| 458 |
_message_level = 3; |
|
| 459 |
break; |
|
| 460 |
} |
|
| 458 | 461 |
} |
| 459 | 462 |
|
| 460 | 463 |
} //END OF NAMESPACE LEMON |
| ... | ... |
@@ -70,81 +70,60 @@ |
| 70 | 70 |
virtual void _eraseRowId(int i); |
| 71 | 71 |
|
| 72 | 72 |
virtual void _getColName(int col, std::string& name) const; |
| 73 | 73 |
virtual void _setColName(int col, const std::string& name); |
| 74 | 74 |
virtual int _colByName(const std::string& name) const; |
| 75 | 75 |
|
| 76 | 76 |
virtual void _getRowName(int row, std::string& name) const; |
| 77 | 77 |
virtual void _setRowName(int row, const std::string& name); |
| 78 | 78 |
virtual int _rowByName(const std::string& name) const; |
| 79 | 79 |
|
| 80 | 80 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 81 | 81 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 82 | 82 |
|
| 83 | 83 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 84 | 84 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 85 | 85 |
|
| 86 | 86 |
virtual void _setCoeff(int row, int col, Value value); |
| 87 | 87 |
virtual Value _getCoeff(int row, int col) const; |
| 88 | 88 |
|
| 89 | 89 |
virtual void _setColLowerBound(int i, Value value); |
| 90 | 90 |
virtual Value _getColLowerBound(int i) const; |
| 91 | 91 |
virtual void _setColUpperBound(int i, Value value); |
| 92 | 92 |
virtual Value _getColUpperBound(int i) const; |
| 93 | 93 |
|
| 94 | 94 |
virtual void _setRowLowerBound(int i, Value value); |
| 95 | 95 |
virtual Value _getRowLowerBound(int i) const; |
| 96 | 96 |
virtual void _setRowUpperBound(int i, Value value); |
| 97 | 97 |
virtual Value _getRowUpperBound(int i) const; |
| 98 | 98 |
|
| 99 | 99 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 100 | 100 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 101 | 101 |
|
| 102 | 102 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 103 | 103 |
virtual Value _getObjCoeff(int i) const; |
| 104 | 104 |
|
| 105 | 105 |
virtual void _setSense(Sense sense); |
| 106 | 106 |
virtual Sense _getSense() const; |
| 107 | 107 |
|
| 108 | 108 |
virtual ColTypes _getColType(int col) const; |
| 109 | 109 |
virtual void _setColType(int col, ColTypes col_type); |
| 110 | 110 |
|
| 111 | 111 |
virtual SolveExitStatus _solve(); |
| 112 | 112 |
virtual ProblemType _getType() const; |
| 113 | 113 |
virtual Value _getSol(int i) const; |
| 114 | 114 |
virtual Value _getSolValue() const; |
| 115 | 115 |
|
| 116 | 116 |
virtual void _clear(); |
| 117 | 117 |
|
| 118 |
|
|
| 118 |
virtual void _messageLevel(MessageLevel level); |
|
| 119 |
void _applyMessageLevel(); |
|
| 119 | 120 |
|
| 120 |
///Enum for \c messageLevel() parameter |
|
| 121 |
enum MessageLevel {
|
|
| 122 |
/// no output (default value) |
|
| 123 |
MESSAGE_NO_OUTPUT = 0, |
|
| 124 |
/// error messages only |
|
| 125 |
MESSAGE_ERROR_MESSAGE = 1, |
|
| 126 |
/// normal output |
|
| 127 |
MESSAGE_NORMAL_OUTPUT = 2, |
|
| 128 |
/// full output (includes informational messages) |
|
| 129 |
MESSAGE_FULL_OUTPUT = 3 |
|
| 130 |
|
|
| 121 |
int _message_level; |
|
| 131 | 122 |
|
| 132 |
private: |
|
| 133 |
|
|
| 134 |
MessageLevel _message_level; |
|
| 135 |
|
|
| 136 |
public: |
|
| 137 |
|
|
| 138 |
///Set the verbosity of the messages |
|
| 139 |
|
|
| 140 |
///Set the verbosity of the messages |
|
| 141 |
/// |
|
| 142 |
///\param m is the level of the messages output by the solver routines. |
|
| 143 |
void messageLevel(MessageLevel m); |
|
| 144 |
|
|
| 123 |
|
|
| 145 | 124 |
|
| 146 | 125 |
}; |
| 147 | 126 |
|
| 148 | 127 |
} |
| 149 | 128 |
|
| 150 | 129 |
#endif |
| ... | ... |
@@ -408,223 +408,223 @@ |
| 408 | 408 |
_local_level = false; |
| 409 | 409 |
} |
| 410 | 410 |
_level = &elevator; |
| 411 | 411 |
return *this; |
| 412 | 412 |
} |
| 413 | 413 |
|
| 414 | 414 |
/// \brief Returns a const reference to the elevator. |
| 415 | 415 |
/// |
| 416 | 416 |
/// Returns a const reference to the elevator. |
| 417 | 417 |
/// |
| 418 | 418 |
/// \pre Either \ref run() or \ref init() must be called before |
| 419 | 419 |
/// using this function. |
| 420 | 420 |
const Elevator& elevator() const {
|
| 421 | 421 |
return *_level; |
| 422 | 422 |
} |
| 423 | 423 |
|
| 424 | 424 |
/// \brief Sets the tolerance used by algorithm. |
| 425 | 425 |
/// |
| 426 | 426 |
/// Sets the tolerance used by algorithm. |
| 427 | 427 |
Circulation& tolerance(const Tolerance& tolerance) const {
|
| 428 | 428 |
_tol = tolerance; |
| 429 | 429 |
return *this; |
| 430 | 430 |
} |
| 431 | 431 |
|
| 432 | 432 |
/// \brief Returns a const reference to the tolerance. |
| 433 | 433 |
/// |
| 434 | 434 |
/// Returns a const reference to the tolerance. |
| 435 | 435 |
const Tolerance& tolerance() const {
|
| 436 | 436 |
return tolerance; |
| 437 | 437 |
} |
| 438 | 438 |
|
| 439 | 439 |
/// \name Execution Control |
| 440 | 440 |
/// The simplest way to execute the algorithm is to call \ref run().\n |
| 441 | 441 |
/// If you need more control on the initial solution or the execution, |
| 442 | 442 |
/// first you have to call one of the \ref init() functions, then |
| 443 | 443 |
/// the \ref start() function. |
| 444 | 444 |
|
| 445 | 445 |
///@{
|
| 446 | 446 |
|
| 447 | 447 |
/// Initializes the internal data structures. |
| 448 | 448 |
|
| 449 | 449 |
/// Initializes the internal data structures and sets all flow values |
| 450 | 450 |
/// to the lower bound. |
| 451 | 451 |
void init() |
| 452 | 452 |
{
|
| 453 | 453 |
createStructures(); |
| 454 | 454 |
|
| 455 | 455 |
for(NodeIt n(_g);n!=INVALID;++n) {
|
| 456 |
_excess |
|
| 456 |
(*_excess)[n] = (*_delta)[n]; |
|
| 457 | 457 |
} |
| 458 | 458 |
|
| 459 | 459 |
for (ArcIt e(_g);e!=INVALID;++e) {
|
| 460 | 460 |
_flow->set(e, (*_lo)[e]); |
| 461 |
_excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_flow)[e]); |
|
| 462 |
_excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_flow)[e]); |
|
| 461 |
(*_excess)[_g.target(e)] += (*_flow)[e]; |
|
| 462 |
(*_excess)[_g.source(e)] -= (*_flow)[e]; |
|
| 463 | 463 |
} |
| 464 | 464 |
|
| 465 | 465 |
// global relabeling tested, but in general case it provides |
| 466 | 466 |
// worse performance for random digraphs |
| 467 | 467 |
_level->initStart(); |
| 468 | 468 |
for(NodeIt n(_g);n!=INVALID;++n) |
| 469 | 469 |
_level->initAddItem(n); |
| 470 | 470 |
_level->initFinish(); |
| 471 | 471 |
for(NodeIt n(_g);n!=INVALID;++n) |
| 472 | 472 |
if(_tol.positive((*_excess)[n])) |
| 473 | 473 |
_level->activate(n); |
| 474 | 474 |
} |
| 475 | 475 |
|
| 476 | 476 |
/// Initializes the internal data structures using a greedy approach. |
| 477 | 477 |
|
| 478 | 478 |
/// Initializes the internal data structures using a greedy approach |
| 479 | 479 |
/// to construct the initial solution. |
| 480 | 480 |
void greedyInit() |
| 481 | 481 |
{
|
| 482 | 482 |
createStructures(); |
| 483 | 483 |
|
| 484 | 484 |
for(NodeIt n(_g);n!=INVALID;++n) {
|
| 485 |
_excess |
|
| 485 |
(*_excess)[n] = (*_delta)[n]; |
|
| 486 | 486 |
} |
| 487 | 487 |
|
| 488 | 488 |
for (ArcIt e(_g);e!=INVALID;++e) {
|
| 489 | 489 |
if (!_tol.positive((*_excess)[_g.target(e)] + (*_up)[e])) {
|
| 490 | 490 |
_flow->set(e, (*_up)[e]); |
| 491 |
_excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_up)[e]); |
|
| 492 |
_excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_up)[e]); |
|
| 491 |
(*_excess)[_g.target(e)] += (*_up)[e]; |
|
| 492 |
(*_excess)[_g.source(e)] -= (*_up)[e]; |
|
| 493 | 493 |
} else if (_tol.positive((*_excess)[_g.target(e)] + (*_lo)[e])) {
|
| 494 | 494 |
_flow->set(e, (*_lo)[e]); |
| 495 |
_excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_lo)[e]); |
|
| 496 |
_excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_lo)[e]); |
|
| 495 |
(*_excess)[_g.target(e)] += (*_lo)[e]; |
|
| 496 |
(*_excess)[_g.source(e)] -= (*_lo)[e]; |
|
| 497 | 497 |
} else {
|
| 498 | 498 |
Value fc = -(*_excess)[_g.target(e)]; |
| 499 | 499 |
_flow->set(e, fc); |
| 500 |
_excess->set(_g.target(e), 0); |
|
| 501 |
_excess->set(_g.source(e), (*_excess)[_g.source(e)] - fc); |
|
| 500 |
(*_excess)[_g.target(e)] = 0; |
|
| 501 |
(*_excess)[_g.source(e)] -= fc; |
|
| 502 | 502 |
} |
| 503 | 503 |
} |
| 504 | 504 |
|
| 505 | 505 |
_level->initStart(); |
| 506 | 506 |
for(NodeIt n(_g);n!=INVALID;++n) |
| 507 | 507 |
_level->initAddItem(n); |
| 508 | 508 |
_level->initFinish(); |
| 509 | 509 |
for(NodeIt n(_g);n!=INVALID;++n) |
| 510 | 510 |
if(_tol.positive((*_excess)[n])) |
| 511 | 511 |
_level->activate(n); |
| 512 | 512 |
} |
| 513 | 513 |
|
| 514 | 514 |
///Executes the algorithm |
| 515 | 515 |
|
| 516 | 516 |
///This function executes the algorithm. |
| 517 | 517 |
/// |
| 518 | 518 |
///\return \c true if a feasible circulation is found. |
| 519 | 519 |
/// |
| 520 | 520 |
///\sa barrier() |
| 521 | 521 |
///\sa barrierMap() |
| 522 | 522 |
bool start() |
| 523 | 523 |
{
|
| 524 | 524 |
|
| 525 | 525 |
Node act; |
| 526 | 526 |
Node bact=INVALID; |
| 527 | 527 |
Node last_activated=INVALID; |
| 528 | 528 |
while((act=_level->highestActive())!=INVALID) {
|
| 529 | 529 |
int actlevel=(*_level)[act]; |
| 530 | 530 |
int mlevel=_node_num; |
| 531 | 531 |
Value exc=(*_excess)[act]; |
| 532 | 532 |
|
| 533 | 533 |
for(OutArcIt e(_g,act);e!=INVALID; ++e) {
|
| 534 | 534 |
Node v = _g.target(e); |
| 535 | 535 |
Value fc=(*_up)[e]-(*_flow)[e]; |
| 536 | 536 |
if(!_tol.positive(fc)) continue; |
| 537 | 537 |
if((*_level)[v]<actlevel) {
|
| 538 | 538 |
if(!_tol.less(fc, exc)) {
|
| 539 | 539 |
_flow->set(e, (*_flow)[e] + exc); |
| 540 |
|
|
| 540 |
(*_excess)[v] += exc; |
|
| 541 | 541 |
if(!_level->active(v) && _tol.positive((*_excess)[v])) |
| 542 | 542 |
_level->activate(v); |
| 543 |
|
|
| 543 |
(*_excess)[act] = 0; |
|
| 544 | 544 |
_level->deactivate(act); |
| 545 | 545 |
goto next_l; |
| 546 | 546 |
} |
| 547 | 547 |
else {
|
| 548 | 548 |
_flow->set(e, (*_up)[e]); |
| 549 |
|
|
| 549 |
(*_excess)[v] += fc; |
|
| 550 | 550 |
if(!_level->active(v) && _tol.positive((*_excess)[v])) |
| 551 | 551 |
_level->activate(v); |
| 552 | 552 |
exc-=fc; |
| 553 | 553 |
} |
| 554 | 554 |
} |
| 555 | 555 |
else if((*_level)[v]<mlevel) mlevel=(*_level)[v]; |
| 556 | 556 |
} |
| 557 | 557 |
for(InArcIt e(_g,act);e!=INVALID; ++e) {
|
| 558 | 558 |
Node v = _g.source(e); |
| 559 | 559 |
Value fc=(*_flow)[e]-(*_lo)[e]; |
| 560 | 560 |
if(!_tol.positive(fc)) continue; |
| 561 | 561 |
if((*_level)[v]<actlevel) {
|
| 562 | 562 |
if(!_tol.less(fc, exc)) {
|
| 563 | 563 |
_flow->set(e, (*_flow)[e] - exc); |
| 564 |
|
|
| 564 |
(*_excess)[v] += exc; |
|
| 565 | 565 |
if(!_level->active(v) && _tol.positive((*_excess)[v])) |
| 566 | 566 |
_level->activate(v); |
| 567 |
|
|
| 567 |
(*_excess)[act] = 0; |
|
| 568 | 568 |
_level->deactivate(act); |
| 569 | 569 |
goto next_l; |
| 570 | 570 |
} |
| 571 | 571 |
else {
|
| 572 | 572 |
_flow->set(e, (*_lo)[e]); |
| 573 |
|
|
| 573 |
(*_excess)[v] += fc; |
|
| 574 | 574 |
if(!_level->active(v) && _tol.positive((*_excess)[v])) |
| 575 | 575 |
_level->activate(v); |
| 576 | 576 |
exc-=fc; |
| 577 | 577 |
} |
| 578 | 578 |
} |
| 579 | 579 |
else if((*_level)[v]<mlevel) mlevel=(*_level)[v]; |
| 580 | 580 |
} |
| 581 | 581 |
|
| 582 |
_excess |
|
| 582 |
(*_excess)[act] = exc; |
|
| 583 | 583 |
if(!_tol.positive(exc)) _level->deactivate(act); |
| 584 | 584 |
else if(mlevel==_node_num) {
|
| 585 | 585 |
_level->liftHighestActiveToTop(); |
| 586 | 586 |
_el = _node_num; |
| 587 | 587 |
return false; |
| 588 | 588 |
} |
| 589 | 589 |
else {
|
| 590 | 590 |
_level->liftHighestActive(mlevel+1); |
| 591 | 591 |
if(_level->onLevel(actlevel)==0) {
|
| 592 | 592 |
_el = actlevel; |
| 593 | 593 |
return false; |
| 594 | 594 |
} |
| 595 | 595 |
} |
| 596 | 596 |
next_l: |
| 597 | 597 |
; |
| 598 | 598 |
} |
| 599 | 599 |
return true; |
| 600 | 600 |
} |
| 601 | 601 |
|
| 602 | 602 |
/// Runs the algorithm. |
| 603 | 603 |
|
| 604 | 604 |
/// This function runs the algorithm. |
| 605 | 605 |
/// |
| 606 | 606 |
/// \return \c true if a feasible circulation is found. |
| 607 | 607 |
/// |
| 608 | 608 |
/// \note Apart from the return value, c.run() is just a shortcut of |
| 609 | 609 |
/// the following code. |
| 610 | 610 |
/// \code |
| 611 | 611 |
/// c.greedyInit(); |
| 612 | 612 |
/// c.start(); |
| 613 | 613 |
/// \endcode |
| 614 | 614 |
bool run() {
|
| 615 | 615 |
greedyInit(); |
| 616 | 616 |
return start(); |
| 617 | 617 |
} |
| 618 | 618 |
|
| 619 | 619 |
/// @} |
| 620 | 620 |
|
| 621 | 621 |
/// \name Query Functions |
| 622 | 622 |
/// The results of the circulation algorithm can be obtained using |
| 623 | 623 |
/// these functions.\n |
| 624 | 624 |
/// Either \ref run() or \ref start() should be called before |
| 625 | 625 |
/// using them. |
| 626 | 626 |
|
| 627 | 627 |
///@{
|
| 628 | 628 |
|
| 629 | 629 |
/// \brief Returns the flow on the given arc. |
| 630 | 630 |
/// |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <lemon/clp.h> |
| 20 | 20 |
#include <coin/ClpSimplex.hpp> |
| 21 | 21 |
|
| 22 | 22 |
namespace lemon {
|
| 23 | 23 |
|
| 24 | 24 |
ClpLp::ClpLp() {
|
| 25 | 25 |
_prob = new ClpSimplex(); |
| 26 | 26 |
_init_temporals(); |
| 27 |
messageLevel( |
|
| 27 |
messageLevel(MESSAGE_NOTHING); |
|
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
ClpLp::ClpLp(const ClpLp& other) {
|
| 31 | 31 |
_prob = new ClpSimplex(*other._prob); |
| 32 | 32 |
rows = other.rows; |
| 33 | 33 |
cols = other.cols; |
| 34 | 34 |
_init_temporals(); |
| 35 |
messageLevel( |
|
| 35 |
messageLevel(MESSAGE_NOTHING); |
|
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 | 38 |
ClpLp::~ClpLp() {
|
| 39 | 39 |
delete _prob; |
| 40 | 40 |
_clear_temporals(); |
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 | 43 |
void ClpLp::_init_temporals() {
|
| 44 | 44 |
_primal_ray = 0; |
| 45 | 45 |
_dual_ray = 0; |
| 46 | 46 |
} |
| 47 | 47 |
|
| 48 | 48 |
void ClpLp::_clear_temporals() {
|
| 49 | 49 |
if (_primal_ray) {
|
| 50 | 50 |
delete[] _primal_ray; |
| 51 | 51 |
_primal_ray = 0; |
| 52 | 52 |
} |
| 53 | 53 |
if (_dual_ray) {
|
| 54 | 54 |
delete[] _dual_ray; |
| 55 | 55 |
_dual_ray = 0; |
| 56 | 56 |
} |
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
ClpLp* ClpLp::newSolver() const {
|
| 60 | 60 |
ClpLp* newlp = new ClpLp; |
| 61 | 61 |
return newlp; |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
ClpLp* ClpLp::cloneSolver() const {
|
| 65 | 65 |
ClpLp* copylp = new ClpLp(*this); |
| 66 | 66 |
return copylp; |
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 | 69 |
const char* ClpLp::_solverName() const { return "ClpLp"; }
|
| 70 | 70 |
|
| 71 | 71 |
int ClpLp::_addCol() {
|
| 72 | 72 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0); |
| 73 | 73 |
return _prob->numberColumns() - 1; |
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 | 76 |
int ClpLp::_addRow() {
|
| 77 | 77 |
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); |
| 78 | 78 |
return _prob->numberRows() - 1; |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
|
| 82 | 82 |
void ClpLp::_eraseCol(int c) {
|
| 83 | 83 |
_col_names_ref.erase(_prob->getColumnName(c)); |
| ... | ... |
@@ -385,53 +385,69 @@ |
| 385 | 385 |
} else if (_prob->isProvenDualInfeasible()) {
|
| 386 | 386 |
return UNBOUNDED; |
| 387 | 387 |
} else {
|
| 388 | 388 |
return UNDEFINED; |
| 389 | 389 |
} |
| 390 | 390 |
} |
| 391 | 391 |
|
| 392 | 392 |
ClpLp::ProblemType ClpLp::_getDualType() const {
|
| 393 | 393 |
if (_prob->isProvenOptimal()) {
|
| 394 | 394 |
return OPTIMAL; |
| 395 | 395 |
} else if (_prob->isProvenDualInfeasible()) {
|
| 396 | 396 |
return INFEASIBLE; |
| 397 | 397 |
} else if (_prob->isProvenPrimalInfeasible()) {
|
| 398 | 398 |
return INFEASIBLE; |
| 399 | 399 |
} else {
|
| 400 | 400 |
return UNDEFINED; |
| 401 | 401 |
} |
| 402 | 402 |
} |
| 403 | 403 |
|
| 404 | 404 |
void ClpLp::_setSense(ClpLp::Sense sense) {
|
| 405 | 405 |
switch (sense) {
|
| 406 | 406 |
case MIN: |
| 407 | 407 |
_prob->setOptimizationDirection(1); |
| 408 | 408 |
break; |
| 409 | 409 |
case MAX: |
| 410 | 410 |
_prob->setOptimizationDirection(-1); |
| 411 | 411 |
break; |
| 412 | 412 |
} |
| 413 | 413 |
} |
| 414 | 414 |
|
| 415 | 415 |
ClpLp::Sense ClpLp::_getSense() const {
|
| 416 | 416 |
double dir = _prob->optimizationDirection(); |
| 417 | 417 |
if (dir > 0.0) {
|
| 418 | 418 |
return MIN; |
| 419 | 419 |
} else {
|
| 420 | 420 |
return MAX; |
| 421 | 421 |
} |
| 422 | 422 |
} |
| 423 | 423 |
|
| 424 | 424 |
void ClpLp::_clear() {
|
| 425 | 425 |
delete _prob; |
| 426 | 426 |
_prob = new ClpSimplex(); |
| 427 | 427 |
rows.clear(); |
| 428 | 428 |
cols.clear(); |
| 429 | 429 |
_col_names_ref.clear(); |
| 430 | 430 |
_clear_temporals(); |
| 431 | 431 |
} |
| 432 | 432 |
|
| 433 |
void ClpLp::messageLevel(MessageLevel m) {
|
|
| 434 |
_prob->setLogLevel(static_cast<int>(m)); |
|
| 433 |
void ClpLp::_messageLevel(MessageLevel level) {
|
|
| 434 |
switch (level) {
|
|
| 435 |
case MESSAGE_NOTHING: |
|
| 436 |
_prob->setLogLevel(0); |
|
| 437 |
break; |
|
| 438 |
case MESSAGE_ERROR: |
|
| 439 |
_prob->setLogLevel(1); |
|
| 440 |
break; |
|
| 441 |
case MESSAGE_WARNING: |
|
| 442 |
_prob->setLogLevel(2); |
|
| 443 |
break; |
|
| 444 |
case MESSAGE_NORMAL: |
|
| 445 |
_prob->setLogLevel(3); |
|
| 446 |
break; |
|
| 447 |
case MESSAGE_VERBOSE: |
|
| 448 |
_prob->setLogLevel(4); |
|
| 449 |
break; |
|
| 450 |
} |
|
| 435 | 451 |
} |
| 436 | 452 |
|
| 437 | 453 |
} //END OF NAMESPACE LEMON |
| ... | ... |
@@ -91,91 +91,73 @@ |
| 91 | 91 |
virtual int _rowByName(const std::string& name) const; |
| 92 | 92 |
|
| 93 | 93 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 94 | 94 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 95 | 95 |
|
| 96 | 96 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 97 | 97 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 98 | 98 |
|
| 99 | 99 |
virtual void _setCoeff(int row, int col, Value value); |
| 100 | 100 |
virtual Value _getCoeff(int row, int col) const; |
| 101 | 101 |
|
| 102 | 102 |
virtual void _setColLowerBound(int i, Value value); |
| 103 | 103 |
virtual Value _getColLowerBound(int i) const; |
| 104 | 104 |
virtual void _setColUpperBound(int i, Value value); |
| 105 | 105 |
virtual Value _getColUpperBound(int i) const; |
| 106 | 106 |
|
| 107 | 107 |
virtual void _setRowLowerBound(int i, Value value); |
| 108 | 108 |
virtual Value _getRowLowerBound(int i) const; |
| 109 | 109 |
virtual void _setRowUpperBound(int i, Value value); |
| 110 | 110 |
virtual Value _getRowUpperBound(int i) const; |
| 111 | 111 |
|
| 112 | 112 |
virtual void _setObjCoeffs(ExprIterator, ExprIterator); |
| 113 | 113 |
virtual void _getObjCoeffs(InsertIterator) const; |
| 114 | 114 |
|
| 115 | 115 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 116 | 116 |
virtual Value _getObjCoeff(int i) const; |
| 117 | 117 |
|
| 118 | 118 |
virtual void _setSense(Sense sense); |
| 119 | 119 |
virtual Sense _getSense() const; |
| 120 | 120 |
|
| 121 | 121 |
virtual SolveExitStatus _solve(); |
| 122 | 122 |
|
| 123 | 123 |
virtual Value _getPrimal(int i) const; |
| 124 | 124 |
virtual Value _getDual(int i) const; |
| 125 | 125 |
|
| 126 | 126 |
virtual Value _getPrimalValue() const; |
| 127 | 127 |
|
| 128 | 128 |
virtual Value _getPrimalRay(int i) const; |
| 129 | 129 |
virtual Value _getDualRay(int i) const; |
| 130 | 130 |
|
| 131 | 131 |
virtual VarStatus _getColStatus(int i) const; |
| 132 | 132 |
virtual VarStatus _getRowStatus(int i) const; |
| 133 | 133 |
|
| 134 | 134 |
virtual ProblemType _getPrimalType() const; |
| 135 | 135 |
virtual ProblemType _getDualType() const; |
| 136 | 136 |
|
| 137 | 137 |
virtual void _clear(); |
| 138 | 138 |
|
| 139 |
virtual void _messageLevel(MessageLevel); |
|
| 140 |
|
|
| 139 | 141 |
public: |
| 140 | 142 |
|
| 141 | 143 |
///Solves LP with primal simplex method. |
| 142 | 144 |
SolveExitStatus solvePrimal(); |
| 143 | 145 |
|
| 144 | 146 |
///Solves LP with dual simplex method. |
| 145 | 147 |
SolveExitStatus solveDual(); |
| 146 | 148 |
|
| 147 | 149 |
///Solves LP with barrier method. |
| 148 | 150 |
SolveExitStatus solveBarrier(); |
| 149 | 151 |
|
| 150 | 152 |
///Returns the constraint identifier understood by CLP. |
| 151 | 153 |
int clpRow(Row r) const { return rows(id(r)); }
|
| 152 | 154 |
|
| 153 | 155 |
///Returns the variable identifier understood by CLP. |
| 154 | 156 |
int clpCol(Col c) const { return cols(id(c)); }
|
| 155 | 157 |
|
| 156 |
///Enum for \c messageLevel() parameter |
|
| 157 |
enum MessageLevel {
|
|
| 158 |
/// no output (default value) |
|
| 159 |
MESSAGE_NO_OUTPUT = 0, |
|
| 160 |
/// print final solution |
|
| 161 |
MESSAGE_FINAL_SOLUTION = 1, |
|
| 162 |
/// print factorization |
|
| 163 |
MESSAGE_FACTORIZATION = 2, |
|
| 164 |
/// normal output |
|
| 165 |
MESSAGE_NORMAL_OUTPUT = 3, |
|
| 166 |
/// verbose output |
|
| 167 |
MESSAGE_VERBOSE_OUTPUT = 4 |
|
| 168 |
}; |
|
| 169 |
///Set the verbosity of the messages |
|
| 170 |
|
|
| 171 |
///Set the verbosity of the messages |
|
| 172 |
/// |
|
| 173 |
///\param m is the level of the messages output by the solver routines. |
|
| 174 |
void messageLevel(MessageLevel m); |
|
| 175 |
|
|
| 176 | 158 |
}; |
| 177 | 159 |
|
| 178 | 160 |
} //END OF NAMESPACE LEMON |
| 179 | 161 |
|
| 180 | 162 |
#endif //LEMON_CLP_H |
| 181 | 163 |
| ... | ... |
@@ -376,112 +376,113 @@ |
| 376 | 376 |
void next(Arc&) const {}
|
| 377 | 377 |
|
| 378 | 378 |
|
| 379 | 379 |
void firstIn(Arc&, const Node&) const {}
|
| 380 | 380 |
void nextIn(Arc&) const {}
|
| 381 | 381 |
|
| 382 | 382 |
void firstOut(Arc&, const Node&) const {}
|
| 383 | 383 |
void nextOut(Arc&) const {}
|
| 384 | 384 |
|
| 385 | 385 |
// The second parameter is dummy. |
| 386 | 386 |
Node fromId(int, Node) const { return INVALID; }
|
| 387 | 387 |
// The second parameter is dummy. |
| 388 | 388 |
Arc fromId(int, Arc) const { return INVALID; }
|
| 389 | 389 |
|
| 390 | 390 |
// Dummy parameter. |
| 391 | 391 |
int maxId(Node) const { return -1; }
|
| 392 | 392 |
// Dummy parameter. |
| 393 | 393 |
int maxId(Arc) const { return -1; }
|
| 394 | 394 |
|
| 395 | 395 |
/// \brief The base node of the iterator. |
| 396 | 396 |
/// |
| 397 | 397 |
/// Gives back the base node of the iterator. |
| 398 | 398 |
/// It is always the target of the pointed arc. |
| 399 | 399 |
Node baseNode(const InArcIt&) const { return INVALID; }
|
| 400 | 400 |
|
| 401 | 401 |
/// \brief The running node of the iterator. |
| 402 | 402 |
/// |
| 403 | 403 |
/// Gives back the running node of the iterator. |
| 404 | 404 |
/// It is always the source of the pointed arc. |
| 405 | 405 |
Node runningNode(const InArcIt&) const { return INVALID; }
|
| 406 | 406 |
|
| 407 | 407 |
/// \brief The base node of the iterator. |
| 408 | 408 |
/// |
| 409 | 409 |
/// Gives back the base node of the iterator. |
| 410 | 410 |
/// It is always the source of the pointed arc. |
| 411 | 411 |
Node baseNode(const OutArcIt&) const { return INVALID; }
|
| 412 | 412 |
|
| 413 | 413 |
/// \brief The running node of the iterator. |
| 414 | 414 |
/// |
| 415 | 415 |
/// Gives back the running node of the iterator. |
| 416 | 416 |
/// It is always the target of the pointed arc. |
| 417 | 417 |
Node runningNode(const OutArcIt&) const { return INVALID; }
|
| 418 | 418 |
|
| 419 | 419 |
/// \brief The opposite node on the given arc. |
| 420 | 420 |
/// |
| 421 | 421 |
/// Gives back the opposite node on the given arc. |
| 422 | 422 |
Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
|
| 423 | 423 |
|
| 424 |
/// \brief |
|
| 424 |
/// \brief Reference map of the nodes to type \c T. |
|
| 425 | 425 |
/// |
| 426 |
/// ReadWrite map of the nodes to type \c T. |
|
| 427 |
/// \sa Reference |
|
| 426 |
/// Reference map of the nodes to type \c T. |
|
| 428 | 427 |
template<class T> |
| 429 |
class NodeMap : public |
|
| 428 |
class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
|
|
| 430 | 429 |
public: |
| 431 | 430 |
|
| 432 | 431 |
///\e |
| 433 | 432 |
NodeMap(const Digraph&) { }
|
| 434 | 433 |
///\e |
| 435 | 434 |
NodeMap(const Digraph&, T) { }
|
| 436 | 435 |
|
| 437 | 436 |
private: |
| 438 | 437 |
///Copy constructor |
| 439 |
NodeMap(const NodeMap& nm) : |
|
| 438 |
NodeMap(const NodeMap& nm) : |
|
| 439 |
ReferenceMap<Node, T, T&, const T&>(nm) { }
|
|
| 440 | 440 |
///Assignment operator |
| 441 | 441 |
template <typename CMap> |
| 442 | 442 |
NodeMap& operator=(const CMap&) {
|
| 443 | 443 |
checkConcept<ReadMap<Node, T>, CMap>(); |
| 444 | 444 |
return *this; |
| 445 | 445 |
} |
| 446 | 446 |
}; |
| 447 | 447 |
|
| 448 |
/// \brief |
|
| 448 |
/// \brief Reference map of the arcs to type \c T. |
|
| 449 | 449 |
/// |
| 450 | 450 |
/// Reference map of the arcs to type \c T. |
| 451 |
/// \sa Reference |
|
| 452 | 451 |
template<class T> |
| 453 |
class ArcMap : public |
|
| 452 |
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
|
|
| 454 | 453 |
public: |
| 455 | 454 |
|
| 456 | 455 |
///\e |
| 457 | 456 |
ArcMap(const Digraph&) { }
|
| 458 | 457 |
///\e |
| 459 | 458 |
ArcMap(const Digraph&, T) { }
|
| 460 | 459 |
private: |
| 461 | 460 |
///Copy constructor |
| 462 |
ArcMap(const ArcMap& em) : |
|
| 461 |
ArcMap(const ArcMap& em) : |
|
| 462 |
ReferenceMap<Arc, T, T&, const T&>(em) { }
|
|
| 463 | 463 |
///Assignment operator |
| 464 | 464 |
template <typename CMap> |
| 465 | 465 |
ArcMap& operator=(const CMap&) {
|
| 466 | 466 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
| 467 | 467 |
return *this; |
| 468 | 468 |
} |
| 469 | 469 |
}; |
| 470 | 470 |
|
| 471 | 471 |
template <typename _Digraph> |
| 472 | 472 |
struct Constraints {
|
| 473 | 473 |
void constraints() {
|
| 474 |
checkConcept<BaseDigraphComponent, _Digraph>(); |
|
| 474 | 475 |
checkConcept<IterableDigraphComponent<>, _Digraph>(); |
| 475 | 476 |
checkConcept<IDableDigraphComponent<>, _Digraph>(); |
| 476 | 477 |
checkConcept<MappableDigraphComponent<>, _Digraph>(); |
| 477 | 478 |
} |
| 478 | 479 |
}; |
| 479 | 480 |
|
| 480 | 481 |
}; |
| 481 | 482 |
|
| 482 | 483 |
} //namespace concepts |
| 483 | 484 |
} //namespace lemon |
| 484 | 485 |
|
| 485 | 486 |
|
| 486 | 487 |
|
| 487 | 488 |
#endif |
| ... | ... |
@@ -452,161 +452,161 @@ |
| 452 | 452 |
/// Its usage is quite simple, for example you can count the number |
| 453 | 453 |
/// of outgoing arcs of a node \c n |
| 454 | 454 |
/// in graph \c g of type \c Graph as follows. |
| 455 | 455 |
///\code |
| 456 | 456 |
/// int count=0; |
| 457 | 457 |
/// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count; |
| 458 | 458 |
///\endcode |
| 459 | 459 |
|
| 460 | 460 |
class InArcIt : public Arc {
|
| 461 | 461 |
public: |
| 462 | 462 |
/// Default constructor |
| 463 | 463 |
|
| 464 | 464 |
/// @warning The default constructor sets the iterator |
| 465 | 465 |
/// to an undefined value. |
| 466 | 466 |
InArcIt() { }
|
| 467 | 467 |
/// Copy constructor. |
| 468 | 468 |
|
| 469 | 469 |
/// Copy constructor. |
| 470 | 470 |
/// |
| 471 | 471 |
InArcIt(const InArcIt& e) : Arc(e) { }
|
| 472 | 472 |
/// Initialize the iterator to be invalid. |
| 473 | 473 |
|
| 474 | 474 |
/// Initialize the iterator to be invalid. |
| 475 | 475 |
/// |
| 476 | 476 |
InArcIt(Invalid) { }
|
| 477 | 477 |
/// This constructor sets the iterator to first incoming arc. |
| 478 | 478 |
|
| 479 | 479 |
/// This constructor set the iterator to the first incoming arc of |
| 480 | 480 |
/// the node. |
| 481 | 481 |
///@param n the node |
| 482 | 482 |
///@param g the graph |
| 483 | 483 |
InArcIt(const Graph& g, const Node& n) {
|
| 484 | 484 |
ignore_unused_variable_warning(n); |
| 485 | 485 |
ignore_unused_variable_warning(g); |
| 486 | 486 |
} |
| 487 | 487 |
/// Arc -> InArcIt conversion |
| 488 | 488 |
|
| 489 | 489 |
/// Sets the iterator to the value of the trivial iterator \c e. |
| 490 | 490 |
/// This feature necessitates that each time we |
| 491 | 491 |
/// iterate the arc-set, the iteration order is the same. |
| 492 | 492 |
InArcIt(const Graph&, const Arc&) { }
|
| 493 | 493 |
/// Next incoming arc |
| 494 | 494 |
|
| 495 | 495 |
/// Assign the iterator to the next inarc of the corresponding node. |
| 496 | 496 |
/// |
| 497 | 497 |
InArcIt& operator++() { return *this; }
|
| 498 | 498 |
}; |
| 499 | 499 |
|
| 500 |
/// \brief |
|
| 500 |
/// \brief Reference map of the nodes to type \c T. |
|
| 501 | 501 |
/// |
| 502 |
/// ReadWrite map of the nodes to type \c T. |
|
| 503 |
/// \sa Reference |
|
| 502 |
/// Reference map of the nodes to type \c T. |
|
| 504 | 503 |
template<class T> |
| 505 |
class NodeMap : public |
|
| 504 |
class NodeMap : public ReferenceMap<Node, T, T&, const T&> |
|
| 506 | 505 |
{
|
| 507 | 506 |
public: |
| 508 | 507 |
|
| 509 | 508 |
///\e |
| 510 | 509 |
NodeMap(const Graph&) { }
|
| 511 | 510 |
///\e |
| 512 | 511 |
NodeMap(const Graph&, T) { }
|
| 513 | 512 |
|
| 514 | 513 |
private: |
| 515 | 514 |
///Copy constructor |
| 516 |
NodeMap(const NodeMap& nm) : |
|
| 515 |
NodeMap(const NodeMap& nm) : |
|
| 516 |
ReferenceMap<Node, T, T&, const T&>(nm) { }
|
|
| 517 | 517 |
///Assignment operator |
| 518 | 518 |
template <typename CMap> |
| 519 | 519 |
NodeMap& operator=(const CMap&) {
|
| 520 | 520 |
checkConcept<ReadMap<Node, T>, CMap>(); |
| 521 | 521 |
return *this; |
| 522 | 522 |
} |
| 523 | 523 |
}; |
| 524 | 524 |
|
| 525 |
/// \brief |
|
| 525 |
/// \brief Reference map of the arcs to type \c T. |
|
| 526 | 526 |
/// |
| 527 |
/// Reference map of the directed arcs to type \c T. |
|
| 528 |
/// \sa Reference |
|
| 527 |
/// Reference map of the arcs to type \c T. |
|
| 529 | 528 |
template<class T> |
| 530 |
class ArcMap : public |
|
| 529 |
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> |
|
| 531 | 530 |
{
|
| 532 | 531 |
public: |
| 533 | 532 |
|
| 534 | 533 |
///\e |
| 535 | 534 |
ArcMap(const Graph&) { }
|
| 536 | 535 |
///\e |
| 537 | 536 |
ArcMap(const Graph&, T) { }
|
| 538 | 537 |
private: |
| 539 | 538 |
///Copy constructor |
| 540 |
ArcMap(const ArcMap& em) : |
|
| 539 |
ArcMap(const ArcMap& em) : |
|
| 540 |
ReferenceMap<Arc, T, T&, const T&>(em) { }
|
|
| 541 | 541 |
///Assignment operator |
| 542 | 542 |
template <typename CMap> |
| 543 | 543 |
ArcMap& operator=(const CMap&) {
|
| 544 | 544 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
| 545 | 545 |
return *this; |
| 546 | 546 |
} |
| 547 | 547 |
}; |
| 548 | 548 |
|
| 549 |
/// |
|
| 549 |
/// Reference map of the edges to type \c T. |
|
| 550 | 550 |
|
| 551 |
/// Reference map of the arcs to type \c T. |
|
| 552 |
/// \sa Reference |
|
| 551 |
/// Reference map of the edges to type \c T. |
|
| 553 | 552 |
template<class T> |
| 554 |
class EdgeMap : public |
|
| 553 |
class EdgeMap : public ReferenceMap<Edge, T, T&, const T&> |
|
| 555 | 554 |
{
|
| 556 | 555 |
public: |
| 557 | 556 |
|
| 558 | 557 |
///\e |
| 559 | 558 |
EdgeMap(const Graph&) { }
|
| 560 | 559 |
///\e |
| 561 | 560 |
EdgeMap(const Graph&, T) { }
|
| 562 | 561 |
private: |
| 563 | 562 |
///Copy constructor |
| 564 |
EdgeMap(const EdgeMap& em) : |
|
| 563 |
EdgeMap(const EdgeMap& em) : |
|
| 564 |
ReferenceMap<Edge, T, T&, const T&>(em) {}
|
|
| 565 | 565 |
///Assignment operator |
| 566 | 566 |
template <typename CMap> |
| 567 | 567 |
EdgeMap& operator=(const CMap&) {
|
| 568 | 568 |
checkConcept<ReadMap<Edge, T>, CMap>(); |
| 569 | 569 |
return *this; |
| 570 | 570 |
} |
| 571 | 571 |
}; |
| 572 | 572 |
|
| 573 | 573 |
/// \brief Direct the given edge. |
| 574 | 574 |
/// |
| 575 | 575 |
/// Direct the given edge. The returned arc source |
| 576 | 576 |
/// will be the given node. |
| 577 | 577 |
Arc direct(const Edge&, const Node&) const {
|
| 578 | 578 |
return INVALID; |
| 579 | 579 |
} |
| 580 | 580 |
|
| 581 | 581 |
/// \brief Direct the given edge. |
| 582 | 582 |
/// |
| 583 | 583 |
/// Direct the given edge. The returned arc |
| 584 | 584 |
/// represents the given edge and the direction comes |
| 585 | 585 |
/// from the bool parameter. The source of the edge and |
| 586 | 586 |
/// the directed arc is the same when the given bool is true. |
| 587 | 587 |
Arc direct(const Edge&, bool) const {
|
| 588 | 588 |
return INVALID; |
| 589 | 589 |
} |
| 590 | 590 |
|
| 591 | 591 |
/// \brief Returns true if the arc has default orientation. |
| 592 | 592 |
/// |
| 593 | 593 |
/// Returns whether the given directed arc is same orientation as |
| 594 | 594 |
/// the corresponding edge's default orientation. |
| 595 | 595 |
bool direction(Arc) const { return true; }
|
| 596 | 596 |
|
| 597 | 597 |
/// \brief Returns the opposite directed arc. |
| 598 | 598 |
/// |
| 599 | 599 |
/// Returns the opposite directed arc. |
| 600 | 600 |
Arc oppositeArc(Arc) const { return INVALID; }
|
| 601 | 601 |
|
| 602 | 602 |
/// \brief Opposite node on an arc |
| 603 | 603 |
/// |
| 604 | 604 |
/// \return The opposite of the given node on the given edge. |
| 605 | 605 |
Node oppositeNode(Node, Edge) const { return INVALID; }
|
| 606 | 606 |
|
| 607 | 607 |
/// \brief First node of the edge. |
| 608 | 608 |
/// |
| 609 | 609 |
/// \return The first node of the given edge. |
| 610 | 610 |
/// |
| 611 | 611 |
/// Naturally edges don't have direction and thus |
| 612 | 612 |
/// don't have source and target node. However we use \c u() and \c v() |
| ... | ... |
@@ -703,61 +703,62 @@ |
| 703 | 703 |
// Dummy parameter. |
| 704 | 704 |
int maxId(Arc) const { return -1; }
|
| 705 | 705 |
|
| 706 | 706 |
/// \brief Base node of the iterator |
| 707 | 707 |
/// |
| 708 | 708 |
/// Returns the base node (the source in this case) of the iterator |
| 709 | 709 |
Node baseNode(OutArcIt e) const {
|
| 710 | 710 |
return source(e); |
| 711 | 711 |
} |
| 712 | 712 |
/// \brief Running node of the iterator |
| 713 | 713 |
/// |
| 714 | 714 |
/// Returns the running node (the target in this case) of the |
| 715 | 715 |
/// iterator |
| 716 | 716 |
Node runningNode(OutArcIt e) const {
|
| 717 | 717 |
return target(e); |
| 718 | 718 |
} |
| 719 | 719 |
|
| 720 | 720 |
/// \brief Base node of the iterator |
| 721 | 721 |
/// |
| 722 | 722 |
/// Returns the base node (the target in this case) of the iterator |
| 723 | 723 |
Node baseNode(InArcIt e) const {
|
| 724 | 724 |
return target(e); |
| 725 | 725 |
} |
| 726 | 726 |
/// \brief Running node of the iterator |
| 727 | 727 |
/// |
| 728 | 728 |
/// Returns the running node (the source in this case) of the |
| 729 | 729 |
/// iterator |
| 730 | 730 |
Node runningNode(InArcIt e) const {
|
| 731 | 731 |
return source(e); |
| 732 | 732 |
} |
| 733 | 733 |
|
| 734 | 734 |
/// \brief Base node of the iterator |
| 735 | 735 |
/// |
| 736 | 736 |
/// Returns the base node of the iterator |
| 737 | 737 |
Node baseNode(IncEdgeIt) const {
|
| 738 | 738 |
return INVALID; |
| 739 | 739 |
} |
| 740 | 740 |
|
| 741 | 741 |
/// \brief Running node of the iterator |
| 742 | 742 |
/// |
| 743 | 743 |
/// Returns the running node of the iterator |
| 744 | 744 |
Node runningNode(IncEdgeIt) const {
|
| 745 | 745 |
return INVALID; |
| 746 | 746 |
} |
| 747 | 747 |
|
| 748 | 748 |
template <typename _Graph> |
| 749 | 749 |
struct Constraints {
|
| 750 | 750 |
void constraints() {
|
| 751 |
checkConcept<BaseGraphComponent, _Graph>(); |
|
| 751 | 752 |
checkConcept<IterableGraphComponent<>, _Graph>(); |
| 752 | 753 |
checkConcept<IDableGraphComponent<>, _Graph>(); |
| 753 | 754 |
checkConcept<MappableGraphComponent<>, _Graph>(); |
| 754 | 755 |
} |
| 755 | 756 |
}; |
| 756 | 757 |
|
| 757 | 758 |
}; |
| 758 | 759 |
|
| 759 | 760 |
} |
| 760 | 761 |
|
| 761 | 762 |
} |
| 762 | 763 |
|
| 763 | 764 |
#endif |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup graph_concepts |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief The concept of graph components. |
| 22 | 22 |
|
| 23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| 24 | 24 |
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
#include <lemon/bits/alteration_notifier.h> |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
namespace concepts {
|
| 33 | 33 |
|
| 34 |
/// \brief |
|
| 34 |
/// \brief Concept class for \c Node, \c Arc and \c Edge types. |
|
| 35 | 35 |
/// |
| 36 |
/// This class describes the interface of Node and Arc (and Edge |
|
| 37 |
/// in undirected graphs) subtypes of graph types. |
|
| 36 |
/// This class describes the concept of \c Node, \c Arc and \c Edge |
|
| 37 |
/// subtypes of digraph and graph types. |
|
| 38 | 38 |
/// |
| 39 | 39 |
/// \note This class is a template class so that we can use it to |
| 40 |
/// create graph skeleton classes. The reason for this is than Node |
|
| 41 |
/// and Arc types should \em not derive from the same base class. |
|
| 42 |
/// For Node you should instantiate it with character 'n' and for Arc |
|
| 43 |
/// with 'a'. |
|
| 44 |
|
|
| 40 |
/// create graph skeleton classes. The reason for this is that \c Node |
|
| 41 |
/// and \c Arc (or \c Edge) types should \e not derive from the same |
|
| 42 |
/// base class. For \c Node you should instantiate it with character |
|
| 43 |
/// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'. |
|
| 45 | 44 |
#ifndef DOXYGEN |
| 46 | 45 |
template <char sel = '0'> |
| 47 | 46 |
#endif |
| 48 | 47 |
class GraphItem {
|
| 49 | 48 |
public: |
| 50 | 49 |
/// \brief Default constructor. |
| 51 | 50 |
/// |
| 51 |
/// Default constructor. |
|
| 52 | 52 |
/// \warning The default constructor is not required to set |
| 53 | 53 |
/// the item to some well-defined value. So you should consider it |
| 54 | 54 |
/// as uninitialized. |
| 55 | 55 |
GraphItem() {}
|
| 56 |
|
|
| 56 | 57 |
/// \brief Copy constructor. |
| 57 | 58 |
/// |
| 58 | 59 |
/// Copy constructor. |
| 60 |
GraphItem(const GraphItem &) {}
|
|
| 61 |
|
|
| 62 |
/// \brief Constructor for conversion from \c INVALID. |
|
| 59 | 63 |
/// |
| 60 |
GraphItem(const GraphItem &) {}
|
|
| 61 |
/// \brief Invalid constructor \& conversion. |
|
| 62 |
/// |
|
| 63 |
/// This constructor initializes the item to be invalid. |
|
| 64 |
/// Constructor for conversion from \c INVALID. |
|
| 65 |
/// It initializes the item to be invalid. |
|
| 64 | 66 |
/// \sa Invalid for more details. |
| 65 | 67 |
GraphItem(Invalid) {}
|
| 66 |
|
|
| 68 |
|
|
| 69 |
/// \brief Assignment operator. |
|
| 67 | 70 |
/// |
| 68 |
/// The nodes are assignable. |
|
| 69 |
/// |
|
| 70 |
|
|
| 71 |
/// Assignment operator for the item. |
|
| 72 |
GraphItem& operator=(const GraphItem&) { return *this; }
|
|
| 73 |
|
|
| 71 | 74 |
/// \brief Equality operator. |
| 72 | 75 |
/// |
| 73 |
/// Two iterators are equal if and only if they represents the |
|
| 74 |
/// same node in the graph or both are invalid. |
|
| 75 |
|
|
| 76 |
/// Equality operator. |
|
| 77 |
bool operator==(const GraphItem&) const { return false; }
|
|
| 78 |
|
|
| 76 | 79 |
/// \brief Inequality operator. |
| 77 | 80 |
/// |
| 78 |
/// |
|
| 81 |
/// Inequality operator. |
|
| 82 |
bool operator!=(const GraphItem&) const { return false; }
|
|
| 83 |
|
|
| 84 |
/// \brief Ordering operator. |
|
| 79 | 85 |
/// |
| 80 |
bool operator!=(GraphItem) const { return false; }
|
|
| 81 |
|
|
| 82 |
/// \brief Artificial ordering operator. |
|
| 83 |
/// |
|
| 84 |
/// To allow the use of graph descriptors as key type in std::map or |
|
| 85 |
/// similar associative container we require this. |
|
| 86 |
/// This operator defines an ordering of the items. |
|
| 87 |
/// It makes possible to use graph item types as key types in |
|
| 88 |
/// associative containers (e.g. \c std::map). |
|
| 86 | 89 |
/// |
| 87 | 90 |
/// \note This operator only have to define some strict ordering of |
| 88 | 91 |
/// the items; this order has nothing to do with the iteration |
| 89 | 92 |
/// ordering of the items. |
| 90 |
bool operator<(GraphItem) const { return false; }
|
|
| 93 |
bool operator<(const GraphItem&) const { return false; }
|
|
| 91 | 94 |
|
| 92 | 95 |
template<typename _GraphItem> |
| 93 | 96 |
struct Constraints {
|
| 94 | 97 |
void constraints() {
|
| 95 | 98 |
_GraphItem i1; |
| 96 | 99 |
_GraphItem i2 = i1; |
| 97 | 100 |
_GraphItem i3 = INVALID; |
| 98 | 101 |
|
| 99 | 102 |
i1 = i2 = i3; |
| 100 | 103 |
|
| 101 | 104 |
bool b; |
| 102 |
// b = (ia == ib) && (ia != ib) && (ia < ib); |
|
| 103 | 105 |
b = (ia == ib) && (ia != ib); |
| 104 | 106 |
b = (ia == INVALID) && (ib != INVALID); |
| 105 | 107 |
b = (ia < ib); |
| 106 | 108 |
} |
| 107 | 109 |
|
| 108 | 110 |
const _GraphItem &ia; |
| 109 | 111 |
const _GraphItem &ib; |
| 110 | 112 |
}; |
| 111 | 113 |
}; |
| 112 | 114 |
|
| 113 |
/// \brief |
|
| 115 |
/// \brief Base skeleton class for directed graphs. |
|
| 114 | 116 |
/// |
| 115 |
/// This class provides the minimal set of features needed for a |
|
| 116 |
/// directed graph structure. All digraph concepts have to |
|
| 117 |
/// conform to this base directed graph. It just provides types |
|
| 118 |
/// for nodes and arcs and functions to get the source and the |
|
| 119 |
/// |
|
| 117 |
/// This class describes the base interface of directed graph types. |
|
| 118 |
/// All digraph %concepts have to conform to this class. |
|
| 119 |
/// It just provides types for nodes and arcs and functions |
|
| 120 |
/// to get the source and the target nodes of arcs. |
|
| 120 | 121 |
class BaseDigraphComponent {
|
| 121 | 122 |
public: |
| 122 | 123 |
|
| 123 | 124 |
typedef BaseDigraphComponent Digraph; |
| 124 | 125 |
|
| 125 | 126 |
/// \brief Node class of the digraph. |
| 126 | 127 |
/// |
| 127 |
/// This class represents the Nodes of the digraph. |
|
| 128 |
/// |
|
| 128 |
/// This class represents the nodes of the digraph. |
|
| 129 | 129 |
typedef GraphItem<'n'> Node; |
| 130 | 130 |
|
| 131 | 131 |
/// \brief Arc class of the digraph. |
| 132 | 132 |
/// |
| 133 |
/// This class represents the |
|
| 133 |
/// This class represents the arcs of the digraph. |
|
| 134 |
typedef GraphItem<'a'> Arc; |
|
| 135 |
|
|
| 136 |
/// \brief Return the source node of an arc. |
|
| 134 | 137 |
/// |
| 135 |
|
|
| 138 |
/// This function returns the source node of an arc. |
|
| 139 |
Node source(const Arc&) const { return INVALID; }
|
|
| 136 | 140 |
|
| 137 |
/// \brief |
|
| 141 |
/// \brief Return the target node of an arc. |
|
| 138 | 142 |
/// |
| 139 |
/// |
|
| 143 |
/// This function returns the target node of an arc. |
|
| 144 |
Node target(const Arc&) const { return INVALID; }
|
|
| 145 |
|
|
| 146 |
/// \brief Return the opposite node on the given arc. |
|
| 140 | 147 |
/// |
| 141 |
Node target(const Arc&) const { return INVALID;}
|
|
| 142 |
|
|
| 143 |
/// \brief Gives back the source node of an arc. |
|
| 144 |
/// |
|
| 145 |
/// Gives back the source node of an arc. |
|
| 146 |
/// |
|
| 147 |
Node source(const Arc&) const { return INVALID;}
|
|
| 148 |
|
|
| 149 |
/// \brief Gives back the opposite node on the given arc. |
|
| 150 |
/// |
|
| 151 |
/// |
|
| 148 |
/// This function returns the opposite node on the given arc. |
|
| 152 | 149 |
Node oppositeNode(const Node&, const Arc&) const {
|
| 153 | 150 |
return INVALID; |
| 154 | 151 |
} |
| 155 | 152 |
|
| 156 | 153 |
template <typename _Digraph> |
| 157 | 154 |
struct Constraints {
|
| 158 | 155 |
typedef typename _Digraph::Node Node; |
| 159 | 156 |
typedef typename _Digraph::Arc Arc; |
| 160 | 157 |
|
| 161 | 158 |
void constraints() {
|
| 162 | 159 |
checkConcept<GraphItem<'n'>, Node>(); |
| 163 | 160 |
checkConcept<GraphItem<'a'>, Arc>(); |
| 164 | 161 |
{
|
| 165 | 162 |
Node n; |
| 166 | 163 |
Arc e(INVALID); |
| 167 | 164 |
n = digraph.source(e); |
| 168 | 165 |
n = digraph.target(e); |
| 169 | 166 |
n = digraph.oppositeNode(n, e); |
| 170 | 167 |
} |
| 171 | 168 |
} |
| 172 | 169 |
|
| 173 | 170 |
const _Digraph& digraph; |
| 174 | 171 |
}; |
| 175 | 172 |
}; |
| 176 | 173 |
|
| 177 |
/// \brief |
|
| 174 |
/// \brief Base skeleton class for undirected graphs. |
|
| 178 | 175 |
/// |
| 179 |
/// This class provides the minimal set of features needed for an |
|
| 180 |
/// undirected graph structure. All undirected graph concepts have |
|
| 181 |
/// to conform to this base graph. It just provides types for |
|
| 182 |
/// nodes, arcs and edges and functions to get the |
|
| 183 |
/// source and the target of the arcs and edges, |
|
| 184 |
/// conversion from arcs to edges and function to get |
|
| 185 |
/// |
|
| 176 |
/// This class describes the base interface of undirected graph types. |
|
| 177 |
/// All graph %concepts have to conform to this class. |
|
| 178 |
/// It extends the interface of \ref BaseDigraphComponent with an |
|
| 179 |
/// \c Edge type and functions to get the end nodes of edges, |
|
| 180 |
/// to convert from arcs to edges and to get both direction of edges. |
|
| 186 | 181 |
class BaseGraphComponent : public BaseDigraphComponent {
|
| 187 | 182 |
public: |
| 188 | 183 |
typedef BaseDigraphComponent::Node Node; |
| 189 | 184 |
typedef BaseDigraphComponent::Arc Arc; |
| 190 |
|
|
| 185 |
|
|
| 186 |
/// \brief Undirected edge class of the graph. |
|
| 191 | 187 |
/// |
| 192 |
/// This class represents the edges of the graph. |
|
| 193 |
/// The undirected graphs can be used as a directed graph which |
|
| 194 |
/// for each arc contains the opposite arc too so the graph is |
|
| 195 |
/// bidirected. The edge represents two opposite |
|
| 196 |
/// directed arcs. |
|
| 197 |
class Edge : public GraphItem<'u'> {
|
|
| 188 |
/// This class represents the undirected edges of the graph. |
|
| 189 |
/// Undirected graphs can be used as directed graphs, each edge is |
|
| 190 |
/// represented by two opposite directed arcs. |
|
| 191 |
class Edge : public GraphItem<'e'> {
|
|
| 198 | 192 |
public: |
| 199 |
typedef GraphItem<' |
|
| 193 |
typedef GraphItem<'e'> Parent; |
|
| 194 |
|
|
| 200 | 195 |
/// \brief Default constructor. |
| 201 | 196 |
/// |
| 197 |
/// Default constructor. |
|
| 202 | 198 |
/// \warning The default constructor is not required to set |
| 203 | 199 |
/// the item to some well-defined value. So you should consider it |
| 204 | 200 |
/// as uninitialized. |
| 205 | 201 |
Edge() {}
|
| 202 |
|
|
| 206 | 203 |
/// \brief Copy constructor. |
| 207 | 204 |
/// |
| 208 | 205 |
/// Copy constructor. |
| 206 |
Edge(const Edge &) : Parent() {}
|
|
| 207 |
|
|
| 208 |
/// \brief Constructor for conversion from \c INVALID. |
|
| 209 | 209 |
/// |
| 210 |
Edge(const Edge &) : Parent() {}
|
|
| 211 |
/// \brief Invalid constructor \& conversion. |
|
| 212 |
/// |
|
| 213 |
/// This constructor initializes the item to be invalid. |
|
| 210 |
/// Constructor for conversion from \c INVALID. |
|
| 211 |
/// It initializes the item to be invalid. |
|
| 214 | 212 |
/// \sa Invalid for more details. |
| 215 | 213 |
Edge(Invalid) {}
|
| 216 |
|
|
| 214 |
|
|
| 215 |
/// \brief Constructor for conversion from an arc. |
|
| 217 | 216 |
/// |
| 217 |
/// Constructor for conversion from an arc. |
|
| 218 | 218 |
/// Besides the core graph item functionality each arc should |
| 219 | 219 |
/// be convertible to the represented edge. |
| 220 | 220 |
Edge(const Arc&) {}
|
| 221 |
|
|
| 221 |
|
|
| 222 |
/// \brief Assign an arc to an edge. |
|
| 222 | 223 |
/// |
| 224 |
/// This function assigns an arc to an edge. |
|
| 223 | 225 |
/// Besides the core graph item functionality each arc should |
| 224 | 226 |
/// be convertible to the represented edge. |
| 225 | 227 |
Edge& operator=(const Arc&) { return *this; }
|
| 226 | 228 |
}; |
| 227 | 229 |
|
| 228 |
/// \brief |
|
| 230 |
/// \brief Return one end node of an edge. |
|
| 231 |
/// |
|
| 232 |
/// This function returns one end node of an edge. |
|
| 233 |
Node u(const Edge&) const { return INVALID; }
|
|
| 234 |
|
|
| 235 |
/// \brief Return the other end node of an edge. |
|
| 236 |
/// |
|
| 237 |
/// This function returns the other end node of an edge. |
|
| 238 |
Node v(const Edge&) const { return INVALID; }
|
|
| 239 |
|
|
| 240 |
/// \brief Return a directed arc related to an edge. |
|
| 241 |
/// |
|
| 242 |
/// This function returns a directed arc from its direction and the |
|
| 243 |
/// represented edge. |
|
| 244 |
Arc direct(const Edge&, bool) const { return INVALID; }
|
|
| 245 |
|
|
| 246 |
/// \brief Return a directed arc related to an edge. |
|
| 247 |
/// |
|
| 248 |
/// This function returns a directed arc from its source node and the |
|
| 249 |
/// represented edge. |
|
| 250 |
Arc direct(const Edge&, const Node&) const { return INVALID; }
|
|
| 251 |
|
|
| 252 |
/// \brief Return the direction of the arc. |
|
| 229 | 253 |
/// |
| 230 | 254 |
/// Returns the direction of the arc. Each arc represents an |
| 231 | 255 |
/// edge with a direction. It gives back the |
| 232 | 256 |
/// direction. |
| 233 | 257 |
bool direction(const Arc&) const { return true; }
|
| 234 | 258 |
|
| 235 |
/// \brief |
|
| 259 |
/// \brief Return the opposite arc. |
|
| 236 | 260 |
/// |
| 237 |
/// Returns the directed arc from its direction and the |
|
| 238 |
/// represented edge. |
|
| 239 |
Arc direct(const Edge&, bool) const { return INVALID;}
|
|
| 240 |
|
|
| 241 |
/// \brief Returns the directed arc. |
|
| 242 |
/// |
|
| 243 |
/// Returns the directed arc from its source and the |
|
| 244 |
/// represented edge. |
|
| 245 |
Arc direct(const Edge&, const Node&) const { return INVALID;}
|
|
| 246 |
|
|
| 247 |
/// \brief Returns the opposite arc. |
|
| 248 |
/// |
|
| 249 |
/// Returns the opposite arc. It is the arc representing the |
|
| 250 |
/// same edge and has opposite direction. |
|
| 251 |
Arc oppositeArc(const Arc&) const { return INVALID;}
|
|
| 252 |
|
|
| 253 |
/// \brief Gives back one ending of an edge. |
|
| 254 |
/// |
|
| 255 |
/// Gives back one ending of an edge. |
|
| 256 |
Node u(const Edge&) const { return INVALID;}
|
|
| 257 |
|
|
| 258 |
/// \brief Gives back the other ending of an edge. |
|
| 259 |
/// |
|
| 260 |
/// Gives back the other ending of an edge. |
|
| 261 |
|
|
| 261 |
/// This function returns the opposite arc, i.e. the arc representing |
|
| 262 |
/// the same edge and has opposite direction. |
|
| 263 |
Arc oppositeArc(const Arc&) const { return INVALID; }
|
|
| 262 | 264 |
|
| 263 | 265 |
template <typename _Graph> |
| 264 | 266 |
struct Constraints {
|
| 265 | 267 |
typedef typename _Graph::Node Node; |
| 266 | 268 |
typedef typename _Graph::Arc Arc; |
| 267 | 269 |
typedef typename _Graph::Edge Edge; |
| 268 | 270 |
|
| 269 | 271 |
void constraints() {
|
| 270 | 272 |
checkConcept<BaseDigraphComponent, _Graph>(); |
| 271 |
checkConcept<GraphItem<' |
|
| 273 |
checkConcept<GraphItem<'e'>, Edge>(); |
|
| 272 | 274 |
{
|
| 273 | 275 |
Node n; |
| 274 | 276 |
Edge ue(INVALID); |
| 275 | 277 |
Arc e; |
| 276 | 278 |
n = graph.u(ue); |
| 277 | 279 |
n = graph.v(ue); |
| 278 | 280 |
e = graph.direct(ue, true); |
| 281 |
e = graph.direct(ue, false); |
|
| 279 | 282 |
e = graph.direct(ue, n); |
| 280 | 283 |
e = graph.oppositeArc(e); |
| 281 | 284 |
ue = e; |
| 282 | 285 |
bool d = graph.direction(e); |
| 283 | 286 |
ignore_unused_variable_warning(d); |
| 284 | 287 |
} |
| 285 | 288 |
} |
| 286 | 289 |
|
| 287 | 290 |
const _Graph& graph; |
| 288 | 291 |
}; |
| 289 | 292 |
|
| 290 | 293 |
}; |
| 291 | 294 |
|
| 292 |
/// \brief |
|
| 295 |
/// \brief Skeleton class for \e idable directed graphs. |
|
| 293 | 296 |
/// |
| 294 |
/// This class provides beside the core digraph features |
|
| 295 |
/// core id functions for the digraph structure. |
|
| 296 |
/// The most of the base digraphs should conform to this concept. |
|
| 297 |
/// The id's are unique and immutable. |
|
| 297 |
/// This class describes the interface of \e idable directed graphs. |
|
| 298 |
/// It extends \ref BaseDigraphComponent with the core ID functions. |
|
| 299 |
/// The ids of the items must be unique and immutable. |
|
| 300 |
/// This concept is part of the Digraph concept. |
|
| 298 | 301 |
template <typename BAS = BaseDigraphComponent> |
| 299 | 302 |
class IDableDigraphComponent : public BAS {
|
| 300 | 303 |
public: |
| 301 | 304 |
|
| 302 | 305 |
typedef BAS Base; |
| 303 | 306 |
typedef typename Base::Node Node; |
| 304 | 307 |
typedef typename Base::Arc Arc; |
| 305 | 308 |
|
| 306 |
/// \brief |
|
| 309 |
/// \brief Return a unique integer id for the given node. |
|
| 307 | 310 |
/// |
| 308 |
/// |
|
| 311 |
/// This function returns a unique integer id for the given node. |
|
| 312 |
int id(const Node&) const { return -1; }
|
|
| 313 |
|
|
| 314 |
/// \brief Return the node by its unique id. |
|
| 309 | 315 |
/// |
| 310 |
|
|
| 316 |
/// This function returns the node by its unique id. |
|
| 317 |
/// If the digraph does not contain a node with the given id, |
|
| 318 |
/// then the result of the function is undefined. |
|
| 319 |
Node nodeFromId(int) const { return INVALID; }
|
|
| 311 | 320 |
|
| 312 |
/// \brief |
|
| 321 |
/// \brief Return a unique integer id for the given arc. |
|
| 313 | 322 |
/// |
| 314 |
/// Gives back the node by the unique id. |
|
| 315 |
/// If the digraph does not contain node with the given id |
|
| 316 |
/// then the result of the function is undetermined. |
|
| 317 |
Node nodeFromId(int) const { return INVALID;}
|
|
| 323 |
/// This function returns a unique integer id for the given arc. |
|
| 324 |
int id(const Arc&) const { return -1; }
|
|
| 318 | 325 |
|
| 319 |
/// \brief |
|
| 326 |
/// \brief Return the arc by its unique id. |
|
| 320 | 327 |
/// |
| 321 |
/// |
|
| 328 |
/// This function returns the arc by its unique id. |
|
| 329 |
/// If the digraph does not contain an arc with the given id, |
|
| 330 |
/// then the result of the function is undefined. |
|
| 331 |
Arc arcFromId(int) const { return INVALID; }
|
|
| 332 |
|
|
| 333 |
/// \brief Return an integer greater or equal to the maximum |
|
| 334 |
/// node id. |
|
| 322 | 335 |
/// |
| 323 |
|
|
| 336 |
/// This function returns an integer greater or equal to the |
|
| 337 |
/// maximum node id. |
|
| 338 |
int maxNodeId() const { return -1; }
|
|
| 324 | 339 |
|
| 325 |
/// \brief |
|
| 340 |
/// \brief Return an integer greater or equal to the maximum |
|
| 341 |
/// arc id. |
|
| 326 | 342 |
/// |
| 327 |
/// Gives back the arc by the unique id. |
|
| 328 |
/// If the digraph does not contain arc with the given id |
|
| 329 |
/// then the result of the function is undetermined. |
|
| 330 |
Arc arcFromId(int) const { return INVALID;}
|
|
| 331 |
|
|
| 332 |
/// \brief Gives back an integer greater or equal to the maximum |
|
| 333 |
/// Node id. |
|
| 334 |
/// |
|
| 335 |
/// Gives back an integer greater or equal to the maximum Node |
|
| 336 |
/// id. |
|
| 337 |
int maxNodeId() const { return -1;}
|
|
| 338 |
|
|
| 339 |
/// \brief Gives back an integer greater or equal to the maximum |
|
| 340 |
/// Arc id. |
|
| 341 |
/// |
|
| 342 |
/// Gives back an integer greater or equal to the maximum Arc |
|
| 343 |
/// id. |
|
| 344 |
int maxArcId() const { return -1;}
|
|
| 343 |
/// This function returns an integer greater or equal to the |
|
| 344 |
/// maximum arc id. |
|
| 345 |
int maxArcId() const { return -1; }
|
|
| 345 | 346 |
|
| 346 | 347 |
template <typename _Digraph> |
| 347 | 348 |
struct Constraints {
|
| 348 | 349 |
|
| 349 | 350 |
void constraints() {
|
| 350 | 351 |
checkConcept<Base, _Digraph >(); |
| 351 | 352 |
typename _Digraph::Node node; |
| 352 | 353 |
int nid = digraph.id(node); |
| 353 | 354 |
nid = digraph.id(node); |
| 354 | 355 |
node = digraph.nodeFromId(nid); |
| 355 | 356 |
typename _Digraph::Arc arc; |
| 356 | 357 |
int eid = digraph.id(arc); |
| 357 | 358 |
eid = digraph.id(arc); |
| 358 | 359 |
arc = digraph.arcFromId(eid); |
| 359 | 360 |
|
| 360 | 361 |
nid = digraph.maxNodeId(); |
| 361 | 362 |
ignore_unused_variable_warning(nid); |
| 362 | 363 |
eid = digraph.maxArcId(); |
| 363 | 364 |
ignore_unused_variable_warning(eid); |
| 364 | 365 |
} |
| 365 | 366 |
|
| 366 | 367 |
const _Digraph& digraph; |
| 367 | 368 |
}; |
| 368 | 369 |
}; |
| 369 | 370 |
|
| 370 |
/// \brief |
|
| 371 |
/// \brief Skeleton class for \e idable undirected graphs. |
|
| 371 | 372 |
/// |
| 372 |
/// This class provides beside the core undirected graph features |
|
| 373 |
/// core id functions for the undirected graph structure. The |
|
| 374 |
/// most of the base undirected graphs should conform to this |
|
| 375 |
/// concept. The id's are unique and immutable. |
|
| 373 |
/// This class describes the interface of \e idable undirected |
|
| 374 |
/// graphs. It extends \ref IDableDigraphComponent with the core ID |
|
| 375 |
/// functions of undirected graphs. |
|
| 376 |
/// The ids of the items must be unique and immutable. |
|
| 377 |
/// This concept is part of the Graph concept. |
|
| 376 | 378 |
template <typename BAS = BaseGraphComponent> |
| 377 | 379 |
class IDableGraphComponent : public IDableDigraphComponent<BAS> {
|
| 378 | 380 |
public: |
| 379 | 381 |
|
| 380 | 382 |
typedef BAS Base; |
| 381 | 383 |
typedef typename Base::Edge Edge; |
| 382 | 384 |
|
| 383 | 385 |
using IDableDigraphComponent<Base>::id; |
| 384 | 386 |
|
| 385 |
/// \brief |
|
| 387 |
/// \brief Return a unique integer id for the given edge. |
|
| 386 | 388 |
/// |
| 387 |
/// |
|
| 389 |
/// This function returns a unique integer id for the given edge. |
|
| 390 |
int id(const Edge&) const { return -1; }
|
|
| 391 |
|
|
| 392 |
/// \brief Return the edge by its unique id. |
|
| 388 | 393 |
/// |
| 389 |
|
|
| 394 |
/// This function returns the edge by its unique id. |
|
| 395 |
/// If the graph does not contain an edge with the given id, |
|
| 396 |
/// then the result of the function is undefined. |
|
| 397 |
Edge edgeFromId(int) const { return INVALID; }
|
|
| 390 | 398 |
|
| 391 |
/// \brief |
|
| 399 |
/// \brief Return an integer greater or equal to the maximum |
|
| 400 |
/// edge id. |
|
| 392 | 401 |
/// |
| 393 |
/// Gives back the edge by the unique id. If the |
|
| 394 |
/// graph does not contain arc with the given id then the |
|
| 395 |
/// result of the function is undetermined. |
|
| 396 |
Edge edgeFromId(int) const { return INVALID;}
|
|
| 397 |
|
|
| 398 |
/// \brief Gives back an integer greater or equal to the maximum |
|
| 399 |
/// Edge id. |
|
| 400 |
/// |
|
| 401 |
/// Gives back an integer greater or equal to the maximum Edge |
|
| 402 |
/// id. |
|
| 403 |
|
|
| 402 |
/// This function returns an integer greater or equal to the |
|
| 403 |
/// maximum edge id. |
|
| 404 |
int maxEdgeId() const { return -1; }
|
|
| 404 | 405 |
|
| 405 | 406 |
template <typename _Graph> |
| 406 | 407 |
struct Constraints {
|
| 407 | 408 |
|
| 408 | 409 |
void constraints() {
|
| 409 |
checkConcept<Base, _Graph >(); |
|
| 410 | 410 |
checkConcept<IDableDigraphComponent<Base>, _Graph >(); |
| 411 | 411 |
typename _Graph::Edge edge; |
| 412 | 412 |
int ueid = graph.id(edge); |
| 413 | 413 |
ueid = graph.id(edge); |
| 414 | 414 |
edge = graph.edgeFromId(ueid); |
| 415 | 415 |
ueid = graph.maxEdgeId(); |
| 416 | 416 |
ignore_unused_variable_warning(ueid); |
| 417 | 417 |
} |
| 418 | 418 |
|
| 419 | 419 |
const _Graph& graph; |
| 420 | 420 |
}; |
| 421 | 421 |
}; |
| 422 | 422 |
|
| 423 |
/// \brief |
|
| 423 |
/// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types. |
|
| 424 | 424 |
/// |
| 425 |
/// Skeleton class for graph NodeIt and ArcIt. |
|
| 426 |
/// |
|
| 425 |
/// This class describes the concept of \c NodeIt, \c ArcIt and |
|
| 426 |
/// \c EdgeIt subtypes of digraph and graph types. |
|
| 427 | 427 |
template <typename GR, typename Item> |
| 428 | 428 |
class GraphItemIt : public Item {
|
| 429 | 429 |
public: |
| 430 | 430 |
/// \brief Default constructor. |
| 431 | 431 |
/// |
| 432 |
/// @warning The default constructor sets the iterator |
|
| 433 |
/// to an undefined value. |
|
| 432 |
/// Default constructor. |
|
| 433 |
/// \warning The default constructor is not required to set |
|
| 434 |
/// the iterator to some well-defined value. So you should consider it |
|
| 435 |
/// as uninitialized. |
|
| 434 | 436 |
GraphItemIt() {}
|
| 437 |
|
|
| 435 | 438 |
/// \brief Copy constructor. |
| 436 | 439 |
/// |
| 437 | 440 |
/// Copy constructor. |
| 441 |
GraphItemIt(const GraphItemIt& it) : Item(it) {}
|
|
| 442 |
|
|
| 443 |
/// \brief Constructor that sets the iterator to the first item. |
|
| 438 | 444 |
/// |
| 439 |
GraphItemIt(const GraphItemIt& ) {}
|
|
| 440 |
/// \brief Sets the iterator to the first item. |
|
| 445 |
/// Constructor that sets the iterator to the first item. |
|
| 446 |
explicit GraphItemIt(const GR&) {}
|
|
| 447 |
|
|
| 448 |
/// \brief Constructor for conversion from \c INVALID. |
|
| 441 | 449 |
/// |
| 442 |
/// Sets the iterator to the first item of \c the graph. |
|
| 443 |
/// |
|
| 444 |
explicit GraphItemIt(const GR&) {}
|
|
| 445 |
/// \brief Invalid constructor \& conversion. |
|
| 446 |
/// |
|
| 447 |
/// This constructor initializes the item to be invalid. |
|
| 450 |
/// Constructor for conversion from \c INVALID. |
|
| 451 |
/// It initializes the iterator to be invalid. |
|
| 448 | 452 |
/// \sa Invalid for more details. |
| 449 | 453 |
GraphItemIt(Invalid) {}
|
| 450 |
|
|
| 454 |
|
|
| 455 |
/// \brief Assignment operator. |
|
| 451 | 456 |
/// |
| 452 |
/// |
|
| 457 |
/// Assignment operator for the iterator. |
|
| 458 |
GraphItemIt& operator=(const GraphItemIt&) { return *this; }
|
|
| 459 |
|
|
| 460 |
/// \brief Increment the iterator. |
|
| 453 | 461 |
/// |
| 454 |
GraphItemIt& operator=(const GraphItemIt&) { return *this; }
|
|
| 455 |
/// \brief Next item. |
|
| 456 |
/// |
|
| 457 |
/// Assign the iterator to the next item. |
|
| 458 |
/// |
|
| 462 |
/// This operator increments the iterator, i.e. assigns it to the |
|
| 463 |
/// next item. |
|
| 459 | 464 |
GraphItemIt& operator++() { return *this; }
|
| 465 |
|
|
| 460 | 466 |
/// \brief Equality operator |
| 461 | 467 |
/// |
| 468 |
/// Equality operator. |
|
| 462 | 469 |
/// Two iterators are equal if and only if they point to the |
| 463 | 470 |
/// same object or both are invalid. |
| 464 | 471 |
bool operator==(const GraphItemIt&) const { return true;}
|
| 472 |
|
|
| 465 | 473 |
/// \brief Inequality operator |
| 466 | 474 |
/// |
| 467 |
/// \sa operator==(Node n) |
|
| 468 |
/// |
|
| 475 |
/// Inequality operator. |
|
| 476 |
/// Two iterators are equal if and only if they point to the |
|
| 477 |
/// same object or both are invalid. |
|
| 469 | 478 |
bool operator!=(const GraphItemIt&) const { return true;}
|
| 470 | 479 |
|
| 471 | 480 |
template<typename _GraphItemIt> |
| 472 | 481 |
struct Constraints {
|
| 473 | 482 |
void constraints() {
|
| 483 |
checkConcept<GraphItem<>, _GraphItemIt>(); |
|
| 474 | 484 |
_GraphItemIt it1(g); |
| 475 | 485 |
_GraphItemIt it2; |
| 486 |
_GraphItemIt it3 = it1; |
|
| 487 |
_GraphItemIt it4 = INVALID; |
|
| 476 | 488 |
|
| 477 | 489 |
it2 = ++it1; |
| 478 | 490 |
++it2 = it1; |
| 479 | 491 |
++(++it1); |
| 480 | 492 |
|
| 481 | 493 |
Item bi = it1; |
| 482 | 494 |
bi = it2; |
| 483 | 495 |
} |
| 484 |
GR& g; |
|
| 496 |
const GR& g; |
|
| 485 | 497 |
}; |
| 486 | 498 |
}; |
| 487 | 499 |
|
| 488 |
/// \brief |
|
| 500 |
/// \brief Concept class for \c InArcIt, \c OutArcIt and |
|
| 501 |
/// \c IncEdgeIt types. |
|
| 489 | 502 |
/// |
| 490 |
/// \note Because InArcIt and OutArcIt may not inherit from the same |
|
| 491 |
/// base class, the \c sel is a additional template parameter (selector). |
|
| 492 |
/// For InArcIt you should instantiate it with character 'i' and for |
|
| 493 |
/// OutArcIt with 'o'. |
|
| 503 |
/// This class describes the concept of \c InArcIt, \c OutArcIt |
|
| 504 |
/// and \c IncEdgeIt subtypes of digraph and graph types. |
|
| 505 |
/// |
|
| 506 |
/// \note Since these iterator classes do not inherit from the same |
|
| 507 |
/// base class, there is an additional template parameter (selector) |
|
| 508 |
/// \c sel. For \c InArcIt you should instantiate it with character |
|
| 509 |
/// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'. |
|
| 494 | 510 |
template <typename GR, |
| 495 | 511 |
typename Item = typename GR::Arc, |
| 496 | 512 |
typename Base = typename GR::Node, |
| 497 | 513 |
char sel = '0'> |
| 498 | 514 |
class GraphIncIt : public Item {
|
| 499 | 515 |
public: |
| 500 | 516 |
/// \brief Default constructor. |
| 501 | 517 |
/// |
| 502 |
/// @warning The default constructor sets the iterator |
|
| 503 |
/// to an undefined value. |
|
| 518 |
/// Default constructor. |
|
| 519 |
/// \warning The default constructor is not required to set |
|
| 520 |
/// the iterator to some well-defined value. So you should consider it |
|
| 521 |
/// as uninitialized. |
|
| 504 | 522 |
GraphIncIt() {}
|
| 523 |
|
|
| 505 | 524 |
/// \brief Copy constructor. |
| 506 | 525 |
/// |
| 507 | 526 |
/// Copy constructor. |
| 527 |
GraphIncIt(const GraphIncIt& it) : Item(it) {}
|
|
| 528 |
|
|
| 529 |
/// \brief Constructor that sets the iterator to the first |
|
| 530 |
/// incoming or outgoing arc. |
|
| 508 | 531 |
/// |
| 509 |
GraphIncIt(GraphIncIt const& gi) : Item(gi) {}
|
|
| 510 |
/// \brief Sets the iterator to the first arc incoming into or outgoing |
|
| 511 |
/// |
|
| 532 |
/// Constructor that sets the iterator to the first arc |
|
| 533 |
/// incoming to or outgoing from the given node. |
|
| 534 |
explicit GraphIncIt(const GR&, const Base&) {}
|
|
| 535 |
|
|
| 536 |
/// \brief Constructor for conversion from \c INVALID. |
|
| 512 | 537 |
/// |
| 513 |
/// Sets the iterator to the first arc incoming into or outgoing |
|
| 514 |
/// from the node. |
|
| 515 |
/// |
|
| 516 |
explicit GraphIncIt(const GR&, const Base&) {}
|
|
| 517 |
/// \brief Invalid constructor \& conversion. |
|
| 518 |
/// |
|
| 519 |
/// |
|
| 538 |
/// Constructor for conversion from \c INVALID. |
|
| 539 |
/// It initializes the iterator to be invalid. |
|
| 520 | 540 |
/// \sa Invalid for more details. |
| 521 | 541 |
GraphIncIt(Invalid) {}
|
| 522 |
|
|
| 542 |
|
|
| 543 |
/// \brief Assignment operator. |
|
| 523 | 544 |
/// |
| 524 |
/// |
|
| 545 |
/// Assignment operator for the iterator. |
|
| 546 |
GraphIncIt& operator=(const GraphIncIt&) { return *this; }
|
|
| 547 |
|
|
| 548 |
/// \brief Increment the iterator. |
|
| 525 | 549 |
/// |
| 526 |
GraphIncIt& operator=(GraphIncIt const&) { return *this; }
|
|
| 527 |
/// \brief Next item. |
|
| 528 |
/// |
|
| 529 |
/// Assign the iterator to the next item. |
|
| 530 |
/// |
|
| 550 |
/// This operator increments the iterator, i.e. assigns it to the |
|
| 551 |
/// next arc incoming to or outgoing from the given node. |
|
| 531 | 552 |
GraphIncIt& operator++() { return *this; }
|
| 532 | 553 |
|
| 533 | 554 |
/// \brief Equality operator |
| 534 | 555 |
/// |
| 556 |
/// Equality operator. |
|
| 535 | 557 |
/// Two iterators are equal if and only if they point to the |
| 536 | 558 |
/// same object or both are invalid. |
| 537 | 559 |
bool operator==(const GraphIncIt&) const { return true;}
|
| 538 | 560 |
|
| 539 | 561 |
/// \brief Inequality operator |
| 540 | 562 |
/// |
| 541 |
/// \sa operator==(Node n) |
|
| 542 |
/// |
|
| 563 |
/// Inequality operator. |
|
| 564 |
/// Two iterators are equal if and only if they point to the |
|
| 565 |
/// same object or both are invalid. |
|
| 543 | 566 |
bool operator!=(const GraphIncIt&) const { return true;}
|
| 544 | 567 |
|
| 545 | 568 |
template <typename _GraphIncIt> |
| 546 | 569 |
struct Constraints {
|
| 547 | 570 |
void constraints() {
|
| 548 | 571 |
checkConcept<GraphItem<sel>, _GraphIncIt>(); |
| 549 | 572 |
_GraphIncIt it1(graph, node); |
| 550 | 573 |
_GraphIncIt it2; |
| 574 |
_GraphIncIt it3 = it1; |
|
| 575 |
_GraphIncIt it4 = INVALID; |
|
| 551 | 576 |
|
| 552 | 577 |
it2 = ++it1; |
| 553 | 578 |
++it2 = it1; |
| 554 | 579 |
++(++it1); |
| 555 | 580 |
Item e = it1; |
| 556 | 581 |
e = it2; |
| 557 |
|
|
| 558 | 582 |
} |
| 559 |
|
|
| 560 |
Item arc; |
|
| 561 |
Base node; |
|
| 562 |
GR graph; |
|
| 563 |
|
|
| 583 |
const Base& node; |
|
| 584 |
const GR& graph; |
|
| 564 | 585 |
}; |
| 565 | 586 |
}; |
| 566 | 587 |
|
| 567 |
|
|
| 568 |
/// \brief An empty iterable digraph class. |
|
| 588 |
/// \brief Skeleton class for iterable directed graphs. |
|
| 569 | 589 |
/// |
| 570 |
/// This class provides beside the core digraph features |
|
| 571 |
/// iterator based iterable interface for the digraph structure. |
|
| 590 |
/// This class describes the interface of iterable directed |
|
| 591 |
/// graphs. It extends \ref BaseDigraphComponent with the core |
|
| 592 |
/// iterable interface. |
|
| 572 | 593 |
/// This concept is part of the Digraph concept. |
| 573 | 594 |
template <typename BAS = BaseDigraphComponent> |
| 574 | 595 |
class IterableDigraphComponent : public BAS {
|
| 575 | 596 |
|
| 576 | 597 |
public: |
| 577 | 598 |
|
| 578 | 599 |
typedef BAS Base; |
| 579 | 600 |
typedef typename Base::Node Node; |
| 580 | 601 |
typedef typename Base::Arc Arc; |
| 581 | 602 |
|
| 582 | 603 |
typedef IterableDigraphComponent Digraph; |
| 583 | 604 |
|
| 584 |
/// \name Base |
|
| 605 |
/// \name Base Iteration |
|
| 585 | 606 |
/// |
| 586 |
/// This interface provides functions for iteration on digraph items |
|
| 607 |
/// This interface provides functions for iteration on digraph items. |
|
| 587 | 608 |
/// |
| 588 | 609 |
/// @{
|
| 589 | 610 |
|
| 590 |
/// \brief |
|
| 611 |
/// \brief Return the first node. |
|
| 591 | 612 |
/// |
| 592 |
/// Gives back the first node in the iterating order. |
|
| 593 |
/// |
|
| 613 |
/// This function gives back the first node in the iteration order. |
|
| 594 | 614 |
void first(Node&) const {}
|
| 595 | 615 |
|
| 596 |
/// \brief |
|
| 616 |
/// \brief Return the next node. |
|
| 597 | 617 |
/// |
| 598 |
/// Gives back the next node in the iterating order. |
|
| 599 |
/// |
|
| 618 |
/// This function gives back the next node in the iteration order. |
|
| 600 | 619 |
void next(Node&) const {}
|
| 601 | 620 |
|
| 602 |
/// \brief |
|
| 621 |
/// \brief Return the first arc. |
|
| 603 | 622 |
/// |
| 604 |
/// Gives back the first arc in the iterating order. |
|
| 605 |
/// |
|
| 623 |
/// This function gives back the first arc in the iteration order. |
|
| 606 | 624 |
void first(Arc&) const {}
|
| 607 | 625 |
|
| 608 |
/// \brief |
|
| 626 |
/// \brief Return the next arc. |
|
| 609 | 627 |
/// |
| 610 |
/// Gives back the next arc in the iterating order. |
|
| 611 |
/// |
|
| 628 |
/// This function gives back the next arc in the iteration order. |
|
| 612 | 629 |
void next(Arc&) const {}
|
| 613 | 630 |
|
| 614 |
|
|
| 615 |
/// \brief Gives back the first of the arcs point to the given |
|
| 616 |
/// node. |
|
| 631 |
/// \brief Return the first arc incomming to the given node. |
|
| 617 | 632 |
/// |
| 618 |
/// Gives back the first of the arcs point to the given node. |
|
| 619 |
/// |
|
| 633 |
/// This function gives back the first arc incomming to the |
|
| 634 |
/// given node. |
|
| 620 | 635 |
void firstIn(Arc&, const Node&) const {}
|
| 621 | 636 |
|
| 622 |
/// \brief Gives back the next of the arcs points to the given |
|
| 623 |
/// node. |
|
| 637 |
/// \brief Return the next arc incomming to the given node. |
|
| 624 | 638 |
/// |
| 625 |
/// Gives back the next of the arcs points to the given node. |
|
| 626 |
/// |
|
| 639 |
/// This function gives back the next arc incomming to the |
|
| 640 |
/// given node. |
|
| 627 | 641 |
void nextIn(Arc&) const {}
|
| 628 | 642 |
|
| 629 |
/// \brief |
|
| 643 |
/// \brief Return the first arc outgoing form the given node. |
|
| 644 |
/// |
|
| 645 |
/// This function gives back the first arc outgoing form the |
|
| 630 | 646 |
/// given node. |
| 631 |
/// |
|
| 632 |
/// Gives back the first of the arcs start from the given node. |
|
| 633 |
/// |
|
| 634 | 647 |
void firstOut(Arc&, const Node&) const {}
|
| 635 | 648 |
|
| 636 |
/// \brief Gives back the next of the arcs start from the given |
|
| 637 |
/// node. |
|
| 649 |
/// \brief Return the next arc outgoing form the given node. |
|
| 638 | 650 |
/// |
| 639 |
/// Gives back the next of the arcs start from the given node. |
|
| 640 |
/// |
|
| 651 |
/// This function gives back the next arc outgoing form the |
|
| 652 |
/// given node. |
|
| 641 | 653 |
void nextOut(Arc&) const {}
|
| 642 | 654 |
|
| 643 | 655 |
/// @} |
| 644 | 656 |
|
| 645 |
/// \name Class |
|
| 657 |
/// \name Class Based Iteration |
|
| 646 | 658 |
/// |
| 647 |
/// This interface provides |
|
| 659 |
/// This interface provides iterator classes for digraph items. |
|
| 648 | 660 |
/// |
| 649 | 661 |
/// @{
|
| 650 | 662 |
|
| 651 | 663 |
/// \brief This iterator goes through each node. |
| 652 | 664 |
/// |
| 653 | 665 |
/// This iterator goes through each node. |
| 654 | 666 |
/// |
| 655 | 667 |
typedef GraphItemIt<Digraph, Node> NodeIt; |
| 656 | 668 |
|
| 657 |
/// \brief This iterator goes through each |
|
| 669 |
/// \brief This iterator goes through each arc. |
|
| 658 | 670 |
/// |
| 659 |
/// This iterator goes through each |
|
| 671 |
/// This iterator goes through each arc. |
|
| 660 | 672 |
/// |
| 661 | 673 |
typedef GraphItemIt<Digraph, Arc> ArcIt; |
| 662 | 674 |
|
| 663 | 675 |
/// \brief This iterator goes trough the incoming arcs of a node. |
| 664 | 676 |
/// |
| 665 |
/// This iterator goes trough the \e |
|
| 677 |
/// This iterator goes trough the \e incoming arcs of a certain node |
|
| 666 | 678 |
/// of a digraph. |
| 667 | 679 |
typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt; |
| 668 | 680 |
|
| 669 | 681 |
/// \brief This iterator goes trough the outgoing arcs of a node. |
| 670 | 682 |
/// |
| 671 | 683 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
| 672 | 684 |
/// of a digraph. |
| 673 | 685 |
typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt; |
| 674 | 686 |
|
| 675 | 687 |
/// \brief The base node of the iterator. |
| 676 | 688 |
/// |
| 677 |
/// Gives back the base node of the iterator. |
|
| 678 |
/// It is always the target of the pointed arc. |
|
| 689 |
/// This function gives back the base node of the iterator. |
|
| 690 |
/// It is always the target node of the pointed arc. |
|
| 679 | 691 |
Node baseNode(const InArcIt&) const { return INVALID; }
|
| 680 | 692 |
|
| 681 | 693 |
/// \brief The running node of the iterator. |
| 682 | 694 |
/// |
| 683 |
/// Gives back the running node of the iterator. |
|
| 684 |
/// It is always the source of the pointed arc. |
|
| 695 |
/// This function gives back the running node of the iterator. |
|
| 696 |
/// It is always the source node of the pointed arc. |
|
| 685 | 697 |
Node runningNode(const InArcIt&) const { return INVALID; }
|
| 686 | 698 |
|
| 687 | 699 |
/// \brief The base node of the iterator. |
| 688 | 700 |
/// |
| 689 |
/// Gives back the base node of the iterator. |
|
| 690 |
/// It is always the source of the pointed arc. |
|
| 701 |
/// This function gives back the base node of the iterator. |
|
| 702 |
/// It is always the source node of the pointed arc. |
|
| 691 | 703 |
Node baseNode(const OutArcIt&) const { return INVALID; }
|
| 692 | 704 |
|
| 693 | 705 |
/// \brief The running node of the iterator. |
| 694 | 706 |
/// |
| 695 |
/// Gives back the running node of the iterator. |
|
| 696 |
/// It is always the target of the pointed arc. |
|
| 707 |
/// This function gives back the running node of the iterator. |
|
| 708 |
/// It is always the target node of the pointed arc. |
|
| 697 | 709 |
Node runningNode(const OutArcIt&) const { return INVALID; }
|
| 698 | 710 |
|
| 699 | 711 |
/// @} |
| 700 | 712 |
|
| 701 | 713 |
template <typename _Digraph> |
| 702 | 714 |
struct Constraints {
|
| 703 | 715 |
void constraints() {
|
| 704 | 716 |
checkConcept<Base, _Digraph>(); |
| 705 | 717 |
|
| 706 | 718 |
{
|
| 707 | 719 |
typename _Digraph::Node node(INVALID); |
| 708 | 720 |
typename _Digraph::Arc arc(INVALID); |
| 709 | 721 |
{
|
| 710 | 722 |
digraph.first(node); |
| 711 | 723 |
digraph.next(node); |
| 712 | 724 |
} |
| 713 | 725 |
{
|
| 714 | 726 |
digraph.first(arc); |
| 715 | 727 |
digraph.next(arc); |
| 716 | 728 |
} |
| 717 | 729 |
{
|
| 718 | 730 |
digraph.firstIn(arc, node); |
| 719 | 731 |
digraph.nextIn(arc); |
| 720 | 732 |
} |
| 721 | 733 |
{
|
| 722 | 734 |
digraph.firstOut(arc, node); |
| 723 | 735 |
digraph.nextOut(arc); |
| 724 | 736 |
} |
| 725 | 737 |
} |
| 726 | 738 |
|
| 727 | 739 |
{
|
| 728 | 740 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>, |
| 729 | 741 |
typename _Digraph::ArcIt >(); |
| 730 | 742 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>, |
| 731 | 743 |
typename _Digraph::NodeIt >(); |
| 732 | 744 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
| 733 | 745 |
typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>(); |
| 734 | 746 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
| 735 | 747 |
typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>(); |
| 736 | 748 |
|
| 737 | 749 |
typename _Digraph::Node n; |
| 738 |
typename _Digraph::InArcIt ieit(INVALID); |
|
| 739 |
typename _Digraph::OutArcIt oeit(INVALID); |
|
| 740 |
n = digraph.baseNode(ieit); |
|
| 741 |
n = digraph.runningNode(ieit); |
|
| 742 |
n = digraph.baseNode(oeit); |
|
| 743 |
n = digraph.runningNode(oeit); |
|
| 750 |
const typename _Digraph::InArcIt iait(INVALID); |
|
| 751 |
const typename _Digraph::OutArcIt oait(INVALID); |
|
| 752 |
n = digraph.baseNode(iait); |
|
| 753 |
n = digraph.runningNode(iait); |
|
| 754 |
n = digraph.baseNode(oait); |
|
| 755 |
n = digraph.runningNode(oait); |
|
| 744 | 756 |
ignore_unused_variable_warning(n); |
| 745 | 757 |
} |
| 746 | 758 |
} |
| 747 | 759 |
|
| 748 | 760 |
const _Digraph& digraph; |
| 749 |
|
|
| 750 | 761 |
}; |
| 751 | 762 |
}; |
| 752 | 763 |
|
| 753 |
/// \brief |
|
| 764 |
/// \brief Skeleton class for iterable undirected graphs. |
|
| 754 | 765 |
/// |
| 755 |
/// This class provides beside the core graph features iterator |
|
| 756 |
/// based iterable interface for the undirected graph structure. |
|
| 766 |
/// This class describes the interface of iterable undirected |
|
| 767 |
/// graphs. It extends \ref IterableDigraphComponent with the core |
|
| 768 |
/// iterable interface of undirected graphs. |
|
| 757 | 769 |
/// This concept is part of the Graph concept. |
| 758 | 770 |
template <typename BAS = BaseGraphComponent> |
| 759 | 771 |
class IterableGraphComponent : public IterableDigraphComponent<BAS> {
|
| 760 | 772 |
public: |
| 761 | 773 |
|
| 762 | 774 |
typedef BAS Base; |
| 763 | 775 |
typedef typename Base::Node Node; |
| 764 | 776 |
typedef typename Base::Arc Arc; |
| 765 | 777 |
typedef typename Base::Edge Edge; |
| 766 | 778 |
|
| 767 | 779 |
|
| 768 | 780 |
typedef IterableGraphComponent Graph; |
| 769 | 781 |
|
| 770 |
/// \name Base |
|
| 782 |
/// \name Base Iteration |
|
| 771 | 783 |
/// |
| 772 |
/// This interface provides functions for iteration on |
|
| 784 |
/// This interface provides functions for iteration on edges. |
|
| 785 |
/// |
|
| 773 | 786 |
/// @{
|
| 774 | 787 |
|
| 775 | 788 |
using IterableDigraphComponent<Base>::first; |
| 776 | 789 |
using IterableDigraphComponent<Base>::next; |
| 777 | 790 |
|
| 778 |
/// \brief Gives back the first edge in the iterating |
|
| 779 |
/// order. |
|
| 791 |
/// \brief Return the first edge. |
|
| 780 | 792 |
/// |
| 781 |
/// Gives back the first edge in the iterating order. |
|
| 782 |
/// |
|
| 793 |
/// This function gives back the first edge in the iteration order. |
|
| 783 | 794 |
void first(Edge&) const {}
|
| 784 | 795 |
|
| 785 |
/// \brief Gives back the next edge in the iterating |
|
| 786 |
/// order. |
|
| 796 |
/// \brief Return the next edge. |
|
| 787 | 797 |
/// |
| 788 |
/// Gives back the next edge in the iterating order. |
|
| 789 |
/// |
|
| 798 |
/// This function gives back the next edge in the iteration order. |
|
| 790 | 799 |
void next(Edge&) const {}
|
| 791 | 800 |
|
| 792 |
|
|
| 793 |
/// \brief Gives back the first of the edges from the |
|
| 801 |
/// \brief Return the first edge incident to the given node. |
|
| 802 |
/// |
|
| 803 |
/// This function gives back the first edge incident to the given |
|
| 804 |
/// node. The bool parameter gives back the direction for which the |
|
| 805 |
/// source node of the directed arc representing the edge is the |
|
| 794 | 806 |
/// given node. |
| 795 |
/// |
|
| 796 |
/// Gives back the first of the edges from the given |
|
| 797 |
/// node. The bool parameter gives back that direction which |
|
| 798 |
/// gives a good direction of the edge so the source of the |
|
| 799 |
/// directed arc is the given node. |
|
| 800 | 807 |
void firstInc(Edge&, bool&, const Node&) const {}
|
| 801 | 808 |
|
| 802 | 809 |
/// \brief Gives back the next of the edges from the |
| 803 | 810 |
/// given node. |
| 804 | 811 |
/// |
| 805 |
/// Gives back the next of the edges from the given |
|
| 806 |
/// node. The bool parameter should be used as the \c firstInc() |
|
| 807 |
/// |
|
| 812 |
/// This function gives back the next edge incident to the given |
|
| 813 |
/// node. The bool parameter should be used as \c firstInc() use it. |
|
| 808 | 814 |
void nextInc(Edge&, bool&) const {}
|
| 809 | 815 |
|
| 810 | 816 |
using IterableDigraphComponent<Base>::baseNode; |
| 811 | 817 |
using IterableDigraphComponent<Base>::runningNode; |
| 812 | 818 |
|
| 813 | 819 |
/// @} |
| 814 | 820 |
|
| 815 |
/// \name Class |
|
| 821 |
/// \name Class Based Iteration |
|
| 816 | 822 |
/// |
| 817 |
/// This interface provides |
|
| 823 |
/// This interface provides iterator classes for edges. |
|
| 818 | 824 |
/// |
| 819 | 825 |
/// @{
|
| 820 | 826 |
|
| 821 |
/// \brief This iterator goes through each |
|
| 827 |
/// \brief This iterator goes through each edge. |
|
| 822 | 828 |
/// |
| 823 |
/// This iterator goes through each |
|
| 829 |
/// This iterator goes through each edge. |
|
| 824 | 830 |
typedef GraphItemIt<Graph, Edge> EdgeIt; |
| 825 |
|
|
| 831 |
|
|
| 832 |
/// \brief This iterator goes trough the incident edges of a |
|
| 826 | 833 |
/// node. |
| 827 | 834 |
/// |
| 828 |
/// This iterator goes trough the incident |
|
| 835 |
/// This iterator goes trough the incident edges of a certain |
|
| 829 | 836 |
/// node of a graph. |
| 830 |
typedef GraphIncIt<Graph, Edge, Node, ' |
|
| 837 |
typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt; |
|
| 838 |
|
|
| 831 | 839 |
/// \brief The base node of the iterator. |
| 832 | 840 |
/// |
| 833 |
/// |
|
| 841 |
/// This function gives back the base node of the iterator. |
|
| 834 | 842 |
Node baseNode(const IncEdgeIt&) const { return INVALID; }
|
| 835 | 843 |
|
| 836 | 844 |
/// \brief The running node of the iterator. |
| 837 | 845 |
/// |
| 838 |
/// |
|
| 846 |
/// This function gives back the running node of the iterator. |
|
| 839 | 847 |
Node runningNode(const IncEdgeIt&) const { return INVALID; }
|
| 840 | 848 |
|
| 841 | 849 |
/// @} |
| 842 | 850 |
|
| 843 | 851 |
template <typename _Graph> |
| 844 | 852 |
struct Constraints {
|
| 845 | 853 |
void constraints() {
|
| 846 | 854 |
checkConcept<IterableDigraphComponent<Base>, _Graph>(); |
| 847 | 855 |
|
| 848 | 856 |
{
|
| 849 | 857 |
typename _Graph::Node node(INVALID); |
| 850 | 858 |
typename _Graph::Edge edge(INVALID); |
| 851 | 859 |
bool dir; |
| 852 | 860 |
{
|
| 853 | 861 |
graph.first(edge); |
| 854 | 862 |
graph.next(edge); |
| 855 | 863 |
} |
| 856 | 864 |
{
|
| 857 | 865 |
graph.firstInc(edge, dir, node); |
| 858 | 866 |
graph.nextInc(edge, dir); |
| 859 | 867 |
} |
| 860 | 868 |
|
| 861 | 869 |
} |
| 862 | 870 |
|
| 863 | 871 |
{
|
| 864 | 872 |
checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>, |
| 865 | 873 |
typename _Graph::EdgeIt >(); |
| 866 | 874 |
checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
| 867 |
typename _Graph::Node, ' |
|
| 875 |
typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>(); |
|
| 868 | 876 |
|
| 869 | 877 |
typename _Graph::Node n; |
| 870 |
typename _Graph::IncEdgeIt ueit(INVALID); |
|
| 871 |
n = graph.baseNode(ueit); |
|
| 872 |
|
|
| 878 |
const typename _Graph::IncEdgeIt ieit(INVALID); |
|
| 879 |
n = graph.baseNode(ieit); |
|
| 880 |
n = graph.runningNode(ieit); |
|
| 873 | 881 |
} |
| 874 | 882 |
} |
| 875 | 883 |
|
| 876 | 884 |
const _Graph& graph; |
| 877 | 885 |
}; |
| 878 | 886 |
}; |
| 879 | 887 |
|
| 880 |
/// \brief |
|
| 888 |
/// \brief Skeleton class for alterable directed graphs. |
|
| 881 | 889 |
/// |
| 882 |
/// This class provides beside the core digraph features alteration |
|
| 883 |
/// notifier interface for the digraph structure. This implements |
|
| 890 |
/// This class describes the interface of alterable directed |
|
| 891 |
/// graphs. It extends \ref BaseDigraphComponent with the alteration |
|
| 892 |
/// notifier interface. It implements |
|
| 884 | 893 |
/// an observer-notifier pattern for each digraph item. More |
| 885 | 894 |
/// obsevers can be registered into the notifier and whenever an |
| 886 |
/// alteration occured in the digraph all the observers will |
|
| 895 |
/// alteration occured in the digraph all the observers will be |
|
| 887 | 896 |
/// notified about it. |
| 888 | 897 |
template <typename BAS = BaseDigraphComponent> |
| 889 | 898 |
class AlterableDigraphComponent : public BAS {
|
| 890 | 899 |
public: |
| 891 | 900 |
|
| 892 | 901 |
typedef BAS Base; |
| 893 | 902 |
typedef typename Base::Node Node; |
| 894 | 903 |
typedef typename Base::Arc Arc; |
| 895 | 904 |
|
| 896 | 905 |
|
| 897 |
/// |
|
| 906 |
/// Node alteration notifier class. |
|
| 898 | 907 |
typedef AlterationNotifier<AlterableDigraphComponent, Node> |
| 899 | 908 |
NodeNotifier; |
| 900 |
/// |
|
| 909 |
/// Arc alteration notifier class. |
|
| 901 | 910 |
typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
| 902 | 911 |
ArcNotifier; |
| 903 | 912 |
|
| 904 |
/// \brief |
|
| 913 |
/// \brief Return the node alteration notifier. |
|
| 905 | 914 |
/// |
| 906 |
/// |
|
| 915 |
/// This function gives back the node alteration notifier. |
|
| 907 | 916 |
NodeNotifier& notifier(Node) const {
|
| 908 |
return NodeNotifier(); |
|
| 917 |
return NodeNotifier(); |
|
| 909 | 918 |
} |
| 910 | 919 |
|
| 911 |
/// \brief |
|
| 920 |
/// \brief Return the arc alteration notifier. |
|
| 912 | 921 |
/// |
| 913 |
/// |
|
| 922 |
/// This function gives back the arc alteration notifier. |
|
| 914 | 923 |
ArcNotifier& notifier(Arc) const {
|
| 915 | 924 |
return ArcNotifier(); |
| 916 | 925 |
} |
| 917 | 926 |
|
| 918 | 927 |
template <typename _Digraph> |
| 919 | 928 |
struct Constraints {
|
| 920 | 929 |
void constraints() {
|
| 921 | 930 |
checkConcept<Base, _Digraph>(); |
| 922 | 931 |
typename _Digraph::NodeNotifier& nn |
| 923 | 932 |
= digraph.notifier(typename _Digraph::Node()); |
| 924 | 933 |
|
| 925 | 934 |
typename _Digraph::ArcNotifier& en |
| 926 | 935 |
= digraph.notifier(typename _Digraph::Arc()); |
| 927 | 936 |
|
| 928 | 937 |
ignore_unused_variable_warning(nn); |
| 929 | 938 |
ignore_unused_variable_warning(en); |
| 930 | 939 |
} |
| 931 | 940 |
|
| 932 | 941 |
const _Digraph& digraph; |
| 933 |
|
|
| 934 | 942 |
}; |
| 935 |
|
|
| 936 | 943 |
}; |
| 937 | 944 |
|
| 938 |
/// \brief |
|
| 945 |
/// \brief Skeleton class for alterable undirected graphs. |
|
| 939 | 946 |
/// |
| 940 |
/// This class provides beside the core graph features alteration |
|
| 941 |
/// notifier interface for the graph structure. This implements |
|
| 942 |
/// |
|
| 947 |
/// This class describes the interface of alterable undirected |
|
| 948 |
/// graphs. It extends \ref AlterableDigraphComponent with the alteration |
|
| 949 |
/// notifier interface of undirected graphs. It implements |
|
| 950 |
/// an observer-notifier pattern for the edges. More |
|
| 943 | 951 |
/// obsevers can be registered into the notifier and whenever an |
| 944 |
/// alteration occured in the graph all the observers will |
|
| 952 |
/// alteration occured in the graph all the observers will be |
|
| 945 | 953 |
/// notified about it. |
| 946 | 954 |
template <typename BAS = BaseGraphComponent> |
| 947 | 955 |
class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
|
| 948 | 956 |
public: |
| 949 | 957 |
|
| 950 | 958 |
typedef BAS Base; |
| 951 | 959 |
typedef typename Base::Edge Edge; |
| 952 | 960 |
|
| 953 | 961 |
|
| 954 |
/// |
|
| 962 |
/// Edge alteration notifier class. |
|
| 955 | 963 |
typedef AlterationNotifier<AlterableGraphComponent, Edge> |
| 956 | 964 |
EdgeNotifier; |
| 957 | 965 |
|
| 958 |
/// \brief |
|
| 966 |
/// \brief Return the edge alteration notifier. |
|
| 959 | 967 |
/// |
| 960 |
/// |
|
| 968 |
/// This function gives back the edge alteration notifier. |
|
| 961 | 969 |
EdgeNotifier& notifier(Edge) const {
|
| 962 | 970 |
return EdgeNotifier(); |
| 963 | 971 |
} |
| 964 | 972 |
|
| 965 | 973 |
template <typename _Graph> |
| 966 | 974 |
struct Constraints {
|
| 967 | 975 |
void constraints() {
|
| 968 |
checkConcept< |
|
| 976 |
checkConcept<AlterableDigraphComponent<Base>, _Graph>(); |
|
| 969 | 977 |
typename _Graph::EdgeNotifier& uen |
| 970 | 978 |
= graph.notifier(typename _Graph::Edge()); |
| 971 | 979 |
ignore_unused_variable_warning(uen); |
| 972 | 980 |
} |
| 973 | 981 |
|
| 974 | 982 |
const _Graph& graph; |
| 975 | 983 |
}; |
| 976 | 984 |
}; |
| 977 | 985 |
|
| 978 |
/// \brief |
|
| 986 |
/// \brief Concept class for standard graph maps. |
|
| 979 | 987 |
/// |
| 980 |
/// This class describes the common interface of the graph maps |
|
| 981 |
/// (NodeMap, ArcMap), that is maps that can be used to |
|
| 982 |
/// |
|
| 988 |
/// This class describes the concept of standard graph maps, i.e. |
|
| 989 |
/// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and |
|
| 990 |
/// graph types, which can be used for associating data to graph items. |
|
| 991 |
/// The standard graph maps must conform to the ReferenceMap concept. |
|
| 983 | 992 |
template <typename GR, typename K, typename V> |
| 984 |
class GraphMap : public |
|
| 993 |
class GraphMap : public ReferenceMap<K, V, V&, const V&> {
|
|
| 985 | 994 |
public: |
| 986 | 995 |
|
| 987 | 996 |
typedef ReadWriteMap<K, V> Parent; |
| 988 | 997 |
|
| 989 | 998 |
/// The graph type of the map. |
| 990 | 999 |
typedef GR Graph; |
| 991 | 1000 |
/// The key type of the map. |
| 992 | 1001 |
typedef K Key; |
| 993 | 1002 |
/// The value type of the map. |
| 994 | 1003 |
typedef V Value; |
| 1004 |
/// The reference type of the map. |
|
| 1005 |
typedef Value& Reference; |
|
| 1006 |
/// The const reference type of the map. |
|
| 1007 |
typedef const Value& ConstReference; |
|
| 1008 |
|
|
| 1009 |
// The reference map tag. |
|
| 1010 |
typedef True ReferenceMapTag; |
|
| 995 | 1011 |
|
| 996 | 1012 |
/// \brief Construct a new map. |
| 997 | 1013 |
/// |
| 998 | 1014 |
/// Construct a new map for the graph. |
| 999 | 1015 |
explicit GraphMap(const Graph&) {}
|
| 1000 | 1016 |
/// \brief Construct a new map with default value. |
| 1001 | 1017 |
/// |
| 1002 |
/// Construct a new map for the graph and |
|
| 1018 |
/// Construct a new map for the graph and initalize the values. |
|
| 1003 | 1019 |
GraphMap(const Graph&, const Value&) {}
|
| 1004 | 1020 |
|
| 1005 | 1021 |
private: |
| 1006 | 1022 |
/// \brief Copy constructor. |
| 1007 | 1023 |
/// |
| 1008 | 1024 |
/// Copy Constructor. |
| 1009 | 1025 |
GraphMap(const GraphMap&) : Parent() {}
|
| 1010 | 1026 |
|
| 1011 |
/// \brief |
|
| 1027 |
/// \brief Assignment operator. |
|
| 1012 | 1028 |
/// |
| 1013 |
/// |
|
| 1029 |
/// Assignment operator. It does not mofify the underlying graph, |
|
| 1014 | 1030 |
/// it just iterates on the current item set and set the map |
| 1015 | 1031 |
/// with the value returned by the assigned map. |
| 1016 | 1032 |
template <typename CMap> |
| 1017 | 1033 |
GraphMap& operator=(const CMap&) {
|
| 1018 | 1034 |
checkConcept<ReadMap<Key, Value>, CMap>(); |
| 1019 | 1035 |
return *this; |
| 1020 | 1036 |
} |
| 1021 | 1037 |
|
| 1022 | 1038 |
public: |
| 1023 | 1039 |
template<typename _Map> |
| 1024 | 1040 |
struct Constraints {
|
| 1025 | 1041 |
void constraints() {
|
| 1026 |
checkConcept<ReadWriteMap<Key, Value>, _Map >(); |
|
| 1027 |
// Construction with a graph parameter |
|
| 1028 |
_Map a(g); |
|
| 1029 |
// Constructor with a graph and a default value parameter |
|
| 1030 |
_Map a2(g,t); |
|
| 1031 |
// Copy constructor. |
|
| 1032 |
|
|
| 1042 |
checkConcept |
|
| 1043 |
<ReferenceMap<Key, Value, Value&, const Value&>, _Map>(); |
|
| 1044 |
_Map m1(g); |
|
| 1045 |
_Map m2(g,t); |
|
| 1046 |
|
|
| 1047 |
// Copy constructor |
|
| 1048 |
// _Map m3(m); |
|
| 1033 | 1049 |
|
| 1050 |
// Assignment operator |
|
| 1034 | 1051 |
// ReadMap<Key, Value> cmap; |
| 1035 |
// |
|
| 1052 |
// m3 = cmap; |
|
| 1036 | 1053 |
|
| 1037 |
ignore_unused_variable_warning(a); |
|
| 1038 |
ignore_unused_variable_warning(a2); |
|
| 1039 |
|
|
| 1054 |
ignore_unused_variable_warning(m1); |
|
| 1055 |
ignore_unused_variable_warning(m2); |
|
| 1056 |
// ignore_unused_variable_warning(m3); |
|
| 1040 | 1057 |
} |
| 1041 | 1058 |
|
| 1042 |
const _Map & |
|
| 1059 |
const _Map &m; |
|
| 1043 | 1060 |
const Graph &g; |
| 1044 | 1061 |
const typename GraphMap::Value &t; |
| 1045 | 1062 |
}; |
| 1046 | 1063 |
|
| 1047 | 1064 |
}; |
| 1048 | 1065 |
|
| 1049 |
/// \brief |
|
| 1066 |
/// \brief Skeleton class for mappable directed graphs. |
|
| 1050 | 1067 |
/// |
| 1051 |
/// This class provides beside the core digraph features |
|
| 1052 |
/// map interface for the digraph structure. |
|
| 1068 |
/// This class describes the interface of mappable directed graphs. |
|
| 1069 |
/// It extends \ref BaseDigraphComponent with the standard digraph |
|
| 1070 |
/// map classes, namely \c NodeMap and \c ArcMap. |
|
| 1053 | 1071 |
/// This concept is part of the Digraph concept. |
| 1054 | 1072 |
template <typename BAS = BaseDigraphComponent> |
| 1055 | 1073 |
class MappableDigraphComponent : public BAS {
|
| 1056 | 1074 |
public: |
| 1057 | 1075 |
|
| 1058 | 1076 |
typedef BAS Base; |
| 1059 | 1077 |
typedef typename Base::Node Node; |
| 1060 | 1078 |
typedef typename Base::Arc Arc; |
| 1061 | 1079 |
|
| 1062 | 1080 |
typedef MappableDigraphComponent Digraph; |
| 1063 | 1081 |
|
| 1064 |
/// \brief |
|
| 1082 |
/// \brief Standard graph map for the nodes. |
|
| 1065 | 1083 |
/// |
| 1066 |
/// ReadWrite map of the nodes. |
|
| 1067 |
/// |
|
| 1084 |
/// Standard graph map for the nodes. |
|
| 1085 |
/// It conforms to the ReferenceMap concept. |
|
| 1068 | 1086 |
template <typename V> |
| 1069 |
class NodeMap : public GraphMap< |
|
| 1087 |
class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
|
|
| 1070 | 1088 |
public: |
| 1071 | 1089 |
typedef GraphMap<MappableDigraphComponent, Node, V> Parent; |
| 1072 | 1090 |
|
| 1073 | 1091 |
/// \brief Construct a new map. |
| 1074 | 1092 |
/// |
| 1075 | 1093 |
/// Construct a new map for the digraph. |
| 1076 | 1094 |
explicit NodeMap(const MappableDigraphComponent& digraph) |
| 1077 | 1095 |
: Parent(digraph) {}
|
| 1078 | 1096 |
|
| 1079 | 1097 |
/// \brief Construct a new map with default value. |
| 1080 | 1098 |
/// |
| 1081 |
/// Construct a new map for the digraph and |
|
| 1099 |
/// Construct a new map for the digraph and initalize the values. |
|
| 1082 | 1100 |
NodeMap(const MappableDigraphComponent& digraph, const V& value) |
| 1083 | 1101 |
: Parent(digraph, value) {}
|
| 1084 | 1102 |
|
| 1085 | 1103 |
private: |
| 1086 | 1104 |
/// \brief Copy constructor. |
| 1087 | 1105 |
/// |
| 1088 | 1106 |
/// Copy Constructor. |
| 1089 | 1107 |
NodeMap(const NodeMap& nm) : Parent(nm) {}
|
| 1090 | 1108 |
|
| 1091 |
/// \brief |
|
| 1109 |
/// \brief Assignment operator. |
|
| 1092 | 1110 |
/// |
| 1093 |
/// |
|
| 1111 |
/// Assignment operator. |
|
| 1094 | 1112 |
template <typename CMap> |
| 1095 | 1113 |
NodeMap& operator=(const CMap&) {
|
| 1096 | 1114 |
checkConcept<ReadMap<Node, V>, CMap>(); |
| 1097 | 1115 |
return *this; |
| 1098 | 1116 |
} |
| 1099 | 1117 |
|
| 1100 | 1118 |
}; |
| 1101 | 1119 |
|
| 1102 |
/// \brief |
|
| 1120 |
/// \brief Standard graph map for the arcs. |
|
| 1103 | 1121 |
/// |
| 1104 |
/// ReadWrite map of the arcs. |
|
| 1105 |
/// |
|
| 1122 |
/// Standard graph map for the arcs. |
|
| 1123 |
/// It conforms to the ReferenceMap concept. |
|
| 1106 | 1124 |
template <typename V> |
| 1107 |
class ArcMap : public GraphMap< |
|
| 1125 |
class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> {
|
|
| 1108 | 1126 |
public: |
| 1109 | 1127 |
typedef GraphMap<MappableDigraphComponent, Arc, V> Parent; |
| 1110 | 1128 |
|
| 1111 | 1129 |
/// \brief Construct a new map. |
| 1112 | 1130 |
/// |
| 1113 | 1131 |
/// Construct a new map for the digraph. |
| 1114 | 1132 |
explicit ArcMap(const MappableDigraphComponent& digraph) |
| 1115 | 1133 |
: Parent(digraph) {}
|
| 1116 | 1134 |
|
| 1117 | 1135 |
/// \brief Construct a new map with default value. |
| 1118 | 1136 |
/// |
| 1119 |
/// Construct a new map for the digraph and |
|
| 1137 |
/// Construct a new map for the digraph and initalize the values. |
|
| 1120 | 1138 |
ArcMap(const MappableDigraphComponent& digraph, const V& value) |
| 1121 | 1139 |
: Parent(digraph, value) {}
|
| 1122 | 1140 |
|
| 1123 | 1141 |
private: |
| 1124 | 1142 |
/// \brief Copy constructor. |
| 1125 | 1143 |
/// |
| 1126 | 1144 |
/// Copy Constructor. |
| 1127 | 1145 |
ArcMap(const ArcMap& nm) : Parent(nm) {}
|
| 1128 | 1146 |
|
| 1129 |
/// \brief |
|
| 1147 |
/// \brief Assignment operator. |
|
| 1130 | 1148 |
/// |
| 1131 |
/// |
|
| 1149 |
/// Assignment operator. |
|
| 1132 | 1150 |
template <typename CMap> |
| 1133 | 1151 |
ArcMap& operator=(const CMap&) {
|
| 1134 | 1152 |
checkConcept<ReadMap<Arc, V>, CMap>(); |
| 1135 | 1153 |
return *this; |
| 1136 | 1154 |
} |
| 1137 | 1155 |
|
| 1138 | 1156 |
}; |
| 1139 | 1157 |
|
| 1140 | 1158 |
|
| 1141 | 1159 |
template <typename _Digraph> |
| 1142 | 1160 |
struct Constraints {
|
| 1143 | 1161 |
|
| 1144 | 1162 |
struct Dummy {
|
| 1145 | 1163 |
int value; |
| 1146 | 1164 |
Dummy() : value(0) {}
|
| 1147 | 1165 |
Dummy(int _v) : value(_v) {}
|
| 1148 | 1166 |
}; |
| 1149 | 1167 |
|
| 1150 | 1168 |
void constraints() {
|
| 1151 | 1169 |
checkConcept<Base, _Digraph>(); |
| 1152 | 1170 |
{ // int map test
|
| 1153 | 1171 |
typedef typename _Digraph::template NodeMap<int> IntNodeMap; |
| 1154 | 1172 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>, |
| 1155 | 1173 |
IntNodeMap >(); |
| 1156 | 1174 |
} { // bool map test
|
| 1157 | 1175 |
typedef typename _Digraph::template NodeMap<bool> BoolNodeMap; |
| 1158 | 1176 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>, |
| 1159 | 1177 |
BoolNodeMap >(); |
| 1160 | 1178 |
} { // Dummy map test
|
| 1161 | 1179 |
typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap; |
| 1162 | 1180 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>, |
| 1163 | 1181 |
DummyNodeMap >(); |
| 1164 | 1182 |
} |
| 1165 | 1183 |
|
| 1166 | 1184 |
{ // int map test
|
| 1167 | 1185 |
typedef typename _Digraph::template ArcMap<int> IntArcMap; |
| 1168 | 1186 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>, |
| 1169 | 1187 |
IntArcMap >(); |
| 1170 | 1188 |
} { // bool map test
|
| 1171 | 1189 |
typedef typename _Digraph::template ArcMap<bool> BoolArcMap; |
| 1172 | 1190 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>, |
| 1173 | 1191 |
BoolArcMap >(); |
| 1174 | 1192 |
} { // Dummy map test
|
| 1175 | 1193 |
typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap; |
| 1176 | 1194 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>, |
| 1177 | 1195 |
DummyArcMap >(); |
| 1178 | 1196 |
} |
| 1179 | 1197 |
} |
| 1180 | 1198 |
|
| 1181 |
_Digraph& digraph; |
|
| 1199 |
const _Digraph& digraph; |
|
| 1182 | 1200 |
}; |
| 1183 | 1201 |
}; |
| 1184 | 1202 |
|
| 1185 |
/// \brief |
|
| 1203 |
/// \brief Skeleton class for mappable undirected graphs. |
|
| 1186 | 1204 |
/// |
| 1187 |
/// This class provides beside the core graph features |
|
| 1188 |
/// map interface for the graph structure. |
|
| 1205 |
/// This class describes the interface of mappable undirected graphs. |
|
| 1206 |
/// It extends \ref MappableDigraphComponent with the standard graph |
|
| 1207 |
/// map class for edges (\c EdgeMap). |
|
| 1189 | 1208 |
/// This concept is part of the Graph concept. |
| 1190 | 1209 |
template <typename BAS = BaseGraphComponent> |
| 1191 | 1210 |
class MappableGraphComponent : public MappableDigraphComponent<BAS> {
|
| 1192 | 1211 |
public: |
| 1193 | 1212 |
|
| 1194 | 1213 |
typedef BAS Base; |
| 1195 | 1214 |
typedef typename Base::Edge Edge; |
| 1196 | 1215 |
|
| 1197 | 1216 |
typedef MappableGraphComponent Graph; |
| 1198 | 1217 |
|
| 1199 |
/// \brief |
|
| 1218 |
/// \brief Standard graph map for the edges. |
|
| 1200 | 1219 |
/// |
| 1201 |
/// ReadWrite map of the edges. |
|
| 1202 |
/// |
|
| 1220 |
/// Standard graph map for the edges. |
|
| 1221 |
/// It conforms to the ReferenceMap concept. |
|
| 1203 | 1222 |
template <typename V> |
| 1204 |
class EdgeMap : public GraphMap< |
|
| 1223 |
class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> {
|
|
| 1205 | 1224 |
public: |
| 1206 | 1225 |
typedef GraphMap<MappableGraphComponent, Edge, V> Parent; |
| 1207 | 1226 |
|
| 1208 | 1227 |
/// \brief Construct a new map. |
| 1209 | 1228 |
/// |
| 1210 | 1229 |
/// Construct a new map for the graph. |
| 1211 | 1230 |
explicit EdgeMap(const MappableGraphComponent& graph) |
| 1212 | 1231 |
: Parent(graph) {}
|
| 1213 | 1232 |
|
| 1214 | 1233 |
/// \brief Construct a new map with default value. |
| 1215 | 1234 |
/// |
| 1216 |
/// Construct a new map for the graph and |
|
| 1235 |
/// Construct a new map for the graph and initalize the values. |
|
| 1217 | 1236 |
EdgeMap(const MappableGraphComponent& graph, const V& value) |
| 1218 | 1237 |
: Parent(graph, value) {}
|
| 1219 | 1238 |
|
| 1220 | 1239 |
private: |
| 1221 | 1240 |
/// \brief Copy constructor. |
| 1222 | 1241 |
/// |
| 1223 | 1242 |
/// Copy Constructor. |
| 1224 | 1243 |
EdgeMap(const EdgeMap& nm) : Parent(nm) {}
|
| 1225 | 1244 |
|
| 1226 |
/// \brief |
|
| 1245 |
/// \brief Assignment operator. |
|
| 1227 | 1246 |
/// |
| 1228 |
/// |
|
| 1247 |
/// Assignment operator. |
|
| 1229 | 1248 |
template <typename CMap> |
| 1230 | 1249 |
EdgeMap& operator=(const CMap&) {
|
| 1231 | 1250 |
checkConcept<ReadMap<Edge, V>, CMap>(); |
| 1232 | 1251 |
return *this; |
| 1233 | 1252 |
} |
| 1234 | 1253 |
|
| 1235 | 1254 |
}; |
| 1236 | 1255 |
|
| 1237 | 1256 |
|
| 1238 | 1257 |
template <typename _Graph> |
| 1239 | 1258 |
struct Constraints {
|
| 1240 | 1259 |
|
| 1241 | 1260 |
struct Dummy {
|
| 1242 | 1261 |
int value; |
| 1243 | 1262 |
Dummy() : value(0) {}
|
| 1244 | 1263 |
Dummy(int _v) : value(_v) {}
|
| 1245 | 1264 |
}; |
| 1246 | 1265 |
|
| 1247 | 1266 |
void constraints() {
|
| 1248 |
checkConcept< |
|
| 1267 |
checkConcept<MappableDigraphComponent<Base>, _Graph>(); |
|
| 1249 | 1268 |
|
| 1250 | 1269 |
{ // int map test
|
| 1251 | 1270 |
typedef typename _Graph::template EdgeMap<int> IntEdgeMap; |
| 1252 | 1271 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, |
| 1253 | 1272 |
IntEdgeMap >(); |
| 1254 | 1273 |
} { // bool map test
|
| 1255 | 1274 |
typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap; |
| 1256 | 1275 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, |
| 1257 | 1276 |
BoolEdgeMap >(); |
| 1258 | 1277 |
} { // Dummy map test
|
| 1259 | 1278 |
typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap; |
| 1260 | 1279 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>, |
| 1261 | 1280 |
DummyEdgeMap >(); |
| 1262 | 1281 |
} |
| 1263 | 1282 |
} |
| 1264 | 1283 |
|
| 1265 |
_Graph& graph; |
|
| 1284 |
const _Graph& graph; |
|
| 1266 | 1285 |
}; |
| 1267 | 1286 |
}; |
| 1268 | 1287 |
|
| 1269 |
/// \brief |
|
| 1288 |
/// \brief Skeleton class for extendable directed graphs. |
|
| 1270 | 1289 |
/// |
| 1271 |
/// This class provides beside the core digraph features digraph |
|
| 1272 |
/// extendable interface for the digraph structure. The main |
|
| 1273 |
/// difference between the base and this interface is that the |
|
| 1274 |
/// digraph alterations should handled already on this level. |
|
| 1290 |
/// This class describes the interface of extendable directed graphs. |
|
| 1291 |
/// It extends \ref BaseDigraphComponent with functions for adding |
|
| 1292 |
/// nodes and arcs to the digraph. |
|
| 1293 |
/// This concept requires \ref AlterableDigraphComponent. |
|
| 1275 | 1294 |
template <typename BAS = BaseDigraphComponent> |
| 1276 | 1295 |
class ExtendableDigraphComponent : public BAS {
|
| 1277 | 1296 |
public: |
| 1278 | 1297 |
typedef BAS Base; |
| 1279 | 1298 |
|
| 1280 | 1299 |
typedef typename Base::Node Node; |
| 1281 | 1300 |
typedef typename Base::Arc Arc; |
| 1282 | 1301 |
|
| 1283 |
/// \brief |
|
| 1302 |
/// \brief Add a new node to the digraph. |
|
| 1284 | 1303 |
/// |
| 1285 |
/// Adds a new node to the digraph. |
|
| 1286 |
/// |
|
| 1304 |
/// This function adds a new node to the digraph. |
|
| 1287 | 1305 |
Node addNode() {
|
| 1288 | 1306 |
return INVALID; |
| 1289 | 1307 |
} |
| 1290 | 1308 |
|
| 1291 |
/// \brief |
|
| 1309 |
/// \brief Add a new arc connecting the given two nodes. |
|
| 1292 | 1310 |
/// |
| 1293 |
/// |
|
| 1311 |
/// This function adds a new arc connecting the given two nodes |
|
| 1312 |
/// of the digraph. |
|
| 1294 | 1313 |
Arc addArc(const Node&, const Node&) {
|
| 1295 | 1314 |
return INVALID; |
| 1296 | 1315 |
} |
| 1297 | 1316 |
|
| 1298 | 1317 |
template <typename _Digraph> |
| 1299 | 1318 |
struct Constraints {
|
| 1300 | 1319 |
void constraints() {
|
| 1301 | 1320 |
checkConcept<Base, _Digraph>(); |
| 1302 | 1321 |
typename _Digraph::Node node_a, node_b; |
| 1303 | 1322 |
node_a = digraph.addNode(); |
| 1304 | 1323 |
node_b = digraph.addNode(); |
| 1305 | 1324 |
typename _Digraph::Arc arc; |
| 1306 | 1325 |
arc = digraph.addArc(node_a, node_b); |
| 1307 | 1326 |
} |
| 1308 | 1327 |
|
| 1309 | 1328 |
_Digraph& digraph; |
| 1310 | 1329 |
}; |
| 1311 | 1330 |
}; |
| 1312 | 1331 |
|
| 1313 |
/// \brief |
|
| 1332 |
/// \brief Skeleton class for extendable undirected graphs. |
|
| 1314 | 1333 |
/// |
| 1315 |
/// This class provides beside the core undirected graph features |
|
| 1316 |
/// core undircted graph extend interface for the graph structure. |
|
| 1317 |
/// The main difference between the base and this interface is |
|
| 1318 |
/// that the graph alterations should handled already on this |
|
| 1319 |
/// |
|
| 1334 |
/// This class describes the interface of extendable undirected graphs. |
|
| 1335 |
/// It extends \ref BaseGraphComponent with functions for adding |
|
| 1336 |
/// nodes and edges to the graph. |
|
| 1337 |
/// This concept requires \ref AlterableGraphComponent. |
|
| 1320 | 1338 |
template <typename BAS = BaseGraphComponent> |
| 1321 | 1339 |
class ExtendableGraphComponent : public BAS {
|
| 1322 | 1340 |
public: |
| 1323 | 1341 |
|
| 1324 | 1342 |
typedef BAS Base; |
| 1325 | 1343 |
typedef typename Base::Node Node; |
| 1326 | 1344 |
typedef typename Base::Edge Edge; |
| 1327 | 1345 |
|
| 1328 |
/// \brief |
|
| 1346 |
/// \brief Add a new node to the digraph. |
|
| 1329 | 1347 |
/// |
| 1330 |
/// Adds a new node to the graph. |
|
| 1331 |
/// |
|
| 1348 |
/// This function adds a new node to the digraph. |
|
| 1332 | 1349 |
Node addNode() {
|
| 1333 | 1350 |
return INVALID; |
| 1334 | 1351 |
} |
| 1335 | 1352 |
|
| 1336 |
/// \brief |
|
| 1353 |
/// \brief Add a new edge connecting the given two nodes. |
|
| 1337 | 1354 |
/// |
| 1338 |
/// Adds a new arc connects the the given two nodes. |
|
| 1339 |
Edge addArc(const Node&, const Node&) {
|
|
| 1355 |
/// This function adds a new edge connecting the given two nodes |
|
| 1356 |
/// of the graph. |
|
| 1357 |
Edge addEdge(const Node&, const Node&) {
|
|
| 1340 | 1358 |
return INVALID; |
| 1341 | 1359 |
} |
| 1342 | 1360 |
|
| 1343 | 1361 |
template <typename _Graph> |
| 1344 | 1362 |
struct Constraints {
|
| 1345 | 1363 |
void constraints() {
|
| 1346 | 1364 |
checkConcept<Base, _Graph>(); |
| 1347 | 1365 |
typename _Graph::Node node_a, node_b; |
| 1348 | 1366 |
node_a = graph.addNode(); |
| 1349 | 1367 |
node_b = graph.addNode(); |
| 1350 | 1368 |
typename _Graph::Edge edge; |
| 1351 | 1369 |
edge = graph.addEdge(node_a, node_b); |
| 1352 | 1370 |
} |
| 1353 | 1371 |
|
| 1354 | 1372 |
_Graph& graph; |
| 1355 | 1373 |
}; |
| 1356 | 1374 |
}; |
| 1357 | 1375 |
|
| 1358 |
/// \brief |
|
| 1376 |
/// \brief Skeleton class for erasable directed graphs. |
|
| 1359 | 1377 |
/// |
| 1360 |
/// This class provides beside the core digraph features core erase |
|
| 1361 |
/// functions for the digraph structure. The main difference between |
|
| 1362 |
/// the base and this interface is that the digraph alterations |
|
| 1363 |
/// should handled already on this level. |
|
| 1378 |
/// This class describes the interface of erasable directed graphs. |
|
| 1379 |
/// It extends \ref BaseDigraphComponent with functions for removing |
|
| 1380 |
/// nodes and arcs from the digraph. |
|
| 1381 |
/// This concept requires \ref AlterableDigraphComponent. |
|
| 1364 | 1382 |
template <typename BAS = BaseDigraphComponent> |
| 1365 | 1383 |
class ErasableDigraphComponent : public BAS {
|
| 1366 | 1384 |
public: |
| 1367 | 1385 |
|
| 1368 | 1386 |
typedef BAS Base; |
| 1369 | 1387 |
typedef typename Base::Node Node; |
| 1370 | 1388 |
typedef typename Base::Arc Arc; |
| 1371 | 1389 |
|
| 1372 | 1390 |
/// \brief Erase a node from the digraph. |
| 1373 | 1391 |
/// |
| 1374 |
/// Erase a node from the digraph. This function should |
|
| 1375 |
/// erase all arcs connecting to the node. |
|
| 1392 |
/// This function erases the given node from the digraph and all arcs |
|
| 1393 |
/// connected to the node. |
|
| 1376 | 1394 |
void erase(const Node&) {}
|
| 1377 | 1395 |
|
| 1378 | 1396 |
/// \brief Erase an arc from the digraph. |
| 1379 | 1397 |
/// |
| 1380 |
/// Erase an arc from the digraph. |
|
| 1381 |
/// |
|
| 1398 |
/// This function erases the given arc from the digraph. |
|
| 1382 | 1399 |
void erase(const Arc&) {}
|
| 1383 | 1400 |
|
| 1384 | 1401 |
template <typename _Digraph> |
| 1385 | 1402 |
struct Constraints {
|
| 1386 | 1403 |
void constraints() {
|
| 1387 | 1404 |
checkConcept<Base, _Digraph>(); |
| 1388 |
typename _Digraph::Node node; |
|
| 1405 |
const typename _Digraph::Node node(INVALID); |
|
| 1389 | 1406 |
digraph.erase(node); |
| 1390 |
typename _Digraph::Arc arc; |
|
| 1407 |
const typename _Digraph::Arc arc(INVALID); |
|
| 1391 | 1408 |
digraph.erase(arc); |
| 1392 | 1409 |
} |
| 1393 | 1410 |
|
| 1394 | 1411 |
_Digraph& digraph; |
| 1395 | 1412 |
}; |
| 1396 | 1413 |
}; |
| 1397 | 1414 |
|
| 1398 |
/// \brief |
|
| 1415 |
/// \brief Skeleton class for erasable undirected graphs. |
|
| 1399 | 1416 |
/// |
| 1400 |
/// This class provides beside the core undirected graph features |
|
| 1401 |
/// core erase functions for the undirceted graph structure. The |
|
| 1402 |
/// main difference between the base and this interface is that |
|
| 1403 |
/// the graph alterations should handled already on this level. |
|
| 1417 |
/// This class describes the interface of erasable undirected graphs. |
|
| 1418 |
/// It extends \ref BaseGraphComponent with functions for removing |
|
| 1419 |
/// nodes and edges from the graph. |
|
| 1420 |
/// This concept requires \ref AlterableGraphComponent. |
|
| 1404 | 1421 |
template <typename BAS = BaseGraphComponent> |
| 1405 | 1422 |
class ErasableGraphComponent : public BAS {
|
| 1406 | 1423 |
public: |
| 1407 | 1424 |
|
| 1408 | 1425 |
typedef BAS Base; |
| 1409 | 1426 |
typedef typename Base::Node Node; |
| 1410 | 1427 |
typedef typename Base::Edge Edge; |
| 1411 | 1428 |
|
| 1412 | 1429 |
/// \brief Erase a node from the graph. |
| 1413 | 1430 |
/// |
| 1414 |
/// Erase a node from the graph. This function should erase |
|
| 1415 |
/// arcs connecting to the node. |
|
| 1431 |
/// This function erases the given node from the graph and all edges |
|
| 1432 |
/// connected to the node. |
|
| 1416 | 1433 |
void erase(const Node&) {}
|
| 1417 | 1434 |
|
| 1418 |
/// \brief Erase an |
|
| 1435 |
/// \brief Erase an edge from the digraph. |
|
| 1419 | 1436 |
/// |
| 1420 |
/// Erase an arc from the graph. |
|
| 1421 |
/// |
|
| 1437 |
/// This function erases the given edge from the digraph. |
|
| 1422 | 1438 |
void erase(const Edge&) {}
|
| 1423 | 1439 |
|
| 1424 | 1440 |
template <typename _Graph> |
| 1425 | 1441 |
struct Constraints {
|
| 1426 | 1442 |
void constraints() {
|
| 1427 | 1443 |
checkConcept<Base, _Graph>(); |
| 1428 |
typename _Graph::Node node; |
|
| 1444 |
const typename _Graph::Node node(INVALID); |
|
| 1429 | 1445 |
graph.erase(node); |
| 1430 |
typename _Graph::Edge edge; |
|
| 1446 |
const typename _Graph::Edge edge(INVALID); |
|
| 1431 | 1447 |
graph.erase(edge); |
| 1432 | 1448 |
} |
| 1433 | 1449 |
|
| 1434 | 1450 |
_Graph& graph; |
| 1435 | 1451 |
}; |
| 1436 | 1452 |
}; |
| 1437 | 1453 |
|
| 1438 |
/// \brief |
|
| 1454 |
/// \brief Skeleton class for clearable directed graphs. |
|
| 1439 | 1455 |
/// |
| 1440 |
/// This class provides beside the core digraph features core clear |
|
| 1441 |
/// functions for the digraph structure. The main difference between |
|
| 1442 |
/// the base and this interface is that the digraph alterations |
|
| 1443 |
/// should handled already on this level. |
|
| 1456 |
/// This class describes the interface of clearable directed graphs. |
|
| 1457 |
/// It extends \ref BaseDigraphComponent with a function for clearing |
|
| 1458 |
/// the digraph. |
|
| 1459 |
/// This concept requires \ref AlterableDigraphComponent. |
|
| 1444 | 1460 |
template <typename BAS = BaseDigraphComponent> |
| 1445 | 1461 |
class ClearableDigraphComponent : public BAS {
|
| 1446 | 1462 |
public: |
| 1447 | 1463 |
|
| 1448 | 1464 |
typedef BAS Base; |
| 1449 | 1465 |
|
| 1450 | 1466 |
/// \brief Erase all nodes and arcs from the digraph. |
| 1451 | 1467 |
/// |
| 1452 |
/// Erase all nodes and arcs from the digraph. |
|
| 1453 |
/// |
|
| 1468 |
/// This function erases all nodes and arcs from the digraph. |
|
| 1454 | 1469 |
void clear() {}
|
| 1455 | 1470 |
|
| 1456 | 1471 |
template <typename _Digraph> |
| 1457 | 1472 |
struct Constraints {
|
| 1458 | 1473 |
void constraints() {
|
| 1459 | 1474 |
checkConcept<Base, _Digraph>(); |
| 1460 | 1475 |
digraph.clear(); |
| 1461 | 1476 |
} |
| 1462 | 1477 |
|
| 1463 |
_Digraph digraph; |
|
| 1478 |
_Digraph& digraph; |
|
| 1464 | 1479 |
}; |
| 1465 | 1480 |
}; |
| 1466 | 1481 |
|
| 1467 |
/// \brief |
|
| 1482 |
/// \brief Skeleton class for clearable undirected graphs. |
|
| 1468 | 1483 |
/// |
| 1469 |
/// This class provides beside the core undirected graph features |
|
| 1470 |
/// core clear functions for the undirected graph structure. The |
|
| 1471 |
/// main difference between the base and this interface is that |
|
| 1472 |
/// the graph alterations should handled already on this level. |
|
| 1484 |
/// This class describes the interface of clearable undirected graphs. |
|
| 1485 |
/// It extends \ref BaseGraphComponent with a function for clearing |
|
| 1486 |
/// the graph. |
|
| 1487 |
/// This concept requires \ref AlterableGraphComponent. |
|
| 1473 | 1488 |
template <typename BAS = BaseGraphComponent> |
| 1474 | 1489 |
class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
|
| 1475 | 1490 |
public: |
| 1476 | 1491 |
|
| 1477 | 1492 |
typedef BAS Base; |
| 1478 | 1493 |
|
| 1494 |
/// \brief Erase all nodes and edges from the graph. |
|
| 1495 |
/// |
|
| 1496 |
/// This function erases all nodes and edges from the graph. |
|
| 1497 |
void clear() {}
|
|
| 1498 |
|
|
| 1479 | 1499 |
template <typename _Graph> |
| 1480 | 1500 |
struct Constraints {
|
| 1481 | 1501 |
void constraints() {
|
| 1482 |
checkConcept< |
|
| 1502 |
checkConcept<Base, _Graph>(); |
|
| 1503 |
graph.clear(); |
|
| 1483 | 1504 |
} |
| 1484 | 1505 |
|
| 1485 |
_Graph graph; |
|
| 1506 |
_Graph& graph; |
|
| 1486 | 1507 |
}; |
| 1487 | 1508 |
}; |
| 1488 | 1509 |
|
| 1489 | 1510 |
} |
| 1490 | 1511 |
|
| 1491 | 1512 |
} |
| 1492 | 1513 |
|
| 1493 | 1514 |
#endif |
| ... | ... |
@@ -26,99 +26,99 @@ |
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/concept_check.h> |
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
namespace concepts {
|
| 32 | 32 |
|
| 33 | 33 |
/// \addtogroup concept |
| 34 | 34 |
/// @{
|
| 35 | 35 |
|
| 36 | 36 |
/// \brief The heap concept. |
| 37 | 37 |
/// |
| 38 | 38 |
/// Concept class describing the main interface of heaps. A \e heap |
| 39 | 39 |
/// is a data structure for storing items with specified values called |
| 40 | 40 |
/// \e priorities in such a way that finding the item with minimum |
| 41 | 41 |
/// priority is efficient. In a heap one can change the priority of an |
| 42 | 42 |
/// item, add or erase an item, etc. |
| 43 | 43 |
/// |
| 44 | 44 |
/// \tparam PR Type of the priority of the items. |
| 45 | 45 |
/// \tparam IM A read and writable item map with int values, used |
| 46 | 46 |
/// internally to handle the cross references. |
| 47 | 47 |
/// \tparam Comp A functor class for the ordering of the priorities. |
| 48 | 48 |
/// The default is \c std::less<PR>. |
| 49 | 49 |
#ifdef DOXYGEN |
| 50 | 50 |
template <typename PR, typename IM, typename Comp = std::less<PR> > |
| 51 | 51 |
#else |
| 52 | 52 |
template <typename PR, typename IM> |
| 53 | 53 |
#endif |
| 54 | 54 |
class Heap {
|
| 55 | 55 |
public: |
| 56 | 56 |
|
| 57 | 57 |
/// Type of the item-int map. |
| 58 | 58 |
typedef IM ItemIntMap; |
| 59 | 59 |
/// Type of the priorities. |
| 60 | 60 |
typedef PR Prio; |
| 61 | 61 |
/// Type of the items stored in the heap. |
| 62 | 62 |
typedef typename ItemIntMap::Key Item; |
| 63 | 63 |
|
| 64 | 64 |
/// \brief Type to represent the states of the items. |
| 65 | 65 |
/// |
| 66 | 66 |
/// Each item has a state associated to it. It can be "in heap", |
| 67 | 67 |
/// "pre heap" or "post heap". The later two are indifferent |
| 68 | 68 |
/// from the point of view of the heap, but may be useful for |
| 69 | 69 |
/// the user. |
| 70 | 70 |
/// |
| 71 | 71 |
/// The item-int map must be initialized in such way that it assigns |
| 72 | 72 |
/// \c PRE_HEAP (<tt>-1</tt>) to any element to be put in the heap. |
| 73 | 73 |
enum State {
|
| 74 |
IN_HEAP = 0, ///< The "in heap" state constant. |
|
| 75 |
PRE_HEAP = -1, ///< The "pre heap" state constant. |
|
| 76 |
|
|
| 74 |
IN_HEAP = 0, ///< = 0. The "in heap" state constant. |
|
| 75 |
PRE_HEAP = -1, ///< = -1. The "pre heap" state constant. |
|
| 76 |
POST_HEAP = -2 ///< = -2. The "post heap" state constant. |
|
| 77 | 77 |
}; |
| 78 | 78 |
|
| 79 | 79 |
/// \brief The constructor. |
| 80 | 80 |
/// |
| 81 | 81 |
/// The constructor. |
| 82 | 82 |
/// \param map A map that assigns \c int values to keys of type |
| 83 | 83 |
/// \c Item. It is used internally by the heap implementations to |
| 84 | 84 |
/// handle the cross references. The assigned value must be |
| 85 | 85 |
/// \c PRE_HEAP (<tt>-1</tt>) for every item. |
| 86 | 86 |
explicit Heap(ItemIntMap &map) {}
|
| 87 | 87 |
|
| 88 | 88 |
/// \brief The number of items stored in the heap. |
| 89 | 89 |
/// |
| 90 | 90 |
/// Returns the number of items stored in the heap. |
| 91 | 91 |
int size() const { return 0; }
|
| 92 | 92 |
|
| 93 | 93 |
/// \brief Checks if the heap is empty. |
| 94 | 94 |
/// |
| 95 | 95 |
/// Returns \c true if the heap is empty. |
| 96 | 96 |
bool empty() const { return false; }
|
| 97 | 97 |
|
| 98 | 98 |
/// \brief Makes the heap empty. |
| 99 | 99 |
/// |
| 100 | 100 |
/// Makes the heap empty. |
| 101 | 101 |
void clear(); |
| 102 | 102 |
|
| 103 | 103 |
/// \brief Inserts an item into the heap with the given priority. |
| 104 | 104 |
/// |
| 105 | 105 |
/// Inserts the given item into the heap with the given priority. |
| 106 | 106 |
/// \param i The item to insert. |
| 107 | 107 |
/// \param p The priority of the item. |
| 108 | 108 |
void push(const Item &i, const Prio &p) {}
|
| 109 | 109 |
|
| 110 | 110 |
/// \brief Returns the item having minimum priority. |
| 111 | 111 |
/// |
| 112 | 112 |
/// Returns the item having minimum priority. |
| 113 | 113 |
/// \pre The heap must be non-empty. |
| 114 | 114 |
Item top() const {}
|
| 115 | 115 |
|
| 116 | 116 |
/// \brief The minimum priority. |
| 117 | 117 |
/// |
| 118 | 118 |
/// Returns the minimum priority. |
| 119 | 119 |
/// \pre The heap must be non-empty. |
| 120 | 120 |
Prio prio() const {}
|
| 121 | 121 |
|
| 122 | 122 |
/// \brief Removes the item having minimum priority. |
| 123 | 123 |
/// |
| 124 | 124 |
/// Removes the item having minimum priority. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_CONNECTIVITY_H |
| 20 | 20 |
#define LEMON_CONNECTIVITY_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/dfs.h> |
| 23 | 23 |
#include <lemon/bfs.h> |
| 24 | 24 |
#include <lemon/core.h> |
| 25 | 25 |
#include <lemon/maps.h> |
| 26 | 26 |
#include <lemon/adaptors.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/concepts/digraph.h> |
| 29 | 29 |
#include <lemon/concepts/graph.h> |
| 30 | 30 |
#include <lemon/concept_check.h> |
| 31 | 31 |
|
| 32 | 32 |
#include <stack> |
| 33 | 33 |
#include <functional> |
| 34 | 34 |
|
| 35 |
/// \ingroup |
|
| 35 |
/// \ingroup graph_properties |
|
| 36 | 36 |
/// \file |
| 37 | 37 |
/// \brief Connectivity algorithms |
| 38 | 38 |
/// |
| 39 | 39 |
/// Connectivity algorithms |
| 40 | 40 |
|
| 41 | 41 |
namespace lemon {
|
| 42 | 42 |
|
| 43 |
/// \ingroup |
|
| 43 |
/// \ingroup graph_properties |
|
| 44 | 44 |
/// |
| 45 | 45 |
/// \brief Check whether the given undirected graph is connected. |
| 46 | 46 |
/// |
| 47 | 47 |
/// Check whether the given undirected graph is connected. |
| 48 | 48 |
/// \param graph The undirected graph. |
| 49 | 49 |
/// \return \c true when there is path between any two nodes in the graph. |
| 50 | 50 |
/// \note By definition, the empty graph is connected. |
| 51 | 51 |
template <typename Graph> |
| 52 | 52 |
bool connected(const Graph& graph) {
|
| 53 | 53 |
checkConcept<concepts::Graph, Graph>(); |
| 54 | 54 |
typedef typename Graph::NodeIt NodeIt; |
| 55 | 55 |
if (NodeIt(graph) == INVALID) return true; |
| 56 | 56 |
Dfs<Graph> dfs(graph); |
| 57 | 57 |
dfs.run(NodeIt(graph)); |
| 58 | 58 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 59 | 59 |
if (!dfs.reached(it)) {
|
| 60 | 60 |
return false; |
| 61 | 61 |
} |
| 62 | 62 |
} |
| 63 | 63 |
return true; |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 |
/// \ingroup |
|
| 66 |
/// \ingroup graph_properties |
|
| 67 | 67 |
/// |
| 68 | 68 |
/// \brief Count the number of connected components of an undirected graph |
| 69 | 69 |
/// |
| 70 | 70 |
/// Count the number of connected components of an undirected graph |
| 71 | 71 |
/// |
| 72 | 72 |
/// \param graph The graph. It must be undirected. |
| 73 | 73 |
/// \return The number of components |
| 74 | 74 |
/// \note By definition, the empty graph consists |
| 75 | 75 |
/// of zero connected components. |
| 76 | 76 |
template <typename Graph> |
| 77 | 77 |
int countConnectedComponents(const Graph &graph) {
|
| 78 | 78 |
checkConcept<concepts::Graph, Graph>(); |
| 79 | 79 |
typedef typename Graph::Node Node; |
| 80 | 80 |
typedef typename Graph::Arc Arc; |
| 81 | 81 |
|
| 82 | 82 |
typedef NullMap<Node, Arc> PredMap; |
| 83 | 83 |
typedef NullMap<Node, int> DistMap; |
| 84 | 84 |
|
| 85 | 85 |
int compNum = 0; |
| 86 | 86 |
typename Bfs<Graph>:: |
| 87 | 87 |
template SetPredMap<PredMap>:: |
| 88 | 88 |
template SetDistMap<DistMap>:: |
| 89 | 89 |
Create bfs(graph); |
| 90 | 90 |
|
| 91 | 91 |
PredMap predMap; |
| 92 | 92 |
bfs.predMap(predMap); |
| 93 | 93 |
|
| 94 | 94 |
DistMap distMap; |
| 95 | 95 |
bfs.distMap(distMap); |
| 96 | 96 |
|
| 97 | 97 |
bfs.init(); |
| 98 | 98 |
for(typename Graph::NodeIt n(graph); n != INVALID; ++n) {
|
| 99 | 99 |
if (!bfs.reached(n)) {
|
| 100 | 100 |
bfs.addSource(n); |
| 101 | 101 |
bfs.start(); |
| 102 | 102 |
++compNum; |
| 103 | 103 |
} |
| 104 | 104 |
} |
| 105 | 105 |
return compNum; |
| 106 | 106 |
} |
| 107 | 107 |
|
| 108 |
/// \ingroup |
|
| 108 |
/// \ingroup graph_properties |
|
| 109 | 109 |
/// |
| 110 | 110 |
/// \brief Find the connected components of an undirected graph |
| 111 | 111 |
/// |
| 112 | 112 |
/// Find the connected components of an undirected graph. |
| 113 | 113 |
/// |
| 114 |
/// \image html connected_components.png |
|
| 115 |
/// \image latex connected_components.eps "Connected components" width=\textwidth |
|
| 116 |
/// |
|
| 114 | 117 |
/// \param graph The graph. It must be undirected. |
| 115 | 118 |
/// \retval compMap A writable node map. The values will be set from 0 to |
| 116 | 119 |
/// the number of the connected components minus one. Each values of the map |
| 117 | 120 |
/// will be set exactly once, the values of a certain component will be |
| 118 | 121 |
/// set continuously. |
| 119 | 122 |
/// \return The number of components |
| 120 |
/// |
|
| 121 | 123 |
template <class Graph, class NodeMap> |
| 122 | 124 |
int connectedComponents(const Graph &graph, NodeMap &compMap) {
|
| 123 | 125 |
checkConcept<concepts::Graph, Graph>(); |
| 124 | 126 |
typedef typename Graph::Node Node; |
| 125 | 127 |
typedef typename Graph::Arc Arc; |
| 126 | 128 |
checkConcept<concepts::WriteMap<Node, int>, NodeMap>(); |
| 127 | 129 |
|
| 128 | 130 |
typedef NullMap<Node, Arc> PredMap; |
| 129 | 131 |
typedef NullMap<Node, int> DistMap; |
| 130 | 132 |
|
| 131 | 133 |
int compNum = 0; |
| 132 | 134 |
typename Bfs<Graph>:: |
| 133 | 135 |
template SetPredMap<PredMap>:: |
| 134 | 136 |
template SetDistMap<DistMap>:: |
| 135 | 137 |
Create bfs(graph); |
| 136 | 138 |
|
| 137 | 139 |
PredMap predMap; |
| 138 | 140 |
bfs.predMap(predMap); |
| 139 | 141 |
|
| 140 | 142 |
DistMap distMap; |
| 141 | 143 |
bfs.distMap(distMap); |
| 142 | 144 |
|
| 143 | 145 |
bfs.init(); |
| 144 | 146 |
for(typename Graph::NodeIt n(graph); n != INVALID; ++n) {
|
| 145 | 147 |
if(!bfs.reached(n)) {
|
| 146 | 148 |
bfs.addSource(n); |
| 147 | 149 |
while (!bfs.emptyQueue()) {
|
| 148 | 150 |
compMap.set(bfs.nextNode(), compNum); |
| 149 | 151 |
bfs.processNextNode(); |
| 150 | 152 |
} |
| 151 | 153 |
++compNum; |
| 152 | 154 |
} |
| 153 | 155 |
} |
| 154 | 156 |
return compNum; |
| 155 | 157 |
} |
| 156 | 158 |
|
| 157 | 159 |
namespace _connectivity_bits {
|
| 158 | 160 |
|
| 159 | 161 |
template <typename Digraph, typename Iterator > |
| 160 | 162 |
struct LeaveOrderVisitor : public DfsVisitor<Digraph> {
|
| 161 | 163 |
public: |
| 162 | 164 |
typedef typename Digraph::Node Node; |
| 163 | 165 |
LeaveOrderVisitor(Iterator it) : _it(it) {}
|
| 164 | 166 |
|
| 165 | 167 |
void leave(const Node& node) {
|
| 166 | 168 |
*(_it++) = node; |
| 167 | 169 |
} |
| 168 | 170 |
|
| ... | ... |
@@ -182,286 +184,288 @@ |
| 182 | 184 |
void reach(const Node& node) {
|
| 183 | 185 |
_map.set(node, _value); |
| 184 | 186 |
} |
| 185 | 187 |
private: |
| 186 | 188 |
Map& _map; |
| 187 | 189 |
Value& _value; |
| 188 | 190 |
}; |
| 189 | 191 |
|
| 190 | 192 |
template <typename Digraph, typename ArcMap> |
| 191 | 193 |
struct StronglyConnectedCutArcsVisitor : public DfsVisitor<Digraph> {
|
| 192 | 194 |
public: |
| 193 | 195 |
typedef typename Digraph::Node Node; |
| 194 | 196 |
typedef typename Digraph::Arc Arc; |
| 195 | 197 |
|
| 196 | 198 |
StronglyConnectedCutArcsVisitor(const Digraph& digraph, |
| 197 | 199 |
ArcMap& cutMap, |
| 198 | 200 |
int& cutNum) |
| 199 | 201 |
: _digraph(digraph), _cutMap(cutMap), _cutNum(cutNum), |
| 200 | 202 |
_compMap(digraph, -1), _num(-1) {
|
| 201 | 203 |
} |
| 202 | 204 |
|
| 203 | 205 |
void start(const Node&) {
|
| 204 | 206 |
++_num; |
| 205 | 207 |
} |
| 206 | 208 |
|
| 207 | 209 |
void reach(const Node& node) {
|
| 208 | 210 |
_compMap.set(node, _num); |
| 209 | 211 |
} |
| 210 | 212 |
|
| 211 | 213 |
void examine(const Arc& arc) {
|
| 212 | 214 |
if (_compMap[_digraph.source(arc)] != |
| 213 | 215 |
_compMap[_digraph.target(arc)]) {
|
| 214 | 216 |
_cutMap.set(arc, true); |
| 215 | 217 |
++_cutNum; |
| 216 | 218 |
} |
| 217 | 219 |
} |
| 218 | 220 |
private: |
| 219 | 221 |
const Digraph& _digraph; |
| 220 | 222 |
ArcMap& _cutMap; |
| 221 | 223 |
int& _cutNum; |
| 222 | 224 |
|
| 223 | 225 |
typename Digraph::template NodeMap<int> _compMap; |
| 224 | 226 |
int _num; |
| 225 | 227 |
}; |
| 226 | 228 |
|
| 227 | 229 |
} |
| 228 | 230 |
|
| 229 | 231 |
|
| 230 |
/// \ingroup |
|
| 232 |
/// \ingroup graph_properties |
|
| 231 | 233 |
/// |
| 232 | 234 |
/// \brief Check whether the given directed graph is strongly connected. |
| 233 | 235 |
/// |
| 234 | 236 |
/// Check whether the given directed graph is strongly connected. The |
| 235 | 237 |
/// graph is strongly connected when any two nodes of the graph are |
| 236 | 238 |
/// connected with directed paths in both direction. |
| 237 | 239 |
/// \return \c false when the graph is not strongly connected. |
| 238 | 240 |
/// \see connected |
| 239 | 241 |
/// |
| 240 | 242 |
/// \note By definition, the empty graph is strongly connected. |
| 241 | 243 |
template <typename Digraph> |
| 242 | 244 |
bool stronglyConnected(const Digraph& digraph) {
|
| 243 | 245 |
checkConcept<concepts::Digraph, Digraph>(); |
| 244 | 246 |
|
| 245 | 247 |
typedef typename Digraph::Node Node; |
| 246 | 248 |
typedef typename Digraph::NodeIt NodeIt; |
| 247 | 249 |
|
| 248 | 250 |
typename Digraph::Node source = NodeIt(digraph); |
| 249 | 251 |
if (source == INVALID) return true; |
| 250 | 252 |
|
| 251 | 253 |
using namespace _connectivity_bits; |
| 252 | 254 |
|
| 253 | 255 |
typedef DfsVisitor<Digraph> Visitor; |
| 254 | 256 |
Visitor visitor; |
| 255 | 257 |
|
| 256 | 258 |
DfsVisit<Digraph, Visitor> dfs(digraph, visitor); |
| 257 | 259 |
dfs.init(); |
| 258 | 260 |
dfs.addSource(source); |
| 259 | 261 |
dfs.start(); |
| 260 | 262 |
|
| 261 | 263 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 262 | 264 |
if (!dfs.reached(it)) {
|
| 263 | 265 |
return false; |
| 264 | 266 |
} |
| 265 | 267 |
} |
| 266 | 268 |
|
| 267 | 269 |
typedef ReverseDigraph<const Digraph> RDigraph; |
| 268 | 270 |
typedef typename RDigraph::NodeIt RNodeIt; |
| 269 | 271 |
RDigraph rdigraph(digraph); |
| 270 | 272 |
|
| 271 | 273 |
typedef DfsVisitor<Digraph> RVisitor; |
| 272 | 274 |
RVisitor rvisitor; |
| 273 | 275 |
|
| 274 | 276 |
DfsVisit<RDigraph, RVisitor> rdfs(rdigraph, rvisitor); |
| 275 | 277 |
rdfs.init(); |
| 276 | 278 |
rdfs.addSource(source); |
| 277 | 279 |
rdfs.start(); |
| 278 | 280 |
|
| 279 | 281 |
for (RNodeIt it(rdigraph); it != INVALID; ++it) {
|
| 280 | 282 |
if (!rdfs.reached(it)) {
|
| 281 | 283 |
return false; |
| 282 | 284 |
} |
| 283 | 285 |
} |
| 284 | 286 |
|
| 285 | 287 |
return true; |
| 286 | 288 |
} |
| 287 | 289 |
|
| 288 |
/// \ingroup |
|
| 290 |
/// \ingroup graph_properties |
|
| 289 | 291 |
/// |
| 290 | 292 |
/// \brief Count the strongly connected components of a directed graph |
| 291 | 293 |
/// |
| 292 | 294 |
/// Count the strongly connected components of a directed graph. |
| 293 | 295 |
/// The strongly connected components are the classes of an |
| 294 | 296 |
/// equivalence relation on the nodes of the graph. Two nodes are in |
| 295 | 297 |
/// the same class if they are connected with directed paths in both |
| 296 | 298 |
/// direction. |
| 297 | 299 |
/// |
| 298 | 300 |
/// \param digraph The graph. |
| 299 | 301 |
/// \return The number of components |
| 300 | 302 |
/// \note By definition, the empty graph has zero |
| 301 | 303 |
/// strongly connected components. |
| 302 | 304 |
template <typename Digraph> |
| 303 | 305 |
int countStronglyConnectedComponents(const Digraph& digraph) {
|
| 304 | 306 |
checkConcept<concepts::Digraph, Digraph>(); |
| 305 | 307 |
|
| 306 | 308 |
using namespace _connectivity_bits; |
| 307 | 309 |
|
| 308 | 310 |
typedef typename Digraph::Node Node; |
| 309 | 311 |
typedef typename Digraph::Arc Arc; |
| 310 | 312 |
typedef typename Digraph::NodeIt NodeIt; |
| 311 | 313 |
typedef typename Digraph::ArcIt ArcIt; |
| 312 | 314 |
|
| 313 | 315 |
typedef std::vector<Node> Container; |
| 314 | 316 |
typedef typename Container::iterator Iterator; |
| 315 | 317 |
|
| 316 | 318 |
Container nodes(countNodes(digraph)); |
| 317 | 319 |
typedef LeaveOrderVisitor<Digraph, Iterator> Visitor; |
| 318 | 320 |
Visitor visitor(nodes.begin()); |
| 319 | 321 |
|
| 320 | 322 |
DfsVisit<Digraph, Visitor> dfs(digraph, visitor); |
| 321 | 323 |
dfs.init(); |
| 322 | 324 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 323 | 325 |
if (!dfs.reached(it)) {
|
| 324 | 326 |
dfs.addSource(it); |
| 325 | 327 |
dfs.start(); |
| 326 | 328 |
} |
| 327 | 329 |
} |
| 328 | 330 |
|
| 329 | 331 |
typedef typename Container::reverse_iterator RIterator; |
| 330 | 332 |
typedef ReverseDigraph<const Digraph> RDigraph; |
| 331 | 333 |
|
| 332 | 334 |
RDigraph rdigraph(digraph); |
| 333 | 335 |
|
| 334 | 336 |
typedef DfsVisitor<Digraph> RVisitor; |
| 335 | 337 |
RVisitor rvisitor; |
| 336 | 338 |
|
| 337 | 339 |
DfsVisit<RDigraph, RVisitor> rdfs(rdigraph, rvisitor); |
| 338 | 340 |
|
| 339 | 341 |
int compNum = 0; |
| 340 | 342 |
|
| 341 | 343 |
rdfs.init(); |
| 342 | 344 |
for (RIterator it = nodes.rbegin(); it != nodes.rend(); ++it) {
|
| 343 | 345 |
if (!rdfs.reached(*it)) {
|
| 344 | 346 |
rdfs.addSource(*it); |
| 345 | 347 |
rdfs.start(); |
| 346 | 348 |
++compNum; |
| 347 | 349 |
} |
| 348 | 350 |
} |
| 349 | 351 |
return compNum; |
| 350 | 352 |
} |
| 351 | 353 |
|
| 352 |
/// \ingroup |
|
| 354 |
/// \ingroup graph_properties |
|
| 353 | 355 |
/// |
| 354 | 356 |
/// \brief Find the strongly connected components of a directed graph |
| 355 | 357 |
/// |
| 356 | 358 |
/// Find the strongly connected components of a directed graph. The |
| 357 | 359 |
/// strongly connected components are the classes of an equivalence |
| 358 | 360 |
/// relation on the nodes of the graph. Two nodes are in |
| 359 | 361 |
/// relationship when there are directed paths between them in both |
| 360 | 362 |
/// direction. In addition, the numbering of components will satisfy |
| 361 | 363 |
/// that there is no arc going from a higher numbered component to |
| 362 | 364 |
/// a lower. |
| 363 | 365 |
/// |
| 366 |
/// \image html strongly_connected_components.png |
|
| 367 |
/// \image latex strongly_connected_components.eps "Strongly connected components" width=\textwidth |
|
| 368 |
/// |
|
| 364 | 369 |
/// \param digraph The digraph. |
| 365 | 370 |
/// \retval compMap A writable node map. The values will be set from 0 to |
| 366 | 371 |
/// the number of the strongly connected components minus one. Each value |
| 367 | 372 |
/// of the map will be set exactly once, the values of a certain component |
| 368 | 373 |
/// will be set continuously. |
| 369 | 374 |
/// \return The number of components |
| 370 |
/// |
|
| 371 | 375 |
template <typename Digraph, typename NodeMap> |
| 372 | 376 |
int stronglyConnectedComponents(const Digraph& digraph, NodeMap& compMap) {
|
| 373 | 377 |
checkConcept<concepts::Digraph, Digraph>(); |
| 374 | 378 |
typedef typename Digraph::Node Node; |
| 375 | 379 |
typedef typename Digraph::NodeIt NodeIt; |
| 376 | 380 |
checkConcept<concepts::WriteMap<Node, int>, NodeMap>(); |
| 377 | 381 |
|
| 378 | 382 |
using namespace _connectivity_bits; |
| 379 | 383 |
|
| 380 | 384 |
typedef std::vector<Node> Container; |
| 381 | 385 |
typedef typename Container::iterator Iterator; |
| 382 | 386 |
|
| 383 | 387 |
Container nodes(countNodes(digraph)); |
| 384 | 388 |
typedef LeaveOrderVisitor<Digraph, Iterator> Visitor; |
| 385 | 389 |
Visitor visitor(nodes.begin()); |
| 386 | 390 |
|
| 387 | 391 |
DfsVisit<Digraph, Visitor> dfs(digraph, visitor); |
| 388 | 392 |
dfs.init(); |
| 389 | 393 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 390 | 394 |
if (!dfs.reached(it)) {
|
| 391 | 395 |
dfs.addSource(it); |
| 392 | 396 |
dfs.start(); |
| 393 | 397 |
} |
| 394 | 398 |
} |
| 395 | 399 |
|
| 396 | 400 |
typedef typename Container::reverse_iterator RIterator; |
| 397 | 401 |
typedef ReverseDigraph<const Digraph> RDigraph; |
| 398 | 402 |
|
| 399 | 403 |
RDigraph rdigraph(digraph); |
| 400 | 404 |
|
| 401 | 405 |
int compNum = 0; |
| 402 | 406 |
|
| 403 | 407 |
typedef FillMapVisitor<RDigraph, NodeMap> RVisitor; |
| 404 | 408 |
RVisitor rvisitor(compMap, compNum); |
| 405 | 409 |
|
| 406 | 410 |
DfsVisit<RDigraph, RVisitor> rdfs(rdigraph, rvisitor); |
| 407 | 411 |
|
| 408 | 412 |
rdfs.init(); |
| 409 | 413 |
for (RIterator it = nodes.rbegin(); it != nodes.rend(); ++it) {
|
| 410 | 414 |
if (!rdfs.reached(*it)) {
|
| 411 | 415 |
rdfs.addSource(*it); |
| 412 | 416 |
rdfs.start(); |
| 413 | 417 |
++compNum; |
| 414 | 418 |
} |
| 415 | 419 |
} |
| 416 | 420 |
return compNum; |
| 417 | 421 |
} |
| 418 | 422 |
|
| 419 |
/// \ingroup |
|
| 423 |
/// \ingroup graph_properties |
|
| 420 | 424 |
/// |
| 421 | 425 |
/// \brief Find the cut arcs of the strongly connected components. |
| 422 | 426 |
/// |
| 423 | 427 |
/// Find the cut arcs of the strongly connected components. |
| 424 | 428 |
/// The strongly connected components are the classes of an equivalence |
| 425 | 429 |
/// relation on the nodes of the graph. Two nodes are in relationship |
| 426 | 430 |
/// when there are directed paths between them in both direction. |
| 427 | 431 |
/// The strongly connected components are separated by the cut arcs. |
| 428 | 432 |
/// |
| 429 | 433 |
/// \param graph The graph. |
| 430 | 434 |
/// \retval cutMap A writable node map. The values will be set true when the |
| 431 | 435 |
/// arc is a cut arc. |
| 432 | 436 |
/// |
| 433 | 437 |
/// \return The number of cut arcs |
| 434 | 438 |
template <typename Digraph, typename ArcMap> |
| 435 | 439 |
int stronglyConnectedCutArcs(const Digraph& graph, ArcMap& cutMap) {
|
| 436 | 440 |
checkConcept<concepts::Digraph, Digraph>(); |
| 437 | 441 |
typedef typename Digraph::Node Node; |
| 438 | 442 |
typedef typename Digraph::Arc Arc; |
| 439 | 443 |
typedef typename Digraph::NodeIt NodeIt; |
| 440 | 444 |
checkConcept<concepts::WriteMap<Arc, bool>, ArcMap>(); |
| 441 | 445 |
|
| 442 | 446 |
using namespace _connectivity_bits; |
| 443 | 447 |
|
| 444 | 448 |
typedef std::vector<Node> Container; |
| 445 | 449 |
typedef typename Container::iterator Iterator; |
| 446 | 450 |
|
| 447 | 451 |
Container nodes(countNodes(graph)); |
| 448 | 452 |
typedef LeaveOrderVisitor<Digraph, Iterator> Visitor; |
| 449 | 453 |
Visitor visitor(nodes.begin()); |
| 450 | 454 |
|
| 451 | 455 |
DfsVisit<Digraph, Visitor> dfs(graph, visitor); |
| 452 | 456 |
dfs.init(); |
| 453 | 457 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 454 | 458 |
if (!dfs.reached(it)) {
|
| 455 | 459 |
dfs.addSource(it); |
| 456 | 460 |
dfs.start(); |
| 457 | 461 |
} |
| 458 | 462 |
} |
| 459 | 463 |
|
| 460 | 464 |
typedef typename Container::reverse_iterator RIterator; |
| 461 | 465 |
typedef ReverseDigraph<const Digraph> RDigraph; |
| 462 | 466 |
|
| 463 | 467 |
RDigraph rgraph(graph); |
| 464 | 468 |
|
| 465 | 469 |
int cutNum = 0; |
| 466 | 470 |
|
| 467 | 471 |
typedef StronglyConnectedCutArcsVisitor<RDigraph, ArcMap> RVisitor; |
| ... | ... |
@@ -655,190 +659,192 @@ |
| 655 | 659 |
} |
| 656 | 660 |
return; |
| 657 | 661 |
} |
| 658 | 662 |
if (_predMap[_graph.source(edge)] == _graph.target(edge)) return; |
| 659 | 663 |
if (_retMap[_graph.source(edge)] > _numMap[_graph.target(edge)]) {
|
| 660 | 664 |
_retMap.set(_graph.source(edge), _numMap[_graph.target(edge)]); |
| 661 | 665 |
} |
| 662 | 666 |
} |
| 663 | 667 |
|
| 664 | 668 |
void backtrack(const Arc& edge) {
|
| 665 | 669 |
if (_retMap[_graph.source(edge)] > _retMap[_graph.target(edge)]) {
|
| 666 | 670 |
_retMap.set(_graph.source(edge), _retMap[_graph.target(edge)]); |
| 667 | 671 |
} |
| 668 | 672 |
if (_numMap[_graph.source(edge)] <= _retMap[_graph.target(edge)]) {
|
| 669 | 673 |
if (_predMap[_graph.source(edge)] != INVALID) {
|
| 670 | 674 |
if (!_cutMap[_graph.source(edge)]) {
|
| 671 | 675 |
_cutMap.set(_graph.source(edge), true); |
| 672 | 676 |
++_cutNum; |
| 673 | 677 |
} |
| 674 | 678 |
} else if (rootCut) {
|
| 675 | 679 |
if (!_cutMap[_graph.source(edge)]) {
|
| 676 | 680 |
_cutMap.set(_graph.source(edge), true); |
| 677 | 681 |
++_cutNum; |
| 678 | 682 |
} |
| 679 | 683 |
} else {
|
| 680 | 684 |
rootCut = true; |
| 681 | 685 |
} |
| 682 | 686 |
} |
| 683 | 687 |
} |
| 684 | 688 |
|
| 685 | 689 |
private: |
| 686 | 690 |
const Digraph& _graph; |
| 687 | 691 |
NodeMap& _cutMap; |
| 688 | 692 |
int& _cutNum; |
| 689 | 693 |
|
| 690 | 694 |
typename Digraph::template NodeMap<int> _numMap; |
| 691 | 695 |
typename Digraph::template NodeMap<int> _retMap; |
| 692 | 696 |
typename Digraph::template NodeMap<Node> _predMap; |
| 693 | 697 |
std::stack<Edge> _edgeStack; |
| 694 | 698 |
int _num; |
| 695 | 699 |
bool rootCut; |
| 696 | 700 |
}; |
| 697 | 701 |
|
| 698 | 702 |
} |
| 699 | 703 |
|
| 700 | 704 |
template <typename Graph> |
| 701 | 705 |
int countBiNodeConnectedComponents(const Graph& graph); |
| 702 | 706 |
|
| 703 |
/// \ingroup |
|
| 707 |
/// \ingroup graph_properties |
|
| 704 | 708 |
/// |
| 705 | 709 |
/// \brief Checks the graph is bi-node-connected. |
| 706 | 710 |
/// |
| 707 | 711 |
/// This function checks that the undirected graph is bi-node-connected |
| 708 | 712 |
/// graph. The graph is bi-node-connected if any two undirected edge is |
| 709 | 713 |
/// on same circle. |
| 710 | 714 |
/// |
| 711 | 715 |
/// \param graph The graph. |
| 712 | 716 |
/// \return \c true when the graph bi-node-connected. |
| 713 | 717 |
template <typename Graph> |
| 714 | 718 |
bool biNodeConnected(const Graph& graph) {
|
| 715 | 719 |
return countBiNodeConnectedComponents(graph) <= 1; |
| 716 | 720 |
} |
| 717 | 721 |
|
| 718 |
/// \ingroup |
|
| 722 |
/// \ingroup graph_properties |
|
| 719 | 723 |
/// |
| 720 | 724 |
/// \brief Count the biconnected components. |
| 721 | 725 |
/// |
| 722 | 726 |
/// This function finds the bi-node-connected components in an undirected |
| 723 | 727 |
/// graph. The biconnected components are the classes of an equivalence |
| 724 | 728 |
/// relation on the undirected edges. Two undirected edge is in relationship |
| 725 | 729 |
/// when they are on same circle. |
| 726 | 730 |
/// |
| 727 | 731 |
/// \param graph The graph. |
| 728 | 732 |
/// \return The number of components. |
| 729 | 733 |
template <typename Graph> |
| 730 | 734 |
int countBiNodeConnectedComponents(const Graph& graph) {
|
| 731 | 735 |
checkConcept<concepts::Graph, Graph>(); |
| 732 | 736 |
typedef typename Graph::NodeIt NodeIt; |
| 733 | 737 |
|
| 734 | 738 |
using namespace _connectivity_bits; |
| 735 | 739 |
|
| 736 | 740 |
typedef CountBiNodeConnectedComponentsVisitor<Graph> Visitor; |
| 737 | 741 |
|
| 738 | 742 |
int compNum = 0; |
| 739 | 743 |
Visitor visitor(graph, compNum); |
| 740 | 744 |
|
| 741 | 745 |
DfsVisit<Graph, Visitor> dfs(graph, visitor); |
| 742 | 746 |
dfs.init(); |
| 743 | 747 |
|
| 744 | 748 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 745 | 749 |
if (!dfs.reached(it)) {
|
| 746 | 750 |
dfs.addSource(it); |
| 747 | 751 |
dfs.start(); |
| 748 | 752 |
} |
| 749 | 753 |
} |
| 750 | 754 |
return compNum; |
| 751 | 755 |
} |
| 752 | 756 |
|
| 753 |
/// \ingroup |
|
| 757 |
/// \ingroup graph_properties |
|
| 754 | 758 |
/// |
| 755 | 759 |
/// \brief Find the bi-node-connected components. |
| 756 | 760 |
/// |
| 757 | 761 |
/// This function finds the bi-node-connected components in an undirected |
| 758 | 762 |
/// graph. The bi-node-connected components are the classes of an equivalence |
| 759 | 763 |
/// relation on the undirected edges. Two undirected edge are in relationship |
| 760 | 764 |
/// when they are on same circle. |
| 761 | 765 |
/// |
| 766 |
/// \image html node_biconnected_components.png |
|
| 767 |
/// \image latex node_biconnected_components.eps "bi-node-connected components" width=\textwidth |
|
| 768 |
/// |
|
| 762 | 769 |
/// \param graph The graph. |
| 763 | 770 |
/// \retval compMap A writable uedge map. The values will be set from 0 |
| 764 | 771 |
/// to the number of the biconnected components minus one. Each values |
| 765 | 772 |
/// of the map will be set exactly once, the values of a certain component |
| 766 | 773 |
/// will be set continuously. |
| 767 | 774 |
/// \return The number of components. |
| 768 |
/// |
|
| 769 | 775 |
template <typename Graph, typename EdgeMap> |
| 770 | 776 |
int biNodeConnectedComponents(const Graph& graph, |
| 771 | 777 |
EdgeMap& compMap) {
|
| 772 | 778 |
checkConcept<concepts::Graph, Graph>(); |
| 773 | 779 |
typedef typename Graph::NodeIt NodeIt; |
| 774 | 780 |
typedef typename Graph::Edge Edge; |
| 775 | 781 |
checkConcept<concepts::WriteMap<Edge, int>, EdgeMap>(); |
| 776 | 782 |
|
| 777 | 783 |
using namespace _connectivity_bits; |
| 778 | 784 |
|
| 779 | 785 |
typedef BiNodeConnectedComponentsVisitor<Graph, EdgeMap> Visitor; |
| 780 | 786 |
|
| 781 | 787 |
int compNum = 0; |
| 782 | 788 |
Visitor visitor(graph, compMap, compNum); |
| 783 | 789 |
|
| 784 | 790 |
DfsVisit<Graph, Visitor> dfs(graph, visitor); |
| 785 | 791 |
dfs.init(); |
| 786 | 792 |
|
| 787 | 793 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 788 | 794 |
if (!dfs.reached(it)) {
|
| 789 | 795 |
dfs.addSource(it); |
| 790 | 796 |
dfs.start(); |
| 791 | 797 |
} |
| 792 | 798 |
} |
| 793 | 799 |
return compNum; |
| 794 | 800 |
} |
| 795 | 801 |
|
| 796 |
/// \ingroup |
|
| 802 |
/// \ingroup graph_properties |
|
| 797 | 803 |
/// |
| 798 | 804 |
/// \brief Find the bi-node-connected cut nodes. |
| 799 | 805 |
/// |
| 800 | 806 |
/// This function finds the bi-node-connected cut nodes in an undirected |
| 801 | 807 |
/// graph. The bi-node-connected components are the classes of an equivalence |
| 802 | 808 |
/// relation on the undirected edges. Two undirected edges are in |
| 803 | 809 |
/// relationship when they are on same circle. The biconnected components |
| 804 | 810 |
/// are separted by nodes which are the cut nodes of the components. |
| 805 | 811 |
/// |
| 806 | 812 |
/// \param graph The graph. |
| 807 | 813 |
/// \retval cutMap A writable edge map. The values will be set true when |
| 808 | 814 |
/// the node separate two or more components. |
| 809 | 815 |
/// \return The number of the cut nodes. |
| 810 | 816 |
template <typename Graph, typename NodeMap> |
| 811 | 817 |
int biNodeConnectedCutNodes(const Graph& graph, NodeMap& cutMap) {
|
| 812 | 818 |
checkConcept<concepts::Graph, Graph>(); |
| 813 | 819 |
typedef typename Graph::Node Node; |
| 814 | 820 |
typedef typename Graph::NodeIt NodeIt; |
| 815 | 821 |
checkConcept<concepts::WriteMap<Node, bool>, NodeMap>(); |
| 816 | 822 |
|
| 817 | 823 |
using namespace _connectivity_bits; |
| 818 | 824 |
|
| 819 | 825 |
typedef BiNodeConnectedCutNodesVisitor<Graph, NodeMap> Visitor; |
| 820 | 826 |
|
| 821 | 827 |
int cutNum = 0; |
| 822 | 828 |
Visitor visitor(graph, cutMap, cutNum); |
| 823 | 829 |
|
| 824 | 830 |
DfsVisit<Graph, Visitor> dfs(graph, visitor); |
| 825 | 831 |
dfs.init(); |
| 826 | 832 |
|
| 827 | 833 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 828 | 834 |
if (!dfs.reached(it)) {
|
| 829 | 835 |
dfs.addSource(it); |
| 830 | 836 |
dfs.start(); |
| 831 | 837 |
} |
| 832 | 838 |
} |
| 833 | 839 |
return cutNum; |
| 834 | 840 |
} |
| 835 | 841 |
|
| 836 | 842 |
namespace _connectivity_bits {
|
| 837 | 843 |
|
| 838 | 844 |
template <typename Digraph> |
| 839 | 845 |
class CountBiEdgeConnectedComponentsVisitor : public DfsVisitor<Digraph> {
|
| 840 | 846 |
public: |
| 841 | 847 |
typedef typename Digraph::Node Node; |
| 842 | 848 |
typedef typename Digraph::Arc Arc; |
| 843 | 849 |
typedef typename Digraph::Edge Edge; |
| 844 | 850 |
|
| ... | ... |
@@ -978,559 +984,565 @@ |
| 978 | 984 |
_numMap.set(node, _num); |
| 979 | 985 |
_retMap.set(node, _num); |
| 980 | 986 |
++_num; |
| 981 | 987 |
} |
| 982 | 988 |
|
| 983 | 989 |
void leave(const Node& node) {
|
| 984 | 990 |
if (_numMap[node] <= _retMap[node]) {
|
| 985 | 991 |
if (_predMap[node] != INVALID) {
|
| 986 | 992 |
_cutMap.set(_predMap[node], true); |
| 987 | 993 |
++_cutNum; |
| 988 | 994 |
} |
| 989 | 995 |
} |
| 990 | 996 |
} |
| 991 | 997 |
|
| 992 | 998 |
void discover(const Arc& edge) {
|
| 993 | 999 |
_predMap.set(_graph.target(edge), edge); |
| 994 | 1000 |
} |
| 995 | 1001 |
|
| 996 | 1002 |
void examine(const Arc& edge) {
|
| 997 | 1003 |
if (_predMap[_graph.source(edge)] == _graph.oppositeArc(edge)) {
|
| 998 | 1004 |
return; |
| 999 | 1005 |
} |
| 1000 | 1006 |
if (_retMap[_graph.source(edge)] > _retMap[_graph.target(edge)]) {
|
| 1001 | 1007 |
_retMap.set(_graph.source(edge), _retMap[_graph.target(edge)]); |
| 1002 | 1008 |
} |
| 1003 | 1009 |
} |
| 1004 | 1010 |
|
| 1005 | 1011 |
void backtrack(const Arc& edge) {
|
| 1006 | 1012 |
if (_retMap[_graph.source(edge)] > _retMap[_graph.target(edge)]) {
|
| 1007 | 1013 |
_retMap.set(_graph.source(edge), _retMap[_graph.target(edge)]); |
| 1008 | 1014 |
} |
| 1009 | 1015 |
} |
| 1010 | 1016 |
|
| 1011 | 1017 |
private: |
| 1012 | 1018 |
const Digraph& _graph; |
| 1013 | 1019 |
ArcMap& _cutMap; |
| 1014 | 1020 |
int& _cutNum; |
| 1015 | 1021 |
|
| 1016 | 1022 |
typename Digraph::template NodeMap<int> _numMap; |
| 1017 | 1023 |
typename Digraph::template NodeMap<int> _retMap; |
| 1018 | 1024 |
typename Digraph::template NodeMap<Arc> _predMap; |
| 1019 | 1025 |
int _num; |
| 1020 | 1026 |
}; |
| 1021 | 1027 |
} |
| 1022 | 1028 |
|
| 1023 | 1029 |
template <typename Graph> |
| 1024 | 1030 |
int countBiEdgeConnectedComponents(const Graph& graph); |
| 1025 | 1031 |
|
| 1026 |
/// \ingroup |
|
| 1032 |
/// \ingroup graph_properties |
|
| 1027 | 1033 |
/// |
| 1028 | 1034 |
/// \brief Checks that the graph is bi-edge-connected. |
| 1029 | 1035 |
/// |
| 1030 | 1036 |
/// This function checks that the graph is bi-edge-connected. The undirected |
| 1031 | 1037 |
/// graph is bi-edge-connected when any two nodes are connected with two |
| 1032 | 1038 |
/// edge-disjoint paths. |
| 1033 | 1039 |
/// |
| 1034 | 1040 |
/// \param graph The undirected graph. |
| 1035 | 1041 |
/// \return The number of components. |
| 1036 | 1042 |
template <typename Graph> |
| 1037 | 1043 |
bool biEdgeConnected(const Graph& graph) {
|
| 1038 | 1044 |
return countBiEdgeConnectedComponents(graph) <= 1; |
| 1039 | 1045 |
} |
| 1040 | 1046 |
|
| 1041 |
/// \ingroup |
|
| 1047 |
/// \ingroup graph_properties |
|
| 1042 | 1048 |
/// |
| 1043 | 1049 |
/// \brief Count the bi-edge-connected components. |
| 1044 | 1050 |
/// |
| 1045 | 1051 |
/// This function count the bi-edge-connected components in an undirected |
| 1046 | 1052 |
/// graph. The bi-edge-connected components are the classes of an equivalence |
| 1047 | 1053 |
/// relation on the nodes. Two nodes are in relationship when they are |
| 1048 | 1054 |
/// connected with at least two edge-disjoint paths. |
| 1049 | 1055 |
/// |
| 1050 | 1056 |
/// \param graph The undirected graph. |
| 1051 | 1057 |
/// \return The number of components. |
| 1052 | 1058 |
template <typename Graph> |
| 1053 | 1059 |
int countBiEdgeConnectedComponents(const Graph& graph) {
|
| 1054 | 1060 |
checkConcept<concepts::Graph, Graph>(); |
| 1055 | 1061 |
typedef typename Graph::NodeIt NodeIt; |
| 1056 | 1062 |
|
| 1057 | 1063 |
using namespace _connectivity_bits; |
| 1058 | 1064 |
|
| 1059 | 1065 |
typedef CountBiEdgeConnectedComponentsVisitor<Graph> Visitor; |
| 1060 | 1066 |
|
| 1061 | 1067 |
int compNum = 0; |
| 1062 | 1068 |
Visitor visitor(graph, compNum); |
| 1063 | 1069 |
|
| 1064 | 1070 |
DfsVisit<Graph, Visitor> dfs(graph, visitor); |
| 1065 | 1071 |
dfs.init(); |
| 1066 | 1072 |
|
| 1067 | 1073 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1068 | 1074 |
if (!dfs.reached(it)) {
|
| 1069 | 1075 |
dfs.addSource(it); |
| 1070 | 1076 |
dfs.start(); |
| 1071 | 1077 |
} |
| 1072 | 1078 |
} |
| 1073 | 1079 |
return compNum; |
| 1074 | 1080 |
} |
| 1075 | 1081 |
|
| 1076 |
/// \ingroup |
|
| 1082 |
/// \ingroup graph_properties |
|
| 1077 | 1083 |
/// |
| 1078 | 1084 |
/// \brief Find the bi-edge-connected components. |
| 1079 | 1085 |
/// |
| 1080 | 1086 |
/// This function finds the bi-edge-connected components in an undirected |
| 1081 | 1087 |
/// graph. The bi-edge-connected components are the classes of an equivalence |
| 1082 | 1088 |
/// relation on the nodes. Two nodes are in relationship when they are |
| 1083 | 1089 |
/// connected at least two edge-disjoint paths. |
| 1084 | 1090 |
/// |
| 1091 |
/// \image html edge_biconnected_components.png |
|
| 1092 |
/// \image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
|
| 1093 |
/// |
|
| 1085 | 1094 |
/// \param graph The graph. |
| 1086 | 1095 |
/// \retval compMap A writable node map. The values will be set from 0 to |
| 1087 | 1096 |
/// the number of the biconnected components minus one. Each values |
| 1088 | 1097 |
/// of the map will be set exactly once, the values of a certain component |
| 1089 | 1098 |
/// will be set continuously. |
| 1090 | 1099 |
/// \return The number of components. |
| 1091 |
/// |
|
| 1092 | 1100 |
template <typename Graph, typename NodeMap> |
| 1093 | 1101 |
int biEdgeConnectedComponents(const Graph& graph, NodeMap& compMap) {
|
| 1094 | 1102 |
checkConcept<concepts::Graph, Graph>(); |
| 1095 | 1103 |
typedef typename Graph::NodeIt NodeIt; |
| 1096 | 1104 |
typedef typename Graph::Node Node; |
| 1097 | 1105 |
checkConcept<concepts::WriteMap<Node, int>, NodeMap>(); |
| 1098 | 1106 |
|
| 1099 | 1107 |
using namespace _connectivity_bits; |
| 1100 | 1108 |
|
| 1101 | 1109 |
typedef BiEdgeConnectedComponentsVisitor<Graph, NodeMap> Visitor; |
| 1102 | 1110 |
|
| 1103 | 1111 |
int compNum = 0; |
| 1104 | 1112 |
Visitor visitor(graph, compMap, compNum); |
| 1105 | 1113 |
|
| 1106 | 1114 |
DfsVisit<Graph, Visitor> dfs(graph, visitor); |
| 1107 | 1115 |
dfs.init(); |
| 1108 | 1116 |
|
| 1109 | 1117 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1110 | 1118 |
if (!dfs.reached(it)) {
|
| 1111 | 1119 |
dfs.addSource(it); |
| 1112 | 1120 |
dfs.start(); |
| 1113 | 1121 |
} |
| 1114 | 1122 |
} |
| 1115 | 1123 |
return compNum; |
| 1116 | 1124 |
} |
| 1117 | 1125 |
|
| 1118 |
/// \ingroup |
|
| 1126 |
/// \ingroup graph_properties |
|
| 1119 | 1127 |
/// |
| 1120 | 1128 |
/// \brief Find the bi-edge-connected cut edges. |
| 1121 | 1129 |
/// |
| 1122 | 1130 |
/// This function finds the bi-edge-connected components in an undirected |
| 1123 | 1131 |
/// graph. The bi-edge-connected components are the classes of an equivalence |
| 1124 | 1132 |
/// relation on the nodes. Two nodes are in relationship when they are |
| 1125 | 1133 |
/// connected with at least two edge-disjoint paths. The bi-edge-connected |
| 1126 | 1134 |
/// components are separted by edges which are the cut edges of the |
| 1127 | 1135 |
/// components. |
| 1128 | 1136 |
/// |
| 1129 | 1137 |
/// \param graph The graph. |
| 1130 | 1138 |
/// \retval cutMap A writable node map. The values will be set true when the |
| 1131 | 1139 |
/// edge is a cut edge. |
| 1132 | 1140 |
/// \return The number of cut edges. |
| 1133 | 1141 |
template <typename Graph, typename EdgeMap> |
| 1134 | 1142 |
int biEdgeConnectedCutEdges(const Graph& graph, EdgeMap& cutMap) {
|
| 1135 | 1143 |
checkConcept<concepts::Graph, Graph>(); |
| 1136 | 1144 |
typedef typename Graph::NodeIt NodeIt; |
| 1137 | 1145 |
typedef typename Graph::Edge Edge; |
| 1138 | 1146 |
checkConcept<concepts::WriteMap<Edge, bool>, EdgeMap>(); |
| 1139 | 1147 |
|
| 1140 | 1148 |
using namespace _connectivity_bits; |
| 1141 | 1149 |
|
| 1142 | 1150 |
typedef BiEdgeConnectedCutEdgesVisitor<Graph, EdgeMap> Visitor; |
| 1143 | 1151 |
|
| 1144 | 1152 |
int cutNum = 0; |
| 1145 | 1153 |
Visitor visitor(graph, cutMap, cutNum); |
| 1146 | 1154 |
|
| 1147 | 1155 |
DfsVisit<Graph, Visitor> dfs(graph, visitor); |
| 1148 | 1156 |
dfs.init(); |
| 1149 | 1157 |
|
| 1150 | 1158 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1151 | 1159 |
if (!dfs.reached(it)) {
|
| 1152 | 1160 |
dfs.addSource(it); |
| 1153 | 1161 |
dfs.start(); |
| 1154 | 1162 |
} |
| 1155 | 1163 |
} |
| 1156 | 1164 |
return cutNum; |
| 1157 | 1165 |
} |
| 1158 | 1166 |
|
| 1159 | 1167 |
|
| 1160 | 1168 |
namespace _connectivity_bits {
|
| 1161 | 1169 |
|
| 1162 | 1170 |
template <typename Digraph, typename IntNodeMap> |
| 1163 | 1171 |
class TopologicalSortVisitor : public DfsVisitor<Digraph> {
|
| 1164 | 1172 |
public: |
| 1165 | 1173 |
typedef typename Digraph::Node Node; |
| 1166 | 1174 |
typedef typename Digraph::Arc edge; |
| 1167 | 1175 |
|
| 1168 | 1176 |
TopologicalSortVisitor(IntNodeMap& order, int num) |
| 1169 | 1177 |
: _order(order), _num(num) {}
|
| 1170 | 1178 |
|
| 1171 | 1179 |
void leave(const Node& node) {
|
| 1172 | 1180 |
_order.set(node, --_num); |
| 1173 | 1181 |
} |
| 1174 | 1182 |
|
| 1175 | 1183 |
private: |
| 1176 | 1184 |
IntNodeMap& _order; |
| 1177 | 1185 |
int _num; |
| 1178 | 1186 |
}; |
| 1179 | 1187 |
|
| 1180 | 1188 |
} |
| 1181 | 1189 |
|
| 1182 |
/// \ingroup |
|
| 1190 |
/// \ingroup graph_properties |
|
| 1183 | 1191 |
/// |
| 1184 | 1192 |
/// \brief Sort the nodes of a DAG into topolgical order. |
| 1185 | 1193 |
/// |
| 1186 | 1194 |
/// Sort the nodes of a DAG into topolgical order. |
| 1187 | 1195 |
/// |
| 1188 | 1196 |
/// \param graph The graph. It must be directed and acyclic. |
| 1189 | 1197 |
/// \retval order A writable node map. The values will be set from 0 to |
| 1190 | 1198 |
/// the number of the nodes in the graph minus one. Each values of the map |
| 1191 | 1199 |
/// will be set exactly once, the values will be set descending order. |
| 1192 | 1200 |
/// |
| 1193 | 1201 |
/// \see checkedTopologicalSort |
| 1194 | 1202 |
/// \see dag |
| 1195 | 1203 |
template <typename Digraph, typename NodeMap> |
| 1196 | 1204 |
void topologicalSort(const Digraph& graph, NodeMap& order) {
|
| 1197 | 1205 |
using namespace _connectivity_bits; |
| 1198 | 1206 |
|
| 1199 | 1207 |
checkConcept<concepts::Digraph, Digraph>(); |
| 1200 | 1208 |
checkConcept<concepts::WriteMap<typename Digraph::Node, int>, NodeMap>(); |
| 1201 | 1209 |
|
| 1202 | 1210 |
typedef typename Digraph::Node Node; |
| 1203 | 1211 |
typedef typename Digraph::NodeIt NodeIt; |
| 1204 | 1212 |
typedef typename Digraph::Arc Arc; |
| 1205 | 1213 |
|
| 1206 | 1214 |
TopologicalSortVisitor<Digraph, NodeMap> |
| 1207 | 1215 |
visitor(order, countNodes(graph)); |
| 1208 | 1216 |
|
| 1209 | 1217 |
DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> > |
| 1210 | 1218 |
dfs(graph, visitor); |
| 1211 | 1219 |
|
| 1212 | 1220 |
dfs.init(); |
| 1213 | 1221 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1214 | 1222 |
if (!dfs.reached(it)) {
|
| 1215 | 1223 |
dfs.addSource(it); |
| 1216 | 1224 |
dfs.start(); |
| 1217 | 1225 |
} |
| 1218 | 1226 |
} |
| 1219 | 1227 |
} |
| 1220 | 1228 |
|
| 1221 |
/// \ingroup |
|
| 1229 |
/// \ingroup graph_properties |
|
| 1222 | 1230 |
/// |
| 1223 | 1231 |
/// \brief Sort the nodes of a DAG into topolgical order. |
| 1224 | 1232 |
/// |
| 1225 | 1233 |
/// Sort the nodes of a DAG into topolgical order. It also checks |
| 1226 | 1234 |
/// that the given graph is DAG. |
| 1227 | 1235 |
/// |
| 1228 | 1236 |
/// \param digraph The graph. It must be directed and acyclic. |
| 1229 | 1237 |
/// \retval order A readable - writable node map. The values will be set |
| 1230 | 1238 |
/// from 0 to the number of the nodes in the graph minus one. Each values |
| 1231 | 1239 |
/// of the map will be set exactly once, the values will be set descending |
| 1232 | 1240 |
/// order. |
| 1233 | 1241 |
/// \return \c false when the graph is not DAG. |
| 1234 | 1242 |
/// |
| 1235 | 1243 |
/// \see topologicalSort |
| 1236 | 1244 |
/// \see dag |
| 1237 | 1245 |
template <typename Digraph, typename NodeMap> |
| 1238 | 1246 |
bool checkedTopologicalSort(const Digraph& digraph, NodeMap& order) {
|
| 1239 | 1247 |
using namespace _connectivity_bits; |
| 1240 | 1248 |
|
| 1241 | 1249 |
checkConcept<concepts::Digraph, Digraph>(); |
| 1242 | 1250 |
checkConcept<concepts::ReadWriteMap<typename Digraph::Node, int>, |
| 1243 | 1251 |
NodeMap>(); |
| 1244 | 1252 |
|
| 1245 | 1253 |
typedef typename Digraph::Node Node; |
| 1246 | 1254 |
typedef typename Digraph::NodeIt NodeIt; |
| 1247 | 1255 |
typedef typename Digraph::Arc Arc; |
| 1248 | 1256 |
|
| 1249 | 1257 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 1250 | 1258 |
order.set(it, -1); |
| 1251 | 1259 |
} |
| 1252 | 1260 |
|
| 1253 | 1261 |
TopologicalSortVisitor<Digraph, NodeMap> |
| 1254 | 1262 |
visitor(order, countNodes(digraph)); |
| 1255 | 1263 |
|
| 1256 | 1264 |
DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> > |
| 1257 | 1265 |
dfs(digraph, visitor); |
| 1258 | 1266 |
|
| 1259 | 1267 |
dfs.init(); |
| 1260 | 1268 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 1261 | 1269 |
if (!dfs.reached(it)) {
|
| 1262 | 1270 |
dfs.addSource(it); |
| 1263 | 1271 |
while (!dfs.emptyQueue()) {
|
| 1264 | 1272 |
Arc arc = dfs.nextArc(); |
| 1265 | 1273 |
Node target = digraph.target(arc); |
| 1266 | 1274 |
if (dfs.reached(target) && order[target] == -1) {
|
| 1267 | 1275 |
return false; |
| 1268 | 1276 |
} |
| 1269 | 1277 |
dfs.processNextArc(); |
| 1270 | 1278 |
} |
| 1271 | 1279 |
} |
| 1272 | 1280 |
} |
| 1273 | 1281 |
return true; |
| 1274 | 1282 |
} |
| 1275 | 1283 |
|
| 1276 |
/// \ingroup |
|
| 1284 |
/// \ingroup graph_properties |
|
| 1277 | 1285 |
/// |
| 1278 | 1286 |
/// \brief Check that the given directed graph is a DAG. |
| 1279 | 1287 |
/// |
| 1280 | 1288 |
/// Check that the given directed graph is a DAG. The DAG is |
| 1281 | 1289 |
/// an Directed Acyclic Digraph. |
| 1282 | 1290 |
/// \return \c false when the graph is not DAG. |
| 1283 | 1291 |
/// \see acyclic |
| 1284 | 1292 |
template <typename Digraph> |
| 1285 | 1293 |
bool dag(const Digraph& digraph) {
|
| 1286 | 1294 |
|
| 1287 | 1295 |
checkConcept<concepts::Digraph, Digraph>(); |
| 1288 | 1296 |
|
| 1289 | 1297 |
typedef typename Digraph::Node Node; |
| 1290 | 1298 |
typedef typename Digraph::NodeIt NodeIt; |
| 1291 | 1299 |
typedef typename Digraph::Arc Arc; |
| 1292 | 1300 |
|
| 1293 | 1301 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
| 1294 | 1302 |
|
| 1295 | 1303 |
typename Dfs<Digraph>::template SetProcessedMap<ProcessedMap>:: |
| 1296 | 1304 |
Create dfs(digraph); |
| 1297 | 1305 |
|
| 1298 | 1306 |
ProcessedMap processed(digraph); |
| 1299 | 1307 |
dfs.processedMap(processed); |
| 1300 | 1308 |
|
| 1301 | 1309 |
dfs.init(); |
| 1302 | 1310 |
for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 1303 | 1311 |
if (!dfs.reached(it)) {
|
| 1304 | 1312 |
dfs.addSource(it); |
| 1305 | 1313 |
while (!dfs.emptyQueue()) {
|
| 1306 | 1314 |
Arc edge = dfs.nextArc(); |
| 1307 | 1315 |
Node target = digraph.target(edge); |
| 1308 | 1316 |
if (dfs.reached(target) && !processed[target]) {
|
| 1309 | 1317 |
return false; |
| 1310 | 1318 |
} |
| 1311 | 1319 |
dfs.processNextArc(); |
| 1312 | 1320 |
} |
| 1313 | 1321 |
} |
| 1314 | 1322 |
} |
| 1315 | 1323 |
return true; |
| 1316 | 1324 |
} |
| 1317 | 1325 |
|
| 1318 |
/// \ingroup |
|
| 1326 |
/// \ingroup graph_properties |
|
| 1319 | 1327 |
/// |
| 1320 | 1328 |
/// \brief Check that the given undirected graph is acyclic. |
| 1321 | 1329 |
/// |
| 1322 | 1330 |
/// Check that the given undirected graph acyclic. |
| 1323 | 1331 |
/// \param graph The undirected graph. |
| 1324 | 1332 |
/// \return \c true when there is no circle in the graph. |
| 1325 | 1333 |
/// \see dag |
| 1326 | 1334 |
template <typename Graph> |
| 1327 | 1335 |
bool acyclic(const Graph& graph) {
|
| 1328 | 1336 |
checkConcept<concepts::Graph, Graph>(); |
| 1329 | 1337 |
typedef typename Graph::Node Node; |
| 1330 | 1338 |
typedef typename Graph::NodeIt NodeIt; |
| 1331 | 1339 |
typedef typename Graph::Arc Arc; |
| 1332 | 1340 |
Dfs<Graph> dfs(graph); |
| 1333 | 1341 |
dfs.init(); |
| 1334 | 1342 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1335 | 1343 |
if (!dfs.reached(it)) {
|
| 1336 | 1344 |
dfs.addSource(it); |
| 1337 | 1345 |
while (!dfs.emptyQueue()) {
|
| 1338 | 1346 |
Arc edge = dfs.nextArc(); |
| 1339 | 1347 |
Node source = graph.source(edge); |
| 1340 | 1348 |
Node target = graph.target(edge); |
| 1341 | 1349 |
if (dfs.reached(target) && |
| 1342 | 1350 |
dfs.predArc(source) != graph.oppositeArc(edge)) {
|
| 1343 | 1351 |
return false; |
| 1344 | 1352 |
} |
| 1345 | 1353 |
dfs.processNextArc(); |
| 1346 | 1354 |
} |
| 1347 | 1355 |
} |
| 1348 | 1356 |
} |
| 1349 | 1357 |
return true; |
| 1350 | 1358 |
} |
| 1351 | 1359 |
|
| 1352 |
/// \ingroup |
|
| 1360 |
/// \ingroup graph_properties |
|
| 1353 | 1361 |
/// |
| 1354 | 1362 |
/// \brief Check that the given undirected graph is tree. |
| 1355 | 1363 |
/// |
| 1356 | 1364 |
/// Check that the given undirected graph is tree. |
| 1357 | 1365 |
/// \param graph The undirected graph. |
| 1358 | 1366 |
/// \return \c true when the graph is acyclic and connected. |
| 1359 | 1367 |
template <typename Graph> |
| 1360 | 1368 |
bool tree(const Graph& graph) {
|
| 1361 | 1369 |
checkConcept<concepts::Graph, Graph>(); |
| 1362 | 1370 |
typedef typename Graph::Node Node; |
| 1363 | 1371 |
typedef typename Graph::NodeIt NodeIt; |
| 1364 | 1372 |
typedef typename Graph::Arc Arc; |
| 1365 | 1373 |
Dfs<Graph> dfs(graph); |
| 1366 | 1374 |
dfs.init(); |
| 1367 | 1375 |
dfs.addSource(NodeIt(graph)); |
| 1368 | 1376 |
while (!dfs.emptyQueue()) {
|
| 1369 | 1377 |
Arc edge = dfs.nextArc(); |
| 1370 | 1378 |
Node source = graph.source(edge); |
| 1371 | 1379 |
Node target = graph.target(edge); |
| 1372 | 1380 |
if (dfs.reached(target) && |
| 1373 | 1381 |
dfs.predArc(source) != graph.oppositeArc(edge)) {
|
| 1374 | 1382 |
return false; |
| 1375 | 1383 |
} |
| 1376 | 1384 |
dfs.processNextArc(); |
| 1377 | 1385 |
} |
| 1378 | 1386 |
for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1379 | 1387 |
if (!dfs.reached(it)) {
|
| 1380 | 1388 |
return false; |
| 1381 | 1389 |
} |
| 1382 | 1390 |
} |
| 1383 | 1391 |
return true; |
| 1384 | 1392 |
} |
| 1385 | 1393 |
|
| 1386 | 1394 |
namespace _connectivity_bits {
|
| 1387 | 1395 |
|
| 1388 | 1396 |
template <typename Digraph> |
| 1389 | 1397 |
class BipartiteVisitor : public BfsVisitor<Digraph> {
|
| 1390 | 1398 |
public: |
| 1391 | 1399 |
typedef typename Digraph::Arc Arc; |
| 1392 | 1400 |
typedef typename Digraph::Node Node; |
| 1393 | 1401 |
|
| 1394 | 1402 |
BipartiteVisitor(const Digraph& graph, bool& bipartite) |
| 1395 | 1403 |
: _graph(graph), _part(graph), _bipartite(bipartite) {}
|
| 1396 | 1404 |
|
| 1397 | 1405 |
void start(const Node& node) {
|
| 1398 | 1406 |
_part[node] = true; |
| 1399 | 1407 |
} |
| 1400 | 1408 |
void discover(const Arc& edge) {
|
| 1401 | 1409 |
_part.set(_graph.target(edge), !_part[_graph.source(edge)]); |
| 1402 | 1410 |
} |
| 1403 | 1411 |
void examine(const Arc& edge) {
|
| 1404 | 1412 |
_bipartite = _bipartite && |
| 1405 | 1413 |
_part[_graph.target(edge)] != _part[_graph.source(edge)]; |
| 1406 | 1414 |
} |
| 1407 | 1415 |
|
| 1408 | 1416 |
private: |
| 1409 | 1417 |
|
| 1410 | 1418 |
const Digraph& _graph; |
| 1411 | 1419 |
typename Digraph::template NodeMap<bool> _part; |
| 1412 | 1420 |
bool& _bipartite; |
| 1413 | 1421 |
}; |
| 1414 | 1422 |
|
| 1415 | 1423 |
template <typename Digraph, typename PartMap> |
| 1416 | 1424 |
class BipartitePartitionsVisitor : public BfsVisitor<Digraph> {
|
| 1417 | 1425 |
public: |
| 1418 | 1426 |
typedef typename Digraph::Arc Arc; |
| 1419 | 1427 |
typedef typename Digraph::Node Node; |
| 1420 | 1428 |
|
| 1421 | 1429 |
BipartitePartitionsVisitor(const Digraph& graph, |
| 1422 | 1430 |
PartMap& part, bool& bipartite) |
| 1423 | 1431 |
: _graph(graph), _part(part), _bipartite(bipartite) {}
|
| 1424 | 1432 |
|
| 1425 | 1433 |
void start(const Node& node) {
|
| 1426 | 1434 |
_part.set(node, true); |
| 1427 | 1435 |
} |
| 1428 | 1436 |
void discover(const Arc& edge) {
|
| 1429 | 1437 |
_part.set(_graph.target(edge), !_part[_graph.source(edge)]); |
| 1430 | 1438 |
} |
| 1431 | 1439 |
void examine(const Arc& edge) {
|
| 1432 | 1440 |
_bipartite = _bipartite && |
| 1433 | 1441 |
_part[_graph.target(edge)] != _part[_graph.source(edge)]; |
| 1434 | 1442 |
} |
| 1435 | 1443 |
|
| 1436 | 1444 |
private: |
| 1437 | 1445 |
|
| 1438 | 1446 |
const Digraph& _graph; |
| 1439 | 1447 |
PartMap& _part; |
| 1440 | 1448 |
bool& _bipartite; |
| 1441 | 1449 |
}; |
| 1442 | 1450 |
} |
| 1443 | 1451 |
|
| 1444 |
/// \ingroup |
|
| 1452 |
/// \ingroup graph_properties |
|
| 1445 | 1453 |
/// |
| 1446 | 1454 |
/// \brief Check if the given undirected graph is bipartite or not |
| 1447 | 1455 |
/// |
| 1448 | 1456 |
/// The function checks if the given undirected \c graph graph is bipartite |
| 1449 | 1457 |
/// or not. The \ref Bfs algorithm is used to calculate the result. |
| 1450 | 1458 |
/// \param graph The undirected graph. |
| 1451 | 1459 |
/// \return \c true if \c graph is bipartite, \c false otherwise. |
| 1452 | 1460 |
/// \sa bipartitePartitions |
| 1453 | 1461 |
template<typename Graph> |
| 1454 | 1462 |
inline bool bipartite(const Graph &graph){
|
| 1455 | 1463 |
using namespace _connectivity_bits; |
| 1456 | 1464 |
|
| 1457 | 1465 |
checkConcept<concepts::Graph, Graph>(); |
| 1458 | 1466 |
|
| 1459 | 1467 |
typedef typename Graph::NodeIt NodeIt; |
| 1460 | 1468 |
typedef typename Graph::ArcIt ArcIt; |
| 1461 | 1469 |
|
| 1462 | 1470 |
bool bipartite = true; |
| 1463 | 1471 |
|
| 1464 | 1472 |
BipartiteVisitor<Graph> |
| 1465 | 1473 |
visitor(graph, bipartite); |
| 1466 | 1474 |
BfsVisit<Graph, BipartiteVisitor<Graph> > |
| 1467 | 1475 |
bfs(graph, visitor); |
| 1468 | 1476 |
bfs.init(); |
| 1469 | 1477 |
for(NodeIt it(graph); it != INVALID; ++it) {
|
| 1470 | 1478 |
if(!bfs.reached(it)){
|
| 1471 | 1479 |
bfs.addSource(it); |
| 1472 | 1480 |
while (!bfs.emptyQueue()) {
|
| 1473 | 1481 |
bfs.processNextNode(); |
| 1474 | 1482 |
if (!bipartite) return false; |
| 1475 | 1483 |
} |
| 1476 | 1484 |
} |
| 1477 | 1485 |
} |
| 1478 | 1486 |
return true; |
| 1479 | 1487 |
} |
| 1480 | 1488 |
|
| 1481 |
/// \ingroup |
|
| 1489 |
/// \ingroup graph_properties |
|
| 1482 | 1490 |
/// |
| 1483 | 1491 |
/// \brief Check if the given undirected graph is bipartite or not |
| 1484 | 1492 |
/// |
| 1485 | 1493 |
/// The function checks if the given undirected graph is bipartite |
| 1486 | 1494 |
/// or not. The \ref Bfs algorithm is used to calculate the result. |
| 1487 | 1495 |
/// During the execution, the \c partMap will be set as the two |
| 1488 | 1496 |
/// partitions of the graph. |
| 1497 |
/// |
|
| 1498 |
/// \image html bipartite_partitions.png |
|
| 1499 |
/// \image latex bipartite_partitions.eps "Bipartite partititions" width=\textwidth |
|
| 1500 |
/// |
|
| 1489 | 1501 |
/// \param graph The undirected graph. |
| 1490 | 1502 |
/// \retval partMap A writable bool map of nodes. It will be set as the |
| 1491 | 1503 |
/// two partitions of the graph. |
| 1492 | 1504 |
/// \return \c true if \c graph is bipartite, \c false otherwise. |
| 1493 | 1505 |
template<typename Graph, typename NodeMap> |
| 1494 | 1506 |
inline bool bipartitePartitions(const Graph &graph, NodeMap &partMap){
|
| 1495 | 1507 |
using namespace _connectivity_bits; |
| 1496 | 1508 |
|
| 1497 | 1509 |
checkConcept<concepts::Graph, Graph>(); |
| 1498 | 1510 |
|
| 1499 | 1511 |
typedef typename Graph::Node Node; |
| 1500 | 1512 |
typedef typename Graph::NodeIt NodeIt; |
| 1501 | 1513 |
typedef typename Graph::ArcIt ArcIt; |
| 1502 | 1514 |
|
| 1503 | 1515 |
bool bipartite = true; |
| 1504 | 1516 |
|
| 1505 | 1517 |
BipartitePartitionsVisitor<Graph, NodeMap> |
| 1506 | 1518 |
visitor(graph, partMap, bipartite); |
| 1507 | 1519 |
BfsVisit<Graph, BipartitePartitionsVisitor<Graph, NodeMap> > |
| 1508 | 1520 |
bfs(graph, visitor); |
| 1509 | 1521 |
bfs.init(); |
| 1510 | 1522 |
for(NodeIt it(graph); it != INVALID; ++it) {
|
| 1511 | 1523 |
if(!bfs.reached(it)){
|
| 1512 | 1524 |
bfs.addSource(it); |
| 1513 | 1525 |
while (!bfs.emptyQueue()) {
|
| 1514 | 1526 |
bfs.processNextNode(); |
| 1515 | 1527 |
if (!bipartite) return false; |
| 1516 | 1528 |
} |
| 1517 | 1529 |
} |
| 1518 | 1530 |
} |
| 1519 | 1531 |
return true; |
| 1520 | 1532 |
} |
| 1521 | 1533 |
|
| 1522 | 1534 |
/// \brief Returns true when there are not loop edges in the graph. |
| 1523 | 1535 |
/// |
| 1524 | 1536 |
/// Returns true when there are not loop edges in the graph. |
| 1525 | 1537 |
template <typename Digraph> |
| 1526 | 1538 |
bool loopFree(const Digraph& digraph) {
|
| 1527 | 1539 |
for (typename Digraph::ArcIt it(digraph); it != INVALID; ++it) {
|
| 1528 | 1540 |
if (digraph.source(it) == digraph.target(it)) return false; |
| 1529 | 1541 |
} |
| 1530 | 1542 |
return true; |
| 1531 | 1543 |
} |
| 1532 | 1544 |
|
| 1533 | 1545 |
/// \brief Returns true when there are not parallel edges in the graph. |
| 1534 | 1546 |
/// |
| 1535 | 1547 |
/// Returns true when there are not parallel edges in the graph. |
| 1536 | 1548 |
template <typename Digraph> |
| ... | ... |
@@ -1270,273 +1270,273 @@ |
| 1270 | 1270 |
bool operator()(Arc a,Arc b) const |
| 1271 | 1271 |
{
|
| 1272 | 1272 |
return g.target(a)<g.target(b); |
| 1273 | 1273 |
} |
| 1274 | 1274 |
}; |
| 1275 | 1275 |
|
| 1276 | 1276 |
public: |
| 1277 | 1277 |
|
| 1278 | 1278 |
///Constructor |
| 1279 | 1279 |
|
| 1280 | 1280 |
///Constructor. |
| 1281 | 1281 |
/// |
| 1282 | 1282 |
///It builds up the search database. |
| 1283 | 1283 |
DynArcLookUp(const Digraph &g) |
| 1284 | 1284 |
: _g(g),_head(g),_parent(g),_left(g),_right(g) |
| 1285 | 1285 |
{
|
| 1286 | 1286 |
Parent::attach(_g.notifier(typename Digraph::Arc())); |
| 1287 | 1287 |
refresh(); |
| 1288 | 1288 |
} |
| 1289 | 1289 |
|
| 1290 | 1290 |
protected: |
| 1291 | 1291 |
|
| 1292 | 1292 |
virtual void add(const Arc& arc) {
|
| 1293 | 1293 |
insert(arc); |
| 1294 | 1294 |
} |
| 1295 | 1295 |
|
| 1296 | 1296 |
virtual void add(const std::vector<Arc>& arcs) {
|
| 1297 | 1297 |
for (int i = 0; i < int(arcs.size()); ++i) {
|
| 1298 | 1298 |
insert(arcs[i]); |
| 1299 | 1299 |
} |
| 1300 | 1300 |
} |
| 1301 | 1301 |
|
| 1302 | 1302 |
virtual void erase(const Arc& arc) {
|
| 1303 | 1303 |
remove(arc); |
| 1304 | 1304 |
} |
| 1305 | 1305 |
|
| 1306 | 1306 |
virtual void erase(const std::vector<Arc>& arcs) {
|
| 1307 | 1307 |
for (int i = 0; i < int(arcs.size()); ++i) {
|
| 1308 | 1308 |
remove(arcs[i]); |
| 1309 | 1309 |
} |
| 1310 | 1310 |
} |
| 1311 | 1311 |
|
| 1312 | 1312 |
virtual void build() {
|
| 1313 | 1313 |
refresh(); |
| 1314 | 1314 |
} |
| 1315 | 1315 |
|
| 1316 | 1316 |
virtual void clear() {
|
| 1317 | 1317 |
for(NodeIt n(_g);n!=INVALID;++n) {
|
| 1318 |
_head |
|
| 1318 |
_head[n] = INVALID; |
|
| 1319 | 1319 |
} |
| 1320 | 1320 |
} |
| 1321 | 1321 |
|
| 1322 | 1322 |
void insert(Arc arc) {
|
| 1323 | 1323 |
Node s = _g.source(arc); |
| 1324 | 1324 |
Node t = _g.target(arc); |
| 1325 |
_left.set(arc, INVALID); |
|
| 1326 |
_right.set(arc, INVALID); |
|
| 1325 |
_left[arc] = INVALID; |
|
| 1326 |
_right[arc] = INVALID; |
|
| 1327 | 1327 |
|
| 1328 | 1328 |
Arc e = _head[s]; |
| 1329 | 1329 |
if (e == INVALID) {
|
| 1330 |
_head.set(s, arc); |
|
| 1331 |
_parent.set(arc, INVALID); |
|
| 1330 |
_head[s] = arc; |
|
| 1331 |
_parent[arc] = INVALID; |
|
| 1332 | 1332 |
return; |
| 1333 | 1333 |
} |
| 1334 | 1334 |
while (true) {
|
| 1335 | 1335 |
if (t < _g.target(e)) {
|
| 1336 | 1336 |
if (_left[e] == INVALID) {
|
| 1337 |
_left.set(e, arc); |
|
| 1338 |
_parent.set(arc, e); |
|
| 1337 |
_left[e] = arc; |
|
| 1338 |
_parent[arc] = e; |
|
| 1339 | 1339 |
splay(arc); |
| 1340 | 1340 |
return; |
| 1341 | 1341 |
} else {
|
| 1342 | 1342 |
e = _left[e]; |
| 1343 | 1343 |
} |
| 1344 | 1344 |
} else {
|
| 1345 | 1345 |
if (_right[e] == INVALID) {
|
| 1346 |
_right.set(e, arc); |
|
| 1347 |
_parent.set(arc, e); |
|
| 1346 |
_right[e] = arc; |
|
| 1347 |
_parent[arc] = e; |
|
| 1348 | 1348 |
splay(arc); |
| 1349 | 1349 |
return; |
| 1350 | 1350 |
} else {
|
| 1351 | 1351 |
e = _right[e]; |
| 1352 | 1352 |
} |
| 1353 | 1353 |
} |
| 1354 | 1354 |
} |
| 1355 | 1355 |
} |
| 1356 | 1356 |
|
| 1357 | 1357 |
void remove(Arc arc) {
|
| 1358 | 1358 |
if (_left[arc] == INVALID) {
|
| 1359 | 1359 |
if (_right[arc] != INVALID) {
|
| 1360 |
_parent |
|
| 1360 |
_parent[_right[arc]] = _parent[arc]; |
|
| 1361 | 1361 |
} |
| 1362 | 1362 |
if (_parent[arc] != INVALID) {
|
| 1363 | 1363 |
if (_left[_parent[arc]] == arc) {
|
| 1364 |
_left |
|
| 1364 |
_left[_parent[arc]] = _right[arc]; |
|
| 1365 | 1365 |
} else {
|
| 1366 |
_right |
|
| 1366 |
_right[_parent[arc]] = _right[arc]; |
|
| 1367 | 1367 |
} |
| 1368 | 1368 |
} else {
|
| 1369 |
_head |
|
| 1369 |
_head[_g.source(arc)] = _right[arc]; |
|
| 1370 | 1370 |
} |
| 1371 | 1371 |
} else if (_right[arc] == INVALID) {
|
| 1372 |
_parent |
|
| 1372 |
_parent[_left[arc]] = _parent[arc]; |
|
| 1373 | 1373 |
if (_parent[arc] != INVALID) {
|
| 1374 | 1374 |
if (_left[_parent[arc]] == arc) {
|
| 1375 |
_left |
|
| 1375 |
_left[_parent[arc]] = _left[arc]; |
|
| 1376 | 1376 |
} else {
|
| 1377 |
_right |
|
| 1377 |
_right[_parent[arc]] = _left[arc]; |
|
| 1378 | 1378 |
} |
| 1379 | 1379 |
} else {
|
| 1380 |
_head |
|
| 1380 |
_head[_g.source(arc)] = _left[arc]; |
|
| 1381 | 1381 |
} |
| 1382 | 1382 |
} else {
|
| 1383 | 1383 |
Arc e = _left[arc]; |
| 1384 | 1384 |
if (_right[e] != INVALID) {
|
| 1385 | 1385 |
e = _right[e]; |
| 1386 | 1386 |
while (_right[e] != INVALID) {
|
| 1387 | 1387 |
e = _right[e]; |
| 1388 | 1388 |
} |
| 1389 | 1389 |
Arc s = _parent[e]; |
| 1390 |
_right |
|
| 1390 |
_right[_parent[e]] = _left[e]; |
|
| 1391 | 1391 |
if (_left[e] != INVALID) {
|
| 1392 |
_parent |
|
| 1392 |
_parent[_left[e]] = _parent[e]; |
|
| 1393 | 1393 |
} |
| 1394 | 1394 |
|
| 1395 |
_left.set(e, _left[arc]); |
|
| 1396 |
_parent.set(_left[arc], e); |
|
| 1397 |
_right.set(e, _right[arc]); |
|
| 1398 |
_parent.set(_right[arc], e); |
|
| 1395 |
_left[e] = _left[arc]; |
|
| 1396 |
_parent[_left[arc]] = e; |
|
| 1397 |
_right[e] = _right[arc]; |
|
| 1398 |
_parent[_right[arc]] = e; |
|
| 1399 | 1399 |
|
| 1400 |
_parent |
|
| 1400 |
_parent[e] = _parent[arc]; |
|
| 1401 | 1401 |
if (_parent[arc] != INVALID) {
|
| 1402 | 1402 |
if (_left[_parent[arc]] == arc) {
|
| 1403 |
_left |
|
| 1403 |
_left[_parent[arc]] = e; |
|
| 1404 | 1404 |
} else {
|
| 1405 |
_right |
|
| 1405 |
_right[_parent[arc]] = e; |
|
| 1406 | 1406 |
} |
| 1407 | 1407 |
} |
| 1408 | 1408 |
splay(s); |
| 1409 | 1409 |
} else {
|
| 1410 |
_right.set(e, _right[arc]); |
|
| 1411 |
_parent.set(_right[arc], e); |
|
| 1412 |
|
|
| 1410 |
_right[e] = _right[arc]; |
|
| 1411 |
_parent[_right[arc]] = e; |
|
| 1412 |
_parent[e] = _parent[arc]; |
|
| 1413 | 1413 |
|
| 1414 | 1414 |
if (_parent[arc] != INVALID) {
|
| 1415 | 1415 |
if (_left[_parent[arc]] == arc) {
|
| 1416 |
_left |
|
| 1416 |
_left[_parent[arc]] = e; |
|
| 1417 | 1417 |
} else {
|
| 1418 |
_right |
|
| 1418 |
_right[_parent[arc]] = e; |
|
| 1419 | 1419 |
} |
| 1420 | 1420 |
} else {
|
| 1421 |
_head |
|
| 1421 |
_head[_g.source(arc)] = e; |
|
| 1422 | 1422 |
} |
| 1423 | 1423 |
} |
| 1424 | 1424 |
} |
| 1425 | 1425 |
} |
| 1426 | 1426 |
|
| 1427 | 1427 |
Arc refreshRec(std::vector<Arc> &v,int a,int b) |
| 1428 | 1428 |
{
|
| 1429 | 1429 |
int m=(a+b)/2; |
| 1430 | 1430 |
Arc me=v[m]; |
| 1431 | 1431 |
if (a < m) {
|
| 1432 | 1432 |
Arc left = refreshRec(v,a,m-1); |
| 1433 |
_left.set(me, left); |
|
| 1434 |
_parent.set(left, me); |
|
| 1433 |
_left[me] = left; |
|
| 1434 |
_parent[left] = me; |
|
| 1435 | 1435 |
} else {
|
| 1436 |
_left |
|
| 1436 |
_left[me] = INVALID; |
|
| 1437 | 1437 |
} |
| 1438 | 1438 |
if (m < b) {
|
| 1439 | 1439 |
Arc right = refreshRec(v,m+1,b); |
| 1440 |
_right.set(me, right); |
|
| 1441 |
_parent.set(right, me); |
|
| 1440 |
_right[me] = right; |
|
| 1441 |
_parent[right] = me; |
|
| 1442 | 1442 |
} else {
|
| 1443 |
_right |
|
| 1443 |
_right[me] = INVALID; |
|
| 1444 | 1444 |
} |
| 1445 | 1445 |
return me; |
| 1446 | 1446 |
} |
| 1447 | 1447 |
|
| 1448 | 1448 |
void refresh() {
|
| 1449 | 1449 |
for(NodeIt n(_g);n!=INVALID;++n) {
|
| 1450 | 1450 |
std::vector<Arc> v; |
| 1451 | 1451 |
for(OutArcIt a(_g,n);a!=INVALID;++a) v.push_back(a); |
| 1452 | 1452 |
if (!v.empty()) {
|
| 1453 | 1453 |
std::sort(v.begin(),v.end(),ArcLess(_g)); |
| 1454 | 1454 |
Arc head = refreshRec(v,0,v.size()-1); |
| 1455 |
_head.set(n, head); |
|
| 1456 |
_parent.set(head, INVALID); |
|
| 1455 |
_head[n] = head; |
|
| 1456 |
_parent[head] = INVALID; |
|
| 1457 | 1457 |
} |
| 1458 |
else _head |
|
| 1458 |
else _head[n] = INVALID; |
|
| 1459 | 1459 |
} |
| 1460 | 1460 |
} |
| 1461 | 1461 |
|
| 1462 | 1462 |
void zig(Arc v) {
|
| 1463 | 1463 |
Arc w = _parent[v]; |
| 1464 |
_parent.set(v, _parent[w]); |
|
| 1465 |
_parent.set(w, v); |
|
| 1466 |
_left.set(w, _right[v]); |
|
| 1467 |
_right.set(v, w); |
|
| 1464 |
_parent[v] = _parent[w]; |
|
| 1465 |
_parent[w] = v; |
|
| 1466 |
_left[w] = _right[v]; |
|
| 1467 |
_right[v] = w; |
|
| 1468 | 1468 |
if (_parent[v] != INVALID) {
|
| 1469 | 1469 |
if (_right[_parent[v]] == w) {
|
| 1470 |
_right |
|
| 1470 |
_right[_parent[v]] = v; |
|
| 1471 | 1471 |
} else {
|
| 1472 |
_left |
|
| 1472 |
_left[_parent[v]] = v; |
|
| 1473 | 1473 |
} |
| 1474 | 1474 |
} |
| 1475 | 1475 |
if (_left[w] != INVALID){
|
| 1476 |
_parent |
|
| 1476 |
_parent[_left[w]] = w; |
|
| 1477 | 1477 |
} |
| 1478 | 1478 |
} |
| 1479 | 1479 |
|
| 1480 | 1480 |
void zag(Arc v) {
|
| 1481 | 1481 |
Arc w = _parent[v]; |
| 1482 |
_parent.set(v, _parent[w]); |
|
| 1483 |
_parent.set(w, v); |
|
| 1484 |
_right.set(w, _left[v]); |
|
| 1485 |
_left.set(v, w); |
|
| 1482 |
_parent[v] = _parent[w]; |
|
| 1483 |
_parent[w] = v; |
|
| 1484 |
_right[w] = _left[v]; |
|
| 1485 |
_left[v] = w; |
|
| 1486 | 1486 |
if (_parent[v] != INVALID){
|
| 1487 | 1487 |
if (_left[_parent[v]] == w) {
|
| 1488 |
_left |
|
| 1488 |
_left[_parent[v]] = v; |
|
| 1489 | 1489 |
} else {
|
| 1490 |
_right |
|
| 1490 |
_right[_parent[v]] = v; |
|
| 1491 | 1491 |
} |
| 1492 | 1492 |
} |
| 1493 | 1493 |
if (_right[w] != INVALID){
|
| 1494 |
_parent |
|
| 1494 |
_parent[_right[w]] = w; |
|
| 1495 | 1495 |
} |
| 1496 | 1496 |
} |
| 1497 | 1497 |
|
| 1498 | 1498 |
void splay(Arc v) {
|
| 1499 | 1499 |
while (_parent[v] != INVALID) {
|
| 1500 | 1500 |
if (v == _left[_parent[v]]) {
|
| 1501 | 1501 |
if (_parent[_parent[v]] == INVALID) {
|
| 1502 | 1502 |
zig(v); |
| 1503 | 1503 |
} else {
|
| 1504 | 1504 |
if (_parent[v] == _left[_parent[_parent[v]]]) {
|
| 1505 | 1505 |
zig(_parent[v]); |
| 1506 | 1506 |
zig(v); |
| 1507 | 1507 |
} else {
|
| 1508 | 1508 |
zig(v); |
| 1509 | 1509 |
zag(v); |
| 1510 | 1510 |
} |
| 1511 | 1511 |
} |
| 1512 | 1512 |
} else {
|
| 1513 | 1513 |
if (_parent[_parent[v]] == INVALID) {
|
| 1514 | 1514 |
zag(v); |
| 1515 | 1515 |
} else {
|
| 1516 | 1516 |
if (_parent[v] == _left[_parent[_parent[v]]]) {
|
| 1517 | 1517 |
zag(v); |
| 1518 | 1518 |
zig(v); |
| 1519 | 1519 |
} else {
|
| 1520 | 1520 |
zag(_parent[v]); |
| 1521 | 1521 |
zag(v); |
| 1522 | 1522 |
} |
| 1523 | 1523 |
} |
| 1524 | 1524 |
} |
| 1525 | 1525 |
} |
| 1526 | 1526 |
_head[_g.source(v)] = v; |
| 1527 | 1527 |
} |
| 1528 | 1528 |
|
| 1529 | 1529 |
|
| 1530 | 1530 |
public: |
| 1531 | 1531 |
|
| 1532 | 1532 |
///Find an arc between two nodes. |
| 1533 | 1533 |
|
| 1534 | 1534 |
///Find an arc between two nodes. |
| 1535 | 1535 |
///\param s The source node. |
| 1536 | 1536 |
///\param t The target node. |
| 1537 | 1537 |
///\param p The previous arc between \c s and \c t. It it is INVALID or |
| 1538 | 1538 |
///not given, the operator finds the first appropriate arc. |
| 1539 | 1539 |
///\return An arc from \c s to \c t after \c p or |
| 1540 | 1540 |
///\ref INVALID if there is no more. |
| 1541 | 1541 |
/// |
| 1542 | 1542 |
///For example, you can count the number of arcs from \c u to \c v in the |
| ... | ... |
@@ -27,110 +27,113 @@ |
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 | 29 |
|
| 30 | 30 |
///\file |
| 31 | 31 |
///\brief Implementation of the LEMON-CPLEX lp solver interface. |
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
CplexEnv::LicenseError::LicenseError(int status) {
|
| 35 | 35 |
if (!CPXgeterrorstring(0, status, _message)) {
|
| 36 | 36 |
std::strcpy(_message, "Cplex unknown error"); |
| 37 | 37 |
} |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
CplexEnv::CplexEnv() {
|
| 41 | 41 |
int status; |
| 42 | 42 |
_cnt = new int; |
| 43 | 43 |
_env = CPXopenCPLEX(&status); |
| 44 | 44 |
if (_env == 0) {
|
| 45 | 45 |
delete _cnt; |
| 46 | 46 |
_cnt = 0; |
| 47 | 47 |
throw LicenseError(status); |
| 48 | 48 |
} |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
CplexEnv::CplexEnv(const CplexEnv& other) {
|
| 52 | 52 |
_env = other._env; |
| 53 | 53 |
_cnt = other._cnt; |
| 54 | 54 |
++(*_cnt); |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
CplexEnv& CplexEnv::operator=(const CplexEnv& other) {
|
| 58 | 58 |
_env = other._env; |
| 59 | 59 |
_cnt = other._cnt; |
| 60 | 60 |
++(*_cnt); |
| 61 | 61 |
return *this; |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
CplexEnv::~CplexEnv() {
|
| 65 | 65 |
--(*_cnt); |
| 66 | 66 |
if (*_cnt == 0) {
|
| 67 | 67 |
delete _cnt; |
| 68 | 68 |
CPXcloseCPLEX(&_env); |
| 69 | 69 |
} |
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 | 72 |
CplexBase::CplexBase() : LpBase() {
|
| 73 | 73 |
int status; |
| 74 | 74 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
| 75 |
messageLevel(MESSAGE_NOTHING); |
|
| 75 | 76 |
} |
| 76 | 77 |
|
| 77 | 78 |
CplexBase::CplexBase(const CplexEnv& env) |
| 78 | 79 |
: LpBase(), _env(env) {
|
| 79 | 80 |
int status; |
| 80 | 81 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
| 82 |
messageLevel(MESSAGE_NOTHING); |
|
| 81 | 83 |
} |
| 82 | 84 |
|
| 83 | 85 |
CplexBase::CplexBase(const CplexBase& cplex) |
| 84 | 86 |
: LpBase() {
|
| 85 | 87 |
int status; |
| 86 | 88 |
_prob = CPXcloneprob(cplexEnv(), cplex._prob, &status); |
| 87 | 89 |
rows = cplex.rows; |
| 88 | 90 |
cols = cplex.cols; |
| 91 |
messageLevel(MESSAGE_NOTHING); |
|
| 89 | 92 |
} |
| 90 | 93 |
|
| 91 | 94 |
CplexBase::~CplexBase() {
|
| 92 | 95 |
CPXfreeprob(cplexEnv(),&_prob); |
| 93 | 96 |
} |
| 94 | 97 |
|
| 95 | 98 |
int CplexBase::_addCol() {
|
| 96 | 99 |
int i = CPXgetnumcols(cplexEnv(), _prob); |
| 97 | 100 |
double lb = -INF, ub = INF; |
| 98 | 101 |
CPXnewcols(cplexEnv(), _prob, 1, 0, &lb, &ub, 0, 0); |
| 99 | 102 |
return i; |
| 100 | 103 |
} |
| 101 | 104 |
|
| 102 | 105 |
|
| 103 | 106 |
int CplexBase::_addRow() {
|
| 104 | 107 |
int i = CPXgetnumrows(cplexEnv(), _prob); |
| 105 | 108 |
const double ub = INF; |
| 106 | 109 |
const char s = 'L'; |
| 107 | 110 |
CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); |
| 108 | 111 |
return i; |
| 109 | 112 |
} |
| 110 | 113 |
|
| 111 | 114 |
|
| 112 | 115 |
void CplexBase::_eraseCol(int i) {
|
| 113 | 116 |
CPXdelcols(cplexEnv(), _prob, i, i); |
| 114 | 117 |
} |
| 115 | 118 |
|
| 116 | 119 |
void CplexBase::_eraseRow(int i) {
|
| 117 | 120 |
CPXdelrows(cplexEnv(), _prob, i, i); |
| 118 | 121 |
} |
| 119 | 122 |
|
| 120 | 123 |
void CplexBase::_eraseColId(int i) {
|
| 121 | 124 |
cols.eraseIndex(i); |
| 122 | 125 |
cols.shiftIndices(i); |
| 123 | 126 |
} |
| 124 | 127 |
void CplexBase::_eraseRowId(int i) {
|
| 125 | 128 |
rows.eraseIndex(i); |
| 126 | 129 |
rows.shiftIndices(i); |
| 127 | 130 |
} |
| 128 | 131 |
|
| 129 | 132 |
void CplexBase::_getColName(int col, std::string &name) const {
|
| 130 | 133 |
int size; |
| 131 | 134 |
CPXgetcolname(cplexEnv(), _prob, 0, 0, 0, &size, col, col); |
| 132 | 135 |
if (size == 0) {
|
| 133 | 136 |
name.clear(); |
| 134 | 137 |
return; |
| 135 | 138 |
} |
| 136 | 139 |
|
| ... | ... |
@@ -393,410 +396,432 @@ |
| 393 | 396 |
++b; |
| 394 | 397 |
} |
| 395 | 398 |
} |
| 396 | 399 |
} |
| 397 | 400 |
|
| 398 | 401 |
void CplexBase::_setObjCoeff(int i, Value obj_coef) |
| 399 | 402 |
{
|
| 400 | 403 |
CPXchgobj(cplexEnv(), _prob, 1, &i, &obj_coef); |
| 401 | 404 |
} |
| 402 | 405 |
|
| 403 | 406 |
CplexBase::Value CplexBase::_getObjCoeff(int i) const |
| 404 | 407 |
{
|
| 405 | 408 |
Value x; |
| 406 | 409 |
CPXgetobj(cplexEnv(), _prob, &x, i, i); |
| 407 | 410 |
return x; |
| 408 | 411 |
} |
| 409 | 412 |
|
| 410 | 413 |
void CplexBase::_setSense(CplexBase::Sense sense) {
|
| 411 | 414 |
switch (sense) {
|
| 412 | 415 |
case MIN: |
| 413 | 416 |
CPXchgobjsen(cplexEnv(), _prob, CPX_MIN); |
| 414 | 417 |
break; |
| 415 | 418 |
case MAX: |
| 416 | 419 |
CPXchgobjsen(cplexEnv(), _prob, CPX_MAX); |
| 417 | 420 |
break; |
| 418 | 421 |
} |
| 419 | 422 |
} |
| 420 | 423 |
|
| 421 | 424 |
CplexBase::Sense CplexBase::_getSense() const {
|
| 422 | 425 |
switch (CPXgetobjsen(cplexEnv(), _prob)) {
|
| 423 | 426 |
case CPX_MIN: |
| 424 | 427 |
return MIN; |
| 425 | 428 |
case CPX_MAX: |
| 426 | 429 |
return MAX; |
| 427 | 430 |
default: |
| 428 | 431 |
LEMON_ASSERT(false, "Invalid sense"); |
| 429 | 432 |
return CplexBase::Sense(); |
| 430 | 433 |
} |
| 431 | 434 |
} |
| 432 | 435 |
|
| 433 | 436 |
void CplexBase::_clear() {
|
| 434 | 437 |
CPXfreeprob(cplexEnv(),&_prob); |
| 435 | 438 |
int status; |
| 436 | 439 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
| 437 | 440 |
rows.clear(); |
| 438 | 441 |
cols.clear(); |
| 439 | 442 |
} |
| 440 | 443 |
|
| 444 |
void CplexBase::_messageLevel(MessageLevel level) {
|
|
| 445 |
switch (level) {
|
|
| 446 |
case MESSAGE_NOTHING: |
|
| 447 |
_message_enabled = false; |
|
| 448 |
break; |
|
| 449 |
case MESSAGE_ERROR: |
|
| 450 |
case MESSAGE_WARNING: |
|
| 451 |
case MESSAGE_NORMAL: |
|
| 452 |
case MESSAGE_VERBOSE: |
|
| 453 |
_message_enabled = true; |
|
| 454 |
break; |
|
| 455 |
} |
|
| 456 |
} |
|
| 457 |
|
|
| 458 |
void CplexBase::_applyMessageLevel() {
|
|
| 459 |
CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, |
|
| 460 |
_message_enabled ? CPX_ON : CPX_OFF); |
|
| 461 |
} |
|
| 462 |
|
|
| 441 | 463 |
// CplexLp members |
| 442 | 464 |
|
| 443 | 465 |
CplexLp::CplexLp() |
| 444 | 466 |
: LpBase(), LpSolver(), CplexBase() {}
|
| 445 | 467 |
|
| 446 | 468 |
CplexLp::CplexLp(const CplexEnv& env) |
| 447 | 469 |
: LpBase(), LpSolver(), CplexBase(env) {}
|
| 448 | 470 |
|
| 449 | 471 |
CplexLp::CplexLp(const CplexLp& other) |
| 450 | 472 |
: LpBase(), LpSolver(), CplexBase(other) {}
|
| 451 | 473 |
|
| 452 | 474 |
CplexLp::~CplexLp() {}
|
| 453 | 475 |
|
| 454 | 476 |
CplexLp* CplexLp::newSolver() const { return new CplexLp; }
|
| 455 | 477 |
CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); }
|
| 456 | 478 |
|
| 457 | 479 |
const char* CplexLp::_solverName() const { return "CplexLp"; }
|
| 458 | 480 |
|
| 459 | 481 |
void CplexLp::_clear_temporals() {
|
| 460 | 482 |
_col_status.clear(); |
| 461 | 483 |
_row_status.clear(); |
| 462 | 484 |
_primal_ray.clear(); |
| 463 | 485 |
_dual_ray.clear(); |
| 464 | 486 |
} |
| 465 | 487 |
|
| 466 | 488 |
// The routine returns zero unless an error occurred during the |
| 467 | 489 |
// optimization. Examples of errors include exhausting available |
| 468 | 490 |
// memory (CPXERR_NO_MEMORY) or encountering invalid data in the |
| 469 | 491 |
// CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a |
| 470 | 492 |
// user-specified CPLEX limit, or proving the model infeasible or |
| 471 | 493 |
// unbounded, are not considered errors. Note that a zero return |
| 472 | 494 |
// value does not necessarily mean that a solution exists. Use query |
| 473 | 495 |
// routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain |
| 474 | 496 |
// further information about the status of the optimization. |
| 475 | 497 |
CplexLp::SolveExitStatus CplexLp::convertStatus(int status) {
|
| 476 | 498 |
#if CPX_VERSION >= 800 |
| 477 | 499 |
if (status == 0) {
|
| 478 | 500 |
switch (CPXgetstat(cplexEnv(), _prob)) {
|
| 479 | 501 |
case CPX_STAT_OPTIMAL: |
| 480 | 502 |
case CPX_STAT_INFEASIBLE: |
| 481 | 503 |
case CPX_STAT_UNBOUNDED: |
| 482 | 504 |
return SOLVED; |
| 483 | 505 |
default: |
| 484 | 506 |
return UNSOLVED; |
| 485 | 507 |
} |
| 486 | 508 |
} else {
|
| 487 | 509 |
return UNSOLVED; |
| 488 | 510 |
} |
| 489 | 511 |
#else |
| 490 | 512 |
if (status == 0) {
|
| 491 | 513 |
//We want to exclude some cases |
| 492 | 514 |
switch (CPXgetstat(cplexEnv(), _prob)) {
|
| 493 | 515 |
case CPX_OBJ_LIM: |
| 494 | 516 |
case CPX_IT_LIM_FEAS: |
| 495 | 517 |
case CPX_IT_LIM_INFEAS: |
| 496 | 518 |
case CPX_TIME_LIM_FEAS: |
| 497 | 519 |
case CPX_TIME_LIM_INFEAS: |
| 498 | 520 |
return UNSOLVED; |
| 499 | 521 |
default: |
| 500 | 522 |
return SOLVED; |
| 501 | 523 |
} |
| 502 | 524 |
} else {
|
| 503 | 525 |
return UNSOLVED; |
| 504 | 526 |
} |
| 505 | 527 |
#endif |
| 506 | 528 |
} |
| 507 | 529 |
|
| 508 | 530 |
CplexLp::SolveExitStatus CplexLp::_solve() {
|
| 509 | 531 |
_clear_temporals(); |
| 532 |
_applyMessageLevel(); |
|
| 510 | 533 |
return convertStatus(CPXlpopt(cplexEnv(), _prob)); |
| 511 | 534 |
} |
| 512 | 535 |
|
| 513 | 536 |
CplexLp::SolveExitStatus CplexLp::solvePrimal() {
|
| 514 | 537 |
_clear_temporals(); |
| 538 |
_applyMessageLevel(); |
|
| 515 | 539 |
return convertStatus(CPXprimopt(cplexEnv(), _prob)); |
| 516 | 540 |
} |
| 517 | 541 |
|
| 518 | 542 |
CplexLp::SolveExitStatus CplexLp::solveDual() {
|
| 519 | 543 |
_clear_temporals(); |
| 544 |
_applyMessageLevel(); |
|
| 520 | 545 |
return convertStatus(CPXdualopt(cplexEnv(), _prob)); |
| 521 | 546 |
} |
| 522 | 547 |
|
| 523 | 548 |
CplexLp::SolveExitStatus CplexLp::solveBarrier() {
|
| 524 | 549 |
_clear_temporals(); |
| 550 |
_applyMessageLevel(); |
|
| 525 | 551 |
return convertStatus(CPXbaropt(cplexEnv(), _prob)); |
| 526 | 552 |
} |
| 527 | 553 |
|
| 528 | 554 |
CplexLp::Value CplexLp::_getPrimal(int i) const {
|
| 529 | 555 |
Value x; |
| 530 | 556 |
CPXgetx(cplexEnv(), _prob, &x, i, i); |
| 531 | 557 |
return x; |
| 532 | 558 |
} |
| 533 | 559 |
|
| 534 | 560 |
CplexLp::Value CplexLp::_getDual(int i) const {
|
| 535 | 561 |
Value y; |
| 536 | 562 |
CPXgetpi(cplexEnv(), _prob, &y, i, i); |
| 537 | 563 |
return y; |
| 538 | 564 |
} |
| 539 | 565 |
|
| 540 | 566 |
CplexLp::Value CplexLp::_getPrimalValue() const {
|
| 541 | 567 |
Value objval; |
| 542 | 568 |
CPXgetobjval(cplexEnv(), _prob, &objval); |
| 543 | 569 |
return objval; |
| 544 | 570 |
} |
| 545 | 571 |
|
| 546 | 572 |
CplexLp::VarStatus CplexLp::_getColStatus(int i) const {
|
| 547 | 573 |
if (_col_status.empty()) {
|
| 548 | 574 |
_col_status.resize(CPXgetnumcols(cplexEnv(), _prob)); |
| 549 | 575 |
CPXgetbase(cplexEnv(), _prob, &_col_status.front(), 0); |
| 550 | 576 |
} |
| 551 | 577 |
switch (_col_status[i]) {
|
| 552 | 578 |
case CPX_BASIC: |
| 553 | 579 |
return BASIC; |
| 554 | 580 |
case CPX_FREE_SUPER: |
| 555 | 581 |
return FREE; |
| 556 | 582 |
case CPX_AT_LOWER: |
| 557 | 583 |
return LOWER; |
| 558 | 584 |
case CPX_AT_UPPER: |
| 559 | 585 |
return UPPER; |
| 560 | 586 |
default: |
| 561 | 587 |
LEMON_ASSERT(false, "Wrong column status"); |
| 562 | 588 |
return CplexLp::VarStatus(); |
| 563 | 589 |
} |
| 564 | 590 |
} |
| 565 | 591 |
|
| 566 | 592 |
CplexLp::VarStatus CplexLp::_getRowStatus(int i) const {
|
| 567 | 593 |
if (_row_status.empty()) {
|
| 568 | 594 |
_row_status.resize(CPXgetnumrows(cplexEnv(), _prob)); |
| 569 | 595 |
CPXgetbase(cplexEnv(), _prob, 0, &_row_status.front()); |
| 570 | 596 |
} |
| 571 | 597 |
switch (_row_status[i]) {
|
| 572 | 598 |
case CPX_BASIC: |
| 573 | 599 |
return BASIC; |
| 574 | 600 |
case CPX_AT_LOWER: |
| 575 | 601 |
{
|
| 576 | 602 |
char s; |
| 577 | 603 |
CPXgetsense(cplexEnv(), _prob, &s, i, i); |
| 578 | 604 |
return s != 'L' ? LOWER : UPPER; |
| 579 | 605 |
} |
| 580 | 606 |
case CPX_AT_UPPER: |
| 581 | 607 |
return UPPER; |
| 582 | 608 |
default: |
| 583 | 609 |
LEMON_ASSERT(false, "Wrong row status"); |
| 584 | 610 |
return CplexLp::VarStatus(); |
| 585 | 611 |
} |
| 586 | 612 |
} |
| 587 | 613 |
|
| 588 | 614 |
CplexLp::Value CplexLp::_getPrimalRay(int i) const {
|
| 589 | 615 |
if (_primal_ray.empty()) {
|
| 590 | 616 |
_primal_ray.resize(CPXgetnumcols(cplexEnv(), _prob)); |
| 591 | 617 |
CPXgetray(cplexEnv(), _prob, &_primal_ray.front()); |
| 592 | 618 |
} |
| 593 | 619 |
return _primal_ray[i]; |
| 594 | 620 |
} |
| 595 | 621 |
|
| 596 | 622 |
CplexLp::Value CplexLp::_getDualRay(int i) const {
|
| 597 | 623 |
if (_dual_ray.empty()) {
|
| 598 | 624 |
|
| 599 | 625 |
} |
| 600 | 626 |
return _dual_ray[i]; |
| 601 | 627 |
} |
| 602 | 628 |
|
| 603 |
// |
|
| 629 |
// Cplex 7.0 status values |
|
| 604 | 630 |
// This table lists the statuses, returned by the CPXgetstat() |
| 605 | 631 |
// routine, for solutions to LP problems or mixed integer problems. If |
| 606 | 632 |
// no solution exists, the return value is zero. |
| 607 | 633 |
|
| 608 | 634 |
// For Simplex, Barrier |
| 609 | 635 |
// 1 CPX_OPTIMAL |
| 610 | 636 |
// Optimal solution found |
| 611 | 637 |
// 2 CPX_INFEASIBLE |
| 612 | 638 |
// Problem infeasible |
| 613 | 639 |
// 3 CPX_UNBOUNDED |
| 614 | 640 |
// Problem unbounded |
| 615 | 641 |
// 4 CPX_OBJ_LIM |
| 616 | 642 |
// Objective limit exceeded in Phase II |
| 617 | 643 |
// 5 CPX_IT_LIM_FEAS |
| 618 | 644 |
// Iteration limit exceeded in Phase II |
| 619 | 645 |
// 6 CPX_IT_LIM_INFEAS |
| 620 | 646 |
// Iteration limit exceeded in Phase I |
| 621 | 647 |
// 7 CPX_TIME_LIM_FEAS |
| 622 | 648 |
// Time limit exceeded in Phase II |
| 623 | 649 |
// 8 CPX_TIME_LIM_INFEAS |
| 624 | 650 |
// Time limit exceeded in Phase I |
| 625 | 651 |
// 9 CPX_NUM_BEST_FEAS |
| 626 | 652 |
// Problem non-optimal, singularities in Phase II |
| 627 | 653 |
// 10 CPX_NUM_BEST_INFEAS |
| 628 | 654 |
// Problem non-optimal, singularities in Phase I |
| 629 | 655 |
// 11 CPX_OPTIMAL_INFEAS |
| 630 | 656 |
// Optimal solution found, unscaled infeasibilities |
| 631 | 657 |
// 12 CPX_ABORT_FEAS |
| 632 | 658 |
// Aborted in Phase II |
| 633 | 659 |
// 13 CPX_ABORT_INFEAS |
| 634 | 660 |
// Aborted in Phase I |
| 635 | 661 |
// 14 CPX_ABORT_DUAL_INFEAS |
| 636 | 662 |
// Aborted in barrier, dual infeasible |
| 637 | 663 |
// 15 CPX_ABORT_PRIM_INFEAS |
| 638 | 664 |
// Aborted in barrier, primal infeasible |
| 639 | 665 |
// 16 CPX_ABORT_PRIM_DUAL_INFEAS |
| 640 | 666 |
// Aborted in barrier, primal and dual infeasible |
| 641 | 667 |
// 17 CPX_ABORT_PRIM_DUAL_FEAS |
| 642 | 668 |
// Aborted in barrier, primal and dual feasible |
| 643 | 669 |
// 18 CPX_ABORT_CROSSOVER |
| 644 | 670 |
// Aborted in crossover |
| 645 | 671 |
// 19 CPX_INForUNBD |
| 646 | 672 |
// Infeasible or unbounded |
| 647 | 673 |
// 20 CPX_PIVOT |
| 648 | 674 |
// User pivot used |
| 649 | 675 |
// |
| 650 |
// |
|
| 676 |
// Pending return values |
|
| 651 | 677 |
// ??case CPX_ABORT_DUAL_INFEAS |
| 652 | 678 |
// ??case CPX_ABORT_CROSSOVER |
| 653 | 679 |
// ??case CPX_INForUNBD |
| 654 | 680 |
// ??case CPX_PIVOT |
| 655 | 681 |
|
| 656 | 682 |
//Some more interesting stuff: |
| 657 | 683 |
|
| 658 | 684 |
// CPX_PARAM_PROBMETHOD 1062 int LPMETHOD |
| 659 | 685 |
// 0 Automatic |
| 660 | 686 |
// 1 Primal Simplex |
| 661 | 687 |
// 2 Dual Simplex |
| 662 | 688 |
// 3 Network Simplex |
| 663 | 689 |
// 4 Standard Barrier |
| 664 | 690 |
// Default: 0 |
| 665 | 691 |
// Description: Method for linear optimization. |
| 666 | 692 |
// Determines which algorithm is used when CPXlpopt() (or "optimize" |
| 667 | 693 |
// in the Interactive Optimizer) is called. Currently the behavior of |
| 668 | 694 |
// the "Automatic" setting is that CPLEX simply invokes the dual |
| 669 | 695 |
// simplex method, but this capability may be expanded in the future |
| 670 | 696 |
// so that CPLEX chooses the method based on problem characteristics |
| 671 | 697 |
#if CPX_VERSION < 900 |
| 672 | 698 |
void statusSwitch(CPXENVptr cplexEnv(),int& stat){
|
| 673 | 699 |
int lpmethod; |
| 674 | 700 |
CPXgetintparam (cplexEnv(),CPX_PARAM_PROBMETHOD,&lpmethod); |
| 675 | 701 |
if (lpmethod==2){
|
| 676 | 702 |
if (stat==CPX_UNBOUNDED){
|
| 677 | 703 |
stat=CPX_INFEASIBLE; |
| 678 | 704 |
} |
| 679 | 705 |
else{
|
| 680 | 706 |
if (stat==CPX_INFEASIBLE) |
| 681 | 707 |
stat=CPX_UNBOUNDED; |
| 682 | 708 |
} |
| 683 | 709 |
} |
| 684 | 710 |
} |
| 685 | 711 |
#else |
| 686 | 712 |
void statusSwitch(CPXENVptr,int&){}
|
| 687 | 713 |
#endif |
| 688 | 714 |
|
| 689 | 715 |
CplexLp::ProblemType CplexLp::_getPrimalType() const {
|
| 690 | 716 |
// Unboundedness not treated well: the following is from cplex 9.0 doc |
| 691 | 717 |
// About Unboundedness |
| 692 | 718 |
|
| 693 | 719 |
// The treatment of models that are unbounded involves a few |
| 694 | 720 |
// subtleties. Specifically, a declaration of unboundedness means that |
| 695 | 721 |
// ILOG CPLEX has determined that the model has an unbounded |
| 696 | 722 |
// ray. Given any feasible solution x with objective z, a multiple of |
| 697 | 723 |
// the unbounded ray can be added to x to give a feasible solution |
| 698 | 724 |
// with objective z-1 (or z+1 for maximization models). Thus, if a |
| 699 | 725 |
// feasible solution exists, then the optimal objective is |
| 700 | 726 |
// unbounded. Note that ILOG CPLEX has not necessarily concluded that |
| 701 | 727 |
// a feasible solution exists. Users can call the routine CPXsolninfo |
| 702 | 728 |
// to determine whether ILOG CPLEX has also concluded that the model |
| 703 | 729 |
// has a feasible solution. |
| 704 | 730 |
|
| 705 | 731 |
int stat = CPXgetstat(cplexEnv(), _prob); |
| 706 | 732 |
#if CPX_VERSION >= 800 |
| 707 | 733 |
switch (stat) |
| 708 | 734 |
{
|
| 709 | 735 |
case CPX_STAT_OPTIMAL: |
| 710 | 736 |
return OPTIMAL; |
| 711 | 737 |
case CPX_STAT_UNBOUNDED: |
| 712 | 738 |
return UNBOUNDED; |
| 713 | 739 |
case CPX_STAT_INFEASIBLE: |
| 714 | 740 |
return INFEASIBLE; |
| 715 | 741 |
default: |
| 716 | 742 |
return UNDEFINED; |
| 717 | 743 |
} |
| 718 | 744 |
#else |
| 719 | 745 |
statusSwitch(cplexEnv(),stat); |
| 720 | 746 |
//CPXgetstat(cplexEnv(), _prob); |
| 721 |
//printf("A primal status: %d, CPX_OPTIMAL=%d \n",stat,CPX_OPTIMAL);
|
|
| 722 | 747 |
switch (stat) {
|
| 723 | 748 |
case 0: |
| 724 | 749 |
return UNDEFINED; //Undefined |
| 725 | 750 |
case CPX_OPTIMAL://Optimal |
| 726 | 751 |
return OPTIMAL; |
| 727 | 752 |
case CPX_UNBOUNDED://Unbounded |
| 728 | 753 |
return INFEASIBLE;//In case of dual simplex |
| 729 | 754 |
//return UNBOUNDED; |
| 730 | 755 |
case CPX_INFEASIBLE://Infeasible |
| 731 | 756 |
// case CPX_IT_LIM_INFEAS: |
| 732 | 757 |
// case CPX_TIME_LIM_INFEAS: |
| 733 | 758 |
// case CPX_NUM_BEST_INFEAS: |
| 734 | 759 |
// case CPX_OPTIMAL_INFEAS: |
| 735 | 760 |
// case CPX_ABORT_INFEAS: |
| 736 | 761 |
// case CPX_ABORT_PRIM_INFEAS: |
| 737 | 762 |
// case CPX_ABORT_PRIM_DUAL_INFEAS: |
| 738 | 763 |
return UNBOUNDED;//In case of dual simplex |
| 739 | 764 |
//return INFEASIBLE; |
| 740 | 765 |
// case CPX_OBJ_LIM: |
| 741 | 766 |
// case CPX_IT_LIM_FEAS: |
| 742 | 767 |
// case CPX_TIME_LIM_FEAS: |
| 743 | 768 |
// case CPX_NUM_BEST_FEAS: |
| 744 | 769 |
// case CPX_ABORT_FEAS: |
| 745 | 770 |
// case CPX_ABORT_PRIM_DUAL_FEAS: |
| 746 | 771 |
// return FEASIBLE; |
| 747 | 772 |
default: |
| 748 | 773 |
return UNDEFINED; //Everything else comes here |
| 749 | 774 |
//FIXME error |
| 750 | 775 |
} |
| 751 | 776 |
#endif |
| 752 | 777 |
} |
| 753 | 778 |
|
| 754 |
//9.0 |
|
| 779 |
// Cplex 9.0 status values |
|
| 755 | 780 |
// CPX_STAT_ABORT_DUAL_OBJ_LIM |
| 756 | 781 |
// CPX_STAT_ABORT_IT_LIM |
| 757 | 782 |
// CPX_STAT_ABORT_OBJ_LIM |
| 758 | 783 |
// CPX_STAT_ABORT_PRIM_OBJ_LIM |
| 759 | 784 |
// CPX_STAT_ABORT_TIME_LIM |
| 760 | 785 |
// CPX_STAT_ABORT_USER |
| 761 | 786 |
// CPX_STAT_FEASIBLE_RELAXED |
| 762 | 787 |
// CPX_STAT_INFEASIBLE |
| 763 | 788 |
// CPX_STAT_INForUNBD |
| 764 | 789 |
// CPX_STAT_NUM_BEST |
| 765 | 790 |
// CPX_STAT_OPTIMAL |
| 766 | 791 |
// CPX_STAT_OPTIMAL_FACE_UNBOUNDED |
| 767 | 792 |
// CPX_STAT_OPTIMAL_INFEAS |
| 768 | 793 |
// CPX_STAT_OPTIMAL_RELAXED |
| 769 | 794 |
// CPX_STAT_UNBOUNDED |
| 770 | 795 |
|
| 771 | 796 |
CplexLp::ProblemType CplexLp::_getDualType() const {
|
| 772 | 797 |
int stat = CPXgetstat(cplexEnv(), _prob); |
| 773 | 798 |
#if CPX_VERSION >= 800 |
| 774 | 799 |
switch (stat) {
|
| 775 | 800 |
case CPX_STAT_OPTIMAL: |
| 776 | 801 |
return OPTIMAL; |
| 777 | 802 |
case CPX_STAT_UNBOUNDED: |
| 778 | 803 |
return INFEASIBLE; |
| 779 | 804 |
default: |
| 780 | 805 |
return UNDEFINED; |
| 781 | 806 |
} |
| 782 | 807 |
#else |
| 783 | 808 |
statusSwitch(cplexEnv(),stat); |
| 784 | 809 |
switch (stat) {
|
| 785 | 810 |
case 0: |
| 786 | 811 |
return UNDEFINED; //Undefined |
| 787 | 812 |
case CPX_OPTIMAL://Optimal |
| 788 | 813 |
return OPTIMAL; |
| 789 | 814 |
case CPX_UNBOUNDED: |
| 790 | 815 |
return INFEASIBLE; |
| 791 | 816 |
default: |
| 792 | 817 |
return UNDEFINED; //Everything else comes here |
| 793 | 818 |
//FIXME error |
| 794 | 819 |
} |
| 795 | 820 |
#endif |
| 796 | 821 |
} |
| 797 | 822 |
|
| 798 | 823 |
// CplexMip members |
| 799 | 824 |
|
| 800 | 825 |
CplexMip::CplexMip() |
| 801 | 826 |
: LpBase(), MipSolver(), CplexBase() {
|
| 802 | 827 |
|
| ... | ... |
@@ -819,96 +844,97 @@ |
| 819 | 844 |
} |
| 820 | 845 |
|
| 821 | 846 |
CplexMip::CplexMip(const CplexMip& other) |
| 822 | 847 |
: LpBase(), MipSolver(), CplexBase(other) {}
|
| 823 | 848 |
|
| 824 | 849 |
CplexMip::~CplexMip() {}
|
| 825 | 850 |
|
| 826 | 851 |
CplexMip* CplexMip::newSolver() const { return new CplexMip; }
|
| 827 | 852 |
CplexMip* CplexMip::cloneSolver() const {return new CplexMip(*this); }
|
| 828 | 853 |
|
| 829 | 854 |
const char* CplexMip::_solverName() const { return "CplexMip"; }
|
| 830 | 855 |
|
| 831 | 856 |
void CplexMip::_setColType(int i, CplexMip::ColTypes col_type) {
|
| 832 | 857 |
|
| 833 | 858 |
// Note If a variable is to be changed to binary, a call to CPXchgbds |
| 834 | 859 |
// should also be made to change the bounds to 0 and 1. |
| 835 | 860 |
|
| 836 | 861 |
switch (col_type){
|
| 837 | 862 |
case INTEGER: {
|
| 838 | 863 |
const char t = 'I'; |
| 839 | 864 |
CPXchgctype (cplexEnv(), _prob, 1, &i, &t); |
| 840 | 865 |
} break; |
| 841 | 866 |
case REAL: {
|
| 842 | 867 |
const char t = 'C'; |
| 843 | 868 |
CPXchgctype (cplexEnv(), _prob, 1, &i, &t); |
| 844 | 869 |
} break; |
| 845 | 870 |
default: |
| 846 | 871 |
break; |
| 847 | 872 |
} |
| 848 | 873 |
} |
| 849 | 874 |
|
| 850 | 875 |
CplexMip::ColTypes CplexMip::_getColType(int i) const {
|
| 851 | 876 |
char t; |
| 852 | 877 |
CPXgetctype (cplexEnv(), _prob, &t, i, i); |
| 853 | 878 |
switch (t) {
|
| 854 | 879 |
case 'I': |
| 855 | 880 |
return INTEGER; |
| 856 | 881 |
case 'C': |
| 857 | 882 |
return REAL; |
| 858 | 883 |
default: |
| 859 | 884 |
LEMON_ASSERT(false, "Invalid column type"); |
| 860 | 885 |
return ColTypes(); |
| 861 | 886 |
} |
| 862 | 887 |
|
| 863 | 888 |
} |
| 864 | 889 |
|
| 865 | 890 |
CplexMip::SolveExitStatus CplexMip::_solve() {
|
| 866 | 891 |
int status; |
| 892 |
_applyMessageLevel(); |
|
| 867 | 893 |
status = CPXmipopt (cplexEnv(), _prob); |
| 868 | 894 |
if (status==0) |
| 869 | 895 |
return SOLVED; |
| 870 | 896 |
else |
| 871 | 897 |
return UNSOLVED; |
| 872 | 898 |
|
| 873 | 899 |
} |
| 874 | 900 |
|
| 875 | 901 |
|
| 876 | 902 |
CplexMip::ProblemType CplexMip::_getType() const {
|
| 877 | 903 |
|
| 878 | 904 |
int stat = CPXgetstat(cplexEnv(), _prob); |
| 879 | 905 |
|
| 880 | 906 |
//Fortunately, MIP statuses did not change for cplex 8.0 |
| 881 | 907 |
switch (stat) {
|
| 882 | 908 |
case CPXMIP_OPTIMAL: |
| 883 | 909 |
// Optimal integer solution has been found. |
| 884 | 910 |
case CPXMIP_OPTIMAL_TOL: |
| 885 | 911 |
// Optimal soluton with the tolerance defined by epgap or epagap has |
| 886 | 912 |
// been found. |
| 887 | 913 |
return OPTIMAL; |
| 888 | 914 |
//This also exists in later issues |
| 889 | 915 |
// case CPXMIP_UNBOUNDED: |
| 890 | 916 |
//return UNBOUNDED; |
| 891 | 917 |
case CPXMIP_INFEASIBLE: |
| 892 | 918 |
return INFEASIBLE; |
| 893 | 919 |
default: |
| 894 | 920 |
return UNDEFINED; |
| 895 | 921 |
} |
| 896 | 922 |
//Unboundedness not treated well: the following is from cplex 9.0 doc |
| 897 | 923 |
// About Unboundedness |
| 898 | 924 |
|
| 899 | 925 |
// The treatment of models that are unbounded involves a few |
| 900 | 926 |
// subtleties. Specifically, a declaration of unboundedness means that |
| 901 | 927 |
// ILOG CPLEX has determined that the model has an unbounded |
| 902 | 928 |
// ray. Given any feasible solution x with objective z, a multiple of |
| 903 | 929 |
// the unbounded ray can be added to x to give a feasible solution |
| 904 | 930 |
// with objective z-1 (or z+1 for maximization models). Thus, if a |
| 905 | 931 |
// feasible solution exists, then the optimal objective is |
| 906 | 932 |
// unbounded. Note that ILOG CPLEX has not necessarily concluded that |
| 907 | 933 |
// a feasible solution exists. Users can call the routine CPXsolninfo |
| 908 | 934 |
// to determine whether ILOG CPLEX has also concluded that the model |
| 909 | 935 |
// has a feasible solution. |
| 910 | 936 |
} |
| 911 | 937 |
|
| 912 | 938 |
CplexMip::Value CplexMip::_getSol(int i) const {
|
| 913 | 939 |
Value x; |
| 914 | 940 |
CPXgetmipx(cplexEnv(), _prob, &x, i, i); |
| ... | ... |
@@ -99,104 +99,119 @@ |
| 99 | 99 |
|
| 100 | 100 |
virtual void _eraseColId(int i); |
| 101 | 101 |
virtual void _eraseRowId(int i); |
| 102 | 102 |
|
| 103 | 103 |
virtual void _getColName(int col, std::string& name) const; |
| 104 | 104 |
virtual void _setColName(int col, const std::string& name); |
| 105 | 105 |
virtual int _colByName(const std::string& name) const; |
| 106 | 106 |
|
| 107 | 107 |
virtual void _getRowName(int row, std::string& name) const; |
| 108 | 108 |
virtual void _setRowName(int row, const std::string& name); |
| 109 | 109 |
virtual int _rowByName(const std::string& name) const; |
| 110 | 110 |
|
| 111 | 111 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 112 | 112 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 113 | 113 |
|
| 114 | 114 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 115 | 115 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 116 | 116 |
|
| 117 | 117 |
virtual void _setCoeff(int row, int col, Value value); |
| 118 | 118 |
virtual Value _getCoeff(int row, int col) const; |
| 119 | 119 |
|
| 120 | 120 |
virtual void _setColLowerBound(int i, Value value); |
| 121 | 121 |
virtual Value _getColLowerBound(int i) const; |
| 122 | 122 |
|
| 123 | 123 |
virtual void _setColUpperBound(int i, Value value); |
| 124 | 124 |
virtual Value _getColUpperBound(int i) const; |
| 125 | 125 |
|
| 126 | 126 |
private: |
| 127 | 127 |
void _set_row_bounds(int i, Value lb, Value ub); |
| 128 | 128 |
protected: |
| 129 | 129 |
|
| 130 | 130 |
virtual void _setRowLowerBound(int i, Value value); |
| 131 | 131 |
virtual Value _getRowLowerBound(int i) const; |
| 132 | 132 |
|
| 133 | 133 |
virtual void _setRowUpperBound(int i, Value value); |
| 134 | 134 |
virtual Value _getRowUpperBound(int i) const; |
| 135 | 135 |
|
| 136 | 136 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 137 | 137 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 138 | 138 |
|
| 139 | 139 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 140 | 140 |
virtual Value _getObjCoeff(int i) const; |
| 141 | 141 |
|
| 142 | 142 |
virtual void _setSense(Sense sense); |
| 143 | 143 |
virtual Sense _getSense() const; |
| 144 | 144 |
|
| 145 | 145 |
virtual void _clear(); |
| 146 | 146 |
|
| 147 |
virtual void _messageLevel(MessageLevel level); |
|
| 148 |
void _applyMessageLevel(); |
|
| 149 |
|
|
| 150 |
bool _message_enabled; |
|
| 151 |
|
|
| 147 | 152 |
public: |
| 148 | 153 |
|
| 149 | 154 |
/// Returns the used \c CplexEnv instance |
| 150 | 155 |
const CplexEnv& env() const { return _env; }
|
| 156 |
|
|
| 157 |
/// \brief Returns the const cpxenv pointer |
|
| 151 | 158 |
/// |
| 159 |
/// \note The cpxenv might be destructed with the solver. |
|
| 152 | 160 |
const cpxenv* cplexEnv() const { return _env.cplexEnv(); }
|
| 153 | 161 |
|
| 162 |
/// \brief Returns the const cpxenv pointer |
|
| 163 |
/// |
|
| 164 |
/// \note The cpxenv might be destructed with the solver. |
|
| 165 |
cpxenv* cplexEnv() { return _env.cplexEnv(); }
|
|
| 166 |
|
|
| 167 |
/// Returns the cplex problem object |
|
| 154 | 168 |
cpxlp* cplexLp() { return _prob; }
|
| 169 |
/// Returns the cplex problem object |
|
| 155 | 170 |
const cpxlp* cplexLp() const { return _prob; }
|
| 156 | 171 |
|
| 157 | 172 |
}; |
| 158 | 173 |
|
| 159 | 174 |
/// \brief Interface for the CPLEX LP solver |
| 160 | 175 |
/// |
| 161 | 176 |
/// This class implements an interface for the CPLEX LP solver. |
| 162 | 177 |
///\ingroup lp_group |
| 163 | 178 |
class CplexLp : public LpSolver, public CplexBase {
|
| 164 | 179 |
public: |
| 165 | 180 |
/// \e |
| 166 | 181 |
CplexLp(); |
| 167 | 182 |
/// \e |
| 168 | 183 |
CplexLp(const CplexEnv&); |
| 169 | 184 |
/// \e |
| 170 | 185 |
CplexLp(const CplexLp&); |
| 171 | 186 |
/// \e |
| 172 | 187 |
virtual ~CplexLp(); |
| 173 | 188 |
|
| 174 | 189 |
/// \e |
| 175 | 190 |
virtual CplexLp* cloneSolver() const; |
| 176 | 191 |
/// \e |
| 177 | 192 |
virtual CplexLp* newSolver() const; |
| 178 | 193 |
|
| 179 | 194 |
private: |
| 180 | 195 |
|
| 181 | 196 |
// these values cannot retrieved element by element |
| 182 | 197 |
mutable std::vector<int> _col_status; |
| 183 | 198 |
mutable std::vector<int> _row_status; |
| 184 | 199 |
|
| 185 | 200 |
mutable std::vector<Value> _primal_ray; |
| 186 | 201 |
mutable std::vector<Value> _dual_ray; |
| 187 | 202 |
|
| 188 | 203 |
void _clear_temporals(); |
| 189 | 204 |
|
| 190 | 205 |
SolveExitStatus convertStatus(int status); |
| 191 | 206 |
|
| 192 | 207 |
protected: |
| 193 | 208 |
|
| 194 | 209 |
virtual const char* _solverName() const; |
| 195 | 210 |
|
| 196 | 211 |
virtual SolveExitStatus _solve(); |
| 197 | 212 |
virtual Value _getPrimal(int i) const; |
| 198 | 213 |
virtual Value _getDual(int i) const; |
| 199 | 214 |
virtual Value _getPrimalValue() const; |
| 200 | 215 |
|
| 201 | 216 |
virtual VarStatus _getColStatus(int i) const; |
| 202 | 217 |
virtual VarStatus _getRowStatus(int i) const; |
| ... | ... |
@@ -161,97 +161,97 @@ |
| 161 | 161 |
PredMap *_pred; |
| 162 | 162 |
//Indicates if _pred is locally allocated (true) or not. |
| 163 | 163 |
bool local_pred; |
| 164 | 164 |
//Pointer to the map of distances. |
| 165 | 165 |
DistMap *_dist; |
| 166 | 166 |
//Indicates if _dist is locally allocated (true) or not. |
| 167 | 167 |
bool local_dist; |
| 168 | 168 |
//Pointer to the map of reached status of the nodes. |
| 169 | 169 |
ReachedMap *_reached; |
| 170 | 170 |
//Indicates if _reached is locally allocated (true) or not. |
| 171 | 171 |
bool local_reached; |
| 172 | 172 |
//Pointer to the map of processed status of the nodes. |
| 173 | 173 |
ProcessedMap *_processed; |
| 174 | 174 |
//Indicates if _processed is locally allocated (true) or not. |
| 175 | 175 |
bool local_processed; |
| 176 | 176 |
|
| 177 | 177 |
std::vector<typename Digraph::OutArcIt> _stack; |
| 178 | 178 |
int _stack_head; |
| 179 | 179 |
|
| 180 | 180 |
//Creates the maps if necessary. |
| 181 | 181 |
void create_maps() |
| 182 | 182 |
{
|
| 183 | 183 |
if(!_pred) {
|
| 184 | 184 |
local_pred = true; |
| 185 | 185 |
_pred = Traits::createPredMap(*G); |
| 186 | 186 |
} |
| 187 | 187 |
if(!_dist) {
|
| 188 | 188 |
local_dist = true; |
| 189 | 189 |
_dist = Traits::createDistMap(*G); |
| 190 | 190 |
} |
| 191 | 191 |
if(!_reached) {
|
| 192 | 192 |
local_reached = true; |
| 193 | 193 |
_reached = Traits::createReachedMap(*G); |
| 194 | 194 |
} |
| 195 | 195 |
if(!_processed) {
|
| 196 | 196 |
local_processed = true; |
| 197 | 197 |
_processed = Traits::createProcessedMap(*G); |
| 198 | 198 |
} |
| 199 | 199 |
} |
| 200 | 200 |
|
| 201 | 201 |
protected: |
| 202 | 202 |
|
| 203 | 203 |
Dfs() {}
|
| 204 | 204 |
|
| 205 | 205 |
public: |
| 206 | 206 |
|
| 207 | 207 |
typedef Dfs Create; |
| 208 | 208 |
|
| 209 |
///\name Named |
|
| 209 |
///\name Named Template Parameters |
|
| 210 | 210 |
|
| 211 | 211 |
///@{
|
| 212 | 212 |
|
| 213 | 213 |
template <class T> |
| 214 | 214 |
struct SetPredMapTraits : public Traits {
|
| 215 | 215 |
typedef T PredMap; |
| 216 | 216 |
static PredMap *createPredMap(const Digraph &) |
| 217 | 217 |
{
|
| 218 | 218 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
| 219 | 219 |
return 0; // ignore warnings |
| 220 | 220 |
} |
| 221 | 221 |
}; |
| 222 | 222 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 223 | 223 |
///\c PredMap type. |
| 224 | 224 |
/// |
| 225 | 225 |
///\ref named-templ-param "Named parameter" for setting |
| 226 | 226 |
///\c PredMap type. |
| 227 | 227 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 228 | 228 |
template <class T> |
| 229 | 229 |
struct SetPredMap : public Dfs<Digraph, SetPredMapTraits<T> > {
|
| 230 | 230 |
typedef Dfs<Digraph, SetPredMapTraits<T> > Create; |
| 231 | 231 |
}; |
| 232 | 232 |
|
| 233 | 233 |
template <class T> |
| 234 | 234 |
struct SetDistMapTraits : public Traits {
|
| 235 | 235 |
typedef T DistMap; |
| 236 | 236 |
static DistMap *createDistMap(const Digraph &) |
| 237 | 237 |
{
|
| 238 | 238 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
| 239 | 239 |
return 0; // ignore warnings |
| 240 | 240 |
} |
| 241 | 241 |
}; |
| 242 | 242 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 243 | 243 |
///\c DistMap type. |
| 244 | 244 |
/// |
| 245 | 245 |
///\ref named-templ-param "Named parameter" for setting |
| 246 | 246 |
///\c DistMap type. |
| 247 | 247 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 248 | 248 |
template <class T> |
| 249 | 249 |
struct SetDistMap : public Dfs< Digraph, SetDistMapTraits<T> > {
|
| 250 | 250 |
typedef Dfs<Digraph, SetDistMapTraits<T> > Create; |
| 251 | 251 |
}; |
| 252 | 252 |
|
| 253 | 253 |
template <class T> |
| 254 | 254 |
struct SetReachedMapTraits : public Traits {
|
| 255 | 255 |
typedef T ReachedMap; |
| 256 | 256 |
static ReachedMap *createReachedMap(const Digraph &) |
| 257 | 257 |
{
|
| ... | ... |
@@ -241,97 +241,97 @@ |
| 241 | 241 |
//Indicates if _pred is locally allocated (true) or not. |
| 242 | 242 |
bool local_pred; |
| 243 | 243 |
//Pointer to the map of distances. |
| 244 | 244 |
DistMap *_dist; |
| 245 | 245 |
//Indicates if _dist is locally allocated (true) or not. |
| 246 | 246 |
bool local_dist; |
| 247 | 247 |
//Pointer to the map of processed status of the nodes. |
| 248 | 248 |
ProcessedMap *_processed; |
| 249 | 249 |
//Indicates if _processed is locally allocated (true) or not. |
| 250 | 250 |
bool local_processed; |
| 251 | 251 |
//Pointer to the heap cross references. |
| 252 | 252 |
HeapCrossRef *_heap_cross_ref; |
| 253 | 253 |
//Indicates if _heap_cross_ref is locally allocated (true) or not. |
| 254 | 254 |
bool local_heap_cross_ref; |
| 255 | 255 |
//Pointer to the heap. |
| 256 | 256 |
Heap *_heap; |
| 257 | 257 |
//Indicates if _heap is locally allocated (true) or not. |
| 258 | 258 |
bool local_heap; |
| 259 | 259 |
|
| 260 | 260 |
//Creates the maps if necessary. |
| 261 | 261 |
void create_maps() |
| 262 | 262 |
{
|
| 263 | 263 |
if(!_pred) {
|
| 264 | 264 |
local_pred = true; |
| 265 | 265 |
_pred = Traits::createPredMap(*G); |
| 266 | 266 |
} |
| 267 | 267 |
if(!_dist) {
|
| 268 | 268 |
local_dist = true; |
| 269 | 269 |
_dist = Traits::createDistMap(*G); |
| 270 | 270 |
} |
| 271 | 271 |
if(!_processed) {
|
| 272 | 272 |
local_processed = true; |
| 273 | 273 |
_processed = Traits::createProcessedMap(*G); |
| 274 | 274 |
} |
| 275 | 275 |
if (!_heap_cross_ref) {
|
| 276 | 276 |
local_heap_cross_ref = true; |
| 277 | 277 |
_heap_cross_ref = Traits::createHeapCrossRef(*G); |
| 278 | 278 |
} |
| 279 | 279 |
if (!_heap) {
|
| 280 | 280 |
local_heap = true; |
| 281 | 281 |
_heap = Traits::createHeap(*_heap_cross_ref); |
| 282 | 282 |
} |
| 283 | 283 |
} |
| 284 | 284 |
|
| 285 | 285 |
public: |
| 286 | 286 |
|
| 287 | 287 |
typedef Dijkstra Create; |
| 288 | 288 |
|
| 289 |
///\name Named |
|
| 289 |
///\name Named Template Parameters |
|
| 290 | 290 |
|
| 291 | 291 |
///@{
|
| 292 | 292 |
|
| 293 | 293 |
template <class T> |
| 294 | 294 |
struct SetPredMapTraits : public Traits {
|
| 295 | 295 |
typedef T PredMap; |
| 296 | 296 |
static PredMap *createPredMap(const Digraph &) |
| 297 | 297 |
{
|
| 298 | 298 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
| 299 | 299 |
return 0; // ignore warnings |
| 300 | 300 |
} |
| 301 | 301 |
}; |
| 302 | 302 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 303 | 303 |
///\c PredMap type. |
| 304 | 304 |
/// |
| 305 | 305 |
///\ref named-templ-param "Named parameter" for setting |
| 306 | 306 |
///\c PredMap type. |
| 307 | 307 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 308 | 308 |
template <class T> |
| 309 | 309 |
struct SetPredMap |
| 310 | 310 |
: public Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > {
|
| 311 | 311 |
typedef Dijkstra< Digraph, LengthMap, SetPredMapTraits<T> > Create; |
| 312 | 312 |
}; |
| 313 | 313 |
|
| 314 | 314 |
template <class T> |
| 315 | 315 |
struct SetDistMapTraits : public Traits {
|
| 316 | 316 |
typedef T DistMap; |
| 317 | 317 |
static DistMap *createDistMap(const Digraph &) |
| 318 | 318 |
{
|
| 319 | 319 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
| 320 | 320 |
return 0; // ignore warnings |
| 321 | 321 |
} |
| 322 | 322 |
}; |
| 323 | 323 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 324 | 324 |
///\c DistMap type. |
| 325 | 325 |
/// |
| 326 | 326 |
///\ref named-templ-param "Named parameter" for setting |
| 327 | 327 |
///\c DistMap type. |
| 328 | 328 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 329 | 329 |
template <class T> |
| 330 | 330 |
struct SetDistMap |
| 331 | 331 |
: public Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > {
|
| 332 | 332 |
typedef Dijkstra< Digraph, LengthMap, SetDistMapTraits<T> > Create; |
| 333 | 333 |
}; |
| 334 | 334 |
|
| 335 | 335 |
template <class T> |
| 336 | 336 |
struct SetProcessedMapTraits : public Traits {
|
| 337 | 337 |
typedef T ProcessedMap; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_DIMACS_H |
| 20 | 20 |
#define LEMON_DIMACS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iostream> |
| 23 | 23 |
#include <string> |
| 24 | 24 |
#include <vector> |
| 25 | 25 |
#include <limits> |
| 26 | 26 |
#include <lemon/maps.h> |
| 27 | 27 |
#include <lemon/error.h> |
| 28 | 28 |
/// \ingroup dimacs_group |
| 29 | 29 |
/// \file |
| 30 | 30 |
/// \brief DIMACS file format reader. |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
/// \addtogroup dimacs_group |
| 35 | 35 |
/// @{
|
| 36 | 36 |
|
| 37 | 37 |
/// DIMACS file type descriptor. |
| 38 | 38 |
struct DimacsDescriptor |
| 39 | 39 |
{
|
| 40 |
///File type enum |
|
| 41 |
enum Type |
|
| 42 |
{
|
|
| 43 |
NONE, MIN, MAX, SP, MAT |
|
| 44 |
|
|
| 40 |
///\brief DIMACS file type enum |
|
| 41 |
/// |
|
| 42 |
///DIMACS file type enum. |
|
| 43 |
enum Type {
|
|
| 44 |
NONE, ///< Undefined type. |
|
| 45 |
MIN, ///< DIMACS file type for minimum cost flow problems. |
|
| 46 |
MAX, ///< DIMACS file type for maximum flow problems. |
|
| 47 |
SP, ///< DIMACS file type for shostest path problems. |
|
| 48 |
MAT ///< DIMACS file type for plain graphs and matching problems. |
|
| 49 |
}; |
|
| 45 | 50 |
///The file type |
| 46 | 51 |
Type type; |
| 47 | 52 |
///The number of nodes in the graph |
| 48 | 53 |
int nodeNum; |
| 49 | 54 |
///The number of edges in the graph |
| 50 | 55 |
int edgeNum; |
| 51 | 56 |
int lineShift; |
| 52 |
/// |
|
| 57 |
///Constructor. It sets the type to \c NONE. |
|
| 53 | 58 |
DimacsDescriptor() : type(NONE) {}
|
| 54 | 59 |
}; |
| 55 | 60 |
|
| 56 | 61 |
///Discover the type of a DIMACS file |
| 57 | 62 |
|
| 58 |
///It starts seeking the beginning of the file for the problem type |
|
| 59 |
///and size info. The found data is returned in a special struct |
|
| 60 |
///that can be evaluated and passed to the appropriate reader |
|
| 61 |
///function. |
|
| 63 |
///This function starts seeking the beginning of the given file for the |
|
| 64 |
///problem type and size info. |
|
| 65 |
///The found data is returned in a special struct that can be evaluated |
|
| 66 |
///and passed to the appropriate reader function. |
|
| 62 | 67 |
DimacsDescriptor dimacsType(std::istream& is) |
| 63 | 68 |
{
|
| 64 | 69 |
DimacsDescriptor r; |
| 65 | 70 |
std::string problem,str; |
| 66 | 71 |
char c; |
| 67 | 72 |
r.lineShift=0; |
| 68 | 73 |
while (is >> c) |
| 69 | 74 |
switch(c) |
| 70 | 75 |
{
|
| 71 | 76 |
case 'p': |
| 72 | 77 |
if(is >> problem >> r.nodeNum >> r.edgeNum) |
| 73 | 78 |
{
|
| 74 | 79 |
getline(is, str); |
| 75 | 80 |
r.lineShift++; |
| 76 | 81 |
if(problem=="min") r.type=DimacsDescriptor::MIN; |
| 77 | 82 |
else if(problem=="max") r.type=DimacsDescriptor::MAX; |
| 78 | 83 |
else if(problem=="sp") r.type=DimacsDescriptor::SP; |
| 79 | 84 |
else if(problem=="mat") r.type=DimacsDescriptor::MAT; |
| 80 | 85 |
else throw FormatError("Unknown problem type");
|
| 81 | 86 |
return r; |
| 82 | 87 |
} |
| 83 | 88 |
else |
| 84 | 89 |
{
|
| 85 | 90 |
throw FormatError("Missing or wrong problem type declaration.");
|
| 86 | 91 |
} |
| 87 | 92 |
break; |
| 88 | 93 |
case 'c': |
| 89 | 94 |
getline(is, str); |
| 90 | 95 |
r.lineShift++; |
| 91 | 96 |
break; |
| 92 | 97 |
default: |
| 93 | 98 |
throw FormatError("Unknown DIMACS declaration.");
|
| 94 | 99 |
} |
| 95 | 100 |
throw FormatError("Missing problem type declaration.");
|
| 96 | 101 |
} |
| 97 | 102 |
|
| 98 | 103 |
|
| 99 |
|
|
| 100 |
/// DIMACS minimum cost flow reader function. |
|
| 104 |
/// \brief DIMACS minimum cost flow reader function. |
|
| 101 | 105 |
/// |
| 102 | 106 |
/// This function reads a minimum cost flow instance from DIMACS format, |
| 103 | 107 |
/// i.e. from a DIMACS file having a line starting with |
| 104 | 108 |
/// \code |
| 105 | 109 |
/// p min |
| 106 | 110 |
/// \endcode |
| 107 | 111 |
/// At the beginning, \c g is cleared by \c g.clear(). The supply |
| 108 | 112 |
/// amount of the nodes are written to the \c supply node map |
| 109 | 113 |
/// (they are signed values). The lower bounds, capacities and costs |
| 110 | 114 |
/// of the arcs are written to the \c lower, \c capacity and \c cost |
| 111 | 115 |
/// arc maps. |
| 112 | 116 |
/// |
| 113 | 117 |
/// If the capacity of an arc is less than the lower bound, it will |
| 114 | 118 |
/// be set to "infinite" instead. The actual value of "infinite" is |
| 115 | 119 |
/// contolled by the \c infty parameter. If it is 0 (the default value), |
| 116 | 120 |
/// \c std::numeric_limits<Capacity>::infinity() will be used if available, |
| 117 | 121 |
/// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to |
| 118 | 122 |
/// a non-zero value, that value will be used as "infinite". |
| 119 | 123 |
/// |
| 120 | 124 |
/// If the file type was previously evaluated by dimacsType(), then |
| 121 | 125 |
/// the descriptor struct should be given by the \c dest parameter. |
| 122 | 126 |
template <typename Digraph, typename LowerMap, |
| 123 | 127 |
typename CapacityMap, typename CostMap, |
| 124 | 128 |
typename SupplyMap> |
| 125 | 129 |
void readDimacsMin(std::istream& is, |
| 126 | 130 |
Digraph &g, |
| 127 | 131 |
LowerMap& lower, |
| 128 | 132 |
CapacityMap& capacity, |
| 129 | 133 |
CostMap& cost, |
| 130 | 134 |
SupplyMap& supply, |
| 131 | 135 |
typename CapacityMap::Value infty = 0, |
| 132 | 136 |
DimacsDescriptor desc=DimacsDescriptor()) |
| 133 | 137 |
{
|
| 134 | 138 |
g.clear(); |
| 135 | 139 |
std::vector<typename Digraph::Node> nodes; |
| 136 | 140 |
typename Digraph::Arc e; |
| 137 | 141 |
std::string problem, str; |
| 138 | 142 |
char c; |
| 139 | 143 |
int i, j; |
| 140 | 144 |
if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is); |
| 141 | 145 |
if(desc.type!=DimacsDescriptor::MIN) |
| 142 | 146 |
throw FormatError("Problem type mismatch");
|
| 143 | 147 |
|
| 144 | 148 |
nodes.resize(desc.nodeNum + 1); |
| 145 | 149 |
for (int k = 1; k <= desc.nodeNum; ++k) {
|
| 146 | 150 |
nodes[k] = g.addNode(); |
| 147 | 151 |
supply.set(nodes[k], 0); |
| 148 | 152 |
} |
| ... | ... |
@@ -208,207 +212,207 @@ |
| 208 | 212 |
infty = std::numeric_limits<Capacity>::has_infinity ? |
| 209 | 213 |
std::numeric_limits<Capacity>::infinity() : |
| 210 | 214 |
std::numeric_limits<Capacity>::max(); |
| 211 | 215 |
|
| 212 | 216 |
while (is >> c) {
|
| 213 | 217 |
switch (c) {
|
| 214 | 218 |
case 'c': // comment line |
| 215 | 219 |
getline(is, str); |
| 216 | 220 |
break; |
| 217 | 221 |
case 'n': // node definition line |
| 218 | 222 |
if (desc.type==DimacsDescriptor::SP) { // shortest path problem
|
| 219 | 223 |
is >> i; |
| 220 | 224 |
getline(is, str); |
| 221 | 225 |
s = nodes[i]; |
| 222 | 226 |
} |
| 223 | 227 |
if (desc.type==DimacsDescriptor::MAX) { // max flow problem
|
| 224 | 228 |
is >> i >> d; |
| 225 | 229 |
getline(is, str); |
| 226 | 230 |
if (d == 's') s = nodes[i]; |
| 227 | 231 |
if (d == 't') t = nodes[i]; |
| 228 | 232 |
} |
| 229 | 233 |
break; |
| 230 | 234 |
case 'a': // arc definition line |
| 231 | 235 |
if (desc.type==DimacsDescriptor::SP) {
|
| 232 | 236 |
is >> i >> j >> _cap; |
| 233 | 237 |
getline(is, str); |
| 234 | 238 |
e = g.addArc(nodes[i], nodes[j]); |
| 235 | 239 |
capacity.set(e, _cap); |
| 236 | 240 |
} |
| 237 | 241 |
else if (desc.type==DimacsDescriptor::MAX) {
|
| 238 | 242 |
is >> i >> j >> _cap; |
| 239 | 243 |
getline(is, str); |
| 240 | 244 |
e = g.addArc(nodes[i], nodes[j]); |
| 241 | 245 |
if (_cap >= 0) |
| 242 | 246 |
capacity.set(e, _cap); |
| 243 | 247 |
else |
| 244 | 248 |
capacity.set(e, infty); |
| 245 | 249 |
} |
| 246 | 250 |
else {
|
| 247 | 251 |
is >> i >> j; |
| 248 | 252 |
getline(is, str); |
| 249 | 253 |
g.addArc(nodes[i], nodes[j]); |
| 250 | 254 |
} |
| 251 | 255 |
break; |
| 252 | 256 |
} |
| 253 | 257 |
} |
| 254 | 258 |
} |
| 255 | 259 |
|
| 256 |
/// DIMACS maximum flow reader function. |
|
| 260 |
/// \brief DIMACS maximum flow reader function. |
|
| 257 | 261 |
/// |
| 258 | 262 |
/// This function reads a maximum flow instance from DIMACS format, |
| 259 | 263 |
/// i.e. from a DIMACS file having a line starting with |
| 260 | 264 |
/// \code |
| 261 | 265 |
/// p max |
| 262 | 266 |
/// \endcode |
| 263 | 267 |
/// At the beginning, \c g is cleared by \c g.clear(). The arc |
| 264 | 268 |
/// capacities are written to the \c capacity arc map and \c s and |
| 265 | 269 |
/// \c t are set to the source and the target nodes. |
| 266 | 270 |
/// |
| 267 | 271 |
/// If the capacity of an arc is negative, it will |
| 268 | 272 |
/// be set to "infinite" instead. The actual value of "infinite" is |
| 269 | 273 |
/// contolled by the \c infty parameter. If it is 0 (the default value), |
| 270 | 274 |
/// \c std::numeric_limits<Capacity>::infinity() will be used if available, |
| 271 | 275 |
/// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to |
| 272 | 276 |
/// a non-zero value, that value will be used as "infinite". |
| 273 | 277 |
/// |
| 274 | 278 |
/// If the file type was previously evaluated by dimacsType(), then |
| 275 | 279 |
/// the descriptor struct should be given by the \c dest parameter. |
| 276 | 280 |
template<typename Digraph, typename CapacityMap> |
| 277 | 281 |
void readDimacsMax(std::istream& is, |
| 278 | 282 |
Digraph &g, |
| 279 | 283 |
CapacityMap& capacity, |
| 280 | 284 |
typename Digraph::Node &s, |
| 281 | 285 |
typename Digraph::Node &t, |
| 282 | 286 |
typename CapacityMap::Value infty = 0, |
| 283 | 287 |
DimacsDescriptor desc=DimacsDescriptor()) {
|
| 284 | 288 |
if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is); |
| 285 | 289 |
if(desc.type!=DimacsDescriptor::MAX) |
| 286 | 290 |
throw FormatError("Problem type mismatch");
|
| 287 | 291 |
_readDimacs(is,g,capacity,s,t,infty,desc); |
| 288 | 292 |
} |
| 289 | 293 |
|
| 290 |
/// DIMACS shortest path reader function. |
|
| 294 |
/// \brief DIMACS shortest path reader function. |
|
| 291 | 295 |
/// |
| 292 | 296 |
/// This function reads a shortest path instance from DIMACS format, |
| 293 | 297 |
/// i.e. from a DIMACS file having a line starting with |
| 294 | 298 |
/// \code |
| 295 | 299 |
/// p sp |
| 296 | 300 |
/// \endcode |
| 297 | 301 |
/// At the beginning, \c g is cleared by \c g.clear(). The arc |
| 298 | 302 |
/// lengths are written to the \c length arc map and \c s is set to the |
| 299 | 303 |
/// source node. |
| 300 | 304 |
/// |
| 301 | 305 |
/// If the file type was previously evaluated by dimacsType(), then |
| 302 | 306 |
/// the descriptor struct should be given by the \c dest parameter. |
| 303 | 307 |
template<typename Digraph, typename LengthMap> |
| 304 | 308 |
void readDimacsSp(std::istream& is, |
| 305 | 309 |
Digraph &g, |
| 306 | 310 |
LengthMap& length, |
| 307 | 311 |
typename Digraph::Node &s, |
| 308 | 312 |
DimacsDescriptor desc=DimacsDescriptor()) {
|
| 309 | 313 |
typename Digraph::Node t; |
| 310 | 314 |
if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is); |
| 311 | 315 |
if(desc.type!=DimacsDescriptor::SP) |
| 312 | 316 |
throw FormatError("Problem type mismatch");
|
| 313 | 317 |
_readDimacs(is, g, length, s, t, 0, desc); |
| 314 | 318 |
} |
| 315 | 319 |
|
| 316 |
/// DIMACS capacitated digraph reader function. |
|
| 320 |
/// \brief DIMACS capacitated digraph reader function. |
|
| 317 | 321 |
/// |
| 318 | 322 |
/// This function reads an arc capacitated digraph instance from |
| 319 | 323 |
/// DIMACS 'max' or 'sp' format. |
| 320 | 324 |
/// At the beginning, \c g is cleared by \c g.clear() |
| 321 | 325 |
/// and the arc capacities/lengths are written to the \c capacity |
| 322 | 326 |
/// arc map. |
| 323 | 327 |
/// |
| 324 | 328 |
/// In case of the 'max' format, if the capacity of an arc is negative, |
| 325 | 329 |
/// it will |
| 326 | 330 |
/// be set to "infinite" instead. The actual value of "infinite" is |
| 327 | 331 |
/// contolled by the \c infty parameter. If it is 0 (the default value), |
| 328 | 332 |
/// \c std::numeric_limits<Capacity>::infinity() will be used if available, |
| 329 | 333 |
/// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to |
| 330 | 334 |
/// a non-zero value, that value will be used as "infinite". |
| 331 | 335 |
/// |
| 332 | 336 |
/// If the file type was previously evaluated by dimacsType(), then |
| 333 | 337 |
/// the descriptor struct should be given by the \c dest parameter. |
| 334 | 338 |
template<typename Digraph, typename CapacityMap> |
| 335 | 339 |
void readDimacsCap(std::istream& is, |
| 336 | 340 |
Digraph &g, |
| 337 | 341 |
CapacityMap& capacity, |
| 338 | 342 |
typename CapacityMap::Value infty = 0, |
| 339 | 343 |
DimacsDescriptor desc=DimacsDescriptor()) {
|
| 340 | 344 |
typename Digraph::Node u,v; |
| 341 | 345 |
if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is); |
| 342 | 346 |
if(desc.type!=DimacsDescriptor::MAX || desc.type!=DimacsDescriptor::SP) |
| 343 | 347 |
throw FormatError("Problem type mismatch");
|
| 344 | 348 |
_readDimacs(is, g, capacity, u, v, infty, desc); |
| 345 | 349 |
} |
| 346 | 350 |
|
| 347 | 351 |
template<typename Graph> |
| 348 | 352 |
typename enable_if<lemon::UndirectedTagIndicator<Graph>,void>::type |
| 349 | 353 |
_addArcEdge(Graph &g, typename Graph::Node s, typename Graph::Node t, |
| 350 | 354 |
dummy<0> = 0) |
| 351 | 355 |
{
|
| 352 | 356 |
g.addEdge(s,t); |
| 353 | 357 |
} |
| 354 | 358 |
template<typename Graph> |
| 355 | 359 |
typename disable_if<lemon::UndirectedTagIndicator<Graph>,void>::type |
| 356 | 360 |
_addArcEdge(Graph &g, typename Graph::Node s, typename Graph::Node t, |
| 357 | 361 |
dummy<1> = 1) |
| 358 | 362 |
{
|
| 359 | 363 |
g.addArc(s,t); |
| 360 | 364 |
} |
| 361 | 365 |
|
| 362 |
/// DIMACS plain (di)graph reader function. |
|
| 366 |
/// \brief DIMACS plain (di)graph reader function. |
|
| 363 | 367 |
/// |
| 364 |
/// This function reads a (di)graph without any designated nodes and |
|
| 365 |
/// maps from DIMACS format, i.e. from DIMACS files having a line |
|
| 366 |
/// |
|
| 368 |
/// This function reads a plain (di)graph without any designated nodes |
|
| 369 |
/// and maps (e.g. a matching instance) from DIMACS format, i.e. from |
|
| 370 |
/// DIMACS files having a line starting with |
|
| 367 | 371 |
/// \code |
| 368 | 372 |
/// p mat |
| 369 | 373 |
/// \endcode |
| 370 | 374 |
/// At the beginning, \c g is cleared by \c g.clear(). |
| 371 | 375 |
/// |
| 372 | 376 |
/// If the file type was previously evaluated by dimacsType(), then |
| 373 | 377 |
/// the descriptor struct should be given by the \c dest parameter. |
| 374 | 378 |
template<typename Graph> |
| 375 | 379 |
void readDimacsMat(std::istream& is, Graph &g, |
| 376 | 380 |
DimacsDescriptor desc=DimacsDescriptor()) |
| 377 | 381 |
{
|
| 378 | 382 |
if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is); |
| 379 | 383 |
if(desc.type!=DimacsDescriptor::MAT) |
| 380 | 384 |
throw FormatError("Problem type mismatch");
|
| 381 | 385 |
|
| 382 | 386 |
g.clear(); |
| 383 | 387 |
std::vector<typename Graph::Node> nodes; |
| 384 | 388 |
char c; |
| 385 | 389 |
int i, j; |
| 386 | 390 |
std::string str; |
| 387 | 391 |
nodes.resize(desc.nodeNum + 1); |
| 388 | 392 |
for (int k = 1; k <= desc.nodeNum; ++k) {
|
| 389 | 393 |
nodes[k] = g.addNode(); |
| 390 | 394 |
} |
| 391 | 395 |
|
| 392 | 396 |
while (is >> c) {
|
| 393 | 397 |
switch (c) {
|
| 394 | 398 |
case 'c': // comment line |
| 395 | 399 |
getline(is, str); |
| 396 | 400 |
break; |
| 397 | 401 |
case 'n': // node definition line |
| 398 | 402 |
break; |
| 399 | 403 |
case 'a': // arc definition line |
| 400 | 404 |
is >> i >> j; |
| 401 | 405 |
getline(is, str); |
| 402 | 406 |
_addArcEdge(g,nodes[i], nodes[j]); |
| 403 | 407 |
break; |
| 404 | 408 |
} |
| 405 | 409 |
} |
| 406 | 410 |
} |
| 407 | 411 |
|
| 408 | 412 |
/// DIMACS plain digraph writer function. |
| 409 | 413 |
/// |
| 410 | 414 |
/// This function writes a digraph without any designated nodes and |
| 411 | 415 |
/// maps into DIMACS format, i.e. into DIMACS file having a line |
| 412 | 416 |
/// starting with |
| 413 | 417 |
/// \code |
| 414 | 418 |
/// p mat |
| ... | ... |
@@ -31,113 +31,113 @@ |
| 31 | 31 |
#include <lemon/bits/traits.h> |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
///Class for handling "labels" in push-relabel type algorithms. |
| 36 | 36 |
|
| 37 | 37 |
///A class for handling "labels" in push-relabel type algorithms. |
| 38 | 38 |
/// |
| 39 | 39 |
///\ingroup auxdat |
| 40 | 40 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
| 41 | 41 |
///to the edges or nodes of a graph, manipulate and query them through |
| 42 | 42 |
///operations typically arising in "push-relabel" type algorithms. |
| 43 | 43 |
/// |
| 44 | 44 |
///Each item is either \em active or not, and you can also choose a |
| 45 | 45 |
///highest level active item. |
| 46 | 46 |
/// |
| 47 | 47 |
///\sa LinkedElevator |
| 48 | 48 |
/// |
| 49 | 49 |
///\param GR Type of the underlying graph. |
| 50 | 50 |
///\param Item Type of the items the data is assigned to (\c GR::Node, |
| 51 | 51 |
///\c GR::Arc or \c GR::Edge). |
| 52 | 52 |
template<class GR, class Item> |
| 53 | 53 |
class Elevator |
| 54 | 54 |
{
|
| 55 | 55 |
public: |
| 56 | 56 |
|
| 57 | 57 |
typedef Item Key; |
| 58 | 58 |
typedef int Value; |
| 59 | 59 |
|
| 60 | 60 |
private: |
| 61 | 61 |
|
| 62 | 62 |
typedef Item *Vit; |
| 63 | 63 |
typedef typename ItemSetTraits<GR,Item>::template Map<Vit>::Type VitMap; |
| 64 | 64 |
typedef typename ItemSetTraits<GR,Item>::template Map<int>::Type IntMap; |
| 65 | 65 |
|
| 66 | 66 |
const GR &_g; |
| 67 | 67 |
int _max_level; |
| 68 | 68 |
int _item_num; |
| 69 | 69 |
VitMap _where; |
| 70 | 70 |
IntMap _level; |
| 71 | 71 |
std::vector<Item> _items; |
| 72 | 72 |
std::vector<Vit> _first; |
| 73 | 73 |
std::vector<Vit> _last_active; |
| 74 | 74 |
|
| 75 | 75 |
int _highest_active; |
| 76 | 76 |
|
| 77 | 77 |
void copy(Item i, Vit p) |
| 78 | 78 |
{
|
| 79 |
_where |
|
| 79 |
_where[*p=i] = p; |
|
| 80 | 80 |
} |
| 81 | 81 |
void copy(Vit s, Vit p) |
| 82 | 82 |
{
|
| 83 | 83 |
if(s!=p) |
| 84 | 84 |
{
|
| 85 | 85 |
Item i=*s; |
| 86 | 86 |
*p=i; |
| 87 |
_where |
|
| 87 |
_where[i] = p; |
|
| 88 | 88 |
} |
| 89 | 89 |
} |
| 90 | 90 |
void swap(Vit i, Vit j) |
| 91 | 91 |
{
|
| 92 | 92 |
Item ti=*i; |
| 93 | 93 |
Vit ct = _where[ti]; |
| 94 |
_where.set(ti,_where[*i=*j]); |
|
| 95 |
_where.set(*j,ct); |
|
| 94 |
_where[ti] = _where[*i=*j]; |
|
| 95 |
_where[*j] = ct; |
|
| 96 | 96 |
*j=ti; |
| 97 | 97 |
} |
| 98 | 98 |
|
| 99 | 99 |
public: |
| 100 | 100 |
|
| 101 | 101 |
///Constructor with given maximum level. |
| 102 | 102 |
|
| 103 | 103 |
///Constructor with given maximum level. |
| 104 | 104 |
/// |
| 105 | 105 |
///\param graph The underlying graph. |
| 106 | 106 |
///\param max_level The maximum allowed level. |
| 107 | 107 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>. |
| 108 | 108 |
Elevator(const GR &graph,int max_level) : |
| 109 | 109 |
_g(graph), |
| 110 | 110 |
_max_level(max_level), |
| 111 | 111 |
_item_num(_max_level), |
| 112 | 112 |
_where(graph), |
| 113 | 113 |
_level(graph,0), |
| 114 | 114 |
_items(_max_level), |
| 115 | 115 |
_first(_max_level+2), |
| 116 | 116 |
_last_active(_max_level+2), |
| 117 | 117 |
_highest_active(-1) {}
|
| 118 | 118 |
///Constructor. |
| 119 | 119 |
|
| 120 | 120 |
///Constructor. |
| 121 | 121 |
/// |
| 122 | 122 |
///\param graph The underlying graph. |
| 123 | 123 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>, |
| 124 | 124 |
///where \c max_level is equal to the number of labeled items in the graph. |
| 125 | 125 |
Elevator(const GR &graph) : |
| 126 | 126 |
_g(graph), |
| 127 | 127 |
_max_level(countItems<GR, Item>(graph)), |
| 128 | 128 |
_item_num(_max_level), |
| 129 | 129 |
_where(graph), |
| 130 | 130 |
_level(graph,0), |
| 131 | 131 |
_items(_max_level), |
| 132 | 132 |
_first(_max_level+2), |
| 133 | 133 |
_last_active(_max_level+2), |
| 134 | 134 |
_highest_active(-1) |
| 135 | 135 |
{
|
| 136 | 136 |
} |
| 137 | 137 |
|
| 138 | 138 |
///Activate item \c i. |
| 139 | 139 |
|
| 140 | 140 |
///Activate item \c i. |
| 141 | 141 |
///\pre Item \c i shouldn't be active before. |
| 142 | 142 |
void activate(Item i) |
| 143 | 143 |
{
|
| ... | ... |
@@ -181,314 +181,314 @@ |
| 181 | 181 |
} |
| 182 | 182 |
///Return the number of active items on level \c l. |
| 183 | 183 |
int activesOnLevel(int l) const |
| 184 | 184 |
{
|
| 185 | 185 |
return _last_active[l]-_first[l]+1; |
| 186 | 186 |
} |
| 187 | 187 |
///Return true if there is no active item on level \c l. |
| 188 | 188 |
bool activeFree(int l) const |
| 189 | 189 |
{
|
| 190 | 190 |
return _last_active[l]<_first[l]; |
| 191 | 191 |
} |
| 192 | 192 |
///Return the maximum allowed level. |
| 193 | 193 |
int maxLevel() const |
| 194 | 194 |
{
|
| 195 | 195 |
return _max_level; |
| 196 | 196 |
} |
| 197 | 197 |
|
| 198 | 198 |
///\name Highest Active Item |
| 199 | 199 |
///Functions for working with the highest level |
| 200 | 200 |
///active item. |
| 201 | 201 |
|
| 202 | 202 |
///@{
|
| 203 | 203 |
|
| 204 | 204 |
///Return a highest level active item. |
| 205 | 205 |
|
| 206 | 206 |
///Return a highest level active item or INVALID if there is no active |
| 207 | 207 |
///item. |
| 208 | 208 |
Item highestActive() const |
| 209 | 209 |
{
|
| 210 | 210 |
return _highest_active>=0?*_last_active[_highest_active]:INVALID; |
| 211 | 211 |
} |
| 212 | 212 |
|
| 213 | 213 |
///Return the highest active level. |
| 214 | 214 |
|
| 215 | 215 |
///Return the level of the highest active item or -1 if there is no active |
| 216 | 216 |
///item. |
| 217 | 217 |
int highestActiveLevel() const |
| 218 | 218 |
{
|
| 219 | 219 |
return _highest_active; |
| 220 | 220 |
} |
| 221 | 221 |
|
| 222 | 222 |
///Lift the highest active item by one. |
| 223 | 223 |
|
| 224 | 224 |
///Lift the item returned by highestActive() by one. |
| 225 | 225 |
/// |
| 226 | 226 |
void liftHighestActive() |
| 227 | 227 |
{
|
| 228 | 228 |
Item it = *_last_active[_highest_active]; |
| 229 |
|
|
| 229 |
++_level[it]; |
|
| 230 | 230 |
swap(_last_active[_highest_active]--,_last_active[_highest_active+1]); |
| 231 | 231 |
--_first[++_highest_active]; |
| 232 | 232 |
} |
| 233 | 233 |
|
| 234 | 234 |
///Lift the highest active item to the given level. |
| 235 | 235 |
|
| 236 | 236 |
///Lift the item returned by highestActive() to level \c new_level. |
| 237 | 237 |
/// |
| 238 | 238 |
///\warning \c new_level must be strictly higher |
| 239 | 239 |
///than the current level. |
| 240 | 240 |
/// |
| 241 | 241 |
void liftHighestActive(int new_level) |
| 242 | 242 |
{
|
| 243 | 243 |
const Item li = *_last_active[_highest_active]; |
| 244 | 244 |
|
| 245 | 245 |
copy(--_first[_highest_active+1],_last_active[_highest_active]--); |
| 246 | 246 |
for(int l=_highest_active+1;l<new_level;l++) |
| 247 | 247 |
{
|
| 248 | 248 |
copy(--_first[l+1],_first[l]); |
| 249 | 249 |
--_last_active[l]; |
| 250 | 250 |
} |
| 251 | 251 |
copy(li,_first[new_level]); |
| 252 |
_level |
|
| 252 |
_level[li] = new_level; |
|
| 253 | 253 |
_highest_active=new_level; |
| 254 | 254 |
} |
| 255 | 255 |
|
| 256 | 256 |
///Lift the highest active item to the top level. |
| 257 | 257 |
|
| 258 | 258 |
///Lift the item returned by highestActive() to the top level and |
| 259 | 259 |
///deactivate it. |
| 260 | 260 |
void liftHighestActiveToTop() |
| 261 | 261 |
{
|
| 262 | 262 |
const Item li = *_last_active[_highest_active]; |
| 263 | 263 |
|
| 264 | 264 |
copy(--_first[_highest_active+1],_last_active[_highest_active]--); |
| 265 | 265 |
for(int l=_highest_active+1;l<_max_level;l++) |
| 266 | 266 |
{
|
| 267 | 267 |
copy(--_first[l+1],_first[l]); |
| 268 | 268 |
--_last_active[l]; |
| 269 | 269 |
} |
| 270 | 270 |
copy(li,_first[_max_level]); |
| 271 | 271 |
--_last_active[_max_level]; |
| 272 |
_level |
|
| 272 |
_level[li] = _max_level; |
|
| 273 | 273 |
|
| 274 | 274 |
while(_highest_active>=0 && |
| 275 | 275 |
_last_active[_highest_active]<_first[_highest_active]) |
| 276 | 276 |
_highest_active--; |
| 277 | 277 |
} |
| 278 | 278 |
|
| 279 | 279 |
///@} |
| 280 | 280 |
|
| 281 | 281 |
///\name Active Item on Certain Level |
| 282 | 282 |
///Functions for working with the active items. |
| 283 | 283 |
|
| 284 | 284 |
///@{
|
| 285 | 285 |
|
| 286 | 286 |
///Return an active item on level \c l. |
| 287 | 287 |
|
| 288 | 288 |
///Return an active item on level \c l or \ref INVALID if there is no such |
| 289 | 289 |
///an item. (\c l must be from the range [0...\c max_level]. |
| 290 | 290 |
Item activeOn(int l) const |
| 291 | 291 |
{
|
| 292 | 292 |
return _last_active[l]>=_first[l]?*_last_active[l]:INVALID; |
| 293 | 293 |
} |
| 294 | 294 |
|
| 295 | 295 |
///Lift the active item returned by \c activeOn(level) by one. |
| 296 | 296 |
|
| 297 | 297 |
///Lift the active item returned by \ref activeOn() "activeOn(level)" |
| 298 | 298 |
///by one. |
| 299 | 299 |
Item liftActiveOn(int level) |
| 300 | 300 |
{
|
| 301 | 301 |
Item it =*_last_active[level]; |
| 302 |
|
|
| 302 |
++_level[it]; |
|
| 303 | 303 |
swap(_last_active[level]--, --_first[level+1]); |
| 304 | 304 |
if (level+1>_highest_active) ++_highest_active; |
| 305 | 305 |
} |
| 306 | 306 |
|
| 307 | 307 |
///Lift the active item returned by \c activeOn(level) to the given level. |
| 308 | 308 |
|
| 309 | 309 |
///Lift the active item returned by \ref activeOn() "activeOn(level)" |
| 310 | 310 |
///to the given level. |
| 311 | 311 |
void liftActiveOn(int level, int new_level) |
| 312 | 312 |
{
|
| 313 | 313 |
const Item ai = *_last_active[level]; |
| 314 | 314 |
|
| 315 | 315 |
copy(--_first[level+1], _last_active[level]--); |
| 316 | 316 |
for(int l=level+1;l<new_level;l++) |
| 317 | 317 |
{
|
| 318 | 318 |
copy(_last_active[l],_first[l]); |
| 319 | 319 |
copy(--_first[l+1], _last_active[l]--); |
| 320 | 320 |
} |
| 321 | 321 |
copy(ai,_first[new_level]); |
| 322 |
_level |
|
| 322 |
_level[ai] = new_level; |
|
| 323 | 323 |
if (new_level>_highest_active) _highest_active=new_level; |
| 324 | 324 |
} |
| 325 | 325 |
|
| 326 | 326 |
///Lift the active item returned by \c activeOn(level) to the top level. |
| 327 | 327 |
|
| 328 | 328 |
///Lift the active item returned by \ref activeOn() "activeOn(level)" |
| 329 | 329 |
///to the top level and deactivate it. |
| 330 | 330 |
void liftActiveToTop(int level) |
| 331 | 331 |
{
|
| 332 | 332 |
const Item ai = *_last_active[level]; |
| 333 | 333 |
|
| 334 | 334 |
copy(--_first[level+1],_last_active[level]--); |
| 335 | 335 |
for(int l=level+1;l<_max_level;l++) |
| 336 | 336 |
{
|
| 337 | 337 |
copy(_last_active[l],_first[l]); |
| 338 | 338 |
copy(--_first[l+1], _last_active[l]--); |
| 339 | 339 |
} |
| 340 | 340 |
copy(ai,_first[_max_level]); |
| 341 | 341 |
--_last_active[_max_level]; |
| 342 |
_level |
|
| 342 |
_level[ai] = _max_level; |
|
| 343 | 343 |
|
| 344 | 344 |
if (_highest_active==level) {
|
| 345 | 345 |
while(_highest_active>=0 && |
| 346 | 346 |
_last_active[_highest_active]<_first[_highest_active]) |
| 347 | 347 |
_highest_active--; |
| 348 | 348 |
} |
| 349 | 349 |
} |
| 350 | 350 |
|
| 351 | 351 |
///@} |
| 352 | 352 |
|
| 353 | 353 |
///Lift an active item to a higher level. |
| 354 | 354 |
|
| 355 | 355 |
///Lift an active item to a higher level. |
| 356 | 356 |
///\param i The item to be lifted. It must be active. |
| 357 | 357 |
///\param new_level The new level of \c i. It must be strictly higher |
| 358 | 358 |
///than the current level. |
| 359 | 359 |
/// |
| 360 | 360 |
void lift(Item i, int new_level) |
| 361 | 361 |
{
|
| 362 | 362 |
const int lo = _level[i]; |
| 363 | 363 |
const Vit w = _where[i]; |
| 364 | 364 |
|
| 365 | 365 |
copy(_last_active[lo],w); |
| 366 | 366 |
copy(--_first[lo+1],_last_active[lo]--); |
| 367 | 367 |
for(int l=lo+1;l<new_level;l++) |
| 368 | 368 |
{
|
| 369 | 369 |
copy(_last_active[l],_first[l]); |
| 370 | 370 |
copy(--_first[l+1],_last_active[l]--); |
| 371 | 371 |
} |
| 372 | 372 |
copy(i,_first[new_level]); |
| 373 |
_level |
|
| 373 |
_level[i] = new_level; |
|
| 374 | 374 |
if(new_level>_highest_active) _highest_active=new_level; |
| 375 | 375 |
} |
| 376 | 376 |
|
| 377 | 377 |
///Move an inactive item to the top but one level (in a dirty way). |
| 378 | 378 |
|
| 379 | 379 |
///This function moves an inactive item from the top level to the top |
| 380 | 380 |
///but one level (in a dirty way). |
| 381 | 381 |
///\warning It makes the underlying datastructure corrupt, so use it |
| 382 | 382 |
///only if you really know what it is for. |
| 383 | 383 |
///\pre The item is on the top level. |
| 384 | 384 |
void dirtyTopButOne(Item i) {
|
| 385 |
_level |
|
| 385 |
_level[i] = _max_level - 1; |
|
| 386 | 386 |
} |
| 387 | 387 |
|
| 388 | 388 |
///Lift all items on and above the given level to the top level. |
| 389 | 389 |
|
| 390 | 390 |
///This function lifts all items on and above level \c l to the top |
| 391 | 391 |
///level and deactivates them. |
| 392 | 392 |
void liftToTop(int l) |
| 393 | 393 |
{
|
| 394 | 394 |
const Vit f=_first[l]; |
| 395 | 395 |
const Vit tl=_first[_max_level]; |
| 396 | 396 |
for(Vit i=f;i!=tl;++i) |
| 397 |
_level |
|
| 397 |
_level[*i] = _max_level; |
|
| 398 | 398 |
for(int i=l;i<=_max_level;i++) |
| 399 | 399 |
{
|
| 400 | 400 |
_first[i]=f; |
| 401 | 401 |
_last_active[i]=f-1; |
| 402 | 402 |
} |
| 403 | 403 |
for(_highest_active=l-1; |
| 404 | 404 |
_highest_active>=0 && |
| 405 | 405 |
_last_active[_highest_active]<_first[_highest_active]; |
| 406 | 406 |
_highest_active--) ; |
| 407 | 407 |
} |
| 408 | 408 |
|
| 409 | 409 |
private: |
| 410 | 410 |
int _init_lev; |
| 411 | 411 |
Vit _init_num; |
| 412 | 412 |
|
| 413 | 413 |
public: |
| 414 | 414 |
|
| 415 | 415 |
///\name Initialization |
| 416 | 416 |
///Using these functions you can initialize the levels of the items. |
| 417 | 417 |
///\n |
| 418 | 418 |
///The initialization must be started with calling \c initStart(). |
| 419 | 419 |
///Then the items should be listed level by level starting with the |
| 420 | 420 |
///lowest one (level 0) using \c initAddItem() and \c initNewLevel(). |
| 421 | 421 |
///Finally \c initFinish() must be called. |
| 422 | 422 |
///The items not listed are put on the highest level. |
| 423 | 423 |
///@{
|
| 424 | 424 |
|
| 425 | 425 |
///Start the initialization process. |
| 426 | 426 |
void initStart() |
| 427 | 427 |
{
|
| 428 | 428 |
_init_lev=0; |
| 429 | 429 |
_init_num=&_items[0]; |
| 430 | 430 |
_first[0]=&_items[0]; |
| 431 | 431 |
_last_active[0]=&_items[0]-1; |
| 432 | 432 |
Vit n=&_items[0]; |
| 433 | 433 |
for(typename ItemSetTraits<GR,Item>::ItemIt i(_g);i!=INVALID;++i) |
| 434 | 434 |
{
|
| 435 | 435 |
*n=i; |
| 436 |
_where.set(i,n); |
|
| 437 |
_level.set(i,_max_level); |
|
| 436 |
_where[i] = n; |
|
| 437 |
_level[i] = _max_level; |
|
| 438 | 438 |
++n; |
| 439 | 439 |
} |
| 440 | 440 |
} |
| 441 | 441 |
|
| 442 | 442 |
///Add an item to the current level. |
| 443 | 443 |
void initAddItem(Item i) |
| 444 | 444 |
{
|
| 445 | 445 |
swap(_where[i],_init_num); |
| 446 |
_level |
|
| 446 |
_level[i] = _init_lev; |
|
| 447 | 447 |
++_init_num; |
| 448 | 448 |
} |
| 449 | 449 |
|
| 450 | 450 |
///Start a new level. |
| 451 | 451 |
|
| 452 | 452 |
///Start a new level. |
| 453 | 453 |
///It shouldn't be used before the items on level 0 are listed. |
| 454 | 454 |
void initNewLevel() |
| 455 | 455 |
{
|
| 456 | 456 |
_init_lev++; |
| 457 | 457 |
_first[_init_lev]=_init_num; |
| 458 | 458 |
_last_active[_init_lev]=_init_num-1; |
| 459 | 459 |
} |
| 460 | 460 |
|
| 461 | 461 |
///Finalize the initialization process. |
| 462 | 462 |
void initFinish() |
| 463 | 463 |
{
|
| 464 | 464 |
for(_init_lev++;_init_lev<=_max_level;_init_lev++) |
| 465 | 465 |
{
|
| 466 | 466 |
_first[_init_lev]=_init_num; |
| 467 | 467 |
_last_active[_init_lev]=_init_num-1; |
| 468 | 468 |
} |
| 469 | 469 |
_first[_max_level+1]=&_items[0]+_item_num; |
| 470 | 470 |
_last_active[_max_level+1]=&_items[0]+_item_num-1; |
| 471 | 471 |
_highest_active = -1; |
| 472 | 472 |
} |
| 473 | 473 |
|
| 474 | 474 |
///@} |
| 475 | 475 |
|
| 476 | 476 |
}; |
| 477 | 477 |
|
| 478 | 478 |
///Class for handling "labels" in push-relabel type algorithms. |
| 479 | 479 |
|
| 480 | 480 |
///A class for handling "labels" in push-relabel type algorithms. |
| 481 | 481 |
/// |
| 482 | 482 |
///\ingroup auxdat |
| 483 | 483 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
| 484 | 484 |
///to the edges or nodes of a graph, manipulate and query them through |
| 485 | 485 |
///operations typically arising in "push-relabel" type algorithms. |
| 486 | 486 |
/// |
| 487 | 487 |
///Each item is either \em active or not, and you can also choose a |
| 488 | 488 |
///highest level active item. |
| 489 | 489 |
/// |
| 490 | 490 |
///\sa Elevator |
| 491 | 491 |
/// |
| 492 | 492 |
///\param GR Type of the underlying graph. |
| 493 | 493 |
///\param Item Type of the items the data is assigned to (\c GR::Node, |
| 494 | 494 |
///\c GR::Arc or \c GR::Edge). |
| ... | ... |
@@ -506,477 +506,477 @@ |
| 506 | 506 |
typedef typename ItemSetTraits<GR,Item>:: |
| 507 | 507 |
template Map<int>::Type IntMap; |
| 508 | 508 |
typedef typename ItemSetTraits<GR,Item>:: |
| 509 | 509 |
template Map<bool>::Type BoolMap; |
| 510 | 510 |
|
| 511 | 511 |
const GR &_graph; |
| 512 | 512 |
int _max_level; |
| 513 | 513 |
int _item_num; |
| 514 | 514 |
std::vector<Item> _first, _last; |
| 515 | 515 |
ItemMap _prev, _next; |
| 516 | 516 |
int _highest_active; |
| 517 | 517 |
IntMap _level; |
| 518 | 518 |
BoolMap _active; |
| 519 | 519 |
|
| 520 | 520 |
public: |
| 521 | 521 |
///Constructor with given maximum level. |
| 522 | 522 |
|
| 523 | 523 |
///Constructor with given maximum level. |
| 524 | 524 |
/// |
| 525 | 525 |
///\param graph The underlying graph. |
| 526 | 526 |
///\param max_level The maximum allowed level. |
| 527 | 527 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>. |
| 528 | 528 |
LinkedElevator(const GR& graph, int max_level) |
| 529 | 529 |
: _graph(graph), _max_level(max_level), _item_num(_max_level), |
| 530 | 530 |
_first(_max_level + 1), _last(_max_level + 1), |
| 531 | 531 |
_prev(graph), _next(graph), |
| 532 | 532 |
_highest_active(-1), _level(graph), _active(graph) {}
|
| 533 | 533 |
|
| 534 | 534 |
///Constructor. |
| 535 | 535 |
|
| 536 | 536 |
///Constructor. |
| 537 | 537 |
/// |
| 538 | 538 |
///\param graph The underlying graph. |
| 539 | 539 |
///Set the range of the possible labels to <tt>[0..max_level]</tt>, |
| 540 | 540 |
///where \c max_level is equal to the number of labeled items in the graph. |
| 541 | 541 |
LinkedElevator(const GR& graph) |
| 542 | 542 |
: _graph(graph), _max_level(countItems<GR, Item>(graph)), |
| 543 | 543 |
_item_num(_max_level), |
| 544 | 544 |
_first(_max_level + 1), _last(_max_level + 1), |
| 545 | 545 |
_prev(graph, INVALID), _next(graph, INVALID), |
| 546 | 546 |
_highest_active(-1), _level(graph), _active(graph) {}
|
| 547 | 547 |
|
| 548 | 548 |
|
| 549 | 549 |
///Activate item \c i. |
| 550 | 550 |
|
| 551 | 551 |
///Activate item \c i. |
| 552 | 552 |
///\pre Item \c i shouldn't be active before. |
| 553 | 553 |
void activate(Item i) {
|
| 554 |
_active |
|
| 554 |
_active[i] = true; |
|
| 555 | 555 |
|
| 556 | 556 |
int level = _level[i]; |
| 557 | 557 |
if (level > _highest_active) {
|
| 558 | 558 |
_highest_active = level; |
| 559 | 559 |
} |
| 560 | 560 |
|
| 561 | 561 |
if (_prev[i] == INVALID || _active[_prev[i]]) return; |
| 562 | 562 |
//unlace |
| 563 |
_next |
|
| 563 |
_next[_prev[i]] = _next[i]; |
|
| 564 | 564 |
if (_next[i] != INVALID) {
|
| 565 |
_prev |
|
| 565 |
_prev[_next[i]] = _prev[i]; |
|
| 566 | 566 |
} else {
|
| 567 | 567 |
_last[level] = _prev[i]; |
| 568 | 568 |
} |
| 569 | 569 |
//lace |
| 570 |
_next.set(i, _first[level]); |
|
| 571 |
_prev.set(_first[level], i); |
|
| 572 |
|
|
| 570 |
_next[i] = _first[level]; |
|
| 571 |
_prev[_first[level]] = i; |
|
| 572 |
_prev[i] = INVALID; |
|
| 573 | 573 |
_first[level] = i; |
| 574 | 574 |
|
| 575 | 575 |
} |
| 576 | 576 |
|
| 577 | 577 |
///Deactivate item \c i. |
| 578 | 578 |
|
| 579 | 579 |
///Deactivate item \c i. |
| 580 | 580 |
///\pre Item \c i must be active before. |
| 581 | 581 |
void deactivate(Item i) {
|
| 582 |
_active |
|
| 582 |
_active[i] = false; |
|
| 583 | 583 |
int level = _level[i]; |
| 584 | 584 |
|
| 585 | 585 |
if (_next[i] == INVALID || !_active[_next[i]]) |
| 586 | 586 |
goto find_highest_level; |
| 587 | 587 |
|
| 588 | 588 |
//unlace |
| 589 |
_prev |
|
| 589 |
_prev[_next[i]] = _prev[i]; |
|
| 590 | 590 |
if (_prev[i] != INVALID) {
|
| 591 |
_next |
|
| 591 |
_next[_prev[i]] = _next[i]; |
|
| 592 | 592 |
} else {
|
| 593 | 593 |
_first[_level[i]] = _next[i]; |
| 594 | 594 |
} |
| 595 | 595 |
//lace |
| 596 |
_prev.set(i, _last[level]); |
|
| 597 |
_next.set(_last[level], i); |
|
| 598 |
|
|
| 596 |
_prev[i] = _last[level]; |
|
| 597 |
_next[_last[level]] = i; |
|
| 598 |
_next[i] = INVALID; |
|
| 599 | 599 |
_last[level] = i; |
| 600 | 600 |
|
| 601 | 601 |
find_highest_level: |
| 602 | 602 |
if (level == _highest_active) {
|
| 603 | 603 |
while (_highest_active >= 0 && activeFree(_highest_active)) |
| 604 | 604 |
--_highest_active; |
| 605 | 605 |
} |
| 606 | 606 |
} |
| 607 | 607 |
|
| 608 | 608 |
///Query whether item \c i is active |
| 609 | 609 |
bool active(Item i) const { return _active[i]; }
|
| 610 | 610 |
|
| 611 | 611 |
///Return the level of item \c i. |
| 612 | 612 |
int operator[](Item i) const { return _level[i]; }
|
| 613 | 613 |
|
| 614 | 614 |
///Return the number of items on level \c l. |
| 615 | 615 |
int onLevel(int l) const {
|
| 616 | 616 |
int num = 0; |
| 617 | 617 |
Item n = _first[l]; |
| 618 | 618 |
while (n != INVALID) {
|
| 619 | 619 |
++num; |
| 620 | 620 |
n = _next[n]; |
| 621 | 621 |
} |
| 622 | 622 |
return num; |
| 623 | 623 |
} |
| 624 | 624 |
|
| 625 | 625 |
///Return true if the level is empty. |
| 626 | 626 |
bool emptyLevel(int l) const {
|
| 627 | 627 |
return _first[l] == INVALID; |
| 628 | 628 |
} |
| 629 | 629 |
|
| 630 | 630 |
///Return the number of items above level \c l. |
| 631 | 631 |
int aboveLevel(int l) const {
|
| 632 | 632 |
int num = 0; |
| 633 | 633 |
for (int level = l + 1; level < _max_level; ++level) |
| 634 | 634 |
num += onLevel(level); |
| 635 | 635 |
return num; |
| 636 | 636 |
} |
| 637 | 637 |
|
| 638 | 638 |
///Return the number of active items on level \c l. |
| 639 | 639 |
int activesOnLevel(int l) const {
|
| 640 | 640 |
int num = 0; |
| 641 | 641 |
Item n = _first[l]; |
| 642 | 642 |
while (n != INVALID && _active[n]) {
|
| 643 | 643 |
++num; |
| 644 | 644 |
n = _next[n]; |
| 645 | 645 |
} |
| 646 | 646 |
return num; |
| 647 | 647 |
} |
| 648 | 648 |
|
| 649 | 649 |
///Return true if there is no active item on level \c l. |
| 650 | 650 |
bool activeFree(int l) const {
|
| 651 | 651 |
return _first[l] == INVALID || !_active[_first[l]]; |
| 652 | 652 |
} |
| 653 | 653 |
|
| 654 | 654 |
///Return the maximum allowed level. |
| 655 | 655 |
int maxLevel() const {
|
| 656 | 656 |
return _max_level; |
| 657 | 657 |
} |
| 658 | 658 |
|
| 659 | 659 |
///\name Highest Active Item |
| 660 | 660 |
///Functions for working with the highest level |
| 661 | 661 |
///active item. |
| 662 | 662 |
|
| 663 | 663 |
///@{
|
| 664 | 664 |
|
| 665 | 665 |
///Return a highest level active item. |
| 666 | 666 |
|
| 667 | 667 |
///Return a highest level active item or INVALID if there is no active |
| 668 | 668 |
///item. |
| 669 | 669 |
Item highestActive() const {
|
| 670 | 670 |
return _highest_active >= 0 ? _first[_highest_active] : INVALID; |
| 671 | 671 |
} |
| 672 | 672 |
|
| 673 | 673 |
///Return the highest active level. |
| 674 | 674 |
|
| 675 | 675 |
///Return the level of the highest active item or -1 if there is no active |
| 676 | 676 |
///item. |
| 677 | 677 |
int highestActiveLevel() const {
|
| 678 | 678 |
return _highest_active; |
| 679 | 679 |
} |
| 680 | 680 |
|
| 681 | 681 |
///Lift the highest active item by one. |
| 682 | 682 |
|
| 683 | 683 |
///Lift the item returned by highestActive() by one. |
| 684 | 684 |
/// |
| 685 | 685 |
void liftHighestActive() {
|
| 686 | 686 |
Item i = _first[_highest_active]; |
| 687 | 687 |
if (_next[i] != INVALID) {
|
| 688 |
_prev |
|
| 688 |
_prev[_next[i]] = INVALID; |
|
| 689 | 689 |
_first[_highest_active] = _next[i]; |
| 690 | 690 |
} else {
|
| 691 | 691 |
_first[_highest_active] = INVALID; |
| 692 | 692 |
_last[_highest_active] = INVALID; |
| 693 | 693 |
} |
| 694 |
_level |
|
| 694 |
_level[i] = ++_highest_active; |
|
| 695 | 695 |
if (_first[_highest_active] == INVALID) {
|
| 696 | 696 |
_first[_highest_active] = i; |
| 697 | 697 |
_last[_highest_active] = i; |
| 698 |
_prev.set(i, INVALID); |
|
| 699 |
_next.set(i, INVALID); |
|
| 698 |
_prev[i] = INVALID; |
|
| 699 |
_next[i] = INVALID; |
|
| 700 | 700 |
} else {
|
| 701 |
_prev.set(_first[_highest_active], i); |
|
| 702 |
_next.set(i, _first[_highest_active]); |
|
| 701 |
_prev[_first[_highest_active]] = i; |
|
| 702 |
_next[i] = _first[_highest_active]; |
|
| 703 | 703 |
_first[_highest_active] = i; |
| 704 | 704 |
} |
| 705 | 705 |
} |
| 706 | 706 |
|
| 707 | 707 |
///Lift the highest active item to the given level. |
| 708 | 708 |
|
| 709 | 709 |
///Lift the item returned by highestActive() to level \c new_level. |
| 710 | 710 |
/// |
| 711 | 711 |
///\warning \c new_level must be strictly higher |
| 712 | 712 |
///than the current level. |
| 713 | 713 |
/// |
| 714 | 714 |
void liftHighestActive(int new_level) {
|
| 715 | 715 |
Item i = _first[_highest_active]; |
| 716 | 716 |
if (_next[i] != INVALID) {
|
| 717 |
_prev |
|
| 717 |
_prev[_next[i]] = INVALID; |
|
| 718 | 718 |
_first[_highest_active] = _next[i]; |
| 719 | 719 |
} else {
|
| 720 | 720 |
_first[_highest_active] = INVALID; |
| 721 | 721 |
_last[_highest_active] = INVALID; |
| 722 | 722 |
} |
| 723 |
_level |
|
| 723 |
_level[i] = _highest_active = new_level; |
|
| 724 | 724 |
if (_first[_highest_active] == INVALID) {
|
| 725 | 725 |
_first[_highest_active] = _last[_highest_active] = i; |
| 726 |
_prev.set(i, INVALID); |
|
| 727 |
_next.set(i, INVALID); |
|
| 726 |
_prev[i] = INVALID; |
|
| 727 |
_next[i] = INVALID; |
|
| 728 | 728 |
} else {
|
| 729 |
_prev.set(_first[_highest_active], i); |
|
| 730 |
_next.set(i, _first[_highest_active]); |
|
| 729 |
_prev[_first[_highest_active]] = i; |
|
| 730 |
_next[i] = _first[_highest_active]; |
|
| 731 | 731 |
_first[_highest_active] = i; |
| 732 | 732 |
} |
| 733 | 733 |
} |
| 734 | 734 |
|
| 735 | 735 |
///Lift the highest active item to the top level. |
| 736 | 736 |
|
| 737 | 737 |
///Lift the item returned by highestActive() to the top level and |
| 738 | 738 |
///deactivate it. |
| 739 | 739 |
void liftHighestActiveToTop() {
|
| 740 | 740 |
Item i = _first[_highest_active]; |
| 741 |
_level |
|
| 741 |
_level[i] = _max_level; |
|
| 742 | 742 |
if (_next[i] != INVALID) {
|
| 743 |
_prev |
|
| 743 |
_prev[_next[i]] = INVALID; |
|
| 744 | 744 |
_first[_highest_active] = _next[i]; |
| 745 | 745 |
} else {
|
| 746 | 746 |
_first[_highest_active] = INVALID; |
| 747 | 747 |
_last[_highest_active] = INVALID; |
| 748 | 748 |
} |
| 749 | 749 |
while (_highest_active >= 0 && activeFree(_highest_active)) |
| 750 | 750 |
--_highest_active; |
| 751 | 751 |
} |
| 752 | 752 |
|
| 753 | 753 |
///@} |
| 754 | 754 |
|
| 755 | 755 |
///\name Active Item on Certain Level |
| 756 | 756 |
///Functions for working with the active items. |
| 757 | 757 |
|
| 758 | 758 |
///@{
|
| 759 | 759 |
|
| 760 | 760 |
///Return an active item on level \c l. |
| 761 | 761 |
|
| 762 | 762 |
///Return an active item on level \c l or \ref INVALID if there is no such |
| 763 | 763 |
///an item. (\c l must be from the range [0...\c max_level]. |
| 764 | 764 |
Item activeOn(int l) const |
| 765 | 765 |
{
|
| 766 | 766 |
return _active[_first[l]] ? _first[l] : INVALID; |
| 767 | 767 |
} |
| 768 | 768 |
|
| 769 | 769 |
///Lift the active item returned by \c activeOn(l) by one. |
| 770 | 770 |
|
| 771 | 771 |
///Lift the active item returned by \ref activeOn() "activeOn(l)" |
| 772 | 772 |
///by one. |
| 773 | 773 |
Item liftActiveOn(int l) |
| 774 | 774 |
{
|
| 775 | 775 |
Item i = _first[l]; |
| 776 | 776 |
if (_next[i] != INVALID) {
|
| 777 |
_prev |
|
| 777 |
_prev[_next[i]] = INVALID; |
|
| 778 | 778 |
_first[l] = _next[i]; |
| 779 | 779 |
} else {
|
| 780 | 780 |
_first[l] = INVALID; |
| 781 | 781 |
_last[l] = INVALID; |
| 782 | 782 |
} |
| 783 |
_level |
|
| 783 |
_level[i] = ++l; |
|
| 784 | 784 |
if (_first[l] == INVALID) {
|
| 785 | 785 |
_first[l] = _last[l] = i; |
| 786 |
_prev.set(i, INVALID); |
|
| 787 |
_next.set(i, INVALID); |
|
| 786 |
_prev[i] = INVALID; |
|
| 787 |
_next[i] = INVALID; |
|
| 788 | 788 |
} else {
|
| 789 |
_prev.set(_first[l], i); |
|
| 790 |
_next.set(i, _first[l]); |
|
| 789 |
_prev[_first[l]] = i; |
|
| 790 |
_next[i] = _first[l]; |
|
| 791 | 791 |
_first[l] = i; |
| 792 | 792 |
} |
| 793 | 793 |
if (_highest_active < l) {
|
| 794 | 794 |
_highest_active = l; |
| 795 | 795 |
} |
| 796 | 796 |
} |
| 797 | 797 |
|
| 798 | 798 |
///Lift the active item returned by \c activeOn(l) to the given level. |
| 799 | 799 |
|
| 800 | 800 |
///Lift the active item returned by \ref activeOn() "activeOn(l)" |
| 801 | 801 |
///to the given level. |
| 802 | 802 |
void liftActiveOn(int l, int new_level) |
| 803 | 803 |
{
|
| 804 | 804 |
Item i = _first[l]; |
| 805 | 805 |
if (_next[i] != INVALID) {
|
| 806 |
_prev |
|
| 806 |
_prev[_next[i]] = INVALID; |
|
| 807 | 807 |
_first[l] = _next[i]; |
| 808 | 808 |
} else {
|
| 809 | 809 |
_first[l] = INVALID; |
| 810 | 810 |
_last[l] = INVALID; |
| 811 | 811 |
} |
| 812 |
_level |
|
| 812 |
_level[i] = l = new_level; |
|
| 813 | 813 |
if (_first[l] == INVALID) {
|
| 814 | 814 |
_first[l] = _last[l] = i; |
| 815 |
_prev.set(i, INVALID); |
|
| 816 |
_next.set(i, INVALID); |
|
| 815 |
_prev[i] = INVALID; |
|
| 816 |
_next[i] = INVALID; |
|
| 817 | 817 |
} else {
|
| 818 |
_prev.set(_first[l], i); |
|
| 819 |
_next.set(i, _first[l]); |
|
| 818 |
_prev[_first[l]] = i; |
|
| 819 |
_next[i] = _first[l]; |
|
| 820 | 820 |
_first[l] = i; |
| 821 | 821 |
} |
| 822 | 822 |
if (_highest_active < l) {
|
| 823 | 823 |
_highest_active = l; |
| 824 | 824 |
} |
| 825 | 825 |
} |
| 826 | 826 |
|
| 827 | 827 |
///Lift the active item returned by \c activeOn(l) to the top level. |
| 828 | 828 |
|
| 829 | 829 |
///Lift the active item returned by \ref activeOn() "activeOn(l)" |
| 830 | 830 |
///to the top level and deactivate it. |
| 831 | 831 |
void liftActiveToTop(int l) |
| 832 | 832 |
{
|
| 833 | 833 |
Item i = _first[l]; |
| 834 | 834 |
if (_next[i] != INVALID) {
|
| 835 |
_prev |
|
| 835 |
_prev[_next[i]] = INVALID; |
|
| 836 | 836 |
_first[l] = _next[i]; |
| 837 | 837 |
} else {
|
| 838 | 838 |
_first[l] = INVALID; |
| 839 | 839 |
_last[l] = INVALID; |
| 840 | 840 |
} |
| 841 |
_level |
|
| 841 |
_level[i] = _max_level; |
|
| 842 | 842 |
if (l == _highest_active) {
|
| 843 | 843 |
while (_highest_active >= 0 && activeFree(_highest_active)) |
| 844 | 844 |
--_highest_active; |
| 845 | 845 |
} |
| 846 | 846 |
} |
| 847 | 847 |
|
| 848 | 848 |
///@} |
| 849 | 849 |
|
| 850 | 850 |
/// \brief Lift an active item to a higher level. |
| 851 | 851 |
/// |
| 852 | 852 |
/// Lift an active item to a higher level. |
| 853 | 853 |
/// \param i The item to be lifted. It must be active. |
| 854 | 854 |
/// \param new_level The new level of \c i. It must be strictly higher |
| 855 | 855 |
/// than the current level. |
| 856 | 856 |
/// |
| 857 | 857 |
void lift(Item i, int new_level) {
|
| 858 | 858 |
if (_next[i] != INVALID) {
|
| 859 |
_prev |
|
| 859 |
_prev[_next[i]] = _prev[i]; |
|
| 860 | 860 |
} else {
|
| 861 | 861 |
_last[new_level] = _prev[i]; |
| 862 | 862 |
} |
| 863 | 863 |
if (_prev[i] != INVALID) {
|
| 864 |
_next |
|
| 864 |
_next[_prev[i]] = _next[i]; |
|
| 865 | 865 |
} else {
|
| 866 | 866 |
_first[new_level] = _next[i]; |
| 867 | 867 |
} |
| 868 |
_level |
|
| 868 |
_level[i] = new_level; |
|
| 869 | 869 |
if (_first[new_level] == INVALID) {
|
| 870 | 870 |
_first[new_level] = _last[new_level] = i; |
| 871 |
_prev.set(i, INVALID); |
|
| 872 |
_next.set(i, INVALID); |
|
| 871 |
_prev[i] = INVALID; |
|
| 872 |
_next[i] = INVALID; |
|
| 873 | 873 |
} else {
|
| 874 |
_prev.set(_first[new_level], i); |
|
| 875 |
_next.set(i, _first[new_level]); |
|
| 874 |
_prev[_first[new_level]] = i; |
|
| 875 |
_next[i] = _first[new_level]; |
|
| 876 | 876 |
_first[new_level] = i; |
| 877 | 877 |
} |
| 878 | 878 |
if (_highest_active < new_level) {
|
| 879 | 879 |
_highest_active = new_level; |
| 880 | 880 |
} |
| 881 | 881 |
} |
| 882 | 882 |
|
| 883 | 883 |
///Move an inactive item to the top but one level (in a dirty way). |
| 884 | 884 |
|
| 885 | 885 |
///This function moves an inactive item from the top level to the top |
| 886 | 886 |
///but one level (in a dirty way). |
| 887 | 887 |
///\warning It makes the underlying datastructure corrupt, so use it |
| 888 | 888 |
///only if you really know what it is for. |
| 889 | 889 |
///\pre The item is on the top level. |
| 890 | 890 |
void dirtyTopButOne(Item i) {
|
| 891 |
_level |
|
| 891 |
_level[i] = _max_level - 1; |
|
| 892 | 892 |
} |
| 893 | 893 |
|
| 894 | 894 |
///Lift all items on and above the given level to the top level. |
| 895 | 895 |
|
| 896 | 896 |
///This function lifts all items on and above level \c l to the top |
| 897 | 897 |
///level and deactivates them. |
| 898 | 898 |
void liftToTop(int l) {
|
| 899 | 899 |
for (int i = l + 1; _first[i] != INVALID; ++i) {
|
| 900 | 900 |
Item n = _first[i]; |
| 901 | 901 |
while (n != INVALID) {
|
| 902 |
_level |
|
| 902 |
_level[n] = _max_level; |
|
| 903 | 903 |
n = _next[n]; |
| 904 | 904 |
} |
| 905 | 905 |
_first[i] = INVALID; |
| 906 | 906 |
_last[i] = INVALID; |
| 907 | 907 |
} |
| 908 | 908 |
if (_highest_active > l - 1) {
|
| 909 | 909 |
_highest_active = l - 1; |
| 910 | 910 |
while (_highest_active >= 0 && activeFree(_highest_active)) |
| 911 | 911 |
--_highest_active; |
| 912 | 912 |
} |
| 913 | 913 |
} |
| 914 | 914 |
|
| 915 | 915 |
private: |
| 916 | 916 |
|
| 917 | 917 |
int _init_level; |
| 918 | 918 |
|
| 919 | 919 |
public: |
| 920 | 920 |
|
| 921 | 921 |
///\name Initialization |
| 922 | 922 |
///Using these functions you can initialize the levels of the items. |
| 923 | 923 |
///\n |
| 924 | 924 |
///The initialization must be started with calling \c initStart(). |
| 925 | 925 |
///Then the items should be listed level by level starting with the |
| 926 | 926 |
///lowest one (level 0) using \c initAddItem() and \c initNewLevel(). |
| 927 | 927 |
///Finally \c initFinish() must be called. |
| 928 | 928 |
///The items not listed are put on the highest level. |
| 929 | 929 |
///@{
|
| 930 | 930 |
|
| 931 | 931 |
///Start the initialization process. |
| 932 | 932 |
void initStart() {
|
| 933 | 933 |
|
| 934 | 934 |
for (int i = 0; i <= _max_level; ++i) {
|
| 935 | 935 |
_first[i] = _last[i] = INVALID; |
| 936 | 936 |
} |
| 937 | 937 |
_init_level = 0; |
| 938 | 938 |
for(typename ItemSetTraits<GR,Item>::ItemIt i(_graph); |
| 939 | 939 |
i != INVALID; ++i) {
|
| 940 |
_level.set(i, _max_level); |
|
| 941 |
_active.set(i, false); |
|
| 940 |
_level[i] = _max_level; |
|
| 941 |
_active[i] = false; |
|
| 942 | 942 |
} |
| 943 | 943 |
} |
| 944 | 944 |
|
| 945 | 945 |
///Add an item to the current level. |
| 946 | 946 |
void initAddItem(Item i) {
|
| 947 |
_level |
|
| 947 |
_level[i] = _init_level; |
|
| 948 | 948 |
if (_last[_init_level] == INVALID) {
|
| 949 | 949 |
_first[_init_level] = i; |
| 950 | 950 |
_last[_init_level] = i; |
| 951 |
_prev.set(i, INVALID); |
|
| 952 |
_next.set(i, INVALID); |
|
| 951 |
_prev[i] = INVALID; |
|
| 952 |
_next[i] = INVALID; |
|
| 953 | 953 |
} else {
|
| 954 |
_prev.set(i, _last[_init_level]); |
|
| 955 |
_next.set(i, INVALID); |
|
| 956 |
|
|
| 954 |
_prev[i] = _last[_init_level]; |
|
| 955 |
_next[i] = INVALID; |
|
| 956 |
_next[_last[_init_level]] = i; |
|
| 957 | 957 |
_last[_init_level] = i; |
| 958 | 958 |
} |
| 959 | 959 |
} |
| 960 | 960 |
|
| 961 | 961 |
///Start a new level. |
| 962 | 962 |
|
| 963 | 963 |
///Start a new level. |
| 964 | 964 |
///It shouldn't be used before the items on level 0 are listed. |
| 965 | 965 |
void initNewLevel() {
|
| 966 | 966 |
++_init_level; |
| 967 | 967 |
} |
| 968 | 968 |
|
| 969 | 969 |
///Finalize the initialization process. |
| 970 | 970 |
void initFinish() {
|
| 971 | 971 |
_highest_active = -1; |
| 972 | 972 |
} |
| 973 | 973 |
|
| 974 | 974 |
///@} |
| 975 | 975 |
|
| 976 | 976 |
}; |
| 977 | 977 |
|
| 978 | 978 |
|
| 979 | 979 |
} //END OF NAMESPACE LEMON |
| 980 | 980 |
|
| 981 | 981 |
#endif |
| 982 | 982 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_EULER_H |
| 20 | 20 |
#define LEMON_EULER_H |
| 21 | 21 |
|
| 22 | 22 |
#include<lemon/core.h> |
| 23 | 23 |
#include<lemon/adaptors.h> |
| 24 | 24 |
#include<lemon/connectivity.h> |
| 25 | 25 |
#include <list> |
| 26 | 26 |
|
| 27 |
/// \ingroup |
|
| 27 |
/// \ingroup graph_properties |
|
| 28 | 28 |
/// \file |
| 29 | 29 |
/// \brief Euler tour |
| 30 | 30 |
/// |
| 31 | 31 |
///This file provides an Euler tour iterator and ways to check |
| 32 | 32 |
///if a digraph is euler. |
| 33 | 33 |
|
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
///Euler iterator for digraphs. |
| 38 | 38 |
|
| 39 |
/// \ingroup |
|
| 39 |
/// \ingroup graph_properties |
|
| 40 | 40 |
///This iterator converts to the \c Arc type of the digraph and using |
| 41 | 41 |
///operator ++, it provides an Euler tour of a \e directed |
| 42 | 42 |
///graph (if there exists). |
| 43 | 43 |
/// |
| 44 | 44 |
///For example |
| 45 | 45 |
///if the given digraph is Euler (i.e it has only one nontrivial component |
| 46 | 46 |
///and the in-degree is equal to the out-degree for all nodes), |
| 47 | 47 |
///the following code will put the arcs of \c g |
| 48 | 48 |
///to the vector \c et according to an |
| 49 | 49 |
///Euler tour of \c g. |
| 50 | 50 |
///\code |
| 51 | 51 |
/// std::vector<ListDigraph::Arc> et; |
| 52 | 52 |
/// for(DiEulerIt<ListDigraph> e(g),e!=INVALID;++e) |
| 53 | 53 |
/// et.push_back(e); |
| 54 | 54 |
///\endcode |
| 55 | 55 |
///If \c g is not Euler then the resulted tour will not be full or closed. |
| 56 | 56 |
///\sa EulerIt |
| 57 | 57 |
template<typename GR> |
| 58 | 58 |
class DiEulerIt |
| 59 | 59 |
{
|
| 60 | 60 |
typedef typename GR::Node Node; |
| 61 | 61 |
typedef typename GR::NodeIt NodeIt; |
| 62 | 62 |
typedef typename GR::Arc Arc; |
| 63 | 63 |
typedef typename GR::ArcIt ArcIt; |
| 64 | 64 |
typedef typename GR::OutArcIt OutArcIt; |
| 65 | 65 |
typedef typename GR::InArcIt InArcIt; |
| 66 | 66 |
|
| 67 | 67 |
const GR &g; |
| 68 | 68 |
typename GR::template NodeMap<OutArcIt> nedge; |
| 69 | 69 |
std::list<Arc> euler; |
| 70 | 70 |
|
| 71 | 71 |
public: |
| 72 | 72 |
|
| 73 | 73 |
///Constructor |
| 74 | 74 |
|
| 75 | 75 |
///\param gr A digraph. |
| 76 | 76 |
///\param start The starting point of the tour. If it is not given |
| 77 | 77 |
/// the tour will start from the first node. |
| 78 | 78 |
DiEulerIt(const GR &gr, typename GR::Node start = INVALID) |
| 79 | 79 |
: g(gr), nedge(g) |
| 80 | 80 |
{
|
| 81 | 81 |
if(start==INVALID) start=NodeIt(g); |
| 82 | 82 |
for(NodeIt n(g);n!=INVALID;++n) nedge[n]=OutArcIt(g,n); |
| 83 | 83 |
while(nedge[start]!=INVALID) {
|
| 84 | 84 |
euler.push_back(nedge[start]); |
| 85 | 85 |
Node next=g.target(nedge[start]); |
| 86 | 86 |
++nedge[start]; |
| 87 | 87 |
start=next; |
| 88 | 88 |
} |
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 | 91 |
///Arc Conversion |
| 92 | 92 |
operator Arc() { return euler.empty()?INVALID:euler.front(); }
|
| 93 | 93 |
bool operator==(Invalid) { return euler.empty(); }
|
| 94 | 94 |
bool operator!=(Invalid) { return !euler.empty(); }
|
| 95 | 95 |
|
| 96 | 96 |
///Next arc of the tour |
| 97 | 97 |
DiEulerIt &operator++() {
|
| 98 | 98 |
Node s=g.target(euler.front()); |
| 99 | 99 |
euler.pop_front(); |
| 100 | 100 |
//This produces a warning.Strange. |
| 101 | 101 |
//std::list<Arc>::iterator next=euler.begin(); |
| 102 | 102 |
typename std::list<Arc>::iterator next=euler.begin(); |
| 103 | 103 |
while(nedge[s]!=INVALID) {
|
| 104 | 104 |
euler.insert(next,nedge[s]); |
| 105 | 105 |
Node n=g.target(nedge[s]); |
| 106 | 106 |
++nedge[s]; |
| 107 | 107 |
s=n; |
| 108 | 108 |
} |
| 109 | 109 |
return *this; |
| 110 | 110 |
} |
| 111 | 111 |
///Postfix incrementation |
| 112 | 112 |
|
| 113 | 113 |
///\warning This incrementation |
| 114 | 114 |
///returns an \c Arc, not an \ref DiEulerIt, as one may |
| 115 | 115 |
///expect. |
| 116 | 116 |
Arc operator++(int) |
| 117 | 117 |
{
|
| 118 | 118 |
Arc e=*this; |
| 119 | 119 |
++(*this); |
| 120 | 120 |
return e; |
| 121 | 121 |
} |
| 122 | 122 |
}; |
| 123 | 123 |
|
| 124 | 124 |
///Euler iterator for graphs. |
| 125 | 125 |
|
| 126 |
/// \ingroup |
|
| 126 |
/// \ingroup graph_properties |
|
| 127 | 127 |
///This iterator converts to the \c Arc (or \c Edge) |
| 128 | 128 |
///type of the digraph and using |
| 129 | 129 |
///operator ++, it provides an Euler tour of an undirected |
| 130 | 130 |
///digraph (if there exists). |
| 131 | 131 |
/// |
| 132 | 132 |
///For example |
| 133 | 133 |
///if the given digraph if Euler (i.e it has only one nontrivial component |
| 134 | 134 |
///and the degree of each node is even), |
| 135 | 135 |
///the following code will print the arc IDs according to an |
| 136 | 136 |
///Euler tour of \c g. |
| 137 | 137 |
///\code |
| 138 | 138 |
/// for(EulerIt<ListGraph> e(g),e!=INVALID;++e) {
|
| 139 | 139 |
/// std::cout << g.id(Edge(e)) << std::eol; |
| 140 | 140 |
/// } |
| 141 | 141 |
///\endcode |
| 142 | 142 |
///Although the iterator provides an Euler tour of an graph, |
| 143 | 143 |
///it still returns Arcs in order to indicate the direction of the tour. |
| 144 | 144 |
///(But Arc will convert to Edges, of course). |
| 145 | 145 |
/// |
| 146 | 146 |
///If \c g is not Euler then the resulted tour will not be full or closed. |
| 147 | 147 |
///\sa EulerIt |
| 148 | 148 |
template<typename GR> |
| 149 | 149 |
class EulerIt |
| 150 | 150 |
{
|
| 151 | 151 |
typedef typename GR::Node Node; |
| 152 | 152 |
typedef typename GR::NodeIt NodeIt; |
| 153 | 153 |
typedef typename GR::Arc Arc; |
| 154 | 154 |
typedef typename GR::Edge Edge; |
| 155 | 155 |
typedef typename GR::ArcIt ArcIt; |
| 156 | 156 |
typedef typename GR::OutArcIt OutArcIt; |
| 157 | 157 |
typedef typename GR::InArcIt InArcIt; |
| 158 | 158 |
|
| 159 | 159 |
const GR &g; |
| 160 | 160 |
typename GR::template NodeMap<OutArcIt> nedge; |
| 161 | 161 |
typename GR::template EdgeMap<bool> visited; |
| 162 | 162 |
std::list<Arc> euler; |
| 163 | 163 |
|
| 164 | 164 |
public: |
| 165 | 165 |
|
| 166 | 166 |
///Constructor |
| 167 | 167 |
|
| 168 | 168 |
///\param gr An graph. |
| 169 | 169 |
///\param start The starting point of the tour. If it is not given |
| 170 | 170 |
/// the tour will start from the first node. |
| 171 | 171 |
EulerIt(const GR &gr, typename GR::Node start = INVALID) |
| 172 | 172 |
: g(gr), nedge(g), visited(g, false) |
| 173 | 173 |
{
|
| 174 | 174 |
if(start==INVALID) start=NodeIt(g); |
| ... | ... |
@@ -183,82 +183,82 @@ |
| 183 | 183 |
} |
| 184 | 184 |
} |
| 185 | 185 |
|
| 186 | 186 |
///Arc Conversion |
| 187 | 187 |
operator Arc() const { return euler.empty()?INVALID:euler.front(); }
|
| 188 | 188 |
///Arc Conversion |
| 189 | 189 |
operator Edge() const { return euler.empty()?INVALID:euler.front(); }
|
| 190 | 190 |
///\e |
| 191 | 191 |
bool operator==(Invalid) const { return euler.empty(); }
|
| 192 | 192 |
///\e |
| 193 | 193 |
bool operator!=(Invalid) const { return !euler.empty(); }
|
| 194 | 194 |
|
| 195 | 195 |
///Next arc of the tour |
| 196 | 196 |
EulerIt &operator++() {
|
| 197 | 197 |
Node s=g.target(euler.front()); |
| 198 | 198 |
euler.pop_front(); |
| 199 | 199 |
typename std::list<Arc>::iterator next=euler.begin(); |
| 200 | 200 |
|
| 201 | 201 |
while(nedge[s]!=INVALID) {
|
| 202 | 202 |
while(nedge[s]!=INVALID && visited[nedge[s]]) ++nedge[s]; |
| 203 | 203 |
if(nedge[s]==INVALID) break; |
| 204 | 204 |
else {
|
| 205 | 205 |
euler.insert(next,nedge[s]); |
| 206 | 206 |
visited[nedge[s]]=true; |
| 207 | 207 |
Node n=g.target(nedge[s]); |
| 208 | 208 |
++nedge[s]; |
| 209 | 209 |
s=n; |
| 210 | 210 |
} |
| 211 | 211 |
} |
| 212 | 212 |
return *this; |
| 213 | 213 |
} |
| 214 | 214 |
|
| 215 | 215 |
///Postfix incrementation |
| 216 | 216 |
|
| 217 | 217 |
///\warning This incrementation |
| 218 | 218 |
///returns an \c Arc, not an \ref EulerIt, as one may |
| 219 | 219 |
///expect. |
| 220 | 220 |
Arc operator++(int) |
| 221 | 221 |
{
|
| 222 | 222 |
Arc e=*this; |
| 223 | 223 |
++(*this); |
| 224 | 224 |
return e; |
| 225 | 225 |
} |
| 226 | 226 |
}; |
| 227 | 227 |
|
| 228 | 228 |
|
| 229 | 229 |
///Checks if the graph is Eulerian |
| 230 | 230 |
|
| 231 |
/// \ingroup |
|
| 231 |
/// \ingroup graph_properties |
|
| 232 | 232 |
///Checks if the graph is Eulerian. It works for both directed and undirected |
| 233 | 233 |
///graphs. |
| 234 | 234 |
///\note By definition, a digraph is called \e Eulerian if |
| 235 | 235 |
///and only if it is connected and the number of its incoming and outgoing |
| 236 | 236 |
///arcs are the same for each node. |
| 237 | 237 |
///Similarly, an undirected graph is called \e Eulerian if |
| 238 | 238 |
///and only if it is connected and the number of incident arcs is even |
| 239 | 239 |
///for each node. <em>Therefore, there are digraphs which are not Eulerian, |
| 240 | 240 |
///but still have an Euler tour</em>. |
| 241 | 241 |
template<typename GR> |
| 242 | 242 |
#ifdef DOXYGEN |
| 243 | 243 |
bool |
| 244 | 244 |
#else |
| 245 | 245 |
typename enable_if<UndirectedTagIndicator<GR>,bool>::type |
| 246 | 246 |
eulerian(const GR &g) |
| 247 | 247 |
{
|
| 248 | 248 |
for(typename GR::NodeIt n(g);n!=INVALID;++n) |
| 249 | 249 |
if(countIncEdges(g,n)%2) return false; |
| 250 | 250 |
return connected(g); |
| 251 | 251 |
} |
| 252 | 252 |
template<class GR> |
| 253 | 253 |
typename disable_if<UndirectedTagIndicator<GR>,bool>::type |
| 254 | 254 |
#endif |
| 255 | 255 |
eulerian(const GR &g) |
| 256 | 256 |
{
|
| 257 | 257 |
for(typename GR::NodeIt n(g);n!=INVALID;++n) |
| 258 | 258 |
if(countInArcs(g,n)!=countOutArcs(g,n)) return false; |
| 259 | 259 |
return connected(Undirector<const GR>(g)); |
| 260 | 260 |
} |
| 261 | 261 |
|
| 262 | 262 |
} |
| 263 | 263 |
|
| 264 | 264 |
#endif |
| ... | ... |
@@ -112,99 +112,98 @@ |
| 112 | 112 |
node._id = _node_num - 1; |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 | 115 |
static void next(Node& node) {
|
| 116 | 116 |
--node._id; |
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
void first(Arc& arc) const {
|
| 120 | 120 |
arc._id = _arc_num - 1; |
| 121 | 121 |
} |
| 122 | 122 |
|
| 123 | 123 |
static void next(Arc& arc) {
|
| 124 | 124 |
--arc._id; |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 | 127 |
void firstOut(Arc& arc, const Node& node) const {
|
| 128 | 128 |
arc._id = (node._id + 1) * _node_num - 1; |
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 | 131 |
void nextOut(Arc& arc) const {
|
| 132 | 132 |
if (arc._id % _node_num == 0) arc._id = 0; |
| 133 | 133 |
--arc._id; |
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 | 136 |
void firstIn(Arc& arc, const Node& node) const {
|
| 137 | 137 |
arc._id = _arc_num + node._id - _node_num; |
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 | 140 |
void nextIn(Arc& arc) const {
|
| 141 | 141 |
arc._id -= _node_num; |
| 142 | 142 |
if (arc._id < 0) arc._id = -1; |
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 | 145 |
}; |
| 146 | 146 |
|
| 147 | 147 |
typedef DigraphExtender<FullDigraphBase> ExtendedFullDigraphBase; |
| 148 | 148 |
|
| 149 | 149 |
/// \ingroup graphs |
| 150 | 150 |
/// |
| 151 | 151 |
/// \brief A full digraph class. |
| 152 | 152 |
/// |
| 153 | 153 |
/// This is a simple and fast directed full graph implementation. |
| 154 | 154 |
/// From each node go arcs to each node (including the source node), |
| 155 | 155 |
/// therefore the number of the arcs in the digraph is the square of |
| 156 | 156 |
/// the node number. This digraph type is completely static, so you |
| 157 | 157 |
/// can neither add nor delete either arcs or nodes, and it needs |
| 158 | 158 |
/// constant space in memory. |
| 159 | 159 |
/// |
| 160 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept |
|
| 161 |
/// and it also has an important extra feature that its maps are |
|
| 162 |
/// |
|
| 160 |
/// This class fully conforms to the \ref concepts::Digraph |
|
| 161 |
/// "Digraph concept". |
|
| 163 | 162 |
/// |
| 164 | 163 |
/// The \c FullDigraph and \c FullGraph classes are very similar, |
| 165 | 164 |
/// but there are two differences. While this class conforms only |
| 166 | 165 |
/// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph |
| 167 | 166 |
/// class conforms to the \ref concepts::Graph "Graph" concept, |
| 168 | 167 |
/// moreover \c FullGraph does not contain a loop arc for each |
| 169 | 168 |
/// node as \c FullDigraph does. |
| 170 | 169 |
/// |
| 171 | 170 |
/// \sa FullGraph |
| 172 | 171 |
class FullDigraph : public ExtendedFullDigraphBase {
|
| 173 | 172 |
public: |
| 174 | 173 |
|
| 175 | 174 |
typedef ExtendedFullDigraphBase Parent; |
| 176 | 175 |
|
| 177 | 176 |
/// \brief Constructor |
| 178 | 177 |
FullDigraph() { construct(0); }
|
| 179 | 178 |
|
| 180 | 179 |
/// \brief Constructor |
| 181 | 180 |
/// |
| 182 | 181 |
/// Constructor. |
| 183 | 182 |
/// \param n The number of the nodes. |
| 184 | 183 |
FullDigraph(int n) { construct(n); }
|
| 185 | 184 |
|
| 186 | 185 |
/// \brief Resizes the digraph |
| 187 | 186 |
/// |
| 188 | 187 |
/// Resizes the digraph. The function will fully destroy and |
| 189 | 188 |
/// rebuild the digraph. This cause that the maps of the digraph will |
| 190 | 189 |
/// reallocated automatically and the previous values will be lost. |
| 191 | 190 |
void resize(int n) {
|
| 192 | 191 |
Parent::notifier(Arc()).clear(); |
| 193 | 192 |
Parent::notifier(Node()).clear(); |
| 194 | 193 |
construct(n); |
| 195 | 194 |
Parent::notifier(Node()).build(); |
| 196 | 195 |
Parent::notifier(Arc()).build(); |
| 197 | 196 |
} |
| 198 | 197 |
|
| 199 | 198 |
/// \brief Returns the node with the given index. |
| 200 | 199 |
/// |
| 201 | 200 |
/// Returns the node with the given index. Since it is a static |
| 202 | 201 |
/// digraph its nodes can be indexed with integers from the range |
| 203 | 202 |
/// <tt>[0..nodeNum()-1]</tt>. |
| 204 | 203 |
/// \sa index() |
| 205 | 204 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 206 | 205 |
|
| 207 | 206 |
/// \brief Returns the index of the given node. |
| 208 | 207 |
/// |
| 209 | 208 |
/// Returns the index of the given node. Since it is a static |
| 210 | 209 |
/// digraph its nodes can be indexed with integers from the range |
| ... | ... |
@@ -482,99 +481,97 @@ |
| 482 | 481 |
} |
| 483 | 482 |
|
| 484 | 483 |
void firstInc(Edge& edge, bool& dir, const Node& node) const {
|
| 485 | 484 |
int u = node._id, v = _node_num - 1; |
| 486 | 485 |
if (u < v) {
|
| 487 | 486 |
edge._id = _eid(u, v); |
| 488 | 487 |
dir = true; |
| 489 | 488 |
} else {
|
| 490 | 489 |
--v; |
| 491 | 490 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 492 | 491 |
dir = false; |
| 493 | 492 |
} |
| 494 | 493 |
} |
| 495 | 494 |
|
| 496 | 495 |
void nextInc(Edge& edge, bool& dir) const {
|
| 497 | 496 |
int u, v; |
| 498 | 497 |
if (dir) {
|
| 499 | 498 |
_uvid(edge._id, u, v); |
| 500 | 499 |
--v; |
| 501 | 500 |
if (u < v) {
|
| 502 | 501 |
edge._id = _eid(u, v); |
| 503 | 502 |
} else {
|
| 504 | 503 |
--v; |
| 505 | 504 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 506 | 505 |
dir = false; |
| 507 | 506 |
} |
| 508 | 507 |
} else {
|
| 509 | 508 |
_uvid(edge._id, v, u); |
| 510 | 509 |
--v; |
| 511 | 510 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 512 | 511 |
} |
| 513 | 512 |
} |
| 514 | 513 |
|
| 515 | 514 |
}; |
| 516 | 515 |
|
| 517 | 516 |
typedef GraphExtender<FullGraphBase> ExtendedFullGraphBase; |
| 518 | 517 |
|
| 519 | 518 |
/// \ingroup graphs |
| 520 | 519 |
/// |
| 521 | 520 |
/// \brief An undirected full graph class. |
| 522 | 521 |
/// |
| 523 | 522 |
/// This is a simple and fast undirected full graph |
| 524 | 523 |
/// implementation. From each node go edge to each other node, |
| 525 | 524 |
/// therefore the number of edges in the graph is \f$n(n-1)/2\f$. |
| 526 | 525 |
/// This graph type is completely static, so you can neither |
| 527 | 526 |
/// add nor delete either edges or nodes, and it needs constant |
| 528 | 527 |
/// space in memory. |
| 529 | 528 |
/// |
| 530 |
/// This class conforms to the \ref concepts::Graph "Graph" concept |
|
| 531 |
/// and it also has an important extra feature that its maps are |
|
| 532 |
/// |
|
| 529 |
/// This class fully conforms to the \ref concepts::Graph "Graph concept". |
|
| 533 | 530 |
/// |
| 534 | 531 |
/// The \c FullGraph and \c FullDigraph classes are very similar, |
| 535 | 532 |
/// but there are two differences. While the \c FullDigraph class |
| 536 | 533 |
/// conforms only to the \ref concepts::Digraph "Digraph" concept, |
| 537 | 534 |
/// this class conforms to the \ref concepts::Graph "Graph" concept, |
| 538 | 535 |
/// moreover \c FullGraph does not contain a loop arc for each |
| 539 | 536 |
/// node as \c FullDigraph does. |
| 540 | 537 |
/// |
| 541 | 538 |
/// \sa FullDigraph |
| 542 | 539 |
class FullGraph : public ExtendedFullGraphBase {
|
| 543 | 540 |
public: |
| 544 | 541 |
|
| 545 | 542 |
typedef ExtendedFullGraphBase Parent; |
| 546 | 543 |
|
| 547 | 544 |
/// \brief Constructor |
| 548 | 545 |
FullGraph() { construct(0); }
|
| 549 | 546 |
|
| 550 | 547 |
/// \brief Constructor |
| 551 | 548 |
/// |
| 552 | 549 |
/// Constructor. |
| 553 | 550 |
/// \param n The number of the nodes. |
| 554 | 551 |
FullGraph(int n) { construct(n); }
|
| 555 | 552 |
|
| 556 | 553 |
/// \brief Resizes the graph |
| 557 | 554 |
/// |
| 558 | 555 |
/// Resizes the graph. The function will fully destroy and |
| 559 | 556 |
/// rebuild the graph. This cause that the maps of the graph will |
| 560 | 557 |
/// reallocated automatically and the previous values will be lost. |
| 561 | 558 |
void resize(int n) {
|
| 562 | 559 |
Parent::notifier(Arc()).clear(); |
| 563 | 560 |
Parent::notifier(Edge()).clear(); |
| 564 | 561 |
Parent::notifier(Node()).clear(); |
| 565 | 562 |
construct(n); |
| 566 | 563 |
Parent::notifier(Node()).build(); |
| 567 | 564 |
Parent::notifier(Edge()).build(); |
| 568 | 565 |
Parent::notifier(Arc()).build(); |
| 569 | 566 |
} |
| 570 | 567 |
|
| 571 | 568 |
/// \brief Returns the node with the given index. |
| 572 | 569 |
/// |
| 573 | 570 |
/// Returns the node with the given index. Since it is a static |
| 574 | 571 |
/// graph its nodes can be indexed with integers from the range |
| 575 | 572 |
/// <tt>[0..nodeNum()-1]</tt>. |
| 576 | 573 |
/// \sa index() |
| 577 | 574 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 578 | 575 |
|
| 579 | 576 |
/// \brief Returns the index of the given node. |
| 580 | 577 |
/// |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\file |
| 20 | 20 |
///\brief Implementation of the LEMON GLPK LP and MIP solver interface. |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/glpk.h> |
| 23 | 23 |
#include <glpk.h> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/assert.h> |
| 26 | 26 |
|
| 27 | 27 |
namespace lemon {
|
| 28 | 28 |
|
| 29 | 29 |
// GlpkBase members |
| 30 | 30 |
|
| 31 | 31 |
GlpkBase::GlpkBase() : LpBase() {
|
| 32 | 32 |
lp = glp_create_prob(); |
| 33 | 33 |
glp_create_index(lp); |
| 34 |
messageLevel(MESSAGE_NOTHING); |
|
| 34 | 35 |
} |
| 35 | 36 |
|
| 36 | 37 |
GlpkBase::GlpkBase(const GlpkBase &other) : LpBase() {
|
| 37 | 38 |
lp = glp_create_prob(); |
| 38 | 39 |
glp_copy_prob(lp, other.lp, GLP_ON); |
| 39 | 40 |
glp_create_index(lp); |
| 40 | 41 |
rows = other.rows; |
| 41 | 42 |
cols = other.cols; |
| 43 |
messageLevel(MESSAGE_NOTHING); |
|
| 42 | 44 |
} |
| 43 | 45 |
|
| 44 | 46 |
GlpkBase::~GlpkBase() {
|
| 45 | 47 |
glp_delete_prob(lp); |
| 46 | 48 |
} |
| 47 | 49 |
|
| 48 | 50 |
int GlpkBase::_addCol() {
|
| 49 | 51 |
int i = glp_add_cols(lp, 1); |
| 50 | 52 |
glp_set_col_bnds(lp, i, GLP_FR, 0.0, 0.0); |
| 51 | 53 |
return i; |
| 52 | 54 |
} |
| 53 | 55 |
|
| 54 | 56 |
int GlpkBase::_addRow() {
|
| 55 | 57 |
int i = glp_add_rows(lp, 1); |
| 56 | 58 |
glp_set_row_bnds(lp, i, GLP_FR, 0.0, 0.0); |
| 57 | 59 |
return i; |
| 58 | 60 |
} |
| 59 | 61 |
|
| 60 | 62 |
void GlpkBase::_eraseCol(int i) {
|
| 61 | 63 |
int ca[2]; |
| 62 | 64 |
ca[1] = i; |
| 63 | 65 |
glp_del_cols(lp, 1, ca); |
| 64 | 66 |
} |
| 65 | 67 |
|
| 66 | 68 |
void GlpkBase::_eraseRow(int i) {
|
| 67 | 69 |
int ra[2]; |
| 68 | 70 |
ra[1] = i; |
| 69 | 71 |
glp_del_rows(lp, 1, ra); |
| 70 | 72 |
} |
| 71 | 73 |
|
| 72 | 74 |
void GlpkBase::_eraseColId(int i) {
|
| 73 | 75 |
cols.eraseIndex(i); |
| 74 | 76 |
cols.shiftIndices(i); |
| 75 | 77 |
} |
| 76 | 78 |
|
| 77 | 79 |
void GlpkBase::_eraseRowId(int i) {
|
| 78 | 80 |
rows.eraseIndex(i); |
| 79 | 81 |
rows.shiftIndices(i); |
| 80 | 82 |
} |
| 81 | 83 |
|
| 82 | 84 |
void GlpkBase::_getColName(int c, std::string& name) const {
|
| 83 | 85 |
const char *str = glp_get_col_name(lp, c); |
| 84 | 86 |
if (str) name = str; |
| 85 | 87 |
else name.clear(); |
| 86 | 88 |
} |
| 87 | 89 |
|
| 88 | 90 |
void GlpkBase::_setColName(int c, const std::string & name) {
|
| 89 | 91 |
glp_set_col_name(lp, c, const_cast<char*>(name.c_str())); |
| ... | ... |
@@ -481,188 +483,180 @@ |
| 481 | 483 |
++b; |
| 482 | 484 |
} |
| 483 | 485 |
} |
| 484 | 486 |
} |
| 485 | 487 |
|
| 486 | 488 |
void GlpkBase::_setObjCoeff(int i, Value obj_coef) {
|
| 487 | 489 |
//i = 0 means the constant term (shift) |
| 488 | 490 |
glp_set_obj_coef(lp, i, obj_coef); |
| 489 | 491 |
} |
| 490 | 492 |
|
| 491 | 493 |
GlpkBase::Value GlpkBase::_getObjCoeff(int i) const {
|
| 492 | 494 |
//i = 0 means the constant term (shift) |
| 493 | 495 |
return glp_get_obj_coef(lp, i); |
| 494 | 496 |
} |
| 495 | 497 |
|
| 496 | 498 |
void GlpkBase::_setSense(GlpkBase::Sense sense) {
|
| 497 | 499 |
switch (sense) {
|
| 498 | 500 |
case MIN: |
| 499 | 501 |
glp_set_obj_dir(lp, GLP_MIN); |
| 500 | 502 |
break; |
| 501 | 503 |
case MAX: |
| 502 | 504 |
glp_set_obj_dir(lp, GLP_MAX); |
| 503 | 505 |
break; |
| 504 | 506 |
} |
| 505 | 507 |
} |
| 506 | 508 |
|
| 507 | 509 |
GlpkBase::Sense GlpkBase::_getSense() const {
|
| 508 | 510 |
switch(glp_get_obj_dir(lp)) {
|
| 509 | 511 |
case GLP_MIN: |
| 510 | 512 |
return MIN; |
| 511 | 513 |
case GLP_MAX: |
| 512 | 514 |
return MAX; |
| 513 | 515 |
default: |
| 514 | 516 |
LEMON_ASSERT(false, "Wrong sense"); |
| 515 | 517 |
return GlpkBase::Sense(); |
| 516 | 518 |
} |
| 517 | 519 |
} |
| 518 | 520 |
|
| 519 | 521 |
void GlpkBase::_clear() {
|
| 520 | 522 |
glp_erase_prob(lp); |
| 521 | 523 |
rows.clear(); |
| 522 | 524 |
cols.clear(); |
| 523 | 525 |
} |
| 524 | 526 |
|
| 525 | 527 |
void GlpkBase::freeEnv() {
|
| 526 | 528 |
glp_free_env(); |
| 527 | 529 |
} |
| 528 | 530 |
|
| 531 |
void GlpkBase::_messageLevel(MessageLevel level) {
|
|
| 532 |
switch (level) {
|
|
| 533 |
case MESSAGE_NOTHING: |
|
| 534 |
_message_level = GLP_MSG_OFF; |
|
| 535 |
break; |
|
| 536 |
case MESSAGE_ERROR: |
|
| 537 |
_message_level = GLP_MSG_ERR; |
|
| 538 |
break; |
|
| 539 |
case MESSAGE_WARNING: |
|
| 540 |
_message_level = GLP_MSG_ERR; |
|
| 541 |
break; |
|
| 542 |
case MESSAGE_NORMAL: |
|
| 543 |
_message_level = GLP_MSG_ON; |
|
| 544 |
break; |
|
| 545 |
case MESSAGE_VERBOSE: |
|
| 546 |
_message_level = GLP_MSG_ALL; |
|
| 547 |
break; |
|
| 548 |
} |
|
| 549 |
} |
|
| 550 |
|
|
| 529 | 551 |
GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper; |
| 530 | 552 |
|
| 531 | 553 |
// GlpkLp members |
| 532 | 554 |
|
| 533 | 555 |
GlpkLp::GlpkLp() |
| 534 | 556 |
: LpBase(), LpSolver(), GlpkBase() {
|
| 535 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
| 536 | 557 |
presolver(false); |
| 537 | 558 |
} |
| 538 | 559 |
|
| 539 | 560 |
GlpkLp::GlpkLp(const GlpkLp& other) |
| 540 | 561 |
: LpBase(other), LpSolver(other), GlpkBase(other) {
|
| 541 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
| 542 | 562 |
presolver(false); |
| 543 | 563 |
} |
| 544 | 564 |
|
| 545 | 565 |
GlpkLp* GlpkLp::newSolver() const { return new GlpkLp; }
|
| 546 | 566 |
GlpkLp* GlpkLp::cloneSolver() const { return new GlpkLp(*this); }
|
| 547 | 567 |
|
| 548 | 568 |
const char* GlpkLp::_solverName() const { return "GlpkLp"; }
|
| 549 | 569 |
|
| 550 | 570 |
void GlpkLp::_clear_temporals() {
|
| 551 | 571 |
_primal_ray.clear(); |
| 552 | 572 |
_dual_ray.clear(); |
| 553 | 573 |
} |
| 554 | 574 |
|
| 555 | 575 |
GlpkLp::SolveExitStatus GlpkLp::_solve() {
|
| 556 | 576 |
return solvePrimal(); |
| 557 | 577 |
} |
| 558 | 578 |
|
| 559 | 579 |
GlpkLp::SolveExitStatus GlpkLp::solvePrimal() {
|
| 560 | 580 |
_clear_temporals(); |
| 561 | 581 |
|
| 562 | 582 |
glp_smcp smcp; |
| 563 | 583 |
glp_init_smcp(&smcp); |
| 564 | 584 |
|
| 565 |
switch (_message_level) {
|
|
| 566 |
case MESSAGE_NO_OUTPUT: |
|
| 567 |
smcp.msg_lev = GLP_MSG_OFF; |
|
| 568 |
break; |
|
| 569 |
case MESSAGE_ERROR_MESSAGE: |
|
| 570 |
smcp.msg_lev = GLP_MSG_ERR; |
|
| 571 |
break; |
|
| 572 |
case MESSAGE_NORMAL_OUTPUT: |
|
| 573 |
smcp.msg_lev = GLP_MSG_ON; |
|
| 574 |
break; |
|
| 575 |
case MESSAGE_FULL_OUTPUT: |
|
| 576 |
smcp.msg_lev = GLP_MSG_ALL; |
|
| 577 |
break; |
|
| 578 |
} |
|
| 585 |
smcp.msg_lev = _message_level; |
|
| 579 | 586 |
smcp.presolve = _presolve; |
| 580 | 587 |
|
| 581 | 588 |
// If the basis is not valid we get an error return value. |
| 582 | 589 |
// In this case we can try to create a new basis. |
| 583 | 590 |
switch (glp_simplex(lp, &smcp)) {
|
| 584 | 591 |
case 0: |
| 585 | 592 |
break; |
| 586 | 593 |
case GLP_EBADB: |
| 587 | 594 |
case GLP_ESING: |
| 588 | 595 |
case GLP_ECOND: |
| 589 | 596 |
glp_term_out(false); |
| 590 | 597 |
glp_adv_basis(lp, 0); |
| 591 | 598 |
glp_term_out(true); |
| 592 | 599 |
if (glp_simplex(lp, &smcp) != 0) return UNSOLVED; |
| 593 | 600 |
break; |
| 594 | 601 |
default: |
| 595 | 602 |
return UNSOLVED; |
| 596 | 603 |
} |
| 597 | 604 |
|
| 598 | 605 |
return SOLVED; |
| 599 | 606 |
} |
| 600 | 607 |
|
| 601 | 608 |
GlpkLp::SolveExitStatus GlpkLp::solveDual() {
|
| 602 | 609 |
_clear_temporals(); |
| 603 | 610 |
|
| 604 | 611 |
glp_smcp smcp; |
| 605 | 612 |
glp_init_smcp(&smcp); |
| 606 | 613 |
|
| 607 |
switch (_message_level) {
|
|
| 608 |
case MESSAGE_NO_OUTPUT: |
|
| 609 |
smcp.msg_lev = GLP_MSG_OFF; |
|
| 610 |
break; |
|
| 611 |
case MESSAGE_ERROR_MESSAGE: |
|
| 612 |
smcp.msg_lev = GLP_MSG_ERR; |
|
| 613 |
break; |
|
| 614 |
case MESSAGE_NORMAL_OUTPUT: |
|
| 615 |
smcp.msg_lev = GLP_MSG_ON; |
|
| 616 |
break; |
|
| 617 |
case MESSAGE_FULL_OUTPUT: |
|
| 618 |
smcp.msg_lev = GLP_MSG_ALL; |
|
| 619 |
break; |
|
| 620 |
} |
|
| 614 |
smcp.msg_lev = _message_level; |
|
| 621 | 615 |
smcp.meth = GLP_DUAL; |
| 622 | 616 |
smcp.presolve = _presolve; |
| 623 | 617 |
|
| 624 | 618 |
// If the basis is not valid we get an error return value. |
| 625 | 619 |
// In this case we can try to create a new basis. |
| 626 | 620 |
switch (glp_simplex(lp, &smcp)) {
|
| 627 | 621 |
case 0: |
| 628 | 622 |
break; |
| 629 | 623 |
case GLP_EBADB: |
| 630 | 624 |
case GLP_ESING: |
| 631 | 625 |
case GLP_ECOND: |
| 632 | 626 |
glp_term_out(false); |
| 633 | 627 |
glp_adv_basis(lp, 0); |
| 634 | 628 |
glp_term_out(true); |
| 635 | 629 |
if (glp_simplex(lp, &smcp) != 0) return UNSOLVED; |
| 636 | 630 |
break; |
| 637 | 631 |
default: |
| 638 | 632 |
return UNSOLVED; |
| 639 | 633 |
} |
| 640 | 634 |
return SOLVED; |
| 641 | 635 |
} |
| 642 | 636 |
|
| 643 | 637 |
GlpkLp::Value GlpkLp::_getPrimal(int i) const {
|
| 644 | 638 |
return glp_get_col_prim(lp, i); |
| 645 | 639 |
} |
| 646 | 640 |
|
| 647 | 641 |
GlpkLp::Value GlpkLp::_getDual(int i) const {
|
| 648 | 642 |
return glp_get_row_dual(lp, i); |
| 649 | 643 |
} |
| 650 | 644 |
|
| 651 | 645 |
GlpkLp::Value GlpkLp::_getPrimalValue() const {
|
| 652 | 646 |
return glp_get_obj_val(lp); |
| 653 | 647 |
} |
| 654 | 648 |
|
| 655 | 649 |
GlpkLp::VarStatus GlpkLp::_getColStatus(int i) const {
|
| 656 | 650 |
switch (glp_get_col_stat(lp, i)) {
|
| 657 | 651 |
case GLP_BS: |
| 658 | 652 |
return BASIC; |
| 659 | 653 |
case GLP_UP: |
| 660 | 654 |
return UPPER; |
| 661 | 655 |
case GLP_LO: |
| 662 | 656 |
return LOWER; |
| 663 | 657 |
case GLP_NF: |
| 664 | 658 |
return FREE; |
| 665 | 659 |
case GLP_NS: |
| 666 | 660 |
return FIXED; |
| 667 | 661 |
default: |
| 668 | 662 |
LEMON_ASSERT(false, "Wrong column status"); |
| ... | ... |
@@ -813,197 +807,161 @@ |
| 813 | 807 |
} |
| 814 | 808 |
|
| 815 | 809 |
GlpkLp::ProblemType GlpkLp::_getPrimalType() const {
|
| 816 | 810 |
if (glp_get_status(lp) == GLP_OPT) |
| 817 | 811 |
return OPTIMAL; |
| 818 | 812 |
switch (glp_get_prim_stat(lp)) {
|
| 819 | 813 |
case GLP_UNDEF: |
| 820 | 814 |
return UNDEFINED; |
| 821 | 815 |
case GLP_FEAS: |
| 822 | 816 |
case GLP_INFEAS: |
| 823 | 817 |
if (glp_get_dual_stat(lp) == GLP_NOFEAS) {
|
| 824 | 818 |
return UNBOUNDED; |
| 825 | 819 |
} else {
|
| 826 | 820 |
return UNDEFINED; |
| 827 | 821 |
} |
| 828 | 822 |
case GLP_NOFEAS: |
| 829 | 823 |
return INFEASIBLE; |
| 830 | 824 |
default: |
| 831 | 825 |
LEMON_ASSERT(false, "Wrong primal type"); |
| 832 | 826 |
return GlpkLp::ProblemType(); |
| 833 | 827 |
} |
| 834 | 828 |
} |
| 835 | 829 |
|
| 836 | 830 |
GlpkLp::ProblemType GlpkLp::_getDualType() const {
|
| 837 | 831 |
if (glp_get_status(lp) == GLP_OPT) |
| 838 | 832 |
return OPTIMAL; |
| 839 | 833 |
switch (glp_get_dual_stat(lp)) {
|
| 840 | 834 |
case GLP_UNDEF: |
| 841 | 835 |
return UNDEFINED; |
| 842 | 836 |
case GLP_FEAS: |
| 843 | 837 |
case GLP_INFEAS: |
| 844 | 838 |
if (glp_get_prim_stat(lp) == GLP_NOFEAS) {
|
| 845 | 839 |
return UNBOUNDED; |
| 846 | 840 |
} else {
|
| 847 | 841 |
return UNDEFINED; |
| 848 | 842 |
} |
| 849 | 843 |
case GLP_NOFEAS: |
| 850 | 844 |
return INFEASIBLE; |
| 851 | 845 |
default: |
| 852 | 846 |
LEMON_ASSERT(false, "Wrong primal type"); |
| 853 | 847 |
return GlpkLp::ProblemType(); |
| 854 | 848 |
} |
| 855 | 849 |
} |
| 856 | 850 |
|
| 857 | 851 |
void GlpkLp::presolver(bool presolve) {
|
| 858 | 852 |
_presolve = presolve; |
| 859 | 853 |
} |
| 860 | 854 |
|
| 861 |
void GlpkLp::messageLevel(MessageLevel m) {
|
|
| 862 |
_message_level = m; |
|
| 863 |
} |
|
| 864 |
|
|
| 865 | 855 |
// GlpkMip members |
| 866 | 856 |
|
| 867 | 857 |
GlpkMip::GlpkMip() |
| 868 | 858 |
: LpBase(), MipSolver(), GlpkBase() {
|
| 869 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
| 870 | 859 |
} |
| 871 | 860 |
|
| 872 | 861 |
GlpkMip::GlpkMip(const GlpkMip& other) |
| 873 | 862 |
: LpBase(), MipSolver(), GlpkBase(other) {
|
| 874 |
messageLevel(MESSAGE_NO_OUTPUT); |
|
| 875 | 863 |
} |
| 876 | 864 |
|
| 877 | 865 |
void GlpkMip::_setColType(int i, GlpkMip::ColTypes col_type) {
|
| 878 | 866 |
switch (col_type) {
|
| 879 | 867 |
case INTEGER: |
| 880 | 868 |
glp_set_col_kind(lp, i, GLP_IV); |
| 881 | 869 |
break; |
| 882 | 870 |
case REAL: |
| 883 | 871 |
glp_set_col_kind(lp, i, GLP_CV); |
| 884 | 872 |
break; |
| 885 | 873 |
} |
| 886 | 874 |
} |
| 887 | 875 |
|
| 888 | 876 |
GlpkMip::ColTypes GlpkMip::_getColType(int i) const {
|
| 889 | 877 |
switch (glp_get_col_kind(lp, i)) {
|
| 890 | 878 |
case GLP_IV: |
| 891 | 879 |
case GLP_BV: |
| 892 | 880 |
return INTEGER; |
| 893 | 881 |
default: |
| 894 | 882 |
return REAL; |
| 895 | 883 |
} |
| 896 | 884 |
|
| 897 | 885 |
} |
| 898 | 886 |
|
| 899 | 887 |
GlpkMip::SolveExitStatus GlpkMip::_solve() {
|
| 900 | 888 |
glp_smcp smcp; |
| 901 | 889 |
glp_init_smcp(&smcp); |
| 902 | 890 |
|
| 903 |
switch (_message_level) {
|
|
| 904 |
case MESSAGE_NO_OUTPUT: |
|
| 905 |
smcp.msg_lev = GLP_MSG_OFF; |
|
| 906 |
break; |
|
| 907 |
case MESSAGE_ERROR_MESSAGE: |
|
| 908 |
smcp.msg_lev = GLP_MSG_ERR; |
|
| 909 |
break; |
|
| 910 |
case MESSAGE_NORMAL_OUTPUT: |
|
| 911 |
smcp.msg_lev = GLP_MSG_ON; |
|
| 912 |
break; |
|
| 913 |
case MESSAGE_FULL_OUTPUT: |
|
| 914 |
smcp.msg_lev = GLP_MSG_ALL; |
|
| 915 |
break; |
|
| 916 |
} |
|
| 891 |
smcp.msg_lev = _message_level; |
|
| 917 | 892 |
smcp.meth = GLP_DUAL; |
| 918 | 893 |
|
| 919 | 894 |
// If the basis is not valid we get an error return value. |
| 920 | 895 |
// In this case we can try to create a new basis. |
| 921 | 896 |
switch (glp_simplex(lp, &smcp)) {
|
| 922 | 897 |
case 0: |
| 923 | 898 |
break; |
| 924 | 899 |
case GLP_EBADB: |
| 925 | 900 |
case GLP_ESING: |
| 926 | 901 |
case GLP_ECOND: |
| 927 | 902 |
glp_term_out(false); |
| 928 | 903 |
glp_adv_basis(lp, 0); |
| 929 | 904 |
glp_term_out(true); |
| 930 | 905 |
if (glp_simplex(lp, &smcp) != 0) return UNSOLVED; |
| 931 | 906 |
break; |
| 932 | 907 |
default: |
| 933 | 908 |
return UNSOLVED; |
| 934 | 909 |
} |
| 935 | 910 |
|
| 936 | 911 |
if (glp_get_status(lp) != GLP_OPT) return SOLVED; |
| 937 | 912 |
|
| 938 | 913 |
glp_iocp iocp; |
| 939 | 914 |
glp_init_iocp(&iocp); |
| 940 | 915 |
|
| 941 |
switch (_message_level) {
|
|
| 942 |
case MESSAGE_NO_OUTPUT: |
|
| 943 |
iocp.msg_lev = GLP_MSG_OFF; |
|
| 944 |
break; |
|
| 945 |
case MESSAGE_ERROR_MESSAGE: |
|
| 946 |
iocp.msg_lev = GLP_MSG_ERR; |
|
| 947 |
break; |
|
| 948 |
case MESSAGE_NORMAL_OUTPUT: |
|
| 949 |
iocp.msg_lev = GLP_MSG_ON; |
|
| 950 |
break; |
|
| 951 |
case MESSAGE_FULL_OUTPUT: |
|
| 952 |
iocp.msg_lev = GLP_MSG_ALL; |
|
| 953 |
break; |
|
| 954 |
} |
|
| 916 |
iocp.msg_lev = _message_level; |
|
| 955 | 917 |
|
| 956 | 918 |
if (glp_intopt(lp, &iocp) != 0) return UNSOLVED; |
| 957 | 919 |
return SOLVED; |
| 958 | 920 |
} |
| 959 | 921 |
|
| 960 | 922 |
|
| 961 | 923 |
GlpkMip::ProblemType GlpkMip::_getType() const {
|
| 962 | 924 |
switch (glp_get_status(lp)) {
|
| 963 | 925 |
case GLP_OPT: |
| 964 | 926 |
switch (glp_mip_status(lp)) {
|
| 965 | 927 |
case GLP_UNDEF: |
| 966 | 928 |
return UNDEFINED; |
| 967 | 929 |
case GLP_NOFEAS: |
| 968 | 930 |
return INFEASIBLE; |
| 969 | 931 |
case GLP_FEAS: |
| 970 | 932 |
return FEASIBLE; |
| 971 | 933 |
case GLP_OPT: |
| 972 | 934 |
return OPTIMAL; |
| 973 | 935 |
default: |
| 974 | 936 |
LEMON_ASSERT(false, "Wrong problem type."); |
| 975 | 937 |
return GlpkMip::ProblemType(); |
| 976 | 938 |
} |
| 977 | 939 |
case GLP_NOFEAS: |
| 978 | 940 |
return INFEASIBLE; |
| 979 | 941 |
case GLP_INFEAS: |
| 980 | 942 |
case GLP_FEAS: |
| 981 | 943 |
if (glp_get_dual_stat(lp) == GLP_NOFEAS) {
|
| 982 | 944 |
return UNBOUNDED; |
| 983 | 945 |
} else {
|
| 984 | 946 |
return UNDEFINED; |
| 985 | 947 |
} |
| 986 | 948 |
default: |
| 987 | 949 |
LEMON_ASSERT(false, "Wrong problem type."); |
| 988 | 950 |
return GlpkMip::ProblemType(); |
| 989 | 951 |
} |
| 990 | 952 |
} |
| 991 | 953 |
|
| 992 | 954 |
GlpkMip::Value GlpkMip::_getSol(int i) const {
|
| 993 | 955 |
return glp_mip_col_val(lp, i); |
| 994 | 956 |
} |
| 995 | 957 |
|
| 996 | 958 |
GlpkMip::Value GlpkMip::_getSolValue() const {
|
| 997 | 959 |
return glp_mip_obj_val(lp); |
| 998 | 960 |
} |
| 999 | 961 |
|
| 1000 | 962 |
GlpkMip* GlpkMip::newSolver() const { return new GlpkMip; }
|
| 1001 | 963 |
GlpkMip* GlpkMip::cloneSolver() const {return new GlpkMip(*this); }
|
| 1002 | 964 |
|
| 1003 | 965 |
const char* GlpkMip::_solverName() const { return "GlpkMip"; }
|
| 1004 | 966 |
|
| 1005 |
void GlpkMip::messageLevel(MessageLevel m) {
|
|
| 1006 |
_message_level = m; |
|
| 1007 |
} |
|
| 1008 |
|
|
| 1009 | 967 |
} //END OF NAMESPACE LEMON |
| ... | ... |
@@ -55,223 +55,181 @@ |
| 55 | 55 |
virtual int _addRow(); |
| 56 | 56 |
|
| 57 | 57 |
virtual void _eraseCol(int i); |
| 58 | 58 |
virtual void _eraseRow(int i); |
| 59 | 59 |
|
| 60 | 60 |
virtual void _eraseColId(int i); |
| 61 | 61 |
virtual void _eraseRowId(int i); |
| 62 | 62 |
|
| 63 | 63 |
virtual void _getColName(int col, std::string& name) const; |
| 64 | 64 |
virtual void _setColName(int col, const std::string& name); |
| 65 | 65 |
virtual int _colByName(const std::string& name) const; |
| 66 | 66 |
|
| 67 | 67 |
virtual void _getRowName(int row, std::string& name) const; |
| 68 | 68 |
virtual void _setRowName(int row, const std::string& name); |
| 69 | 69 |
virtual int _rowByName(const std::string& name) const; |
| 70 | 70 |
|
| 71 | 71 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 72 | 72 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 73 | 73 |
|
| 74 | 74 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 75 | 75 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 76 | 76 |
|
| 77 | 77 |
virtual void _setCoeff(int row, int col, Value value); |
| 78 | 78 |
virtual Value _getCoeff(int row, int col) const; |
| 79 | 79 |
|
| 80 | 80 |
virtual void _setColLowerBound(int i, Value value); |
| 81 | 81 |
virtual Value _getColLowerBound(int i) const; |
| 82 | 82 |
|
| 83 | 83 |
virtual void _setColUpperBound(int i, Value value); |
| 84 | 84 |
virtual Value _getColUpperBound(int i) const; |
| 85 | 85 |
|
| 86 | 86 |
virtual void _setRowLowerBound(int i, Value value); |
| 87 | 87 |
virtual Value _getRowLowerBound(int i) const; |
| 88 | 88 |
|
| 89 | 89 |
virtual void _setRowUpperBound(int i, Value value); |
| 90 | 90 |
virtual Value _getRowUpperBound(int i) const; |
| 91 | 91 |
|
| 92 | 92 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 93 | 93 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 94 | 94 |
|
| 95 | 95 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 96 | 96 |
virtual Value _getObjCoeff(int i) const; |
| 97 | 97 |
|
| 98 | 98 |
virtual void _setSense(Sense); |
| 99 | 99 |
virtual Sense _getSense() const; |
| 100 | 100 |
|
| 101 | 101 |
virtual void _clear(); |
| 102 | 102 |
|
| 103 |
virtual void _messageLevel(MessageLevel level); |
|
| 104 |
|
|
| 103 | 105 |
private: |
| 104 | 106 |
|
| 105 | 107 |
static void freeEnv(); |
| 106 | 108 |
|
| 107 | 109 |
struct FreeEnvHelper {
|
| 108 | 110 |
~FreeEnvHelper() {
|
| 109 | 111 |
freeEnv(); |
| 110 | 112 |
} |
| 111 | 113 |
}; |
| 112 | 114 |
|
| 113 | 115 |
static FreeEnvHelper freeEnvHelper; |
| 116 |
|
|
| 117 |
protected: |
|
| 118 |
|
|
| 119 |
int _message_level; |
|
| 114 | 120 |
|
| 115 | 121 |
public: |
| 116 | 122 |
|
| 117 | 123 |
///Pointer to the underlying GLPK data structure. |
| 118 | 124 |
LPX *lpx() {return lp;}
|
| 119 | 125 |
///Const pointer to the underlying GLPK data structure. |
| 120 | 126 |
const LPX *lpx() const {return lp;}
|
| 121 | 127 |
|
| 122 | 128 |
///Returns the constraint identifier understood by GLPK. |
| 123 | 129 |
int lpxRow(Row r) const { return rows(id(r)); }
|
| 124 | 130 |
|
| 125 | 131 |
///Returns the variable identifier understood by GLPK. |
| 126 | 132 |
int lpxCol(Col c) const { return cols(id(c)); }
|
| 127 | 133 |
|
| 128 | 134 |
}; |
| 129 | 135 |
|
| 130 | 136 |
/// \brief Interface for the GLPK LP solver |
| 131 | 137 |
/// |
| 132 | 138 |
/// This class implements an interface for the GLPK LP solver. |
| 133 | 139 |
///\ingroup lp_group |
| 134 | 140 |
class GlpkLp : public LpSolver, public GlpkBase {
|
| 135 | 141 |
public: |
| 136 | 142 |
|
| 137 | 143 |
///\e |
| 138 | 144 |
GlpkLp(); |
| 139 | 145 |
///\e |
| 140 | 146 |
GlpkLp(const GlpkLp&); |
| 141 | 147 |
|
| 142 | 148 |
///\e |
| 143 | 149 |
virtual GlpkLp* cloneSolver() const; |
| 144 | 150 |
///\e |
| 145 | 151 |
virtual GlpkLp* newSolver() const; |
| 146 | 152 |
|
| 147 | 153 |
private: |
| 148 | 154 |
|
| 149 | 155 |
mutable std::vector<double> _primal_ray; |
| 150 | 156 |
mutable std::vector<double> _dual_ray; |
| 151 | 157 |
|
| 152 | 158 |
void _clear_temporals(); |
| 153 | 159 |
|
| 154 | 160 |
protected: |
| 155 | 161 |
|
| 156 | 162 |
virtual const char* _solverName() const; |
| 157 | 163 |
|
| 158 | 164 |
virtual SolveExitStatus _solve(); |
| 159 | 165 |
virtual Value _getPrimal(int i) const; |
| 160 | 166 |
virtual Value _getDual(int i) const; |
| 161 | 167 |
|
| 162 | 168 |
virtual Value _getPrimalValue() const; |
| 163 | 169 |
|
| 164 | 170 |
virtual VarStatus _getColStatus(int i) const; |
| 165 | 171 |
virtual VarStatus _getRowStatus(int i) const; |
| 166 | 172 |
|
| 167 | 173 |
virtual Value _getPrimalRay(int i) const; |
| 168 | 174 |
virtual Value _getDualRay(int i) const; |
| 169 | 175 |
|
| 170 | 176 |
virtual ProblemType _getPrimalType() const; |
| 171 | 177 |
virtual ProblemType _getDualType() const; |
| 172 | 178 |
|
| 173 | 179 |
public: |
| 174 | 180 |
|
| 175 | 181 |
///Solve with primal simplex |
| 176 | 182 |
SolveExitStatus solvePrimal(); |
| 177 | 183 |
|
| 178 | 184 |
///Solve with dual simplex |
| 179 | 185 |
SolveExitStatus solveDual(); |
| 180 | 186 |
|
| 181 | 187 |
private: |
| 182 | 188 |
|
| 183 | 189 |
bool _presolve; |
| 184 | 190 |
|
| 185 | 191 |
public: |
| 186 | 192 |
|
| 187 | 193 |
///Turns on or off the presolver |
| 188 | 194 |
|
| 189 | 195 |
///Turns on (\c b is \c true) or off (\c b is \c false) the presolver |
| 190 | 196 |
/// |
| 191 | 197 |
///The presolver is off by default. |
| 192 | 198 |
void presolver(bool presolve); |
| 193 | 199 |
|
| 194 |
///Enum for \c messageLevel() parameter |
|
| 195 |
enum MessageLevel {
|
|
| 196 |
/// no output (default value) |
|
| 197 |
MESSAGE_NO_OUTPUT = 0, |
|
| 198 |
/// error messages only |
|
| 199 |
MESSAGE_ERROR_MESSAGE = 1, |
|
| 200 |
/// normal output |
|
| 201 |
MESSAGE_NORMAL_OUTPUT = 2, |
|
| 202 |
/// full output (includes informational messages) |
|
| 203 |
MESSAGE_FULL_OUTPUT = 3 |
|
| 204 |
}; |
|
| 205 |
|
|
| 206 |
private: |
|
| 207 |
|
|
| 208 |
MessageLevel _message_level; |
|
| 209 |
|
|
| 210 |
public: |
|
| 211 |
|
|
| 212 |
///Set the verbosity of the messages |
|
| 213 |
|
|
| 214 |
///Set the verbosity of the messages |
|
| 215 |
/// |
|
| 216 |
///\param m is the level of the messages output by the solver routines. |
|
| 217 |
void messageLevel(MessageLevel m); |
|
| 218 | 200 |
}; |
| 219 | 201 |
|
| 220 | 202 |
/// \brief Interface for the GLPK MIP solver |
| 221 | 203 |
/// |
| 222 | 204 |
/// This class implements an interface for the GLPK MIP solver. |
| 223 | 205 |
///\ingroup lp_group |
| 224 | 206 |
class GlpkMip : public MipSolver, public GlpkBase {
|
| 225 | 207 |
public: |
| 226 | 208 |
|
| 227 | 209 |
///\e |
| 228 | 210 |
GlpkMip(); |
| 229 | 211 |
///\e |
| 230 | 212 |
GlpkMip(const GlpkMip&); |
| 231 | 213 |
|
| 232 | 214 |
virtual GlpkMip* cloneSolver() const; |
| 233 | 215 |
virtual GlpkMip* newSolver() const; |
| 234 | 216 |
|
| 235 | 217 |
protected: |
| 236 | 218 |
|
| 237 | 219 |
virtual const char* _solverName() const; |
| 238 | 220 |
|
| 239 | 221 |
virtual ColTypes _getColType(int col) const; |
| 240 | 222 |
virtual void _setColType(int col, ColTypes col_type); |
| 241 | 223 |
|
| 242 | 224 |
virtual SolveExitStatus _solve(); |
| 243 | 225 |
virtual ProblemType _getType() const; |
| 244 | 226 |
virtual Value _getSol(int i) const; |
| 245 | 227 |
virtual Value _getSolValue() const; |
| 246 | 228 |
|
| 247 |
///Enum for \c messageLevel() parameter |
|
| 248 |
enum MessageLevel {
|
|
| 249 |
/// no output (default value) |
|
| 250 |
MESSAGE_NO_OUTPUT = 0, |
|
| 251 |
/// error messages only |
|
| 252 |
MESSAGE_ERROR_MESSAGE = 1, |
|
| 253 |
/// normal output |
|
| 254 |
MESSAGE_NORMAL_OUTPUT = 2, |
|
| 255 |
/// full output (includes informational messages) |
|
| 256 |
MESSAGE_FULL_OUTPUT = 3 |
|
| 257 |
}; |
|
| 258 |
|
|
| 259 |
private: |
|
| 260 |
|
|
| 261 |
MessageLevel _message_level; |
|
| 262 |
|
|
| 263 |
public: |
|
| 264 |
|
|
| 265 |
///Set the verbosity of the messages |
|
| 266 |
|
|
| 267 |
///Set the verbosity of the messages |
|
| 268 |
/// |
|
| 269 |
///\param m is the level of the messages output by the solver routines. |
|
| 270 |
void messageLevel(MessageLevel m); |
|
| 271 | 229 |
}; |
| 272 | 230 |
|
| 273 | 231 |
|
| 274 | 232 |
} //END OF NAMESPACE LEMON |
| 275 | 233 |
|
| 276 | 234 |
#endif //LEMON_GLPK_H |
| 277 | 235 |
| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_GOMORY_HU_TREE_H |
| 20 | 20 |
#define LEMON_GOMORY_HU_TREE_H |
| 21 | 21 |
|
| 22 | 22 |
#include <limits> |
| 23 | 23 |
|
| 24 | 24 |
#include <lemon/core.h> |
| 25 | 25 |
#include <lemon/preflow.h> |
| 26 | 26 |
#include <lemon/concept_check.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
/// \ingroup min_cut |
| 30 | 30 |
/// \file |
| 31 | 31 |
/// \brief Gomory-Hu cut tree in graphs. |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
/// \ingroup min_cut |
| 36 | 36 |
/// |
| 37 | 37 |
/// \brief Gomory-Hu cut tree algorithm |
| 38 | 38 |
/// |
| 39 | 39 |
/// The Gomory-Hu tree is a tree on the node set of a given graph, but it |
| 40 | 40 |
/// may contain edges which are not in the original graph. It has the |
| 41 | 41 |
/// property that the minimum capacity edge of the path between two nodes |
| 42 | 42 |
/// in this tree has the same weight as the minimum cut in the graph |
| 43 | 43 |
/// between these nodes. Moreover the components obtained by removing |
| 44 | 44 |
/// this edge from the tree determine the corresponding minimum cut. |
| 45 |
/// |
|
| 46 | 45 |
/// Therefore once this tree is computed, the minimum cut between any pair |
| 47 | 46 |
/// of nodes can easily be obtained. |
| 48 | 47 |
/// |
| 49 | 48 |
/// The algorithm calculates \e n-1 distinct minimum cuts (currently with |
| 50 |
/// the \ref Preflow algorithm), therefore the algorithm has |
|
| 51 |
/// \f$(O(n^3\sqrt{e})\f$ overall time complexity. It calculates a
|
|
| 52 |
/// rooted Gomory-Hu tree, its structure and the weights can be obtained |
|
| 53 |
/// by \c predNode(), \c predValue() and \c rootDist(). |
|
| 54 |
/// |
|
| 55 |
/// The members \c minCutMap() and \c minCutValue() calculate |
|
| 49 |
/// the \ref Preflow algorithm), thus it has \f$O(n^3\sqrt{e})\f$ overall
|
|
| 50 |
/// time complexity. It calculates a rooted Gomory-Hu tree. |
|
| 51 |
/// The structure of the tree and the edge weights can be |
|
| 52 |
/// obtained using \c predNode(), \c predValue() and \c rootDist(). |
|
| 53 |
/// The functions \c minCutMap() and \c minCutValue() calculate |
|
| 56 | 54 |
/// the minimum cut and the minimum cut value between any two nodes |
| 57 | 55 |
/// in the graph. You can also list (iterate on) the nodes and the |
| 58 | 56 |
/// edges of the cuts using \c MinCutNodeIt and \c MinCutEdgeIt. |
| 59 | 57 |
/// |
| 60 | 58 |
/// \tparam GR The type of the undirected graph the algorithm runs on. |
| 61 |
/// \tparam CAP The type of the edge map describing the edge capacities. |
|
| 62 |
/// It is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>" by default. |
|
| 59 |
/// \tparam CAP The type of the edge map containing the capacities. |
|
| 60 |
/// The default map type is \ref concepts::Graph::EdgeMap "GR::EdgeMap<int>". |
|
| 63 | 61 |
#ifdef DOXYGEN |
| 64 | 62 |
template <typename GR, |
| 65 | 63 |
typename CAP> |
| 66 | 64 |
#else |
| 67 | 65 |
template <typename GR, |
| 68 | 66 |
typename CAP = typename GR::template EdgeMap<int> > |
| 69 | 67 |
#endif |
| 70 | 68 |
class GomoryHu {
|
| 71 | 69 |
public: |
| 72 | 70 |
|
| 73 |
/// The graph type |
|
| 71 |
/// The graph type of the algorithm |
|
| 74 | 72 |
typedef GR Graph; |
| 75 |
/// The type of the |
|
| 73 |
/// The capacity map type of the algorithm |
|
| 76 | 74 |
typedef CAP Capacity; |
| 77 | 75 |
/// The value type of capacities |
| 78 | 76 |
typedef typename Capacity::Value Value; |
| 79 | 77 |
|
| 80 | 78 |
private: |
| 81 | 79 |
|
| 82 | 80 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
| 83 | 81 |
|
| 84 | 82 |
const Graph& _graph; |
| 85 | 83 |
const Capacity& _capacity; |
| 86 | 84 |
|
| 87 | 85 |
Node _root; |
| 88 | 86 |
typename Graph::template NodeMap<Node>* _pred; |
| 89 | 87 |
typename Graph::template NodeMap<Value>* _weight; |
| 90 | 88 |
typename Graph::template NodeMap<int>* _order; |
| 91 | 89 |
|
| 92 | 90 |
void createStructures() {
|
| 93 | 91 |
if (!_pred) {
|
| 94 | 92 |
_pred = new typename Graph::template NodeMap<Node>(_graph); |
| 95 | 93 |
} |
| 96 | 94 |
if (!_weight) {
|
| 97 | 95 |
_weight = new typename Graph::template NodeMap<Value>(_graph); |
| 98 | 96 |
} |
| 99 | 97 |
if (!_order) {
|
| 100 | 98 |
_order = new typename Graph::template NodeMap<int>(_graph); |
| 101 | 99 |
} |
| 102 | 100 |
} |
| 103 | 101 |
|
| 104 | 102 |
void destroyStructures() {
|
| 105 | 103 |
if (_pred) {
|
| 106 | 104 |
delete _pred; |
| 107 | 105 |
} |
| 108 | 106 |
if (_weight) {
|
| 109 | 107 |
delete _weight; |
| 110 | 108 |
} |
| 111 | 109 |
if (_order) {
|
| 112 | 110 |
delete _order; |
| 113 | 111 |
} |
| 114 | 112 |
} |
| 115 | 113 |
|
| 116 | 114 |
public: |
| 117 | 115 |
|
| 118 | 116 |
/// \brief Constructor |
| 119 | 117 |
/// |
| 120 |
/// Constructor |
|
| 118 |
/// Constructor. |
|
| 121 | 119 |
/// \param graph The undirected graph the algorithm runs on. |
| 122 | 120 |
/// \param capacity The edge capacity map. |
| 123 | 121 |
GomoryHu(const Graph& graph, const Capacity& capacity) |
| 124 | 122 |
: _graph(graph), _capacity(capacity), |
| 125 | 123 |
_pred(0), _weight(0), _order(0) |
| 126 | 124 |
{
|
| 127 | 125 |
checkConcept<concepts::ReadMap<Edge, Value>, Capacity>(); |
| 128 | 126 |
} |
| 129 | 127 |
|
| 130 | 128 |
|
| 131 | 129 |
/// \brief Destructor |
| 132 | 130 |
/// |
| 133 |
/// Destructor |
|
| 131 |
/// Destructor. |
|
| 134 | 132 |
~GomoryHu() {
|
| 135 | 133 |
destroyStructures(); |
| 136 | 134 |
} |
| 137 | 135 |
|
| 138 | 136 |
private: |
| 139 | 137 |
|
| 140 | 138 |
// Initialize the internal data structures |
| 141 | 139 |
void init() {
|
| 142 | 140 |
createStructures(); |
| 143 | 141 |
|
| 144 | 142 |
_root = NodeIt(_graph); |
| 145 | 143 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 146 |
_pred->set(n, _root); |
|
| 147 |
_order->set(n, -1); |
|
| 144 |
(*_pred)[n] = _root; |
|
| 145 |
(*_order)[n] = -1; |
|
| 148 | 146 |
} |
| 149 |
_pred->set(_root, INVALID); |
|
| 150 |
_weight->set(_root, std::numeric_limits<Value>::max()); |
|
| 147 |
(*_pred)[_root] = INVALID; |
|
| 148 |
(*_weight)[_root] = std::numeric_limits<Value>::max(); |
|
| 151 | 149 |
} |
| 152 | 150 |
|
| 153 | 151 |
|
| 154 | 152 |
// Start the algorithm |
| 155 | 153 |
void start() {
|
| 156 | 154 |
Preflow<Graph, Capacity> fa(_graph, _capacity, _root, INVALID); |
| 157 | 155 |
|
| 158 | 156 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 159 | 157 |
if (n == _root) continue; |
| 160 | 158 |
|
| 161 | 159 |
Node pn = (*_pred)[n]; |
| 162 | 160 |
fa.source(n); |
| 163 | 161 |
fa.target(pn); |
| 164 | 162 |
|
| 165 | 163 |
fa.runMinCut(); |
| 166 | 164 |
|
| 167 |
_weight |
|
| 165 |
(*_weight)[n] = fa.flowValue(); |
|
| 168 | 166 |
|
| 169 | 167 |
for (NodeIt nn(_graph); nn != INVALID; ++nn) {
|
| 170 | 168 |
if (nn != n && fa.minCut(nn) && (*_pred)[nn] == pn) {
|
| 171 |
_pred |
|
| 169 |
(*_pred)[nn] = n; |
|
| 172 | 170 |
} |
| 173 | 171 |
} |
| 174 | 172 |
if ((*_pred)[pn] != INVALID && fa.minCut((*_pred)[pn])) {
|
| 175 |
_pred->set(n, (*_pred)[pn]); |
|
| 176 |
_pred->set(pn, n); |
|
| 177 |
_weight->set(n, (*_weight)[pn]); |
|
| 178 |
_weight->set(pn, fa.flowValue()); |
|
| 173 |
(*_pred)[n] = (*_pred)[pn]; |
|
| 174 |
(*_pred)[pn] = n; |
|
| 175 |
(*_weight)[n] = (*_weight)[pn]; |
|
| 176 |
(*_weight)[pn] = fa.flowValue(); |
|
| 179 | 177 |
} |
| 180 | 178 |
} |
| 181 | 179 |
|
| 182 |
_order |
|
| 180 |
(*_order)[_root] = 0; |
|
| 183 | 181 |
int index = 1; |
| 184 | 182 |
|
| 185 | 183 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 186 | 184 |
std::vector<Node> st; |
| 187 | 185 |
Node nn = n; |
| 188 | 186 |
while ((*_order)[nn] == -1) {
|
| 189 | 187 |
st.push_back(nn); |
| 190 | 188 |
nn = (*_pred)[nn]; |
| 191 | 189 |
} |
| 192 | 190 |
while (!st.empty()) {
|
| 193 |
_order |
|
| 191 |
(*_order)[st.back()] = index++; |
|
| 194 | 192 |
st.pop_back(); |
| 195 | 193 |
} |
| 196 | 194 |
} |
| 197 | 195 |
} |
| 198 | 196 |
|
| 199 | 197 |
public: |
| 200 | 198 |
|
| 201 | 199 |
///\name Execution Control |
| 202 | 200 |
|
| 203 | 201 |
///@{
|
| 204 | 202 |
|
| 205 | 203 |
/// \brief Run the Gomory-Hu algorithm. |
| 206 | 204 |
/// |
| 207 | 205 |
/// This function runs the Gomory-Hu algorithm. |
| 208 | 206 |
void run() {
|
| 209 | 207 |
init(); |
| 210 | 208 |
start(); |
| 211 | 209 |
} |
| 212 | 210 |
|
| 213 | 211 |
/// @} |
| 214 | 212 |
|
| 215 | 213 |
///\name Query Functions |
| 216 | 214 |
///The results of the algorithm can be obtained using these |
| 217 | 215 |
///functions.\n |
| 218 |
///\ref run() |
|
| 216 |
///\ref run() should be called before using them.\n |
|
| 219 | 217 |
///See also \ref MinCutNodeIt and \ref MinCutEdgeIt. |
| 220 | 218 |
|
| 221 | 219 |
///@{
|
| 222 | 220 |
|
| 223 | 221 |
/// \brief Return the predecessor node in the Gomory-Hu tree. |
| 224 | 222 |
/// |
| 225 |
/// This function returns the predecessor node in the Gomory-Hu tree. |
|
| 226 |
/// If the node is |
|
| 227 |
/// the root of the Gomory-Hu tree, then it returns \c INVALID. |
|
| 228 |
Node predNode(const Node& node) {
|
|
| 223 |
/// This function returns the predecessor node of the given node |
|
| 224 |
/// in the Gomory-Hu tree. |
|
| 225 |
/// If \c node is the root of the tree, then it returns \c INVALID. |
|
| 226 |
/// |
|
| 227 |
/// \pre \ref run() must be called before using this function. |
|
| 228 |
Node predNode(const Node& node) const {
|
|
| 229 | 229 |
return (*_pred)[node]; |
| 230 | 230 |
} |
| 231 | 231 |
|
| 232 |
/// \brief Return the distance from the root node in the Gomory-Hu tree. |
|
| 233 |
/// |
|
| 234 |
/// This function returns the distance of \c node from the root node |
|
| 235 |
/// in the Gomory-Hu tree. |
|
| 236 |
int rootDist(const Node& node) {
|
|
| 237 |
return (*_order)[node]; |
|
| 238 |
} |
|
| 239 |
|
|
| 240 | 232 |
/// \brief Return the weight of the predecessor edge in the |
| 241 | 233 |
/// Gomory-Hu tree. |
| 242 | 234 |
/// |
| 243 |
/// This function returns the weight of the predecessor edge in the |
|
| 244 |
/// Gomory-Hu tree. If the node is the root, the result is undefined. |
|
| 245 |
|
|
| 235 |
/// This function returns the weight of the predecessor edge of the |
|
| 236 |
/// given node in the Gomory-Hu tree. |
|
| 237 |
/// If \c node is the root of the tree, the result is undefined. |
|
| 238 |
/// |
|
| 239 |
/// \pre \ref run() must be called before using this function. |
|
| 240 |
Value predValue(const Node& node) const {
|
|
| 246 | 241 |
return (*_weight)[node]; |
| 247 | 242 |
} |
| 248 | 243 |
|
| 244 |
/// \brief Return the distance from the root node in the Gomory-Hu tree. |
|
| 245 |
/// |
|
| 246 |
/// This function returns the distance of the given node from the root |
|
| 247 |
/// node in the Gomory-Hu tree. |
|
| 248 |
/// |
|
| 249 |
/// \pre \ref run() must be called before using this function. |
|
| 250 |
int rootDist(const Node& node) const {
|
|
| 251 |
return (*_order)[node]; |
|
| 252 |
} |
|
| 253 |
|
|
| 249 | 254 |
/// \brief Return the minimum cut value between two nodes |
| 250 | 255 |
/// |
| 251 |
/// This function returns the minimum cut value between two nodes. The |
|
| 252 |
/// algorithm finds the nearest common ancestor in the Gomory-Hu |
|
| 253 |
/// tree and calculates the minimum weight edge on the paths to |
|
| 254 |
/// the ancestor. |
|
| 256 |
/// This function returns the minimum cut value between the nodes |
|
| 257 |
/// \c s and \c t. |
|
| 258 |
/// It finds the nearest common ancestor of the given nodes in the |
|
| 259 |
/// Gomory-Hu tree and calculates the minimum weight edge on the |
|
| 260 |
/// paths to the ancestor. |
|
| 261 |
/// |
|
| 262 |
/// \pre \ref run() must be called before using this function. |
|
| 255 | 263 |
Value minCutValue(const Node& s, const Node& t) const {
|
| 256 | 264 |
Node sn = s, tn = t; |
| 257 | 265 |
Value value = std::numeric_limits<Value>::max(); |
| 258 | 266 |
|
| 259 | 267 |
while (sn != tn) {
|
| 260 | 268 |
if ((*_order)[sn] < (*_order)[tn]) {
|
| 261 | 269 |
if ((*_weight)[tn] <= value) value = (*_weight)[tn]; |
| 262 | 270 |
tn = (*_pred)[tn]; |
| 263 | 271 |
} else {
|
| 264 | 272 |
if ((*_weight)[sn] <= value) value = (*_weight)[sn]; |
| 265 | 273 |
sn = (*_pred)[sn]; |
| 266 | 274 |
} |
| 267 | 275 |
} |
| 268 | 276 |
return value; |
| 269 | 277 |
} |
| 270 | 278 |
|
| 271 | 279 |
/// \brief Return the minimum cut between two nodes |
| 272 | 280 |
/// |
| 273 | 281 |
/// This function returns the minimum cut between the nodes \c s and \c t |
| 274 | 282 |
/// in the \c cutMap parameter by setting the nodes in the component of |
| 275 | 283 |
/// \c s to \c true and the other nodes to \c false. |
| 276 | 284 |
/// |
| 277 |
/// For higher level interfaces |
|
| 285 |
/// For higher level interfaces see MinCutNodeIt and MinCutEdgeIt. |
|
| 286 |
/// |
|
| 287 |
/// \param s The base node. |
|
| 288 |
/// \param t The node you want to separate from node \c s. |
|
| 289 |
/// \param cutMap The cut will be returned in this map. |
|
| 290 |
/// It must be a \c bool (or convertible) \ref concepts::ReadWriteMap |
|
| 291 |
/// "ReadWriteMap" on the graph nodes. |
|
| 292 |
/// |
|
| 293 |
/// \return The value of the minimum cut between \c s and \c t. |
|
| 294 |
/// |
|
| 295 |
/// \pre \ref run() must be called before using this function. |
|
| 278 | 296 |
template <typename CutMap> |
| 279 |
Value minCutMap(const Node& s, ///< |
|
| 297 |
Value minCutMap(const Node& s, ///< |
|
| 280 | 298 |
const Node& t, |
| 281 |
///< |
|
| 299 |
///< |
|
| 282 | 300 |
CutMap& cutMap |
| 283 |
///< The cut will be returned in this map. |
|
| 284 |
/// It must be a \c bool (or convertible) |
|
| 285 |
/// \ref concepts::ReadWriteMap "ReadWriteMap" |
|
| 286 |
/// on the graph nodes. |
|
| 301 |
///< |
|
| 287 | 302 |
) const {
|
| 288 | 303 |
Node sn = s, tn = t; |
| 289 | 304 |
bool s_root=false; |
| 290 | 305 |
Node rn = INVALID; |
| 291 | 306 |
Value value = std::numeric_limits<Value>::max(); |
| 292 | 307 |
|
| 293 | 308 |
while (sn != tn) {
|
| 294 | 309 |
if ((*_order)[sn] < (*_order)[tn]) {
|
| 295 | 310 |
if ((*_weight)[tn] <= value) {
|
| 296 | 311 |
rn = tn; |
| 297 | 312 |
s_root = false; |
| 298 | 313 |
value = (*_weight)[tn]; |
| 299 | 314 |
} |
| 300 | 315 |
tn = (*_pred)[tn]; |
| 301 | 316 |
} else {
|
| 302 | 317 |
if ((*_weight)[sn] <= value) {
|
| 303 | 318 |
rn = sn; |
| 304 | 319 |
s_root = true; |
| 305 | 320 |
value = (*_weight)[sn]; |
| 306 | 321 |
} |
| 307 | 322 |
sn = (*_pred)[sn]; |
| 308 | 323 |
} |
| 309 | 324 |
} |
| 310 | 325 |
|
| 311 | 326 |
typename Graph::template NodeMap<bool> reached(_graph, false); |
| 312 |
reached |
|
| 327 |
reached[_root] = true; |
|
| 313 | 328 |
cutMap.set(_root, !s_root); |
| 314 |
reached |
|
| 329 |
reached[rn] = true; |
|
| 315 | 330 |
cutMap.set(rn, s_root); |
| 316 | 331 |
|
| 317 | 332 |
std::vector<Node> st; |
| 318 | 333 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 319 | 334 |
st.clear(); |
| 320 | 335 |
Node nn = n; |
| 321 | 336 |
while (!reached[nn]) {
|
| 322 | 337 |
st.push_back(nn); |
| 323 | 338 |
nn = (*_pred)[nn]; |
| 324 | 339 |
} |
| 325 | 340 |
while (!st.empty()) {
|
| 326 | 341 |
cutMap.set(st.back(), cutMap[nn]); |
| 327 | 342 |
st.pop_back(); |
| 328 | 343 |
} |
| 329 | 344 |
} |
| 330 | 345 |
|
| 331 | 346 |
return value; |
| 332 | 347 |
} |
| 333 | 348 |
|
| 334 | 349 |
///@} |
| 335 | 350 |
|
| 336 | 351 |
friend class MinCutNodeIt; |
| 337 | 352 |
|
| 338 | 353 |
/// Iterate on the nodes of a minimum cut |
| 339 | 354 |
|
| 340 | 355 |
/// This iterator class lists the nodes of a minimum cut found by |
| 341 |
/// GomoryHu. Before using it, you must allocate a GomoryHu class |
|
| 356 |
/// GomoryHu. Before using it, you must allocate a GomoryHu class |
|
| 342 | 357 |
/// and call its \ref GomoryHu::run() "run()" method. |
| 343 | 358 |
/// |
| 344 | 359 |
/// This example counts the nodes in the minimum cut separating \c s from |
| 345 | 360 |
/// \c t. |
| 346 | 361 |
/// \code |
| 347 | 362 |
/// GomoruHu<Graph> gom(g, capacities); |
| 348 | 363 |
/// gom.run(); |
| 349 | 364 |
/// int cnt=0; |
| 350 | 365 |
/// for(GomoruHu<Graph>::MinCutNodeIt n(gom,s,t); n!=INVALID; ++n) ++cnt; |
| 351 | 366 |
/// \endcode |
| 352 | 367 |
class MinCutNodeIt |
| 353 | 368 |
{
|
| 354 | 369 |
bool _side; |
| 355 | 370 |
typename Graph::NodeIt _node_it; |
| 356 | 371 |
typename Graph::template NodeMap<bool> _cut; |
| 357 | 372 |
public: |
| 358 | 373 |
/// Constructor |
| 359 | 374 |
|
| 360 | 375 |
/// Constructor. |
| 361 | 376 |
/// |
| 362 | 377 |
MinCutNodeIt(GomoryHu const &gomory, |
| 363 | 378 |
///< The GomoryHu class. You must call its |
| 364 | 379 |
/// run() method |
| 365 | 380 |
/// before initializing this iterator. |
| 366 | 381 |
const Node& s, ///< The base node. |
| 367 | 382 |
const Node& t, |
| 368 | 383 |
///< The node you want to separate from node \c s. |
| 369 | 384 |
bool side=true |
| 370 | 385 |
///< If it is \c true (default) then the iterator lists |
| 371 | 386 |
/// the nodes of the component containing \c s, |
| 372 | 387 |
/// otherwise it lists the other component. |
| 373 | 388 |
/// \note As the minimum cut is not always unique, |
| 374 | 389 |
/// \code |
| 375 | 390 |
/// MinCutNodeIt(gomory, s, t, true); |
| 376 | 391 |
/// \endcode |
| 377 | 392 |
/// and |
| 378 | 393 |
/// \code |
| 379 | 394 |
/// MinCutNodeIt(gomory, t, s, false); |
| 380 | 395 |
/// \endcode |
| 381 | 396 |
/// does not necessarily give the same set of nodes. |
| 382 | 397 |
/// However it is ensured that |
| 383 | 398 |
/// \code |
| 384 | 399 |
/// MinCutNodeIt(gomory, s, t, true); |
| 385 | 400 |
/// \endcode |
| 386 | 401 |
/// and |
| 387 | 402 |
/// \code |
| 388 | 403 |
/// MinCutNodeIt(gomory, s, t, false); |
| 389 | 404 |
/// \endcode |
| 390 | 405 |
/// together list each node exactly once. |
| 391 | 406 |
) |
| 392 | 407 |
: _side(side), _cut(gomory._graph) |
| 393 | 408 |
{
|
| 394 | 409 |
gomory.minCutMap(s,t,_cut); |
| 395 | 410 |
for(_node_it=typename Graph::NodeIt(gomory._graph); |
| 396 | 411 |
_node_it!=INVALID && _cut[_node_it]!=_side; |
| 397 | 412 |
++_node_it) {}
|
| 398 | 413 |
} |
| 399 | 414 |
/// Conversion to \c Node |
| 400 | 415 |
|
| 401 | 416 |
/// Conversion to \c Node. |
| 402 | 417 |
/// |
| 403 | 418 |
operator typename Graph::Node() const |
| 404 | 419 |
{
|
| 405 | 420 |
return _node_it; |
| 406 | 421 |
} |
| 407 | 422 |
bool operator==(Invalid) { return _node_it==INVALID; }
|
| 408 | 423 |
bool operator!=(Invalid) { return _node_it!=INVALID; }
|
| 409 | 424 |
/// Next node |
| 410 | 425 |
|
| 411 | 426 |
/// Next node. |
| 412 | 427 |
/// |
| 413 | 428 |
MinCutNodeIt &operator++() |
| 414 | 429 |
{
|
| 415 | 430 |
for(++_node_it;_node_it!=INVALID&&_cut[_node_it]!=_side;++_node_it) {}
|
| 416 | 431 |
return *this; |
| 417 | 432 |
} |
| 418 | 433 |
/// Postfix incrementation |
| 419 | 434 |
|
| 420 | 435 |
/// Postfix incrementation. |
| 421 | 436 |
/// |
| 422 | 437 |
/// \warning This incrementation |
| 423 | 438 |
/// returns a \c Node, not a \c MinCutNodeIt, as one may |
| 424 | 439 |
/// expect. |
| 425 | 440 |
typename Graph::Node operator++(int) |
| 426 | 441 |
{
|
| 427 | 442 |
typename Graph::Node n=*this; |
| 428 | 443 |
++(*this); |
| 429 | 444 |
return n; |
| 430 | 445 |
} |
| 431 | 446 |
}; |
| 432 | 447 |
|
| 433 | 448 |
friend class MinCutEdgeIt; |
| 434 | 449 |
|
| 435 | 450 |
/// Iterate on the edges of a minimum cut |
| 436 | 451 |
|
| 437 | 452 |
/// This iterator class lists the edges of a minimum cut found by |
| 438 |
/// GomoryHu. Before using it, you must allocate a GomoryHu class |
|
| 453 |
/// GomoryHu. Before using it, you must allocate a GomoryHu class |
|
| 439 | 454 |
/// and call its \ref GomoryHu::run() "run()" method. |
| 440 | 455 |
/// |
| 441 | 456 |
/// This example computes the value of the minimum cut separating \c s from |
| 442 | 457 |
/// \c t. |
| 443 | 458 |
/// \code |
| 444 | 459 |
/// GomoruHu<Graph> gom(g, capacities); |
| 445 | 460 |
/// gom.run(); |
| 446 | 461 |
/// int value=0; |
| 447 | 462 |
/// for(GomoruHu<Graph>::MinCutEdgeIt e(gom,s,t); e!=INVALID; ++e) |
| 448 | 463 |
/// value+=capacities[e]; |
| 449 | 464 |
/// \endcode |
| 450 |
/// the result will be the same as it is returned by |
|
| 451 |
/// \ref GomoryHu::minCutValue() "gom.minCutValue(s,t)" |
|
| 465 |
/// The result will be the same as the value returned by |
|
| 466 |
/// \ref GomoryHu::minCutValue() "gom.minCutValue(s,t)". |
|
| 452 | 467 |
class MinCutEdgeIt |
| 453 | 468 |
{
|
| 454 | 469 |
bool _side; |
| 455 | 470 |
const Graph &_graph; |
| 456 | 471 |
typename Graph::NodeIt _node_it; |
| 457 | 472 |
typename Graph::OutArcIt _arc_it; |
| 458 | 473 |
typename Graph::template NodeMap<bool> _cut; |
| 459 | 474 |
void step() |
| 460 | 475 |
{
|
| 461 | 476 |
++_arc_it; |
| 462 | 477 |
while(_node_it!=INVALID && _arc_it==INVALID) |
| 463 | 478 |
{
|
| 464 | 479 |
for(++_node_it;_node_it!=INVALID&&!_cut[_node_it];++_node_it) {}
|
| 465 | 480 |
if(_node_it!=INVALID) |
| 466 | 481 |
_arc_it=typename Graph::OutArcIt(_graph,_node_it); |
| 467 | 482 |
} |
| 468 | 483 |
} |
| 469 | 484 |
|
| 470 | 485 |
public: |
| 486 |
/// Constructor |
|
| 487 |
|
|
| 488 |
/// Constructor. |
|
| 489 |
/// |
|
| 471 | 490 |
MinCutEdgeIt(GomoryHu const &gomory, |
| 472 | 491 |
///< The GomoryHu class. You must call its |
| 473 | 492 |
/// run() method |
| 474 | 493 |
/// before initializing this iterator. |
| 475 | 494 |
const Node& s, ///< The base node. |
| 476 | 495 |
const Node& t, |
| 477 | 496 |
///< The node you want to separate from node \c s. |
| 478 | 497 |
bool side=true |
| 479 | 498 |
///< If it is \c true (default) then the listed arcs |
| 480 | 499 |
/// will be oriented from the |
| 481 |
/// |
|
| 500 |
/// nodes of the component containing \c s, |
|
| 482 | 501 |
/// otherwise they will be oriented in the opposite |
| 483 | 502 |
/// direction. |
| 484 | 503 |
) |
| 485 | 504 |
: _graph(gomory._graph), _cut(_graph) |
| 486 | 505 |
{
|
| 487 | 506 |
gomory.minCutMap(s,t,_cut); |
| 488 | 507 |
if(!side) |
| 489 | 508 |
for(typename Graph::NodeIt n(_graph);n!=INVALID;++n) |
| 490 | 509 |
_cut[n]=!_cut[n]; |
| 491 | 510 |
|
| 492 | 511 |
for(_node_it=typename Graph::NodeIt(_graph); |
| 493 | 512 |
_node_it!=INVALID && !_cut[_node_it]; |
| 494 | 513 |
++_node_it) {}
|
| 495 | 514 |
_arc_it = _node_it!=INVALID ? |
| 496 | 515 |
typename Graph::OutArcIt(_graph,_node_it) : INVALID; |
| 497 | 516 |
while(_node_it!=INVALID && _arc_it == INVALID) |
| 498 | 517 |
{
|
| 499 | 518 |
for(++_node_it; _node_it!=INVALID&&!_cut[_node_it]; ++_node_it) {}
|
| 500 | 519 |
if(_node_it!=INVALID) |
| 501 | 520 |
_arc_it= typename Graph::OutArcIt(_graph,_node_it); |
| 502 | 521 |
} |
| 503 | 522 |
while(_arc_it!=INVALID && _cut[_graph.target(_arc_it)]) step(); |
| 504 | 523 |
} |
| 505 | 524 |
/// Conversion to \c Arc |
| 506 | 525 |
|
| 507 | 526 |
/// Conversion to \c Arc. |
| 508 | 527 |
/// |
| 509 | 528 |
operator typename Graph::Arc() const |
| 510 | 529 |
{
|
| 511 | 530 |
return _arc_it; |
| 512 | 531 |
} |
| 513 | 532 |
/// Conversion to \c Edge |
| 514 | 533 |
|
| 515 | 534 |
/// Conversion to \c Edge. |
| 516 | 535 |
/// |
| 517 | 536 |
operator typename Graph::Edge() const |
| 518 | 537 |
{
|
| 519 | 538 |
return _arc_it; |
| 520 | 539 |
} |
| 521 | 540 |
bool operator==(Invalid) { return _node_it==INVALID; }
|
| 522 | 541 |
bool operator!=(Invalid) { return _node_it!=INVALID; }
|
| 523 | 542 |
/// Next edge |
| 524 | 543 |
|
| 525 | 544 |
/// Next edge. |
| 526 | 545 |
/// |
| 527 | 546 |
MinCutEdgeIt &operator++() |
| 528 | 547 |
{
|
| 529 | 548 |
step(); |
| ... | ... |
@@ -223,112 +223,108 @@ |
| 223 | 223 |
|
| 224 | 224 |
using T::NodeTextColorType; |
| 225 | 225 |
using T::CUST_COL; |
| 226 | 226 |
using T::DIST_COL; |
| 227 | 227 |
using T::DIST_BW; |
| 228 | 228 |
using T::_nodeTextColorType; |
| 229 | 229 |
using T::_nodeTextColors; |
| 230 | 230 |
|
| 231 | 231 |
using T::_autoNodeScale; |
| 232 | 232 |
using T::_autoArcWidthScale; |
| 233 | 233 |
|
| 234 | 234 |
using T::_absoluteNodeSizes; |
| 235 | 235 |
using T::_absoluteArcWidths; |
| 236 | 236 |
|
| 237 | 237 |
|
| 238 | 238 |
using T::_negY; |
| 239 | 239 |
using T::_preScale; |
| 240 | 240 |
|
| 241 | 241 |
// dradnats ++C eht yb deriuqer si ti eveileb t'naC |
| 242 | 242 |
|
| 243 | 243 |
typedef typename T::Graph Graph; |
| 244 | 244 |
typedef typename Graph::Node Node; |
| 245 | 245 |
typedef typename Graph::NodeIt NodeIt; |
| 246 | 246 |
typedef typename Graph::Arc Arc; |
| 247 | 247 |
typedef typename Graph::ArcIt ArcIt; |
| 248 | 248 |
typedef typename Graph::InArcIt InArcIt; |
| 249 | 249 |
typedef typename Graph::OutArcIt OutArcIt; |
| 250 | 250 |
|
| 251 | 251 |
static const int INTERPOL_PREC; |
| 252 | 252 |
static const double A4HEIGHT; |
| 253 | 253 |
static const double A4WIDTH; |
| 254 | 254 |
static const double A4BORDER; |
| 255 | 255 |
|
| 256 | 256 |
bool dontPrint; |
| 257 | 257 |
|
| 258 | 258 |
public: |
| 259 | 259 |
///Node shapes |
| 260 | 260 |
|
| 261 | 261 |
///Node shapes. |
| 262 | 262 |
/// |
| 263 | 263 |
enum NodeShapes {
|
| 264 | 264 |
/// = 0 |
| 265 | 265 |
///\image html nodeshape_0.png |
| 266 | 266 |
///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm |
| 267 | 267 |
CIRCLE=0, |
| 268 | 268 |
/// = 1 |
| 269 | 269 |
///\image html nodeshape_1.png |
| 270 | 270 |
///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm |
| 271 |
/// |
|
| 272 | 271 |
SQUARE=1, |
| 273 | 272 |
/// = 2 |
| 274 | 273 |
///\image html nodeshape_2.png |
| 275 | 274 |
///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm |
| 276 |
/// |
|
| 277 | 275 |
DIAMOND=2, |
| 278 | 276 |
/// = 3 |
| 279 | 277 |
///\image html nodeshape_3.png |
| 280 |
///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm |
|
| 281 |
/// |
|
| 278 |
///\image latex nodeshape_3.eps "MALE shape (3)" width=2cm |
|
| 282 | 279 |
MALE=3, |
| 283 | 280 |
/// = 4 |
| 284 | 281 |
///\image html nodeshape_4.png |
| 285 |
///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm |
|
| 286 |
/// |
|
| 282 |
///\image latex nodeshape_4.eps "FEMALE shape (4)" width=2cm |
|
| 287 | 283 |
FEMALE=4 |
| 288 | 284 |
}; |
| 289 | 285 |
|
| 290 | 286 |
private: |
| 291 | 287 |
class arcLess {
|
| 292 | 288 |
const Graph &g; |
| 293 | 289 |
public: |
| 294 | 290 |
arcLess(const Graph &_g) : g(_g) {}
|
| 295 | 291 |
bool operator()(Arc a,Arc b) const |
| 296 | 292 |
{
|
| 297 | 293 |
Node ai=std::min(g.source(a),g.target(a)); |
| 298 | 294 |
Node aa=std::max(g.source(a),g.target(a)); |
| 299 | 295 |
Node bi=std::min(g.source(b),g.target(b)); |
| 300 | 296 |
Node ba=std::max(g.source(b),g.target(b)); |
| 301 | 297 |
return ai<bi || |
| 302 | 298 |
(ai==bi && (aa < ba || |
| 303 | 299 |
(aa==ba && ai==g.source(a) && bi==g.target(b)))); |
| 304 | 300 |
} |
| 305 | 301 |
}; |
| 306 | 302 |
bool isParallel(Arc e,Arc f) const |
| 307 | 303 |
{
|
| 308 | 304 |
return (g.source(e)==g.source(f)&& |
| 309 | 305 |
g.target(e)==g.target(f)) || |
| 310 | 306 |
(g.source(e)==g.target(f)&& |
| 311 | 307 |
g.target(e)==g.source(f)); |
| 312 | 308 |
} |
| 313 | 309 |
template<class TT> |
| 314 | 310 |
static std::string psOut(const dim2::Point<TT> &p) |
| 315 | 311 |
{
|
| 316 | 312 |
std::ostringstream os; |
| 317 | 313 |
os << p.x << ' ' << p.y; |
| 318 | 314 |
return os.str(); |
| 319 | 315 |
} |
| 320 | 316 |
static std::string psOut(const Color &c) |
| 321 | 317 |
{
|
| 322 | 318 |
std::ostringstream os; |
| 323 | 319 |
os << c.red() << ' ' << c.green() << ' ' << c.blue(); |
| 324 | 320 |
return os.str(); |
| 325 | 321 |
} |
| 326 | 322 |
|
| 327 | 323 |
public: |
| 328 | 324 |
GraphToEps(const T &t) : T(t), dontPrint(false) {};
|
| 329 | 325 |
|
| 330 | 326 |
template<class X> struct CoordsTraits : public T {
|
| 331 | 327 |
typedef X CoordsMapType; |
| 332 | 328 |
const X &_coords; |
| 333 | 329 |
CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
|
| 334 | 330 |
}; |
| ... | ... |
@@ -452,99 +452,97 @@ |
| 452 | 452 |
Arc down(Node n) const {
|
| 453 | 453 |
if (n._id >= _width) {
|
| 454 | 454 |
return Arc((n._id - _width) << 1); |
| 455 | 455 |
} else {
|
| 456 | 456 |
return INVALID; |
| 457 | 457 |
} |
| 458 | 458 |
} |
| 459 | 459 |
|
| 460 | 460 |
private: |
| 461 | 461 |
int _width, _height; |
| 462 | 462 |
int _node_num, _edge_num; |
| 463 | 463 |
int _edge_limit; |
| 464 | 464 |
}; |
| 465 | 465 |
|
| 466 | 466 |
|
| 467 | 467 |
typedef GraphExtender<GridGraphBase> ExtendedGridGraphBase; |
| 468 | 468 |
|
| 469 | 469 |
/// \ingroup graphs |
| 470 | 470 |
/// |
| 471 | 471 |
/// \brief Grid graph class |
| 472 | 472 |
/// |
| 473 | 473 |
/// This class implements a special graph type. The nodes of the |
| 474 | 474 |
/// graph can be indexed by two integer \c (i,j) value where \c i is |
| 475 | 475 |
/// in the \c [0..width()-1] range and j is in the \c |
| 476 | 476 |
/// [0..height()-1] range. Two nodes are connected in the graph if |
| 477 | 477 |
/// the indexes differ exactly on one position and exactly one is |
| 478 | 478 |
/// the difference. The nodes of the graph can be indexed by position |
| 479 | 479 |
/// with the \c operator()() function. The positions of the nodes can be |
| 480 | 480 |
/// get with \c pos(), \c col() and \c row() members. The outgoing |
| 481 | 481 |
/// arcs can be retrieved with the \c right(), \c up(), \c left() |
| 482 | 482 |
/// and \c down() functions, where the bottom-left corner is the |
| 483 | 483 |
/// origin. |
| 484 | 484 |
/// |
| 485 | 485 |
/// \image html grid_graph.png |
| 486 | 486 |
/// \image latex grid_graph.eps "Grid graph" width=\textwidth |
| 487 | 487 |
/// |
| 488 | 488 |
/// A short example about the basic usage: |
| 489 | 489 |
///\code |
| 490 | 490 |
/// GridGraph graph(rows, cols); |
| 491 | 491 |
/// GridGraph::NodeMap<int> val(graph); |
| 492 | 492 |
/// for (int i = 0; i < graph.width(); ++i) {
|
| 493 | 493 |
/// for (int j = 0; j < graph.height(); ++j) {
|
| 494 | 494 |
/// val[graph(i, j)] = i + j; |
| 495 | 495 |
/// } |
| 496 | 496 |
/// } |
| 497 | 497 |
///\endcode |
| 498 | 498 |
/// |
| 499 | 499 |
/// This graph type fully conforms to the \ref concepts::Graph |
| 500 |
/// "Graph" concept, and it also has an important extra feature |
|
| 501 |
/// that its maps are real \ref concepts::ReferenceMap |
|
| 502 |
/// " |
|
| 500 |
/// "Graph concept". |
|
| 503 | 501 |
class GridGraph : public ExtendedGridGraphBase {
|
| 504 | 502 |
public: |
| 505 | 503 |
|
| 506 | 504 |
typedef ExtendedGridGraphBase Parent; |
| 507 | 505 |
|
| 508 | 506 |
/// \brief Map to get the indices of the nodes as dim2::Point<int>. |
| 509 | 507 |
/// |
| 510 | 508 |
/// Map to get the indices of the nodes as dim2::Point<int>. |
| 511 | 509 |
class IndexMap {
|
| 512 | 510 |
public: |
| 513 | 511 |
/// \brief The key type of the map |
| 514 | 512 |
typedef GridGraph::Node Key; |
| 515 | 513 |
/// \brief The value type of the map |
| 516 | 514 |
typedef dim2::Point<int> Value; |
| 517 | 515 |
|
| 518 | 516 |
/// \brief Constructor |
| 519 | 517 |
/// |
| 520 | 518 |
/// Constructor |
| 521 | 519 |
IndexMap(const GridGraph& graph) : _graph(graph) {}
|
| 522 | 520 |
|
| 523 | 521 |
/// \brief The subscript operator |
| 524 | 522 |
/// |
| 525 | 523 |
/// The subscript operator. |
| 526 | 524 |
Value operator[](Key key) const {
|
| 527 | 525 |
return _graph.pos(key); |
| 528 | 526 |
} |
| 529 | 527 |
|
| 530 | 528 |
private: |
| 531 | 529 |
const GridGraph& _graph; |
| 532 | 530 |
}; |
| 533 | 531 |
|
| 534 | 532 |
/// \brief Map to get the column of the nodes. |
| 535 | 533 |
/// |
| 536 | 534 |
/// Map to get the column of the nodes. |
| 537 | 535 |
class ColMap {
|
| 538 | 536 |
public: |
| 539 | 537 |
/// \brief The key type of the map |
| 540 | 538 |
typedef GridGraph::Node Key; |
| 541 | 539 |
/// \brief The value type of the map |
| 542 | 540 |
typedef int Value; |
| 543 | 541 |
|
| 544 | 542 |
/// \brief Constructor |
| 545 | 543 |
/// |
| 546 | 544 |
/// Constructor |
| 547 | 545 |
ColMap(const GridGraph& graph) : _graph(graph) {}
|
| 548 | 546 |
|
| 549 | 547 |
/// \brief The subscript operator |
| 550 | 548 |
/// |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_HAO_ORLIN_H |
| 20 | 20 |
#define LEMON_HAO_ORLIN_H |
| 21 | 21 |
|
| 22 | 22 |
#include <vector> |
| 23 | 23 |
#include <list> |
| 24 | 24 |
#include <limits> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/maps.h> |
| 27 | 27 |
#include <lemon/core.h> |
| 28 | 28 |
#include <lemon/tolerance.h> |
| 29 | 29 |
|
| 30 | 30 |
/// \file |
| 31 | 31 |
/// \ingroup min_cut |
| 32 | 32 |
/// \brief Implementation of the Hao-Orlin algorithm. |
| 33 | 33 |
/// |
| 34 |
/// Implementation of the Hao-Orlin algorithm class for testing network |
|
| 35 |
/// reliability. |
|
| 34 |
/// Implementation of the Hao-Orlin algorithm for finding a minimum cut |
|
| 35 |
/// in a digraph. |
|
| 36 | 36 |
|
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
/// \ingroup min_cut |
| 40 | 40 |
/// |
| 41 |
/// \brief |
|
| 41 |
/// \brief Hao-Orlin algorithm for finding a minimum cut in a digraph. |
|
| 42 | 42 |
/// |
| 43 |
/// Hao-Orlin calculates a minimum cut in a directed graph |
|
| 44 |
/// \f$D=(V,A)\f$. It takes a fixed node \f$ source \in V \f$ and |
|
| 43 |
/// This class implements the Hao-Orlin algorithm for finding a minimum |
|
| 44 |
/// value cut in a directed graph \f$D=(V,A)\f$. |
|
| 45 |
/// It takes a fixed node \f$ source \in V \f$ and |
|
| 45 | 46 |
/// consists of two phases: in the first phase it determines a |
| 46 | 47 |
/// minimum cut with \f$ source \f$ on the source-side (i.e. a set |
| 47 |
/// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal |
|
| 48 |
/// out-degree) and in the second phase it determines a minimum cut |
|
| 48 |
/// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal outgoing |
|
| 49 |
/// capacity) and in the second phase it determines a minimum cut |
|
| 49 | 50 |
/// with \f$ source \f$ on the sink-side (i.e. a set |
| 50 |
/// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal |
|
| 51 |
/// out-degree). Obviously, the smaller of these two cuts will be a |
|
| 51 |
/// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal outgoing |
|
| 52 |
/// capacity). Obviously, the smaller of these two cuts will be a |
|
| 52 | 53 |
/// minimum cut of \f$ D \f$. The algorithm is a modified |
| 53 |
/// push-relabel |
|
| 54 |
/// preflow push-relabel algorithm. Our implementation calculates |
|
| 54 | 55 |
/// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the
|
| 55 | 56 |
/// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The |
| 56 |
/// purpose of such algorithm is testing network reliability. For an |
|
| 57 |
/// undirected graph you can run just the first phase of the |
|
| 58 |
/// algorithm or you can use the algorithm of Nagamochi and Ibaraki |
|
| 59 |
/// which solves the undirected problem in |
|
| 60 |
/// \f$ O(nm + n^2 \log n) \f$ time: it is implemented in the |
|
| 61 |
/// NagamochiIbaraki algorithm class. |
|
| 57 |
/// purpose of such algorithm is e.g. testing network reliability. |
|
| 62 | 58 |
/// |
| 63 |
/// \param GR The digraph class the algorithm runs on. |
|
| 64 |
/// \param CAP An arc map of capacities which can be any numreric type. |
|
| 65 |
/// The default type is \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
|
| 66 |
/// \param TOL Tolerance class for handling inexact computations. The |
|
| 59 |
/// For an undirected graph you can run just the first phase of the |
|
| 60 |
/// algorithm or you can use the algorithm of Nagamochi and Ibaraki, |
|
| 61 |
/// which solves the undirected problem in \f$ O(nm + n^2 \log n) \f$ |
|
| 62 |
/// time. It is implemented in the NagamochiIbaraki algorithm class. |
|
| 63 |
/// |
|
| 64 |
/// \tparam GR The type of the digraph the algorithm runs on. |
|
| 65 |
/// \tparam CAP The type of the arc map containing the capacities, |
|
| 66 |
/// which can be any numreric type. The default map type is |
|
| 67 |
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
|
| 68 |
/// \tparam TOL Tolerance class for handling inexact computations. The |
|
| 67 | 69 |
/// default tolerance type is \ref Tolerance "Tolerance<CAP::Value>". |
| 68 | 70 |
#ifdef DOXYGEN |
| 69 | 71 |
template <typename GR, typename CAP, typename TOL> |
| 70 | 72 |
#else |
| 71 | 73 |
template <typename GR, |
| 72 | 74 |
typename CAP = typename GR::template ArcMap<int>, |
| 73 | 75 |
typename TOL = Tolerance<typename CAP::Value> > |
| 74 | 76 |
#endif |
| 75 | 77 |
class HaoOrlin {
|
| 78 |
public: |
|
| 79 |
|
|
| 80 |
/// The digraph type of the algorithm |
|
| 81 |
typedef GR Digraph; |
|
| 82 |
/// The capacity map type of the algorithm |
|
| 83 |
typedef CAP CapacityMap; |
|
| 84 |
/// The tolerance type of the algorithm |
|
| 85 |
typedef TOL Tolerance; |
|
| 86 |
|
|
| 76 | 87 |
private: |
| 77 | 88 |
|
| 78 |
typedef GR Digraph; |
|
| 79 |
typedef CAP CapacityMap; |
|
| 80 |
typedef TOL Tolerance; |
|
| 81 |
|
|
| 82 | 89 |
typedef typename CapacityMap::Value Value; |
| 83 | 90 |
|
| 84 |
|
|
| 91 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
|
| 85 | 92 |
|
| 86 | 93 |
const Digraph& _graph; |
| 87 | 94 |
const CapacityMap* _capacity; |
| 88 | 95 |
|
| 89 | 96 |
typedef typename Digraph::template ArcMap<Value> FlowMap; |
| 90 | 97 |
FlowMap* _flow; |
| 91 | 98 |
|
| 92 | 99 |
Node _source; |
| 93 | 100 |
|
| 94 | 101 |
int _node_num; |
| 95 | 102 |
|
| 96 | 103 |
// Bucketing structure |
| 97 | 104 |
std::vector<Node> _first, _last; |
| 98 | 105 |
typename Digraph::template NodeMap<Node>* _next; |
| 99 | 106 |
typename Digraph::template NodeMap<Node>* _prev; |
| 100 | 107 |
typename Digraph::template NodeMap<bool>* _active; |
| 101 | 108 |
typename Digraph::template NodeMap<int>* _bucket; |
| 102 | 109 |
|
| 103 | 110 |
std::vector<bool> _dormant; |
| 104 | 111 |
|
| 105 | 112 |
std::list<std::list<int> > _sets; |
| 106 | 113 |
std::list<int>::iterator _highest; |
| 107 | 114 |
|
| 108 | 115 |
typedef typename Digraph::template NodeMap<Value> ExcessMap; |
| 109 | 116 |
ExcessMap* _excess; |
| 110 | 117 |
|
| 111 | 118 |
typedef typename Digraph::template NodeMap<bool> SourceSetMap; |
| 112 | 119 |
SourceSetMap* _source_set; |
| 113 | 120 |
|
| 114 | 121 |
Value _min_cut; |
| 115 | 122 |
|
| 116 | 123 |
typedef typename Digraph::template NodeMap<bool> MinCutMap; |
| 117 | 124 |
MinCutMap* _min_cut_map; |
| 118 | 125 |
|
| 119 | 126 |
Tolerance _tolerance; |
| 120 | 127 |
|
| 121 | 128 |
public: |
| 122 | 129 |
|
| 123 | 130 |
/// \brief Constructor |
| 124 | 131 |
/// |
| 125 | 132 |
/// Constructor of the algorithm class. |
| 126 | 133 |
HaoOrlin(const Digraph& graph, const CapacityMap& capacity, |
| 127 | 134 |
const Tolerance& tolerance = Tolerance()) : |
| 128 | 135 |
_graph(graph), _capacity(&capacity), _flow(0), _source(), |
| 129 | 136 |
_node_num(), _first(), _last(), _next(0), _prev(0), |
| 130 | 137 |
_active(0), _bucket(0), _dormant(), _sets(), _highest(), |
| 131 | 138 |
_excess(0), _source_set(0), _min_cut(), _min_cut_map(0), |
| 132 | 139 |
_tolerance(tolerance) {}
|
| 133 | 140 |
|
| 134 | 141 |
~HaoOrlin() {
|
| 135 | 142 |
if (_min_cut_map) {
|
| 136 | 143 |
delete _min_cut_map; |
| 137 | 144 |
} |
| 138 | 145 |
if (_source_set) {
|
| 139 | 146 |
delete _source_set; |
| 140 | 147 |
} |
| 141 | 148 |
if (_excess) {
|
| 142 | 149 |
delete _excess; |
| 143 | 150 |
} |
| 144 | 151 |
if (_next) {
|
| 145 | 152 |
delete _next; |
| 146 | 153 |
} |
| 147 | 154 |
if (_prev) {
|
| 148 | 155 |
delete _prev; |
| 149 | 156 |
} |
| 150 | 157 |
if (_active) {
|
| 151 | 158 |
delete _active; |
| 152 | 159 |
} |
| 153 | 160 |
if (_bucket) {
|
| 154 | 161 |
delete _bucket; |
| 155 | 162 |
} |
| 156 | 163 |
if (_flow) {
|
| 157 | 164 |
delete _flow; |
| 158 | 165 |
} |
| 159 | 166 |
} |
| 160 | 167 |
|
| 161 | 168 |
private: |
| 162 | 169 |
|
| 163 | 170 |
void activate(const Node& i) {
|
| 164 |
_active |
|
| 171 |
(*_active)[i] = true; |
|
| 165 | 172 |
|
| 166 | 173 |
int bucket = (*_bucket)[i]; |
| 167 | 174 |
|
| 168 | 175 |
if ((*_prev)[i] == INVALID || (*_active)[(*_prev)[i]]) return; |
| 169 | 176 |
//unlace |
| 170 |
_next |
|
| 177 |
(*_next)[(*_prev)[i]] = (*_next)[i]; |
|
| 171 | 178 |
if ((*_next)[i] != INVALID) {
|
| 172 |
_prev |
|
| 179 |
(*_prev)[(*_next)[i]] = (*_prev)[i]; |
|
| 173 | 180 |
} else {
|
| 174 | 181 |
_last[bucket] = (*_prev)[i]; |
| 175 | 182 |
} |
| 176 | 183 |
//lace |
| 177 |
_next->set(i, _first[bucket]); |
|
| 178 |
_prev->set(_first[bucket], i); |
|
| 179 |
|
|
| 184 |
(*_next)[i] = _first[bucket]; |
|
| 185 |
(*_prev)[_first[bucket]] = i; |
|
| 186 |
(*_prev)[i] = INVALID; |
|
| 180 | 187 |
_first[bucket] = i; |
| 181 | 188 |
} |
| 182 | 189 |
|
| 183 | 190 |
void deactivate(const Node& i) {
|
| 184 |
_active |
|
| 191 |
(*_active)[i] = false; |
|
| 185 | 192 |
int bucket = (*_bucket)[i]; |
| 186 | 193 |
|
| 187 | 194 |
if ((*_next)[i] == INVALID || !(*_active)[(*_next)[i]]) return; |
| 188 | 195 |
|
| 189 | 196 |
//unlace |
| 190 |
_prev |
|
| 197 |
(*_prev)[(*_next)[i]] = (*_prev)[i]; |
|
| 191 | 198 |
if ((*_prev)[i] != INVALID) {
|
| 192 |
_next |
|
| 199 |
(*_next)[(*_prev)[i]] = (*_next)[i]; |
|
| 193 | 200 |
} else {
|
| 194 | 201 |
_first[bucket] = (*_next)[i]; |
| 195 | 202 |
} |
| 196 | 203 |
//lace |
| 197 |
_prev->set(i, _last[bucket]); |
|
| 198 |
_next->set(_last[bucket], i); |
|
| 199 |
|
|
| 204 |
(*_prev)[i] = _last[bucket]; |
|
| 205 |
(*_next)[_last[bucket]] = i; |
|
| 206 |
(*_next)[i] = INVALID; |
|
| 200 | 207 |
_last[bucket] = i; |
| 201 | 208 |
} |
| 202 | 209 |
|
| 203 | 210 |
void addItem(const Node& i, int bucket) {
|
| 204 | 211 |
(*_bucket)[i] = bucket; |
| 205 | 212 |
if (_last[bucket] != INVALID) {
|
| 206 |
_prev->set(i, _last[bucket]); |
|
| 207 |
_next->set(_last[bucket], i); |
|
| 208 |
|
|
| 213 |
(*_prev)[i] = _last[bucket]; |
|
| 214 |
(*_next)[_last[bucket]] = i; |
|
| 215 |
(*_next)[i] = INVALID; |
|
| 209 | 216 |
_last[bucket] = i; |
| 210 | 217 |
} else {
|
| 211 |
_prev |
|
| 218 |
(*_prev)[i] = INVALID; |
|
| 212 | 219 |
_first[bucket] = i; |
| 213 |
_next |
|
| 220 |
(*_next)[i] = INVALID; |
|
| 214 | 221 |
_last[bucket] = i; |
| 215 | 222 |
} |
| 216 | 223 |
} |
| 217 | 224 |
|
| 218 | 225 |
void findMinCutOut() {
|
| 219 | 226 |
|
| 220 | 227 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 221 |
_excess |
|
| 228 |
(*_excess)[n] = 0; |
|
| 229 |
(*_source_set)[n] = false; |
|
| 222 | 230 |
} |
| 223 | 231 |
|
| 224 | 232 |
for (ArcIt a(_graph); a != INVALID; ++a) {
|
| 225 |
_flow |
|
| 233 |
(*_flow)[a] = 0; |
|
| 226 | 234 |
} |
| 227 | 235 |
|
| 228 | 236 |
int bucket_num = 0; |
| 229 | 237 |
std::vector<Node> queue(_node_num); |
| 230 | 238 |
int qfirst = 0, qlast = 0, qsep = 0; |
| 231 | 239 |
|
| 232 | 240 |
{
|
| 233 | 241 |
typename Digraph::template NodeMap<bool> reached(_graph, false); |
| 234 | 242 |
|
| 235 |
reached |
|
| 243 |
reached[_source] = true; |
|
| 236 | 244 |
bool first_set = true; |
| 237 | 245 |
|
| 238 | 246 |
for (NodeIt t(_graph); t != INVALID; ++t) {
|
| 239 | 247 |
if (reached[t]) continue; |
| 240 | 248 |
_sets.push_front(std::list<int>()); |
| 241 | 249 |
|
| 242 | 250 |
queue[qlast++] = t; |
| 243 |
reached |
|
| 251 |
reached[t] = true; |
|
| 244 | 252 |
|
| 245 | 253 |
while (qfirst != qlast) {
|
| 246 | 254 |
if (qsep == qfirst) {
|
| 247 | 255 |
++bucket_num; |
| 248 | 256 |
_sets.front().push_front(bucket_num); |
| 249 | 257 |
_dormant[bucket_num] = !first_set; |
| 250 | 258 |
_first[bucket_num] = _last[bucket_num] = INVALID; |
| 251 | 259 |
qsep = qlast; |
| 252 | 260 |
} |
| 253 | 261 |
|
| 254 | 262 |
Node n = queue[qfirst++]; |
| 255 | 263 |
addItem(n, bucket_num); |
| 256 | 264 |
|
| 257 | 265 |
for (InArcIt a(_graph, n); a != INVALID; ++a) {
|
| 258 | 266 |
Node u = _graph.source(a); |
| 259 | 267 |
if (!reached[u] && _tolerance.positive((*_capacity)[a])) {
|
| 260 |
reached |
|
| 268 |
reached[u] = true; |
|
| 261 | 269 |
queue[qlast++] = u; |
| 262 | 270 |
} |
| 263 | 271 |
} |
| 264 | 272 |
} |
| 265 | 273 |
first_set = false; |
| 266 | 274 |
} |
| 267 | 275 |
|
| 268 | 276 |
++bucket_num; |
| 269 |
_bucket |
|
| 277 |
(*_bucket)[_source] = 0; |
|
| 270 | 278 |
_dormant[0] = true; |
| 271 | 279 |
} |
| 272 |
_source_set |
|
| 280 |
(*_source_set)[_source] = true; |
|
| 273 | 281 |
|
| 274 | 282 |
Node target = _last[_sets.back().back()]; |
| 275 | 283 |
{
|
| 276 | 284 |
for (OutArcIt a(_graph, _source); a != INVALID; ++a) {
|
| 277 | 285 |
if (_tolerance.positive((*_capacity)[a])) {
|
| 278 | 286 |
Node u = _graph.target(a); |
| 279 |
_flow->set(a, (*_capacity)[a]); |
|
| 280 |
_excess->set(u, (*_excess)[u] + (*_capacity)[a]); |
|
| 287 |
(*_flow)[a] = (*_capacity)[a]; |
|
| 288 |
(*_excess)[u] += (*_capacity)[a]; |
|
| 281 | 289 |
if (!(*_active)[u] && u != _source) {
|
| 282 | 290 |
activate(u); |
| 283 | 291 |
} |
| 284 | 292 |
} |
| 285 | 293 |
} |
| 286 | 294 |
|
| 287 | 295 |
if ((*_active)[target]) {
|
| 288 | 296 |
deactivate(target); |
| 289 | 297 |
} |
| 290 | 298 |
|
| 291 | 299 |
_highest = _sets.back().begin(); |
| 292 | 300 |
while (_highest != _sets.back().end() && |
| 293 | 301 |
!(*_active)[_first[*_highest]]) {
|
| 294 | 302 |
++_highest; |
| 295 | 303 |
} |
| 296 | 304 |
} |
| 297 | 305 |
|
| 298 | 306 |
while (true) {
|
| 299 | 307 |
while (_highest != _sets.back().end()) {
|
| 300 | 308 |
Node n = _first[*_highest]; |
| 301 | 309 |
Value excess = (*_excess)[n]; |
| 302 | 310 |
int next_bucket = _node_num; |
| 303 | 311 |
|
| 304 | 312 |
int under_bucket; |
| 305 | 313 |
if (++std::list<int>::iterator(_highest) == _sets.back().end()) {
|
| 306 | 314 |
under_bucket = -1; |
| 307 | 315 |
} else {
|
| 308 | 316 |
under_bucket = *(++std::list<int>::iterator(_highest)); |
| 309 | 317 |
} |
| 310 | 318 |
|
| 311 | 319 |
for (OutArcIt a(_graph, n); a != INVALID; ++a) {
|
| 312 | 320 |
Node v = _graph.target(a); |
| 313 | 321 |
if (_dormant[(*_bucket)[v]]) continue; |
| 314 | 322 |
Value rem = (*_capacity)[a] - (*_flow)[a]; |
| 315 | 323 |
if (!_tolerance.positive(rem)) continue; |
| 316 | 324 |
if ((*_bucket)[v] == under_bucket) {
|
| 317 | 325 |
if (!(*_active)[v] && v != target) {
|
| 318 | 326 |
activate(v); |
| 319 | 327 |
} |
| 320 | 328 |
if (!_tolerance.less(rem, excess)) {
|
| 321 |
_flow->set(a, (*_flow)[a] + excess); |
|
| 322 |
_excess->set(v, (*_excess)[v] + excess); |
|
| 329 |
(*_flow)[a] += excess; |
|
| 330 |
(*_excess)[v] += excess; |
|
| 323 | 331 |
excess = 0; |
| 324 | 332 |
goto no_more_push; |
| 325 | 333 |
} else {
|
| 326 | 334 |
excess -= rem; |
| 327 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 328 |
_flow->set(a, (*_capacity)[a]); |
|
| 335 |
(*_excess)[v] += rem; |
|
| 336 |
(*_flow)[a] = (*_capacity)[a]; |
|
| 329 | 337 |
} |
| 330 | 338 |
} else if (next_bucket > (*_bucket)[v]) {
|
| 331 | 339 |
next_bucket = (*_bucket)[v]; |
| 332 | 340 |
} |
| 333 | 341 |
} |
| 334 | 342 |
|
| 335 | 343 |
for (InArcIt a(_graph, n); a != INVALID; ++a) {
|
| 336 | 344 |
Node v = _graph.source(a); |
| 337 | 345 |
if (_dormant[(*_bucket)[v]]) continue; |
| 338 | 346 |
Value rem = (*_flow)[a]; |
| 339 | 347 |
if (!_tolerance.positive(rem)) continue; |
| 340 | 348 |
if ((*_bucket)[v] == under_bucket) {
|
| 341 | 349 |
if (!(*_active)[v] && v != target) {
|
| 342 | 350 |
activate(v); |
| 343 | 351 |
} |
| 344 | 352 |
if (!_tolerance.less(rem, excess)) {
|
| 345 |
_flow->set(a, (*_flow)[a] - excess); |
|
| 346 |
_excess->set(v, (*_excess)[v] + excess); |
|
| 353 |
(*_flow)[a] -= excess; |
|
| 354 |
(*_excess)[v] += excess; |
|
| 347 | 355 |
excess = 0; |
| 348 | 356 |
goto no_more_push; |
| 349 | 357 |
} else {
|
| 350 | 358 |
excess -= rem; |
| 351 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 352 |
_flow->set(a, 0); |
|
| 359 |
(*_excess)[v] += rem; |
|
| 360 |
(*_flow)[a] = 0; |
|
| 353 | 361 |
} |
| 354 | 362 |
} else if (next_bucket > (*_bucket)[v]) {
|
| 355 | 363 |
next_bucket = (*_bucket)[v]; |
| 356 | 364 |
} |
| 357 | 365 |
} |
| 358 | 366 |
|
| 359 | 367 |
no_more_push: |
| 360 | 368 |
|
| 361 |
_excess |
|
| 369 |
(*_excess)[n] = excess; |
|
| 362 | 370 |
|
| 363 | 371 |
if (excess != 0) {
|
| 364 | 372 |
if ((*_next)[n] == INVALID) {
|
| 365 | 373 |
typename std::list<std::list<int> >::iterator new_set = |
| 366 | 374 |
_sets.insert(--_sets.end(), std::list<int>()); |
| 367 | 375 |
new_set->splice(new_set->end(), _sets.back(), |
| 368 | 376 |
_sets.back().begin(), ++_highest); |
| 369 | 377 |
for (std::list<int>::iterator it = new_set->begin(); |
| 370 | 378 |
it != new_set->end(); ++it) {
|
| 371 | 379 |
_dormant[*it] = true; |
| 372 | 380 |
} |
| 373 | 381 |
while (_highest != _sets.back().end() && |
| 374 | 382 |
!(*_active)[_first[*_highest]]) {
|
| 375 | 383 |
++_highest; |
| 376 | 384 |
} |
| 377 | 385 |
} else if (next_bucket == _node_num) {
|
| 378 | 386 |
_first[(*_bucket)[n]] = (*_next)[n]; |
| 379 |
_prev |
|
| 387 |
(*_prev)[(*_next)[n]] = INVALID; |
|
| 380 | 388 |
|
| 381 | 389 |
std::list<std::list<int> >::iterator new_set = |
| 382 | 390 |
_sets.insert(--_sets.end(), std::list<int>()); |
| 383 | 391 |
|
| 384 | 392 |
new_set->push_front(bucket_num); |
| 385 |
_bucket |
|
| 393 |
(*_bucket)[n] = bucket_num; |
|
| 386 | 394 |
_first[bucket_num] = _last[bucket_num] = n; |
| 387 |
_next->set(n, INVALID); |
|
| 388 |
_prev->set(n, INVALID); |
|
| 395 |
(*_next)[n] = INVALID; |
|
| 396 |
(*_prev)[n] = INVALID; |
|
| 389 | 397 |
_dormant[bucket_num] = true; |
| 390 | 398 |
++bucket_num; |
| 391 | 399 |
|
| 392 | 400 |
while (_highest != _sets.back().end() && |
| 393 | 401 |
!(*_active)[_first[*_highest]]) {
|
| 394 | 402 |
++_highest; |
| 395 | 403 |
} |
| 396 | 404 |
} else {
|
| 397 | 405 |
_first[*_highest] = (*_next)[n]; |
| 398 |
_prev |
|
| 406 |
(*_prev)[(*_next)[n]] = INVALID; |
|
| 399 | 407 |
|
| 400 | 408 |
while (next_bucket != *_highest) {
|
| 401 | 409 |
--_highest; |
| 402 | 410 |
} |
| 403 | 411 |
|
| 404 | 412 |
if (_highest == _sets.back().begin()) {
|
| 405 | 413 |
_sets.back().push_front(bucket_num); |
| 406 | 414 |
_dormant[bucket_num] = false; |
| 407 | 415 |
_first[bucket_num] = _last[bucket_num] = INVALID; |
| 408 | 416 |
++bucket_num; |
| 409 | 417 |
} |
| 410 | 418 |
--_highest; |
| 411 | 419 |
|
| 412 |
_bucket->set(n, *_highest); |
|
| 413 |
_next->set(n, _first[*_highest]); |
|
| 420 |
(*_bucket)[n] = *_highest; |
|
| 421 |
(*_next)[n] = _first[*_highest]; |
|
| 414 | 422 |
if (_first[*_highest] != INVALID) {
|
| 415 |
_prev |
|
| 423 |
(*_prev)[_first[*_highest]] = n; |
|
| 416 | 424 |
} else {
|
| 417 | 425 |
_last[*_highest] = n; |
| 418 | 426 |
} |
| 419 | 427 |
_first[*_highest] = n; |
| 420 | 428 |
} |
| 421 | 429 |
} else {
|
| 422 | 430 |
|
| 423 | 431 |
deactivate(n); |
| 424 | 432 |
if (!(*_active)[_first[*_highest]]) {
|
| 425 | 433 |
++_highest; |
| 426 | 434 |
if (_highest != _sets.back().end() && |
| 427 | 435 |
!(*_active)[_first[*_highest]]) {
|
| 428 | 436 |
_highest = _sets.back().end(); |
| 429 | 437 |
} |
| 430 | 438 |
} |
| 431 | 439 |
} |
| 432 | 440 |
} |
| 433 | 441 |
|
| 434 | 442 |
if ((*_excess)[target] < _min_cut) {
|
| 435 | 443 |
_min_cut = (*_excess)[target]; |
| 436 | 444 |
for (NodeIt i(_graph); i != INVALID; ++i) {
|
| 437 |
_min_cut_map |
|
| 445 |
(*_min_cut_map)[i] = true; |
|
| 438 | 446 |
} |
| 439 | 447 |
for (std::list<int>::iterator it = _sets.back().begin(); |
| 440 | 448 |
it != _sets.back().end(); ++it) {
|
| 441 | 449 |
Node n = _first[*it]; |
| 442 | 450 |
while (n != INVALID) {
|
| 443 |
_min_cut_map |
|
| 451 |
(*_min_cut_map)[n] = false; |
|
| 444 | 452 |
n = (*_next)[n]; |
| 445 | 453 |
} |
| 446 | 454 |
} |
| 447 | 455 |
} |
| 448 | 456 |
|
| 449 | 457 |
{
|
| 450 | 458 |
Node new_target; |
| 451 | 459 |
if ((*_prev)[target] != INVALID || (*_next)[target] != INVALID) {
|
| 452 | 460 |
if ((*_next)[target] == INVALID) {
|
| 453 | 461 |
_last[(*_bucket)[target]] = (*_prev)[target]; |
| 454 | 462 |
new_target = (*_prev)[target]; |
| 455 | 463 |
} else {
|
| 456 |
_prev |
|
| 464 |
(*_prev)[(*_next)[target]] = (*_prev)[target]; |
|
| 457 | 465 |
new_target = (*_next)[target]; |
| 458 | 466 |
} |
| 459 | 467 |
if ((*_prev)[target] == INVALID) {
|
| 460 | 468 |
_first[(*_bucket)[target]] = (*_next)[target]; |
| 461 | 469 |
} else {
|
| 462 |
_next |
|
| 470 |
(*_next)[(*_prev)[target]] = (*_next)[target]; |
|
| 463 | 471 |
} |
| 464 | 472 |
} else {
|
| 465 | 473 |
_sets.back().pop_back(); |
| 466 | 474 |
if (_sets.back().empty()) {
|
| 467 | 475 |
_sets.pop_back(); |
| 468 | 476 |
if (_sets.empty()) |
| 469 | 477 |
break; |
| 470 | 478 |
for (std::list<int>::iterator it = _sets.back().begin(); |
| 471 | 479 |
it != _sets.back().end(); ++it) {
|
| 472 | 480 |
_dormant[*it] = false; |
| 473 | 481 |
} |
| 474 | 482 |
} |
| 475 | 483 |
new_target = _last[_sets.back().back()]; |
| 476 | 484 |
} |
| 477 | 485 |
|
| 478 |
_bucket |
|
| 486 |
(*_bucket)[target] = 0; |
|
| 479 | 487 |
|
| 480 |
_source_set |
|
| 488 |
(*_source_set)[target] = true; |
|
| 481 | 489 |
for (OutArcIt a(_graph, target); a != INVALID; ++a) {
|
| 482 | 490 |
Value rem = (*_capacity)[a] - (*_flow)[a]; |
| 483 | 491 |
if (!_tolerance.positive(rem)) continue; |
| 484 | 492 |
Node v = _graph.target(a); |
| 485 | 493 |
if (!(*_active)[v] && !(*_source_set)[v]) {
|
| 486 | 494 |
activate(v); |
| 487 | 495 |
} |
| 488 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 489 |
_flow->set(a, (*_capacity)[a]); |
|
| 496 |
(*_excess)[v] += rem; |
|
| 497 |
(*_flow)[a] = (*_capacity)[a]; |
|
| 490 | 498 |
} |
| 491 | 499 |
|
| 492 | 500 |
for (InArcIt a(_graph, target); a != INVALID; ++a) {
|
| 493 | 501 |
Value rem = (*_flow)[a]; |
| 494 | 502 |
if (!_tolerance.positive(rem)) continue; |
| 495 | 503 |
Node v = _graph.source(a); |
| 496 | 504 |
if (!(*_active)[v] && !(*_source_set)[v]) {
|
| 497 | 505 |
activate(v); |
| 498 | 506 |
} |
| 499 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 500 |
_flow->set(a, 0); |
|
| 507 |
(*_excess)[v] += rem; |
|
| 508 |
(*_flow)[a] = 0; |
|
| 501 | 509 |
} |
| 502 | 510 |
|
| 503 | 511 |
target = new_target; |
| 504 | 512 |
if ((*_active)[target]) {
|
| 505 | 513 |
deactivate(target); |
| 506 | 514 |
} |
| 507 | 515 |
|
| 508 | 516 |
_highest = _sets.back().begin(); |
| 509 | 517 |
while (_highest != _sets.back().end() && |
| 510 | 518 |
!(*_active)[_first[*_highest]]) {
|
| 511 | 519 |
++_highest; |
| 512 | 520 |
} |
| 513 | 521 |
} |
| 514 | 522 |
} |
| 515 | 523 |
} |
| 516 | 524 |
|
| 517 | 525 |
void findMinCutIn() {
|
| 518 | 526 |
|
| 519 | 527 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 520 |
_excess |
|
| 528 |
(*_excess)[n] = 0; |
|
| 529 |
(*_source_set)[n] = false; |
|
| 521 | 530 |
} |
| 522 | 531 |
|
| 523 | 532 |
for (ArcIt a(_graph); a != INVALID; ++a) {
|
| 524 |
_flow |
|
| 533 |
(*_flow)[a] = 0; |
|
| 525 | 534 |
} |
| 526 | 535 |
|
| 527 | 536 |
int bucket_num = 0; |
| 528 | 537 |
std::vector<Node> queue(_node_num); |
| 529 | 538 |
int qfirst = 0, qlast = 0, qsep = 0; |
| 530 | 539 |
|
| 531 | 540 |
{
|
| 532 | 541 |
typename Digraph::template NodeMap<bool> reached(_graph, false); |
| 533 | 542 |
|
| 534 |
reached |
|
| 543 |
reached[_source] = true; |
|
| 535 | 544 |
|
| 536 | 545 |
bool first_set = true; |
| 537 | 546 |
|
| 538 | 547 |
for (NodeIt t(_graph); t != INVALID; ++t) {
|
| 539 | 548 |
if (reached[t]) continue; |
| 540 | 549 |
_sets.push_front(std::list<int>()); |
| 541 | 550 |
|
| 542 | 551 |
queue[qlast++] = t; |
| 543 |
reached |
|
| 552 |
reached[t] = true; |
|
| 544 | 553 |
|
| 545 | 554 |
while (qfirst != qlast) {
|
| 546 | 555 |
if (qsep == qfirst) {
|
| 547 | 556 |
++bucket_num; |
| 548 | 557 |
_sets.front().push_front(bucket_num); |
| 549 | 558 |
_dormant[bucket_num] = !first_set; |
| 550 | 559 |
_first[bucket_num] = _last[bucket_num] = INVALID; |
| 551 | 560 |
qsep = qlast; |
| 552 | 561 |
} |
| 553 | 562 |
|
| 554 | 563 |
Node n = queue[qfirst++]; |
| 555 | 564 |
addItem(n, bucket_num); |
| 556 | 565 |
|
| 557 | 566 |
for (OutArcIt a(_graph, n); a != INVALID; ++a) {
|
| 558 | 567 |
Node u = _graph.target(a); |
| 559 | 568 |
if (!reached[u] && _tolerance.positive((*_capacity)[a])) {
|
| 560 |
reached |
|
| 569 |
reached[u] = true; |
|
| 561 | 570 |
queue[qlast++] = u; |
| 562 | 571 |
} |
| 563 | 572 |
} |
| 564 | 573 |
} |
| 565 | 574 |
first_set = false; |
| 566 | 575 |
} |
| 567 | 576 |
|
| 568 | 577 |
++bucket_num; |
| 569 |
_bucket |
|
| 578 |
(*_bucket)[_source] = 0; |
|
| 570 | 579 |
_dormant[0] = true; |
| 571 | 580 |
} |
| 572 |
_source_set |
|
| 581 |
(*_source_set)[_source] = true; |
|
| 573 | 582 |
|
| 574 | 583 |
Node target = _last[_sets.back().back()]; |
| 575 | 584 |
{
|
| 576 | 585 |
for (InArcIt a(_graph, _source); a != INVALID; ++a) {
|
| 577 | 586 |
if (_tolerance.positive((*_capacity)[a])) {
|
| 578 | 587 |
Node u = _graph.source(a); |
| 579 |
_flow->set(a, (*_capacity)[a]); |
|
| 580 |
_excess->set(u, (*_excess)[u] + (*_capacity)[a]); |
|
| 588 |
(*_flow)[a] = (*_capacity)[a]; |
|
| 589 |
(*_excess)[u] += (*_capacity)[a]; |
|
| 581 | 590 |
if (!(*_active)[u] && u != _source) {
|
| 582 | 591 |
activate(u); |
| 583 | 592 |
} |
| 584 | 593 |
} |
| 585 | 594 |
} |
| 586 | 595 |
if ((*_active)[target]) {
|
| 587 | 596 |
deactivate(target); |
| 588 | 597 |
} |
| 589 | 598 |
|
| 590 | 599 |
_highest = _sets.back().begin(); |
| 591 | 600 |
while (_highest != _sets.back().end() && |
| 592 | 601 |
!(*_active)[_first[*_highest]]) {
|
| 593 | 602 |
++_highest; |
| 594 | 603 |
} |
| 595 | 604 |
} |
| 596 | 605 |
|
| 597 | 606 |
|
| 598 | 607 |
while (true) {
|
| 599 | 608 |
while (_highest != _sets.back().end()) {
|
| 600 | 609 |
Node n = _first[*_highest]; |
| 601 | 610 |
Value excess = (*_excess)[n]; |
| 602 | 611 |
int next_bucket = _node_num; |
| 603 | 612 |
|
| 604 | 613 |
int under_bucket; |
| 605 | 614 |
if (++std::list<int>::iterator(_highest) == _sets.back().end()) {
|
| 606 | 615 |
under_bucket = -1; |
| 607 | 616 |
} else {
|
| 608 | 617 |
under_bucket = *(++std::list<int>::iterator(_highest)); |
| 609 | 618 |
} |
| 610 | 619 |
|
| 611 | 620 |
for (InArcIt a(_graph, n); a != INVALID; ++a) {
|
| 612 | 621 |
Node v = _graph.source(a); |
| 613 | 622 |
if (_dormant[(*_bucket)[v]]) continue; |
| 614 | 623 |
Value rem = (*_capacity)[a] - (*_flow)[a]; |
| 615 | 624 |
if (!_tolerance.positive(rem)) continue; |
| 616 | 625 |
if ((*_bucket)[v] == under_bucket) {
|
| 617 | 626 |
if (!(*_active)[v] && v != target) {
|
| 618 | 627 |
activate(v); |
| 619 | 628 |
} |
| 620 | 629 |
if (!_tolerance.less(rem, excess)) {
|
| 621 |
_flow->set(a, (*_flow)[a] + excess); |
|
| 622 |
_excess->set(v, (*_excess)[v] + excess); |
|
| 630 |
(*_flow)[a] += excess; |
|
| 631 |
(*_excess)[v] += excess; |
|
| 623 | 632 |
excess = 0; |
| 624 | 633 |
goto no_more_push; |
| 625 | 634 |
} else {
|
| 626 | 635 |
excess -= rem; |
| 627 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 628 |
_flow->set(a, (*_capacity)[a]); |
|
| 636 |
(*_excess)[v] += rem; |
|
| 637 |
(*_flow)[a] = (*_capacity)[a]; |
|
| 629 | 638 |
} |
| 630 | 639 |
} else if (next_bucket > (*_bucket)[v]) {
|
| 631 | 640 |
next_bucket = (*_bucket)[v]; |
| 632 | 641 |
} |
| 633 | 642 |
} |
| 634 | 643 |
|
| 635 | 644 |
for (OutArcIt a(_graph, n); a != INVALID; ++a) {
|
| 636 | 645 |
Node v = _graph.target(a); |
| 637 | 646 |
if (_dormant[(*_bucket)[v]]) continue; |
| 638 | 647 |
Value rem = (*_flow)[a]; |
| 639 | 648 |
if (!_tolerance.positive(rem)) continue; |
| 640 | 649 |
if ((*_bucket)[v] == under_bucket) {
|
| 641 | 650 |
if (!(*_active)[v] && v != target) {
|
| 642 | 651 |
activate(v); |
| 643 | 652 |
} |
| 644 | 653 |
if (!_tolerance.less(rem, excess)) {
|
| 645 |
_flow->set(a, (*_flow)[a] - excess); |
|
| 646 |
_excess->set(v, (*_excess)[v] + excess); |
|
| 654 |
(*_flow)[a] -= excess; |
|
| 655 |
(*_excess)[v] += excess; |
|
| 647 | 656 |
excess = 0; |
| 648 | 657 |
goto no_more_push; |
| 649 | 658 |
} else {
|
| 650 | 659 |
excess -= rem; |
| 651 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 652 |
_flow->set(a, 0); |
|
| 660 |
(*_excess)[v] += rem; |
|
| 661 |
(*_flow)[a] = 0; |
|
| 653 | 662 |
} |
| 654 | 663 |
} else if (next_bucket > (*_bucket)[v]) {
|
| 655 | 664 |
next_bucket = (*_bucket)[v]; |
| 656 | 665 |
} |
| 657 | 666 |
} |
| 658 | 667 |
|
| 659 | 668 |
no_more_push: |
| 660 | 669 |
|
| 661 |
_excess |
|
| 670 |
(*_excess)[n] = excess; |
|
| 662 | 671 |
|
| 663 | 672 |
if (excess != 0) {
|
| 664 | 673 |
if ((*_next)[n] == INVALID) {
|
| 665 | 674 |
typename std::list<std::list<int> >::iterator new_set = |
| 666 | 675 |
_sets.insert(--_sets.end(), std::list<int>()); |
| 667 | 676 |
new_set->splice(new_set->end(), _sets.back(), |
| 668 | 677 |
_sets.back().begin(), ++_highest); |
| 669 | 678 |
for (std::list<int>::iterator it = new_set->begin(); |
| 670 | 679 |
it != new_set->end(); ++it) {
|
| 671 | 680 |
_dormant[*it] = true; |
| 672 | 681 |
} |
| 673 | 682 |
while (_highest != _sets.back().end() && |
| 674 | 683 |
!(*_active)[_first[*_highest]]) {
|
| 675 | 684 |
++_highest; |
| 676 | 685 |
} |
| 677 | 686 |
} else if (next_bucket == _node_num) {
|
| 678 | 687 |
_first[(*_bucket)[n]] = (*_next)[n]; |
| 679 |
_prev |
|
| 688 |
(*_prev)[(*_next)[n]] = INVALID; |
|
| 680 | 689 |
|
| 681 | 690 |
std::list<std::list<int> >::iterator new_set = |
| 682 | 691 |
_sets.insert(--_sets.end(), std::list<int>()); |
| 683 | 692 |
|
| 684 | 693 |
new_set->push_front(bucket_num); |
| 685 |
_bucket |
|
| 694 |
(*_bucket)[n] = bucket_num; |
|
| 686 | 695 |
_first[bucket_num] = _last[bucket_num] = n; |
| 687 |
_next->set(n, INVALID); |
|
| 688 |
_prev->set(n, INVALID); |
|
| 696 |
(*_next)[n] = INVALID; |
|
| 697 |
(*_prev)[n] = INVALID; |
|
| 689 | 698 |
_dormant[bucket_num] = true; |
| 690 | 699 |
++bucket_num; |
| 691 | 700 |
|
| 692 | 701 |
while (_highest != _sets.back().end() && |
| 693 | 702 |
!(*_active)[_first[*_highest]]) {
|
| 694 | 703 |
++_highest; |
| 695 | 704 |
} |
| 696 | 705 |
} else {
|
| 697 | 706 |
_first[*_highest] = (*_next)[n]; |
| 698 |
_prev |
|
| 707 |
(*_prev)[(*_next)[n]] = INVALID; |
|
| 699 | 708 |
|
| 700 | 709 |
while (next_bucket != *_highest) {
|
| 701 | 710 |
--_highest; |
| 702 | 711 |
} |
| 703 | 712 |
if (_highest == _sets.back().begin()) {
|
| 704 | 713 |
_sets.back().push_front(bucket_num); |
| 705 | 714 |
_dormant[bucket_num] = false; |
| 706 | 715 |
_first[bucket_num] = _last[bucket_num] = INVALID; |
| 707 | 716 |
++bucket_num; |
| 708 | 717 |
} |
| 709 | 718 |
--_highest; |
| 710 | 719 |
|
| 711 |
_bucket->set(n, *_highest); |
|
| 712 |
_next->set(n, _first[*_highest]); |
|
| 720 |
(*_bucket)[n] = *_highest; |
|
| 721 |
(*_next)[n] = _first[*_highest]; |
|
| 713 | 722 |
if (_first[*_highest] != INVALID) {
|
| 714 |
_prev |
|
| 723 |
(*_prev)[_first[*_highest]] = n; |
|
| 715 | 724 |
} else {
|
| 716 | 725 |
_last[*_highest] = n; |
| 717 | 726 |
} |
| 718 | 727 |
_first[*_highest] = n; |
| 719 | 728 |
} |
| 720 | 729 |
} else {
|
| 721 | 730 |
|
| 722 | 731 |
deactivate(n); |
| 723 | 732 |
if (!(*_active)[_first[*_highest]]) {
|
| 724 | 733 |
++_highest; |
| 725 | 734 |
if (_highest != _sets.back().end() && |
| 726 | 735 |
!(*_active)[_first[*_highest]]) {
|
| 727 | 736 |
_highest = _sets.back().end(); |
| 728 | 737 |
} |
| 729 | 738 |
} |
| 730 | 739 |
} |
| 731 | 740 |
} |
| 732 | 741 |
|
| 733 | 742 |
if ((*_excess)[target] < _min_cut) {
|
| 734 | 743 |
_min_cut = (*_excess)[target]; |
| 735 | 744 |
for (NodeIt i(_graph); i != INVALID; ++i) {
|
| 736 |
_min_cut_map |
|
| 745 |
(*_min_cut_map)[i] = false; |
|
| 737 | 746 |
} |
| 738 | 747 |
for (std::list<int>::iterator it = _sets.back().begin(); |
| 739 | 748 |
it != _sets.back().end(); ++it) {
|
| 740 | 749 |
Node n = _first[*it]; |
| 741 | 750 |
while (n != INVALID) {
|
| 742 |
_min_cut_map |
|
| 751 |
(*_min_cut_map)[n] = true; |
|
| 743 | 752 |
n = (*_next)[n]; |
| 744 | 753 |
} |
| 745 | 754 |
} |
| 746 | 755 |
} |
| 747 | 756 |
|
| 748 | 757 |
{
|
| 749 | 758 |
Node new_target; |
| 750 | 759 |
if ((*_prev)[target] != INVALID || (*_next)[target] != INVALID) {
|
| 751 | 760 |
if ((*_next)[target] == INVALID) {
|
| 752 | 761 |
_last[(*_bucket)[target]] = (*_prev)[target]; |
| 753 | 762 |
new_target = (*_prev)[target]; |
| 754 | 763 |
} else {
|
| 755 |
_prev |
|
| 764 |
(*_prev)[(*_next)[target]] = (*_prev)[target]; |
|
| 756 | 765 |
new_target = (*_next)[target]; |
| 757 | 766 |
} |
| 758 | 767 |
if ((*_prev)[target] == INVALID) {
|
| 759 | 768 |
_first[(*_bucket)[target]] = (*_next)[target]; |
| 760 | 769 |
} else {
|
| 761 |
_next |
|
| 770 |
(*_next)[(*_prev)[target]] = (*_next)[target]; |
|
| 762 | 771 |
} |
| 763 | 772 |
} else {
|
| 764 | 773 |
_sets.back().pop_back(); |
| 765 | 774 |
if (_sets.back().empty()) {
|
| 766 | 775 |
_sets.pop_back(); |
| 767 | 776 |
if (_sets.empty()) |
| 768 | 777 |
break; |
| 769 | 778 |
for (std::list<int>::iterator it = _sets.back().begin(); |
| 770 | 779 |
it != _sets.back().end(); ++it) {
|
| 771 | 780 |
_dormant[*it] = false; |
| 772 | 781 |
} |
| 773 | 782 |
} |
| 774 | 783 |
new_target = _last[_sets.back().back()]; |
| 775 | 784 |
} |
| 776 | 785 |
|
| 777 |
_bucket |
|
| 786 |
(*_bucket)[target] = 0; |
|
| 778 | 787 |
|
| 779 |
_source_set |
|
| 788 |
(*_source_set)[target] = true; |
|
| 780 | 789 |
for (InArcIt a(_graph, target); a != INVALID; ++a) {
|
| 781 | 790 |
Value rem = (*_capacity)[a] - (*_flow)[a]; |
| 782 | 791 |
if (!_tolerance.positive(rem)) continue; |
| 783 | 792 |
Node v = _graph.source(a); |
| 784 | 793 |
if (!(*_active)[v] && !(*_source_set)[v]) {
|
| 785 | 794 |
activate(v); |
| 786 | 795 |
} |
| 787 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 788 |
_flow->set(a, (*_capacity)[a]); |
|
| 796 |
(*_excess)[v] += rem; |
|
| 797 |
(*_flow)[a] = (*_capacity)[a]; |
|
| 789 | 798 |
} |
| 790 | 799 |
|
| 791 | 800 |
for (OutArcIt a(_graph, target); a != INVALID; ++a) {
|
| 792 | 801 |
Value rem = (*_flow)[a]; |
| 793 | 802 |
if (!_tolerance.positive(rem)) continue; |
| 794 | 803 |
Node v = _graph.target(a); |
| 795 | 804 |
if (!(*_active)[v] && !(*_source_set)[v]) {
|
| 796 | 805 |
activate(v); |
| 797 | 806 |
} |
| 798 |
_excess->set(v, (*_excess)[v] + rem); |
|
| 799 |
_flow->set(a, 0); |
|
| 807 |
(*_excess)[v] += rem; |
|
| 808 |
(*_flow)[a] = 0; |
|
| 800 | 809 |
} |
| 801 | 810 |
|
| 802 | 811 |
target = new_target; |
| 803 | 812 |
if ((*_active)[target]) {
|
| 804 | 813 |
deactivate(target); |
| 805 | 814 |
} |
| 806 | 815 |
|
| 807 | 816 |
_highest = _sets.back().begin(); |
| 808 | 817 |
while (_highest != _sets.back().end() && |
| 809 | 818 |
!(*_active)[_first[*_highest]]) {
|
| 810 | 819 |
++_highest; |
| 811 | 820 |
} |
| 812 | 821 |
} |
| 813 | 822 |
} |
| 814 | 823 |
} |
| 815 | 824 |
|
| 816 | 825 |
public: |
| 817 | 826 |
|
| 818 |
/// \name Execution |
|
| 827 |
/// \name Execution Control |
|
| 819 | 828 |
/// The simplest way to execute the algorithm is to use |
| 820 | 829 |
/// one of the member functions called \ref run(). |
| 821 | 830 |
/// \n |
| 822 |
/// If you need more control on the execution, |
|
| 823 |
/// first you must call \ref init(), then the \ref calculateIn() or |
|
| 824 |
/// |
|
| 831 |
/// If you need better control on the execution, |
|
| 832 |
/// you have to call one of the \ref init() functions first, then |
|
| 833 |
/// \ref calculateOut() and/or \ref calculateIn(). |
|
| 825 | 834 |
|
| 826 | 835 |
/// @{
|
| 827 | 836 |
|
| 828 |
/// \brief |
|
| 837 |
/// \brief Initialize the internal data structures. |
|
| 829 | 838 |
/// |
| 830 |
/// Initializes the internal data structures. It creates |
|
| 831 |
/// the maps, residual graph adaptors and some bucket structures |
|
| 832 |
/// |
|
| 839 |
/// This function initializes the internal data structures. It creates |
|
| 840 |
/// the maps and some bucket structures for the algorithm. |
|
| 841 |
/// The first node is used as the source node for the push-relabel |
|
| 842 |
/// algorithm. |
|
| 833 | 843 |
void init() {
|
| 834 | 844 |
init(NodeIt(_graph)); |
| 835 | 845 |
} |
| 836 | 846 |
|
| 837 |
/// \brief |
|
| 847 |
/// \brief Initialize the internal data structures. |
|
| 838 | 848 |
/// |
| 839 |
/// Initializes the internal data structures. It creates |
|
| 840 |
/// the maps, residual graph adaptor and some bucket structures |
|
| 841 |
/// for the algorithm. Node \c source is used as the push-relabel |
|
| 842 |
/// algorithm's source. |
|
| 849 |
/// This function initializes the internal data structures. It creates |
|
| 850 |
/// the maps and some bucket structures for the algorithm. |
|
| 851 |
/// The given node is used as the source node for the push-relabel |
|
| 852 |
/// algorithm. |
|
| 843 | 853 |
void init(const Node& source) {
|
| 844 | 854 |
_source = source; |
| 845 | 855 |
|
| 846 | 856 |
_node_num = countNodes(_graph); |
| 847 | 857 |
|
| 848 | 858 |
_first.resize(_node_num); |
| 849 | 859 |
_last.resize(_node_num); |
| 850 | 860 |
|
| 851 | 861 |
_dormant.resize(_node_num); |
| 852 | 862 |
|
| 853 | 863 |
if (!_flow) {
|
| 854 | 864 |
_flow = new FlowMap(_graph); |
| 855 | 865 |
} |
| 856 | 866 |
if (!_next) {
|
| 857 | 867 |
_next = new typename Digraph::template NodeMap<Node>(_graph); |
| 858 | 868 |
} |
| 859 | 869 |
if (!_prev) {
|
| 860 | 870 |
_prev = new typename Digraph::template NodeMap<Node>(_graph); |
| 861 | 871 |
} |
| 862 | 872 |
if (!_active) {
|
| 863 | 873 |
_active = new typename Digraph::template NodeMap<bool>(_graph); |
| 864 | 874 |
} |
| 865 | 875 |
if (!_bucket) {
|
| 866 | 876 |
_bucket = new typename Digraph::template NodeMap<int>(_graph); |
| 867 | 877 |
} |
| 868 | 878 |
if (!_excess) {
|
| 869 | 879 |
_excess = new ExcessMap(_graph); |
| 870 | 880 |
} |
| 871 | 881 |
if (!_source_set) {
|
| 872 | 882 |
_source_set = new SourceSetMap(_graph); |
| 873 | 883 |
} |
| 874 | 884 |
if (!_min_cut_map) {
|
| 875 | 885 |
_min_cut_map = new MinCutMap(_graph); |
| 876 | 886 |
} |
| 877 | 887 |
|
| 878 | 888 |
_min_cut = std::numeric_limits<Value>::max(); |
| 879 | 889 |
} |
| 880 | 890 |
|
| 881 | 891 |
|
| 882 |
/// \brief |
|
| 892 |
/// \brief Calculate a minimum cut with \f$ source \f$ on the |
|
| 883 | 893 |
/// source-side. |
| 884 | 894 |
/// |
| 885 |
/// |
|
| 895 |
/// This function calculates a minimum cut with \f$ source \f$ on the |
|
| 886 | 896 |
/// source-side (i.e. a set \f$ X\subsetneq V \f$ with |
| 887 |
/// \f$ source \in X \f$ and minimal |
|
| 897 |
/// \f$ source \in X \f$ and minimal outgoing capacity). |
|
| 898 |
/// |
|
| 899 |
/// \pre \ref init() must be called before using this function. |
|
| 888 | 900 |
void calculateOut() {
|
| 889 | 901 |
findMinCutOut(); |
| 890 | 902 |
} |
| 891 | 903 |
|
| 892 |
/// \brief Calculates a minimum cut with \f$ source \f$ on the |
|
| 893 |
/// target-side. |
|
| 904 |
/// \brief Calculate a minimum cut with \f$ source \f$ on the |
|
| 905 |
/// sink-side. |
|
| 894 | 906 |
/// |
| 895 |
/// Calculates a minimum cut with \f$ source \f$ on the |
|
| 896 |
/// target-side (i.e. a set \f$ X\subsetneq V \f$ with |
|
| 897 |
/// \f$ source \ |
|
| 907 |
/// This function calculates a minimum cut with \f$ source \f$ on the |
|
| 908 |
/// sink-side (i.e. a set \f$ X\subsetneq V \f$ with |
|
| 909 |
/// \f$ source \notin X \f$ and minimal outgoing capacity). |
|
| 910 |
/// |
|
| 911 |
/// \pre \ref init() must be called before using this function. |
|
| 898 | 912 |
void calculateIn() {
|
| 899 | 913 |
findMinCutIn(); |
| 900 | 914 |
} |
| 901 | 915 |
|
| 902 | 916 |
|
| 903 |
/// \brief |
|
| 917 |
/// \brief Run the algorithm. |
|
| 904 | 918 |
/// |
| 905 |
/// Runs the algorithm. It finds nodes \c source and \c target |
|
| 906 |
/// arbitrarily and then calls \ref init(), \ref calculateOut() |
|
| 919 |
/// This function runs the algorithm. It finds nodes \c source and |
|
| 920 |
/// \c target arbitrarily and then calls \ref init(), \ref calculateOut() |
|
| 907 | 921 |
/// and \ref calculateIn(). |
| 908 | 922 |
void run() {
|
| 909 | 923 |
init(); |
| 910 | 924 |
calculateOut(); |
| 911 | 925 |
calculateIn(); |
| 912 | 926 |
} |
| 913 | 927 |
|
| 914 |
/// \brief |
|
| 928 |
/// \brief Run the algorithm. |
|
| 915 | 929 |
/// |
| 916 |
/// Runs the algorithm. It uses the given \c source node, finds a |
|
| 917 |
/// proper \c target and then calls the \ref init(), \ref |
|
| 918 |
/// |
|
| 930 |
/// This function runs the algorithm. It uses the given \c source node, |
|
| 931 |
/// finds a proper \c target node and then calls the \ref init(), |
|
| 932 |
/// \ref calculateOut() and \ref calculateIn(). |
|
| 919 | 933 |
void run(const Node& s) {
|
| 920 | 934 |
init(s); |
| 921 | 935 |
calculateOut(); |
| 922 | 936 |
calculateIn(); |
| 923 | 937 |
} |
| 924 | 938 |
|
| 925 | 939 |
/// @} |
| 926 | 940 |
|
| 927 | 941 |
/// \name Query Functions |
| 928 | 942 |
/// The result of the %HaoOrlin algorithm |
| 929 |
/// can be obtained using these functions. |
|
| 930 |
/// \n |
|
| 931 |
/// Before using these functions, either \ref run(), \ref |
|
| 932 |
/// calculateOut() or \ref calculateIn() must be called. |
|
| 943 |
/// can be obtained using these functions.\n |
|
| 944 |
/// \ref run(), \ref calculateOut() or \ref calculateIn() |
|
| 945 |
/// should be called before using them. |
|
| 933 | 946 |
|
| 934 | 947 |
/// @{
|
| 935 | 948 |
|
| 936 |
/// \brief |
|
| 949 |
/// \brief Return the value of the minimum cut. |
|
| 937 | 950 |
/// |
| 938 |
/// |
|
| 951 |
/// This function returns the value of the minimum cut. |
|
| 952 |
/// |
|
| 953 |
/// \pre \ref run(), \ref calculateOut() or \ref calculateIn() |
|
| 954 |
/// must be called before using this function. |
|
| 939 | 955 |
Value minCutValue() const {
|
| 940 | 956 |
return _min_cut; |
| 941 | 957 |
} |
| 942 | 958 |
|
| 943 | 959 |
|
| 944 |
/// \brief |
|
| 960 |
/// \brief Return a minimum cut. |
|
| 945 | 961 |
/// |
| 946 |
/// Sets \c nodeMap to the characteristic vector of a minimum |
|
| 947 |
/// value cut: it will give a nonempty set \f$ X\subsetneq V \f$ |
|
| 948 |
/// with minimal out-degree (i.e. \c nodeMap will be true exactly |
|
| 949 |
/// for the nodes of \f$ X \f$). \pre nodeMap should be a |
|
| 950 |
/// bool-valued node-map. |
|
| 951 |
template <typename NodeMap> |
|
| 952 |
|
|
| 962 |
/// This function sets \c cutMap to the characteristic vector of a |
|
| 963 |
/// minimum value cut: it will give a non-empty set \f$ X\subsetneq V \f$ |
|
| 964 |
/// with minimal outgoing capacity (i.e. \c cutMap will be \c true exactly |
|
| 965 |
/// for the nodes of \f$ X \f$). |
|
| 966 |
/// |
|
| 967 |
/// \param cutMap A \ref concepts::WriteMap "writable" node map with |
|
| 968 |
/// \c bool (or convertible) value type. |
|
| 969 |
/// |
|
| 970 |
/// \return The value of the minimum cut. |
|
| 971 |
/// |
|
| 972 |
/// \pre \ref run(), \ref calculateOut() or \ref calculateIn() |
|
| 973 |
/// must be called before using this function. |
|
| 974 |
template <typename CutMap> |
|
| 975 |
Value minCutMap(CutMap& cutMap) const {
|
|
| 953 | 976 |
for (NodeIt it(_graph); it != INVALID; ++it) {
|
| 954 |
|
|
| 977 |
cutMap.set(it, (*_min_cut_map)[it]); |
|
| 955 | 978 |
} |
| 956 | 979 |
return _min_cut; |
| 957 | 980 |
} |
| 958 | 981 |
|
| 959 | 982 |
/// @} |
| 960 | 983 |
|
| 961 | 984 |
}; //class HaoOrlin |
| 962 | 985 |
|
| 963 |
|
|
| 964 | 986 |
} //namespace lemon |
| 965 | 987 |
|
| 966 | 988 |
#endif //LEMON_HAO_ORLIN_H |
| ... | ... |
@@ -247,99 +247,97 @@ |
| 247 | 247 |
} |
| 248 | 248 |
|
| 249 | 249 |
int dimension() const {
|
| 250 | 250 |
return _dim; |
| 251 | 251 |
} |
| 252 | 252 |
|
| 253 | 253 |
bool projection(Node node, int n) const {
|
| 254 | 254 |
return static_cast<bool>(node._id & (1 << n)); |
| 255 | 255 |
} |
| 256 | 256 |
|
| 257 | 257 |
int dimension(Edge edge) const {
|
| 258 | 258 |
return edge._id >> (_dim-1); |
| 259 | 259 |
} |
| 260 | 260 |
|
| 261 | 261 |
int dimension(Arc arc) const {
|
| 262 | 262 |
return arc._id >> _dim; |
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 | 265 |
int index(Node node) const {
|
| 266 | 266 |
return node._id; |
| 267 | 267 |
} |
| 268 | 268 |
|
| 269 | 269 |
Node operator()(int ix) const {
|
| 270 | 270 |
return Node(ix); |
| 271 | 271 |
} |
| 272 | 272 |
|
| 273 | 273 |
private: |
| 274 | 274 |
int _dim; |
| 275 | 275 |
int _node_num, _edge_num; |
| 276 | 276 |
}; |
| 277 | 277 |
|
| 278 | 278 |
|
| 279 | 279 |
typedef GraphExtender<HypercubeGraphBase> ExtendedHypercubeGraphBase; |
| 280 | 280 |
|
| 281 | 281 |
/// \ingroup graphs |
| 282 | 282 |
/// |
| 283 | 283 |
/// \brief Hypercube graph class |
| 284 | 284 |
/// |
| 285 | 285 |
/// This class implements a special graph type. The nodes of the graph |
| 286 | 286 |
/// are indiced with integers with at most \c dim binary digits. |
| 287 | 287 |
/// Two nodes are connected in the graph if and only if their indices |
| 288 | 288 |
/// differ only on one position in the binary form. |
| 289 | 289 |
/// |
| 290 | 290 |
/// \note The type of the indices is chosen to \c int for efficiency |
| 291 | 291 |
/// reasons. Thus the maximum dimension of this implementation is 26 |
| 292 | 292 |
/// (assuming that the size of \c int is 32 bit). |
| 293 | 293 |
/// |
| 294 | 294 |
/// This graph type fully conforms to the \ref concepts::Graph |
| 295 |
/// "Graph" concept, and it also has an important extra feature |
|
| 296 |
/// that its maps are real \ref concepts::ReferenceMap |
|
| 297 |
/// " |
|
| 295 |
/// "Graph concept". |
|
| 298 | 296 |
class HypercubeGraph : public ExtendedHypercubeGraphBase {
|
| 299 | 297 |
public: |
| 300 | 298 |
|
| 301 | 299 |
typedef ExtendedHypercubeGraphBase Parent; |
| 302 | 300 |
|
| 303 | 301 |
/// \brief Constructs a hypercube graph with \c dim dimensions. |
| 304 | 302 |
/// |
| 305 | 303 |
/// Constructs a hypercube graph with \c dim dimensions. |
| 306 | 304 |
HypercubeGraph(int dim) { construct(dim); }
|
| 307 | 305 |
|
| 308 | 306 |
/// \brief The number of dimensions. |
| 309 | 307 |
/// |
| 310 | 308 |
/// Gives back the number of dimensions. |
| 311 | 309 |
int dimension() const {
|
| 312 | 310 |
return Parent::dimension(); |
| 313 | 311 |
} |
| 314 | 312 |
|
| 315 | 313 |
/// \brief Returns \c true if the n'th bit of the node is one. |
| 316 | 314 |
/// |
| 317 | 315 |
/// Returns \c true if the n'th bit of the node is one. |
| 318 | 316 |
bool projection(Node node, int n) const {
|
| 319 | 317 |
return Parent::projection(node, n); |
| 320 | 318 |
} |
| 321 | 319 |
|
| 322 | 320 |
/// \brief The dimension id of an edge. |
| 323 | 321 |
/// |
| 324 | 322 |
/// Gives back the dimension id of the given edge. |
| 325 | 323 |
/// It is in the [0..dim-1] range. |
| 326 | 324 |
int dimension(Edge edge) const {
|
| 327 | 325 |
return Parent::dimension(edge); |
| 328 | 326 |
} |
| 329 | 327 |
|
| 330 | 328 |
/// \brief The dimension id of an arc. |
| 331 | 329 |
/// |
| 332 | 330 |
/// Gives back the dimension id of the given arc. |
| 333 | 331 |
/// It is in the [0..dim-1] range. |
| 334 | 332 |
int dimension(Arc arc) const {
|
| 335 | 333 |
return Parent::dimension(arc); |
| 336 | 334 |
} |
| 337 | 335 |
|
| 338 | 336 |
/// \brief The index of a node. |
| 339 | 337 |
/// |
| 340 | 338 |
/// Gives back the index of the given node. |
| 341 | 339 |
/// The lower bits of the integer describes the node. |
| 342 | 340 |
int index(Node node) const {
|
| 343 | 341 |
return Parent::index(node); |
| 344 | 342 |
} |
| 345 | 343 |
| ... | ... |
@@ -203,127 +203,125 @@ |
| 203 | 203 |
seq.push_back(std::make_pair(it, in[it])); |
| 204 | 204 |
} |
| 205 | 205 |
|
| 206 | 206 |
std::sort(seq.begin(), seq.end(), PairComp<Sequence>()); |
| 207 | 207 |
return KruskalOutputSelector<Graph, Sequence, Out>:: |
| 208 | 208 |
kruskal(graph, seq, out); |
| 209 | 209 |
} |
| 210 | 210 |
}; |
| 211 | 211 |
|
| 212 | 212 |
template <typename T> |
| 213 | 213 |
struct RemoveConst {
|
| 214 | 214 |
typedef T type; |
| 215 | 215 |
}; |
| 216 | 216 |
|
| 217 | 217 |
template <typename T> |
| 218 | 218 |
struct RemoveConst<const T> {
|
| 219 | 219 |
typedef T type; |
| 220 | 220 |
}; |
| 221 | 221 |
|
| 222 | 222 |
template <typename Graph, typename In, typename Out> |
| 223 | 223 |
struct KruskalOutputSelector<Graph, In, Out, |
| 224 | 224 |
typename enable_if<SequenceOutputIndicator<Out>, void>::type > |
| 225 | 225 |
{
|
| 226 | 226 |
typedef typename In::value_type::second_type Value; |
| 227 | 227 |
|
| 228 | 228 |
static Value kruskal(const Graph& graph, const In& in, Out& out) {
|
| 229 | 229 |
typedef LoggerBoolMap<typename RemoveConst<Out>::type> Map; |
| 230 | 230 |
Map map(out); |
| 231 | 231 |
return _kruskal_bits::kruskal(graph, in, map); |
| 232 | 232 |
} |
| 233 | 233 |
|
| 234 | 234 |
}; |
| 235 | 235 |
|
| 236 | 236 |
template <typename Graph, typename In, typename Out> |
| 237 | 237 |
struct KruskalOutputSelector<Graph, In, Out, |
| 238 | 238 |
typename enable_if<MapOutputIndicator<Out>, void>::type > |
| 239 | 239 |
{
|
| 240 | 240 |
typedef typename In::value_type::second_type Value; |
| 241 | 241 |
|
| 242 | 242 |
static Value kruskal(const Graph& graph, const In& in, Out& out) {
|
| 243 | 243 |
return _kruskal_bits::kruskal(graph, in, out); |
| 244 | 244 |
} |
| 245 | 245 |
}; |
| 246 | 246 |
|
| 247 | 247 |
} |
| 248 | 248 |
|
| 249 | 249 |
/// \ingroup spantree |
| 250 | 250 |
/// |
| 251 |
/// \brief Kruskal algorithm |
|
| 251 |
/// \brief Kruskal's algorithm for finding a minimum cost spanning tree of |
|
| 252 | 252 |
/// a graph. |
| 253 | 253 |
/// |
| 254 | 254 |
/// This function runs Kruskal's algorithm to find a minimum cost |
| 255 |
/// spanning tree. |
|
| 255 |
/// spanning tree of a graph. |
|
| 256 | 256 |
/// Due to some C++ hacking, it accepts various input and output types. |
| 257 | 257 |
/// |
| 258 | 258 |
/// \param g The graph the algorithm runs on. |
| 259 | 259 |
/// It can be either \ref concepts::Digraph "directed" or |
| 260 | 260 |
/// \ref concepts::Graph "undirected". |
| 261 | 261 |
/// If the graph is directed, the algorithm consider it to be |
| 262 | 262 |
/// undirected by disregarding the direction of the arcs. |
| 263 | 263 |
/// |
| 264 | 264 |
/// \param in This object is used to describe the arc/edge costs. |
| 265 | 265 |
/// It can be one of the following choices. |
| 266 | 266 |
/// - An STL compatible 'Forward Container' with |
| 267 |
/// <tt>std::pair<GR::Arc,X></tt> or |
|
| 268 |
/// <tt>std::pair<GR::Edge,X></tt> as its <tt>value_type</tt>, where |
|
| 269 |
/// |
|
| 267 |
/// <tt>std::pair<GR::Arc,C></tt> or |
|
| 268 |
/// <tt>std::pair<GR::Edge,C></tt> as its <tt>value_type</tt>, where |
|
| 269 |
/// \c C is the type of the costs. The pairs indicates the arcs/edges |
|
| 270 | 270 |
/// along with the assigned cost. <em>They must be in a |
| 271 | 271 |
/// cost-ascending order.</em> |
| 272 | 272 |
/// - Any readable arc/edge map. The values of the map indicate the |
| 273 | 273 |
/// arc/edge costs. |
| 274 | 274 |
/// |
| 275 | 275 |
/// \retval out Here we also have a choice. |
| 276 |
/// - It can be a writable \c bool arc/edge map. After running the |
|
| 277 |
/// algorithm it will contain the found minimum cost spanning |
|
| 276 |
/// - It can be a writable arc/edge map with \c bool value type. After |
|
| 277 |
/// running the algorithm it will contain the found minimum cost spanning |
|
| 278 | 278 |
/// tree: the value of an arc/edge will be set to \c true if it belongs |
| 279 | 279 |
/// to the tree, otherwise it will be set to \c false. The value of |
| 280 | 280 |
/// each arc/edge will be set exactly once. |
| 281 | 281 |
/// - It can also be an iteraror of an STL Container with |
| 282 | 282 |
/// <tt>GR::Arc</tt> or <tt>GR::Edge</tt> as its |
| 283 | 283 |
/// <tt>value_type</tt>. The algorithm copies the elements of the |
| 284 | 284 |
/// found tree into this sequence. For example, if we know that the |
| 285 | 285 |
/// spanning tree of the graph \c g has say 53 arcs, then we can |
| 286 | 286 |
/// put its arcs into an STL vector \c tree with a code like this. |
| 287 | 287 |
///\code |
| 288 | 288 |
/// std::vector<Arc> tree(53); |
| 289 | 289 |
/// kruskal(g,cost,tree.begin()); |
| 290 | 290 |
///\endcode |
| 291 | 291 |
/// Or if we don't know in advance the size of the tree, we can |
| 292 | 292 |
/// write this. |
| 293 | 293 |
///\code |
| 294 | 294 |
/// std::vector<Arc> tree; |
| 295 | 295 |
/// kruskal(g,cost,std::back_inserter(tree)); |
| 296 | 296 |
///\endcode |
| 297 | 297 |
/// |
| 298 | 298 |
/// \return The total cost of the found spanning tree. |
| 299 | 299 |
/// |
| 300 | 300 |
/// \note If the input graph is not (weakly) connected, a spanning |
| 301 | 301 |
/// forest is calculated instead of a spanning tree. |
| 302 | 302 |
|
| 303 | 303 |
#ifdef DOXYGEN |
| 304 |
template <class Graph, class In, class Out> |
|
| 305 |
Value kruskal(GR const& g, const In& in, Out& out) |
|
| 304 |
template <typename Graph, typename In, typename Out> |
|
| 305 |
Value kruskal(const Graph& g, const In& in, Out& out) |
|
| 306 | 306 |
#else |
| 307 | 307 |
template <class Graph, class In, class Out> |
| 308 | 308 |
inline typename _kruskal_bits::KruskalValueSelector<In>::Value |
| 309 | 309 |
kruskal(const Graph& graph, const In& in, Out& out) |
| 310 | 310 |
#endif |
| 311 | 311 |
{
|
| 312 | 312 |
return _kruskal_bits::KruskalInputSelector<Graph, In, Out>:: |
| 313 | 313 |
kruskal(graph, in, out); |
| 314 | 314 |
} |
| 315 | 315 |
|
| 316 | 316 |
|
| 317 |
|
|
| 318 |
|
|
| 319 | 317 |
template <class Graph, class In, class Out> |
| 320 | 318 |
inline typename _kruskal_bits::KruskalValueSelector<In>::Value |
| 321 | 319 |
kruskal(const Graph& graph, const In& in, const Out& out) |
| 322 | 320 |
{
|
| 323 | 321 |
return _kruskal_bits::KruskalInputSelector<Graph, In, const Out>:: |
| 324 | 322 |
kruskal(graph, in, out); |
| 325 | 323 |
} |
| 326 | 324 |
|
| 327 | 325 |
} //namespace lemon |
| 328 | 326 |
|
| 329 | 327 |
#endif //LEMON_KRUSKAL_H |
| ... | ... |
@@ -547,97 +547,97 @@ |
| 547 | 547 |
} |
| 548 | 548 |
|
| 549 | 549 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 550 | 550 |
it != _attributes.end(); ++it) {
|
| 551 | 551 |
delete it->second; |
| 552 | 552 |
} |
| 553 | 553 |
|
| 554 | 554 |
if (local_is) {
|
| 555 | 555 |
delete _is; |
| 556 | 556 |
} |
| 557 | 557 |
|
| 558 | 558 |
} |
| 559 | 559 |
|
| 560 | 560 |
private: |
| 561 | 561 |
|
| 562 | 562 |
template <typename TDGR> |
| 563 | 563 |
friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is); |
| 564 | 564 |
template <typename TDGR> |
| 565 | 565 |
friend DigraphReader<TDGR> digraphReader(TDGR& digraph, |
| 566 | 566 |
const std::string& fn); |
| 567 | 567 |
template <typename TDGR> |
| 568 | 568 |
friend DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn); |
| 569 | 569 |
|
| 570 | 570 |
DigraphReader(DigraphReader& other) |
| 571 | 571 |
: _is(other._is), local_is(other.local_is), _digraph(other._digraph), |
| 572 | 572 |
_use_nodes(other._use_nodes), _use_arcs(other._use_arcs), |
| 573 | 573 |
_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
|
| 574 | 574 |
|
| 575 | 575 |
other._is = 0; |
| 576 | 576 |
other.local_is = false; |
| 577 | 577 |
|
| 578 | 578 |
_node_index.swap(other._node_index); |
| 579 | 579 |
_arc_index.swap(other._arc_index); |
| 580 | 580 |
|
| 581 | 581 |
_node_maps.swap(other._node_maps); |
| 582 | 582 |
_arc_maps.swap(other._arc_maps); |
| 583 | 583 |
_attributes.swap(other._attributes); |
| 584 | 584 |
|
| 585 | 585 |
_nodes_caption = other._nodes_caption; |
| 586 | 586 |
_arcs_caption = other._arcs_caption; |
| 587 | 587 |
_attributes_caption = other._attributes_caption; |
| 588 | 588 |
|
| 589 | 589 |
} |
| 590 | 590 |
|
| 591 | 591 |
DigraphReader& operator=(const DigraphReader&); |
| 592 | 592 |
|
| 593 | 593 |
public: |
| 594 | 594 |
|
| 595 |
/// \name Reading |
|
| 595 |
/// \name Reading Rules |
|
| 596 | 596 |
/// @{
|
| 597 | 597 |
|
| 598 | 598 |
/// \brief Node map reading rule |
| 599 | 599 |
/// |
| 600 | 600 |
/// Add a node map reading rule to the reader. |
| 601 | 601 |
template <typename Map> |
| 602 | 602 |
DigraphReader& nodeMap(const std::string& caption, Map& map) {
|
| 603 | 603 |
checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); |
| 604 | 604 |
_reader_bits::MapStorageBase<Node>* storage = |
| 605 | 605 |
new _reader_bits::MapStorage<Node, Map>(map); |
| 606 | 606 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 607 | 607 |
return *this; |
| 608 | 608 |
} |
| 609 | 609 |
|
| 610 | 610 |
/// \brief Node map reading rule |
| 611 | 611 |
/// |
| 612 | 612 |
/// Add a node map reading rule with specialized converter to the |
| 613 | 613 |
/// reader. |
| 614 | 614 |
template <typename Map, typename Converter> |
| 615 | 615 |
DigraphReader& nodeMap(const std::string& caption, Map& map, |
| 616 | 616 |
const Converter& converter = Converter()) {
|
| 617 | 617 |
checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); |
| 618 | 618 |
_reader_bits::MapStorageBase<Node>* storage = |
| 619 | 619 |
new _reader_bits::MapStorage<Node, Map, Converter>(map, converter); |
| 620 | 620 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 621 | 621 |
return *this; |
| 622 | 622 |
} |
| 623 | 623 |
|
| 624 | 624 |
/// \brief Arc map reading rule |
| 625 | 625 |
/// |
| 626 | 626 |
/// Add an arc map reading rule to the reader. |
| 627 | 627 |
template <typename Map> |
| 628 | 628 |
DigraphReader& arcMap(const std::string& caption, Map& map) {
|
| 629 | 629 |
checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); |
| 630 | 630 |
_reader_bits::MapStorageBase<Arc>* storage = |
| 631 | 631 |
new _reader_bits::MapStorage<Arc, Map>(map); |
| 632 | 632 |
_arc_maps.push_back(std::make_pair(caption, storage)); |
| 633 | 633 |
return *this; |
| 634 | 634 |
} |
| 635 | 635 |
|
| 636 | 636 |
/// \brief Arc map reading rule |
| 637 | 637 |
/// |
| 638 | 638 |
/// Add an arc map reading rule with specialized converter to the |
| 639 | 639 |
/// reader. |
| 640 | 640 |
template <typename Map, typename Converter> |
| 641 | 641 |
DigraphReader& arcMap(const std::string& caption, Map& map, |
| 642 | 642 |
const Converter& converter = Converter()) {
|
| 643 | 643 |
checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); |
| ... | ... |
@@ -652,126 +652,126 @@ |
| 652 | 652 |
/// Add an attribute reading rule to the reader. |
| 653 | 653 |
template <typename Value> |
| 654 | 654 |
DigraphReader& attribute(const std::string& caption, Value& value) {
|
| 655 | 655 |
_reader_bits::ValueStorageBase* storage = |
| 656 | 656 |
new _reader_bits::ValueStorage<Value>(value); |
| 657 | 657 |
_attributes.insert(std::make_pair(caption, storage)); |
| 658 | 658 |
return *this; |
| 659 | 659 |
} |
| 660 | 660 |
|
| 661 | 661 |
/// \brief Attribute reading rule |
| 662 | 662 |
/// |
| 663 | 663 |
/// Add an attribute reading rule with specialized converter to the |
| 664 | 664 |
/// reader. |
| 665 | 665 |
template <typename Value, typename Converter> |
| 666 | 666 |
DigraphReader& attribute(const std::string& caption, Value& value, |
| 667 | 667 |
const Converter& converter = Converter()) {
|
| 668 | 668 |
_reader_bits::ValueStorageBase* storage = |
| 669 | 669 |
new _reader_bits::ValueStorage<Value, Converter>(value, converter); |
| 670 | 670 |
_attributes.insert(std::make_pair(caption, storage)); |
| 671 | 671 |
return *this; |
| 672 | 672 |
} |
| 673 | 673 |
|
| 674 | 674 |
/// \brief Node reading rule |
| 675 | 675 |
/// |
| 676 | 676 |
/// Add a node reading rule to reader. |
| 677 | 677 |
DigraphReader& node(const std::string& caption, Node& node) {
|
| 678 | 678 |
typedef _reader_bits::MapLookUpConverter<Node> Converter; |
| 679 | 679 |
Converter converter(_node_index); |
| 680 | 680 |
_reader_bits::ValueStorageBase* storage = |
| 681 | 681 |
new _reader_bits::ValueStorage<Node, Converter>(node, converter); |
| 682 | 682 |
_attributes.insert(std::make_pair(caption, storage)); |
| 683 | 683 |
return *this; |
| 684 | 684 |
} |
| 685 | 685 |
|
| 686 | 686 |
/// \brief Arc reading rule |
| 687 | 687 |
/// |
| 688 | 688 |
/// Add an arc reading rule to reader. |
| 689 | 689 |
DigraphReader& arc(const std::string& caption, Arc& arc) {
|
| 690 | 690 |
typedef _reader_bits::MapLookUpConverter<Arc> Converter; |
| 691 | 691 |
Converter converter(_arc_index); |
| 692 | 692 |
_reader_bits::ValueStorageBase* storage = |
| 693 | 693 |
new _reader_bits::ValueStorage<Arc, Converter>(arc, converter); |
| 694 | 694 |
_attributes.insert(std::make_pair(caption, storage)); |
| 695 | 695 |
return *this; |
| 696 | 696 |
} |
| 697 | 697 |
|
| 698 | 698 |
/// @} |
| 699 | 699 |
|
| 700 |
/// \name Select |
|
| 700 |
/// \name Select Section by Name |
|
| 701 | 701 |
/// @{
|
| 702 | 702 |
|
| 703 | 703 |
/// \brief Set \c \@nodes section to be read |
| 704 | 704 |
/// |
| 705 | 705 |
/// Set \c \@nodes section to be read |
| 706 | 706 |
DigraphReader& nodes(const std::string& caption) {
|
| 707 | 707 |
_nodes_caption = caption; |
| 708 | 708 |
return *this; |
| 709 | 709 |
} |
| 710 | 710 |
|
| 711 | 711 |
/// \brief Set \c \@arcs section to be read |
| 712 | 712 |
/// |
| 713 | 713 |
/// Set \c \@arcs section to be read |
| 714 | 714 |
DigraphReader& arcs(const std::string& caption) {
|
| 715 | 715 |
_arcs_caption = caption; |
| 716 | 716 |
return *this; |
| 717 | 717 |
} |
| 718 | 718 |
|
| 719 | 719 |
/// \brief Set \c \@attributes section to be read |
| 720 | 720 |
/// |
| 721 | 721 |
/// Set \c \@attributes section to be read |
| 722 | 722 |
DigraphReader& attributes(const std::string& caption) {
|
| 723 | 723 |
_attributes_caption = caption; |
| 724 | 724 |
return *this; |
| 725 | 725 |
} |
| 726 | 726 |
|
| 727 | 727 |
/// @} |
| 728 | 728 |
|
| 729 |
/// \name Using |
|
| 729 |
/// \name Using Previously Constructed Node or Arc Set |
|
| 730 | 730 |
/// @{
|
| 731 | 731 |
|
| 732 | 732 |
/// \brief Use previously constructed node set |
| 733 | 733 |
/// |
| 734 | 734 |
/// Use previously constructed node set, and specify the node |
| 735 | 735 |
/// label map. |
| 736 | 736 |
template <typename Map> |
| 737 | 737 |
DigraphReader& useNodes(const Map& map) {
|
| 738 | 738 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 739 | 739 |
LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); |
| 740 | 740 |
_use_nodes = true; |
| 741 | 741 |
_writer_bits::DefaultConverter<typename Map::Value> converter; |
| 742 | 742 |
for (NodeIt n(_digraph); n != INVALID; ++n) {
|
| 743 | 743 |
_node_index.insert(std::make_pair(converter(map[n]), n)); |
| 744 | 744 |
} |
| 745 | 745 |
return *this; |
| 746 | 746 |
} |
| 747 | 747 |
|
| 748 | 748 |
/// \brief Use previously constructed node set |
| 749 | 749 |
/// |
| 750 | 750 |
/// Use previously constructed node set, and specify the node |
| 751 | 751 |
/// label map and a functor which converts the label map values to |
| 752 | 752 |
/// \c std::string. |
| 753 | 753 |
template <typename Map, typename Converter> |
| 754 | 754 |
DigraphReader& useNodes(const Map& map, |
| 755 | 755 |
const Converter& converter = Converter()) {
|
| 756 | 756 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 757 | 757 |
LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); |
| 758 | 758 |
_use_nodes = true; |
| 759 | 759 |
for (NodeIt n(_digraph); n != INVALID; ++n) {
|
| 760 | 760 |
_node_index.insert(std::make_pair(converter(map[n]), n)); |
| 761 | 761 |
} |
| 762 | 762 |
return *this; |
| 763 | 763 |
} |
| 764 | 764 |
|
| 765 | 765 |
/// \brief Use previously constructed arc set |
| 766 | 766 |
/// |
| 767 | 767 |
/// Use previously constructed arc set, and specify the arc |
| 768 | 768 |
/// label map. |
| 769 | 769 |
template <typename Map> |
| 770 | 770 |
DigraphReader& useArcs(const Map& map) {
|
| 771 | 771 |
checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); |
| 772 | 772 |
LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member"); |
| 773 | 773 |
_use_arcs = true; |
| 774 | 774 |
_writer_bits::DefaultConverter<typename Map::Value> converter; |
| 775 | 775 |
for (ArcIt a(_digraph); a != INVALID; ++a) {
|
| 776 | 776 |
_arc_index.insert(std::make_pair(converter(map[a]), a)); |
| 777 | 777 |
} |
| ... | ... |
@@ -1070,97 +1070,97 @@ |
| 1070 | 1070 |
std::set<std::string> read_attr; |
| 1071 | 1071 |
|
| 1072 | 1072 |
char c; |
| 1073 | 1073 |
while (readLine() && line >> c && c != '@') {
|
| 1074 | 1074 |
line.putback(c); |
| 1075 | 1075 |
|
| 1076 | 1076 |
std::string attr, token; |
| 1077 | 1077 |
if (!_reader_bits::readToken(line, attr)) |
| 1078 | 1078 |
throw FormatError("Attribute name not found");
|
| 1079 | 1079 |
if (!_reader_bits::readToken(line, token)) |
| 1080 | 1080 |
throw FormatError("Attribute value not found");
|
| 1081 | 1081 |
if (line >> c) |
| 1082 | 1082 |
throw FormatError("Extra character at the end of line");
|
| 1083 | 1083 |
|
| 1084 | 1084 |
{
|
| 1085 | 1085 |
std::set<std::string>::iterator it = read_attr.find(attr); |
| 1086 | 1086 |
if (it != read_attr.end()) {
|
| 1087 | 1087 |
std::ostringstream msg; |
| 1088 | 1088 |
msg << "Multiple occurence of attribute: " << attr; |
| 1089 | 1089 |
throw FormatError(msg.str()); |
| 1090 | 1090 |
} |
| 1091 | 1091 |
read_attr.insert(attr); |
| 1092 | 1092 |
} |
| 1093 | 1093 |
|
| 1094 | 1094 |
{
|
| 1095 | 1095 |
typename Attributes::iterator it = _attributes.lower_bound(attr); |
| 1096 | 1096 |
while (it != _attributes.end() && it->first == attr) {
|
| 1097 | 1097 |
it->second->set(token); |
| 1098 | 1098 |
++it; |
| 1099 | 1099 |
} |
| 1100 | 1100 |
} |
| 1101 | 1101 |
|
| 1102 | 1102 |
} |
| 1103 | 1103 |
if (readSuccess()) {
|
| 1104 | 1104 |
line.putback(c); |
| 1105 | 1105 |
} |
| 1106 | 1106 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 1107 | 1107 |
it != _attributes.end(); ++it) {
|
| 1108 | 1108 |
if (read_attr.find(it->first) == read_attr.end()) {
|
| 1109 | 1109 |
std::ostringstream msg; |
| 1110 | 1110 |
msg << "Attribute not found: " << it->first; |
| 1111 | 1111 |
throw FormatError(msg.str()); |
| 1112 | 1112 |
} |
| 1113 | 1113 |
} |
| 1114 | 1114 |
} |
| 1115 | 1115 |
|
| 1116 | 1116 |
public: |
| 1117 | 1117 |
|
| 1118 |
/// \name Execution of the |
|
| 1118 |
/// \name Execution of the Reader |
|
| 1119 | 1119 |
/// @{
|
| 1120 | 1120 |
|
| 1121 | 1121 |
/// \brief Start the batch processing |
| 1122 | 1122 |
/// |
| 1123 | 1123 |
/// This function starts the batch processing |
| 1124 | 1124 |
void run() {
|
| 1125 | 1125 |
LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); |
| 1126 | 1126 |
|
| 1127 | 1127 |
bool nodes_done = _skip_nodes; |
| 1128 | 1128 |
bool arcs_done = _skip_arcs; |
| 1129 | 1129 |
bool attributes_done = false; |
| 1130 | 1130 |
|
| 1131 | 1131 |
line_num = 0; |
| 1132 | 1132 |
readLine(); |
| 1133 | 1133 |
skipSection(); |
| 1134 | 1134 |
|
| 1135 | 1135 |
while (readSuccess()) {
|
| 1136 | 1136 |
try {
|
| 1137 | 1137 |
char c; |
| 1138 | 1138 |
std::string section, caption; |
| 1139 | 1139 |
line >> c; |
| 1140 | 1140 |
_reader_bits::readToken(line, section); |
| 1141 | 1141 |
_reader_bits::readToken(line, caption); |
| 1142 | 1142 |
|
| 1143 | 1143 |
if (line >> c) |
| 1144 | 1144 |
throw FormatError("Extra character at the end of line");
|
| 1145 | 1145 |
|
| 1146 | 1146 |
if (section == "nodes" && !nodes_done) {
|
| 1147 | 1147 |
if (_nodes_caption.empty() || _nodes_caption == caption) {
|
| 1148 | 1148 |
readNodes(); |
| 1149 | 1149 |
nodes_done = true; |
| 1150 | 1150 |
} |
| 1151 | 1151 |
} else if ((section == "arcs" || section == "edges") && |
| 1152 | 1152 |
!arcs_done) {
|
| 1153 | 1153 |
if (_arcs_caption.empty() || _arcs_caption == caption) {
|
| 1154 | 1154 |
readArcs(); |
| 1155 | 1155 |
arcs_done = true; |
| 1156 | 1156 |
} |
| 1157 | 1157 |
} else if (section == "attributes" && !attributes_done) {
|
| 1158 | 1158 |
if (_attributes_caption.empty() || _attributes_caption == caption) {
|
| 1159 | 1159 |
readAttributes(); |
| 1160 | 1160 |
attributes_done = true; |
| 1161 | 1161 |
} |
| 1162 | 1162 |
} else {
|
| 1163 | 1163 |
readLine(); |
| 1164 | 1164 |
skipSection(); |
| 1165 | 1165 |
} |
| 1166 | 1166 |
} catch (FormatError& error) {
|
| ... | ... |
@@ -1370,97 +1370,97 @@ |
| 1370 | 1370 |
it != _edge_maps.end(); ++it) {
|
| 1371 | 1371 |
delete it->second; |
| 1372 | 1372 |
} |
| 1373 | 1373 |
|
| 1374 | 1374 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 1375 | 1375 |
it != _attributes.end(); ++it) {
|
| 1376 | 1376 |
delete it->second; |
| 1377 | 1377 |
} |
| 1378 | 1378 |
|
| 1379 | 1379 |
if (local_is) {
|
| 1380 | 1380 |
delete _is; |
| 1381 | 1381 |
} |
| 1382 | 1382 |
|
| 1383 | 1383 |
} |
| 1384 | 1384 |
|
| 1385 | 1385 |
private: |
| 1386 | 1386 |
template <typename TGR> |
| 1387 | 1387 |
friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is); |
| 1388 | 1388 |
template <typename TGR> |
| 1389 | 1389 |
friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); |
| 1390 | 1390 |
template <typename TGR> |
| 1391 | 1391 |
friend GraphReader<TGR> graphReader(TGR& graph, const char *fn); |
| 1392 | 1392 |
|
| 1393 | 1393 |
GraphReader(GraphReader& other) |
| 1394 | 1394 |
: _is(other._is), local_is(other.local_is), _graph(other._graph), |
| 1395 | 1395 |
_use_nodes(other._use_nodes), _use_edges(other._use_edges), |
| 1396 | 1396 |
_skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
|
| 1397 | 1397 |
|
| 1398 | 1398 |
other._is = 0; |
| 1399 | 1399 |
other.local_is = false; |
| 1400 | 1400 |
|
| 1401 | 1401 |
_node_index.swap(other._node_index); |
| 1402 | 1402 |
_edge_index.swap(other._edge_index); |
| 1403 | 1403 |
|
| 1404 | 1404 |
_node_maps.swap(other._node_maps); |
| 1405 | 1405 |
_edge_maps.swap(other._edge_maps); |
| 1406 | 1406 |
_attributes.swap(other._attributes); |
| 1407 | 1407 |
|
| 1408 | 1408 |
_nodes_caption = other._nodes_caption; |
| 1409 | 1409 |
_edges_caption = other._edges_caption; |
| 1410 | 1410 |
_attributes_caption = other._attributes_caption; |
| 1411 | 1411 |
|
| 1412 | 1412 |
} |
| 1413 | 1413 |
|
| 1414 | 1414 |
GraphReader& operator=(const GraphReader&); |
| 1415 | 1415 |
|
| 1416 | 1416 |
public: |
| 1417 | 1417 |
|
| 1418 |
/// \name Reading |
|
| 1418 |
/// \name Reading Rules |
|
| 1419 | 1419 |
/// @{
|
| 1420 | 1420 |
|
| 1421 | 1421 |
/// \brief Node map reading rule |
| 1422 | 1422 |
/// |
| 1423 | 1423 |
/// Add a node map reading rule to the reader. |
| 1424 | 1424 |
template <typename Map> |
| 1425 | 1425 |
GraphReader& nodeMap(const std::string& caption, Map& map) {
|
| 1426 | 1426 |
checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); |
| 1427 | 1427 |
_reader_bits::MapStorageBase<Node>* storage = |
| 1428 | 1428 |
new _reader_bits::MapStorage<Node, Map>(map); |
| 1429 | 1429 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 1430 | 1430 |
return *this; |
| 1431 | 1431 |
} |
| 1432 | 1432 |
|
| 1433 | 1433 |
/// \brief Node map reading rule |
| 1434 | 1434 |
/// |
| 1435 | 1435 |
/// Add a node map reading rule with specialized converter to the |
| 1436 | 1436 |
/// reader. |
| 1437 | 1437 |
template <typename Map, typename Converter> |
| 1438 | 1438 |
GraphReader& nodeMap(const std::string& caption, Map& map, |
| 1439 | 1439 |
const Converter& converter = Converter()) {
|
| 1440 | 1440 |
checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); |
| 1441 | 1441 |
_reader_bits::MapStorageBase<Node>* storage = |
| 1442 | 1442 |
new _reader_bits::MapStorage<Node, Map, Converter>(map, converter); |
| 1443 | 1443 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 1444 | 1444 |
return *this; |
| 1445 | 1445 |
} |
| 1446 | 1446 |
|
| 1447 | 1447 |
/// \brief Edge map reading rule |
| 1448 | 1448 |
/// |
| 1449 | 1449 |
/// Add an edge map reading rule to the reader. |
| 1450 | 1450 |
template <typename Map> |
| 1451 | 1451 |
GraphReader& edgeMap(const std::string& caption, Map& map) {
|
| 1452 | 1452 |
checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>(); |
| 1453 | 1453 |
_reader_bits::MapStorageBase<Edge>* storage = |
| 1454 | 1454 |
new _reader_bits::MapStorage<Edge, Map>(map); |
| 1455 | 1455 |
_edge_maps.push_back(std::make_pair(caption, storage)); |
| 1456 | 1456 |
return *this; |
| 1457 | 1457 |
} |
| 1458 | 1458 |
|
| 1459 | 1459 |
/// \brief Edge map reading rule |
| 1460 | 1460 |
/// |
| 1461 | 1461 |
/// Add an edge map reading rule with specialized converter to the |
| 1462 | 1462 |
/// reader. |
| 1463 | 1463 |
template <typename Map, typename Converter> |
| 1464 | 1464 |
GraphReader& edgeMap(const std::string& caption, Map& map, |
| 1465 | 1465 |
const Converter& converter = Converter()) {
|
| 1466 | 1466 |
checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>(); |
| ... | ... |
@@ -1521,126 +1521,126 @@ |
| 1521 | 1521 |
/// reader. |
| 1522 | 1522 |
template <typename Value, typename Converter> |
| 1523 | 1523 |
GraphReader& attribute(const std::string& caption, Value& value, |
| 1524 | 1524 |
const Converter& converter = Converter()) {
|
| 1525 | 1525 |
_reader_bits::ValueStorageBase* storage = |
| 1526 | 1526 |
new _reader_bits::ValueStorage<Value, Converter>(value, converter); |
| 1527 | 1527 |
_attributes.insert(std::make_pair(caption, storage)); |
| 1528 | 1528 |
return *this; |
| 1529 | 1529 |
} |
| 1530 | 1530 |
|
| 1531 | 1531 |
/// \brief Node reading rule |
| 1532 | 1532 |
/// |
| 1533 | 1533 |
/// Add a node reading rule to reader. |
| 1534 | 1534 |
GraphReader& node(const std::string& caption, Node& node) {
|
| 1535 | 1535 |
typedef _reader_bits::MapLookUpConverter<Node> Converter; |
| 1536 | 1536 |
Converter converter(_node_index); |
| 1537 | 1537 |
_reader_bits::ValueStorageBase* storage = |
| 1538 | 1538 |
new _reader_bits::ValueStorage<Node, Converter>(node, converter); |
| 1539 | 1539 |
_attributes.insert(std::make_pair(caption, storage)); |
| 1540 | 1540 |
return *this; |
| 1541 | 1541 |
} |
| 1542 | 1542 |
|
| 1543 | 1543 |
/// \brief Edge reading rule |
| 1544 | 1544 |
/// |
| 1545 | 1545 |
/// Add an edge reading rule to reader. |
| 1546 | 1546 |
GraphReader& edge(const std::string& caption, Edge& edge) {
|
| 1547 | 1547 |
typedef _reader_bits::MapLookUpConverter<Edge> Converter; |
| 1548 | 1548 |
Converter converter(_edge_index); |
| 1549 | 1549 |
_reader_bits::ValueStorageBase* storage = |
| 1550 | 1550 |
new _reader_bits::ValueStorage<Edge, Converter>(edge, converter); |
| 1551 | 1551 |
_attributes.insert(std::make_pair(caption, storage)); |
| 1552 | 1552 |
return *this; |
| 1553 | 1553 |
} |
| 1554 | 1554 |
|
| 1555 | 1555 |
/// \brief Arc reading rule |
| 1556 | 1556 |
/// |
| 1557 | 1557 |
/// Add an arc reading rule to reader. |
| 1558 | 1558 |
GraphReader& arc(const std::string& caption, Arc& arc) {
|
| 1559 | 1559 |
typedef _reader_bits::GraphArcLookUpConverter<GR> Converter; |
| 1560 | 1560 |
Converter converter(_graph, _edge_index); |
| 1561 | 1561 |
_reader_bits::ValueStorageBase* storage = |
| 1562 | 1562 |
new _reader_bits::ValueStorage<Arc, Converter>(arc, converter); |
| 1563 | 1563 |
_attributes.insert(std::make_pair(caption, storage)); |
| 1564 | 1564 |
return *this; |
| 1565 | 1565 |
} |
| 1566 | 1566 |
|
| 1567 | 1567 |
/// @} |
| 1568 | 1568 |
|
| 1569 |
/// \name Select |
|
| 1569 |
/// \name Select Section by Name |
|
| 1570 | 1570 |
/// @{
|
| 1571 | 1571 |
|
| 1572 | 1572 |
/// \brief Set \c \@nodes section to be read |
| 1573 | 1573 |
/// |
| 1574 | 1574 |
/// Set \c \@nodes section to be read. |
| 1575 | 1575 |
GraphReader& nodes(const std::string& caption) {
|
| 1576 | 1576 |
_nodes_caption = caption; |
| 1577 | 1577 |
return *this; |
| 1578 | 1578 |
} |
| 1579 | 1579 |
|
| 1580 | 1580 |
/// \brief Set \c \@edges section to be read |
| 1581 | 1581 |
/// |
| 1582 | 1582 |
/// Set \c \@edges section to be read. |
| 1583 | 1583 |
GraphReader& edges(const std::string& caption) {
|
| 1584 | 1584 |
_edges_caption = caption; |
| 1585 | 1585 |
return *this; |
| 1586 | 1586 |
} |
| 1587 | 1587 |
|
| 1588 | 1588 |
/// \brief Set \c \@attributes section to be read |
| 1589 | 1589 |
/// |
| 1590 | 1590 |
/// Set \c \@attributes section to be read. |
| 1591 | 1591 |
GraphReader& attributes(const std::string& caption) {
|
| 1592 | 1592 |
_attributes_caption = caption; |
| 1593 | 1593 |
return *this; |
| 1594 | 1594 |
} |
| 1595 | 1595 |
|
| 1596 | 1596 |
/// @} |
| 1597 | 1597 |
|
| 1598 |
/// \name Using |
|
| 1598 |
/// \name Using Previously Constructed Node or Edge Set |
|
| 1599 | 1599 |
/// @{
|
| 1600 | 1600 |
|
| 1601 | 1601 |
/// \brief Use previously constructed node set |
| 1602 | 1602 |
/// |
| 1603 | 1603 |
/// Use previously constructed node set, and specify the node |
| 1604 | 1604 |
/// label map. |
| 1605 | 1605 |
template <typename Map> |
| 1606 | 1606 |
GraphReader& useNodes(const Map& map) {
|
| 1607 | 1607 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 1608 | 1608 |
LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); |
| 1609 | 1609 |
_use_nodes = true; |
| 1610 | 1610 |
_writer_bits::DefaultConverter<typename Map::Value> converter; |
| 1611 | 1611 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 1612 | 1612 |
_node_index.insert(std::make_pair(converter(map[n]), n)); |
| 1613 | 1613 |
} |
| 1614 | 1614 |
return *this; |
| 1615 | 1615 |
} |
| 1616 | 1616 |
|
| 1617 | 1617 |
/// \brief Use previously constructed node set |
| 1618 | 1618 |
/// |
| 1619 | 1619 |
/// Use previously constructed node set, and specify the node |
| 1620 | 1620 |
/// label map and a functor which converts the label map values to |
| 1621 | 1621 |
/// \c std::string. |
| 1622 | 1622 |
template <typename Map, typename Converter> |
| 1623 | 1623 |
GraphReader& useNodes(const Map& map, |
| 1624 | 1624 |
const Converter& converter = Converter()) {
|
| 1625 | 1625 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 1626 | 1626 |
LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); |
| 1627 | 1627 |
_use_nodes = true; |
| 1628 | 1628 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 1629 | 1629 |
_node_index.insert(std::make_pair(converter(map[n]), n)); |
| 1630 | 1630 |
} |
| 1631 | 1631 |
return *this; |
| 1632 | 1632 |
} |
| 1633 | 1633 |
|
| 1634 | 1634 |
/// \brief Use previously constructed edge set |
| 1635 | 1635 |
/// |
| 1636 | 1636 |
/// Use previously constructed edge set, and specify the edge |
| 1637 | 1637 |
/// label map. |
| 1638 | 1638 |
template <typename Map> |
| 1639 | 1639 |
GraphReader& useEdges(const Map& map) {
|
| 1640 | 1640 |
checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>(); |
| 1641 | 1641 |
LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member"); |
| 1642 | 1642 |
_use_edges = true; |
| 1643 | 1643 |
_writer_bits::DefaultConverter<typename Map::Value> converter; |
| 1644 | 1644 |
for (EdgeIt a(_graph); a != INVALID; ++a) {
|
| 1645 | 1645 |
_edge_index.insert(std::make_pair(converter(map[a]), a)); |
| 1646 | 1646 |
} |
| ... | ... |
@@ -1940,97 +1940,97 @@ |
| 1940 | 1940 |
std::set<std::string> read_attr; |
| 1941 | 1941 |
|
| 1942 | 1942 |
char c; |
| 1943 | 1943 |
while (readLine() && line >> c && c != '@') {
|
| 1944 | 1944 |
line.putback(c); |
| 1945 | 1945 |
|
| 1946 | 1946 |
std::string attr, token; |
| 1947 | 1947 |
if (!_reader_bits::readToken(line, attr)) |
| 1948 | 1948 |
throw FormatError("Attribute name not found");
|
| 1949 | 1949 |
if (!_reader_bits::readToken(line, token)) |
| 1950 | 1950 |
throw FormatError("Attribute value not found");
|
| 1951 | 1951 |
if (line >> c) |
| 1952 | 1952 |
throw FormatError("Extra character at the end of line");
|
| 1953 | 1953 |
|
| 1954 | 1954 |
{
|
| 1955 | 1955 |
std::set<std::string>::iterator it = read_attr.find(attr); |
| 1956 | 1956 |
if (it != read_attr.end()) {
|
| 1957 | 1957 |
std::ostringstream msg; |
| 1958 | 1958 |
msg << "Multiple occurence of attribute: " << attr; |
| 1959 | 1959 |
throw FormatError(msg.str()); |
| 1960 | 1960 |
} |
| 1961 | 1961 |
read_attr.insert(attr); |
| 1962 | 1962 |
} |
| 1963 | 1963 |
|
| 1964 | 1964 |
{
|
| 1965 | 1965 |
typename Attributes::iterator it = _attributes.lower_bound(attr); |
| 1966 | 1966 |
while (it != _attributes.end() && it->first == attr) {
|
| 1967 | 1967 |
it->second->set(token); |
| 1968 | 1968 |
++it; |
| 1969 | 1969 |
} |
| 1970 | 1970 |
} |
| 1971 | 1971 |
|
| 1972 | 1972 |
} |
| 1973 | 1973 |
if (readSuccess()) {
|
| 1974 | 1974 |
line.putback(c); |
| 1975 | 1975 |
} |
| 1976 | 1976 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 1977 | 1977 |
it != _attributes.end(); ++it) {
|
| 1978 | 1978 |
if (read_attr.find(it->first) == read_attr.end()) {
|
| 1979 | 1979 |
std::ostringstream msg; |
| 1980 | 1980 |
msg << "Attribute not found: " << it->first; |
| 1981 | 1981 |
throw FormatError(msg.str()); |
| 1982 | 1982 |
} |
| 1983 | 1983 |
} |
| 1984 | 1984 |
} |
| 1985 | 1985 |
|
| 1986 | 1986 |
public: |
| 1987 | 1987 |
|
| 1988 |
/// \name Execution of the |
|
| 1988 |
/// \name Execution of the Reader |
|
| 1989 | 1989 |
/// @{
|
| 1990 | 1990 |
|
| 1991 | 1991 |
/// \brief Start the batch processing |
| 1992 | 1992 |
/// |
| 1993 | 1993 |
/// This function starts the batch processing |
| 1994 | 1994 |
void run() {
|
| 1995 | 1995 |
|
| 1996 | 1996 |
LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); |
| 1997 | 1997 |
|
| 1998 | 1998 |
bool nodes_done = _skip_nodes; |
| 1999 | 1999 |
bool edges_done = _skip_edges; |
| 2000 | 2000 |
bool attributes_done = false; |
| 2001 | 2001 |
|
| 2002 | 2002 |
line_num = 0; |
| 2003 | 2003 |
readLine(); |
| 2004 | 2004 |
skipSection(); |
| 2005 | 2005 |
|
| 2006 | 2006 |
while (readSuccess()) {
|
| 2007 | 2007 |
try {
|
| 2008 | 2008 |
char c; |
| 2009 | 2009 |
std::string section, caption; |
| 2010 | 2010 |
line >> c; |
| 2011 | 2011 |
_reader_bits::readToken(line, section); |
| 2012 | 2012 |
_reader_bits::readToken(line, caption); |
| 2013 | 2013 |
|
| 2014 | 2014 |
if (line >> c) |
| 2015 | 2015 |
throw FormatError("Extra character at the end of line");
|
| 2016 | 2016 |
|
| 2017 | 2017 |
if (section == "nodes" && !nodes_done) {
|
| 2018 | 2018 |
if (_nodes_caption.empty() || _nodes_caption == caption) {
|
| 2019 | 2019 |
readNodes(); |
| 2020 | 2020 |
nodes_done = true; |
| 2021 | 2021 |
} |
| 2022 | 2022 |
} else if ((section == "edges" || section == "arcs") && |
| 2023 | 2023 |
!edges_done) {
|
| 2024 | 2024 |
if (_edges_caption.empty() || _edges_caption == caption) {
|
| 2025 | 2025 |
readEdges(); |
| 2026 | 2026 |
edges_done = true; |
| 2027 | 2027 |
} |
| 2028 | 2028 |
} else if (section == "attributes" && !attributes_done) {
|
| 2029 | 2029 |
if (_attributes_caption.empty() || _attributes_caption == caption) {
|
| 2030 | 2030 |
readAttributes(); |
| 2031 | 2031 |
attributes_done = true; |
| 2032 | 2032 |
} |
| 2033 | 2033 |
} else {
|
| 2034 | 2034 |
readLine(); |
| 2035 | 2035 |
skipSection(); |
| 2036 | 2036 |
} |
| ... | ... |
@@ -2164,97 +2164,97 @@ |
| 2164 | 2164 |
throw IoError("Cannot open file", fn);
|
| 2165 | 2165 |
} |
| 2166 | 2166 |
} |
| 2167 | 2167 |
|
| 2168 | 2168 |
/// \brief Constructor |
| 2169 | 2169 |
/// |
| 2170 | 2170 |
/// Construct a section reader, which reads from the given file. |
| 2171 | 2171 |
SectionReader(const char* fn) |
| 2172 | 2172 |
: _is(new std::ifstream(fn)), local_is(true), |
| 2173 | 2173 |
_filename(fn) {
|
| 2174 | 2174 |
if (!(*_is)) {
|
| 2175 | 2175 |
delete _is; |
| 2176 | 2176 |
throw IoError("Cannot open file", fn);
|
| 2177 | 2177 |
} |
| 2178 | 2178 |
} |
| 2179 | 2179 |
|
| 2180 | 2180 |
/// \brief Destructor |
| 2181 | 2181 |
~SectionReader() {
|
| 2182 | 2182 |
for (Sections::iterator it = _sections.begin(); |
| 2183 | 2183 |
it != _sections.end(); ++it) {
|
| 2184 | 2184 |
delete it->second; |
| 2185 | 2185 |
} |
| 2186 | 2186 |
|
| 2187 | 2187 |
if (local_is) {
|
| 2188 | 2188 |
delete _is; |
| 2189 | 2189 |
} |
| 2190 | 2190 |
|
| 2191 | 2191 |
} |
| 2192 | 2192 |
|
| 2193 | 2193 |
private: |
| 2194 | 2194 |
|
| 2195 | 2195 |
friend SectionReader sectionReader(std::istream& is); |
| 2196 | 2196 |
friend SectionReader sectionReader(const std::string& fn); |
| 2197 | 2197 |
friend SectionReader sectionReader(const char* fn); |
| 2198 | 2198 |
|
| 2199 | 2199 |
SectionReader(SectionReader& other) |
| 2200 | 2200 |
: _is(other._is), local_is(other.local_is) {
|
| 2201 | 2201 |
|
| 2202 | 2202 |
other._is = 0; |
| 2203 | 2203 |
other.local_is = false; |
| 2204 | 2204 |
|
| 2205 | 2205 |
_sections.swap(other._sections); |
| 2206 | 2206 |
} |
| 2207 | 2207 |
|
| 2208 | 2208 |
SectionReader& operator=(const SectionReader&); |
| 2209 | 2209 |
|
| 2210 | 2210 |
public: |
| 2211 | 2211 |
|
| 2212 |
/// \name Section |
|
| 2212 |
/// \name Section Readers |
|
| 2213 | 2213 |
/// @{
|
| 2214 | 2214 |
|
| 2215 | 2215 |
/// \brief Add a section processor with line oriented reading |
| 2216 | 2216 |
/// |
| 2217 | 2217 |
/// The first parameter is the type descriptor of the section, the |
| 2218 | 2218 |
/// second is a functor, which takes just one \c std::string |
| 2219 | 2219 |
/// parameter. At the reading process, each line of the section |
| 2220 | 2220 |
/// will be given to the functor object. However, the empty lines |
| 2221 | 2221 |
/// and the comment lines are filtered out, and the leading |
| 2222 | 2222 |
/// whitespaces are trimmed from each processed string. |
| 2223 | 2223 |
/// |
| 2224 | 2224 |
/// For example let's see a section, which contain several |
| 2225 | 2225 |
/// integers, which should be inserted into a vector. |
| 2226 | 2226 |
///\code |
| 2227 | 2227 |
/// @numbers |
| 2228 | 2228 |
/// 12 45 23 |
| 2229 | 2229 |
/// 4 |
| 2230 | 2230 |
/// 23 6 |
| 2231 | 2231 |
///\endcode |
| 2232 | 2232 |
/// |
| 2233 | 2233 |
/// The functor is implemented as a struct: |
| 2234 | 2234 |
///\code |
| 2235 | 2235 |
/// struct NumberSection {
|
| 2236 | 2236 |
/// std::vector<int>& _data; |
| 2237 | 2237 |
/// NumberSection(std::vector<int>& data) : _data(data) {}
|
| 2238 | 2238 |
/// void operator()(const std::string& line) {
|
| 2239 | 2239 |
/// std::istringstream ls(line); |
| 2240 | 2240 |
/// int value; |
| 2241 | 2241 |
/// while (ls >> value) _data.push_back(value); |
| 2242 | 2242 |
/// } |
| 2243 | 2243 |
/// }; |
| 2244 | 2244 |
/// |
| 2245 | 2245 |
/// // ... |
| 2246 | 2246 |
/// |
| 2247 | 2247 |
/// reader.sectionLines("numbers", NumberSection(vec));
|
| 2248 | 2248 |
///\endcode |
| 2249 | 2249 |
template <typename Functor> |
| 2250 | 2250 |
SectionReader& sectionLines(const std::string& type, Functor functor) {
|
| 2251 | 2251 |
LEMON_ASSERT(!type.empty(), "Type is empty."); |
| 2252 | 2252 |
LEMON_ASSERT(_sections.find(type) == _sections.end(), |
| 2253 | 2253 |
"Multiple reading of section."); |
| 2254 | 2254 |
_sections.insert(std::make_pair(type, |
| 2255 | 2255 |
new _reader_bits::LineSection<Functor>(functor))); |
| 2256 | 2256 |
return *this; |
| 2257 | 2257 |
} |
| 2258 | 2258 |
|
| 2259 | 2259 |
|
| 2260 | 2260 |
/// \brief Add a section processor with stream oriented reading |
| ... | ... |
@@ -2263,97 +2263,97 @@ |
| 2263 | 2263 |
/// a functor, which takes an \c std::istream& and an \c int& |
| 2264 | 2264 |
/// parameter, the latter regard to the line number of stream. The |
| 2265 | 2265 |
/// functor can read the input while the section go on, and the |
| 2266 | 2266 |
/// line number should be modified accordingly. |
| 2267 | 2267 |
template <typename Functor> |
| 2268 | 2268 |
SectionReader& sectionStream(const std::string& type, Functor functor) {
|
| 2269 | 2269 |
LEMON_ASSERT(!type.empty(), "Type is empty."); |
| 2270 | 2270 |
LEMON_ASSERT(_sections.find(type) == _sections.end(), |
| 2271 | 2271 |
"Multiple reading of section."); |
| 2272 | 2272 |
_sections.insert(std::make_pair(type, |
| 2273 | 2273 |
new _reader_bits::StreamSection<Functor>(functor))); |
| 2274 | 2274 |
return *this; |
| 2275 | 2275 |
} |
| 2276 | 2276 |
|
| 2277 | 2277 |
/// @} |
| 2278 | 2278 |
|
| 2279 | 2279 |
private: |
| 2280 | 2280 |
|
| 2281 | 2281 |
bool readLine() {
|
| 2282 | 2282 |
std::string str; |
| 2283 | 2283 |
while(++line_num, std::getline(*_is, str)) {
|
| 2284 | 2284 |
line.clear(); line.str(str); |
| 2285 | 2285 |
char c; |
| 2286 | 2286 |
if (line >> std::ws >> c && c != '#') {
|
| 2287 | 2287 |
line.putback(c); |
| 2288 | 2288 |
return true; |
| 2289 | 2289 |
} |
| 2290 | 2290 |
} |
| 2291 | 2291 |
return false; |
| 2292 | 2292 |
} |
| 2293 | 2293 |
|
| 2294 | 2294 |
bool readSuccess() {
|
| 2295 | 2295 |
return static_cast<bool>(*_is); |
| 2296 | 2296 |
} |
| 2297 | 2297 |
|
| 2298 | 2298 |
void skipSection() {
|
| 2299 | 2299 |
char c; |
| 2300 | 2300 |
while (readSuccess() && line >> c && c != '@') {
|
| 2301 | 2301 |
readLine(); |
| 2302 | 2302 |
} |
| 2303 | 2303 |
if (readSuccess()) {
|
| 2304 | 2304 |
line.putback(c); |
| 2305 | 2305 |
} |
| 2306 | 2306 |
} |
| 2307 | 2307 |
|
| 2308 | 2308 |
public: |
| 2309 | 2309 |
|
| 2310 | 2310 |
|
| 2311 |
/// \name Execution of the |
|
| 2311 |
/// \name Execution of the Reader |
|
| 2312 | 2312 |
/// @{
|
| 2313 | 2313 |
|
| 2314 | 2314 |
/// \brief Start the batch processing |
| 2315 | 2315 |
/// |
| 2316 | 2316 |
/// This function starts the batch processing. |
| 2317 | 2317 |
void run() {
|
| 2318 | 2318 |
|
| 2319 | 2319 |
LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); |
| 2320 | 2320 |
|
| 2321 | 2321 |
std::set<std::string> extra_sections; |
| 2322 | 2322 |
|
| 2323 | 2323 |
line_num = 0; |
| 2324 | 2324 |
readLine(); |
| 2325 | 2325 |
skipSection(); |
| 2326 | 2326 |
|
| 2327 | 2327 |
while (readSuccess()) {
|
| 2328 | 2328 |
try {
|
| 2329 | 2329 |
char c; |
| 2330 | 2330 |
std::string section, caption; |
| 2331 | 2331 |
line >> c; |
| 2332 | 2332 |
_reader_bits::readToken(line, section); |
| 2333 | 2333 |
_reader_bits::readToken(line, caption); |
| 2334 | 2334 |
|
| 2335 | 2335 |
if (line >> c) |
| 2336 | 2336 |
throw FormatError("Extra character at the end of line");
|
| 2337 | 2337 |
|
| 2338 | 2338 |
if (extra_sections.find(section) != extra_sections.end()) {
|
| 2339 | 2339 |
std::ostringstream msg; |
| 2340 | 2340 |
msg << "Multiple occurence of section: " << section; |
| 2341 | 2341 |
throw FormatError(msg.str()); |
| 2342 | 2342 |
} |
| 2343 | 2343 |
Sections::iterator it = _sections.find(section); |
| 2344 | 2344 |
if (it != _sections.end()) {
|
| 2345 | 2345 |
extra_sections.insert(section); |
| 2346 | 2346 |
it->second->process(*_is, line_num); |
| 2347 | 2347 |
} |
| 2348 | 2348 |
readLine(); |
| 2349 | 2349 |
skipSection(); |
| 2350 | 2350 |
} catch (FormatError& error) {
|
| 2351 | 2351 |
error.line(line_num); |
| 2352 | 2352 |
error.file(_filename); |
| 2353 | 2353 |
throw; |
| 2354 | 2354 |
} |
| 2355 | 2355 |
} |
| 2356 | 2356 |
for (Sections::iterator it = _sections.begin(); |
| 2357 | 2357 |
it != _sections.end(); ++it) {
|
| 2358 | 2358 |
if (extra_sections.find(it->first) == extra_sections.end()) {
|
| 2359 | 2359 |
std::ostringstream os; |
| ... | ... |
@@ -2455,282 +2455,282 @@ |
| 2455 | 2455 |
std::istringstream line; |
| 2456 | 2456 |
|
| 2457 | 2457 |
public: |
| 2458 | 2458 |
|
| 2459 | 2459 |
/// \brief Constructor |
| 2460 | 2460 |
/// |
| 2461 | 2461 |
/// Construct an \e LGF contents reader, which reads from the given |
| 2462 | 2462 |
/// input stream. |
| 2463 | 2463 |
LgfContents(std::istream& is) |
| 2464 | 2464 |
: _is(&is), local_is(false) {}
|
| 2465 | 2465 |
|
| 2466 | 2466 |
/// \brief Constructor |
| 2467 | 2467 |
/// |
| 2468 | 2468 |
/// Construct an \e LGF contents reader, which reads from the given |
| 2469 | 2469 |
/// file. |
| 2470 | 2470 |
LgfContents(const std::string& fn) |
| 2471 | 2471 |
: _is(new std::ifstream(fn.c_str())), local_is(true) {
|
| 2472 | 2472 |
if (!(*_is)) {
|
| 2473 | 2473 |
delete _is; |
| 2474 | 2474 |
throw IoError("Cannot open file", fn);
|
| 2475 | 2475 |
} |
| 2476 | 2476 |
} |
| 2477 | 2477 |
|
| 2478 | 2478 |
/// \brief Constructor |
| 2479 | 2479 |
/// |
| 2480 | 2480 |
/// Construct an \e LGF contents reader, which reads from the given |
| 2481 | 2481 |
/// file. |
| 2482 | 2482 |
LgfContents(const char* fn) |
| 2483 | 2483 |
: _is(new std::ifstream(fn)), local_is(true) {
|
| 2484 | 2484 |
if (!(*_is)) {
|
| 2485 | 2485 |
delete _is; |
| 2486 | 2486 |
throw IoError("Cannot open file", fn);
|
| 2487 | 2487 |
} |
| 2488 | 2488 |
} |
| 2489 | 2489 |
|
| 2490 | 2490 |
/// \brief Destructor |
| 2491 | 2491 |
~LgfContents() {
|
| 2492 | 2492 |
if (local_is) delete _is; |
| 2493 | 2493 |
} |
| 2494 | 2494 |
|
| 2495 | 2495 |
private: |
| 2496 | 2496 |
|
| 2497 | 2497 |
LgfContents(const LgfContents&); |
| 2498 | 2498 |
LgfContents& operator=(const LgfContents&); |
| 2499 | 2499 |
|
| 2500 | 2500 |
public: |
| 2501 | 2501 |
|
| 2502 | 2502 |
|
| 2503 |
/// \name Node |
|
| 2503 |
/// \name Node Sections |
|
| 2504 | 2504 |
/// @{
|
| 2505 | 2505 |
|
| 2506 | 2506 |
/// \brief Gives back the number of node sections in the file. |
| 2507 | 2507 |
/// |
| 2508 | 2508 |
/// Gives back the number of node sections in the file. |
| 2509 | 2509 |
int nodeSectionNum() const {
|
| 2510 | 2510 |
return _node_sections.size(); |
| 2511 | 2511 |
} |
| 2512 | 2512 |
|
| 2513 | 2513 |
/// \brief Returns the node section name at the given position. |
| 2514 | 2514 |
/// |
| 2515 | 2515 |
/// Returns the node section name at the given position. |
| 2516 | 2516 |
const std::string& nodeSection(int i) const {
|
| 2517 | 2517 |
return _node_sections[i]; |
| 2518 | 2518 |
} |
| 2519 | 2519 |
|
| 2520 | 2520 |
/// \brief Gives back the node maps for the given section. |
| 2521 | 2521 |
/// |
| 2522 | 2522 |
/// Gives back the node maps for the given section. |
| 2523 | 2523 |
const std::vector<std::string>& nodeMapNames(int i) const {
|
| 2524 | 2524 |
return _node_maps[i]; |
| 2525 | 2525 |
} |
| 2526 | 2526 |
|
| 2527 | 2527 |
/// @} |
| 2528 | 2528 |
|
| 2529 |
/// \name Arc/Edge |
|
| 2529 |
/// \name Arc/Edge Sections |
|
| 2530 | 2530 |
/// @{
|
| 2531 | 2531 |
|
| 2532 | 2532 |
/// \brief Gives back the number of arc/edge sections in the file. |
| 2533 | 2533 |
/// |
| 2534 | 2534 |
/// Gives back the number of arc/edge sections in the file. |
| 2535 | 2535 |
/// \note It is synonym of \c edgeSectionNum(). |
| 2536 | 2536 |
int arcSectionNum() const {
|
| 2537 | 2537 |
return _edge_sections.size(); |
| 2538 | 2538 |
} |
| 2539 | 2539 |
|
| 2540 | 2540 |
/// \brief Returns the arc/edge section name at the given position. |
| 2541 | 2541 |
/// |
| 2542 | 2542 |
/// Returns the arc/edge section name at the given position. |
| 2543 | 2543 |
/// \note It is synonym of \c edgeSection(). |
| 2544 | 2544 |
const std::string& arcSection(int i) const {
|
| 2545 | 2545 |
return _edge_sections[i]; |
| 2546 | 2546 |
} |
| 2547 | 2547 |
|
| 2548 | 2548 |
/// \brief Gives back the arc/edge maps for the given section. |
| 2549 | 2549 |
/// |
| 2550 | 2550 |
/// Gives back the arc/edge maps for the given section. |
| 2551 | 2551 |
/// \note It is synonym of \c edgeMapNames(). |
| 2552 | 2552 |
const std::vector<std::string>& arcMapNames(int i) const {
|
| 2553 | 2553 |
return _edge_maps[i]; |
| 2554 | 2554 |
} |
| 2555 | 2555 |
|
| 2556 | 2556 |
/// @} |
| 2557 | 2557 |
|
| 2558 | 2558 |
/// \name Synonyms |
| 2559 | 2559 |
/// @{
|
| 2560 | 2560 |
|
| 2561 | 2561 |
/// \brief Gives back the number of arc/edge sections in the file. |
| 2562 | 2562 |
/// |
| 2563 | 2563 |
/// Gives back the number of arc/edge sections in the file. |
| 2564 | 2564 |
/// \note It is synonym of \c arcSectionNum(). |
| 2565 | 2565 |
int edgeSectionNum() const {
|
| 2566 | 2566 |
return _edge_sections.size(); |
| 2567 | 2567 |
} |
| 2568 | 2568 |
|
| 2569 | 2569 |
/// \brief Returns the section name at the given position. |
| 2570 | 2570 |
/// |
| 2571 | 2571 |
/// Returns the section name at the given position. |
| 2572 | 2572 |
/// \note It is synonym of \c arcSection(). |
| 2573 | 2573 |
const std::string& edgeSection(int i) const {
|
| 2574 | 2574 |
return _edge_sections[i]; |
| 2575 | 2575 |
} |
| 2576 | 2576 |
|
| 2577 | 2577 |
/// \brief Gives back the edge maps for the given section. |
| 2578 | 2578 |
/// |
| 2579 | 2579 |
/// Gives back the edge maps for the given section. |
| 2580 | 2580 |
/// \note It is synonym of \c arcMapNames(). |
| 2581 | 2581 |
const std::vector<std::string>& edgeMapNames(int i) const {
|
| 2582 | 2582 |
return _edge_maps[i]; |
| 2583 | 2583 |
} |
| 2584 | 2584 |
|
| 2585 | 2585 |
/// @} |
| 2586 | 2586 |
|
| 2587 |
/// \name Attribute |
|
| 2587 |
/// \name Attribute Sections |
|
| 2588 | 2588 |
/// @{
|
| 2589 | 2589 |
|
| 2590 | 2590 |
/// \brief Gives back the number of attribute sections in the file. |
| 2591 | 2591 |
/// |
| 2592 | 2592 |
/// Gives back the number of attribute sections in the file. |
| 2593 | 2593 |
int attributeSectionNum() const {
|
| 2594 | 2594 |
return _attribute_sections.size(); |
| 2595 | 2595 |
} |
| 2596 | 2596 |
|
| 2597 | 2597 |
/// \brief Returns the attribute section name at the given position. |
| 2598 | 2598 |
/// |
| 2599 | 2599 |
/// Returns the attribute section name at the given position. |
| 2600 | 2600 |
const std::string& attributeSectionNames(int i) const {
|
| 2601 | 2601 |
return _attribute_sections[i]; |
| 2602 | 2602 |
} |
| 2603 | 2603 |
|
| 2604 | 2604 |
/// \brief Gives back the attributes for the given section. |
| 2605 | 2605 |
/// |
| 2606 | 2606 |
/// Gives back the attributes for the given section. |
| 2607 | 2607 |
const std::vector<std::string>& attributes(int i) const {
|
| 2608 | 2608 |
return _attributes[i]; |
| 2609 | 2609 |
} |
| 2610 | 2610 |
|
| 2611 | 2611 |
/// @} |
| 2612 | 2612 |
|
| 2613 |
/// \name Extra |
|
| 2613 |
/// \name Extra Sections |
|
| 2614 | 2614 |
/// @{
|
| 2615 | 2615 |
|
| 2616 | 2616 |
/// \brief Gives back the number of extra sections in the file. |
| 2617 | 2617 |
/// |
| 2618 | 2618 |
/// Gives back the number of extra sections in the file. |
| 2619 | 2619 |
int extraSectionNum() const {
|
| 2620 | 2620 |
return _extra_sections.size(); |
| 2621 | 2621 |
} |
| 2622 | 2622 |
|
| 2623 | 2623 |
/// \brief Returns the extra section type at the given position. |
| 2624 | 2624 |
/// |
| 2625 | 2625 |
/// Returns the section type at the given position. |
| 2626 | 2626 |
const std::string& extraSection(int i) const {
|
| 2627 | 2627 |
return _extra_sections[i]; |
| 2628 | 2628 |
} |
| 2629 | 2629 |
|
| 2630 | 2630 |
/// @} |
| 2631 | 2631 |
|
| 2632 | 2632 |
private: |
| 2633 | 2633 |
|
| 2634 | 2634 |
bool readLine() {
|
| 2635 | 2635 |
std::string str; |
| 2636 | 2636 |
while(++line_num, std::getline(*_is, str)) {
|
| 2637 | 2637 |
line.clear(); line.str(str); |
| 2638 | 2638 |
char c; |
| 2639 | 2639 |
if (line >> std::ws >> c && c != '#') {
|
| 2640 | 2640 |
line.putback(c); |
| 2641 | 2641 |
return true; |
| 2642 | 2642 |
} |
| 2643 | 2643 |
} |
| 2644 | 2644 |
return false; |
| 2645 | 2645 |
} |
| 2646 | 2646 |
|
| 2647 | 2647 |
bool readSuccess() {
|
| 2648 | 2648 |
return static_cast<bool>(*_is); |
| 2649 | 2649 |
} |
| 2650 | 2650 |
|
| 2651 | 2651 |
void skipSection() {
|
| 2652 | 2652 |
char c; |
| 2653 | 2653 |
while (readSuccess() && line >> c && c != '@') {
|
| 2654 | 2654 |
readLine(); |
| 2655 | 2655 |
} |
| 2656 | 2656 |
if (readSuccess()) {
|
| 2657 | 2657 |
line.putback(c); |
| 2658 | 2658 |
} |
| 2659 | 2659 |
} |
| 2660 | 2660 |
|
| 2661 | 2661 |
void readMaps(std::vector<std::string>& maps) {
|
| 2662 | 2662 |
char c; |
| 2663 | 2663 |
if (!readLine() || !(line >> c) || c == '@') {
|
| 2664 | 2664 |
if (readSuccess() && line) line.putback(c); |
| 2665 | 2665 |
return; |
| 2666 | 2666 |
} |
| 2667 | 2667 |
line.putback(c); |
| 2668 | 2668 |
std::string map; |
| 2669 | 2669 |
while (_reader_bits::readToken(line, map)) {
|
| 2670 | 2670 |
maps.push_back(map); |
| 2671 | 2671 |
} |
| 2672 | 2672 |
} |
| 2673 | 2673 |
|
| 2674 | 2674 |
void readAttributes(std::vector<std::string>& attrs) {
|
| 2675 | 2675 |
readLine(); |
| 2676 | 2676 |
char c; |
| 2677 | 2677 |
while (readSuccess() && line >> c && c != '@') {
|
| 2678 | 2678 |
line.putback(c); |
| 2679 | 2679 |
std::string attr; |
| 2680 | 2680 |
_reader_bits::readToken(line, attr); |
| 2681 | 2681 |
attrs.push_back(attr); |
| 2682 | 2682 |
readLine(); |
| 2683 | 2683 |
} |
| 2684 | 2684 |
line.putback(c); |
| 2685 | 2685 |
} |
| 2686 | 2686 |
|
| 2687 | 2687 |
public: |
| 2688 | 2688 |
|
| 2689 |
/// \name Execution of the |
|
| 2689 |
/// \name Execution of the Contents Reader |
|
| 2690 | 2690 |
/// @{
|
| 2691 | 2691 |
|
| 2692 | 2692 |
/// \brief Starts the reading |
| 2693 | 2693 |
/// |
| 2694 | 2694 |
/// This function starts the reading. |
| 2695 | 2695 |
void run() {
|
| 2696 | 2696 |
|
| 2697 | 2697 |
readLine(); |
| 2698 | 2698 |
skipSection(); |
| 2699 | 2699 |
|
| 2700 | 2700 |
while (readSuccess()) {
|
| 2701 | 2701 |
|
| 2702 | 2702 |
char c; |
| 2703 | 2703 |
line >> c; |
| 2704 | 2704 |
|
| 2705 | 2705 |
std::string section, caption; |
| 2706 | 2706 |
_reader_bits::readToken(line, section); |
| 2707 | 2707 |
_reader_bits::readToken(line, caption); |
| 2708 | 2708 |
|
| 2709 | 2709 |
if (section == "nodes") {
|
| 2710 | 2710 |
_node_sections.push_back(caption); |
| 2711 | 2711 |
_node_maps.push_back(std::vector<std::string>()); |
| 2712 | 2712 |
readMaps(_node_maps.back()); |
| 2713 | 2713 |
readLine(); skipSection(); |
| 2714 | 2714 |
} else if (section == "arcs" || section == "edges") {
|
| 2715 | 2715 |
_edge_sections.push_back(caption); |
| 2716 | 2716 |
_arc_sections.push_back(section == "arcs"); |
| 2717 | 2717 |
_edge_maps.push_back(std::vector<std::string>()); |
| 2718 | 2718 |
readMaps(_edge_maps.back()); |
| 2719 | 2719 |
readLine(); skipSection(); |
| 2720 | 2720 |
} else if (section == "attributes") {
|
| 2721 | 2721 |
_attribute_sections.push_back(caption); |
| 2722 | 2722 |
_attributes.push_back(std::vector<std::string>()); |
| 2723 | 2723 |
readAttributes(_attributes.back()); |
| 2724 | 2724 |
} else {
|
| 2725 | 2725 |
_extra_sections.push_back(section); |
| 2726 | 2726 |
readLine(); skipSection(); |
| 2727 | 2727 |
} |
| 2728 | 2728 |
} |
| 2729 | 2729 |
} |
| 2730 | 2730 |
|
| 2731 | 2731 |
/// @} |
| 2732 | 2732 |
|
| 2733 | 2733 |
}; |
| 2734 | 2734 |
} |
| 2735 | 2735 |
|
| 2736 | 2736 |
#endif |
| ... | ... |
@@ -491,97 +491,97 @@ |
| 491 | 491 |
delete it->second; |
| 492 | 492 |
} |
| 493 | 493 |
|
| 494 | 494 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 495 | 495 |
it != _attributes.end(); ++it) {
|
| 496 | 496 |
delete it->second; |
| 497 | 497 |
} |
| 498 | 498 |
|
| 499 | 499 |
if (local_os) {
|
| 500 | 500 |
delete _os; |
| 501 | 501 |
} |
| 502 | 502 |
} |
| 503 | 503 |
|
| 504 | 504 |
private: |
| 505 | 505 |
|
| 506 | 506 |
template <typename TDGR> |
| 507 | 507 |
friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
| 508 | 508 |
std::ostream& os); |
| 509 | 509 |
template <typename TDGR> |
| 510 | 510 |
friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
| 511 | 511 |
const std::string& fn); |
| 512 | 512 |
template <typename TDGR> |
| 513 | 513 |
friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, |
| 514 | 514 |
const char *fn); |
| 515 | 515 |
|
| 516 | 516 |
DigraphWriter(DigraphWriter& other) |
| 517 | 517 |
: _os(other._os), local_os(other.local_os), _digraph(other._digraph), |
| 518 | 518 |
_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
|
| 519 | 519 |
|
| 520 | 520 |
other._os = 0; |
| 521 | 521 |
other.local_os = false; |
| 522 | 522 |
|
| 523 | 523 |
_node_index.swap(other._node_index); |
| 524 | 524 |
_arc_index.swap(other._arc_index); |
| 525 | 525 |
|
| 526 | 526 |
_node_maps.swap(other._node_maps); |
| 527 | 527 |
_arc_maps.swap(other._arc_maps); |
| 528 | 528 |
_attributes.swap(other._attributes); |
| 529 | 529 |
|
| 530 | 530 |
_nodes_caption = other._nodes_caption; |
| 531 | 531 |
_arcs_caption = other._arcs_caption; |
| 532 | 532 |
_attributes_caption = other._attributes_caption; |
| 533 | 533 |
} |
| 534 | 534 |
|
| 535 | 535 |
DigraphWriter& operator=(const DigraphWriter&); |
| 536 | 536 |
|
| 537 | 537 |
public: |
| 538 | 538 |
|
| 539 |
/// \name Writing |
|
| 539 |
/// \name Writing Rules |
|
| 540 | 540 |
/// @{
|
| 541 | 541 |
|
| 542 | 542 |
/// \brief Node map writing rule |
| 543 | 543 |
/// |
| 544 | 544 |
/// Add a node map writing rule to the writer. |
| 545 | 545 |
template <typename Map> |
| 546 | 546 |
DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
|
| 547 | 547 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 548 | 548 |
_writer_bits::MapStorageBase<Node>* storage = |
| 549 | 549 |
new _writer_bits::MapStorage<Node, Map>(map); |
| 550 | 550 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 551 | 551 |
return *this; |
| 552 | 552 |
} |
| 553 | 553 |
|
| 554 | 554 |
/// \brief Node map writing rule |
| 555 | 555 |
/// |
| 556 | 556 |
/// Add a node map writing rule with specialized converter to the |
| 557 | 557 |
/// writer. |
| 558 | 558 |
template <typename Map, typename Converter> |
| 559 | 559 |
DigraphWriter& nodeMap(const std::string& caption, const Map& map, |
| 560 | 560 |
const Converter& converter = Converter()) {
|
| 561 | 561 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 562 | 562 |
_writer_bits::MapStorageBase<Node>* storage = |
| 563 | 563 |
new _writer_bits::MapStorage<Node, Map, Converter>(map, converter); |
| 564 | 564 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 565 | 565 |
return *this; |
| 566 | 566 |
} |
| 567 | 567 |
|
| 568 | 568 |
/// \brief Arc map writing rule |
| 569 | 569 |
/// |
| 570 | 570 |
/// Add an arc map writing rule to the writer. |
| 571 | 571 |
template <typename Map> |
| 572 | 572 |
DigraphWriter& arcMap(const std::string& caption, const Map& map) {
|
| 573 | 573 |
checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); |
| 574 | 574 |
_writer_bits::MapStorageBase<Arc>* storage = |
| 575 | 575 |
new _writer_bits::MapStorage<Arc, Map>(map); |
| 576 | 576 |
_arc_maps.push_back(std::make_pair(caption, storage)); |
| 577 | 577 |
return *this; |
| 578 | 578 |
} |
| 579 | 579 |
|
| 580 | 580 |
/// \brief Arc map writing rule |
| 581 | 581 |
/// |
| 582 | 582 |
/// Add an arc map writing rule with specialized converter to the |
| 583 | 583 |
/// writer. |
| 584 | 584 |
template <typename Map, typename Converter> |
| 585 | 585 |
DigraphWriter& arcMap(const std::string& caption, const Map& map, |
| 586 | 586 |
const Converter& converter = Converter()) {
|
| 587 | 587 |
checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); |
| ... | ... |
@@ -594,124 +594,124 @@ |
| 594 | 594 |
/// \brief Attribute writing rule |
| 595 | 595 |
/// |
| 596 | 596 |
/// Add an attribute writing rule to the writer. |
| 597 | 597 |
template <typename Value> |
| 598 | 598 |
DigraphWriter& attribute(const std::string& caption, const Value& value) {
|
| 599 | 599 |
_writer_bits::ValueStorageBase* storage = |
| 600 | 600 |
new _writer_bits::ValueStorage<Value>(value); |
| 601 | 601 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 602 | 602 |
return *this; |
| 603 | 603 |
} |
| 604 | 604 |
|
| 605 | 605 |
/// \brief Attribute writing rule |
| 606 | 606 |
/// |
| 607 | 607 |
/// Add an attribute writing rule with specialized converter to the |
| 608 | 608 |
/// writer. |
| 609 | 609 |
template <typename Value, typename Converter> |
| 610 | 610 |
DigraphWriter& attribute(const std::string& caption, const Value& value, |
| 611 | 611 |
const Converter& converter = Converter()) {
|
| 612 | 612 |
_writer_bits::ValueStorageBase* storage = |
| 613 | 613 |
new _writer_bits::ValueStorage<Value, Converter>(value, converter); |
| 614 | 614 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 615 | 615 |
return *this; |
| 616 | 616 |
} |
| 617 | 617 |
|
| 618 | 618 |
/// \brief Node writing rule |
| 619 | 619 |
/// |
| 620 | 620 |
/// Add a node writing rule to the writer. |
| 621 | 621 |
DigraphWriter& node(const std::string& caption, const Node& node) {
|
| 622 | 622 |
typedef _writer_bits::MapLookUpConverter<Node> Converter; |
| 623 | 623 |
Converter converter(_node_index); |
| 624 | 624 |
_writer_bits::ValueStorageBase* storage = |
| 625 | 625 |
new _writer_bits::ValueStorage<Node, Converter>(node, converter); |
| 626 | 626 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 627 | 627 |
return *this; |
| 628 | 628 |
} |
| 629 | 629 |
|
| 630 | 630 |
/// \brief Arc writing rule |
| 631 | 631 |
/// |
| 632 | 632 |
/// Add an arc writing rule to writer. |
| 633 | 633 |
DigraphWriter& arc(const std::string& caption, const Arc& arc) {
|
| 634 | 634 |
typedef _writer_bits::MapLookUpConverter<Arc> Converter; |
| 635 | 635 |
Converter converter(_arc_index); |
| 636 | 636 |
_writer_bits::ValueStorageBase* storage = |
| 637 | 637 |
new _writer_bits::ValueStorage<Arc, Converter>(arc, converter); |
| 638 | 638 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 639 | 639 |
return *this; |
| 640 | 640 |
} |
| 641 | 641 |
|
| 642 |
/// \name Section |
|
| 642 |
/// \name Section Captions |
|
| 643 | 643 |
/// @{
|
| 644 | 644 |
|
| 645 | 645 |
/// \brief Add an additional caption to the \c \@nodes section |
| 646 | 646 |
/// |
| 647 | 647 |
/// Add an additional caption to the \c \@nodes section. |
| 648 | 648 |
DigraphWriter& nodes(const std::string& caption) {
|
| 649 | 649 |
_nodes_caption = caption; |
| 650 | 650 |
return *this; |
| 651 | 651 |
} |
| 652 | 652 |
|
| 653 | 653 |
/// \brief Add an additional caption to the \c \@arcs section |
| 654 | 654 |
/// |
| 655 | 655 |
/// Add an additional caption to the \c \@arcs section. |
| 656 | 656 |
DigraphWriter& arcs(const std::string& caption) {
|
| 657 | 657 |
_arcs_caption = caption; |
| 658 | 658 |
return *this; |
| 659 | 659 |
} |
| 660 | 660 |
|
| 661 | 661 |
/// \brief Add an additional caption to the \c \@attributes section |
| 662 | 662 |
/// |
| 663 | 663 |
/// Add an additional caption to the \c \@attributes section. |
| 664 | 664 |
DigraphWriter& attributes(const std::string& caption) {
|
| 665 | 665 |
_attributes_caption = caption; |
| 666 | 666 |
return *this; |
| 667 | 667 |
} |
| 668 | 668 |
|
| 669 |
/// \name Skipping |
|
| 669 |
/// \name Skipping Section |
|
| 670 | 670 |
/// @{
|
| 671 | 671 |
|
| 672 | 672 |
/// \brief Skip writing the node set |
| 673 | 673 |
/// |
| 674 | 674 |
/// The \c \@nodes section will not be written to the stream. |
| 675 | 675 |
DigraphWriter& skipNodes() {
|
| 676 | 676 |
LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member"); |
| 677 | 677 |
_skip_nodes = true; |
| 678 | 678 |
return *this; |
| 679 | 679 |
} |
| 680 | 680 |
|
| 681 | 681 |
/// \brief Skip writing arc set |
| 682 | 682 |
/// |
| 683 | 683 |
/// The \c \@arcs section will not be written to the stream. |
| 684 | 684 |
DigraphWriter& skipArcs() {
|
| 685 | 685 |
LEMON_ASSERT(!_skip_arcs, "Multiple usage of skipArcs() member"); |
| 686 | 686 |
_skip_arcs = true; |
| 687 | 687 |
return *this; |
| 688 | 688 |
} |
| 689 | 689 |
|
| 690 | 690 |
/// @} |
| 691 | 691 |
|
| 692 | 692 |
private: |
| 693 | 693 |
|
| 694 | 694 |
void writeNodes() {
|
| 695 | 695 |
_writer_bits::MapStorageBase<Node>* label = 0; |
| 696 | 696 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
| 697 | 697 |
it != _node_maps.end(); ++it) {
|
| 698 | 698 |
if (it->first == "label") {
|
| 699 | 699 |
label = it->second; |
| 700 | 700 |
break; |
| 701 | 701 |
} |
| 702 | 702 |
} |
| 703 | 703 |
|
| 704 | 704 |
*_os << "@nodes"; |
| 705 | 705 |
if (!_nodes_caption.empty()) {
|
| 706 | 706 |
_writer_bits::writeToken(*_os << ' ', _nodes_caption); |
| 707 | 707 |
} |
| 708 | 708 |
*_os << std::endl; |
| 709 | 709 |
|
| 710 | 710 |
if (label == 0) {
|
| 711 | 711 |
*_os << "label" << '\t'; |
| 712 | 712 |
} |
| 713 | 713 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
| 714 | 714 |
it != _node_maps.end(); ++it) {
|
| 715 | 715 |
_writer_bits::writeToken(*_os, it->first) << '\t'; |
| 716 | 716 |
} |
| 717 | 717 |
*_os << std::endl; |
| ... | ... |
@@ -838,97 +838,97 @@ |
| 838 | 838 |
} |
| 839 | 839 |
*_os << '\t'; |
| 840 | 840 |
} |
| 841 | 841 |
*_os << std::endl; |
| 842 | 842 |
} |
| 843 | 843 |
} |
| 844 | 844 |
|
| 845 | 845 |
void createArcIndex() {
|
| 846 | 846 |
_writer_bits::MapStorageBase<Arc>* label = 0; |
| 847 | 847 |
for (typename ArcMaps::iterator it = _arc_maps.begin(); |
| 848 | 848 |
it != _arc_maps.end(); ++it) {
|
| 849 | 849 |
if (it->first == "label") {
|
| 850 | 850 |
label = it->second; |
| 851 | 851 |
break; |
| 852 | 852 |
} |
| 853 | 853 |
} |
| 854 | 854 |
|
| 855 | 855 |
if (label == 0) {
|
| 856 | 856 |
for (ArcIt a(_digraph); a != INVALID; ++a) {
|
| 857 | 857 |
std::ostringstream os; |
| 858 | 858 |
os << _digraph.id(a); |
| 859 | 859 |
_arc_index.insert(std::make_pair(a, os.str())); |
| 860 | 860 |
} |
| 861 | 861 |
} else {
|
| 862 | 862 |
for (ArcIt a(_digraph); a != INVALID; ++a) {
|
| 863 | 863 |
std::string value = label->get(a); |
| 864 | 864 |
_arc_index.insert(std::make_pair(a, value)); |
| 865 | 865 |
} |
| 866 | 866 |
} |
| 867 | 867 |
} |
| 868 | 868 |
|
| 869 | 869 |
void writeAttributes() {
|
| 870 | 870 |
if (_attributes.empty()) return; |
| 871 | 871 |
*_os << "@attributes"; |
| 872 | 872 |
if (!_attributes_caption.empty()) {
|
| 873 | 873 |
_writer_bits::writeToken(*_os << ' ', _attributes_caption); |
| 874 | 874 |
} |
| 875 | 875 |
*_os << std::endl; |
| 876 | 876 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 877 | 877 |
it != _attributes.end(); ++it) {
|
| 878 | 878 |
_writer_bits::writeToken(*_os, it->first) << ' '; |
| 879 | 879 |
_writer_bits::writeToken(*_os, it->second->get()); |
| 880 | 880 |
*_os << std::endl; |
| 881 | 881 |
} |
| 882 | 882 |
} |
| 883 | 883 |
|
| 884 | 884 |
public: |
| 885 | 885 |
|
| 886 |
/// \name Execution of the |
|
| 886 |
/// \name Execution of the Writer |
|
| 887 | 887 |
/// @{
|
| 888 | 888 |
|
| 889 | 889 |
/// \brief Start the batch processing |
| 890 | 890 |
/// |
| 891 | 891 |
/// This function starts the batch processing. |
| 892 | 892 |
void run() {
|
| 893 | 893 |
if (!_skip_nodes) {
|
| 894 | 894 |
writeNodes(); |
| 895 | 895 |
} else {
|
| 896 | 896 |
createNodeIndex(); |
| 897 | 897 |
} |
| 898 | 898 |
if (!_skip_arcs) {
|
| 899 | 899 |
writeArcs(); |
| 900 | 900 |
} else {
|
| 901 | 901 |
createArcIndex(); |
| 902 | 902 |
} |
| 903 | 903 |
writeAttributes(); |
| 904 | 904 |
} |
| 905 | 905 |
|
| 906 | 906 |
/// \brief Give back the stream of the writer |
| 907 | 907 |
/// |
| 908 | 908 |
/// Give back the stream of the writer. |
| 909 | 909 |
std::ostream& ostream() {
|
| 910 | 910 |
return *_os; |
| 911 | 911 |
} |
| 912 | 912 |
|
| 913 | 913 |
/// @} |
| 914 | 914 |
}; |
| 915 | 915 |
|
| 916 | 916 |
/// \ingroup lemon_io |
| 917 | 917 |
/// |
| 918 | 918 |
/// \brief Return a \ref DigraphWriter class |
| 919 | 919 |
/// |
| 920 | 920 |
/// This function just returns a \ref DigraphWriter class. |
| 921 | 921 |
/// |
| 922 | 922 |
/// With this function a digraph can be write to a file or output |
| 923 | 923 |
/// stream in \ref lgf-format "LGF" format with several maps and |
| 924 | 924 |
/// attributes. For example, with the following code a network flow |
| 925 | 925 |
/// problem can be written to the standard output, i.e. a digraph |
| 926 | 926 |
/// with a \e capacity map on the arcs and \e source and \e target |
| 927 | 927 |
/// nodes: |
| 928 | 928 |
/// |
| 929 | 929 |
///\code |
| 930 | 930 |
///ListDigraph digraph; |
| 931 | 931 |
///ListDigraph::ArcMap<int> cap(digraph); |
| 932 | 932 |
///ListDigraph::Node src, trg; |
| 933 | 933 |
/// // Setting the capacity map and source and target nodes |
| 934 | 934 |
///digraphWriter(digraph, std::cout). |
| ... | ... |
@@ -1084,97 +1084,97 @@ |
| 1084 | 1084 |
for (typename EdgeMaps::iterator it = _edge_maps.begin(); |
| 1085 | 1085 |
it != _edge_maps.end(); ++it) {
|
| 1086 | 1086 |
delete it->second; |
| 1087 | 1087 |
} |
| 1088 | 1088 |
|
| 1089 | 1089 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 1090 | 1090 |
it != _attributes.end(); ++it) {
|
| 1091 | 1091 |
delete it->second; |
| 1092 | 1092 |
} |
| 1093 | 1093 |
|
| 1094 | 1094 |
if (local_os) {
|
| 1095 | 1095 |
delete _os; |
| 1096 | 1096 |
} |
| 1097 | 1097 |
} |
| 1098 | 1098 |
|
| 1099 | 1099 |
private: |
| 1100 | 1100 |
|
| 1101 | 1101 |
template <typename TGR> |
| 1102 | 1102 |
friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os); |
| 1103 | 1103 |
template <typename TGR> |
| 1104 | 1104 |
friend GraphWriter<TGR> graphWriter(const TGR& graph, |
| 1105 | 1105 |
const std::string& fn); |
| 1106 | 1106 |
template <typename TGR> |
| 1107 | 1107 |
friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn); |
| 1108 | 1108 |
|
| 1109 | 1109 |
GraphWriter(GraphWriter& other) |
| 1110 | 1110 |
: _os(other._os), local_os(other.local_os), _graph(other._graph), |
| 1111 | 1111 |
_skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
|
| 1112 | 1112 |
|
| 1113 | 1113 |
other._os = 0; |
| 1114 | 1114 |
other.local_os = false; |
| 1115 | 1115 |
|
| 1116 | 1116 |
_node_index.swap(other._node_index); |
| 1117 | 1117 |
_edge_index.swap(other._edge_index); |
| 1118 | 1118 |
|
| 1119 | 1119 |
_node_maps.swap(other._node_maps); |
| 1120 | 1120 |
_edge_maps.swap(other._edge_maps); |
| 1121 | 1121 |
_attributes.swap(other._attributes); |
| 1122 | 1122 |
|
| 1123 | 1123 |
_nodes_caption = other._nodes_caption; |
| 1124 | 1124 |
_edges_caption = other._edges_caption; |
| 1125 | 1125 |
_attributes_caption = other._attributes_caption; |
| 1126 | 1126 |
} |
| 1127 | 1127 |
|
| 1128 | 1128 |
GraphWriter& operator=(const GraphWriter&); |
| 1129 | 1129 |
|
| 1130 | 1130 |
public: |
| 1131 | 1131 |
|
| 1132 |
/// \name Writing |
|
| 1132 |
/// \name Writing Rules |
|
| 1133 | 1133 |
/// @{
|
| 1134 | 1134 |
|
| 1135 | 1135 |
/// \brief Node map writing rule |
| 1136 | 1136 |
/// |
| 1137 | 1137 |
/// Add a node map writing rule to the writer. |
| 1138 | 1138 |
template <typename Map> |
| 1139 | 1139 |
GraphWriter& nodeMap(const std::string& caption, const Map& map) {
|
| 1140 | 1140 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 1141 | 1141 |
_writer_bits::MapStorageBase<Node>* storage = |
| 1142 | 1142 |
new _writer_bits::MapStorage<Node, Map>(map); |
| 1143 | 1143 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 1144 | 1144 |
return *this; |
| 1145 | 1145 |
} |
| 1146 | 1146 |
|
| 1147 | 1147 |
/// \brief Node map writing rule |
| 1148 | 1148 |
/// |
| 1149 | 1149 |
/// Add a node map writing rule with specialized converter to the |
| 1150 | 1150 |
/// writer. |
| 1151 | 1151 |
template <typename Map, typename Converter> |
| 1152 | 1152 |
GraphWriter& nodeMap(const std::string& caption, const Map& map, |
| 1153 | 1153 |
const Converter& converter = Converter()) {
|
| 1154 | 1154 |
checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); |
| 1155 | 1155 |
_writer_bits::MapStorageBase<Node>* storage = |
| 1156 | 1156 |
new _writer_bits::MapStorage<Node, Map, Converter>(map, converter); |
| 1157 | 1157 |
_node_maps.push_back(std::make_pair(caption, storage)); |
| 1158 | 1158 |
return *this; |
| 1159 | 1159 |
} |
| 1160 | 1160 |
|
| 1161 | 1161 |
/// \brief Edge map writing rule |
| 1162 | 1162 |
/// |
| 1163 | 1163 |
/// Add an edge map writing rule to the writer. |
| 1164 | 1164 |
template <typename Map> |
| 1165 | 1165 |
GraphWriter& edgeMap(const std::string& caption, const Map& map) {
|
| 1166 | 1166 |
checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>(); |
| 1167 | 1167 |
_writer_bits::MapStorageBase<Edge>* storage = |
| 1168 | 1168 |
new _writer_bits::MapStorage<Edge, Map>(map); |
| 1169 | 1169 |
_edge_maps.push_back(std::make_pair(caption, storage)); |
| 1170 | 1170 |
return *this; |
| 1171 | 1171 |
} |
| 1172 | 1172 |
|
| 1173 | 1173 |
/// \brief Edge map writing rule |
| 1174 | 1174 |
/// |
| 1175 | 1175 |
/// Add an edge map writing rule with specialized converter to the |
| 1176 | 1176 |
/// writer. |
| 1177 | 1177 |
template <typename Map, typename Converter> |
| 1178 | 1178 |
GraphWriter& edgeMap(const std::string& caption, const Map& map, |
| 1179 | 1179 |
const Converter& converter = Converter()) {
|
| 1180 | 1180 |
checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>(); |
| ... | ... |
@@ -1233,124 +1233,124 @@ |
| 1233 | 1233 |
/// |
| 1234 | 1234 |
/// Add an attribute writing rule with specialized converter to the |
| 1235 | 1235 |
/// writer. |
| 1236 | 1236 |
template <typename Value, typename Converter> |
| 1237 | 1237 |
GraphWriter& attribute(const std::string& caption, const Value& value, |
| 1238 | 1238 |
const Converter& converter = Converter()) {
|
| 1239 | 1239 |
_writer_bits::ValueStorageBase* storage = |
| 1240 | 1240 |
new _writer_bits::ValueStorage<Value, Converter>(value, converter); |
| 1241 | 1241 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 1242 | 1242 |
return *this; |
| 1243 | 1243 |
} |
| 1244 | 1244 |
|
| 1245 | 1245 |
/// \brief Node writing rule |
| 1246 | 1246 |
/// |
| 1247 | 1247 |
/// Add a node writing rule to the writer. |
| 1248 | 1248 |
GraphWriter& node(const std::string& caption, const Node& node) {
|
| 1249 | 1249 |
typedef _writer_bits::MapLookUpConverter<Node> Converter; |
| 1250 | 1250 |
Converter converter(_node_index); |
| 1251 | 1251 |
_writer_bits::ValueStorageBase* storage = |
| 1252 | 1252 |
new _writer_bits::ValueStorage<Node, Converter>(node, converter); |
| 1253 | 1253 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 1254 | 1254 |
return *this; |
| 1255 | 1255 |
} |
| 1256 | 1256 |
|
| 1257 | 1257 |
/// \brief Edge writing rule |
| 1258 | 1258 |
/// |
| 1259 | 1259 |
/// Add an edge writing rule to writer. |
| 1260 | 1260 |
GraphWriter& edge(const std::string& caption, const Edge& edge) {
|
| 1261 | 1261 |
typedef _writer_bits::MapLookUpConverter<Edge> Converter; |
| 1262 | 1262 |
Converter converter(_edge_index); |
| 1263 | 1263 |
_writer_bits::ValueStorageBase* storage = |
| 1264 | 1264 |
new _writer_bits::ValueStorage<Edge, Converter>(edge, converter); |
| 1265 | 1265 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 1266 | 1266 |
return *this; |
| 1267 | 1267 |
} |
| 1268 | 1268 |
|
| 1269 | 1269 |
/// \brief Arc writing rule |
| 1270 | 1270 |
/// |
| 1271 | 1271 |
/// Add an arc writing rule to writer. |
| 1272 | 1272 |
GraphWriter& arc(const std::string& caption, const Arc& arc) {
|
| 1273 | 1273 |
typedef _writer_bits::GraphArcLookUpConverter<GR> Converter; |
| 1274 | 1274 |
Converter converter(_graph, _edge_index); |
| 1275 | 1275 |
_writer_bits::ValueStorageBase* storage = |
| 1276 | 1276 |
new _writer_bits::ValueStorage<Arc, Converter>(arc, converter); |
| 1277 | 1277 |
_attributes.push_back(std::make_pair(caption, storage)); |
| 1278 | 1278 |
return *this; |
| 1279 | 1279 |
} |
| 1280 | 1280 |
|
| 1281 |
/// \name Section |
|
| 1281 |
/// \name Section Captions |
|
| 1282 | 1282 |
/// @{
|
| 1283 | 1283 |
|
| 1284 | 1284 |
/// \brief Add an additional caption to the \c \@nodes section |
| 1285 | 1285 |
/// |
| 1286 | 1286 |
/// Add an additional caption to the \c \@nodes section. |
| 1287 | 1287 |
GraphWriter& nodes(const std::string& caption) {
|
| 1288 | 1288 |
_nodes_caption = caption; |
| 1289 | 1289 |
return *this; |
| 1290 | 1290 |
} |
| 1291 | 1291 |
|
| 1292 | 1292 |
/// \brief Add an additional caption to the \c \@arcs section |
| 1293 | 1293 |
/// |
| 1294 | 1294 |
/// Add an additional caption to the \c \@arcs section. |
| 1295 | 1295 |
GraphWriter& edges(const std::string& caption) {
|
| 1296 | 1296 |
_edges_caption = caption; |
| 1297 | 1297 |
return *this; |
| 1298 | 1298 |
} |
| 1299 | 1299 |
|
| 1300 | 1300 |
/// \brief Add an additional caption to the \c \@attributes section |
| 1301 | 1301 |
/// |
| 1302 | 1302 |
/// Add an additional caption to the \c \@attributes section. |
| 1303 | 1303 |
GraphWriter& attributes(const std::string& caption) {
|
| 1304 | 1304 |
_attributes_caption = caption; |
| 1305 | 1305 |
return *this; |
| 1306 | 1306 |
} |
| 1307 | 1307 |
|
| 1308 |
/// \name Skipping |
|
| 1308 |
/// \name Skipping Section |
|
| 1309 | 1309 |
/// @{
|
| 1310 | 1310 |
|
| 1311 | 1311 |
/// \brief Skip writing the node set |
| 1312 | 1312 |
/// |
| 1313 | 1313 |
/// The \c \@nodes section will not be written to the stream. |
| 1314 | 1314 |
GraphWriter& skipNodes() {
|
| 1315 | 1315 |
LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member"); |
| 1316 | 1316 |
_skip_nodes = true; |
| 1317 | 1317 |
return *this; |
| 1318 | 1318 |
} |
| 1319 | 1319 |
|
| 1320 | 1320 |
/// \brief Skip writing edge set |
| 1321 | 1321 |
/// |
| 1322 | 1322 |
/// The \c \@edges section will not be written to the stream. |
| 1323 | 1323 |
GraphWriter& skipEdges() {
|
| 1324 | 1324 |
LEMON_ASSERT(!_skip_edges, "Multiple usage of skipEdges() member"); |
| 1325 | 1325 |
_skip_edges = true; |
| 1326 | 1326 |
return *this; |
| 1327 | 1327 |
} |
| 1328 | 1328 |
|
| 1329 | 1329 |
/// @} |
| 1330 | 1330 |
|
| 1331 | 1331 |
private: |
| 1332 | 1332 |
|
| 1333 | 1333 |
void writeNodes() {
|
| 1334 | 1334 |
_writer_bits::MapStorageBase<Node>* label = 0; |
| 1335 | 1335 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
| 1336 | 1336 |
it != _node_maps.end(); ++it) {
|
| 1337 | 1337 |
if (it->first == "label") {
|
| 1338 | 1338 |
label = it->second; |
| 1339 | 1339 |
break; |
| 1340 | 1340 |
} |
| 1341 | 1341 |
} |
| 1342 | 1342 |
|
| 1343 | 1343 |
*_os << "@nodes"; |
| 1344 | 1344 |
if (!_nodes_caption.empty()) {
|
| 1345 | 1345 |
_writer_bits::writeToken(*_os << ' ', _nodes_caption); |
| 1346 | 1346 |
} |
| 1347 | 1347 |
*_os << std::endl; |
| 1348 | 1348 |
|
| 1349 | 1349 |
if (label == 0) {
|
| 1350 | 1350 |
*_os << "label" << '\t'; |
| 1351 | 1351 |
} |
| 1352 | 1352 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
| 1353 | 1353 |
it != _node_maps.end(); ++it) {
|
| 1354 | 1354 |
_writer_bits::writeToken(*_os, it->first) << '\t'; |
| 1355 | 1355 |
} |
| 1356 | 1356 |
*_os << std::endl; |
| ... | ... |
@@ -1477,97 +1477,97 @@ |
| 1477 | 1477 |
} |
| 1478 | 1478 |
*_os << '\t'; |
| 1479 | 1479 |
} |
| 1480 | 1480 |
*_os << std::endl; |
| 1481 | 1481 |
} |
| 1482 | 1482 |
} |
| 1483 | 1483 |
|
| 1484 | 1484 |
void createEdgeIndex() {
|
| 1485 | 1485 |
_writer_bits::MapStorageBase<Edge>* label = 0; |
| 1486 | 1486 |
for (typename EdgeMaps::iterator it = _edge_maps.begin(); |
| 1487 | 1487 |
it != _edge_maps.end(); ++it) {
|
| 1488 | 1488 |
if (it->first == "label") {
|
| 1489 | 1489 |
label = it->second; |
| 1490 | 1490 |
break; |
| 1491 | 1491 |
} |
| 1492 | 1492 |
} |
| 1493 | 1493 |
|
| 1494 | 1494 |
if (label == 0) {
|
| 1495 | 1495 |
for (EdgeIt e(_graph); e != INVALID; ++e) {
|
| 1496 | 1496 |
std::ostringstream os; |
| 1497 | 1497 |
os << _graph.id(e); |
| 1498 | 1498 |
_edge_index.insert(std::make_pair(e, os.str())); |
| 1499 | 1499 |
} |
| 1500 | 1500 |
} else {
|
| 1501 | 1501 |
for (EdgeIt e(_graph); e != INVALID; ++e) {
|
| 1502 | 1502 |
std::string value = label->get(e); |
| 1503 | 1503 |
_edge_index.insert(std::make_pair(e, value)); |
| 1504 | 1504 |
} |
| 1505 | 1505 |
} |
| 1506 | 1506 |
} |
| 1507 | 1507 |
|
| 1508 | 1508 |
void writeAttributes() {
|
| 1509 | 1509 |
if (_attributes.empty()) return; |
| 1510 | 1510 |
*_os << "@attributes"; |
| 1511 | 1511 |
if (!_attributes_caption.empty()) {
|
| 1512 | 1512 |
_writer_bits::writeToken(*_os << ' ', _attributes_caption); |
| 1513 | 1513 |
} |
| 1514 | 1514 |
*_os << std::endl; |
| 1515 | 1515 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 1516 | 1516 |
it != _attributes.end(); ++it) {
|
| 1517 | 1517 |
_writer_bits::writeToken(*_os, it->first) << ' '; |
| 1518 | 1518 |
_writer_bits::writeToken(*_os, it->second->get()); |
| 1519 | 1519 |
*_os << std::endl; |
| 1520 | 1520 |
} |
| 1521 | 1521 |
} |
| 1522 | 1522 |
|
| 1523 | 1523 |
public: |
| 1524 | 1524 |
|
| 1525 |
/// \name Execution of the |
|
| 1525 |
/// \name Execution of the Writer |
|
| 1526 | 1526 |
/// @{
|
| 1527 | 1527 |
|
| 1528 | 1528 |
/// \brief Start the batch processing |
| 1529 | 1529 |
/// |
| 1530 | 1530 |
/// This function starts the batch processing. |
| 1531 | 1531 |
void run() {
|
| 1532 | 1532 |
if (!_skip_nodes) {
|
| 1533 | 1533 |
writeNodes(); |
| 1534 | 1534 |
} else {
|
| 1535 | 1535 |
createNodeIndex(); |
| 1536 | 1536 |
} |
| 1537 | 1537 |
if (!_skip_edges) {
|
| 1538 | 1538 |
writeEdges(); |
| 1539 | 1539 |
} else {
|
| 1540 | 1540 |
createEdgeIndex(); |
| 1541 | 1541 |
} |
| 1542 | 1542 |
writeAttributes(); |
| 1543 | 1543 |
} |
| 1544 | 1544 |
|
| 1545 | 1545 |
/// \brief Give back the stream of the writer |
| 1546 | 1546 |
/// |
| 1547 | 1547 |
/// Give back the stream of the writer |
| 1548 | 1548 |
std::ostream& ostream() {
|
| 1549 | 1549 |
return *_os; |
| 1550 | 1550 |
} |
| 1551 | 1551 |
|
| 1552 | 1552 |
/// @} |
| 1553 | 1553 |
}; |
| 1554 | 1554 |
|
| 1555 | 1555 |
/// \ingroup lemon_io |
| 1556 | 1556 |
/// |
| 1557 | 1557 |
/// \brief Return a \ref GraphWriter class |
| 1558 | 1558 |
/// |
| 1559 | 1559 |
/// This function just returns a \ref GraphWriter class. |
| 1560 | 1560 |
/// |
| 1561 | 1561 |
/// With this function a graph can be write to a file or output |
| 1562 | 1562 |
/// stream in \ref lgf-format "LGF" format with several maps and |
| 1563 | 1563 |
/// attributes. For example, with the following code a weighted |
| 1564 | 1564 |
/// matching problem can be written to the standard output, i.e. a |
| 1565 | 1565 |
/// graph with a \e weight map on the edges: |
| 1566 | 1566 |
/// |
| 1567 | 1567 |
///\code |
| 1568 | 1568 |
///ListGraph graph; |
| 1569 | 1569 |
///ListGraph::EdgeMap<int> weight(graph); |
| 1570 | 1570 |
/// // Setting the weight map |
| 1571 | 1571 |
///graphWriter(graph, std::cout). |
| 1572 | 1572 |
/// edgeMap("weight", weight).
|
| 1573 | 1573 |
/// run(); |
| ... | ... |
@@ -1654,164 +1654,164 @@ |
| 1654 | 1654 |
delete _os; |
| 1655 | 1655 |
throw IoError("Cannot write file", fn);
|
| 1656 | 1656 |
} |
| 1657 | 1657 |
} |
| 1658 | 1658 |
|
| 1659 | 1659 |
/// \brief Constructor |
| 1660 | 1660 |
/// |
| 1661 | 1661 |
/// Construct a section writer, which writes into the given file. |
| 1662 | 1662 |
SectionWriter(const char* fn) |
| 1663 | 1663 |
: _os(new std::ofstream(fn)), local_os(true) {
|
| 1664 | 1664 |
if (!(*_os)) {
|
| 1665 | 1665 |
delete _os; |
| 1666 | 1666 |
throw IoError("Cannot write file", fn);
|
| 1667 | 1667 |
} |
| 1668 | 1668 |
} |
| 1669 | 1669 |
|
| 1670 | 1670 |
/// \brief Destructor |
| 1671 | 1671 |
~SectionWriter() {
|
| 1672 | 1672 |
for (Sections::iterator it = _sections.begin(); |
| 1673 | 1673 |
it != _sections.end(); ++it) {
|
| 1674 | 1674 |
delete it->second; |
| 1675 | 1675 |
} |
| 1676 | 1676 |
|
| 1677 | 1677 |
if (local_os) {
|
| 1678 | 1678 |
delete _os; |
| 1679 | 1679 |
} |
| 1680 | 1680 |
|
| 1681 | 1681 |
} |
| 1682 | 1682 |
|
| 1683 | 1683 |
private: |
| 1684 | 1684 |
|
| 1685 | 1685 |
friend SectionWriter sectionWriter(std::ostream& os); |
| 1686 | 1686 |
friend SectionWriter sectionWriter(const std::string& fn); |
| 1687 | 1687 |
friend SectionWriter sectionWriter(const char* fn); |
| 1688 | 1688 |
|
| 1689 | 1689 |
SectionWriter(SectionWriter& other) |
| 1690 | 1690 |
: _os(other._os), local_os(other.local_os) {
|
| 1691 | 1691 |
|
| 1692 | 1692 |
other._os = 0; |
| 1693 | 1693 |
other.local_os = false; |
| 1694 | 1694 |
|
| 1695 | 1695 |
_sections.swap(other._sections); |
| 1696 | 1696 |
} |
| 1697 | 1697 |
|
| 1698 | 1698 |
SectionWriter& operator=(const SectionWriter&); |
| 1699 | 1699 |
|
| 1700 | 1700 |
public: |
| 1701 | 1701 |
|
| 1702 |
/// \name Section |
|
| 1702 |
/// \name Section Writers |
|
| 1703 | 1703 |
/// @{
|
| 1704 | 1704 |
|
| 1705 | 1705 |
/// \brief Add a section writer with line oriented writing |
| 1706 | 1706 |
/// |
| 1707 | 1707 |
/// The first parameter is the type descriptor of the section, the |
| 1708 | 1708 |
/// second is a generator with std::string values. At the writing |
| 1709 | 1709 |
/// process, the returned \c std::string will be written into the |
| 1710 | 1710 |
/// output file until it is an empty string. |
| 1711 | 1711 |
/// |
| 1712 | 1712 |
/// For example, an integer vector is written into a section. |
| 1713 | 1713 |
///\code |
| 1714 | 1714 |
/// @numbers |
| 1715 | 1715 |
/// 12 45 23 78 |
| 1716 | 1716 |
/// 4 28 38 28 |
| 1717 | 1717 |
/// 23 6 16 |
| 1718 | 1718 |
///\endcode |
| 1719 | 1719 |
/// |
| 1720 | 1720 |
/// The generator is implemented as a struct. |
| 1721 | 1721 |
///\code |
| 1722 | 1722 |
/// struct NumberSection {
|
| 1723 | 1723 |
/// std::vector<int>::const_iterator _it, _end; |
| 1724 | 1724 |
/// NumberSection(const std::vector<int>& data) |
| 1725 | 1725 |
/// : _it(data.begin()), _end(data.end()) {}
|
| 1726 | 1726 |
/// std::string operator()() {
|
| 1727 | 1727 |
/// int rem_in_line = 4; |
| 1728 | 1728 |
/// std::ostringstream ls; |
| 1729 | 1729 |
/// while (rem_in_line > 0 && _it != _end) {
|
| 1730 | 1730 |
/// ls << *(_it++) << ' '; |
| 1731 | 1731 |
/// --rem_in_line; |
| 1732 | 1732 |
/// } |
| 1733 | 1733 |
/// return ls.str(); |
| 1734 | 1734 |
/// } |
| 1735 | 1735 |
/// }; |
| 1736 | 1736 |
/// |
| 1737 | 1737 |
/// // ... |
| 1738 | 1738 |
/// |
| 1739 | 1739 |
/// writer.sectionLines("numbers", NumberSection(vec));
|
| 1740 | 1740 |
///\endcode |
| 1741 | 1741 |
template <typename Functor> |
| 1742 | 1742 |
SectionWriter& sectionLines(const std::string& type, Functor functor) {
|
| 1743 | 1743 |
LEMON_ASSERT(!type.empty(), "Type is empty."); |
| 1744 | 1744 |
_sections.push_back(std::make_pair(type, |
| 1745 | 1745 |
new _writer_bits::LineSection<Functor>(functor))); |
| 1746 | 1746 |
return *this; |
| 1747 | 1747 |
} |
| 1748 | 1748 |
|
| 1749 | 1749 |
|
| 1750 | 1750 |
/// \brief Add a section writer with stream oriented writing |
| 1751 | 1751 |
/// |
| 1752 | 1752 |
/// The first parameter is the type of the section, the second is |
| 1753 | 1753 |
/// a functor, which takes a \c std::ostream& parameter. The |
| 1754 | 1754 |
/// functor writes the section to the output stream. |
| 1755 | 1755 |
/// \warning The last line must be closed with end-line character. |
| 1756 | 1756 |
template <typename Functor> |
| 1757 | 1757 |
SectionWriter& sectionStream(const std::string& type, Functor functor) {
|
| 1758 | 1758 |
LEMON_ASSERT(!type.empty(), "Type is empty."); |
| 1759 | 1759 |
_sections.push_back(std::make_pair(type, |
| 1760 | 1760 |
new _writer_bits::StreamSection<Functor>(functor))); |
| 1761 | 1761 |
return *this; |
| 1762 | 1762 |
} |
| 1763 | 1763 |
|
| 1764 | 1764 |
/// @} |
| 1765 | 1765 |
|
| 1766 | 1766 |
public: |
| 1767 | 1767 |
|
| 1768 | 1768 |
|
| 1769 |
/// \name Execution of the |
|
| 1769 |
/// \name Execution of the Writer |
|
| 1770 | 1770 |
/// @{
|
| 1771 | 1771 |
|
| 1772 | 1772 |
/// \brief Start the batch processing |
| 1773 | 1773 |
/// |
| 1774 | 1774 |
/// This function starts the batch processing. |
| 1775 | 1775 |
void run() {
|
| 1776 | 1776 |
|
| 1777 | 1777 |
LEMON_ASSERT(_os != 0, "This writer is assigned to an other writer"); |
| 1778 | 1778 |
|
| 1779 | 1779 |
for (Sections::iterator it = _sections.begin(); |
| 1780 | 1780 |
it != _sections.end(); ++it) {
|
| 1781 | 1781 |
(*_os) << '@' << it->first << std::endl; |
| 1782 | 1782 |
it->second->process(*_os); |
| 1783 | 1783 |
} |
| 1784 | 1784 |
} |
| 1785 | 1785 |
|
| 1786 | 1786 |
/// \brief Give back the stream of the writer |
| 1787 | 1787 |
/// |
| 1788 | 1788 |
/// Returns the stream of the writer |
| 1789 | 1789 |
std::ostream& ostream() {
|
| 1790 | 1790 |
return *_os; |
| 1791 | 1791 |
} |
| 1792 | 1792 |
|
| 1793 | 1793 |
/// @} |
| 1794 | 1794 |
|
| 1795 | 1795 |
}; |
| 1796 | 1796 |
|
| 1797 | 1797 |
/// \ingroup lemon_io |
| 1798 | 1798 |
/// |
| 1799 | 1799 |
/// \brief Return a \ref SectionWriter class |
| 1800 | 1800 |
/// |
| 1801 | 1801 |
/// This function just returns a \ref SectionWriter class. |
| 1802 | 1802 |
/// |
| 1803 | 1803 |
/// Please see SectionWriter documentation about the custom section |
| 1804 | 1804 |
/// output. |
| 1805 | 1805 |
/// |
| 1806 | 1806 |
/// \relates SectionWriter |
| 1807 | 1807 |
/// \sa sectionWriter(const std::string& fn) |
| 1808 | 1808 |
/// \sa sectionWriter(const char *fn) |
| 1809 | 1809 |
inline SectionWriter sectionWriter(std::ostream& os) {
|
| 1810 | 1810 |
SectionWriter tmp(os); |
| 1811 | 1811 |
return tmp; |
| 1812 | 1812 |
} |
| 1813 | 1813 |
|
| 1814 | 1814 |
/// \brief Return a \ref SectionWriter class |
| 1815 | 1815 |
/// |
| 1816 | 1816 |
/// This function just returns a \ref SectionWriter class. |
| 1817 | 1817 |
/// \relates SectionWriter |
| ... | ... |
@@ -275,99 +275,96 @@ |
| 275 | 275 |
{
|
| 276 | 276 |
if(arcs[e.id].next_in != -1) |
| 277 | 277 |
arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in; |
| 278 | 278 |
if(arcs[e.id].prev_in != -1) |
| 279 | 279 |
arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in; |
| 280 | 280 |
else nodes[arcs[e.id].target].first_in = arcs[e.id].next_in; |
| 281 | 281 |
if (nodes[n.id].first_in != -1) {
|
| 282 | 282 |
arcs[nodes[n.id].first_in].prev_in = e.id; |
| 283 | 283 |
} |
| 284 | 284 |
arcs[e.id].target = n.id; |
| 285 | 285 |
arcs[e.id].prev_in = -1; |
| 286 | 286 |
arcs[e.id].next_in = nodes[n.id].first_in; |
| 287 | 287 |
nodes[n.id].first_in = e.id; |
| 288 | 288 |
} |
| 289 | 289 |
void changeSource(Arc e, Node n) |
| 290 | 290 |
{
|
| 291 | 291 |
if(arcs[e.id].next_out != -1) |
| 292 | 292 |
arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out; |
| 293 | 293 |
if(arcs[e.id].prev_out != -1) |
| 294 | 294 |
arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out; |
| 295 | 295 |
else nodes[arcs[e.id].source].first_out = arcs[e.id].next_out; |
| 296 | 296 |
if (nodes[n.id].first_out != -1) {
|
| 297 | 297 |
arcs[nodes[n.id].first_out].prev_out = e.id; |
| 298 | 298 |
} |
| 299 | 299 |
arcs[e.id].source = n.id; |
| 300 | 300 |
arcs[e.id].prev_out = -1; |
| 301 | 301 |
arcs[e.id].next_out = nodes[n.id].first_out; |
| 302 | 302 |
nodes[n.id].first_out = e.id; |
| 303 | 303 |
} |
| 304 | 304 |
|
| 305 | 305 |
}; |
| 306 | 306 |
|
| 307 | 307 |
typedef DigraphExtender<ListDigraphBase> ExtendedListDigraphBase; |
| 308 | 308 |
|
| 309 | 309 |
/// \addtogroup graphs |
| 310 | 310 |
/// @{
|
| 311 | 311 |
|
| 312 | 312 |
///A general directed graph structure. |
| 313 | 313 |
|
| 314 | 314 |
///\ref ListDigraph is a simple and fast <em>directed graph</em> |
| 315 | 315 |
///implementation based on static linked lists that are stored in |
| 316 | 316 |
///\c std::vector structures. |
| 317 | 317 |
/// |
| 318 | 318 |
///It conforms to the \ref concepts::Digraph "Digraph concept" and it |
| 319 | 319 |
///also provides several useful additional functionalities. |
| 320 | 320 |
///Most of the member functions and nested classes are documented |
| 321 | 321 |
///only in the concept class. |
| 322 | 322 |
/// |
| 323 |
///An important extra feature of this digraph implementation is that |
|
| 324 |
///its maps are real \ref concepts::ReferenceMap "reference map"s. |
|
| 325 |
/// |
|
| 326 | 323 |
///\sa concepts::Digraph |
| 327 | 324 |
|
| 328 | 325 |
class ListDigraph : public ExtendedListDigraphBase {
|
| 329 | 326 |
private: |
| 330 | 327 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
| 331 | 328 |
|
| 332 | 329 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
| 333 | 330 |
/// |
| 334 | 331 |
ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {};
|
| 335 | 332 |
///\brief Assignment of ListDigraph to another one is \e not allowed. |
| 336 | 333 |
///Use copyDigraph() instead. |
| 337 | 334 |
|
| 338 | 335 |
///Assignment of ListDigraph to another one is \e not allowed. |
| 339 | 336 |
///Use copyDigraph() instead. |
| 340 | 337 |
void operator=(const ListDigraph &) {}
|
| 341 | 338 |
public: |
| 342 | 339 |
|
| 343 | 340 |
typedef ExtendedListDigraphBase Parent; |
| 344 | 341 |
|
| 345 | 342 |
/// Constructor |
| 346 | 343 |
|
| 347 | 344 |
/// Constructor. |
| 348 | 345 |
/// |
| 349 | 346 |
ListDigraph() {}
|
| 350 | 347 |
|
| 351 | 348 |
///Add a new node to the digraph. |
| 352 | 349 |
|
| 353 | 350 |
///Add a new node to the digraph. |
| 354 | 351 |
///\return The new node. |
| 355 | 352 |
Node addNode() { return Parent::addNode(); }
|
| 356 | 353 |
|
| 357 | 354 |
///Add a new arc to the digraph. |
| 358 | 355 |
|
| 359 | 356 |
///Add a new arc to the digraph with source node \c s |
| 360 | 357 |
///and target node \c t. |
| 361 | 358 |
///\return The new arc. |
| 362 | 359 |
Arc addArc(const Node& s, const Node& t) {
|
| 363 | 360 |
return Parent::addArc(s, t); |
| 364 | 361 |
} |
| 365 | 362 |
|
| 366 | 363 |
///\brief Erase a node from the digraph. |
| 367 | 364 |
/// |
| 368 | 365 |
///Erase a node from the digraph. |
| 369 | 366 |
/// |
| 370 | 367 |
void erase(const Node& n) { Parent::erase(n); }
|
| 371 | 368 |
|
| 372 | 369 |
///\brief Erase an arc from the digraph. |
| 373 | 370 |
/// |
| ... | ... |
@@ -1131,99 +1128,96 @@ |
| 1131 | 1128 |
} |
| 1132 | 1129 |
arcs[(2 * e.id) | 1].target = n.id; |
| 1133 | 1130 |
arcs[2 * e.id].prev_out = -1; |
| 1134 | 1131 |
arcs[2 * e.id].next_out = nodes[n.id].first_out; |
| 1135 | 1132 |
nodes[n.id].first_out = 2 * e.id; |
| 1136 | 1133 |
} |
| 1137 | 1134 |
|
| 1138 | 1135 |
void changeU(Edge e, Node n) {
|
| 1139 | 1136 |
if(arcs[(2 * e.id) | 1].next_out != -1) {
|
| 1140 | 1137 |
arcs[arcs[(2 * e.id) | 1].next_out].prev_out = |
| 1141 | 1138 |
arcs[(2 * e.id) | 1].prev_out; |
| 1142 | 1139 |
} |
| 1143 | 1140 |
if(arcs[(2 * e.id) | 1].prev_out != -1) {
|
| 1144 | 1141 |
arcs[arcs[(2 * e.id) | 1].prev_out].next_out = |
| 1145 | 1142 |
arcs[(2 * e.id) | 1].next_out; |
| 1146 | 1143 |
} else {
|
| 1147 | 1144 |
nodes[arcs[2 * e.id].target].first_out = |
| 1148 | 1145 |
arcs[(2 * e.id) | 1].next_out; |
| 1149 | 1146 |
} |
| 1150 | 1147 |
|
| 1151 | 1148 |
if (nodes[n.id].first_out != -1) {
|
| 1152 | 1149 |
arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); |
| 1153 | 1150 |
} |
| 1154 | 1151 |
arcs[2 * e.id].target = n.id; |
| 1155 | 1152 |
arcs[(2 * e.id) | 1].prev_out = -1; |
| 1156 | 1153 |
arcs[(2 * e.id) | 1].next_out = nodes[n.id].first_out; |
| 1157 | 1154 |
nodes[n.id].first_out = ((2 * e.id) | 1); |
| 1158 | 1155 |
} |
| 1159 | 1156 |
|
| 1160 | 1157 |
}; |
| 1161 | 1158 |
|
| 1162 | 1159 |
typedef GraphExtender<ListGraphBase> ExtendedListGraphBase; |
| 1163 | 1160 |
|
| 1164 | 1161 |
|
| 1165 | 1162 |
/// \addtogroup graphs |
| 1166 | 1163 |
/// @{
|
| 1167 | 1164 |
|
| 1168 | 1165 |
///A general undirected graph structure. |
| 1169 | 1166 |
|
| 1170 | 1167 |
///\ref ListGraph is a simple and fast <em>undirected graph</em> |
| 1171 | 1168 |
///implementation based on static linked lists that are stored in |
| 1172 | 1169 |
///\c std::vector structures. |
| 1173 | 1170 |
/// |
| 1174 | 1171 |
///It conforms to the \ref concepts::Graph "Graph concept" and it |
| 1175 | 1172 |
///also provides several useful additional functionalities. |
| 1176 | 1173 |
///Most of the member functions and nested classes are documented |
| 1177 | 1174 |
///only in the concept class. |
| 1178 | 1175 |
/// |
| 1179 |
///An important extra feature of this graph implementation is that |
|
| 1180 |
///its maps are real \ref concepts::ReferenceMap "reference map"s. |
|
| 1181 |
/// |
|
| 1182 | 1176 |
///\sa concepts::Graph |
| 1183 | 1177 |
|
| 1184 | 1178 |
class ListGraph : public ExtendedListGraphBase {
|
| 1185 | 1179 |
private: |
| 1186 | 1180 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
| 1187 | 1181 |
|
| 1188 | 1182 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
| 1189 | 1183 |
/// |
| 1190 | 1184 |
ListGraph(const ListGraph &) :ExtendedListGraphBase() {};
|
| 1191 | 1185 |
///\brief Assignment of ListGraph to another one is \e not allowed. |
| 1192 | 1186 |
///Use copyGraph() instead. |
| 1193 | 1187 |
|
| 1194 | 1188 |
///Assignment of ListGraph to another one is \e not allowed. |
| 1195 | 1189 |
///Use copyGraph() instead. |
| 1196 | 1190 |
void operator=(const ListGraph &) {}
|
| 1197 | 1191 |
public: |
| 1198 | 1192 |
/// Constructor |
| 1199 | 1193 |
|
| 1200 | 1194 |
/// Constructor. |
| 1201 | 1195 |
/// |
| 1202 | 1196 |
ListGraph() {}
|
| 1203 | 1197 |
|
| 1204 | 1198 |
typedef ExtendedListGraphBase Parent; |
| 1205 | 1199 |
|
| 1206 | 1200 |
typedef Parent::OutArcIt IncEdgeIt; |
| 1207 | 1201 |
|
| 1208 | 1202 |
/// \brief Add a new node to the graph. |
| 1209 | 1203 |
/// |
| 1210 | 1204 |
/// Add a new node to the graph. |
| 1211 | 1205 |
/// \return The new node. |
| 1212 | 1206 |
Node addNode() { return Parent::addNode(); }
|
| 1213 | 1207 |
|
| 1214 | 1208 |
/// \brief Add a new edge to the graph. |
| 1215 | 1209 |
/// |
| 1216 | 1210 |
/// Add a new edge to the graph with source node \c s |
| 1217 | 1211 |
/// and target node \c t. |
| 1218 | 1212 |
/// \return The new edge. |
| 1219 | 1213 |
Edge addEdge(const Node& s, const Node& t) {
|
| 1220 | 1214 |
return Parent::addEdge(s, t); |
| 1221 | 1215 |
} |
| 1222 | 1216 |
|
| 1223 | 1217 |
/// \brief Erase a node from the graph. |
| 1224 | 1218 |
/// |
| 1225 | 1219 |
/// Erase a node from the graph. |
| 1226 | 1220 |
/// |
| 1227 | 1221 |
void erase(const Node& n) { Parent::erase(n); }
|
| 1228 | 1222 |
|
| 1229 | 1223 |
/// \brief Erase an edge from the graph. |
| ... | ... |
@@ -7,113 +7,128 @@ |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_LP_BASE_H |
| 20 | 20 |
#define LEMON_LP_BASE_H |
| 21 | 21 |
|
| 22 | 22 |
#include<iostream> |
| 23 | 23 |
#include<vector> |
| 24 | 24 |
#include<map> |
| 25 | 25 |
#include<limits> |
| 26 | 26 |
#include<lemon/math.h> |
| 27 | 27 |
|
| 28 | 28 |
#include<lemon/error.h> |
| 29 | 29 |
#include<lemon/assert.h> |
| 30 | 30 |
|
| 31 | 31 |
#include<lemon/core.h> |
| 32 | 32 |
#include<lemon/bits/solver_bits.h> |
| 33 | 33 |
|
| 34 | 34 |
///\file |
| 35 | 35 |
///\brief The interface of the LP solver interface. |
| 36 | 36 |
///\ingroup lp_group |
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
///Common base class for LP and MIP solvers |
| 40 | 40 |
|
| 41 | 41 |
///Usually this class is not used directly, please use one of the concrete |
| 42 | 42 |
///implementations of the solver interface. |
| 43 | 43 |
///\ingroup lp_group |
| 44 | 44 |
class LpBase {
|
| 45 | 45 |
|
| 46 | 46 |
protected: |
| 47 | 47 |
|
| 48 | 48 |
_solver_bits::VarIndex rows; |
| 49 | 49 |
_solver_bits::VarIndex cols; |
| 50 | 50 |
|
| 51 | 51 |
public: |
| 52 | 52 |
|
| 53 | 53 |
///Possible outcomes of an LP solving procedure |
| 54 | 54 |
enum SolveExitStatus {
|
| 55 |
/// |
|
| 55 |
/// = 0. It means that the problem has been successfully solved: either |
|
| 56 | 56 |
///an optimal solution has been found or infeasibility/unboundedness |
| 57 | 57 |
///has been proved. |
| 58 | 58 |
SOLVED = 0, |
| 59 |
///Any other case (including the case when some user specified |
|
| 60 |
///limit has been exceeded) |
|
| 59 |
/// = 1. Any other case (including the case when some user specified |
|
| 60 |
///limit has been exceeded). |
|
| 61 | 61 |
UNSOLVED = 1 |
| 62 | 62 |
}; |
| 63 | 63 |
|
| 64 | 64 |
///Direction of the optimization |
| 65 | 65 |
enum Sense {
|
| 66 | 66 |
/// Minimization |
| 67 | 67 |
MIN, |
| 68 | 68 |
/// Maximization |
| 69 | 69 |
MAX |
| 70 | 70 |
}; |
| 71 | 71 |
|
| 72 |
///Enum for \c messageLevel() parameter |
|
| 73 |
enum MessageLevel {
|
|
| 74 |
/// No output (default value). |
|
| 75 |
MESSAGE_NOTHING, |
|
| 76 |
/// Error messages only. |
|
| 77 |
MESSAGE_ERROR, |
|
| 78 |
/// Warnings. |
|
| 79 |
MESSAGE_WARNING, |
|
| 80 |
/// Normal output. |
|
| 81 |
MESSAGE_NORMAL, |
|
| 82 |
/// Verbose output. |
|
| 83 |
MESSAGE_VERBOSE |
|
| 84 |
}; |
|
| 85 |
|
|
| 86 |
|
|
| 72 | 87 |
///The floating point type used by the solver |
| 73 | 88 |
typedef double Value; |
| 74 | 89 |
///The infinity constant |
| 75 | 90 |
static const Value INF; |
| 76 | 91 |
///The not a number constant |
| 77 | 92 |
static const Value NaN; |
| 78 | 93 |
|
| 79 | 94 |
friend class Col; |
| 80 | 95 |
friend class ColIt; |
| 81 | 96 |
friend class Row; |
| 82 | 97 |
friend class RowIt; |
| 83 | 98 |
|
| 84 | 99 |
///Refer to a column of the LP. |
| 85 | 100 |
|
| 86 | 101 |
///This type is used to refer to a column of the LP. |
| 87 | 102 |
/// |
| 88 | 103 |
///Its value remains valid and correct even after the addition or erase of |
| 89 | 104 |
///other columns. |
| 90 | 105 |
/// |
| 91 | 106 |
///\note This class is similar to other Item types in LEMON, like |
| 92 | 107 |
///Node and Arc types in digraph. |
| 93 | 108 |
class Col {
|
| 94 | 109 |
friend class LpBase; |
| 95 | 110 |
protected: |
| 96 | 111 |
int _id; |
| 97 | 112 |
explicit Col(int id) : _id(id) {}
|
| 98 | 113 |
public: |
| 99 | 114 |
typedef Value ExprValue; |
| 100 | 115 |
typedef True LpCol; |
| 101 | 116 |
/// Default constructor |
| 102 | 117 |
|
| 103 | 118 |
/// \warning The default constructor sets the Col to an |
| 104 | 119 |
/// undefined value. |
| 105 | 120 |
Col() {}
|
| 106 | 121 |
/// Invalid constructor \& conversion. |
| 107 | 122 |
|
| 108 | 123 |
/// This constructor initializes the Col to be invalid. |
| 109 | 124 |
/// \sa Invalid for more details. |
| 110 | 125 |
Col(const Invalid&) : _id(-1) {}
|
| 111 | 126 |
/// Equality operator |
| 112 | 127 |
|
| 113 | 128 |
/// Two \ref Col "Col"s are equal if and only if they point to |
| 114 | 129 |
/// the same LP column or both are invalid. |
| 115 | 130 |
bool operator==(Col c) const {return _id == c._id;}
|
| 116 | 131 |
/// Inequality operator |
| 117 | 132 |
|
| 118 | 133 |
/// \sa operator==(Col c) |
| 119 | 134 |
/// |
| ... | ... |
@@ -928,112 +943,114 @@ |
| 928 | 943 |
virtual int _addCol() = 0; |
| 929 | 944 |
virtual int _addRow() = 0; |
| 930 | 945 |
|
| 931 | 946 |
virtual void _eraseCol(int col) = 0; |
| 932 | 947 |
virtual void _eraseRow(int row) = 0; |
| 933 | 948 |
|
| 934 | 949 |
virtual void _getColName(int col, std::string& name) const = 0; |
| 935 | 950 |
virtual void _setColName(int col, const std::string& name) = 0; |
| 936 | 951 |
virtual int _colByName(const std::string& name) const = 0; |
| 937 | 952 |
|
| 938 | 953 |
virtual void _getRowName(int row, std::string& name) const = 0; |
| 939 | 954 |
virtual void _setRowName(int row, const std::string& name) = 0; |
| 940 | 955 |
virtual int _rowByName(const std::string& name) const = 0; |
| 941 | 956 |
|
| 942 | 957 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e) = 0; |
| 943 | 958 |
virtual void _getRowCoeffs(int i, InsertIterator b) const = 0; |
| 944 | 959 |
|
| 945 | 960 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e) = 0; |
| 946 | 961 |
virtual void _getColCoeffs(int i, InsertIterator b) const = 0; |
| 947 | 962 |
|
| 948 | 963 |
virtual void _setCoeff(int row, int col, Value value) = 0; |
| 949 | 964 |
virtual Value _getCoeff(int row, int col) const = 0; |
| 950 | 965 |
|
| 951 | 966 |
virtual void _setColLowerBound(int i, Value value) = 0; |
| 952 | 967 |
virtual Value _getColLowerBound(int i) const = 0; |
| 953 | 968 |
|
| 954 | 969 |
virtual void _setColUpperBound(int i, Value value) = 0; |
| 955 | 970 |
virtual Value _getColUpperBound(int i) const = 0; |
| 956 | 971 |
|
| 957 | 972 |
virtual void _setRowLowerBound(int i, Value value) = 0; |
| 958 | 973 |
virtual Value _getRowLowerBound(int i) const = 0; |
| 959 | 974 |
|
| 960 | 975 |
virtual void _setRowUpperBound(int i, Value value) = 0; |
| 961 | 976 |
virtual Value _getRowUpperBound(int i) const = 0; |
| 962 | 977 |
|
| 963 | 978 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e) = 0; |
| 964 | 979 |
virtual void _getObjCoeffs(InsertIterator b) const = 0; |
| 965 | 980 |
|
| 966 | 981 |
virtual void _setObjCoeff(int i, Value obj_coef) = 0; |
| 967 | 982 |
virtual Value _getObjCoeff(int i) const = 0; |
| 968 | 983 |
|
| 969 | 984 |
virtual void _setSense(Sense) = 0; |
| 970 | 985 |
virtual Sense _getSense() const = 0; |
| 971 | 986 |
|
| 972 | 987 |
virtual void _clear() = 0; |
| 973 | 988 |
|
| 974 | 989 |
virtual const char* _solverName() const = 0; |
| 975 | 990 |
|
| 991 |
virtual void _messageLevel(MessageLevel level) = 0; |
|
| 992 |
|
|
| 976 | 993 |
//Own protected stuff |
| 977 | 994 |
|
| 978 | 995 |
//Constant component of the objective function |
| 979 | 996 |
Value obj_const_comp; |
| 980 | 997 |
|
| 981 | 998 |
LpBase() : rows(), cols(), obj_const_comp(0) {}
|
| 982 | 999 |
|
| 983 | 1000 |
public: |
| 984 | 1001 |
|
| 985 | 1002 |
/// Virtual destructor |
| 986 | 1003 |
virtual ~LpBase() {}
|
| 987 | 1004 |
|
| 988 | 1005 |
///Gives back the name of the solver. |
| 989 | 1006 |
const char* solverName() const {return _solverName();}
|
| 990 | 1007 |
|
| 991 |
///\name Build |
|
| 1008 |
///\name Build Up and Modify the LP |
|
| 992 | 1009 |
|
| 993 | 1010 |
///@{
|
| 994 | 1011 |
|
| 995 | 1012 |
///Add a new empty column (i.e a new variable) to the LP |
| 996 | 1013 |
Col addCol() { Col c; c._id = _addColId(_addCol()); return c;}
|
| 997 | 1014 |
|
| 998 | 1015 |
///\brief Adds several new columns (i.e variables) at once |
| 999 | 1016 |
/// |
| 1000 | 1017 |
///This magic function takes a container as its argument and fills |
| 1001 | 1018 |
///its elements with new columns (i.e. variables) |
| 1002 | 1019 |
///\param t can be |
| 1003 | 1020 |
///- a standard STL compatible iterable container with |
| 1004 | 1021 |
///\ref Col as its \c values_type like |
| 1005 | 1022 |
///\code |
| 1006 | 1023 |
///std::vector<LpBase::Col> |
| 1007 | 1024 |
///std::list<LpBase::Col> |
| 1008 | 1025 |
///\endcode |
| 1009 | 1026 |
///- a standard STL compatible iterable container with |
| 1010 | 1027 |
///\ref Col as its \c mapped_type like |
| 1011 | 1028 |
///\code |
| 1012 | 1029 |
///std::map<AnyType,LpBase::Col> |
| 1013 | 1030 |
///\endcode |
| 1014 | 1031 |
///- an iterable lemon \ref concepts::WriteMap "write map" like |
| 1015 | 1032 |
///\code |
| 1016 | 1033 |
///ListGraph::NodeMap<LpBase::Col> |
| 1017 | 1034 |
///ListGraph::ArcMap<LpBase::Col> |
| 1018 | 1035 |
///\endcode |
| 1019 | 1036 |
///\return The number of the created column. |
| 1020 | 1037 |
#ifdef DOXYGEN |
| 1021 | 1038 |
template<class T> |
| 1022 | 1039 |
int addColSet(T &t) { return 0;}
|
| 1023 | 1040 |
#else |
| 1024 | 1041 |
template<class T> |
| 1025 | 1042 |
typename enable_if<typename T::value_type::LpCol,int>::type |
| 1026 | 1043 |
addColSet(T &t,dummy<0> = 0) {
|
| 1027 | 1044 |
int s=0; |
| 1028 | 1045 |
for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;}
|
| 1029 | 1046 |
return s; |
| 1030 | 1047 |
} |
| 1031 | 1048 |
template<class T> |
| 1032 | 1049 |
typename enable_if<typename T::value_type::second_type::LpCol, |
| 1033 | 1050 |
int>::type |
| 1034 | 1051 |
addColSet(T &t,dummy<1> = 1) {
|
| 1035 | 1052 |
int s=0; |
| 1036 | 1053 |
for(typename T::iterator i=t.begin();i!=t.end();++i) {
|
| 1037 | 1054 |
i->second=addCol(); |
| 1038 | 1055 |
s++; |
| 1039 | 1056 |
} |
| ... | ... |
@@ -1482,96 +1499,99 @@ |
| 1482 | 1499 |
///\return The upper bound for row \c r |
| 1483 | 1500 |
Value rowUpperBound(Row r) const {
|
| 1484 | 1501 |
return _getRowUpperBound(rows(id(r))); |
| 1485 | 1502 |
} |
| 1486 | 1503 |
|
| 1487 | 1504 |
///Set an element of the objective function |
| 1488 | 1505 |
void objCoeff(Col c, Value v) {_setObjCoeff(cols(id(c)),v); };
|
| 1489 | 1506 |
|
| 1490 | 1507 |
///Get an element of the objective function |
| 1491 | 1508 |
Value objCoeff(Col c) const { return _getObjCoeff(cols(id(c))); };
|
| 1492 | 1509 |
|
| 1493 | 1510 |
///Set the objective function |
| 1494 | 1511 |
|
| 1495 | 1512 |
///\param e is a linear expression of type \ref Expr. |
| 1496 | 1513 |
/// |
| 1497 | 1514 |
void obj(const Expr& e) {
|
| 1498 | 1515 |
_setObjCoeffs(ExprIterator(e.comps.begin(), cols), |
| 1499 | 1516 |
ExprIterator(e.comps.end(), cols)); |
| 1500 | 1517 |
obj_const_comp = *e; |
| 1501 | 1518 |
} |
| 1502 | 1519 |
|
| 1503 | 1520 |
///Get the objective function |
| 1504 | 1521 |
|
| 1505 | 1522 |
///\return the objective function as a linear expression of type |
| 1506 | 1523 |
///Expr. |
| 1507 | 1524 |
Expr obj() const {
|
| 1508 | 1525 |
Expr e; |
| 1509 | 1526 |
_getObjCoeffs(InsertIterator(e.comps, cols)); |
| 1510 | 1527 |
*e = obj_const_comp; |
| 1511 | 1528 |
return e; |
| 1512 | 1529 |
} |
| 1513 | 1530 |
|
| 1514 | 1531 |
|
| 1515 | 1532 |
///Set the direction of optimization |
| 1516 | 1533 |
void sense(Sense sense) { _setSense(sense); }
|
| 1517 | 1534 |
|
| 1518 | 1535 |
///Query the direction of the optimization |
| 1519 | 1536 |
Sense sense() const {return _getSense(); }
|
| 1520 | 1537 |
|
| 1521 | 1538 |
///Set the sense to maximization |
| 1522 | 1539 |
void max() { _setSense(MAX); }
|
| 1523 | 1540 |
|
| 1524 | 1541 |
///Set the sense to maximization |
| 1525 | 1542 |
void min() { _setSense(MIN); }
|
| 1526 | 1543 |
|
| 1527 | 1544 |
///Clears the problem |
| 1528 | 1545 |
void clear() { _clear(); }
|
| 1529 | 1546 |
|
| 1547 |
/// Sets the message level of the solver |
|
| 1548 |
void messageLevel(MessageLevel level) { _messageLevel(level); }
|
|
| 1549 |
|
|
| 1530 | 1550 |
///@} |
| 1531 | 1551 |
|
| 1532 | 1552 |
}; |
| 1533 | 1553 |
|
| 1534 | 1554 |
/// Addition |
| 1535 | 1555 |
|
| 1536 | 1556 |
///\relates LpBase::Expr |
| 1537 | 1557 |
/// |
| 1538 | 1558 |
inline LpBase::Expr operator+(const LpBase::Expr &a, const LpBase::Expr &b) {
|
| 1539 | 1559 |
LpBase::Expr tmp(a); |
| 1540 | 1560 |
tmp+=b; |
| 1541 | 1561 |
return tmp; |
| 1542 | 1562 |
} |
| 1543 | 1563 |
///Substraction |
| 1544 | 1564 |
|
| 1545 | 1565 |
///\relates LpBase::Expr |
| 1546 | 1566 |
/// |
| 1547 | 1567 |
inline LpBase::Expr operator-(const LpBase::Expr &a, const LpBase::Expr &b) {
|
| 1548 | 1568 |
LpBase::Expr tmp(a); |
| 1549 | 1569 |
tmp-=b; |
| 1550 | 1570 |
return tmp; |
| 1551 | 1571 |
} |
| 1552 | 1572 |
///Multiply with constant |
| 1553 | 1573 |
|
| 1554 | 1574 |
///\relates LpBase::Expr |
| 1555 | 1575 |
/// |
| 1556 | 1576 |
inline LpBase::Expr operator*(const LpBase::Expr &a, const LpBase::Value &b) {
|
| 1557 | 1577 |
LpBase::Expr tmp(a); |
| 1558 | 1578 |
tmp*=b; |
| 1559 | 1579 |
return tmp; |
| 1560 | 1580 |
} |
| 1561 | 1581 |
|
| 1562 | 1582 |
///Multiply with constant |
| 1563 | 1583 |
|
| 1564 | 1584 |
///\relates LpBase::Expr |
| 1565 | 1585 |
/// |
| 1566 | 1586 |
inline LpBase::Expr operator*(const LpBase::Value &a, const LpBase::Expr &b) {
|
| 1567 | 1587 |
LpBase::Expr tmp(b); |
| 1568 | 1588 |
tmp*=a; |
| 1569 | 1589 |
return tmp; |
| 1570 | 1590 |
} |
| 1571 | 1591 |
///Divide with constant |
| 1572 | 1592 |
|
| 1573 | 1593 |
///\relates LpBase::Expr |
| 1574 | 1594 |
/// |
| 1575 | 1595 |
inline LpBase::Expr operator/(const LpBase::Expr &a, const LpBase::Value &b) {
|
| 1576 | 1596 |
LpBase::Expr tmp(a); |
| 1577 | 1597 |
tmp/=b; |
| ... | ... |
@@ -1723,161 +1743,161 @@ |
| 1723 | 1743 |
///Multiply with constant |
| 1724 | 1744 |
|
| 1725 | 1745 |
///\relates LpBase::DualExpr |
| 1726 | 1746 |
/// |
| 1727 | 1747 |
inline LpBase::DualExpr operator*(const LpBase::DualExpr &a, |
| 1728 | 1748 |
const LpBase::Value &b) {
|
| 1729 | 1749 |
LpBase::DualExpr tmp(a); |
| 1730 | 1750 |
tmp*=b; |
| 1731 | 1751 |
return tmp; |
| 1732 | 1752 |
} |
| 1733 | 1753 |
|
| 1734 | 1754 |
///Multiply with constant |
| 1735 | 1755 |
|
| 1736 | 1756 |
///\relates LpBase::DualExpr |
| 1737 | 1757 |
/// |
| 1738 | 1758 |
inline LpBase::DualExpr operator*(const LpBase::Value &a, |
| 1739 | 1759 |
const LpBase::DualExpr &b) {
|
| 1740 | 1760 |
LpBase::DualExpr tmp(b); |
| 1741 | 1761 |
tmp*=a; |
| 1742 | 1762 |
return tmp; |
| 1743 | 1763 |
} |
| 1744 | 1764 |
///Divide with constant |
| 1745 | 1765 |
|
| 1746 | 1766 |
///\relates LpBase::DualExpr |
| 1747 | 1767 |
/// |
| 1748 | 1768 |
inline LpBase::DualExpr operator/(const LpBase::DualExpr &a, |
| 1749 | 1769 |
const LpBase::Value &b) {
|
| 1750 | 1770 |
LpBase::DualExpr tmp(a); |
| 1751 | 1771 |
tmp/=b; |
| 1752 | 1772 |
return tmp; |
| 1753 | 1773 |
} |
| 1754 | 1774 |
|
| 1755 | 1775 |
/// \ingroup lp_group |
| 1756 | 1776 |
/// |
| 1757 | 1777 |
/// \brief Common base class for LP solvers |
| 1758 | 1778 |
/// |
| 1759 | 1779 |
/// This class is an abstract base class for LP solvers. This class |
| 1760 | 1780 |
/// provides a full interface for set and modify an LP problem, |
| 1761 | 1781 |
/// solve it and retrieve the solution. You can use one of the |
| 1762 | 1782 |
/// descendants as a concrete implementation, or the \c Lp |
| 1763 | 1783 |
/// default LP solver. However, if you would like to handle LP |
| 1764 | 1784 |
/// solvers as reference or pointer in a generic way, you can use |
| 1765 | 1785 |
/// this class directly. |
| 1766 | 1786 |
class LpSolver : virtual public LpBase {
|
| 1767 | 1787 |
public: |
| 1768 | 1788 |
|
| 1769 | 1789 |
/// The problem types for primal and dual problems |
| 1770 | 1790 |
enum ProblemType {
|
| 1771 |
///Feasible solution hasn't been found (but may exist). |
|
| 1791 |
/// = 0. Feasible solution hasn't been found (but may exist). |
|
| 1772 | 1792 |
UNDEFINED = 0, |
| 1773 |
///The problem has no feasible solution |
|
| 1793 |
/// = 1. The problem has no feasible solution. |
|
| 1774 | 1794 |
INFEASIBLE = 1, |
| 1775 |
///Feasible solution found |
|
| 1795 |
/// = 2. Feasible solution found. |
|
| 1776 | 1796 |
FEASIBLE = 2, |
| 1777 |
///Optimal solution exists and found |
|
| 1797 |
/// = 3. Optimal solution exists and found. |
|
| 1778 | 1798 |
OPTIMAL = 3, |
| 1779 |
///The cost function is unbounded |
|
| 1799 |
/// = 4. The cost function is unbounded. |
|
| 1780 | 1800 |
UNBOUNDED = 4 |
| 1781 | 1801 |
}; |
| 1782 | 1802 |
|
| 1783 | 1803 |
///The basis status of variables |
| 1784 | 1804 |
enum VarStatus {
|
| 1785 | 1805 |
/// The variable is in the basis |
| 1786 | 1806 |
BASIC, |
| 1787 | 1807 |
/// The variable is free, but not basic |
| 1788 | 1808 |
FREE, |
| 1789 | 1809 |
/// The variable has active lower bound |
| 1790 | 1810 |
LOWER, |
| 1791 | 1811 |
/// The variable has active upper bound |
| 1792 | 1812 |
UPPER, |
| 1793 | 1813 |
/// The variable is non-basic and fixed |
| 1794 | 1814 |
FIXED |
| 1795 | 1815 |
}; |
| 1796 | 1816 |
|
| 1797 | 1817 |
protected: |
| 1798 | 1818 |
|
| 1799 | 1819 |
virtual SolveExitStatus _solve() = 0; |
| 1800 | 1820 |
|
| 1801 | 1821 |
virtual Value _getPrimal(int i) const = 0; |
| 1802 | 1822 |
virtual Value _getDual(int i) const = 0; |
| 1803 | 1823 |
|
| 1804 | 1824 |
virtual Value _getPrimalRay(int i) const = 0; |
| 1805 | 1825 |
virtual Value _getDualRay(int i) const = 0; |
| 1806 | 1826 |
|
| 1807 | 1827 |
virtual Value _getPrimalValue() const = 0; |
| 1808 | 1828 |
|
| 1809 | 1829 |
virtual VarStatus _getColStatus(int i) const = 0; |
| 1810 | 1830 |
virtual VarStatus _getRowStatus(int i) const = 0; |
| 1811 | 1831 |
|
| 1812 | 1832 |
virtual ProblemType _getPrimalType() const = 0; |
| 1813 | 1833 |
virtual ProblemType _getDualType() const = 0; |
| 1814 | 1834 |
|
| 1815 | 1835 |
public: |
| 1816 | 1836 |
|
| 1817 | 1837 |
///Allocate a new LP problem instance |
| 1818 | 1838 |
virtual LpSolver* newSolver() const = 0; |
| 1819 | 1839 |
///Make a copy of the LP problem |
| 1820 | 1840 |
virtual LpSolver* cloneSolver() const = 0; |
| 1821 | 1841 |
|
| 1822 | 1842 |
///\name Solve the LP |
| 1823 | 1843 |
|
| 1824 | 1844 |
///@{
|
| 1825 | 1845 |
|
| 1826 | 1846 |
///\e Solve the LP problem at hand |
| 1827 | 1847 |
/// |
| 1828 | 1848 |
///\return The result of the optimization procedure. Possible |
| 1829 | 1849 |
///values and their meanings can be found in the documentation of |
| 1830 | 1850 |
///\ref SolveExitStatus. |
| 1831 | 1851 |
SolveExitStatus solve() { return _solve(); }
|
| 1832 | 1852 |
|
| 1833 | 1853 |
///@} |
| 1834 | 1854 |
|
| 1835 |
///\name Obtain the |
|
| 1855 |
///\name Obtain the Solution |
|
| 1836 | 1856 |
|
| 1837 | 1857 |
///@{
|
| 1838 | 1858 |
|
| 1839 | 1859 |
/// The type of the primal problem |
| 1840 | 1860 |
ProblemType primalType() const {
|
| 1841 | 1861 |
return _getPrimalType(); |
| 1842 | 1862 |
} |
| 1843 | 1863 |
|
| 1844 | 1864 |
/// The type of the dual problem |
| 1845 | 1865 |
ProblemType dualType() const {
|
| 1846 | 1866 |
return _getDualType(); |
| 1847 | 1867 |
} |
| 1848 | 1868 |
|
| 1849 | 1869 |
/// Return the primal value of the column |
| 1850 | 1870 |
|
| 1851 | 1871 |
/// Return the primal value of the column. |
| 1852 | 1872 |
/// \pre The problem is solved. |
| 1853 | 1873 |
Value primal(Col c) const { return _getPrimal(cols(id(c))); }
|
| 1854 | 1874 |
|
| 1855 | 1875 |
/// Return the primal value of the expression |
| 1856 | 1876 |
|
| 1857 | 1877 |
/// Return the primal value of the expression, i.e. the dot |
| 1858 | 1878 |
/// product of the primal solution and the expression. |
| 1859 | 1879 |
/// \pre The problem is solved. |
| 1860 | 1880 |
Value primal(const Expr& e) const {
|
| 1861 | 1881 |
double res = *e; |
| 1862 | 1882 |
for (Expr::ConstCoeffIt c(e); c != INVALID; ++c) {
|
| 1863 | 1883 |
res += *c * primal(c); |
| 1864 | 1884 |
} |
| 1865 | 1885 |
return res; |
| 1866 | 1886 |
} |
| 1867 | 1887 |
/// Returns a component of the primal ray |
| 1868 | 1888 |
|
| 1869 | 1889 |
/// The primal ray is solution of the modified primal problem, |
| 1870 | 1890 |
/// where we change each finite bound to 0, and we looking for a |
| 1871 | 1891 |
/// negative objective value in case of minimization, and positive |
| 1872 | 1892 |
/// objective value for maximization. If there is such solution, |
| 1873 | 1893 |
/// that proofs the unsolvability of the dual problem, and if a |
| 1874 | 1894 |
/// feasible primal solution exists, then the unboundness of |
| 1875 | 1895 |
/// primal problem. |
| 1876 | 1896 |
/// |
| 1877 | 1897 |
/// \pre The problem is solved and the dual problem is infeasible. |
| 1878 | 1898 |
/// \note Some solvers does not provide primal ray calculation |
| 1879 | 1899 |
/// functions. |
| 1880 | 1900 |
Value primalRay(Col c) const { return _getPrimalRay(cols(id(c))); }
|
| 1881 | 1901 |
|
| 1882 | 1902 |
/// Return the dual value of the row |
| 1883 | 1903 |
|
| ... | ... |
@@ -1909,157 +1929,156 @@ |
| 1909 | 1929 |
/// dual problem. |
| 1910 | 1930 |
/// |
| 1911 | 1931 |
/// \pre The problem is solved and the primal problem is infeasible. |
| 1912 | 1932 |
/// \note Some solvers does not provide dual ray calculation |
| 1913 | 1933 |
/// functions. |
| 1914 | 1934 |
Value dualRay(Row r) const { return _getDualRay(rows(id(r))); }
|
| 1915 | 1935 |
|
| 1916 | 1936 |
/// Return the basis status of the column |
| 1917 | 1937 |
|
| 1918 | 1938 |
/// \see VarStatus |
| 1919 | 1939 |
VarStatus colStatus(Col c) const { return _getColStatus(cols(id(c))); }
|
| 1920 | 1940 |
|
| 1921 | 1941 |
/// Return the basis status of the row |
| 1922 | 1942 |
|
| 1923 | 1943 |
/// \see VarStatus |
| 1924 | 1944 |
VarStatus rowStatus(Row r) const { return _getRowStatus(rows(id(r))); }
|
| 1925 | 1945 |
|
| 1926 | 1946 |
///The value of the objective function |
| 1927 | 1947 |
|
| 1928 | 1948 |
///\return |
| 1929 | 1949 |
///- \ref INF or -\ref INF means either infeasibility or unboundedness |
| 1930 | 1950 |
/// of the primal problem, depending on whether we minimize or maximize. |
| 1931 | 1951 |
///- \ref NaN if no primal solution is found. |
| 1932 | 1952 |
///- The (finite) objective value if an optimal solution is found. |
| 1933 | 1953 |
Value primal() const { return _getPrimalValue()+obj_const_comp;}
|
| 1934 | 1954 |
///@} |
| 1935 | 1955 |
|
| 1936 | 1956 |
protected: |
| 1937 | 1957 |
|
| 1938 | 1958 |
}; |
| 1939 | 1959 |
|
| 1940 | 1960 |
|
| 1941 | 1961 |
/// \ingroup lp_group |
| 1942 | 1962 |
/// |
| 1943 | 1963 |
/// \brief Common base class for MIP solvers |
| 1944 | 1964 |
/// |
| 1945 | 1965 |
/// This class is an abstract base class for MIP solvers. This class |
| 1946 | 1966 |
/// provides a full interface for set and modify an MIP problem, |
| 1947 | 1967 |
/// solve it and retrieve the solution. You can use one of the |
| 1948 | 1968 |
/// descendants as a concrete implementation, or the \c Lp |
| 1949 | 1969 |
/// default MIP solver. However, if you would like to handle MIP |
| 1950 | 1970 |
/// solvers as reference or pointer in a generic way, you can use |
| 1951 | 1971 |
/// this class directly. |
| 1952 | 1972 |
class MipSolver : virtual public LpBase {
|
| 1953 | 1973 |
public: |
| 1954 | 1974 |
|
| 1955 | 1975 |
/// The problem types for MIP problems |
| 1956 | 1976 |
enum ProblemType {
|
| 1957 |
///Feasible solution hasn't been found (but may exist). |
|
| 1977 |
/// = 0. Feasible solution hasn't been found (but may exist). |
|
| 1958 | 1978 |
UNDEFINED = 0, |
| 1959 |
///The problem has no feasible solution |
|
| 1979 |
/// = 1. The problem has no feasible solution. |
|
| 1960 | 1980 |
INFEASIBLE = 1, |
| 1961 |
///Feasible solution found |
|
| 1981 |
/// = 2. Feasible solution found. |
|
| 1962 | 1982 |
FEASIBLE = 2, |
| 1963 |
///Optimal solution exists and found |
|
| 1983 |
/// = 3. Optimal solution exists and found. |
|
| 1964 | 1984 |
OPTIMAL = 3, |
| 1965 |
///The cost function is unbounded |
|
| 1966 |
/// |
|
| 1967 |
///The |
|
| 1985 |
/// = 4. The cost function is unbounded. |
|
| 1986 |
///The Mip or at least the relaxed problem is unbounded. |
|
| 1968 | 1987 |
UNBOUNDED = 4 |
| 1969 | 1988 |
}; |
| 1970 | 1989 |
|
| 1971 | 1990 |
///Allocate a new MIP problem instance |
| 1972 | 1991 |
virtual MipSolver* newSolver() const = 0; |
| 1973 | 1992 |
///Make a copy of the MIP problem |
| 1974 | 1993 |
virtual MipSolver* cloneSolver() const = 0; |
| 1975 | 1994 |
|
| 1976 | 1995 |
///\name Solve the MIP |
| 1977 | 1996 |
|
| 1978 | 1997 |
///@{
|
| 1979 | 1998 |
|
| 1980 | 1999 |
/// Solve the MIP problem at hand |
| 1981 | 2000 |
/// |
| 1982 | 2001 |
///\return The result of the optimization procedure. Possible |
| 1983 | 2002 |
///values and their meanings can be found in the documentation of |
| 1984 | 2003 |
///\ref SolveExitStatus. |
| 1985 | 2004 |
SolveExitStatus solve() { return _solve(); }
|
| 1986 | 2005 |
|
| 1987 | 2006 |
///@} |
| 1988 | 2007 |
|
| 1989 |
///\name |
|
| 2008 |
///\name Set Column Type |
|
| 1990 | 2009 |
///@{
|
| 1991 | 2010 |
|
| 1992 | 2011 |
///Possible variable (column) types (e.g. real, integer, binary etc.) |
| 1993 | 2012 |
enum ColTypes {
|
| 1994 |
///Continuous variable (default) |
|
| 2013 |
/// = 0. Continuous variable (default). |
|
| 1995 | 2014 |
REAL = 0, |
| 1996 |
///Integer variable |
|
| 2015 |
/// = 1. Integer variable. |
|
| 1997 | 2016 |
INTEGER = 1 |
| 1998 | 2017 |
}; |
| 1999 | 2018 |
|
| 2000 | 2019 |
///Sets the type of the given column to the given type |
| 2001 | 2020 |
|
| 2002 | 2021 |
///Sets the type of the given column to the given type. |
| 2003 | 2022 |
/// |
| 2004 | 2023 |
void colType(Col c, ColTypes col_type) {
|
| 2005 | 2024 |
_setColType(cols(id(c)),col_type); |
| 2006 | 2025 |
} |
| 2007 | 2026 |
|
| 2008 | 2027 |
///Gives back the type of the column. |
| 2009 | 2028 |
|
| 2010 | 2029 |
///Gives back the type of the column. |
| 2011 | 2030 |
/// |
| 2012 | 2031 |
ColTypes colType(Col c) const {
|
| 2013 | 2032 |
return _getColType(cols(id(c))); |
| 2014 | 2033 |
} |
| 2015 | 2034 |
///@} |
| 2016 | 2035 |
|
| 2017 |
///\name Obtain the |
|
| 2036 |
///\name Obtain the Solution |
|
| 2018 | 2037 |
|
| 2019 | 2038 |
///@{
|
| 2020 | 2039 |
|
| 2021 | 2040 |
/// The type of the MIP problem |
| 2022 | 2041 |
ProblemType type() const {
|
| 2023 | 2042 |
return _getType(); |
| 2024 | 2043 |
} |
| 2025 | 2044 |
|
| 2026 | 2045 |
/// Return the value of the row in the solution |
| 2027 | 2046 |
|
| 2028 | 2047 |
/// Return the value of the row in the solution. |
| 2029 | 2048 |
/// \pre The problem is solved. |
| 2030 | 2049 |
Value sol(Col c) const { return _getSol(cols(id(c))); }
|
| 2031 | 2050 |
|
| 2032 | 2051 |
/// Return the value of the expression in the solution |
| 2033 | 2052 |
|
| 2034 | 2053 |
/// Return the value of the expression in the solution, i.e. the |
| 2035 | 2054 |
/// dot product of the solution and the expression. |
| 2036 | 2055 |
/// \pre The problem is solved. |
| 2037 | 2056 |
Value sol(const Expr& e) const {
|
| 2038 | 2057 |
double res = *e; |
| 2039 | 2058 |
for (Expr::ConstCoeffIt c(e); c != INVALID; ++c) {
|
| 2040 | 2059 |
res += *c * sol(c); |
| 2041 | 2060 |
} |
| 2042 | 2061 |
return res; |
| 2043 | 2062 |
} |
| 2044 | 2063 |
///The value of the objective function |
| 2045 | 2064 |
|
| 2046 | 2065 |
///\return |
| 2047 | 2066 |
///- \ref INF or -\ref INF means either infeasibility or unboundedness |
| 2048 | 2067 |
/// of the problem, depending on whether we minimize or maximize. |
| 2049 | 2068 |
///- \ref NaN if no primal solution is found. |
| 2050 | 2069 |
///- The (finite) objective value if an optimal solution is found. |
| 2051 | 2070 |
Value solValue() const { return _getSolValue()+obj_const_comp;}
|
| 2052 | 2071 |
///@} |
| 2053 | 2072 |
|
| 2054 | 2073 |
protected: |
| 2055 | 2074 |
|
| 2056 | 2075 |
virtual SolveExitStatus _solve() = 0; |
| 2057 | 2076 |
virtual ColTypes _getColType(int col) const = 0; |
| 2058 | 2077 |
virtual void _setColType(int col, ColTypes col_type) = 0; |
| 2059 | 2078 |
virtual ProblemType _getType() const = 0; |
| 2060 | 2079 |
virtual Value _getSol(int i) const = 0; |
| 2061 | 2080 |
virtual Value _getSolValue() const = 0; |
| 2062 | 2081 |
|
| 2063 | 2082 |
}; |
| 2064 | 2083 |
|
| 2065 | 2084 |
| ... | ... |
@@ -39,96 +39,98 @@ |
| 39 | 39 |
void SkeletonSolverBase::_setColName(int, const std::string &) {}
|
| 40 | 40 |
int SkeletonSolverBase::_colByName(const std::string&) const { return -1; }
|
| 41 | 41 |
|
| 42 | 42 |
void SkeletonSolverBase::_getRowName(int, std::string &) const {}
|
| 43 | 43 |
void SkeletonSolverBase::_setRowName(int, const std::string &) {}
|
| 44 | 44 |
int SkeletonSolverBase::_rowByName(const std::string&) const { return -1; }
|
| 45 | 45 |
|
| 46 | 46 |
void SkeletonSolverBase::_setRowCoeffs(int, ExprIterator, ExprIterator) {}
|
| 47 | 47 |
void SkeletonSolverBase::_getRowCoeffs(int, InsertIterator) const {}
|
| 48 | 48 |
|
| 49 | 49 |
void SkeletonSolverBase::_setColCoeffs(int, ExprIterator, ExprIterator) {}
|
| 50 | 50 |
void SkeletonSolverBase::_getColCoeffs(int, InsertIterator) const {}
|
| 51 | 51 |
|
| 52 | 52 |
void SkeletonSolverBase::_setCoeff(int, int, Value) {}
|
| 53 | 53 |
SkeletonSolverBase::Value SkeletonSolverBase::_getCoeff(int, int) const |
| 54 | 54 |
{ return 0; }
|
| 55 | 55 |
|
| 56 | 56 |
void SkeletonSolverBase::_setColLowerBound(int, Value) {}
|
| 57 | 57 |
SkeletonSolverBase::Value SkeletonSolverBase::_getColLowerBound(int) const |
| 58 | 58 |
{ return 0; }
|
| 59 | 59 |
|
| 60 | 60 |
void SkeletonSolverBase::_setColUpperBound(int, Value) {}
|
| 61 | 61 |
SkeletonSolverBase::Value SkeletonSolverBase::_getColUpperBound(int) const |
| 62 | 62 |
{ return 0; }
|
| 63 | 63 |
|
| 64 | 64 |
void SkeletonSolverBase::_setRowLowerBound(int, Value) {}
|
| 65 | 65 |
SkeletonSolverBase::Value SkeletonSolverBase::_getRowLowerBound(int) const |
| 66 | 66 |
{ return 0; }
|
| 67 | 67 |
|
| 68 | 68 |
void SkeletonSolverBase::_setRowUpperBound(int, Value) {}
|
| 69 | 69 |
SkeletonSolverBase::Value SkeletonSolverBase::_getRowUpperBound(int) const |
| 70 | 70 |
{ return 0; }
|
| 71 | 71 |
|
| 72 | 72 |
void SkeletonSolverBase::_setObjCoeffs(ExprIterator, ExprIterator) {}
|
| 73 | 73 |
void SkeletonSolverBase::_getObjCoeffs(InsertIterator) const {};
|
| 74 | 74 |
|
| 75 | 75 |
void SkeletonSolverBase::_setObjCoeff(int, Value) {}
|
| 76 | 76 |
SkeletonSolverBase::Value SkeletonSolverBase::_getObjCoeff(int) const |
| 77 | 77 |
{ return 0; }
|
| 78 | 78 |
|
| 79 | 79 |
void SkeletonSolverBase::_setSense(Sense) {}
|
| 80 | 80 |
SkeletonSolverBase::Sense SkeletonSolverBase::_getSense() const |
| 81 | 81 |
{ return MIN; }
|
| 82 | 82 |
|
| 83 | 83 |
void SkeletonSolverBase::_clear() {
|
| 84 | 84 |
row_num = col_num = 0; |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 |
void SkeletonSolverBase::_messageLevel(MessageLevel) {}
|
|
| 88 |
|
|
| 87 | 89 |
LpSkeleton::SolveExitStatus LpSkeleton::_solve() { return SOLVED; }
|
| 88 | 90 |
|
| 89 | 91 |
LpSkeleton::Value LpSkeleton::_getPrimal(int) const { return 0; }
|
| 90 | 92 |
LpSkeleton::Value LpSkeleton::_getDual(int) const { return 0; }
|
| 91 | 93 |
LpSkeleton::Value LpSkeleton::_getPrimalValue() const { return 0; }
|
| 92 | 94 |
|
| 93 | 95 |
LpSkeleton::Value LpSkeleton::_getPrimalRay(int) const { return 0; }
|
| 94 | 96 |
LpSkeleton::Value LpSkeleton::_getDualRay(int) const { return 0; }
|
| 95 | 97 |
|
| 96 | 98 |
LpSkeleton::ProblemType LpSkeleton::_getPrimalType() const |
| 97 | 99 |
{ return UNDEFINED; }
|
| 98 | 100 |
|
| 99 | 101 |
LpSkeleton::ProblemType LpSkeleton::_getDualType() const |
| 100 | 102 |
{ return UNDEFINED; }
|
| 101 | 103 |
|
| 102 | 104 |
LpSkeleton::VarStatus LpSkeleton::_getColStatus(int) const |
| 103 | 105 |
{ return BASIC; }
|
| 104 | 106 |
|
| 105 | 107 |
LpSkeleton::VarStatus LpSkeleton::_getRowStatus(int) const |
| 106 | 108 |
{ return BASIC; }
|
| 107 | 109 |
|
| 108 | 110 |
LpSkeleton* LpSkeleton::newSolver() const |
| 109 | 111 |
{ return static_cast<LpSkeleton*>(0); }
|
| 110 | 112 |
|
| 111 | 113 |
LpSkeleton* LpSkeleton::cloneSolver() const |
| 112 | 114 |
{ return static_cast<LpSkeleton*>(0); }
|
| 113 | 115 |
|
| 114 | 116 |
const char* LpSkeleton::_solverName() const { return "LpSkeleton"; }
|
| 115 | 117 |
|
| 116 | 118 |
MipSkeleton::SolveExitStatus MipSkeleton::_solve() |
| 117 | 119 |
{ return SOLVED; }
|
| 118 | 120 |
|
| 119 | 121 |
MipSkeleton::Value MipSkeleton::_getSol(int) const { return 0; }
|
| 120 | 122 |
MipSkeleton::Value MipSkeleton::_getSolValue() const { return 0; }
|
| 121 | 123 |
|
| 122 | 124 |
MipSkeleton::ProblemType MipSkeleton::_getType() const |
| 123 | 125 |
{ return UNDEFINED; }
|
| 124 | 126 |
|
| 125 | 127 |
MipSkeleton* MipSkeleton::newSolver() const |
| 126 | 128 |
{ return static_cast<MipSkeleton*>(0); }
|
| 127 | 129 |
|
| 128 | 130 |
MipSkeleton* MipSkeleton::cloneSolver() const |
| 129 | 131 |
{ return static_cast<MipSkeleton*>(0); }
|
| 130 | 132 |
|
| 131 | 133 |
const char* MipSkeleton::_solverName() const { return "MipSkeleton"; }
|
| 132 | 134 |
|
| 133 | 135 |
} //namespace lemon |
| 134 | 136 |
| ... | ... |
@@ -95,96 +95,98 @@ |
| 95 | 95 |
virtual void _setColUpperBound(int i, Value value); |
| 96 | 96 |
/// \e |
| 97 | 97 |
|
| 98 | 98 |
/// The upper bound of a variable (column) is an |
| 99 | 99 |
/// extended number of type Value, i.e. a finite number of type |
| 100 | 100 |
/// Value or \ref INF. |
| 101 | 101 |
virtual Value _getColUpperBound(int i) const; |
| 102 | 102 |
|
| 103 | 103 |
/// The lower bound of a constraint (row) have to be given by an |
| 104 | 104 |
/// extended number of type Value, i.e. a finite number of type |
| 105 | 105 |
/// Value or -\ref INF. |
| 106 | 106 |
virtual void _setRowLowerBound(int i, Value value); |
| 107 | 107 |
/// \e |
| 108 | 108 |
|
| 109 | 109 |
/// The lower bound of a constraint (row) is an |
| 110 | 110 |
/// extended number of type Value, i.e. a finite number of type |
| 111 | 111 |
/// Value or -\ref INF. |
| 112 | 112 |
virtual Value _getRowLowerBound(int i) const; |
| 113 | 113 |
|
| 114 | 114 |
/// The upper bound of a constraint (row) have to be given by an |
| 115 | 115 |
/// extended number of type Value, i.e. a finite number of type |
| 116 | 116 |
/// Value or \ref INF. |
| 117 | 117 |
virtual void _setRowUpperBound(int i, Value value); |
| 118 | 118 |
/// \e |
| 119 | 119 |
|
| 120 | 120 |
/// The upper bound of a constraint (row) is an |
| 121 | 121 |
/// extended number of type Value, i.e. a finite number of type |
| 122 | 122 |
/// Value or \ref INF. |
| 123 | 123 |
virtual Value _getRowUpperBound(int i) const; |
| 124 | 124 |
|
| 125 | 125 |
/// \e |
| 126 | 126 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 127 | 127 |
/// \e |
| 128 | 128 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 129 | 129 |
|
| 130 | 130 |
/// \e |
| 131 | 131 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 132 | 132 |
/// \e |
| 133 | 133 |
virtual Value _getObjCoeff(int i) const; |
| 134 | 134 |
|
| 135 | 135 |
///\e |
| 136 | 136 |
virtual void _setSense(Sense); |
| 137 | 137 |
///\e |
| 138 | 138 |
virtual Sense _getSense() const; |
| 139 | 139 |
|
| 140 | 140 |
///\e |
| 141 | 141 |
virtual void _clear(); |
| 142 | 142 |
|
| 143 |
///\e |
|
| 144 |
virtual void _messageLevel(MessageLevel); |
|
| 143 | 145 |
}; |
| 144 | 146 |
|
| 145 | 147 |
/// \brief Skeleton class for an LP solver interface |
| 146 | 148 |
/// |
| 147 | 149 |
///This class does nothing, but it can serve as a skeleton when |
| 148 | 150 |
///implementing an interface to new solvers. |
| 149 | 151 |
|
| 150 | 152 |
///\ingroup lp_group |
| 151 | 153 |
class LpSkeleton : public LpSolver, public SkeletonSolverBase {
|
| 152 | 154 |
public: |
| 153 | 155 |
///\e |
| 154 | 156 |
LpSkeleton() : LpSolver(), SkeletonSolverBase() {}
|
| 155 | 157 |
///\e |
| 156 | 158 |
virtual LpSkeleton* newSolver() const; |
| 157 | 159 |
///\e |
| 158 | 160 |
virtual LpSkeleton* cloneSolver() const; |
| 159 | 161 |
protected: |
| 160 | 162 |
|
| 161 | 163 |
///\e |
| 162 | 164 |
virtual SolveExitStatus _solve(); |
| 163 | 165 |
|
| 164 | 166 |
///\e |
| 165 | 167 |
virtual Value _getPrimal(int i) const; |
| 166 | 168 |
///\e |
| 167 | 169 |
virtual Value _getDual(int i) const; |
| 168 | 170 |
|
| 169 | 171 |
///\e |
| 170 | 172 |
virtual Value _getPrimalValue() const; |
| 171 | 173 |
|
| 172 | 174 |
///\e |
| 173 | 175 |
virtual Value _getPrimalRay(int i) const; |
| 174 | 176 |
///\e |
| 175 | 177 |
virtual Value _getDualRay(int i) const; |
| 176 | 178 |
|
| 177 | 179 |
///\e |
| 178 | 180 |
virtual ProblemType _getPrimalType() const; |
| 179 | 181 |
///\e |
| 180 | 182 |
virtual ProblemType _getDualType() const; |
| 181 | 183 |
|
| 182 | 184 |
///\e |
| 183 | 185 |
virtual VarStatus _getColStatus(int i) const; |
| 184 | 186 |
///\e |
| 185 | 187 |
virtual VarStatus _getRowStatus(int i) const; |
| 186 | 188 |
|
| 187 | 189 |
///\e |
| 188 | 190 |
virtual const char* _solverName() const; |
| 189 | 191 |
|
| 190 | 192 |
}; |
| ... | ... |
@@ -2683,98 +2683,98 @@ |
| 2683 | 2683 |
/// Gives back the out-degree of a Node. |
| 2684 | 2684 |
int operator[](const Key& key) const {
|
| 2685 | 2685 |
return _deg[key]; |
| 2686 | 2686 |
} |
| 2687 | 2687 |
|
| 2688 | 2688 |
protected: |
| 2689 | 2689 |
|
| 2690 | 2690 |
typedef typename Digraph::Arc Arc; |
| 2691 | 2691 |
|
| 2692 | 2692 |
virtual void add(const Arc& arc) {
|
| 2693 | 2693 |
++_deg[_digraph.source(arc)]; |
| 2694 | 2694 |
} |
| 2695 | 2695 |
|
| 2696 | 2696 |
virtual void add(const std::vector<Arc>& arcs) {
|
| 2697 | 2697 |
for (int i = 0; i < int(arcs.size()); ++i) {
|
| 2698 | 2698 |
++_deg[_digraph.source(arcs[i])]; |
| 2699 | 2699 |
} |
| 2700 | 2700 |
} |
| 2701 | 2701 |
|
| 2702 | 2702 |
virtual void erase(const Arc& arc) {
|
| 2703 | 2703 |
--_deg[_digraph.source(arc)]; |
| 2704 | 2704 |
} |
| 2705 | 2705 |
|
| 2706 | 2706 |
virtual void erase(const std::vector<Arc>& arcs) {
|
| 2707 | 2707 |
for (int i = 0; i < int(arcs.size()); ++i) {
|
| 2708 | 2708 |
--_deg[_digraph.source(arcs[i])]; |
| 2709 | 2709 |
} |
| 2710 | 2710 |
} |
| 2711 | 2711 |
|
| 2712 | 2712 |
virtual void build() {
|
| 2713 | 2713 |
for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
|
| 2714 | 2714 |
_deg[it] = countOutArcs(_digraph, it); |
| 2715 | 2715 |
} |
| 2716 | 2716 |
} |
| 2717 | 2717 |
|
| 2718 | 2718 |
virtual void clear() {
|
| 2719 | 2719 |
for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
|
| 2720 | 2720 |
_deg[it] = 0; |
| 2721 | 2721 |
} |
| 2722 | 2722 |
} |
| 2723 | 2723 |
private: |
| 2724 | 2724 |
|
| 2725 | 2725 |
const Digraph& _digraph; |
| 2726 | 2726 |
AutoNodeMap _deg; |
| 2727 | 2727 |
}; |
| 2728 | 2728 |
|
| 2729 | 2729 |
/// \brief Potential difference map |
| 2730 | 2730 |
/// |
| 2731 |
/// PotentialMap returns the difference between the potentials of the |
|
| 2732 |
/// source and target nodes of each arc in a digraph, i.e. it returns |
|
| 2731 |
/// PotentialDifferenceMap returns the difference between the potentials of |
|
| 2732 |
/// the source and target nodes of each arc in a digraph, i.e. it returns |
|
| 2733 | 2733 |
/// \code |
| 2734 | 2734 |
/// potential[gr.target(arc)] - potential[gr.source(arc)]. |
| 2735 | 2735 |
/// \endcode |
| 2736 | 2736 |
/// \tparam GR The digraph type. |
| 2737 | 2737 |
/// \tparam POT A node map storing the potentials. |
| 2738 | 2738 |
template <typename GR, typename POT> |
| 2739 | 2739 |
class PotentialDifferenceMap {
|
| 2740 | 2740 |
public: |
| 2741 | 2741 |
/// Key type |
| 2742 | 2742 |
typedef typename GR::Arc Key; |
| 2743 | 2743 |
/// Value type |
| 2744 | 2744 |
typedef typename POT::Value Value; |
| 2745 | 2745 |
|
| 2746 | 2746 |
/// \brief Constructor |
| 2747 | 2747 |
/// |
| 2748 | 2748 |
/// Contructor of the map. |
| 2749 | 2749 |
explicit PotentialDifferenceMap(const GR& gr, |
| 2750 | 2750 |
const POT& potential) |
| 2751 | 2751 |
: _digraph(gr), _potential(potential) {}
|
| 2752 | 2752 |
|
| 2753 | 2753 |
/// \brief Returns the potential difference for the given arc. |
| 2754 | 2754 |
/// |
| 2755 | 2755 |
/// Returns the potential difference for the given arc, i.e. |
| 2756 | 2756 |
/// \code |
| 2757 | 2757 |
/// potential[gr.target(arc)] - potential[gr.source(arc)]. |
| 2758 | 2758 |
/// \endcode |
| 2759 | 2759 |
Value operator[](const Key& arc) const {
|
| 2760 | 2760 |
return _potential[_digraph.target(arc)] - |
| 2761 | 2761 |
_potential[_digraph.source(arc)]; |
| 2762 | 2762 |
} |
| 2763 | 2763 |
|
| 2764 | 2764 |
private: |
| 2765 | 2765 |
const GR& _digraph; |
| 2766 | 2766 |
const POT& _potential; |
| 2767 | 2767 |
}; |
| 2768 | 2768 |
|
| 2769 | 2769 |
/// \brief Returns a PotentialDifferenceMap. |
| 2770 | 2770 |
/// |
| 2771 | 2771 |
/// This function just returns a PotentialDifferenceMap. |
| 2772 | 2772 |
/// \relates PotentialDifferenceMap |
| 2773 | 2773 |
template <typename GR, typename POT> |
| 2774 | 2774 |
PotentialDifferenceMap<GR, POT> |
| 2775 | 2775 |
potentialDifferenceMap(const GR& gr, const POT& potential) {
|
| 2776 | 2776 |
return PotentialDifferenceMap<GR, POT>(gr, potential); |
| 2777 | 2777 |
} |
| 2778 | 2778 |
|
| 2779 | 2779 |
/// @} |
| 2780 | 2780 |
} |
| ... | ... |
@@ -237,327 +237,327 @@ |
| 237 | 237 |
while (true) {
|
| 238 | 238 |
if ((*_matching)[left] == INVALID) break; |
| 239 | 239 |
left = _graph.target((*_matching)[left]); |
| 240 | 240 |
left = (*_blossom_rep)[_blossom_set-> |
| 241 | 241 |
find(_graph.target((*_ear)[left]))]; |
| 242 | 242 |
if (right_set.find(left) != right_set.end()) {
|
| 243 | 243 |
nca = left; |
| 244 | 244 |
break; |
| 245 | 245 |
} |
| 246 | 246 |
left_set.insert(left); |
| 247 | 247 |
|
| 248 | 248 |
if ((*_matching)[right] == INVALID) break; |
| 249 | 249 |
right = _graph.target((*_matching)[right]); |
| 250 | 250 |
right = (*_blossom_rep)[_blossom_set-> |
| 251 | 251 |
find(_graph.target((*_ear)[right]))]; |
| 252 | 252 |
if (left_set.find(right) != left_set.end()) {
|
| 253 | 253 |
nca = right; |
| 254 | 254 |
break; |
| 255 | 255 |
} |
| 256 | 256 |
right_set.insert(right); |
| 257 | 257 |
} |
| 258 | 258 |
|
| 259 | 259 |
if (nca == INVALID) {
|
| 260 | 260 |
if ((*_matching)[left] == INVALID) {
|
| 261 | 261 |
nca = right; |
| 262 | 262 |
while (left_set.find(nca) == left_set.end()) {
|
| 263 | 263 |
nca = _graph.target((*_matching)[nca]); |
| 264 | 264 |
nca =(*_blossom_rep)[_blossom_set-> |
| 265 | 265 |
find(_graph.target((*_ear)[nca]))]; |
| 266 | 266 |
} |
| 267 | 267 |
} else {
|
| 268 | 268 |
nca = left; |
| 269 | 269 |
while (right_set.find(nca) == right_set.end()) {
|
| 270 | 270 |
nca = _graph.target((*_matching)[nca]); |
| 271 | 271 |
nca = (*_blossom_rep)[_blossom_set-> |
| 272 | 272 |
find(_graph.target((*_ear)[nca]))]; |
| 273 | 273 |
} |
| 274 | 274 |
} |
| 275 | 275 |
} |
| 276 | 276 |
} |
| 277 | 277 |
|
| 278 | 278 |
{
|
| 279 | 279 |
|
| 280 | 280 |
Node node = _graph.u(e); |
| 281 | 281 |
Arc arc = _graph.direct(e, true); |
| 282 | 282 |
Node base = (*_blossom_rep)[_blossom_set->find(node)]; |
| 283 | 283 |
|
| 284 | 284 |
while (base != nca) {
|
| 285 |
_ear |
|
| 285 |
(*_ear)[node] = arc; |
|
| 286 | 286 |
|
| 287 | 287 |
Node n = node; |
| 288 | 288 |
while (n != base) {
|
| 289 | 289 |
n = _graph.target((*_matching)[n]); |
| 290 | 290 |
Arc a = (*_ear)[n]; |
| 291 | 291 |
n = _graph.target(a); |
| 292 |
_ear |
|
| 292 |
(*_ear)[n] = _graph.oppositeArc(a); |
|
| 293 | 293 |
} |
| 294 | 294 |
node = _graph.target((*_matching)[base]); |
| 295 | 295 |
_tree_set->erase(base); |
| 296 | 296 |
_tree_set->erase(node); |
| 297 | 297 |
_blossom_set->insert(node, _blossom_set->find(base)); |
| 298 |
_status |
|
| 298 |
(*_status)[node] = EVEN; |
|
| 299 | 299 |
_node_queue[_last++] = node; |
| 300 | 300 |
arc = _graph.oppositeArc((*_ear)[node]); |
| 301 | 301 |
node = _graph.target((*_ear)[node]); |
| 302 | 302 |
base = (*_blossom_rep)[_blossom_set->find(node)]; |
| 303 | 303 |
_blossom_set->join(_graph.target(arc), base); |
| 304 | 304 |
} |
| 305 | 305 |
} |
| 306 | 306 |
|
| 307 |
_blossom_rep |
|
| 307 |
(*_blossom_rep)[_blossom_set->find(nca)] = nca; |
|
| 308 | 308 |
|
| 309 | 309 |
{
|
| 310 | 310 |
|
| 311 | 311 |
Node node = _graph.v(e); |
| 312 | 312 |
Arc arc = _graph.direct(e, false); |
| 313 | 313 |
Node base = (*_blossom_rep)[_blossom_set->find(node)]; |
| 314 | 314 |
|
| 315 | 315 |
while (base != nca) {
|
| 316 |
_ear |
|
| 316 |
(*_ear)[node] = arc; |
|
| 317 | 317 |
|
| 318 | 318 |
Node n = node; |
| 319 | 319 |
while (n != base) {
|
| 320 | 320 |
n = _graph.target((*_matching)[n]); |
| 321 | 321 |
Arc a = (*_ear)[n]; |
| 322 | 322 |
n = _graph.target(a); |
| 323 |
_ear |
|
| 323 |
(*_ear)[n] = _graph.oppositeArc(a); |
|
| 324 | 324 |
} |
| 325 | 325 |
node = _graph.target((*_matching)[base]); |
| 326 | 326 |
_tree_set->erase(base); |
| 327 | 327 |
_tree_set->erase(node); |
| 328 | 328 |
_blossom_set->insert(node, _blossom_set->find(base)); |
| 329 |
_status |
|
| 329 |
(*_status)[node] = EVEN; |
|
| 330 | 330 |
_node_queue[_last++] = node; |
| 331 | 331 |
arc = _graph.oppositeArc((*_ear)[node]); |
| 332 | 332 |
node = _graph.target((*_ear)[node]); |
| 333 | 333 |
base = (*_blossom_rep)[_blossom_set->find(node)]; |
| 334 | 334 |
_blossom_set->join(_graph.target(arc), base); |
| 335 | 335 |
} |
| 336 | 336 |
} |
| 337 | 337 |
|
| 338 |
_blossom_rep |
|
| 338 |
(*_blossom_rep)[_blossom_set->find(nca)] = nca; |
|
| 339 | 339 |
} |
| 340 | 340 |
|
| 341 | 341 |
|
| 342 | 342 |
|
| 343 | 343 |
void extendOnArc(const Arc& a) {
|
| 344 | 344 |
Node base = _graph.source(a); |
| 345 | 345 |
Node odd = _graph.target(a); |
| 346 | 346 |
|
| 347 |
_ear |
|
| 347 |
(*_ear)[odd] = _graph.oppositeArc(a); |
|
| 348 | 348 |
Node even = _graph.target((*_matching)[odd]); |
| 349 |
_blossom_rep->set(_blossom_set->insert(even), even); |
|
| 350 |
_status->set(odd, ODD); |
|
| 351 |
|
|
| 349 |
(*_blossom_rep)[_blossom_set->insert(even)] = even; |
|
| 350 |
(*_status)[odd] = ODD; |
|
| 351 |
(*_status)[even] = EVEN; |
|
| 352 | 352 |
int tree = _tree_set->find((*_blossom_rep)[_blossom_set->find(base)]); |
| 353 | 353 |
_tree_set->insert(odd, tree); |
| 354 | 354 |
_tree_set->insert(even, tree); |
| 355 | 355 |
_node_queue[_last++] = even; |
| 356 | 356 |
|
| 357 | 357 |
} |
| 358 | 358 |
|
| 359 | 359 |
void augmentOnArc(const Arc& a) {
|
| 360 | 360 |
Node even = _graph.source(a); |
| 361 | 361 |
Node odd = _graph.target(a); |
| 362 | 362 |
|
| 363 | 363 |
int tree = _tree_set->find((*_blossom_rep)[_blossom_set->find(even)]); |
| 364 | 364 |
|
| 365 |
_matching->set(odd, _graph.oppositeArc(a)); |
|
| 366 |
_status->set(odd, MATCHED); |
|
| 365 |
(*_matching)[odd] = _graph.oppositeArc(a); |
|
| 366 |
(*_status)[odd] = MATCHED; |
|
| 367 | 367 |
|
| 368 | 368 |
Arc arc = (*_matching)[even]; |
| 369 |
_matching |
|
| 369 |
(*_matching)[even] = a; |
|
| 370 | 370 |
|
| 371 | 371 |
while (arc != INVALID) {
|
| 372 | 372 |
odd = _graph.target(arc); |
| 373 | 373 |
arc = (*_ear)[odd]; |
| 374 | 374 |
even = _graph.target(arc); |
| 375 |
_matching |
|
| 375 |
(*_matching)[odd] = arc; |
|
| 376 | 376 |
arc = (*_matching)[even]; |
| 377 |
_matching |
|
| 377 |
(*_matching)[even] = _graph.oppositeArc((*_matching)[odd]); |
|
| 378 | 378 |
} |
| 379 | 379 |
|
| 380 | 380 |
for (typename TreeSet::ItemIt it(*_tree_set, tree); |
| 381 | 381 |
it != INVALID; ++it) {
|
| 382 | 382 |
if ((*_status)[it] == ODD) {
|
| 383 |
_status |
|
| 383 |
(*_status)[it] = MATCHED; |
|
| 384 | 384 |
} else {
|
| 385 | 385 |
int blossom = _blossom_set->find(it); |
| 386 | 386 |
for (typename BlossomSet::ItemIt jt(*_blossom_set, blossom); |
| 387 | 387 |
jt != INVALID; ++jt) {
|
| 388 |
_status |
|
| 388 |
(*_status)[jt] = MATCHED; |
|
| 389 | 389 |
} |
| 390 | 390 |
_blossom_set->eraseClass(blossom); |
| 391 | 391 |
} |
| 392 | 392 |
} |
| 393 | 393 |
_tree_set->eraseClass(tree); |
| 394 | 394 |
|
| 395 | 395 |
} |
| 396 | 396 |
|
| 397 | 397 |
public: |
| 398 | 398 |
|
| 399 | 399 |
/// \brief Constructor |
| 400 | 400 |
/// |
| 401 | 401 |
/// Constructor. |
| 402 | 402 |
MaxMatching(const Graph& graph) |
| 403 | 403 |
: _graph(graph), _matching(0), _status(0), _ear(0), |
| 404 | 404 |
_blossom_set_index(0), _blossom_set(0), _blossom_rep(0), |
| 405 | 405 |
_tree_set_index(0), _tree_set(0) {}
|
| 406 | 406 |
|
| 407 | 407 |
~MaxMatching() {
|
| 408 | 408 |
destroyStructures(); |
| 409 | 409 |
} |
| 410 | 410 |
|
| 411 | 411 |
/// \name Execution control |
| 412 | 412 |
/// The simplest way to execute the algorithm is to use the |
| 413 | 413 |
/// \c run() member function. |
| 414 | 414 |
/// \n |
| 415 | 415 |
|
| 416 | 416 |
/// If you need better control on the execution, you must call |
| 417 | 417 |
/// \ref init(), \ref greedyInit() or \ref matchingInit() |
| 418 | 418 |
/// functions first, then you can start the algorithm with the \ref |
| 419 | 419 |
/// startSparse() or startDense() functions. |
| 420 | 420 |
|
| 421 | 421 |
///@{
|
| 422 | 422 |
|
| 423 | 423 |
/// \brief Sets the actual matching to the empty matching. |
| 424 | 424 |
/// |
| 425 | 425 |
/// Sets the actual matching to the empty matching. |
| 426 | 426 |
/// |
| 427 | 427 |
void init() {
|
| 428 | 428 |
createStructures(); |
| 429 | 429 |
for(NodeIt n(_graph); n != INVALID; ++n) {
|
| 430 |
_matching->set(n, INVALID); |
|
| 431 |
_status->set(n, UNMATCHED); |
|
| 430 |
(*_matching)[n] = INVALID; |
|
| 431 |
(*_status)[n] = UNMATCHED; |
|
| 432 | 432 |
} |
| 433 | 433 |
} |
| 434 | 434 |
|
| 435 | 435 |
///\brief Finds an initial matching in a greedy way |
| 436 | 436 |
/// |
| 437 | 437 |
///It finds an initial matching in a greedy way. |
| 438 | 438 |
void greedyInit() {
|
| 439 | 439 |
createStructures(); |
| 440 | 440 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 441 |
_matching->set(n, INVALID); |
|
| 442 |
_status->set(n, UNMATCHED); |
|
| 441 |
(*_matching)[n] = INVALID; |
|
| 442 |
(*_status)[n] = UNMATCHED; |
|
| 443 | 443 |
} |
| 444 | 444 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 445 | 445 |
if ((*_matching)[n] == INVALID) {
|
| 446 | 446 |
for (OutArcIt a(_graph, n); a != INVALID ; ++a) {
|
| 447 | 447 |
Node v = _graph.target(a); |
| 448 | 448 |
if ((*_matching)[v] == INVALID && v != n) {
|
| 449 |
_matching->set(n, a); |
|
| 450 |
_status->set(n, MATCHED); |
|
| 451 |
_matching->set(v, _graph.oppositeArc(a)); |
|
| 452 |
_status->set(v, MATCHED); |
|
| 449 |
(*_matching)[n] = a; |
|
| 450 |
(*_status)[n] = MATCHED; |
|
| 451 |
(*_matching)[v] = _graph.oppositeArc(a); |
|
| 452 |
(*_status)[v] = MATCHED; |
|
| 453 | 453 |
break; |
| 454 | 454 |
} |
| 455 | 455 |
} |
| 456 | 456 |
} |
| 457 | 457 |
} |
| 458 | 458 |
} |
| 459 | 459 |
|
| 460 | 460 |
|
| 461 | 461 |
/// \brief Initialize the matching from a map containing. |
| 462 | 462 |
/// |
| 463 | 463 |
/// Initialize the matching from a \c bool valued \c Edge map. This |
| 464 | 464 |
/// map must have the property that there are no two incident edges |
| 465 | 465 |
/// with true value, ie. it contains a matching. |
| 466 | 466 |
/// \return \c true if the map contains a matching. |
| 467 | 467 |
template <typename MatchingMap> |
| 468 | 468 |
bool matchingInit(const MatchingMap& matching) {
|
| 469 | 469 |
createStructures(); |
| 470 | 470 |
|
| 471 | 471 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 472 |
_matching->set(n, INVALID); |
|
| 473 |
_status->set(n, UNMATCHED); |
|
| 472 |
(*_matching)[n] = INVALID; |
|
| 473 |
(*_status)[n] = UNMATCHED; |
|
| 474 | 474 |
} |
| 475 | 475 |
for(EdgeIt e(_graph); e!=INVALID; ++e) {
|
| 476 | 476 |
if (matching[e]) {
|
| 477 | 477 |
|
| 478 | 478 |
Node u = _graph.u(e); |
| 479 | 479 |
if ((*_matching)[u] != INVALID) return false; |
| 480 |
_matching->set(u, _graph.direct(e, true)); |
|
| 481 |
_status->set(u, MATCHED); |
|
| 480 |
(*_matching)[u] = _graph.direct(e, true); |
|
| 481 |
(*_status)[u] = MATCHED; |
|
| 482 | 482 |
|
| 483 | 483 |
Node v = _graph.v(e); |
| 484 | 484 |
if ((*_matching)[v] != INVALID) return false; |
| 485 |
_matching->set(v, _graph.direct(e, false)); |
|
| 486 |
_status->set(v, MATCHED); |
|
| 485 |
(*_matching)[v] = _graph.direct(e, false); |
|
| 486 |
(*_status)[v] = MATCHED; |
|
| 487 | 487 |
} |
| 488 | 488 |
} |
| 489 | 489 |
return true; |
| 490 | 490 |
} |
| 491 | 491 |
|
| 492 | 492 |
/// \brief Starts Edmonds' algorithm |
| 493 | 493 |
/// |
| 494 | 494 |
/// If runs the original Edmonds' algorithm. |
| 495 | 495 |
void startSparse() {
|
| 496 | 496 |
for(NodeIt n(_graph); n != INVALID; ++n) {
|
| 497 | 497 |
if ((*_status)[n] == UNMATCHED) {
|
| 498 | 498 |
(*_blossom_rep)[_blossom_set->insert(n)] = n; |
| 499 | 499 |
_tree_set->insert(n); |
| 500 |
_status |
|
| 500 |
(*_status)[n] = EVEN; |
|
| 501 | 501 |
processSparse(n); |
| 502 | 502 |
} |
| 503 | 503 |
} |
| 504 | 504 |
} |
| 505 | 505 |
|
| 506 | 506 |
/// \brief Starts Edmonds' algorithm. |
| 507 | 507 |
/// |
| 508 | 508 |
/// It runs Edmonds' algorithm with a heuristic of postponing |
| 509 | 509 |
/// shrinks, therefore resulting in a faster algorithm for dense graphs. |
| 510 | 510 |
void startDense() {
|
| 511 | 511 |
for(NodeIt n(_graph); n != INVALID; ++n) {
|
| 512 | 512 |
if ((*_status)[n] == UNMATCHED) {
|
| 513 | 513 |
(*_blossom_rep)[_blossom_set->insert(n)] = n; |
| 514 | 514 |
_tree_set->insert(n); |
| 515 |
_status |
|
| 515 |
(*_status)[n] = EVEN; |
|
| 516 | 516 |
processDense(n); |
| 517 | 517 |
} |
| 518 | 518 |
} |
| 519 | 519 |
} |
| 520 | 520 |
|
| 521 | 521 |
|
| 522 | 522 |
/// \brief Runs Edmonds' algorithm |
| 523 | 523 |
/// |
| 524 | 524 |
/// Runs Edmonds' algorithm for sparse graphs (<tt>m<2*n</tt>) |
| 525 | 525 |
/// or Edmonds' algorithm with a heuristic of |
| 526 | 526 |
/// postponing shrinks for dense graphs. |
| 527 | 527 |
void run() {
|
| 528 | 528 |
if (countEdges(_graph) < 2 * countNodes(_graph)) {
|
| 529 | 529 |
greedyInit(); |
| 530 | 530 |
startSparse(); |
| 531 | 531 |
} else {
|
| 532 | 532 |
init(); |
| 533 | 533 |
startDense(); |
| 534 | 534 |
} |
| 535 | 535 |
} |
| 536 | 536 |
|
| 537 | 537 |
/// @} |
| 538 | 538 |
|
| 539 | 539 |
/// \name Primal solution |
| 540 | 540 |
/// Functions to get the primal solution, ie. the matching. |
| 541 | 541 |
|
| 542 | 542 |
/// @{
|
| 543 | 543 |
|
| 544 | 544 |
///\brief Returns the size of the current matching. |
| 545 | 545 |
/// |
| 546 | 546 |
///Returns the size of the current matching. After \ref |
| 547 | 547 |
///run() it returns the size of the maximum matching in the graph. |
| 548 | 548 |
int matchingSize() const {
|
| 549 | 549 |
int size = 0; |
| 550 | 550 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 551 | 551 |
if ((*_matching)[n] != INVALID) {
|
| 552 | 552 |
++size; |
| 553 | 553 |
} |
| 554 | 554 |
} |
| 555 | 555 |
return size / 2; |
| 556 | 556 |
} |
| 557 | 557 |
|
| 558 | 558 |
/// \brief Returns true when the edge is in the matching. |
| 559 | 559 |
/// |
| 560 | 560 |
/// Returns true when the edge is in the matching. |
| 561 | 561 |
bool matching(const Edge& edge) const {
|
| 562 | 562 |
return edge == (*_matching)[_graph.u(edge)]; |
| 563 | 563 |
} |
| ... | ... |
@@ -1503,215 +1503,215 @@ |
| 1503 | 1503 |
(*_blossom_data)[subblossoms[id]].next = next; |
| 1504 | 1504 |
(*_blossom_data)[subblossoms[id]].pred = pred; |
| 1505 | 1505 |
|
| 1506 | 1506 |
} else {
|
| 1507 | 1507 |
|
| 1508 | 1508 |
for (int i = (ib + 1) % subblossoms.size(); |
| 1509 | 1509 |
i != id; i = (i + 2) % subblossoms.size()) {
|
| 1510 | 1510 |
int sb = subblossoms[i]; |
| 1511 | 1511 |
int tb = subblossoms[(i + 1) % subblossoms.size()]; |
| 1512 | 1512 |
(*_blossom_data)[sb].next = |
| 1513 | 1513 |
_graph.oppositeArc((*_blossom_data)[tb].next); |
| 1514 | 1514 |
} |
| 1515 | 1515 |
|
| 1516 | 1516 |
for (int i = id; i != ib; i = (i + 2) % subblossoms.size()) {
|
| 1517 | 1517 |
int sb = subblossoms[i]; |
| 1518 | 1518 |
int tb = subblossoms[(i + 1) % subblossoms.size()]; |
| 1519 | 1519 |
int ub = subblossoms[(i + 2) % subblossoms.size()]; |
| 1520 | 1520 |
|
| 1521 | 1521 |
(*_blossom_data)[sb].status = ODD; |
| 1522 | 1522 |
matchedToOdd(sb); |
| 1523 | 1523 |
_tree_set->insert(sb, tree); |
| 1524 | 1524 |
(*_blossom_data)[sb].next = next; |
| 1525 | 1525 |
(*_blossom_data)[sb].pred = |
| 1526 | 1526 |
_graph.oppositeArc((*_blossom_data)[tb].next); |
| 1527 | 1527 |
|
| 1528 | 1528 |
(*_blossom_data)[tb].status = EVEN; |
| 1529 | 1529 |
matchedToEven(tb, tree); |
| 1530 | 1530 |
_tree_set->insert(tb, tree); |
| 1531 | 1531 |
(*_blossom_data)[tb].pred = |
| 1532 | 1532 |
(*_blossom_data)[tb].next = |
| 1533 | 1533 |
_graph.oppositeArc((*_blossom_data)[ub].next); |
| 1534 | 1534 |
next = (*_blossom_data)[ub].next; |
| 1535 | 1535 |
} |
| 1536 | 1536 |
|
| 1537 | 1537 |
(*_blossom_data)[subblossoms[ib]].status = ODD; |
| 1538 | 1538 |
matchedToOdd(subblossoms[ib]); |
| 1539 | 1539 |
_tree_set->insert(subblossoms[ib], tree); |
| 1540 | 1540 |
(*_blossom_data)[subblossoms[ib]].next = next; |
| 1541 | 1541 |
(*_blossom_data)[subblossoms[ib]].pred = pred; |
| 1542 | 1542 |
} |
| 1543 | 1543 |
_tree_set->erase(blossom); |
| 1544 | 1544 |
} |
| 1545 | 1545 |
|
| 1546 | 1546 |
void extractBlossom(int blossom, const Node& base, const Arc& matching) {
|
| 1547 | 1547 |
if (_blossom_set->trivial(blossom)) {
|
| 1548 | 1548 |
int bi = (*_node_index)[base]; |
| 1549 | 1549 |
Value pot = (*_node_data)[bi].pot; |
| 1550 | 1550 |
|
| 1551 |
_matching |
|
| 1551 |
(*_matching)[base] = matching; |
|
| 1552 | 1552 |
_blossom_node_list.push_back(base); |
| 1553 |
_node_potential |
|
| 1553 |
(*_node_potential)[base] = pot; |
|
| 1554 | 1554 |
} else {
|
| 1555 | 1555 |
|
| 1556 | 1556 |
Value pot = (*_blossom_data)[blossom].pot; |
| 1557 | 1557 |
int bn = _blossom_node_list.size(); |
| 1558 | 1558 |
|
| 1559 | 1559 |
std::vector<int> subblossoms; |
| 1560 | 1560 |
_blossom_set->split(blossom, std::back_inserter(subblossoms)); |
| 1561 | 1561 |
int b = _blossom_set->find(base); |
| 1562 | 1562 |
int ib = -1; |
| 1563 | 1563 |
for (int i = 0; i < int(subblossoms.size()); ++i) {
|
| 1564 | 1564 |
if (subblossoms[i] == b) { ib = i; break; }
|
| 1565 | 1565 |
} |
| 1566 | 1566 |
|
| 1567 | 1567 |
for (int i = 1; i < int(subblossoms.size()); i += 2) {
|
| 1568 | 1568 |
int sb = subblossoms[(ib + i) % subblossoms.size()]; |
| 1569 | 1569 |
int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
| 1570 | 1570 |
|
| 1571 | 1571 |
Arc m = (*_blossom_data)[tb].next; |
| 1572 | 1572 |
extractBlossom(sb, _graph.target(m), _graph.oppositeArc(m)); |
| 1573 | 1573 |
extractBlossom(tb, _graph.source(m), m); |
| 1574 | 1574 |
} |
| 1575 | 1575 |
extractBlossom(subblossoms[ib], base, matching); |
| 1576 | 1576 |
|
| 1577 | 1577 |
int en = _blossom_node_list.size(); |
| 1578 | 1578 |
|
| 1579 | 1579 |
_blossom_potential.push_back(BlossomVariable(bn, en, pot)); |
| 1580 | 1580 |
} |
| 1581 | 1581 |
} |
| 1582 | 1582 |
|
| 1583 | 1583 |
void extractMatching() {
|
| 1584 | 1584 |
std::vector<int> blossoms; |
| 1585 | 1585 |
for (typename BlossomSet::ClassIt c(*_blossom_set); c != INVALID; ++c) {
|
| 1586 | 1586 |
blossoms.push_back(c); |
| 1587 | 1587 |
} |
| 1588 | 1588 |
|
| 1589 | 1589 |
for (int i = 0; i < int(blossoms.size()); ++i) {
|
| 1590 | 1590 |
if ((*_blossom_data)[blossoms[i]].status == MATCHED) {
|
| 1591 | 1591 |
|
| 1592 | 1592 |
Value offset = (*_blossom_data)[blossoms[i]].offset; |
| 1593 | 1593 |
(*_blossom_data)[blossoms[i]].pot += 2 * offset; |
| 1594 | 1594 |
for (typename BlossomSet::ItemIt n(*_blossom_set, blossoms[i]); |
| 1595 | 1595 |
n != INVALID; ++n) {
|
| 1596 | 1596 |
(*_node_data)[(*_node_index)[n]].pot -= offset; |
| 1597 | 1597 |
} |
| 1598 | 1598 |
|
| 1599 | 1599 |
Arc matching = (*_blossom_data)[blossoms[i]].next; |
| 1600 | 1600 |
Node base = _graph.source(matching); |
| 1601 | 1601 |
extractBlossom(blossoms[i], base, matching); |
| 1602 | 1602 |
} else {
|
| 1603 | 1603 |
Node base = (*_blossom_data)[blossoms[i]].base; |
| 1604 | 1604 |
extractBlossom(blossoms[i], base, INVALID); |
| 1605 | 1605 |
} |
| 1606 | 1606 |
} |
| 1607 | 1607 |
} |
| 1608 | 1608 |
|
| 1609 | 1609 |
public: |
| 1610 | 1610 |
|
| 1611 | 1611 |
/// \brief Constructor |
| 1612 | 1612 |
/// |
| 1613 | 1613 |
/// Constructor. |
| 1614 | 1614 |
MaxWeightedMatching(const Graph& graph, const WeightMap& weight) |
| 1615 | 1615 |
: _graph(graph), _weight(weight), _matching(0), |
| 1616 | 1616 |
_node_potential(0), _blossom_potential(), _blossom_node_list(), |
| 1617 | 1617 |
_node_num(0), _blossom_num(0), |
| 1618 | 1618 |
|
| 1619 | 1619 |
_blossom_index(0), _blossom_set(0), _blossom_data(0), |
| 1620 | 1620 |
_node_index(0), _node_heap_index(0), _node_data(0), |
| 1621 | 1621 |
_tree_set_index(0), _tree_set(0), |
| 1622 | 1622 |
|
| 1623 | 1623 |
_delta1_index(0), _delta1(0), |
| 1624 | 1624 |
_delta2_index(0), _delta2(0), |
| 1625 | 1625 |
_delta3_index(0), _delta3(0), |
| 1626 | 1626 |
_delta4_index(0), _delta4(0), |
| 1627 | 1627 |
|
| 1628 | 1628 |
_delta_sum() {}
|
| 1629 | 1629 |
|
| 1630 | 1630 |
~MaxWeightedMatching() {
|
| 1631 | 1631 |
destroyStructures(); |
| 1632 | 1632 |
} |
| 1633 | 1633 |
|
| 1634 | 1634 |
/// \name Execution control |
| 1635 | 1635 |
/// The simplest way to execute the algorithm is to use the |
| 1636 | 1636 |
/// \c run() member function. |
| 1637 | 1637 |
|
| 1638 | 1638 |
///@{
|
| 1639 | 1639 |
|
| 1640 | 1640 |
/// \brief Initialize the algorithm |
| 1641 | 1641 |
/// |
| 1642 | 1642 |
/// Initialize the algorithm |
| 1643 | 1643 |
void init() {
|
| 1644 | 1644 |
createStructures(); |
| 1645 | 1645 |
|
| 1646 | 1646 |
for (ArcIt e(_graph); e != INVALID; ++e) {
|
| 1647 |
_node_heap_index |
|
| 1647 |
(*_node_heap_index)[e] = BinHeap<Value, IntArcMap>::PRE_HEAP; |
|
| 1648 | 1648 |
} |
| 1649 | 1649 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 1650 |
_delta1_index |
|
| 1650 |
(*_delta1_index)[n] = _delta1->PRE_HEAP; |
|
| 1651 | 1651 |
} |
| 1652 | 1652 |
for (EdgeIt e(_graph); e != INVALID; ++e) {
|
| 1653 |
_delta3_index |
|
| 1653 |
(*_delta3_index)[e] = _delta3->PRE_HEAP; |
|
| 1654 | 1654 |
} |
| 1655 | 1655 |
for (int i = 0; i < _blossom_num; ++i) {
|
| 1656 |
_delta2_index->set(i, _delta2->PRE_HEAP); |
|
| 1657 |
_delta4_index->set(i, _delta4->PRE_HEAP); |
|
| 1656 |
(*_delta2_index)[i] = _delta2->PRE_HEAP; |
|
| 1657 |
(*_delta4_index)[i] = _delta4->PRE_HEAP; |
|
| 1658 | 1658 |
} |
| 1659 | 1659 |
|
| 1660 | 1660 |
int index = 0; |
| 1661 | 1661 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 1662 | 1662 |
Value max = 0; |
| 1663 | 1663 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 1664 | 1664 |
if (_graph.target(e) == n) continue; |
| 1665 | 1665 |
if ((dualScale * _weight[e]) / 2 > max) {
|
| 1666 | 1666 |
max = (dualScale * _weight[e]) / 2; |
| 1667 | 1667 |
} |
| 1668 | 1668 |
} |
| 1669 |
_node_index |
|
| 1669 |
(*_node_index)[n] = index; |
|
| 1670 | 1670 |
(*_node_data)[index].pot = max; |
| 1671 | 1671 |
_delta1->push(n, max); |
| 1672 | 1672 |
int blossom = |
| 1673 | 1673 |
_blossom_set->insert(n, std::numeric_limits<Value>::max()); |
| 1674 | 1674 |
|
| 1675 | 1675 |
_tree_set->insert(blossom); |
| 1676 | 1676 |
|
| 1677 | 1677 |
(*_blossom_data)[blossom].status = EVEN; |
| 1678 | 1678 |
(*_blossom_data)[blossom].pred = INVALID; |
| 1679 | 1679 |
(*_blossom_data)[blossom].next = INVALID; |
| 1680 | 1680 |
(*_blossom_data)[blossom].pot = 0; |
| 1681 | 1681 |
(*_blossom_data)[blossom].offset = 0; |
| 1682 | 1682 |
++index; |
| 1683 | 1683 |
} |
| 1684 | 1684 |
for (EdgeIt e(_graph); e != INVALID; ++e) {
|
| 1685 | 1685 |
int si = (*_node_index)[_graph.u(e)]; |
| 1686 | 1686 |
int ti = (*_node_index)[_graph.v(e)]; |
| 1687 | 1687 |
if (_graph.u(e) != _graph.v(e)) {
|
| 1688 | 1688 |
_delta3->push(e, ((*_node_data)[si].pot + (*_node_data)[ti].pot - |
| 1689 | 1689 |
dualScale * _weight[e]) / 2); |
| 1690 | 1690 |
} |
| 1691 | 1691 |
} |
| 1692 | 1692 |
} |
| 1693 | 1693 |
|
| 1694 | 1694 |
/// \brief Starts the algorithm |
| 1695 | 1695 |
/// |
| 1696 | 1696 |
/// Starts the algorithm |
| 1697 | 1697 |
void start() {
|
| 1698 | 1698 |
enum OpType {
|
| 1699 | 1699 |
D1, D2, D3, D4 |
| 1700 | 1700 |
}; |
| 1701 | 1701 |
|
| 1702 | 1702 |
int unmatched = _node_num; |
| 1703 | 1703 |
while (unmatched > 0) {
|
| 1704 | 1704 |
Value d1 = !_delta1->empty() ? |
| 1705 | 1705 |
_delta1->prio() : std::numeric_limits<Value>::max(); |
| 1706 | 1706 |
|
| 1707 | 1707 |
Value d2 = !_delta2->empty() ? |
| 1708 | 1708 |
_delta2->prio() : std::numeric_limits<Value>::max(); |
| 1709 | 1709 |
|
| 1710 | 1710 |
Value d3 = !_delta3->empty() ? |
| 1711 | 1711 |
_delta3->prio() : std::numeric_limits<Value>::max(); |
| 1712 | 1712 |
|
| 1713 | 1713 |
Value d4 = !_delta4->empty() ? |
| 1714 | 1714 |
_delta4->prio() : std::numeric_limits<Value>::max(); |
| 1715 | 1715 |
|
| 1716 | 1716 |
_delta_sum = d1; OpType ot = D1; |
| 1717 | 1717 |
if (d2 < _delta_sum) { _delta_sum = d2; ot = D2; }
|
| ... | ... |
@@ -2696,206 +2696,206 @@ |
| 2696 | 2696 |
(*_blossom_data)[subblossoms[id]].next = next; |
| 2697 | 2697 |
(*_blossom_data)[subblossoms[id]].pred = pred; |
| 2698 | 2698 |
|
| 2699 | 2699 |
} else {
|
| 2700 | 2700 |
|
| 2701 | 2701 |
for (int i = (ib + 1) % subblossoms.size(); |
| 2702 | 2702 |
i != id; i = (i + 2) % subblossoms.size()) {
|
| 2703 | 2703 |
int sb = subblossoms[i]; |
| 2704 | 2704 |
int tb = subblossoms[(i + 1) % subblossoms.size()]; |
| 2705 | 2705 |
(*_blossom_data)[sb].next = |
| 2706 | 2706 |
_graph.oppositeArc((*_blossom_data)[tb].next); |
| 2707 | 2707 |
} |
| 2708 | 2708 |
|
| 2709 | 2709 |
for (int i = id; i != ib; i = (i + 2) % subblossoms.size()) {
|
| 2710 | 2710 |
int sb = subblossoms[i]; |
| 2711 | 2711 |
int tb = subblossoms[(i + 1) % subblossoms.size()]; |
| 2712 | 2712 |
int ub = subblossoms[(i + 2) % subblossoms.size()]; |
| 2713 | 2713 |
|
| 2714 | 2714 |
(*_blossom_data)[sb].status = ODD; |
| 2715 | 2715 |
matchedToOdd(sb); |
| 2716 | 2716 |
_tree_set->insert(sb, tree); |
| 2717 | 2717 |
(*_blossom_data)[sb].next = next; |
| 2718 | 2718 |
(*_blossom_data)[sb].pred = |
| 2719 | 2719 |
_graph.oppositeArc((*_blossom_data)[tb].next); |
| 2720 | 2720 |
|
| 2721 | 2721 |
(*_blossom_data)[tb].status = EVEN; |
| 2722 | 2722 |
matchedToEven(tb, tree); |
| 2723 | 2723 |
_tree_set->insert(tb, tree); |
| 2724 | 2724 |
(*_blossom_data)[tb].pred = |
| 2725 | 2725 |
(*_blossom_data)[tb].next = |
| 2726 | 2726 |
_graph.oppositeArc((*_blossom_data)[ub].next); |
| 2727 | 2727 |
next = (*_blossom_data)[ub].next; |
| 2728 | 2728 |
} |
| 2729 | 2729 |
|
| 2730 | 2730 |
(*_blossom_data)[subblossoms[ib]].status = ODD; |
| 2731 | 2731 |
matchedToOdd(subblossoms[ib]); |
| 2732 | 2732 |
_tree_set->insert(subblossoms[ib], tree); |
| 2733 | 2733 |
(*_blossom_data)[subblossoms[ib]].next = next; |
| 2734 | 2734 |
(*_blossom_data)[subblossoms[ib]].pred = pred; |
| 2735 | 2735 |
} |
| 2736 | 2736 |
_tree_set->erase(blossom); |
| 2737 | 2737 |
} |
| 2738 | 2738 |
|
| 2739 | 2739 |
void extractBlossom(int blossom, const Node& base, const Arc& matching) {
|
| 2740 | 2740 |
if (_blossom_set->trivial(blossom)) {
|
| 2741 | 2741 |
int bi = (*_node_index)[base]; |
| 2742 | 2742 |
Value pot = (*_node_data)[bi].pot; |
| 2743 | 2743 |
|
| 2744 |
_matching |
|
| 2744 |
(*_matching)[base] = matching; |
|
| 2745 | 2745 |
_blossom_node_list.push_back(base); |
| 2746 |
_node_potential |
|
| 2746 |
(*_node_potential)[base] = pot; |
|
| 2747 | 2747 |
} else {
|
| 2748 | 2748 |
|
| 2749 | 2749 |
Value pot = (*_blossom_data)[blossom].pot; |
| 2750 | 2750 |
int bn = _blossom_node_list.size(); |
| 2751 | 2751 |
|
| 2752 | 2752 |
std::vector<int> subblossoms; |
| 2753 | 2753 |
_blossom_set->split(blossom, std::back_inserter(subblossoms)); |
| 2754 | 2754 |
int b = _blossom_set->find(base); |
| 2755 | 2755 |
int ib = -1; |
| 2756 | 2756 |
for (int i = 0; i < int(subblossoms.size()); ++i) {
|
| 2757 | 2757 |
if (subblossoms[i] == b) { ib = i; break; }
|
| 2758 | 2758 |
} |
| 2759 | 2759 |
|
| 2760 | 2760 |
for (int i = 1; i < int(subblossoms.size()); i += 2) {
|
| 2761 | 2761 |
int sb = subblossoms[(ib + i) % subblossoms.size()]; |
| 2762 | 2762 |
int tb = subblossoms[(ib + i + 1) % subblossoms.size()]; |
| 2763 | 2763 |
|
| 2764 | 2764 |
Arc m = (*_blossom_data)[tb].next; |
| 2765 | 2765 |
extractBlossom(sb, _graph.target(m), _graph.oppositeArc(m)); |
| 2766 | 2766 |
extractBlossom(tb, _graph.source(m), m); |
| 2767 | 2767 |
} |
| 2768 | 2768 |
extractBlossom(subblossoms[ib], base, matching); |
| 2769 | 2769 |
|
| 2770 | 2770 |
int en = _blossom_node_list.size(); |
| 2771 | 2771 |
|
| 2772 | 2772 |
_blossom_potential.push_back(BlossomVariable(bn, en, pot)); |
| 2773 | 2773 |
} |
| 2774 | 2774 |
} |
| 2775 | 2775 |
|
| 2776 | 2776 |
void extractMatching() {
|
| 2777 | 2777 |
std::vector<int> blossoms; |
| 2778 | 2778 |
for (typename BlossomSet::ClassIt c(*_blossom_set); c != INVALID; ++c) {
|
| 2779 | 2779 |
blossoms.push_back(c); |
| 2780 | 2780 |
} |
| 2781 | 2781 |
|
| 2782 | 2782 |
for (int i = 0; i < int(blossoms.size()); ++i) {
|
| 2783 | 2783 |
|
| 2784 | 2784 |
Value offset = (*_blossom_data)[blossoms[i]].offset; |
| 2785 | 2785 |
(*_blossom_data)[blossoms[i]].pot += 2 * offset; |
| 2786 | 2786 |
for (typename BlossomSet::ItemIt n(*_blossom_set, blossoms[i]); |
| 2787 | 2787 |
n != INVALID; ++n) {
|
| 2788 | 2788 |
(*_node_data)[(*_node_index)[n]].pot -= offset; |
| 2789 | 2789 |
} |
| 2790 | 2790 |
|
| 2791 | 2791 |
Arc matching = (*_blossom_data)[blossoms[i]].next; |
| 2792 | 2792 |
Node base = _graph.source(matching); |
| 2793 | 2793 |
extractBlossom(blossoms[i], base, matching); |
| 2794 | 2794 |
} |
| 2795 | 2795 |
} |
| 2796 | 2796 |
|
| 2797 | 2797 |
public: |
| 2798 | 2798 |
|
| 2799 | 2799 |
/// \brief Constructor |
| 2800 | 2800 |
/// |
| 2801 | 2801 |
/// Constructor. |
| 2802 | 2802 |
MaxWeightedPerfectMatching(const Graph& graph, const WeightMap& weight) |
| 2803 | 2803 |
: _graph(graph), _weight(weight), _matching(0), |
| 2804 | 2804 |
_node_potential(0), _blossom_potential(), _blossom_node_list(), |
| 2805 | 2805 |
_node_num(0), _blossom_num(0), |
| 2806 | 2806 |
|
| 2807 | 2807 |
_blossom_index(0), _blossom_set(0), _blossom_data(0), |
| 2808 | 2808 |
_node_index(0), _node_heap_index(0), _node_data(0), |
| 2809 | 2809 |
_tree_set_index(0), _tree_set(0), |
| 2810 | 2810 |
|
| 2811 | 2811 |
_delta2_index(0), _delta2(0), |
| 2812 | 2812 |
_delta3_index(0), _delta3(0), |
| 2813 | 2813 |
_delta4_index(0), _delta4(0), |
| 2814 | 2814 |
|
| 2815 | 2815 |
_delta_sum() {}
|
| 2816 | 2816 |
|
| 2817 | 2817 |
~MaxWeightedPerfectMatching() {
|
| 2818 | 2818 |
destroyStructures(); |
| 2819 | 2819 |
} |
| 2820 | 2820 |
|
| 2821 | 2821 |
/// \name Execution control |
| 2822 | 2822 |
/// The simplest way to execute the algorithm is to use the |
| 2823 | 2823 |
/// \c run() member function. |
| 2824 | 2824 |
|
| 2825 | 2825 |
///@{
|
| 2826 | 2826 |
|
| 2827 | 2827 |
/// \brief Initialize the algorithm |
| 2828 | 2828 |
/// |
| 2829 | 2829 |
/// Initialize the algorithm |
| 2830 | 2830 |
void init() {
|
| 2831 | 2831 |
createStructures(); |
| 2832 | 2832 |
|
| 2833 | 2833 |
for (ArcIt e(_graph); e != INVALID; ++e) {
|
| 2834 |
_node_heap_index |
|
| 2834 |
(*_node_heap_index)[e] = BinHeap<Value, IntArcMap>::PRE_HEAP; |
|
| 2835 | 2835 |
} |
| 2836 | 2836 |
for (EdgeIt e(_graph); e != INVALID; ++e) {
|
| 2837 |
_delta3_index |
|
| 2837 |
(*_delta3_index)[e] = _delta3->PRE_HEAP; |
|
| 2838 | 2838 |
} |
| 2839 | 2839 |
for (int i = 0; i < _blossom_num; ++i) {
|
| 2840 |
_delta2_index->set(i, _delta2->PRE_HEAP); |
|
| 2841 |
_delta4_index->set(i, _delta4->PRE_HEAP); |
|
| 2840 |
(*_delta2_index)[i] = _delta2->PRE_HEAP; |
|
| 2841 |
(*_delta4_index)[i] = _delta4->PRE_HEAP; |
|
| 2842 | 2842 |
} |
| 2843 | 2843 |
|
| 2844 | 2844 |
int index = 0; |
| 2845 | 2845 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 2846 | 2846 |
Value max = - std::numeric_limits<Value>::max(); |
| 2847 | 2847 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 2848 | 2848 |
if (_graph.target(e) == n) continue; |
| 2849 | 2849 |
if ((dualScale * _weight[e]) / 2 > max) {
|
| 2850 | 2850 |
max = (dualScale * _weight[e]) / 2; |
| 2851 | 2851 |
} |
| 2852 | 2852 |
} |
| 2853 |
_node_index |
|
| 2853 |
(*_node_index)[n] = index; |
|
| 2854 | 2854 |
(*_node_data)[index].pot = max; |
| 2855 | 2855 |
int blossom = |
| 2856 | 2856 |
_blossom_set->insert(n, std::numeric_limits<Value>::max()); |
| 2857 | 2857 |
|
| 2858 | 2858 |
_tree_set->insert(blossom); |
| 2859 | 2859 |
|
| 2860 | 2860 |
(*_blossom_data)[blossom].status = EVEN; |
| 2861 | 2861 |
(*_blossom_data)[blossom].pred = INVALID; |
| 2862 | 2862 |
(*_blossom_data)[blossom].next = INVALID; |
| 2863 | 2863 |
(*_blossom_data)[blossom].pot = 0; |
| 2864 | 2864 |
(*_blossom_data)[blossom].offset = 0; |
| 2865 | 2865 |
++index; |
| 2866 | 2866 |
} |
| 2867 | 2867 |
for (EdgeIt e(_graph); e != INVALID; ++e) {
|
| 2868 | 2868 |
int si = (*_node_index)[_graph.u(e)]; |
| 2869 | 2869 |
int ti = (*_node_index)[_graph.v(e)]; |
| 2870 | 2870 |
if (_graph.u(e) != _graph.v(e)) {
|
| 2871 | 2871 |
_delta3->push(e, ((*_node_data)[si].pot + (*_node_data)[ti].pot - |
| 2872 | 2872 |
dualScale * _weight[e]) / 2); |
| 2873 | 2873 |
} |
| 2874 | 2874 |
} |
| 2875 | 2875 |
} |
| 2876 | 2876 |
|
| 2877 | 2877 |
/// \brief Starts the algorithm |
| 2878 | 2878 |
/// |
| 2879 | 2879 |
/// Starts the algorithm |
| 2880 | 2880 |
bool start() {
|
| 2881 | 2881 |
enum OpType {
|
| 2882 | 2882 |
D2, D3, D4 |
| 2883 | 2883 |
}; |
| 2884 | 2884 |
|
| 2885 | 2885 |
int unmatched = _node_num; |
| 2886 | 2886 |
while (unmatched > 0) {
|
| 2887 | 2887 |
Value d2 = !_delta2->empty() ? |
| 2888 | 2888 |
_delta2->prio() : std::numeric_limits<Value>::max(); |
| 2889 | 2889 |
|
| 2890 | 2890 |
Value d3 = !_delta3->empty() ? |
| 2891 | 2891 |
_delta3->prio() : std::numeric_limits<Value>::max(); |
| 2892 | 2892 |
|
| 2893 | 2893 |
Value d4 = !_delta4->empty() ? |
| 2894 | 2894 |
_delta4->prio() : std::numeric_limits<Value>::max(); |
| 2895 | 2895 |
|
| 2896 | 2896 |
_delta_sum = d2; OpType ot = D2; |
| 2897 | 2897 |
if (d3 < _delta_sum) { _delta_sum = d3; ot = D3; }
|
| 2898 | 2898 |
if (d4 < _delta_sum) { _delta_sum = d4; ot = D4; }
|
| 2899 | 2899 |
|
| 2900 | 2900 |
if (_delta_sum == std::numeric_limits<Value>::max()) {
|
| 2901 | 2901 |
return false; |
| ... | ... |
@@ -45,100 +45,100 @@ |
| 45 | 45 |
|
| 46 | 46 |
/// \brief The type of the map that stores the arc costs. |
| 47 | 47 |
/// |
| 48 | 48 |
/// The type of the map that stores the arc costs. |
| 49 | 49 |
/// It must meet the \ref concepts::ReadMap "ReadMap" concept. |
| 50 | 50 |
typedef CM CostMap; |
| 51 | 51 |
|
| 52 | 52 |
/// \brief The value type of the costs. |
| 53 | 53 |
/// |
| 54 | 54 |
/// The value type of the costs. |
| 55 | 55 |
typedef typename CostMap::Value Value; |
| 56 | 56 |
|
| 57 | 57 |
/// \brief The type of the map that stores which arcs are in the |
| 58 | 58 |
/// arborescence. |
| 59 | 59 |
/// |
| 60 | 60 |
/// The type of the map that stores which arcs are in the |
| 61 | 61 |
/// arborescence. It must meet the \ref concepts::WriteMap |
| 62 | 62 |
/// "WriteMap" concept. Initially it will be set to false on each |
| 63 | 63 |
/// arc. After it will set all arborescence arcs once. |
| 64 | 64 |
typedef typename Digraph::template ArcMap<bool> ArborescenceMap; |
| 65 | 65 |
|
| 66 | 66 |
/// \brief Instantiates a \c ArborescenceMap. |
| 67 | 67 |
/// |
| 68 | 68 |
/// This function instantiates a \c ArborescenceMap. |
| 69 | 69 |
/// \param digraph is the graph, to which we would like to |
| 70 | 70 |
/// calculate the \c ArborescenceMap. |
| 71 | 71 |
static ArborescenceMap *createArborescenceMap(const Digraph &digraph){
|
| 72 | 72 |
return new ArborescenceMap(digraph); |
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 | 75 |
/// \brief The type of the \c PredMap |
| 76 | 76 |
/// |
| 77 | 77 |
/// The type of the \c PredMap. It is a node map with an arc value type. |
| 78 | 78 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
| 79 | 79 |
|
| 80 | 80 |
/// \brief Instantiates a \c PredMap. |
| 81 | 81 |
/// |
| 82 | 82 |
/// This function instantiates a \c PredMap. |
| 83 | 83 |
/// \param digraph The digraph to which we would like to define the |
| 84 | 84 |
/// \c PredMap. |
| 85 | 85 |
static PredMap *createPredMap(const Digraph &digraph){
|
| 86 | 86 |
return new PredMap(digraph); |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
}; |
| 90 | 90 |
|
| 91 | 91 |
/// \ingroup spantree |
| 92 | 92 |
/// |
| 93 |
/// \brief |
|
| 93 |
/// \brief Minimum Cost Arborescence algorithm class. |
|
| 94 | 94 |
/// |
| 95 | 95 |
/// This class provides an efficient implementation of |
| 96 |
/// |
|
| 96 |
/// Minimum Cost Arborescence algorithm. The arborescence is a tree |
|
| 97 | 97 |
/// which is directed from a given source node of the digraph. One or |
| 98 | 98 |
/// more sources should be given for the algorithm and it will calculate |
| 99 | 99 |
/// the minimum cost subgraph which are union of arborescences with the |
| 100 | 100 |
/// given sources and spans all the nodes which are reachable from the |
| 101 | 101 |
/// sources. The time complexity of the algorithm is O(n<sup>2</sup>+e). |
| 102 | 102 |
/// |
| 103 | 103 |
/// The algorithm provides also an optimal dual solution, therefore |
| 104 | 104 |
/// the optimality of the solution can be checked. |
| 105 | 105 |
/// |
| 106 | 106 |
/// \param GR The digraph type the algorithm runs on. The default value |
| 107 | 107 |
/// is \ref ListDigraph. |
| 108 | 108 |
/// \param CM This read-only ArcMap determines the costs of the |
| 109 | 109 |
/// arcs. It is read once for each arc, so the map may involve in |
| 110 | 110 |
/// relatively time consuming process to compute the arc cost if |
| 111 | 111 |
/// it is necessary. The default map type is \ref |
| 112 | 112 |
/// concepts::Digraph::ArcMap "Digraph::ArcMap<int>". |
| 113 | 113 |
/// \param TR Traits class to set various data types used |
| 114 | 114 |
/// by the algorithm. The default traits class is |
| 115 | 115 |
/// \ref MinCostArborescenceDefaultTraits |
| 116 | 116 |
/// "MinCostArborescenceDefaultTraits<GR, CM>". See \ref |
| 117 | 117 |
/// MinCostArborescenceDefaultTraits for the documentation of a |
| 118 | 118 |
/// MinCostArborescence traits class. |
| 119 | 119 |
#ifndef DOXYGEN |
| 120 | 120 |
template <typename GR = ListDigraph, |
| 121 | 121 |
typename CM = typename GR::template ArcMap<int>, |
| 122 | 122 |
typename TR = |
| 123 | 123 |
MinCostArborescenceDefaultTraits<GR, CM> > |
| 124 | 124 |
#else |
| 125 | 125 |
template <typename GR, typename CM, typedef TR> |
| 126 | 126 |
#endif |
| 127 | 127 |
class MinCostArborescence {
|
| 128 | 128 |
public: |
| 129 | 129 |
|
| 130 | 130 |
/// The traits. |
| 131 | 131 |
typedef TR Traits; |
| 132 | 132 |
/// The type of the underlying digraph. |
| 133 | 133 |
typedef typename Traits::Digraph Digraph; |
| 134 | 134 |
/// The type of the map that stores the arc costs. |
| 135 | 135 |
typedef typename Traits::CostMap CostMap; |
| 136 | 136 |
///The type of the costs of the arcs. |
| 137 | 137 |
typedef typename Traits::Value Value; |
| 138 | 138 |
///The type of the predecessor map. |
| 139 | 139 |
typedef typename Traits::PredMap PredMap; |
| 140 | 140 |
///The type of the map that stores which arcs are in the arborescence. |
| 141 | 141 |
typedef typename Traits::ArborescenceMap ArborescenceMap; |
| 142 | 142 |
|
| 143 | 143 |
typedef MinCostArborescence Create; |
| 144 | 144 |
|
| ... | ... |
@@ -248,194 +248,194 @@ |
| 248 | 248 |
if (local_pred) {
|
| 249 | 249 |
delete _pred; |
| 250 | 250 |
} |
| 251 | 251 |
if (_arc_order) {
|
| 252 | 252 |
delete _arc_order; |
| 253 | 253 |
} |
| 254 | 254 |
if (_node_order) {
|
| 255 | 255 |
delete _node_order; |
| 256 | 256 |
} |
| 257 | 257 |
if (_cost_arcs) {
|
| 258 | 258 |
delete _cost_arcs; |
| 259 | 259 |
} |
| 260 | 260 |
if (_heap) {
|
| 261 | 261 |
delete _heap; |
| 262 | 262 |
} |
| 263 | 263 |
if (_heap_cross_ref) {
|
| 264 | 264 |
delete _heap_cross_ref; |
| 265 | 265 |
} |
| 266 | 266 |
} |
| 267 | 267 |
|
| 268 | 268 |
Arc prepare(Node node) {
|
| 269 | 269 |
std::vector<Node> nodes; |
| 270 | 270 |
(*_node_order)[node] = _dual_node_list.size(); |
| 271 | 271 |
StackLevel level; |
| 272 | 272 |
level.node_level = _dual_node_list.size(); |
| 273 | 273 |
_dual_node_list.push_back(node); |
| 274 | 274 |
for (InArcIt it(*_digraph, node); it != INVALID; ++it) {
|
| 275 | 275 |
Arc arc = it; |
| 276 | 276 |
Node source = _digraph->source(arc); |
| 277 | 277 |
Value value = (*_cost)[it]; |
| 278 | 278 |
if (source == node || (*_node_order)[source] == -3) continue; |
| 279 | 279 |
if ((*_cost_arcs)[source].arc == INVALID) {
|
| 280 | 280 |
(*_cost_arcs)[source].arc = arc; |
| 281 | 281 |
(*_cost_arcs)[source].value = value; |
| 282 | 282 |
nodes.push_back(source); |
| 283 | 283 |
} else {
|
| 284 | 284 |
if ((*_cost_arcs)[source].value > value) {
|
| 285 | 285 |
(*_cost_arcs)[source].arc = arc; |
| 286 | 286 |
(*_cost_arcs)[source].value = value; |
| 287 | 287 |
} |
| 288 | 288 |
} |
| 289 | 289 |
} |
| 290 | 290 |
CostArc minimum = (*_cost_arcs)[nodes[0]]; |
| 291 | 291 |
for (int i = 1; i < int(nodes.size()); ++i) {
|
| 292 | 292 |
if ((*_cost_arcs)[nodes[i]].value < minimum.value) {
|
| 293 | 293 |
minimum = (*_cost_arcs)[nodes[i]]; |
| 294 | 294 |
} |
| 295 | 295 |
} |
| 296 |
_arc_order |
|
| 296 |
(*_arc_order)[minimum.arc] = _dual_variables.size(); |
|
| 297 | 297 |
DualVariable var(_dual_node_list.size() - 1, |
| 298 | 298 |
_dual_node_list.size(), minimum.value); |
| 299 | 299 |
_dual_variables.push_back(var); |
| 300 | 300 |
for (int i = 0; i < int(nodes.size()); ++i) {
|
| 301 | 301 |
(*_cost_arcs)[nodes[i]].value -= minimum.value; |
| 302 | 302 |
level.arcs.push_back((*_cost_arcs)[nodes[i]]); |
| 303 | 303 |
(*_cost_arcs)[nodes[i]].arc = INVALID; |
| 304 | 304 |
} |
| 305 | 305 |
level_stack.push_back(level); |
| 306 | 306 |
return minimum.arc; |
| 307 | 307 |
} |
| 308 | 308 |
|
| 309 | 309 |
Arc contract(Node node) {
|
| 310 | 310 |
int node_bottom = bottom(node); |
| 311 | 311 |
std::vector<Node> nodes; |
| 312 | 312 |
while (!level_stack.empty() && |
| 313 | 313 |
level_stack.back().node_level >= node_bottom) {
|
| 314 | 314 |
for (int i = 0; i < int(level_stack.back().arcs.size()); ++i) {
|
| 315 | 315 |
Arc arc = level_stack.back().arcs[i].arc; |
| 316 | 316 |
Node source = _digraph->source(arc); |
| 317 | 317 |
Value value = level_stack.back().arcs[i].value; |
| 318 | 318 |
if ((*_node_order)[source] >= node_bottom) continue; |
| 319 | 319 |
if ((*_cost_arcs)[source].arc == INVALID) {
|
| 320 | 320 |
(*_cost_arcs)[source].arc = arc; |
| 321 | 321 |
(*_cost_arcs)[source].value = value; |
| 322 | 322 |
nodes.push_back(source); |
| 323 | 323 |
} else {
|
| 324 | 324 |
if ((*_cost_arcs)[source].value > value) {
|
| 325 | 325 |
(*_cost_arcs)[source].arc = arc; |
| 326 | 326 |
(*_cost_arcs)[source].value = value; |
| 327 | 327 |
} |
| 328 | 328 |
} |
| 329 | 329 |
} |
| 330 | 330 |
level_stack.pop_back(); |
| 331 | 331 |
} |
| 332 | 332 |
CostArc minimum = (*_cost_arcs)[nodes[0]]; |
| 333 | 333 |
for (int i = 1; i < int(nodes.size()); ++i) {
|
| 334 | 334 |
if ((*_cost_arcs)[nodes[i]].value < minimum.value) {
|
| 335 | 335 |
minimum = (*_cost_arcs)[nodes[i]]; |
| 336 | 336 |
} |
| 337 | 337 |
} |
| 338 |
_arc_order |
|
| 338 |
(*_arc_order)[minimum.arc] = _dual_variables.size(); |
|
| 339 | 339 |
DualVariable var(node_bottom, _dual_node_list.size(), minimum.value); |
| 340 | 340 |
_dual_variables.push_back(var); |
| 341 | 341 |
StackLevel level; |
| 342 | 342 |
level.node_level = node_bottom; |
| 343 | 343 |
for (int i = 0; i < int(nodes.size()); ++i) {
|
| 344 | 344 |
(*_cost_arcs)[nodes[i]].value -= minimum.value; |
| 345 | 345 |
level.arcs.push_back((*_cost_arcs)[nodes[i]]); |
| 346 | 346 |
(*_cost_arcs)[nodes[i]].arc = INVALID; |
| 347 | 347 |
} |
| 348 | 348 |
level_stack.push_back(level); |
| 349 | 349 |
return minimum.arc; |
| 350 | 350 |
} |
| 351 | 351 |
|
| 352 | 352 |
int bottom(Node node) {
|
| 353 | 353 |
int k = level_stack.size() - 1; |
| 354 | 354 |
while (level_stack[k].node_level > (*_node_order)[node]) {
|
| 355 | 355 |
--k; |
| 356 | 356 |
} |
| 357 | 357 |
return level_stack[k].node_level; |
| 358 | 358 |
} |
| 359 | 359 |
|
| 360 | 360 |
void finalize(Arc arc) {
|
| 361 | 361 |
Node node = _digraph->target(arc); |
| 362 | 362 |
_heap->push(node, (*_arc_order)[arc]); |
| 363 | 363 |
_pred->set(node, arc); |
| 364 | 364 |
while (!_heap->empty()) {
|
| 365 | 365 |
Node source = _heap->top(); |
| 366 | 366 |
_heap->pop(); |
| 367 |
_node_order |
|
| 367 |
(*_node_order)[source] = -1; |
|
| 368 | 368 |
for (OutArcIt it(*_digraph, source); it != INVALID; ++it) {
|
| 369 | 369 |
if ((*_arc_order)[it] < 0) continue; |
| 370 | 370 |
Node target = _digraph->target(it); |
| 371 | 371 |
switch(_heap->state(target)) {
|
| 372 | 372 |
case Heap::PRE_HEAP: |
| 373 | 373 |
_heap->push(target, (*_arc_order)[it]); |
| 374 | 374 |
_pred->set(target, it); |
| 375 | 375 |
break; |
| 376 | 376 |
case Heap::IN_HEAP: |
| 377 | 377 |
if ((*_arc_order)[it] < (*_heap)[target]) {
|
| 378 | 378 |
_heap->decrease(target, (*_arc_order)[it]); |
| 379 | 379 |
_pred->set(target, it); |
| 380 | 380 |
} |
| 381 | 381 |
break; |
| 382 | 382 |
case Heap::POST_HEAP: |
| 383 | 383 |
break; |
| 384 | 384 |
} |
| 385 | 385 |
} |
| 386 | 386 |
_arborescence->set((*_pred)[source], true); |
| 387 | 387 |
} |
| 388 | 388 |
} |
| 389 | 389 |
|
| 390 | 390 |
|
| 391 | 391 |
public: |
| 392 | 392 |
|
| 393 |
/// \name Named |
|
| 393 |
/// \name Named Template Parameters |
|
| 394 | 394 |
|
| 395 | 395 |
/// @{
|
| 396 | 396 |
|
| 397 | 397 |
template <class T> |
| 398 | 398 |
struct DefArborescenceMapTraits : public Traits {
|
| 399 | 399 |
typedef T ArborescenceMap; |
| 400 | 400 |
static ArborescenceMap *createArborescenceMap(const Digraph &) |
| 401 | 401 |
{
|
| 402 | 402 |
LEMON_ASSERT(false, "ArborescenceMap is not initialized"); |
| 403 | 403 |
return 0; // ignore warnings |
| 404 | 404 |
} |
| 405 | 405 |
}; |
| 406 | 406 |
|
| 407 | 407 |
/// \brief \ref named-templ-param "Named parameter" for |
| 408 | 408 |
/// setting ArborescenceMap type |
| 409 | 409 |
/// |
| 410 | 410 |
/// \ref named-templ-param "Named parameter" for setting |
| 411 | 411 |
/// ArborescenceMap type |
| 412 | 412 |
template <class T> |
| 413 | 413 |
struct DefArborescenceMap |
| 414 | 414 |
: public MinCostArborescence<Digraph, CostMap, |
| 415 | 415 |
DefArborescenceMapTraits<T> > {
|
| 416 | 416 |
}; |
| 417 | 417 |
|
| 418 | 418 |
template <class T> |
| 419 | 419 |
struct DefPredMapTraits : public Traits {
|
| 420 | 420 |
typedef T PredMap; |
| 421 | 421 |
static PredMap *createPredMap(const Digraph &) |
| 422 | 422 |
{
|
| 423 | 423 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
| 424 | 424 |
} |
| 425 | 425 |
}; |
| 426 | 426 |
|
| 427 | 427 |
/// \brief \ref named-templ-param "Named parameter" for |
| 428 | 428 |
/// setting PredMap type |
| 429 | 429 |
/// |
| 430 | 430 |
/// \ref named-templ-param "Named parameter" for setting |
| 431 | 431 |
/// PredMap type |
| 432 | 432 |
template <class T> |
| 433 | 433 |
struct DefPredMap |
| 434 | 434 |
: public MinCostArborescence<Digraph, CostMap, DefPredMapTraits<T> > {
|
| 435 | 435 |
}; |
| 436 | 436 |
|
| 437 | 437 |
/// @} |
| 438 | 438 |
|
| 439 | 439 |
/// \brief Constructor. |
| 440 | 440 |
/// |
| 441 | 441 |
/// \param digraph The digraph the algorithm will run on. |
| ... | ... |
@@ -585,123 +585,123 @@ |
| 585 | 585 |
public: |
| 586 | 586 |
|
| 587 | 587 |
/// \brief Constructor. |
| 588 | 588 |
/// |
| 589 | 589 |
/// Constructor for get the nodeset of the variable. |
| 590 | 590 |
DualIt(const MinCostArborescence& algorithm, int variable) |
| 591 | 591 |
: _algorithm(&algorithm) |
| 592 | 592 |
{
|
| 593 | 593 |
_index = _algorithm->_dual_variables[variable].begin; |
| 594 | 594 |
_last = _algorithm->_dual_variables[variable].end; |
| 595 | 595 |
} |
| 596 | 596 |
|
| 597 | 597 |
/// \brief Conversion to node. |
| 598 | 598 |
/// |
| 599 | 599 |
/// Conversion to node. |
| 600 | 600 |
operator Node() const {
|
| 601 | 601 |
return _algorithm->_dual_node_list[_index]; |
| 602 | 602 |
} |
| 603 | 603 |
|
| 604 | 604 |
/// \brief Increment operator. |
| 605 | 605 |
/// |
| 606 | 606 |
/// Increment operator. |
| 607 | 607 |
DualIt& operator++() {
|
| 608 | 608 |
++_index; |
| 609 | 609 |
return *this; |
| 610 | 610 |
} |
| 611 | 611 |
|
| 612 | 612 |
/// \brief Validity checking |
| 613 | 613 |
/// |
| 614 | 614 |
/// Checks whether the iterator is invalid. |
| 615 | 615 |
bool operator==(Invalid) const {
|
| 616 | 616 |
return _index == _last; |
| 617 | 617 |
} |
| 618 | 618 |
|
| 619 | 619 |
/// \brief Validity checking |
| 620 | 620 |
/// |
| 621 | 621 |
/// Checks whether the iterator is valid. |
| 622 | 622 |
bool operator!=(Invalid) const {
|
| 623 | 623 |
return _index != _last; |
| 624 | 624 |
} |
| 625 | 625 |
|
| 626 | 626 |
private: |
| 627 | 627 |
const MinCostArborescence* _algorithm; |
| 628 | 628 |
int _index, _last; |
| 629 | 629 |
}; |
| 630 | 630 |
|
| 631 | 631 |
/// @} |
| 632 | 632 |
|
| 633 |
/// \name Execution |
|
| 633 |
/// \name Execution Control |
|
| 634 | 634 |
/// The simplest way to execute the algorithm is to use |
| 635 | 635 |
/// one of the member functions called \c run(...). \n |
| 636 | 636 |
/// If you need more control on the execution, |
| 637 | 637 |
/// first you must call \ref init(), then you can add several |
| 638 | 638 |
/// source nodes with \ref addSource(). |
| 639 | 639 |
/// Finally \ref start() will perform the arborescence |
| 640 | 640 |
/// computation. |
| 641 | 641 |
|
| 642 | 642 |
///@{
|
| 643 | 643 |
|
| 644 | 644 |
/// \brief Initializes the internal data structures. |
| 645 | 645 |
/// |
| 646 | 646 |
/// Initializes the internal data structures. |
| 647 | 647 |
/// |
| 648 | 648 |
void init() {
|
| 649 | 649 |
createStructures(); |
| 650 | 650 |
_heap->clear(); |
| 651 | 651 |
for (NodeIt it(*_digraph); it != INVALID; ++it) {
|
| 652 | 652 |
(*_cost_arcs)[it].arc = INVALID; |
| 653 |
_node_order->set(it, -3); |
|
| 654 |
_heap_cross_ref->set(it, Heap::PRE_HEAP); |
|
| 653 |
(*_node_order)[it] = -3; |
|
| 654 |
(*_heap_cross_ref)[it] = Heap::PRE_HEAP; |
|
| 655 | 655 |
_pred->set(it, INVALID); |
| 656 | 656 |
} |
| 657 | 657 |
for (ArcIt it(*_digraph); it != INVALID; ++it) {
|
| 658 | 658 |
_arborescence->set(it, false); |
| 659 |
_arc_order |
|
| 659 |
(*_arc_order)[it] = -1; |
|
| 660 | 660 |
} |
| 661 | 661 |
_dual_node_list.clear(); |
| 662 | 662 |
_dual_variables.clear(); |
| 663 | 663 |
} |
| 664 | 664 |
|
| 665 | 665 |
/// \brief Adds a new source node. |
| 666 | 666 |
/// |
| 667 | 667 |
/// Adds a new source node to the algorithm. |
| 668 | 668 |
void addSource(Node source) {
|
| 669 | 669 |
std::vector<Node> nodes; |
| 670 | 670 |
nodes.push_back(source); |
| 671 | 671 |
while (!nodes.empty()) {
|
| 672 | 672 |
Node node = nodes.back(); |
| 673 | 673 |
nodes.pop_back(); |
| 674 | 674 |
for (OutArcIt it(*_digraph, node); it != INVALID; ++it) {
|
| 675 | 675 |
Node target = _digraph->target(it); |
| 676 | 676 |
if ((*_node_order)[target] == -3) {
|
| 677 | 677 |
(*_node_order)[target] = -2; |
| 678 | 678 |
nodes.push_back(target); |
| 679 | 679 |
queue.push_back(target); |
| 680 | 680 |
} |
| 681 | 681 |
} |
| 682 | 682 |
} |
| 683 | 683 |
(*_node_order)[source] = -1; |
| 684 | 684 |
} |
| 685 | 685 |
|
| 686 | 686 |
/// \brief Processes the next node in the priority queue. |
| 687 | 687 |
/// |
| 688 | 688 |
/// Processes the next node in the priority queue. |
| 689 | 689 |
/// |
| 690 | 690 |
/// \return The processed node. |
| 691 | 691 |
/// |
| 692 | 692 |
/// \warning The queue must not be empty! |
| 693 | 693 |
Node processNextNode() {
|
| 694 | 694 |
Node node = queue.back(); |
| 695 | 695 |
queue.pop_back(); |
| 696 | 696 |
if ((*_node_order)[node] == -2) {
|
| 697 | 697 |
Arc arc = prepare(node); |
| 698 | 698 |
Node source = _digraph->source(arc); |
| 699 | 699 |
while ((*_node_order)[source] != -1) {
|
| 700 | 700 |
if ((*_node_order)[source] >= 0) {
|
| 701 | 701 |
arc = contract(source); |
| 702 | 702 |
} else {
|
| 703 | 703 |
arc = prepare(source); |
| 704 | 704 |
} |
| 705 | 705 |
source = _digraph->source(arc); |
| 706 | 706 |
} |
| 707 | 707 |
finalize(arc); |
| ... | ... |
@@ -359,523 +359,523 @@ |
| 359 | 359 |
} |
| 360 | 360 |
_level = &elevator; |
| 361 | 361 |
return *this; |
| 362 | 362 |
} |
| 363 | 363 |
|
| 364 | 364 |
/// \brief Returns a const reference to the elevator. |
| 365 | 365 |
/// |
| 366 | 366 |
/// Returns a const reference to the elevator. |
| 367 | 367 |
/// |
| 368 | 368 |
/// \pre Either \ref run() or \ref init() must be called before |
| 369 | 369 |
/// using this function. |
| 370 | 370 |
const Elevator& elevator() const {
|
| 371 | 371 |
return *_level; |
| 372 | 372 |
} |
| 373 | 373 |
|
| 374 | 374 |
/// \brief Sets the tolerance used by algorithm. |
| 375 | 375 |
/// |
| 376 | 376 |
/// Sets the tolerance used by algorithm. |
| 377 | 377 |
Preflow& tolerance(const Tolerance& tolerance) const {
|
| 378 | 378 |
_tolerance = tolerance; |
| 379 | 379 |
return *this; |
| 380 | 380 |
} |
| 381 | 381 |
|
| 382 | 382 |
/// \brief Returns a const reference to the tolerance. |
| 383 | 383 |
/// |
| 384 | 384 |
/// Returns a const reference to the tolerance. |
| 385 | 385 |
const Tolerance& tolerance() const {
|
| 386 | 386 |
return tolerance; |
| 387 | 387 |
} |
| 388 | 388 |
|
| 389 | 389 |
/// \name Execution Control |
| 390 | 390 |
/// The simplest way to execute the preflow algorithm is to use |
| 391 | 391 |
/// \ref run() or \ref runMinCut().\n |
| 392 | 392 |
/// If you need more control on the initial solution or the execution, |
| 393 | 393 |
/// first you have to call one of the \ref init() functions, then |
| 394 | 394 |
/// \ref startFirstPhase() and if you need it \ref startSecondPhase(). |
| 395 | 395 |
|
| 396 | 396 |
///@{
|
| 397 | 397 |
|
| 398 | 398 |
/// \brief Initializes the internal data structures. |
| 399 | 399 |
/// |
| 400 | 400 |
/// Initializes the internal data structures and sets the initial |
| 401 | 401 |
/// flow to zero on each arc. |
| 402 | 402 |
void init() {
|
| 403 | 403 |
createStructures(); |
| 404 | 404 |
|
| 405 | 405 |
_phase = true; |
| 406 | 406 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 407 |
_excess |
|
| 407 |
(*_excess)[n] = 0; |
|
| 408 | 408 |
} |
| 409 | 409 |
|
| 410 | 410 |
for (ArcIt e(_graph); e != INVALID; ++e) {
|
| 411 | 411 |
_flow->set(e, 0); |
| 412 | 412 |
} |
| 413 | 413 |
|
| 414 | 414 |
typename Digraph::template NodeMap<bool> reached(_graph, false); |
| 415 | 415 |
|
| 416 | 416 |
_level->initStart(); |
| 417 | 417 |
_level->initAddItem(_target); |
| 418 | 418 |
|
| 419 | 419 |
std::vector<Node> queue; |
| 420 |
reached |
|
| 420 |
reached[_source] = true; |
|
| 421 | 421 |
|
| 422 | 422 |
queue.push_back(_target); |
| 423 |
reached |
|
| 423 |
reached[_target] = true; |
|
| 424 | 424 |
while (!queue.empty()) {
|
| 425 | 425 |
_level->initNewLevel(); |
| 426 | 426 |
std::vector<Node> nqueue; |
| 427 | 427 |
for (int i = 0; i < int(queue.size()); ++i) {
|
| 428 | 428 |
Node n = queue[i]; |
| 429 | 429 |
for (InArcIt e(_graph, n); e != INVALID; ++e) {
|
| 430 | 430 |
Node u = _graph.source(e); |
| 431 | 431 |
if (!reached[u] && _tolerance.positive((*_capacity)[e])) {
|
| 432 |
reached |
|
| 432 |
reached[u] = true; |
|
| 433 | 433 |
_level->initAddItem(u); |
| 434 | 434 |
nqueue.push_back(u); |
| 435 | 435 |
} |
| 436 | 436 |
} |
| 437 | 437 |
} |
| 438 | 438 |
queue.swap(nqueue); |
| 439 | 439 |
} |
| 440 | 440 |
_level->initFinish(); |
| 441 | 441 |
|
| 442 | 442 |
for (OutArcIt e(_graph, _source); e != INVALID; ++e) {
|
| 443 | 443 |
if (_tolerance.positive((*_capacity)[e])) {
|
| 444 | 444 |
Node u = _graph.target(e); |
| 445 | 445 |
if ((*_level)[u] == _level->maxLevel()) continue; |
| 446 | 446 |
_flow->set(e, (*_capacity)[e]); |
| 447 |
|
|
| 447 |
(*_excess)[u] += (*_capacity)[e]; |
|
| 448 | 448 |
if (u != _target && !_level->active(u)) {
|
| 449 | 449 |
_level->activate(u); |
| 450 | 450 |
} |
| 451 | 451 |
} |
| 452 | 452 |
} |
| 453 | 453 |
} |
| 454 | 454 |
|
| 455 | 455 |
/// \brief Initializes the internal data structures using the |
| 456 | 456 |
/// given flow map. |
| 457 | 457 |
/// |
| 458 | 458 |
/// Initializes the internal data structures and sets the initial |
| 459 | 459 |
/// flow to the given \c flowMap. The \c flowMap should contain a |
| 460 | 460 |
/// flow or at least a preflow, i.e. at each node excluding the |
| 461 | 461 |
/// source node the incoming flow should greater or equal to the |
| 462 | 462 |
/// outgoing flow. |
| 463 | 463 |
/// \return \c false if the given \c flowMap is not a preflow. |
| 464 | 464 |
template <typename FlowMap> |
| 465 | 465 |
bool init(const FlowMap& flowMap) {
|
| 466 | 466 |
createStructures(); |
| 467 | 467 |
|
| 468 | 468 |
for (ArcIt e(_graph); e != INVALID; ++e) {
|
| 469 | 469 |
_flow->set(e, flowMap[e]); |
| 470 | 470 |
} |
| 471 | 471 |
|
| 472 | 472 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 473 | 473 |
Value excess = 0; |
| 474 | 474 |
for (InArcIt e(_graph, n); e != INVALID; ++e) {
|
| 475 | 475 |
excess += (*_flow)[e]; |
| 476 | 476 |
} |
| 477 | 477 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 478 | 478 |
excess -= (*_flow)[e]; |
| 479 | 479 |
} |
| 480 | 480 |
if (excess < 0 && n != _source) return false; |
| 481 |
_excess |
|
| 481 |
(*_excess)[n] = excess; |
|
| 482 | 482 |
} |
| 483 | 483 |
|
| 484 | 484 |
typename Digraph::template NodeMap<bool> reached(_graph, false); |
| 485 | 485 |
|
| 486 | 486 |
_level->initStart(); |
| 487 | 487 |
_level->initAddItem(_target); |
| 488 | 488 |
|
| 489 | 489 |
std::vector<Node> queue; |
| 490 |
reached |
|
| 490 |
reached[_source] = true; |
|
| 491 | 491 |
|
| 492 | 492 |
queue.push_back(_target); |
| 493 |
reached |
|
| 493 |
reached[_target] = true; |
|
| 494 | 494 |
while (!queue.empty()) {
|
| 495 | 495 |
_level->initNewLevel(); |
| 496 | 496 |
std::vector<Node> nqueue; |
| 497 | 497 |
for (int i = 0; i < int(queue.size()); ++i) {
|
| 498 | 498 |
Node n = queue[i]; |
| 499 | 499 |
for (InArcIt e(_graph, n); e != INVALID; ++e) {
|
| 500 | 500 |
Node u = _graph.source(e); |
| 501 | 501 |
if (!reached[u] && |
| 502 | 502 |
_tolerance.positive((*_capacity)[e] - (*_flow)[e])) {
|
| 503 |
reached |
|
| 503 |
reached[u] = true; |
|
| 504 | 504 |
_level->initAddItem(u); |
| 505 | 505 |
nqueue.push_back(u); |
| 506 | 506 |
} |
| 507 | 507 |
} |
| 508 | 508 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 509 | 509 |
Node v = _graph.target(e); |
| 510 | 510 |
if (!reached[v] && _tolerance.positive((*_flow)[e])) {
|
| 511 |
reached |
|
| 511 |
reached[v] = true; |
|
| 512 | 512 |
_level->initAddItem(v); |
| 513 | 513 |
nqueue.push_back(v); |
| 514 | 514 |
} |
| 515 | 515 |
} |
| 516 | 516 |
} |
| 517 | 517 |
queue.swap(nqueue); |
| 518 | 518 |
} |
| 519 | 519 |
_level->initFinish(); |
| 520 | 520 |
|
| 521 | 521 |
for (OutArcIt e(_graph, _source); e != INVALID; ++e) {
|
| 522 | 522 |
Value rem = (*_capacity)[e] - (*_flow)[e]; |
| 523 | 523 |
if (_tolerance.positive(rem)) {
|
| 524 | 524 |
Node u = _graph.target(e); |
| 525 | 525 |
if ((*_level)[u] == _level->maxLevel()) continue; |
| 526 | 526 |
_flow->set(e, (*_capacity)[e]); |
| 527 |
|
|
| 527 |
(*_excess)[u] += rem; |
|
| 528 | 528 |
if (u != _target && !_level->active(u)) {
|
| 529 | 529 |
_level->activate(u); |
| 530 | 530 |
} |
| 531 | 531 |
} |
| 532 | 532 |
} |
| 533 | 533 |
for (InArcIt e(_graph, _source); e != INVALID; ++e) {
|
| 534 | 534 |
Value rem = (*_flow)[e]; |
| 535 | 535 |
if (_tolerance.positive(rem)) {
|
| 536 | 536 |
Node v = _graph.source(e); |
| 537 | 537 |
if ((*_level)[v] == _level->maxLevel()) continue; |
| 538 | 538 |
_flow->set(e, 0); |
| 539 |
|
|
| 539 |
(*_excess)[v] += rem; |
|
| 540 | 540 |
if (v != _target && !_level->active(v)) {
|
| 541 | 541 |
_level->activate(v); |
| 542 | 542 |
} |
| 543 | 543 |
} |
| 544 | 544 |
} |
| 545 | 545 |
return true; |
| 546 | 546 |
} |
| 547 | 547 |
|
| 548 | 548 |
/// \brief Starts the first phase of the preflow algorithm. |
| 549 | 549 |
/// |
| 550 | 550 |
/// The preflow algorithm consists of two phases, this method runs |
| 551 | 551 |
/// the first phase. After the first phase the maximum flow value |
| 552 | 552 |
/// and a minimum value cut can already be computed, although a |
| 553 | 553 |
/// maximum flow is not yet obtained. So after calling this method |
| 554 | 554 |
/// \ref flowValue() returns the value of a maximum flow and \ref |
| 555 | 555 |
/// minCut() returns a minimum cut. |
| 556 | 556 |
/// \pre One of the \ref init() functions must be called before |
| 557 | 557 |
/// using this function. |
| 558 | 558 |
void startFirstPhase() {
|
| 559 | 559 |
_phase = true; |
| 560 | 560 |
|
| 561 | 561 |
Node n = _level->highestActive(); |
| 562 | 562 |
int level = _level->highestActiveLevel(); |
| 563 | 563 |
while (n != INVALID) {
|
| 564 | 564 |
int num = _node_num; |
| 565 | 565 |
|
| 566 | 566 |
while (num > 0 && n != INVALID) {
|
| 567 | 567 |
Value excess = (*_excess)[n]; |
| 568 | 568 |
int new_level = _level->maxLevel(); |
| 569 | 569 |
|
| 570 | 570 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 571 | 571 |
Value rem = (*_capacity)[e] - (*_flow)[e]; |
| 572 | 572 |
if (!_tolerance.positive(rem)) continue; |
| 573 | 573 |
Node v = _graph.target(e); |
| 574 | 574 |
if ((*_level)[v] < level) {
|
| 575 | 575 |
if (!_level->active(v) && v != _target) {
|
| 576 | 576 |
_level->activate(v); |
| 577 | 577 |
} |
| 578 | 578 |
if (!_tolerance.less(rem, excess)) {
|
| 579 | 579 |
_flow->set(e, (*_flow)[e] + excess); |
| 580 |
|
|
| 580 |
(*_excess)[v] += excess; |
|
| 581 | 581 |
excess = 0; |
| 582 | 582 |
goto no_more_push_1; |
| 583 | 583 |
} else {
|
| 584 | 584 |
excess -= rem; |
| 585 |
|
|
| 585 |
(*_excess)[v] += rem; |
|
| 586 | 586 |
_flow->set(e, (*_capacity)[e]); |
| 587 | 587 |
} |
| 588 | 588 |
} else if (new_level > (*_level)[v]) {
|
| 589 | 589 |
new_level = (*_level)[v]; |
| 590 | 590 |
} |
| 591 | 591 |
} |
| 592 | 592 |
|
| 593 | 593 |
for (InArcIt e(_graph, n); e != INVALID; ++e) {
|
| 594 | 594 |
Value rem = (*_flow)[e]; |
| 595 | 595 |
if (!_tolerance.positive(rem)) continue; |
| 596 | 596 |
Node v = _graph.source(e); |
| 597 | 597 |
if ((*_level)[v] < level) {
|
| 598 | 598 |
if (!_level->active(v) && v != _target) {
|
| 599 | 599 |
_level->activate(v); |
| 600 | 600 |
} |
| 601 | 601 |
if (!_tolerance.less(rem, excess)) {
|
| 602 | 602 |
_flow->set(e, (*_flow)[e] - excess); |
| 603 |
|
|
| 603 |
(*_excess)[v] += excess; |
|
| 604 | 604 |
excess = 0; |
| 605 | 605 |
goto no_more_push_1; |
| 606 | 606 |
} else {
|
| 607 | 607 |
excess -= rem; |
| 608 |
|
|
| 608 |
(*_excess)[v] += rem; |
|
| 609 | 609 |
_flow->set(e, 0); |
| 610 | 610 |
} |
| 611 | 611 |
} else if (new_level > (*_level)[v]) {
|
| 612 | 612 |
new_level = (*_level)[v]; |
| 613 | 613 |
} |
| 614 | 614 |
} |
| 615 | 615 |
|
| 616 | 616 |
no_more_push_1: |
| 617 | 617 |
|
| 618 |
_excess |
|
| 618 |
(*_excess)[n] = excess; |
|
| 619 | 619 |
|
| 620 | 620 |
if (excess != 0) {
|
| 621 | 621 |
if (new_level + 1 < _level->maxLevel()) {
|
| 622 | 622 |
_level->liftHighestActive(new_level + 1); |
| 623 | 623 |
} else {
|
| 624 | 624 |
_level->liftHighestActiveToTop(); |
| 625 | 625 |
} |
| 626 | 626 |
if (_level->emptyLevel(level)) {
|
| 627 | 627 |
_level->liftToTop(level); |
| 628 | 628 |
} |
| 629 | 629 |
} else {
|
| 630 | 630 |
_level->deactivate(n); |
| 631 | 631 |
} |
| 632 | 632 |
|
| 633 | 633 |
n = _level->highestActive(); |
| 634 | 634 |
level = _level->highestActiveLevel(); |
| 635 | 635 |
--num; |
| 636 | 636 |
} |
| 637 | 637 |
|
| 638 | 638 |
num = _node_num * 20; |
| 639 | 639 |
while (num > 0 && n != INVALID) {
|
| 640 | 640 |
Value excess = (*_excess)[n]; |
| 641 | 641 |
int new_level = _level->maxLevel(); |
| 642 | 642 |
|
| 643 | 643 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 644 | 644 |
Value rem = (*_capacity)[e] - (*_flow)[e]; |
| 645 | 645 |
if (!_tolerance.positive(rem)) continue; |
| 646 | 646 |
Node v = _graph.target(e); |
| 647 | 647 |
if ((*_level)[v] < level) {
|
| 648 | 648 |
if (!_level->active(v) && v != _target) {
|
| 649 | 649 |
_level->activate(v); |
| 650 | 650 |
} |
| 651 | 651 |
if (!_tolerance.less(rem, excess)) {
|
| 652 | 652 |
_flow->set(e, (*_flow)[e] + excess); |
| 653 |
|
|
| 653 |
(*_excess)[v] += excess; |
|
| 654 | 654 |
excess = 0; |
| 655 | 655 |
goto no_more_push_2; |
| 656 | 656 |
} else {
|
| 657 | 657 |
excess -= rem; |
| 658 |
|
|
| 658 |
(*_excess)[v] += rem; |
|
| 659 | 659 |
_flow->set(e, (*_capacity)[e]); |
| 660 | 660 |
} |
| 661 | 661 |
} else if (new_level > (*_level)[v]) {
|
| 662 | 662 |
new_level = (*_level)[v]; |
| 663 | 663 |
} |
| 664 | 664 |
} |
| 665 | 665 |
|
| 666 | 666 |
for (InArcIt e(_graph, n); e != INVALID; ++e) {
|
| 667 | 667 |
Value rem = (*_flow)[e]; |
| 668 | 668 |
if (!_tolerance.positive(rem)) continue; |
| 669 | 669 |
Node v = _graph.source(e); |
| 670 | 670 |
if ((*_level)[v] < level) {
|
| 671 | 671 |
if (!_level->active(v) && v != _target) {
|
| 672 | 672 |
_level->activate(v); |
| 673 | 673 |
} |
| 674 | 674 |
if (!_tolerance.less(rem, excess)) {
|
| 675 | 675 |
_flow->set(e, (*_flow)[e] - excess); |
| 676 |
|
|
| 676 |
(*_excess)[v] += excess; |
|
| 677 | 677 |
excess = 0; |
| 678 | 678 |
goto no_more_push_2; |
| 679 | 679 |
} else {
|
| 680 | 680 |
excess -= rem; |
| 681 |
|
|
| 681 |
(*_excess)[v] += rem; |
|
| 682 | 682 |
_flow->set(e, 0); |
| 683 | 683 |
} |
| 684 | 684 |
} else if (new_level > (*_level)[v]) {
|
| 685 | 685 |
new_level = (*_level)[v]; |
| 686 | 686 |
} |
| 687 | 687 |
} |
| 688 | 688 |
|
| 689 | 689 |
no_more_push_2: |
| 690 | 690 |
|
| 691 |
_excess |
|
| 691 |
(*_excess)[n] = excess; |
|
| 692 | 692 |
|
| 693 | 693 |
if (excess != 0) {
|
| 694 | 694 |
if (new_level + 1 < _level->maxLevel()) {
|
| 695 | 695 |
_level->liftActiveOn(level, new_level + 1); |
| 696 | 696 |
} else {
|
| 697 | 697 |
_level->liftActiveToTop(level); |
| 698 | 698 |
} |
| 699 | 699 |
if (_level->emptyLevel(level)) {
|
| 700 | 700 |
_level->liftToTop(level); |
| 701 | 701 |
} |
| 702 | 702 |
} else {
|
| 703 | 703 |
_level->deactivate(n); |
| 704 | 704 |
} |
| 705 | 705 |
|
| 706 | 706 |
while (level >= 0 && _level->activeFree(level)) {
|
| 707 | 707 |
--level; |
| 708 | 708 |
} |
| 709 | 709 |
if (level == -1) {
|
| 710 | 710 |
n = _level->highestActive(); |
| 711 | 711 |
level = _level->highestActiveLevel(); |
| 712 | 712 |
} else {
|
| 713 | 713 |
n = _level->activeOn(level); |
| 714 | 714 |
} |
| 715 | 715 |
--num; |
| 716 | 716 |
} |
| 717 | 717 |
} |
| 718 | 718 |
} |
| 719 | 719 |
|
| 720 | 720 |
/// \brief Starts the second phase of the preflow algorithm. |
| 721 | 721 |
/// |
| 722 | 722 |
/// The preflow algorithm consists of two phases, this method runs |
| 723 | 723 |
/// the second phase. After calling one of the \ref init() functions |
| 724 | 724 |
/// and \ref startFirstPhase() and then \ref startSecondPhase(), |
| 725 | 725 |
/// \ref flowMap() returns a maximum flow, \ref flowValue() returns the |
| 726 | 726 |
/// value of a maximum flow, \ref minCut() returns a minimum cut |
| 727 | 727 |
/// \pre One of the \ref init() functions and \ref startFirstPhase() |
| 728 | 728 |
/// must be called before using this function. |
| 729 | 729 |
void startSecondPhase() {
|
| 730 | 730 |
_phase = false; |
| 731 | 731 |
|
| 732 | 732 |
typename Digraph::template NodeMap<bool> reached(_graph); |
| 733 | 733 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 734 |
reached |
|
| 734 |
reached[n] = (*_level)[n] < _level->maxLevel(); |
|
| 735 | 735 |
} |
| 736 | 736 |
|
| 737 | 737 |
_level->initStart(); |
| 738 | 738 |
_level->initAddItem(_source); |
| 739 | 739 |
|
| 740 | 740 |
std::vector<Node> queue; |
| 741 | 741 |
queue.push_back(_source); |
| 742 |
reached |
|
| 742 |
reached[_source] = true; |
|
| 743 | 743 |
|
| 744 | 744 |
while (!queue.empty()) {
|
| 745 | 745 |
_level->initNewLevel(); |
| 746 | 746 |
std::vector<Node> nqueue; |
| 747 | 747 |
for (int i = 0; i < int(queue.size()); ++i) {
|
| 748 | 748 |
Node n = queue[i]; |
| 749 | 749 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 750 | 750 |
Node v = _graph.target(e); |
| 751 | 751 |
if (!reached[v] && _tolerance.positive((*_flow)[e])) {
|
| 752 |
reached |
|
| 752 |
reached[v] = true; |
|
| 753 | 753 |
_level->initAddItem(v); |
| 754 | 754 |
nqueue.push_back(v); |
| 755 | 755 |
} |
| 756 | 756 |
} |
| 757 | 757 |
for (InArcIt e(_graph, n); e != INVALID; ++e) {
|
| 758 | 758 |
Node u = _graph.source(e); |
| 759 | 759 |
if (!reached[u] && |
| 760 | 760 |
_tolerance.positive((*_capacity)[e] - (*_flow)[e])) {
|
| 761 |
reached |
|
| 761 |
reached[u] = true; |
|
| 762 | 762 |
_level->initAddItem(u); |
| 763 | 763 |
nqueue.push_back(u); |
| 764 | 764 |
} |
| 765 | 765 |
} |
| 766 | 766 |
} |
| 767 | 767 |
queue.swap(nqueue); |
| 768 | 768 |
} |
| 769 | 769 |
_level->initFinish(); |
| 770 | 770 |
|
| 771 | 771 |
for (NodeIt n(_graph); n != INVALID; ++n) {
|
| 772 | 772 |
if (!reached[n]) {
|
| 773 | 773 |
_level->dirtyTopButOne(n); |
| 774 | 774 |
} else if ((*_excess)[n] > 0 && _target != n) {
|
| 775 | 775 |
_level->activate(n); |
| 776 | 776 |
} |
| 777 | 777 |
} |
| 778 | 778 |
|
| 779 | 779 |
Node n; |
| 780 | 780 |
while ((n = _level->highestActive()) != INVALID) {
|
| 781 | 781 |
Value excess = (*_excess)[n]; |
| 782 | 782 |
int level = _level->highestActiveLevel(); |
| 783 | 783 |
int new_level = _level->maxLevel(); |
| 784 | 784 |
|
| 785 | 785 |
for (OutArcIt e(_graph, n); e != INVALID; ++e) {
|
| 786 | 786 |
Value rem = (*_capacity)[e] - (*_flow)[e]; |
| 787 | 787 |
if (!_tolerance.positive(rem)) continue; |
| 788 | 788 |
Node v = _graph.target(e); |
| 789 | 789 |
if ((*_level)[v] < level) {
|
| 790 | 790 |
if (!_level->active(v) && v != _source) {
|
| 791 | 791 |
_level->activate(v); |
| 792 | 792 |
} |
| 793 | 793 |
if (!_tolerance.less(rem, excess)) {
|
| 794 | 794 |
_flow->set(e, (*_flow)[e] + excess); |
| 795 |
|
|
| 795 |
(*_excess)[v] += excess; |
|
| 796 | 796 |
excess = 0; |
| 797 | 797 |
goto no_more_push; |
| 798 | 798 |
} else {
|
| 799 | 799 |
excess -= rem; |
| 800 |
|
|
| 800 |
(*_excess)[v] += rem; |
|
| 801 | 801 |
_flow->set(e, (*_capacity)[e]); |
| 802 | 802 |
} |
| 803 | 803 |
} else if (new_level > (*_level)[v]) {
|
| 804 | 804 |
new_level = (*_level)[v]; |
| 805 | 805 |
} |
| 806 | 806 |
} |
| 807 | 807 |
|
| 808 | 808 |
for (InArcIt e(_graph, n); e != INVALID; ++e) {
|
| 809 | 809 |
Value rem = (*_flow)[e]; |
| 810 | 810 |
if (!_tolerance.positive(rem)) continue; |
| 811 | 811 |
Node v = _graph.source(e); |
| 812 | 812 |
if ((*_level)[v] < level) {
|
| 813 | 813 |
if (!_level->active(v) && v != _source) {
|
| 814 | 814 |
_level->activate(v); |
| 815 | 815 |
} |
| 816 | 816 |
if (!_tolerance.less(rem, excess)) {
|
| 817 | 817 |
_flow->set(e, (*_flow)[e] - excess); |
| 818 |
|
|
| 818 |
(*_excess)[v] += excess; |
|
| 819 | 819 |
excess = 0; |
| 820 | 820 |
goto no_more_push; |
| 821 | 821 |
} else {
|
| 822 | 822 |
excess -= rem; |
| 823 |
|
|
| 823 |
(*_excess)[v] += rem; |
|
| 824 | 824 |
_flow->set(e, 0); |
| 825 | 825 |
} |
| 826 | 826 |
} else if (new_level > (*_level)[v]) {
|
| 827 | 827 |
new_level = (*_level)[v]; |
| 828 | 828 |
} |
| 829 | 829 |
} |
| 830 | 830 |
|
| 831 | 831 |
no_more_push: |
| 832 | 832 |
|
| 833 |
_excess |
|
| 833 |
(*_excess)[n] = excess; |
|
| 834 | 834 |
|
| 835 | 835 |
if (excess != 0) {
|
| 836 | 836 |
if (new_level + 1 < _level->maxLevel()) {
|
| 837 | 837 |
_level->liftHighestActive(new_level + 1); |
| 838 | 838 |
} else {
|
| 839 | 839 |
// Calculation error |
| 840 | 840 |
_level->liftHighestActiveToTop(); |
| 841 | 841 |
} |
| 842 | 842 |
if (_level->emptyLevel(level)) {
|
| 843 | 843 |
// Calculation error |
| 844 | 844 |
_level->liftToTop(level); |
| 845 | 845 |
} |
| 846 | 846 |
} else {
|
| 847 | 847 |
_level->deactivate(n); |
| 848 | 848 |
} |
| 849 | 849 |
|
| 850 | 850 |
} |
| 851 | 851 |
} |
| 852 | 852 |
|
| 853 | 853 |
/// \brief Runs the preflow algorithm. |
| 854 | 854 |
/// |
| 855 | 855 |
/// Runs the preflow algorithm. |
| 856 | 856 |
/// \note pf.run() is just a shortcut of the following code. |
| 857 | 857 |
/// \code |
| 858 | 858 |
/// pf.init(); |
| 859 | 859 |
/// pf.startFirstPhase(); |
| 860 | 860 |
/// pf.startSecondPhase(); |
| 861 | 861 |
/// \endcode |
| 862 | 862 |
void run() {
|
| 863 | 863 |
init(); |
| 864 | 864 |
startFirstPhase(); |
| 865 | 865 |
startSecondPhase(); |
| 866 | 866 |
} |
| 867 | 867 |
|
| 868 | 868 |
/// \brief Runs the preflow algorithm to compute the minimum cut. |
| 869 | 869 |
/// |
| 870 | 870 |
/// Runs the preflow algorithm to compute the minimum cut. |
| 871 | 871 |
/// \note pf.runMinCut() is just a shortcut of the following code. |
| 872 | 872 |
/// \code |
| 873 | 873 |
/// pf.init(); |
| 874 | 874 |
/// pf.startFirstPhase(); |
| 875 | 875 |
/// \endcode |
| 876 | 876 |
void runMinCut() {
|
| 877 | 877 |
init(); |
| 878 | 878 |
startFirstPhase(); |
| 879 | 879 |
} |
| 880 | 880 |
|
| 881 | 881 |
/// @} |
| ... | ... |
@@ -614,97 +614,97 @@ |
| 614 | 614 |
|
| 615 | 615 |
/// \brief Seeding from file |
| 616 | 616 |
/// |
| 617 | 617 |
/// Seeding the random sequence from file. The linux kernel has two |
| 618 | 618 |
/// devices, <tt>/dev/random</tt> and <tt>/dev/urandom</tt> which |
| 619 | 619 |
/// could give good seed values for pseudo random generators (The |
| 620 | 620 |
/// difference between two devices is that the <tt>random</tt> may |
| 621 | 621 |
/// block the reading operation while the kernel can give good |
| 622 | 622 |
/// source of randomness, while the <tt>urandom</tt> does not |
| 623 | 623 |
/// block the input, but it could give back bytes with worse |
| 624 | 624 |
/// entropy). |
| 625 | 625 |
/// \param file The source file |
| 626 | 626 |
/// \param offset The offset, from the file read. |
| 627 | 627 |
/// \return \c true when the seeding successes. |
| 628 | 628 |
#ifndef WIN32 |
| 629 | 629 |
bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0) |
| 630 | 630 |
#else |
| 631 | 631 |
bool seedFromFile(const std::string& file = "", int offset = 0) |
| 632 | 632 |
#endif |
| 633 | 633 |
{
|
| 634 | 634 |
std::ifstream rs(file.c_str()); |
| 635 | 635 |
const int size = 4; |
| 636 | 636 |
Word buf[size]; |
| 637 | 637 |
if (offset != 0 && !rs.seekg(offset)) return false; |
| 638 | 638 |
if (!rs.read(reinterpret_cast<char*>(buf), sizeof(buf))) return false; |
| 639 | 639 |
seed(buf, buf + size); |
| 640 | 640 |
return true; |
| 641 | 641 |
} |
| 642 | 642 |
|
| 643 | 643 |
/// \brief Seding from process id and time |
| 644 | 644 |
/// |
| 645 | 645 |
/// Seding from process id and time. This function uses the |
| 646 | 646 |
/// current process id and the current time for initialize the |
| 647 | 647 |
/// random sequence. |
| 648 | 648 |
/// \return Currently always \c true. |
| 649 | 649 |
bool seedFromTime() {
|
| 650 | 650 |
#ifndef WIN32 |
| 651 | 651 |
timeval tv; |
| 652 | 652 |
gettimeofday(&tv, 0); |
| 653 | 653 |
seed(getpid() + tv.tv_sec + tv.tv_usec); |
| 654 | 654 |
#else |
| 655 | 655 |
seed(bits::getWinRndSeed()); |
| 656 | 656 |
#endif |
| 657 | 657 |
return true; |
| 658 | 658 |
} |
| 659 | 659 |
|
| 660 | 660 |
/// @} |
| 661 | 661 |
|
| 662 |
///\name Uniform |
|
| 662 |
///\name Uniform Distributions |
|
| 663 | 663 |
/// |
| 664 | 664 |
/// @{
|
| 665 | 665 |
|
| 666 | 666 |
/// \brief Returns a random real number from the range [0, 1) |
| 667 | 667 |
/// |
| 668 | 668 |
/// It returns a random real number from the range [0, 1). The |
| 669 | 669 |
/// default Number type is \c double. |
| 670 | 670 |
template <typename Number> |
| 671 | 671 |
Number real() {
|
| 672 | 672 |
return _random_bits::RealConversion<Number, Word>::convert(core); |
| 673 | 673 |
} |
| 674 | 674 |
|
| 675 | 675 |
double real() {
|
| 676 | 676 |
return real<double>(); |
| 677 | 677 |
} |
| 678 | 678 |
|
| 679 | 679 |
/// \brief Returns a random real number from the range [0, 1) |
| 680 | 680 |
/// |
| 681 | 681 |
/// It returns a random double from the range [0, 1). |
| 682 | 682 |
double operator()() {
|
| 683 | 683 |
return real<double>(); |
| 684 | 684 |
} |
| 685 | 685 |
|
| 686 | 686 |
/// \brief Returns a random real number from the range [0, b) |
| 687 | 687 |
/// |
| 688 | 688 |
/// It returns a random real number from the range [0, b). |
| 689 | 689 |
double operator()(double b) {
|
| 690 | 690 |
return real<double>() * b; |
| 691 | 691 |
} |
| 692 | 692 |
|
| 693 | 693 |
/// \brief Returns a random real number from the range [a, b) |
| 694 | 694 |
/// |
| 695 | 695 |
/// It returns a random real number from the range [a, b). |
| 696 | 696 |
double operator()(double a, double b) {
|
| 697 | 697 |
return real<double>() * (b - a) + a; |
| 698 | 698 |
} |
| 699 | 699 |
|
| 700 | 700 |
/// \brief Returns a random integer from a range |
| 701 | 701 |
/// |
| 702 | 702 |
/// It returns a random integer from the range {0, 1, ..., b - 1}.
|
| 703 | 703 |
template <typename Number> |
| 704 | 704 |
Number integer(Number b) {
|
| 705 | 705 |
return _random_bits::Mapping<Number, Word>::map(core, b); |
| 706 | 706 |
} |
| 707 | 707 |
|
| 708 | 708 |
/// \brief Returns a random integer from a range |
| 709 | 709 |
/// |
| 710 | 710 |
/// It returns a random integer from the range {a, a + 1, ..., b - 1}.
|
| ... | ... |
@@ -717,97 +717,97 @@ |
| 717 | 717 |
/// |
| 718 | 718 |
/// It returns a random integer from the range {0, 1, ..., b - 1}.
|
| 719 | 719 |
template <typename Number> |
| 720 | 720 |
Number operator[](Number b) {
|
| 721 | 721 |
return _random_bits::Mapping<Number, Word>::map(core, b); |
| 722 | 722 |
} |
| 723 | 723 |
|
| 724 | 724 |
/// \brief Returns a random non-negative integer |
| 725 | 725 |
/// |
| 726 | 726 |
/// It returns a random non-negative integer uniformly from the |
| 727 | 727 |
/// whole range of the current \c Number type. The default result |
| 728 | 728 |
/// type of this function is <tt>unsigned int</tt>. |
| 729 | 729 |
template <typename Number> |
| 730 | 730 |
Number uinteger() {
|
| 731 | 731 |
return _random_bits::IntConversion<Number, Word>::convert(core); |
| 732 | 732 |
} |
| 733 | 733 |
|
| 734 | 734 |
unsigned int uinteger() {
|
| 735 | 735 |
return uinteger<unsigned int>(); |
| 736 | 736 |
} |
| 737 | 737 |
|
| 738 | 738 |
/// \brief Returns a random integer |
| 739 | 739 |
/// |
| 740 | 740 |
/// It returns a random integer uniformly from the whole range of |
| 741 | 741 |
/// the current \c Number type. The default result type of this |
| 742 | 742 |
/// function is \c int. |
| 743 | 743 |
template <typename Number> |
| 744 | 744 |
Number integer() {
|
| 745 | 745 |
static const int nb = std::numeric_limits<Number>::digits + |
| 746 | 746 |
(std::numeric_limits<Number>::is_signed ? 1 : 0); |
| 747 | 747 |
return _random_bits::IntConversion<Number, Word, nb>::convert(core); |
| 748 | 748 |
} |
| 749 | 749 |
|
| 750 | 750 |
int integer() {
|
| 751 | 751 |
return integer<int>(); |
| 752 | 752 |
} |
| 753 | 753 |
|
| 754 | 754 |
/// \brief Returns a random bool |
| 755 | 755 |
/// |
| 756 | 756 |
/// It returns a random bool. The generator holds a buffer for |
| 757 | 757 |
/// random bits. Every time when it become empty the generator makes |
| 758 | 758 |
/// a new random word and fill the buffer up. |
| 759 | 759 |
bool boolean() {
|
| 760 | 760 |
return bool_producer.convert(core); |
| 761 | 761 |
} |
| 762 | 762 |
|
| 763 | 763 |
/// @} |
| 764 | 764 |
|
| 765 |
///\name Non-uniform |
|
| 765 |
///\name Non-uniform Distributions |
|
| 766 | 766 |
/// |
| 767 | 767 |
///@{
|
| 768 | 768 |
|
| 769 | 769 |
/// \brief Returns a random bool with given probability of true result. |
| 770 | 770 |
/// |
| 771 | 771 |
/// It returns a random bool with given probability of true result. |
| 772 | 772 |
bool boolean(double p) {
|
| 773 | 773 |
return operator()() < p; |
| 774 | 774 |
} |
| 775 | 775 |
|
| 776 | 776 |
/// Standard normal (Gauss) distribution |
| 777 | 777 |
|
| 778 | 778 |
/// Standard normal (Gauss) distribution. |
| 779 | 779 |
/// \note The Cartesian form of the Box-Muller |
| 780 | 780 |
/// transformation is used to generate a random normal distribution. |
| 781 | 781 |
double gauss() |
| 782 | 782 |
{
|
| 783 | 783 |
double V1,V2,S; |
| 784 | 784 |
do {
|
| 785 | 785 |
V1=2*real<double>()-1; |
| 786 | 786 |
V2=2*real<double>()-1; |
| 787 | 787 |
S=V1*V1+V2*V2; |
| 788 | 788 |
} while(S>=1); |
| 789 | 789 |
return std::sqrt(-2*std::log(S)/S)*V1; |
| 790 | 790 |
} |
| 791 | 791 |
/// Normal (Gauss) distribution with given mean and standard deviation |
| 792 | 792 |
|
| 793 | 793 |
/// Normal (Gauss) distribution with given mean and standard deviation. |
| 794 | 794 |
/// \sa gauss() |
| 795 | 795 |
double gauss(double mean,double std_dev) |
| 796 | 796 |
{
|
| 797 | 797 |
return gauss()*std_dev+mean; |
| 798 | 798 |
} |
| 799 | 799 |
|
| 800 | 800 |
/// Lognormal distribution |
| 801 | 801 |
|
| 802 | 802 |
/// Lognormal distribution. The parameters are the mean and the standard |
| 803 | 803 |
/// deviation of <tt>exp(X)</tt>. |
| 804 | 804 |
/// |
| 805 | 805 |
double lognormal(double n_mean,double n_std_dev) |
| 806 | 806 |
{
|
| 807 | 807 |
return std::exp(gauss(n_mean,n_std_dev)); |
| 808 | 808 |
} |
| 809 | 809 |
/// Lognormal distribution |
| 810 | 810 |
|
| 811 | 811 |
/// Lognormal distribution. The parameter is an <tt>std::pair</tt> of |
| 812 | 812 |
/// the mean and the standard deviation of <tt>exp(X)</tt>. |
| 813 | 813 |
/// |
| ... | ... |
@@ -893,97 +893,97 @@ |
| 893 | 893 |
|
| 894 | 894 |
/// This function generates a Weibull distribution random number. |
| 895 | 895 |
/// |
| 896 | 896 |
///\param k shape parameter (<tt>k>0</tt>) |
| 897 | 897 |
///\param lambda scale parameter (<tt>lambda>0</tt>) |
| 898 | 898 |
/// |
| 899 | 899 |
double weibull(double k,double lambda) |
| 900 | 900 |
{
|
| 901 | 901 |
return lambda*pow(-std::log(1.0-real<double>()),1.0/k); |
| 902 | 902 |
} |
| 903 | 903 |
|
| 904 | 904 |
/// Pareto distribution |
| 905 | 905 |
|
| 906 | 906 |
/// This function generates a Pareto distribution random number. |
| 907 | 907 |
/// |
| 908 | 908 |
///\param k shape parameter (<tt>k>0</tt>) |
| 909 | 909 |
///\param x_min location parameter (<tt>x_min>0</tt>) |
| 910 | 910 |
/// |
| 911 | 911 |
double pareto(double k,double x_min) |
| 912 | 912 |
{
|
| 913 | 913 |
return exponential(gamma(k,1.0/x_min))+x_min; |
| 914 | 914 |
} |
| 915 | 915 |
|
| 916 | 916 |
/// Poisson distribution |
| 917 | 917 |
|
| 918 | 918 |
/// This function generates a Poisson distribution random number with |
| 919 | 919 |
/// parameter \c lambda. |
| 920 | 920 |
/// |
| 921 | 921 |
/// The probability mass function of this distribusion is |
| 922 | 922 |
/// \f[ \frac{e^{-\lambda}\lambda^k}{k!} \f]
|
| 923 | 923 |
/// \note The algorithm is taken from the book of Donald E. Knuth titled |
| 924 | 924 |
/// ''Seminumerical Algorithms'' (1969). Its running time is linear in the |
| 925 | 925 |
/// return value. |
| 926 | 926 |
|
| 927 | 927 |
int poisson(double lambda) |
| 928 | 928 |
{
|
| 929 | 929 |
const double l = std::exp(-lambda); |
| 930 | 930 |
int k=0; |
| 931 | 931 |
double p = 1.0; |
| 932 | 932 |
do {
|
| 933 | 933 |
k++; |
| 934 | 934 |
p*=real<double>(); |
| 935 | 935 |
} while (p>=l); |
| 936 | 936 |
return k-1; |
| 937 | 937 |
} |
| 938 | 938 |
|
| 939 | 939 |
///@} |
| 940 | 940 |
|
| 941 |
///\name Two |
|
| 941 |
///\name Two Dimensional Distributions |
|
| 942 | 942 |
/// |
| 943 | 943 |
///@{
|
| 944 | 944 |
|
| 945 | 945 |
/// Uniform distribution on the full unit circle |
| 946 | 946 |
|
| 947 | 947 |
/// Uniform distribution on the full unit circle. |
| 948 | 948 |
/// |
| 949 | 949 |
dim2::Point<double> disc() |
| 950 | 950 |
{
|
| 951 | 951 |
double V1,V2; |
| 952 | 952 |
do {
|
| 953 | 953 |
V1=2*real<double>()-1; |
| 954 | 954 |
V2=2*real<double>()-1; |
| 955 | 955 |
|
| 956 | 956 |
} while(V1*V1+V2*V2>=1); |
| 957 | 957 |
return dim2::Point<double>(V1,V2); |
| 958 | 958 |
} |
| 959 | 959 |
/// A kind of two dimensional normal (Gauss) distribution |
| 960 | 960 |
|
| 961 | 961 |
/// This function provides a turning symmetric two-dimensional distribution. |
| 962 | 962 |
/// Both coordinates are of standard normal distribution, but they are not |
| 963 | 963 |
/// independent. |
| 964 | 964 |
/// |
| 965 | 965 |
/// \note The coordinates are the two random variables provided by |
| 966 | 966 |
/// the Box-Muller method. |
| 967 | 967 |
dim2::Point<double> gauss2() |
| 968 | 968 |
{
|
| 969 | 969 |
double V1,V2,S; |
| 970 | 970 |
do {
|
| 971 | 971 |
V1=2*real<double>()-1; |
| 972 | 972 |
V2=2*real<double>()-1; |
| 973 | 973 |
S=V1*V1+V2*V2; |
| 974 | 974 |
} while(S>=1); |
| 975 | 975 |
double W=std::sqrt(-2*std::log(S)/S); |
| 976 | 976 |
return dim2::Point<double>(W*V1,W*V2); |
| 977 | 977 |
} |
| 978 | 978 |
/// A kind of two dimensional exponential distribution |
| 979 | 979 |
|
| 980 | 980 |
/// This function provides a turning symmetric two-dimensional distribution. |
| 981 | 981 |
/// The x-coordinate is of conditionally exponential distribution |
| 982 | 982 |
/// with the condition that x is positive and y=0. If x is negative and |
| 983 | 983 |
/// y=0 then, -x is of exponential distribution. The same is true for the |
| 984 | 984 |
/// y-coordinate. |
| 985 | 985 |
dim2::Point<double> exponential2() |
| 986 | 986 |
{
|
| 987 | 987 |
double V1,V2,S; |
| 988 | 988 |
do {
|
| 989 | 989 |
V1=2*real<double>()-1; |
| ... | ... |
@@ -146,99 +146,97 @@ |
| 146 | 146 |
bool operator!=(const Arc i) const {return _id != i._id;}
|
| 147 | 147 |
bool operator<(const Arc i) const {return _id < i._id;}
|
| 148 | 148 |
}; |
| 149 | 149 |
|
| 150 | 150 |
void first(Node& node) const {
|
| 151 | 151 |
node._id = nodes.size() - 1; |
| 152 | 152 |
} |
| 153 | 153 |
|
| 154 | 154 |
static void next(Node& node) {
|
| 155 | 155 |
--node._id; |
| 156 | 156 |
} |
| 157 | 157 |
|
| 158 | 158 |
void first(Arc& arc) const {
|
| 159 | 159 |
arc._id = arcs.size() - 1; |
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 | 162 |
static void next(Arc& arc) {
|
| 163 | 163 |
--arc._id; |
| 164 | 164 |
} |
| 165 | 165 |
|
| 166 | 166 |
void firstOut(Arc& arc, const Node& node) const {
|
| 167 | 167 |
arc._id = nodes[node._id].first_out; |
| 168 | 168 |
} |
| 169 | 169 |
|
| 170 | 170 |
void nextOut(Arc& arc) const {
|
| 171 | 171 |
arc._id = arcs[arc._id].next_out; |
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 | 174 |
void firstIn(Arc& arc, const Node& node) const {
|
| 175 | 175 |
arc._id = nodes[node._id].first_in; |
| 176 | 176 |
} |
| 177 | 177 |
|
| 178 | 178 |
void nextIn(Arc& arc) const {
|
| 179 | 179 |
arc._id = arcs[arc._id].next_in; |
| 180 | 180 |
} |
| 181 | 181 |
|
| 182 | 182 |
}; |
| 183 | 183 |
|
| 184 | 184 |
typedef DigraphExtender<SmartDigraphBase> ExtendedSmartDigraphBase; |
| 185 | 185 |
|
| 186 | 186 |
///\ingroup graphs |
| 187 | 187 |
/// |
| 188 | 188 |
///\brief A smart directed graph class. |
| 189 | 189 |
/// |
| 190 | 190 |
///This is a simple and fast digraph implementation. |
| 191 | 191 |
///It is also quite memory efficient, but at the price |
| 192 | 192 |
///that <b> it does support only limited (only stack-like) |
| 193 | 193 |
///node and arc deletions</b>. |
| 194 |
///It conforms to the \ref concepts::Digraph "Digraph concept" with |
|
| 195 |
///an important extra feature that its maps are real \ref |
|
| 196 |
///concepts:: |
|
| 194 |
///It fully conforms to the \ref concepts::Digraph "Digraph concept". |
|
| 197 | 195 |
/// |
| 198 | 196 |
///\sa concepts::Digraph. |
| 199 | 197 |
class SmartDigraph : public ExtendedSmartDigraphBase {
|
| 200 | 198 |
public: |
| 201 | 199 |
|
| 202 | 200 |
typedef ExtendedSmartDigraphBase Parent; |
| 203 | 201 |
|
| 204 | 202 |
private: |
| 205 | 203 |
|
| 206 | 204 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
| 207 | 205 |
|
| 208 | 206 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
| 209 | 207 |
/// |
| 210 | 208 |
SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
|
| 211 | 209 |
///\brief Assignment of SmartDigraph to another one is \e not allowed. |
| 212 | 210 |
///Use DigraphCopy() instead. |
| 213 | 211 |
|
| 214 | 212 |
///Assignment of SmartDigraph to another one is \e not allowed. |
| 215 | 213 |
///Use DigraphCopy() instead. |
| 216 | 214 |
void operator=(const SmartDigraph &) {}
|
| 217 | 215 |
|
| 218 | 216 |
public: |
| 219 | 217 |
|
| 220 | 218 |
/// Constructor |
| 221 | 219 |
|
| 222 | 220 |
/// Constructor. |
| 223 | 221 |
/// |
| 224 | 222 |
SmartDigraph() {};
|
| 225 | 223 |
|
| 226 | 224 |
///Add a new node to the digraph. |
| 227 | 225 |
|
| 228 | 226 |
/// Add a new node to the digraph. |
| 229 | 227 |
/// \return The new node. |
| 230 | 228 |
Node addNode() { return Parent::addNode(); }
|
| 231 | 229 |
|
| 232 | 230 |
///Add a new arc to the digraph. |
| 233 | 231 |
|
| 234 | 232 |
///Add a new arc to the digraph with source node \c s |
| 235 | 233 |
///and target node \c t. |
| 236 | 234 |
///\return The new arc. |
| 237 | 235 |
Arc addArc(const Node& s, const Node& t) {
|
| 238 | 236 |
return Parent::addArc(s, t); |
| 239 | 237 |
} |
| 240 | 238 |
|
| 241 | 239 |
/// \brief Using this it is possible to avoid the superfluous memory |
| 242 | 240 |
/// allocation. |
| 243 | 241 |
|
| 244 | 242 |
/// Using this it is possible to avoid the superfluous memory |
| ... | ... |
@@ -584,105 +582,99 @@ |
| 584 | 582 |
return a._id >= 0 && a._id < static_cast<int>(arcs.size()); |
| 585 | 583 |
} |
| 586 | 584 |
bool valid(Edge e) const {
|
| 587 | 585 |
return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size()); |
| 588 | 586 |
} |
| 589 | 587 |
|
| 590 | 588 |
Node addNode() {
|
| 591 | 589 |
int n = nodes.size(); |
| 592 | 590 |
nodes.push_back(NodeT()); |
| 593 | 591 |
nodes[n].first_out = -1; |
| 594 | 592 |
|
| 595 | 593 |
return Node(n); |
| 596 | 594 |
} |
| 597 | 595 |
|
| 598 | 596 |
Edge addEdge(Node u, Node v) {
|
| 599 | 597 |
int n = arcs.size(); |
| 600 | 598 |
arcs.push_back(ArcT()); |
| 601 | 599 |
arcs.push_back(ArcT()); |
| 602 | 600 |
|
| 603 | 601 |
arcs[n].target = u._id; |
| 604 | 602 |
arcs[n | 1].target = v._id; |
| 605 | 603 |
|
| 606 | 604 |
arcs[n].next_out = nodes[v._id].first_out; |
| 607 | 605 |
nodes[v._id].first_out = n; |
| 608 | 606 |
|
| 609 | 607 |
arcs[n | 1].next_out = nodes[u._id].first_out; |
| 610 | 608 |
nodes[u._id].first_out = (n | 1); |
| 611 | 609 |
|
| 612 | 610 |
return Edge(n / 2); |
| 613 | 611 |
} |
| 614 | 612 |
|
| 615 | 613 |
void clear() {
|
| 616 | 614 |
arcs.clear(); |
| 617 | 615 |
nodes.clear(); |
| 618 | 616 |
} |
| 619 | 617 |
|
| 620 | 618 |
}; |
| 621 | 619 |
|
| 622 | 620 |
typedef GraphExtender<SmartGraphBase> ExtendedSmartGraphBase; |
| 623 | 621 |
|
| 624 | 622 |
/// \ingroup graphs |
| 625 | 623 |
/// |
| 626 | 624 |
/// \brief A smart undirected graph class. |
| 627 | 625 |
/// |
| 628 | 626 |
/// This is a simple and fast graph implementation. |
| 629 | 627 |
/// It is also quite memory efficient, but at the price |
| 630 | 628 |
/// that <b> it does support only limited (only stack-like) |
| 631 | 629 |
/// node and arc deletions</b>. |
| 632 |
/// Except from this it conforms to |
|
| 633 |
/// the \ref concepts::Graph "Graph concept". |
|
| 634 |
/// |
|
| 635 |
/// It also has an |
|
| 636 |
/// important extra feature that |
|
| 637 |
/// its maps are real \ref concepts::ReferenceMap "reference map"s. |
|
| 630 |
/// It fully conforms to the \ref concepts::Graph "Graph concept". |
|
| 638 | 631 |
/// |
| 639 | 632 |
/// \sa concepts::Graph. |
| 640 |
/// |
|
| 641 | 633 |
class SmartGraph : public ExtendedSmartGraphBase {
|
| 642 | 634 |
private: |
| 643 | 635 |
|
| 644 | 636 |
///SmartGraph is \e not copy constructible. Use GraphCopy() instead. |
| 645 | 637 |
|
| 646 | 638 |
///SmartGraph is \e not copy constructible. Use GraphCopy() instead. |
| 647 | 639 |
/// |
| 648 | 640 |
SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
|
| 649 | 641 |
|
| 650 | 642 |
///\brief Assignment of SmartGraph to another one is \e not allowed. |
| 651 | 643 |
///Use GraphCopy() instead. |
| 652 | 644 |
|
| 653 | 645 |
///Assignment of SmartGraph to another one is \e not allowed. |
| 654 | 646 |
///Use GraphCopy() instead. |
| 655 | 647 |
void operator=(const SmartGraph &) {}
|
| 656 | 648 |
|
| 657 | 649 |
public: |
| 658 | 650 |
|
| 659 | 651 |
typedef ExtendedSmartGraphBase Parent; |
| 660 | 652 |
|
| 661 | 653 |
/// Constructor |
| 662 | 654 |
|
| 663 | 655 |
/// Constructor. |
| 664 | 656 |
/// |
| 665 | 657 |
SmartGraph() {}
|
| 666 | 658 |
|
| 667 | 659 |
///Add a new node to the graph. |
| 668 | 660 |
|
| 669 | 661 |
/// Add a new node to the graph. |
| 670 | 662 |
/// \return The new node. |
| 671 | 663 |
Node addNode() { return Parent::addNode(); }
|
| 672 | 664 |
|
| 673 | 665 |
///Add a new edge to the graph. |
| 674 | 666 |
|
| 675 | 667 |
///Add a new edge to the graph with node \c s |
| 676 | 668 |
///and \c t. |
| 677 | 669 |
///\return The new edge. |
| 678 | 670 |
Edge addEdge(const Node& s, const Node& t) {
|
| 679 | 671 |
return Parent::addEdge(s, t); |
| 680 | 672 |
} |
| 681 | 673 |
|
| 682 | 674 |
/// \brief Node validity check |
| 683 | 675 |
/// |
| 684 | 676 |
/// This function gives back true if the given node is valid, |
| 685 | 677 |
/// ie. it is a real node of the graph. |
| 686 | 678 |
/// |
| 687 | 679 |
/// \warning A removed node (using Snapshot) could become valid again |
| 688 | 680 |
/// when new nodes are added to the graph. |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <iostream> |
| 20 | 20 |
#include <lemon/soplex.h> |
| 21 | 21 |
|
| 22 | 22 |
#include <soplex.h> |
| 23 |
#include <spxout.h> |
|
| 23 | 24 |
|
| 24 | 25 |
|
| 25 | 26 |
///\file |
| 26 | 27 |
///\brief Implementation of the LEMON-SOPLEX lp solver interface. |
| 27 | 28 |
namespace lemon {
|
| 28 | 29 |
|
| 29 | 30 |
SoplexLp::SoplexLp() {
|
| 30 | 31 |
soplex = new soplex::SoPlex; |
| 32 |
messageLevel(MESSAGE_NOTHING); |
|
| 31 | 33 |
} |
| 32 | 34 |
|
| 33 | 35 |
SoplexLp::~SoplexLp() {
|
| 34 | 36 |
delete soplex; |
| 35 | 37 |
} |
| 36 | 38 |
|
| 37 | 39 |
SoplexLp::SoplexLp(const SoplexLp& lp) {
|
| 38 | 40 |
rows = lp.rows; |
| 39 | 41 |
cols = lp.cols; |
| 40 | 42 |
|
| 41 | 43 |
soplex = new soplex::SoPlex; |
| 42 | 44 |
(*static_cast<soplex::SPxLP*>(soplex)) = *(lp.soplex); |
| 43 | 45 |
|
| 44 | 46 |
_col_names = lp._col_names; |
| 45 | 47 |
_col_names_ref = lp._col_names_ref; |
| 46 | 48 |
|
| 47 | 49 |
_row_names = lp._row_names; |
| 48 | 50 |
_row_names_ref = lp._row_names_ref; |
| 49 | 51 |
|
| 52 |
messageLevel(MESSAGE_NOTHING); |
|
| 50 | 53 |
} |
| 51 | 54 |
|
| 52 | 55 |
void SoplexLp::_clear_temporals() {
|
| 53 | 56 |
_primal_values.clear(); |
| 54 | 57 |
_dual_values.clear(); |
| 55 | 58 |
} |
| 56 | 59 |
|
| 57 | 60 |
SoplexLp* SoplexLp::newSolver() const {
|
| 58 | 61 |
SoplexLp* newlp = new SoplexLp(); |
| 59 | 62 |
return newlp; |
| 60 | 63 |
} |
| 61 | 64 |
|
| 62 | 65 |
SoplexLp* SoplexLp::cloneSolver() const {
|
| 63 | 66 |
SoplexLp* newlp = new SoplexLp(*this); |
| 64 | 67 |
return newlp; |
| 65 | 68 |
} |
| 66 | 69 |
|
| 67 | 70 |
const char* SoplexLp::_solverName() const { return "SoplexLp"; }
|
| 68 | 71 |
|
| 69 | 72 |
int SoplexLp::_addCol() {
|
| 70 | 73 |
soplex::LPCol c; |
| 71 | 74 |
c.setLower(-soplex::infinity); |
| 72 | 75 |
c.setUpper(soplex::infinity); |
| 73 | 76 |
soplex->addCol(c); |
| 74 | 77 |
|
| 75 | 78 |
_col_names.push_back(std::string()); |
| 76 | 79 |
|
| 77 | 80 |
return soplex->nCols() - 1; |
| 78 | 81 |
} |
| 79 | 82 |
|
| 80 | 83 |
int SoplexLp::_addRow() {
|
| 81 | 84 |
soplex::LPRow r; |
| 82 | 85 |
r.setLhs(-soplex::infinity); |
| 83 | 86 |
r.setRhs(soplex::infinity); |
| 84 | 87 |
soplex->addRow(r); |
| 85 | 88 |
|
| 86 | 89 |
_row_names.push_back(std::string()); |
| 87 | 90 |
|
| 88 | 91 |
return soplex->nRows() - 1; |
| 89 | 92 |
} |
| 90 | 93 |
|
| 91 | 94 |
|
| 92 | 95 |
void SoplexLp::_eraseCol(int i) {
|
| 93 | 96 |
soplex->removeCol(i); |
| 94 | 97 |
_col_names_ref.erase(_col_names[i]); |
| 95 | 98 |
_col_names[i] = _col_names.back(); |
| 96 | 99 |
_col_names_ref[_col_names.back()] = i; |
| 97 | 100 |
_col_names.pop_back(); |
| ... | ... |
@@ -226,96 +229,98 @@ |
| 226 | 229 |
soplex->changeRange(i, lb != -INF ? lb : -soplex::infinity, soplex->rhs(i)); |
| 227 | 230 |
} |
| 228 | 231 |
|
| 229 | 232 |
SoplexLp::Value SoplexLp::_getRowLowerBound(int i) const {
|
| 230 | 233 |
double res = soplex->lhs(i); |
| 231 | 234 |
return res == -soplex::infinity ? -INF : res; |
| 232 | 235 |
} |
| 233 | 236 |
|
| 234 | 237 |
void SoplexLp::_setRowUpperBound(int i, Value ub) {
|
| 235 | 238 |
LEMON_ASSERT(ub != -INF, "Invalid bound"); |
| 236 | 239 |
soplex->changeRange(i, soplex->lhs(i), ub != INF ? ub : soplex::infinity); |
| 237 | 240 |
} |
| 238 | 241 |
|
| 239 | 242 |
SoplexLp::Value SoplexLp::_getRowUpperBound(int i) const {
|
| 240 | 243 |
double res = soplex->rhs(i); |
| 241 | 244 |
return res == soplex::infinity ? INF : res; |
| 242 | 245 |
} |
| 243 | 246 |
|
| 244 | 247 |
void SoplexLp::_setObjCoeffs(ExprIterator b, ExprIterator e) {
|
| 245 | 248 |
for (int j = 0; j < soplex->nCols(); ++j) {
|
| 246 | 249 |
soplex->changeObj(j, 0.0); |
| 247 | 250 |
} |
| 248 | 251 |
for (ExprIterator it = b; it != e; ++it) {
|
| 249 | 252 |
soplex->changeObj(it->first, it->second); |
| 250 | 253 |
} |
| 251 | 254 |
} |
| 252 | 255 |
|
| 253 | 256 |
void SoplexLp::_getObjCoeffs(InsertIterator b) const {
|
| 254 | 257 |
for (int j = 0; j < soplex->nCols(); ++j) {
|
| 255 | 258 |
Value coef = soplex->obj(j); |
| 256 | 259 |
if (coef != 0.0) {
|
| 257 | 260 |
*b = std::make_pair(j, coef); |
| 258 | 261 |
++b; |
| 259 | 262 |
} |
| 260 | 263 |
} |
| 261 | 264 |
} |
| 262 | 265 |
|
| 263 | 266 |
void SoplexLp::_setObjCoeff(int i, Value obj_coef) {
|
| 264 | 267 |
soplex->changeObj(i, obj_coef); |
| 265 | 268 |
} |
| 266 | 269 |
|
| 267 | 270 |
SoplexLp::Value SoplexLp::_getObjCoeff(int i) const {
|
| 268 | 271 |
return soplex->obj(i); |
| 269 | 272 |
} |
| 270 | 273 |
|
| 271 | 274 |
SoplexLp::SolveExitStatus SoplexLp::_solve() {
|
| 272 | 275 |
|
| 273 | 276 |
_clear_temporals(); |
| 277 |
|
|
| 278 |
_applyMessageLevel(); |
|
| 274 | 279 |
|
| 275 | 280 |
soplex::SPxSolver::Status status = soplex->solve(); |
| 276 | 281 |
|
| 277 | 282 |
switch (status) {
|
| 278 | 283 |
case soplex::SPxSolver::OPTIMAL: |
| 279 | 284 |
case soplex::SPxSolver::INFEASIBLE: |
| 280 | 285 |
case soplex::SPxSolver::UNBOUNDED: |
| 281 | 286 |
return SOLVED; |
| 282 | 287 |
default: |
| 283 | 288 |
return UNSOLVED; |
| 284 | 289 |
} |
| 285 | 290 |
} |
| 286 | 291 |
|
| 287 | 292 |
SoplexLp::Value SoplexLp::_getPrimal(int i) const {
|
| 288 | 293 |
if (_primal_values.empty()) {
|
| 289 | 294 |
_primal_values.resize(soplex->nCols()); |
| 290 | 295 |
soplex::Vector pv(_primal_values.size(), &_primal_values.front()); |
| 291 | 296 |
soplex->getPrimal(pv); |
| 292 | 297 |
} |
| 293 | 298 |
return _primal_values[i]; |
| 294 | 299 |
} |
| 295 | 300 |
|
| 296 | 301 |
SoplexLp::Value SoplexLp::_getDual(int i) const {
|
| 297 | 302 |
if (_dual_values.empty()) {
|
| 298 | 303 |
_dual_values.resize(soplex->nRows()); |
| 299 | 304 |
soplex::Vector dv(_dual_values.size(), &_dual_values.front()); |
| 300 | 305 |
soplex->getDual(dv); |
| 301 | 306 |
} |
| 302 | 307 |
return _dual_values[i]; |
| 303 | 308 |
} |
| 304 | 309 |
|
| 305 | 310 |
SoplexLp::Value SoplexLp::_getPrimalValue() const {
|
| 306 | 311 |
return soplex->objValue(); |
| 307 | 312 |
} |
| 308 | 313 |
|
| 309 | 314 |
SoplexLp::VarStatus SoplexLp::_getColStatus(int i) const {
|
| 310 | 315 |
switch (soplex->getBasisColStatus(i)) {
|
| 311 | 316 |
case soplex::SPxSolver::BASIC: |
| 312 | 317 |
return BASIC; |
| 313 | 318 |
case soplex::SPxSolver::ON_UPPER: |
| 314 | 319 |
return UPPER; |
| 315 | 320 |
case soplex::SPxSolver::ON_LOWER: |
| 316 | 321 |
return LOWER; |
| 317 | 322 |
case soplex::SPxSolver::FIXED: |
| 318 | 323 |
return FIXED; |
| 319 | 324 |
case soplex::SPxSolver::ZERO: |
| 320 | 325 |
return FREE; |
| 321 | 326 |
default: |
| ... | ... |
@@ -374,50 +379,74 @@ |
| 374 | 379 |
} |
| 375 | 380 |
|
| 376 | 381 |
SoplexLp::ProblemType SoplexLp::_getDualType() const {
|
| 377 | 382 |
switch (soplex->status()) {
|
| 378 | 383 |
case soplex::SPxSolver::OPTIMAL: |
| 379 | 384 |
return OPTIMAL; |
| 380 | 385 |
case soplex::SPxSolver::UNBOUNDED: |
| 381 | 386 |
return UNBOUNDED; |
| 382 | 387 |
case soplex::SPxSolver::INFEASIBLE: |
| 383 | 388 |
return INFEASIBLE; |
| 384 | 389 |
default: |
| 385 | 390 |
return UNDEFINED; |
| 386 | 391 |
} |
| 387 | 392 |
} |
| 388 | 393 |
|
| 389 | 394 |
void SoplexLp::_setSense(Sense sense) {
|
| 390 | 395 |
switch (sense) {
|
| 391 | 396 |
case MIN: |
| 392 | 397 |
soplex->changeSense(soplex::SPxSolver::MINIMIZE); |
| 393 | 398 |
break; |
| 394 | 399 |
case MAX: |
| 395 | 400 |
soplex->changeSense(soplex::SPxSolver::MAXIMIZE); |
| 396 | 401 |
} |
| 397 | 402 |
} |
| 398 | 403 |
|
| 399 | 404 |
SoplexLp::Sense SoplexLp::_getSense() const {
|
| 400 | 405 |
switch (soplex->spxSense()) {
|
| 401 | 406 |
case soplex::SPxSolver::MAXIMIZE: |
| 402 | 407 |
return MAX; |
| 403 | 408 |
case soplex::SPxSolver::MINIMIZE: |
| 404 | 409 |
return MIN; |
| 405 | 410 |
default: |
| 406 | 411 |
LEMON_ASSERT(false, "Wrong sense."); |
| 407 | 412 |
return SoplexLp::Sense(); |
| 408 | 413 |
} |
| 409 | 414 |
} |
| 410 | 415 |
|
| 411 | 416 |
void SoplexLp::_clear() {
|
| 412 | 417 |
soplex->clear(); |
| 413 | 418 |
_col_names.clear(); |
| 414 | 419 |
_col_names_ref.clear(); |
| 415 | 420 |
_row_names.clear(); |
| 416 | 421 |
_row_names_ref.clear(); |
| 417 | 422 |
cols.clear(); |
| 418 | 423 |
rows.clear(); |
| 419 | 424 |
_clear_temporals(); |
| 420 | 425 |
} |
| 421 | 426 |
|
| 427 |
void SoplexLp::_messageLevel(MessageLevel level) {
|
|
| 428 |
switch (level) {
|
|
| 429 |
case MESSAGE_NOTHING: |
|
| 430 |
_message_level = -1; |
|
| 431 |
break; |
|
| 432 |
case MESSAGE_ERROR: |
|
| 433 |
_message_level = soplex::SPxOut::ERROR; |
|
| 434 |
break; |
|
| 435 |
case MESSAGE_WARNING: |
|
| 436 |
_message_level = soplex::SPxOut::WARNING; |
|
| 437 |
break; |
|
| 438 |
case MESSAGE_NORMAL: |
|
| 439 |
_message_level = soplex::SPxOut::INFO2; |
|
| 440 |
break; |
|
| 441 |
case MESSAGE_VERBOSE: |
|
| 442 |
_message_level = soplex::SPxOut::DEBUG; |
|
| 443 |
break; |
|
| 444 |
} |
|
| 445 |
} |
|
| 446 |
|
|
| 447 |
void SoplexLp::_applyMessageLevel() {
|
|
| 448 |
soplex::Param::setVerbose(_message_level); |
|
| 449 |
} |
|
| 450 |
|
|
| 422 | 451 |
} //namespace lemon |
| 423 | 452 |
| ... | ... |
@@ -99,54 +99,59 @@ |
| 99 | 99 |
virtual void _setRowName(int row, const std::string& name); |
| 100 | 100 |
virtual int _rowByName(const std::string& name) const; |
| 101 | 101 |
|
| 102 | 102 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
| 103 | 103 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
| 104 | 104 |
|
| 105 | 105 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
| 106 | 106 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
| 107 | 107 |
|
| 108 | 108 |
virtual void _setCoeff(int row, int col, Value value); |
| 109 | 109 |
virtual Value _getCoeff(int row, int col) const; |
| 110 | 110 |
|
| 111 | 111 |
virtual void _setColLowerBound(int i, Value value); |
| 112 | 112 |
virtual Value _getColLowerBound(int i) const; |
| 113 | 113 |
virtual void _setColUpperBound(int i, Value value); |
| 114 | 114 |
virtual Value _getColUpperBound(int i) const; |
| 115 | 115 |
|
| 116 | 116 |
virtual void _setRowLowerBound(int i, Value value); |
| 117 | 117 |
virtual Value _getRowLowerBound(int i) const; |
| 118 | 118 |
virtual void _setRowUpperBound(int i, Value value); |
| 119 | 119 |
virtual Value _getRowUpperBound(int i) const; |
| 120 | 120 |
|
| 121 | 121 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
| 122 | 122 |
virtual void _getObjCoeffs(InsertIterator b) const; |
| 123 | 123 |
|
| 124 | 124 |
virtual void _setObjCoeff(int i, Value obj_coef); |
| 125 | 125 |
virtual Value _getObjCoeff(int i) const; |
| 126 | 126 |
|
| 127 | 127 |
virtual void _setSense(Sense sense); |
| 128 | 128 |
virtual Sense _getSense() const; |
| 129 | 129 |
|
| 130 | 130 |
virtual SolveExitStatus _solve(); |
| 131 | 131 |
virtual Value _getPrimal(int i) const; |
| 132 | 132 |
virtual Value _getDual(int i) const; |
| 133 | 133 |
|
| 134 | 134 |
virtual Value _getPrimalValue() const; |
| 135 | 135 |
|
| 136 | 136 |
virtual Value _getPrimalRay(int i) const; |
| 137 | 137 |
virtual Value _getDualRay(int i) const; |
| 138 | 138 |
|
| 139 | 139 |
virtual VarStatus _getColStatus(int i) const; |
| 140 | 140 |
virtual VarStatus _getRowStatus(int i) const; |
| 141 | 141 |
|
| 142 | 142 |
virtual ProblemType _getPrimalType() const; |
| 143 | 143 |
virtual ProblemType _getDualType() const; |
| 144 | 144 |
|
| 145 | 145 |
virtual void _clear(); |
| 146 | 146 |
|
| 147 |
void _messageLevel(MessageLevel m); |
|
| 148 |
void _applyMessageLevel(); |
|
| 149 |
|
|
| 150 |
int _message_level; |
|
| 151 |
|
|
| 147 | 152 |
}; |
| 148 | 153 |
|
| 149 | 154 |
} //END OF NAMESPACE LEMON |
| 150 | 155 |
|
| 151 | 156 |
#endif //LEMON_SOPLEX_H |
| 152 | 157 |
| ... | ... |
@@ -243,97 +243,97 @@ |
| 243 | 243 |
Suurballe( const Digraph &digraph, |
| 244 | 244 |
const LengthMap &length, |
| 245 | 245 |
Node s, Node t ) : |
| 246 | 246 |
_graph(digraph), _length(length), _flow(0), _local_flow(false), |
| 247 | 247 |
_potential(0), _local_potential(false), _source(s), _target(t), |
| 248 | 248 |
_pred(digraph) {}
|
| 249 | 249 |
|
| 250 | 250 |
/// Destructor. |
| 251 | 251 |
~Suurballe() {
|
| 252 | 252 |
if (_local_flow) delete _flow; |
| 253 | 253 |
if (_local_potential) delete _potential; |
| 254 | 254 |
delete _dijkstra; |
| 255 | 255 |
} |
| 256 | 256 |
|
| 257 | 257 |
/// \brief Set the flow map. |
| 258 | 258 |
/// |
| 259 | 259 |
/// This function sets the flow map. |
| 260 | 260 |
/// |
| 261 | 261 |
/// The found flow contains only 0 and 1 values. It is the union of |
| 262 | 262 |
/// the found arc-disjoint paths. |
| 263 | 263 |
/// |
| 264 | 264 |
/// \return <tt>(*this)</tt> |
| 265 | 265 |
Suurballe& flowMap(FlowMap &map) {
|
| 266 | 266 |
if (_local_flow) {
|
| 267 | 267 |
delete _flow; |
| 268 | 268 |
_local_flow = false; |
| 269 | 269 |
} |
| 270 | 270 |
_flow = ↦ |
| 271 | 271 |
return *this; |
| 272 | 272 |
} |
| 273 | 273 |
|
| 274 | 274 |
/// \brief Set the potential map. |
| 275 | 275 |
/// |
| 276 | 276 |
/// This function sets the potential map. |
| 277 | 277 |
/// |
| 278 | 278 |
/// The potentials provide the dual solution of the underlying |
| 279 | 279 |
/// minimum cost flow problem. |
| 280 | 280 |
/// |
| 281 | 281 |
/// \return <tt>(*this)</tt> |
| 282 | 282 |
Suurballe& potentialMap(PotentialMap &map) {
|
| 283 | 283 |
if (_local_potential) {
|
| 284 | 284 |
delete _potential; |
| 285 | 285 |
_local_potential = false; |
| 286 | 286 |
} |
| 287 | 287 |
_potential = ↦ |
| 288 | 288 |
return *this; |
| 289 | 289 |
} |
| 290 | 290 |
|
| 291 |
/// \name Execution |
|
| 291 |
/// \name Execution Control |
|
| 292 | 292 |
/// The simplest way to execute the algorithm is to call the run() |
| 293 | 293 |
/// function. |
| 294 | 294 |
/// \n |
| 295 | 295 |
/// If you only need the flow that is the union of the found |
| 296 | 296 |
/// arc-disjoint paths, you may call init() and findFlow(). |
| 297 | 297 |
|
| 298 | 298 |
/// @{
|
| 299 | 299 |
|
| 300 | 300 |
/// \brief Run the algorithm. |
| 301 | 301 |
/// |
| 302 | 302 |
/// This function runs the algorithm. |
| 303 | 303 |
/// |
| 304 | 304 |
/// \param k The number of paths to be found. |
| 305 | 305 |
/// |
| 306 | 306 |
/// \return \c k if there are at least \c k arc-disjoint paths from |
| 307 | 307 |
/// \c s to \c t in the digraph. Otherwise it returns the number of |
| 308 | 308 |
/// arc-disjoint paths found. |
| 309 | 309 |
/// |
| 310 | 310 |
/// \note Apart from the return value, <tt>s.run(k)</tt> is just a |
| 311 | 311 |
/// shortcut of the following code. |
| 312 | 312 |
/// \code |
| 313 | 313 |
/// s.init(); |
| 314 | 314 |
/// s.findFlow(k); |
| 315 | 315 |
/// s.findPaths(); |
| 316 | 316 |
/// \endcode |
| 317 | 317 |
int run(int k = 2) {
|
| 318 | 318 |
init(); |
| 319 | 319 |
findFlow(k); |
| 320 | 320 |
findPaths(); |
| 321 | 321 |
return _path_num; |
| 322 | 322 |
} |
| 323 | 323 |
|
| 324 | 324 |
/// \brief Initialize the algorithm. |
| 325 | 325 |
/// |
| 326 | 326 |
/// This function initializes the algorithm. |
| 327 | 327 |
void init() {
|
| 328 | 328 |
// Initialize maps |
| 329 | 329 |
if (!_flow) {
|
| 330 | 330 |
_flow = new FlowMap(_graph); |
| 331 | 331 |
_local_flow = true; |
| 332 | 332 |
} |
| 333 | 333 |
if (!_potential) {
|
| 334 | 334 |
_potential = new PotentialMap(_graph); |
| 335 | 335 |
_local_potential = true; |
| 336 | 336 |
} |
| 337 | 337 |
for (ArcIt e(_graph); e != INVALID; ++e) (*_flow)[e] = 0; |
| 338 | 338 |
for (NodeIt n(_graph); n != INVALID; ++n) (*_potential)[n] = 0; |
| 339 | 339 |
| ... | ... |
@@ -242,97 +242,97 @@ |
| 242 | 242 |
/// |
| 243 | 243 |
/// int main() |
| 244 | 244 |
/// {
|
| 245 | 245 |
/// |
| 246 | 246 |
/// ... |
| 247 | 247 |
/// |
| 248 | 248 |
/// Timer t; |
| 249 | 249 |
/// doSomething(); |
| 250 | 250 |
/// std::cout << t << '\n'; |
| 251 | 251 |
/// t.restart(); |
| 252 | 252 |
/// doSomethingElse(); |
| 253 | 253 |
/// std::cout << t << '\n'; |
| 254 | 254 |
/// |
| 255 | 255 |
/// ... |
| 256 | 256 |
/// |
| 257 | 257 |
/// } |
| 258 | 258 |
///\endcode |
| 259 | 259 |
/// |
| 260 | 260 |
///The \ref Timer can also be \ref stop() "stopped" and |
| 261 | 261 |
///\ref start() "started" again, so it is possible to compute collected |
| 262 | 262 |
///running times. |
| 263 | 263 |
/// |
| 264 | 264 |
///\warning Depending on the operation system and its actual configuration |
| 265 | 265 |
///the time counters have a certain (10ms on a typical Linux system) |
| 266 | 266 |
///granularity. |
| 267 | 267 |
///Therefore this tool is not appropriate to measure very short times. |
| 268 | 268 |
///Also, if you start and stop the timer very frequently, it could lead to |
| 269 | 269 |
///distorted results. |
| 270 | 270 |
/// |
| 271 | 271 |
///\note If you want to measure the running time of the execution of a certain |
| 272 | 272 |
///function, consider the usage of \ref TimeReport instead. |
| 273 | 273 |
/// |
| 274 | 274 |
///\sa TimeReport |
| 275 | 275 |
class Timer |
| 276 | 276 |
{
|
| 277 | 277 |
int _running; //Timer is running iff _running>0; (_running>=0 always holds) |
| 278 | 278 |
TimeStamp start_time; //This is the relativ start-time if the timer |
| 279 | 279 |
//is _running, the collected _running time otherwise. |
| 280 | 280 |
|
| 281 | 281 |
void _reset() {if(_running) start_time.stamp(); else start_time.reset();}
|
| 282 | 282 |
|
| 283 | 283 |
public: |
| 284 | 284 |
///Constructor. |
| 285 | 285 |
|
| 286 | 286 |
///\param run indicates whether or not the timer starts immediately. |
| 287 | 287 |
/// |
| 288 | 288 |
Timer(bool run=true) :_running(run) {_reset();}
|
| 289 | 289 |
|
| 290 |
///\name Control the |
|
| 290 |
///\name Control the State of the Timer |
|
| 291 | 291 |
///Basically a Timer can be either running or stopped, |
| 292 | 292 |
///but it provides a bit finer control on the execution. |
| 293 | 293 |
///The \ref lemon::Timer "Timer" also counts the number of |
| 294 | 294 |
///\ref lemon::Timer::start() "start()" executions, and it stops |
| 295 | 295 |
///only after the same amount (or more) \ref lemon::Timer::stop() |
| 296 | 296 |
///"stop()"s. This can be useful e.g. to compute the running time |
| 297 | 297 |
///of recursive functions. |
| 298 | 298 |
|
| 299 | 299 |
///@{
|
| 300 | 300 |
|
| 301 | 301 |
///Reset and stop the time counters |
| 302 | 302 |
|
| 303 | 303 |
///This function resets and stops the time counters |
| 304 | 304 |
///\sa restart() |
| 305 | 305 |
void reset() |
| 306 | 306 |
{
|
| 307 | 307 |
_running=0; |
| 308 | 308 |
_reset(); |
| 309 | 309 |
} |
| 310 | 310 |
|
| 311 | 311 |
///Start the time counters |
| 312 | 312 |
|
| 313 | 313 |
///This function starts the time counters. |
| 314 | 314 |
/// |
| 315 | 315 |
///If the timer is started more than ones, it will remain running |
| 316 | 316 |
///until the same amount of \ref stop() is called. |
| 317 | 317 |
///\sa stop() |
| 318 | 318 |
void start() |
| 319 | 319 |
{
|
| 320 | 320 |
if(_running) _running++; |
| 321 | 321 |
else {
|
| 322 | 322 |
_running=1; |
| 323 | 323 |
TimeStamp t; |
| 324 | 324 |
t.stamp(); |
| 325 | 325 |
start_time=t-start_time; |
| 326 | 326 |
} |
| 327 | 327 |
} |
| 328 | 328 |
|
| 329 | 329 |
|
| 330 | 330 |
///Stop the time counters |
| 331 | 331 |
|
| 332 | 332 |
///This function stops the time counters. If start() was executed more than |
| 333 | 333 |
///once, then the same number of stop() execution is necessary the really |
| 334 | 334 |
///stop the timer. |
| 335 | 335 |
/// |
| 336 | 336 |
///\sa halt() |
| 337 | 337 |
///\sa start() |
| 338 | 338 |
///\sa restart() |
| ... | ... |
@@ -350,97 +350,97 @@ |
| 350 | 350 |
///Halt (i.e stop immediately) the time counters |
| 351 | 351 |
|
| 352 | 352 |
///This function stops immediately the time counters, i.e. <tt>t.halt()</tt> |
| 353 | 353 |
///is a faster |
| 354 | 354 |
///equivalent of the following. |
| 355 | 355 |
///\code |
| 356 | 356 |
/// while(t.running()) t.stop() |
| 357 | 357 |
///\endcode |
| 358 | 358 |
/// |
| 359 | 359 |
/// |
| 360 | 360 |
///\sa stop() |
| 361 | 361 |
///\sa restart() |
| 362 | 362 |
///\sa reset() |
| 363 | 363 |
|
| 364 | 364 |
void halt() |
| 365 | 365 |
{
|
| 366 | 366 |
if(_running) {
|
| 367 | 367 |
_running=0; |
| 368 | 368 |
TimeStamp t; |
| 369 | 369 |
t.stamp(); |
| 370 | 370 |
start_time=t-start_time; |
| 371 | 371 |
} |
| 372 | 372 |
} |
| 373 | 373 |
|
| 374 | 374 |
///Returns the running state of the timer |
| 375 | 375 |
|
| 376 | 376 |
///This function returns the number of stop() exections that is |
| 377 | 377 |
///necessary to really stop the timer. |
| 378 | 378 |
///For example the timer |
| 379 | 379 |
///is running if and only if the return value is \c true |
| 380 | 380 |
///(i.e. greater than |
| 381 | 381 |
///zero). |
| 382 | 382 |
int running() { return _running; }
|
| 383 | 383 |
|
| 384 | 384 |
|
| 385 | 385 |
///Restart the time counters |
| 386 | 386 |
|
| 387 | 387 |
///This function is a shorthand for |
| 388 | 388 |
///a reset() and a start() calls. |
| 389 | 389 |
/// |
| 390 | 390 |
void restart() |
| 391 | 391 |
{
|
| 392 | 392 |
reset(); |
| 393 | 393 |
start(); |
| 394 | 394 |
} |
| 395 | 395 |
|
| 396 | 396 |
///@} |
| 397 | 397 |
|
| 398 |
///\name Query Functions for the |
|
| 398 |
///\name Query Functions for the Ellapsed Time |
|
| 399 | 399 |
|
| 400 | 400 |
///@{
|
| 401 | 401 |
|
| 402 | 402 |
///Gives back the ellapsed user time of the process |
| 403 | 403 |
double userTime() const |
| 404 | 404 |
{
|
| 405 | 405 |
return operator TimeStamp().userTime(); |
| 406 | 406 |
} |
| 407 | 407 |
///Gives back the ellapsed system time of the process |
| 408 | 408 |
double systemTime() const |
| 409 | 409 |
{
|
| 410 | 410 |
return operator TimeStamp().systemTime(); |
| 411 | 411 |
} |
| 412 | 412 |
///Gives back the ellapsed user time of the process' children |
| 413 | 413 |
|
| 414 | 414 |
///\note On <tt>WIN32</tt> platform this value is not calculated. |
| 415 | 415 |
/// |
| 416 | 416 |
double cUserTime() const |
| 417 | 417 |
{
|
| 418 | 418 |
return operator TimeStamp().cUserTime(); |
| 419 | 419 |
} |
| 420 | 420 |
///Gives back the ellapsed user time of the process' children |
| 421 | 421 |
|
| 422 | 422 |
///\note On <tt>WIN32</tt> platform this value is not calculated. |
| 423 | 423 |
/// |
| 424 | 424 |
double cSystemTime() const |
| 425 | 425 |
{
|
| 426 | 426 |
return operator TimeStamp().cSystemTime(); |
| 427 | 427 |
} |
| 428 | 428 |
///Gives back the ellapsed real time |
| 429 | 429 |
double realTime() const |
| 430 | 430 |
{
|
| 431 | 431 |
return operator TimeStamp().realTime(); |
| 432 | 432 |
} |
| 433 | 433 |
///Computes the ellapsed time |
| 434 | 434 |
|
| 435 | 435 |
///This conversion computes the ellapsed time, therefore you can print |
| 436 | 436 |
///the ellapsed time like this. |
| 437 | 437 |
///\code |
| 438 | 438 |
/// Timer t; |
| 439 | 439 |
/// doSomething(); |
| 440 | 440 |
/// std::cout << t << '\n'; |
| 441 | 441 |
///\endcode |
| 442 | 442 |
operator TimeStamp () const |
| 443 | 443 |
{
|
| 444 | 444 |
TimeStamp t; |
| 445 | 445 |
t.stamp(); |
| 446 | 446 |
return _running?t-start_time:start_time; |
| ... | ... |
@@ -13,131 +13,170 @@ |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/bfs.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "graph_test.h" |
| 27 | 27 |
#include "test_tools.h" |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
|
| 31 | 31 |
char test_lgf[] = |
| 32 | 32 |
"@nodes\n" |
| 33 | 33 |
"label\n" |
| 34 | 34 |
"0\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"5\n" |
| 40 | 40 |
"@arcs\n" |
| 41 | 41 |
" label\n" |
| 42 | 42 |
"0 1 0\n" |
| 43 | 43 |
"1 2 1\n" |
| 44 | 44 |
"2 3 2\n" |
| 45 | 45 |
"3 4 3\n" |
| 46 | 46 |
"0 3 4\n" |
| 47 | 47 |
"0 3 5\n" |
| 48 | 48 |
"5 2 6\n" |
| 49 | 49 |
"@attributes\n" |
| 50 | 50 |
"source 0\n" |
| 51 | 51 |
"target 4\n"; |
| 52 | 52 |
|
| 53 | 53 |
void checkBfsCompile() |
| 54 | 54 |
{
|
| 55 | 55 |
typedef concepts::Digraph Digraph; |
| 56 | 56 |
typedef Bfs<Digraph> BType; |
| 57 | 57 |
typedef Digraph::Node Node; |
| 58 | 58 |
typedef Digraph::Arc Arc; |
| 59 | 59 |
|
| 60 | 60 |
Digraph G; |
| 61 |
Node s, t; |
|
| 61 |
Node s, t, n; |
|
| 62 | 62 |
Arc e; |
| 63 |
int l; |
|
| 63 |
int l, i; |
|
| 64 | 64 |
bool b; |
| 65 | 65 |
BType::DistMap d(G); |
| 66 | 66 |
BType::PredMap p(G); |
| 67 | 67 |
Path<Digraph> pp; |
| 68 |
concepts::ReadMap<Node,bool> nm; |
|
| 68 | 69 |
|
| 69 | 70 |
{
|
| 70 | 71 |
BType bfs_test(G); |
| 72 |
const BType& const_bfs_test = bfs_test; |
|
| 71 | 73 |
|
| 72 | 74 |
bfs_test.run(s); |
| 73 | 75 |
bfs_test.run(s,t); |
| 74 | 76 |
bfs_test.run(); |
| 75 | 77 |
|
| 76 |
l = bfs_test.dist(t); |
|
| 77 |
e = bfs_test.predArc(t); |
|
| 78 |
s = bfs_test.predNode(t); |
|
| 79 |
b = bfs_test.reached(t); |
|
| 80 |
d = bfs_test.distMap(); |
|
| 81 |
p = bfs_test.predMap(); |
|
| 82 |
|
|
| 78 |
bfs_test.init(); |
|
| 79 |
bfs_test.addSource(s); |
|
| 80 |
n = bfs_test.processNextNode(); |
|
| 81 |
n = bfs_test.processNextNode(t, b); |
|
| 82 |
n = bfs_test.processNextNode(nm, n); |
|
| 83 |
n = const_bfs_test.nextNode(); |
|
| 84 |
b = const_bfs_test.emptyQueue(); |
|
| 85 |
i = const_bfs_test.queueSize(); |
|
| 86 |
|
|
| 87 |
bfs_test.start(); |
|
| 88 |
bfs_test.start(t); |
|
| 89 |
bfs_test.start(nm); |
|
| 90 |
|
|
| 91 |
l = const_bfs_test.dist(t); |
|
| 92 |
e = const_bfs_test.predArc(t); |
|
| 93 |
s = const_bfs_test.predNode(t); |
|
| 94 |
b = const_bfs_test.reached(t); |
|
| 95 |
d = const_bfs_test.distMap(); |
|
| 96 |
p = const_bfs_test.predMap(); |
|
| 97 |
pp = const_bfs_test.path(t); |
|
| 83 | 98 |
} |
| 84 | 99 |
{
|
| 85 | 100 |
BType |
| 86 | 101 |
::SetPredMap<concepts::ReadWriteMap<Node,Arc> > |
| 87 | 102 |
::SetDistMap<concepts::ReadWriteMap<Node,int> > |
| 88 | 103 |
::SetReachedMap<concepts::ReadWriteMap<Node,bool> > |
| 104 |
::SetStandardProcessedMap |
|
| 89 | 105 |
::SetProcessedMap<concepts::WriteMap<Node,bool> > |
| 90 |
::SetStandardProcessedMap |
|
| 91 | 106 |
::Create bfs_test(G); |
| 107 |
|
|
| 108 |
concepts::ReadWriteMap<Node,Arc> pred_map; |
|
| 109 |
concepts::ReadWriteMap<Node,int> dist_map; |
|
| 110 |
concepts::ReadWriteMap<Node,bool> reached_map; |
|
| 111 |
concepts::WriteMap<Node,bool> processed_map; |
|
| 112 |
|
|
| 113 |
bfs_test |
|
| 114 |
.predMap(pred_map) |
|
| 115 |
.distMap(dist_map) |
|
| 116 |
.reachedMap(reached_map) |
|
| 117 |
.processedMap(processed_map); |
|
| 92 | 118 |
|
| 93 | 119 |
bfs_test.run(s); |
| 94 | 120 |
bfs_test.run(s,t); |
| 95 | 121 |
bfs_test.run(); |
| 122 |
|
|
| 123 |
bfs_test.init(); |
|
| 124 |
bfs_test.addSource(s); |
|
| 125 |
n = bfs_test.processNextNode(); |
|
| 126 |
n = bfs_test.processNextNode(t, b); |
|
| 127 |
n = bfs_test.processNextNode(nm, n); |
|
| 128 |
n = bfs_test.nextNode(); |
|
| 129 |
b = bfs_test.emptyQueue(); |
|
| 130 |
i = bfs_test.queueSize(); |
|
| 131 |
|
|
| 132 |
bfs_test.start(); |
|
| 133 |
bfs_test.start(t); |
|
| 134 |
bfs_test.start(nm); |
|
| 96 | 135 |
|
| 97 | 136 |
l = bfs_test.dist(t); |
| 98 | 137 |
e = bfs_test.predArc(t); |
| 99 | 138 |
s = bfs_test.predNode(t); |
| 100 | 139 |
b = bfs_test.reached(t); |
| 101 | 140 |
pp = bfs_test.path(t); |
| 102 | 141 |
} |
| 103 | 142 |
} |
| 104 | 143 |
|
| 105 | 144 |
void checkBfsFunctionCompile() |
| 106 | 145 |
{
|
| 107 | 146 |
typedef int VType; |
| 108 | 147 |
typedef concepts::Digraph Digraph; |
| 109 | 148 |
typedef Digraph::Arc Arc; |
| 110 | 149 |
typedef Digraph::Node Node; |
| 111 | 150 |
|
| 112 | 151 |
Digraph g; |
| 113 | 152 |
bool b; |
| 114 | 153 |
bfs(g).run(Node()); |
| 115 | 154 |
b=bfs(g).run(Node(),Node()); |
| 116 | 155 |
bfs(g).run(); |
| 117 | 156 |
bfs(g) |
| 118 | 157 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 119 | 158 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 120 | 159 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
| 121 | 160 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 122 | 161 |
.run(Node()); |
| 123 | 162 |
b=bfs(g) |
| 124 | 163 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 125 | 164 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 126 | 165 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
| 127 | 166 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 128 | 167 |
.path(concepts::Path<Digraph>()) |
| 129 | 168 |
.dist(VType()) |
| 130 | 169 |
.run(Node(),Node()); |
| 131 | 170 |
bfs(g) |
| 132 | 171 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 133 | 172 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 134 | 173 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
| 135 | 174 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 136 | 175 |
.run(); |
| 137 | 176 |
} |
| 138 | 177 |
|
| 139 | 178 |
template <class Digraph> |
| 140 | 179 |
void checkBfs() {
|
| 141 | 180 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 142 | 181 |
|
| 143 | 182 |
Digraph G; |
| ... | ... |
@@ -26,117 +26,124 @@ |
| 26 | 26 |
#include <lemon/concepts/maps.h> |
| 27 | 27 |
|
| 28 | 28 |
using namespace lemon; |
| 29 | 29 |
|
| 30 | 30 |
char test_lgf[] = |
| 31 | 31 |
"@nodes\n" |
| 32 | 32 |
"label\n" |
| 33 | 33 |
"0\n" |
| 34 | 34 |
"1\n" |
| 35 | 35 |
"2\n" |
| 36 | 36 |
"3\n" |
| 37 | 37 |
"4\n" |
| 38 | 38 |
"5\n" |
| 39 | 39 |
"@arcs\n" |
| 40 | 40 |
" lcap ucap\n" |
| 41 | 41 |
"0 1 2 10\n" |
| 42 | 42 |
"0 2 2 6\n" |
| 43 | 43 |
"1 3 4 7\n" |
| 44 | 44 |
"1 4 0 5\n" |
| 45 | 45 |
"2 4 1 3\n" |
| 46 | 46 |
"3 5 3 8\n" |
| 47 | 47 |
"4 5 3 7\n" |
| 48 | 48 |
"@attributes\n" |
| 49 | 49 |
"source 0\n" |
| 50 | 50 |
"sink 5\n"; |
| 51 | 51 |
|
| 52 | 52 |
void checkCirculationCompile() |
| 53 | 53 |
{
|
| 54 | 54 |
typedef int VType; |
| 55 | 55 |
typedef concepts::Digraph Digraph; |
| 56 | 56 |
|
| 57 | 57 |
typedef Digraph::Node Node; |
| 58 | 58 |
typedef Digraph::Arc Arc; |
| 59 | 59 |
typedef concepts::ReadMap<Arc,VType> CapMap; |
| 60 | 60 |
typedef concepts::ReadMap<Node,VType> DeltaMap; |
| 61 | 61 |
typedef concepts::ReadWriteMap<Arc,VType> FlowMap; |
| 62 | 62 |
typedef concepts::WriteMap<Node,bool> BarrierMap; |
| 63 | 63 |
|
| 64 | 64 |
typedef Elevator<Digraph, Digraph::Node> Elev; |
| 65 | 65 |
typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev; |
| 66 | 66 |
|
| 67 | 67 |
Digraph g; |
| 68 | 68 |
Node n; |
| 69 | 69 |
Arc a; |
| 70 | 70 |
CapMap lcap, ucap; |
| 71 | 71 |
DeltaMap delta; |
| 72 | 72 |
FlowMap flow; |
| 73 | 73 |
BarrierMap bar; |
| 74 |
VType v; |
|
| 75 |
bool b; |
|
| 74 | 76 |
|
| 75 |
Circulation<Digraph, CapMap, CapMap, DeltaMap> |
|
| 76 |
::SetFlowMap<FlowMap> |
|
| 77 |
::SetElevator<Elev> |
|
| 78 |
::SetStandardElevator<LinkedElev> |
|
| 79 |
::Create circ_test(g,lcap,ucap,delta); |
|
| 80 |
|
|
| 81 |
circ_test.lowerCapMap(lcap); |
|
| 82 |
circ_test.upperCapMap(ucap); |
|
| 83 |
circ_test.deltaMap(delta); |
|
| 84 |
flow = circ_test.flowMap(); |
|
| 85 |
|
|
| 77 |
typedef Circulation<Digraph, CapMap, CapMap, DeltaMap> |
|
| 78 |
::SetFlowMap<FlowMap> |
|
| 79 |
::SetElevator<Elev> |
|
| 80 |
::SetStandardElevator<LinkedElev> |
|
| 81 |
::Create CirculationType; |
|
| 82 |
CirculationType circ_test(g, lcap, ucap, delta); |
|
| 83 |
const CirculationType& const_circ_test = circ_test; |
|
| 84 |
|
|
| 85 |
circ_test |
|
| 86 |
.lowerCapMap(lcap) |
|
| 87 |
.upperCapMap(ucap) |
|
| 88 |
.deltaMap(delta) |
|
| 89 |
.flowMap(flow); |
|
| 86 | 90 |
|
| 87 | 91 |
circ_test.init(); |
| 88 | 92 |
circ_test.greedyInit(); |
| 89 | 93 |
circ_test.start(); |
| 90 | 94 |
circ_test.run(); |
| 91 | 95 |
|
| 92 |
circ_test.barrier(n); |
|
| 93 |
circ_test.barrierMap(bar); |
|
| 94 |
|
|
| 96 |
v = const_circ_test.flow(a); |
|
| 97 |
const FlowMap& fm = const_circ_test.flowMap(); |
|
| 98 |
b = const_circ_test.barrier(n); |
|
| 99 |
const_circ_test.barrierMap(bar); |
|
| 100 |
|
|
| 101 |
ignore_unused_variable_warning(fm); |
|
| 95 | 102 |
} |
| 96 | 103 |
|
| 97 | 104 |
template <class G, class LM, class UM, class DM> |
| 98 | 105 |
void checkCirculation(const G& g, const LM& lm, const UM& um, |
| 99 | 106 |
const DM& dm, bool find) |
| 100 | 107 |
{
|
| 101 | 108 |
Circulation<G, LM, UM, DM> circ(g, lm, um, dm); |
| 102 | 109 |
bool ret = circ.run(); |
| 103 | 110 |
if (find) {
|
| 104 | 111 |
check(ret, "A feasible solution should have been found."); |
| 105 | 112 |
check(circ.checkFlow(), "The found flow is corrupt."); |
| 106 | 113 |
check(!circ.checkBarrier(), "A barrier should not have been found."); |
| 107 | 114 |
} else {
|
| 108 | 115 |
check(!ret, "A feasible solution should not have been found."); |
| 109 | 116 |
check(circ.checkBarrier(), "The found barrier is corrupt."); |
| 110 | 117 |
} |
| 111 | 118 |
} |
| 112 | 119 |
|
| 113 | 120 |
int main (int, char*[]) |
| 114 | 121 |
{
|
| 115 | 122 |
typedef ListDigraph Digraph; |
| 116 | 123 |
DIGRAPH_TYPEDEFS(Digraph); |
| 117 | 124 |
|
| 118 | 125 |
Digraph g; |
| 119 | 126 |
IntArcMap lo(g), up(g); |
| 120 | 127 |
IntNodeMap delta(g, 0); |
| 121 | 128 |
Node s, t; |
| 122 | 129 |
|
| 123 | 130 |
std::istringstream input(test_lgf); |
| 124 | 131 |
DigraphReader<Digraph>(g,input). |
| 125 | 132 |
arcMap("lcap", lo).
|
| 126 | 133 |
arcMap("ucap", up).
|
| 127 | 134 |
node("source",s).
|
| 128 | 135 |
node("sink",t).
|
| 129 | 136 |
run(); |
| 130 | 137 |
|
| 131 | 138 |
delta[s] = 7; delta[t] = -7; |
| 132 | 139 |
checkCirculation(g, lo, up, delta, true); |
| 133 | 140 |
|
| 134 | 141 |
delta[s] = 13; delta[t] = -13; |
| 135 | 142 |
checkCirculation(g, lo, up, delta, true); |
| 136 | 143 |
|
| 137 | 144 |
delta[s] = 6; delta[t] = -6; |
| 138 | 145 |
checkCirculation(g, lo, up, delta, false); |
| 139 | 146 |
|
| 140 | 147 |
delta[s] = 14; delta[t] = -14; |
| 141 | 148 |
checkCirculation(g, lo, up, delta, false); |
| 142 | 149 |
| ... | ... |
@@ -17,129 +17,164 @@ |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/dfs.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "graph_test.h" |
| 27 | 27 |
#include "test_tools.h" |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
|
| 31 | 31 |
char test_lgf[] = |
| 32 | 32 |
"@nodes\n" |
| 33 | 33 |
"label\n" |
| 34 | 34 |
"0\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"5\n" |
| 40 | 40 |
"6\n" |
| 41 | 41 |
"@arcs\n" |
| 42 | 42 |
" label\n" |
| 43 | 43 |
"0 1 0\n" |
| 44 | 44 |
"1 2 1\n" |
| 45 | 45 |
"2 3 2\n" |
| 46 | 46 |
"1 4 3\n" |
| 47 | 47 |
"4 2 4\n" |
| 48 | 48 |
"4 5 5\n" |
| 49 | 49 |
"5 0 6\n" |
| 50 | 50 |
"6 3 7\n" |
| 51 | 51 |
"@attributes\n" |
| 52 | 52 |
"source 0\n" |
| 53 | 53 |
"target 5\n"; |
| 54 | 54 |
|
| 55 | 55 |
void checkDfsCompile() |
| 56 | 56 |
{
|
| 57 | 57 |
typedef concepts::Digraph Digraph; |
| 58 | 58 |
typedef Dfs<Digraph> DType; |
| 59 | 59 |
typedef Digraph::Node Node; |
| 60 | 60 |
typedef Digraph::Arc Arc; |
| 61 | 61 |
|
| 62 | 62 |
Digraph G; |
| 63 | 63 |
Node s, t; |
| 64 | 64 |
Arc e; |
| 65 |
int l; |
|
| 65 |
int l, i; |
|
| 66 | 66 |
bool b; |
| 67 | 67 |
DType::DistMap d(G); |
| 68 | 68 |
DType::PredMap p(G); |
| 69 | 69 |
Path<Digraph> pp; |
| 70 |
concepts::ReadMap<Arc,bool> am; |
|
| 70 | 71 |
|
| 71 | 72 |
{
|
| 72 | 73 |
DType dfs_test(G); |
| 74 |
const DType& const_dfs_test = dfs_test; |
|
| 73 | 75 |
|
| 74 | 76 |
dfs_test.run(s); |
| 75 | 77 |
dfs_test.run(s,t); |
| 76 | 78 |
dfs_test.run(); |
| 77 | 79 |
|
| 78 |
l = dfs_test.dist(t); |
|
| 79 |
e = dfs_test.predArc(t); |
|
| 80 |
s = dfs_test.predNode(t); |
|
| 81 |
b = dfs_test.reached(t); |
|
| 82 |
d = dfs_test.distMap(); |
|
| 83 |
p = dfs_test.predMap(); |
|
| 84 |
|
|
| 80 |
dfs_test.init(); |
|
| 81 |
dfs_test.addSource(s); |
|
| 82 |
e = dfs_test.processNextArc(); |
|
| 83 |
e = const_dfs_test.nextArc(); |
|
| 84 |
b = const_dfs_test.emptyQueue(); |
|
| 85 |
i = const_dfs_test.queueSize(); |
|
| 86 |
|
|
| 87 |
dfs_test.start(); |
|
| 88 |
dfs_test.start(t); |
|
| 89 |
dfs_test.start(am); |
|
| 90 |
|
|
| 91 |
l = const_dfs_test.dist(t); |
|
| 92 |
e = const_dfs_test.predArc(t); |
|
| 93 |
s = const_dfs_test.predNode(t); |
|
| 94 |
b = const_dfs_test.reached(t); |
|
| 95 |
d = const_dfs_test.distMap(); |
|
| 96 |
p = const_dfs_test.predMap(); |
|
| 97 |
pp = const_dfs_test.path(t); |
|
| 85 | 98 |
} |
| 86 | 99 |
{
|
| 87 | 100 |
DType |
| 88 | 101 |
::SetPredMap<concepts::ReadWriteMap<Node,Arc> > |
| 89 | 102 |
::SetDistMap<concepts::ReadWriteMap<Node,int> > |
| 90 | 103 |
::SetReachedMap<concepts::ReadWriteMap<Node,bool> > |
| 104 |
::SetStandardProcessedMap |
|
| 91 | 105 |
::SetProcessedMap<concepts::WriteMap<Node,bool> > |
| 92 |
::SetStandardProcessedMap |
|
| 93 | 106 |
::Create dfs_test(G); |
| 94 | 107 |
|
| 108 |
concepts::ReadWriteMap<Node,Arc> pred_map; |
|
| 109 |
concepts::ReadWriteMap<Node,int> dist_map; |
|
| 110 |
concepts::ReadWriteMap<Node,bool> reached_map; |
|
| 111 |
concepts::WriteMap<Node,bool> processed_map; |
|
| 112 |
|
|
| 113 |
dfs_test |
|
| 114 |
.predMap(pred_map) |
|
| 115 |
.distMap(dist_map) |
|
| 116 |
.reachedMap(reached_map) |
|
| 117 |
.processedMap(processed_map); |
|
| 118 |
|
|
| 95 | 119 |
dfs_test.run(s); |
| 96 | 120 |
dfs_test.run(s,t); |
| 97 | 121 |
dfs_test.run(); |
| 122 |
dfs_test.init(); |
|
| 123 |
|
|
| 124 |
dfs_test.addSource(s); |
|
| 125 |
e = dfs_test.processNextArc(); |
|
| 126 |
e = dfs_test.nextArc(); |
|
| 127 |
b = dfs_test.emptyQueue(); |
|
| 128 |
i = dfs_test.queueSize(); |
|
| 129 |
|
|
| 130 |
dfs_test.start(); |
|
| 131 |
dfs_test.start(t); |
|
| 132 |
dfs_test.start(am); |
|
| 98 | 133 |
|
| 99 | 134 |
l = dfs_test.dist(t); |
| 100 | 135 |
e = dfs_test.predArc(t); |
| 101 | 136 |
s = dfs_test.predNode(t); |
| 102 | 137 |
b = dfs_test.reached(t); |
| 103 | 138 |
pp = dfs_test.path(t); |
| 104 | 139 |
} |
| 105 | 140 |
} |
| 106 | 141 |
|
| 107 | 142 |
void checkDfsFunctionCompile() |
| 108 | 143 |
{
|
| 109 | 144 |
typedef int VType; |
| 110 | 145 |
typedef concepts::Digraph Digraph; |
| 111 | 146 |
typedef Digraph::Arc Arc; |
| 112 | 147 |
typedef Digraph::Node Node; |
| 113 | 148 |
|
| 114 | 149 |
Digraph g; |
| 115 | 150 |
bool b; |
| 116 | 151 |
dfs(g).run(Node()); |
| 117 | 152 |
b=dfs(g).run(Node(),Node()); |
| 118 | 153 |
dfs(g).run(); |
| 119 | 154 |
dfs(g) |
| 120 | 155 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 121 | 156 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 122 | 157 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
| 123 | 158 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 124 | 159 |
.run(Node()); |
| 125 | 160 |
b=dfs(g) |
| 126 | 161 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 127 | 162 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 128 | 163 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
| 129 | 164 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 130 | 165 |
.path(concepts::Path<Digraph>()) |
| 131 | 166 |
.dist(VType()) |
| 132 | 167 |
.run(Node(),Node()); |
| 133 | 168 |
dfs(g) |
| 134 | 169 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 135 | 170 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 136 | 171 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
| 137 | 172 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 138 | 173 |
.run(); |
| 139 | 174 |
} |
| 140 | 175 |
|
| 141 | 176 |
template <class Digraph> |
| 142 | 177 |
void checkDfs() {
|
| 143 | 178 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 144 | 179 |
|
| 145 | 180 |
Digraph G; |
| ... | ... |
@@ -15,138 +15,184 @@ |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/dijkstra.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
#include <lemon/bin_heap.h> |
| 26 | 26 |
|
| 27 | 27 |
#include "graph_test.h" |
| 28 | 28 |
#include "test_tools.h" |
| 29 | 29 |
|
| 30 | 30 |
using namespace lemon; |
| 31 | 31 |
|
| 32 | 32 |
char test_lgf[] = |
| 33 | 33 |
"@nodes\n" |
| 34 | 34 |
"label\n" |
| 35 | 35 |
"0\n" |
| 36 | 36 |
"1\n" |
| 37 | 37 |
"2\n" |
| 38 | 38 |
"3\n" |
| 39 | 39 |
"4\n" |
| 40 | 40 |
"@arcs\n" |
| 41 | 41 |
" label length\n" |
| 42 | 42 |
"0 1 0 1\n" |
| 43 | 43 |
"1 2 1 1\n" |
| 44 | 44 |
"2 3 2 1\n" |
| 45 | 45 |
"0 3 4 5\n" |
| 46 | 46 |
"0 3 5 10\n" |
| 47 | 47 |
"0 3 6 7\n" |
| 48 | 48 |
"4 2 7 1\n" |
| 49 | 49 |
"@attributes\n" |
| 50 | 50 |
"source 0\n" |
| 51 | 51 |
"target 3\n"; |
| 52 | 52 |
|
| 53 | 53 |
void checkDijkstraCompile() |
| 54 | 54 |
{
|
| 55 | 55 |
typedef int VType; |
| 56 | 56 |
typedef concepts::Digraph Digraph; |
| 57 | 57 |
typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap; |
| 58 | 58 |
typedef Dijkstra<Digraph, LengthMap> DType; |
| 59 | 59 |
typedef Digraph::Node Node; |
| 60 | 60 |
typedef Digraph::Arc Arc; |
| 61 | 61 |
|
| 62 | 62 |
Digraph G; |
| 63 |
Node s, t; |
|
| 63 |
Node s, t, n; |
|
| 64 | 64 |
Arc e; |
| 65 | 65 |
VType l; |
| 66 |
int i; |
|
| 66 | 67 |
bool b; |
| 67 | 68 |
DType::DistMap d(G); |
| 68 | 69 |
DType::PredMap p(G); |
| 69 | 70 |
LengthMap length; |
| 70 | 71 |
Path<Digraph> pp; |
| 72 |
concepts::ReadMap<Node,bool> nm; |
|
| 71 | 73 |
|
| 72 | 74 |
{
|
| 73 | 75 |
DType dijkstra_test(G,length); |
| 76 |
const DType& const_dijkstra_test = dijkstra_test; |
|
| 74 | 77 |
|
| 75 | 78 |
dijkstra_test.run(s); |
| 76 | 79 |
dijkstra_test.run(s,t); |
| 77 | 80 |
|
| 81 |
dijkstra_test.init(); |
|
| 82 |
dijkstra_test.addSource(s); |
|
| 83 |
dijkstra_test.addSource(s, 1); |
|
| 84 |
n = dijkstra_test.processNextNode(); |
|
| 85 |
n = const_dijkstra_test.nextNode(); |
|
| 86 |
b = const_dijkstra_test.emptyQueue(); |
|
| 87 |
i = const_dijkstra_test.queueSize(); |
|
| 88 |
|
|
| 89 |
dijkstra_test.start(); |
|
| 90 |
dijkstra_test.start(t); |
|
| 91 |
dijkstra_test.start(nm); |
|
| 92 |
|
|
| 93 |
l = const_dijkstra_test.dist(t); |
|
| 94 |
e = const_dijkstra_test.predArc(t); |
|
| 95 |
s = const_dijkstra_test.predNode(t); |
|
| 96 |
b = const_dijkstra_test.reached(t); |
|
| 97 |
b = const_dijkstra_test.processed(t); |
|
| 98 |
d = const_dijkstra_test.distMap(); |
|
| 99 |
p = const_dijkstra_test.predMap(); |
|
| 100 |
pp = const_dijkstra_test.path(t); |
|
| 101 |
l = const_dijkstra_test.currentDist(t); |
|
| 102 |
} |
|
| 103 |
{
|
|
| 104 |
DType |
|
| 105 |
::SetPredMap<concepts::ReadWriteMap<Node,Arc> > |
|
| 106 |
::SetDistMap<concepts::ReadWriteMap<Node,VType> > |
|
| 107 |
::SetStandardProcessedMap |
|
| 108 |
::SetProcessedMap<concepts::WriteMap<Node,bool> > |
|
| 109 |
::SetOperationTraits<DijkstraDefaultOperationTraits<VType> > |
|
| 110 |
::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > |
|
| 111 |
::SetStandardHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > |
|
| 112 |
::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> >, |
|
| 113 |
concepts::ReadWriteMap<Node,int> > |
|
| 114 |
::Create dijkstra_test(G,length); |
|
| 115 |
|
|
| 116 |
LengthMap length_map; |
|
| 117 |
concepts::ReadWriteMap<Node,Arc> pred_map; |
|
| 118 |
concepts::ReadWriteMap<Node,VType> dist_map; |
|
| 119 |
concepts::WriteMap<Node,bool> processed_map; |
|
| 120 |
concepts::ReadWriteMap<Node,int> heap_cross_ref; |
|
| 121 |
BinHeap<VType, concepts::ReadWriteMap<Node,int> > heap(heap_cross_ref); |
|
| 122 |
|
|
| 123 |
dijkstra_test |
|
| 124 |
.lengthMap(length_map) |
|
| 125 |
.predMap(pred_map) |
|
| 126 |
.distMap(dist_map) |
|
| 127 |
.processedMap(processed_map) |
|
| 128 |
.heap(heap, heap_cross_ref); |
|
| 129 |
|
|
| 130 |
dijkstra_test.run(s); |
|
| 131 |
dijkstra_test.run(s,t); |
|
| 132 |
|
|
| 133 |
dijkstra_test.addSource(s); |
|
| 134 |
dijkstra_test.addSource(s, 1); |
|
| 135 |
n = dijkstra_test.processNextNode(); |
|
| 136 |
n = dijkstra_test.nextNode(); |
|
| 137 |
b = dijkstra_test.emptyQueue(); |
|
| 138 |
i = dijkstra_test.queueSize(); |
|
| 139 |
|
|
| 140 |
dijkstra_test.start(); |
|
| 141 |
dijkstra_test.start(t); |
|
| 142 |
dijkstra_test.start(nm); |
|
| 143 |
|
|
| 78 | 144 |
l = dijkstra_test.dist(t); |
| 79 | 145 |
e = dijkstra_test.predArc(t); |
| 80 | 146 |
s = dijkstra_test.predNode(t); |
| 81 | 147 |
b = dijkstra_test.reached(t); |
| 82 |
d = dijkstra_test.distMap(); |
|
| 83 |
p = dijkstra_test.predMap(); |
|
| 148 |
b = dijkstra_test.processed(t); |
|
| 84 | 149 |
pp = dijkstra_test.path(t); |
| 85 |
} |
|
| 86 |
{
|
|
| 87 |
DType |
|
| 88 |
::SetPredMap<concepts::ReadWriteMap<Node,Arc> > |
|
| 89 |
::SetDistMap<concepts::ReadWriteMap<Node,VType> > |
|
| 90 |
::SetProcessedMap<concepts::WriteMap<Node,bool> > |
|
| 91 |
::SetStandardProcessedMap |
|
| 92 |
::SetOperationTraits<DijkstraDefaultOperationTraits<VType> > |
|
| 93 |
::SetHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > |
|
| 94 |
::SetStandardHeap<BinHeap<VType, concepts::ReadWriteMap<Node,int> > > |
|
| 95 |
::Create dijkstra_test(G,length); |
|
| 96 |
|
|
| 97 |
dijkstra_test.run(s); |
|
| 98 |
dijkstra_test.run(s,t); |
|
| 99 |
|
|
| 100 |
l = dijkstra_test.dist(t); |
|
| 101 |
e = dijkstra_test.predArc(t); |
|
| 102 |
s = dijkstra_test.predNode(t); |
|
| 103 |
b = dijkstra_test.reached(t); |
|
| 104 |
pp = dijkstra_test.path(t); |
|
| 150 |
l = dijkstra_test.currentDist(t); |
|
| 105 | 151 |
} |
| 106 | 152 |
|
| 107 | 153 |
} |
| 108 | 154 |
|
| 109 | 155 |
void checkDijkstraFunctionCompile() |
| 110 | 156 |
{
|
| 111 | 157 |
typedef int VType; |
| 112 | 158 |
typedef concepts::Digraph Digraph; |
| 113 | 159 |
typedef Digraph::Arc Arc; |
| 114 | 160 |
typedef Digraph::Node Node; |
| 115 | 161 |
typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap; |
| 116 | 162 |
|
| 117 | 163 |
Digraph g; |
| 118 | 164 |
bool b; |
| 119 | 165 |
dijkstra(g,LengthMap()).run(Node()); |
| 120 | 166 |
b=dijkstra(g,LengthMap()).run(Node(),Node()); |
| 121 | 167 |
dijkstra(g,LengthMap()) |
| 122 | 168 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 123 | 169 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 124 | 170 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 125 | 171 |
.run(Node()); |
| 126 | 172 |
b=dijkstra(g,LengthMap()) |
| 127 | 173 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 128 | 174 |
.distMap(concepts::ReadWriteMap<Node,VType>()) |
| 129 | 175 |
.processedMap(concepts::WriteMap<Node,bool>()) |
| 130 | 176 |
.path(concepts::Path<Digraph>()) |
| 131 | 177 |
.dist(VType()) |
| 132 | 178 |
.run(Node(),Node()); |
| 133 | 179 |
} |
| 134 | 180 |
|
| 135 | 181 |
template <class Digraph> |
| 136 | 182 |
void checkDijkstra() {
|
| 137 | 183 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
| 138 | 184 |
typedef typename Digraph::template ArcMap<int> LengthMap; |
| 139 | 185 |
|
| 140 | 186 |
Digraph G; |
| 141 | 187 |
Node s, t; |
| 142 | 188 |
LengthMap length(G); |
| 143 | 189 |
|
| 144 | 190 |
std::istringstream input(test_lgf); |
| 145 | 191 |
digraphReader(G, input). |
| 146 | 192 |
arcMap("length", length).
|
| 147 | 193 |
node("source", s).
|
| 148 | 194 |
node("target", t).
|
| 149 | 195 |
run(); |
| 150 | 196 |
|
| 151 | 197 |
Dijkstra<Digraph, LengthMap> |
| 152 | 198 |
dijkstra_test(G, length); |
| 1 | 1 |
#include <iostream> |
| 2 | 2 |
|
| 3 | 3 |
#include "test_tools.h" |
| 4 | 4 |
#include <lemon/smart_graph.h> |
| 5 |
#include <lemon/concepts/graph.h> |
|
| 6 |
#include <lemon/concepts/maps.h> |
|
| 5 | 7 |
#include <lemon/lgf_reader.h> |
| 6 | 8 |
#include <lemon/gomory_hu.h> |
| 7 | 9 |
#include <cstdlib> |
| 8 | 10 |
|
| 9 | 11 |
using namespace std; |
| 10 | 12 |
using namespace lemon; |
| 11 | 13 |
|
| 12 | 14 |
typedef SmartGraph Graph; |
| 13 | 15 |
|
| 14 | 16 |
char test_lgf[] = |
| 15 | 17 |
"@nodes\n" |
| 16 | 18 |
"label\n" |
| 17 | 19 |
"0\n" |
| 18 | 20 |
"1\n" |
| 19 | 21 |
"2\n" |
| 20 | 22 |
"3\n" |
| 21 | 23 |
"4\n" |
| 22 | 24 |
"@arcs\n" |
| 23 | 25 |
" label capacity\n" |
| 24 | 26 |
"0 1 0 1\n" |
| 25 | 27 |
"1 2 1 1\n" |
| 26 | 28 |
"2 3 2 1\n" |
| 27 | 29 |
"0 3 4 5\n" |
| 28 | 30 |
"0 3 5 10\n" |
| 29 | 31 |
"0 3 6 7\n" |
| 30 | 32 |
"4 2 7 1\n" |
| 31 | 33 |
"@attributes\n" |
| 32 | 34 |
"source 0\n" |
| 33 | 35 |
"target 3\n"; |
| 34 | 36 |
|
| 37 |
void checkGomoryHuCompile() |
|
| 38 |
{
|
|
| 39 |
typedef int Value; |
|
| 40 |
typedef concepts::Graph Graph; |
|
| 41 |
|
|
| 42 |
typedef Graph::Node Node; |
|
| 43 |
typedef Graph::Edge Edge; |
|
| 44 |
typedef concepts::ReadMap<Edge, Value> CapMap; |
|
| 45 |
typedef concepts::ReadWriteMap<Node, bool> CutMap; |
|
| 46 |
|
|
| 47 |
Graph g; |
|
| 48 |
Node n; |
|
| 49 |
CapMap cap; |
|
| 50 |
CutMap cut; |
|
| 51 |
Value v; |
|
| 52 |
int d; |
|
| 53 |
|
|
| 54 |
GomoryHu<Graph, CapMap> gh_test(g, cap); |
|
| 55 |
const GomoryHu<Graph, CapMap>& |
|
| 56 |
const_gh_test = gh_test; |
|
| 57 |
|
|
| 58 |
gh_test.run(); |
|
| 59 |
|
|
| 60 |
n = const_gh_test.predNode(n); |
|
| 61 |
v = const_gh_test.predValue(n); |
|
| 62 |
d = const_gh_test.rootDist(n); |
|
| 63 |
v = const_gh_test.minCutValue(n, n); |
|
| 64 |
v = const_gh_test.minCutMap(n, n, cut); |
|
| 65 |
} |
|
| 66 |
|
|
| 35 | 67 |
GRAPH_TYPEDEFS(Graph); |
| 36 | 68 |
typedef Graph::EdgeMap<int> IntEdgeMap; |
| 37 | 69 |
typedef Graph::NodeMap<bool> BoolNodeMap; |
| 38 | 70 |
|
| 39 | 71 |
int cutValue(const Graph& graph, const BoolNodeMap& cut, |
| 40 | 72 |
const IntEdgeMap& capacity) {
|
| 41 | 73 |
|
| 42 | 74 |
int sum = 0; |
| 43 | 75 |
for (EdgeIt e(graph); e != INVALID; ++e) {
|
| 44 | 76 |
Node s = graph.u(e); |
| 45 | 77 |
Node t = graph.v(e); |
| 46 | 78 |
|
| 47 | 79 |
if (cut[s] != cut[t]) {
|
| 48 | 80 |
sum += capacity[e]; |
| 49 | 81 |
} |
| 50 | 82 |
} |
| 51 | 83 |
return sum; |
| 52 | 84 |
} |
| 53 | 85 |
|
| 54 | 86 |
|
| 55 | 87 |
int main() {
|
| 56 | 88 |
Graph graph; |
| 57 | 89 |
IntEdgeMap capacity(graph); |
| 58 | 90 |
|
| 59 | 91 |
std::istringstream input(test_lgf); |
| 60 | 92 |
GraphReader<Graph>(graph, input). |
| 61 | 93 |
edgeMap("capacity", capacity).run();
|
| 62 | 94 |
|
| 63 | 95 |
GomoryHu<Graph> ght(graph, capacity); |
| 64 | 96 |
ght.run(); |
| 65 | 97 |
|
| 66 | 98 |
for (NodeIt u(graph); u != INVALID; ++u) {
|
| 67 | 99 |
for (NodeIt v(graph); v != u; ++v) {
|
| 68 | 100 |
Preflow<Graph, IntEdgeMap> pf(graph, capacity, u, v); |
| 69 | 101 |
pf.runMinCut(); |
| 70 | 102 |
BoolNodeMap cm(graph); |
| 71 | 103 |
ght.minCutMap(u, v, cm); |
| 72 | 104 |
check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1"); |
| 73 |
check(cm[u] != cm[v], "Wrong cut 3"); |
|
| 74 |
check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 2"); |
|
| 105 |
check(cm[u] != cm[v], "Wrong cut 2"); |
|
| 106 |
check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3"); |
|
| 75 | 107 |
|
| 76 | 108 |
int sum=0; |
| 77 | 109 |
for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a) |
| 78 | 110 |
sum+=capacity[a]; |
| 79 | 111 |
check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt"); |
| 80 | 112 |
|
| 81 | 113 |
sum=0; |
| 82 | 114 |
for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n) |
| 83 | 115 |
sum++; |
| 84 | 116 |
for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,false);n!=INVALID;++n) |
| 85 | 117 |
sum++; |
| 86 | 118 |
check(sum == countNodes(graph), "Problem with MinCutNodeIt"); |
| 87 |
|
|
| 88 | 119 |
} |
| 89 | 120 |
} |
| 90 | 121 |
|
| 91 | 122 |
return 0; |
| 92 | 123 |
} |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <sstream> |
| 20 | 20 |
|
| 21 | 21 |
#include <lemon/smart_graph.h> |
| 22 |
#include <lemon/adaptors.h> |
|
| 23 |
#include <lemon/concepts/digraph.h> |
|
| 24 |
#include <lemon/concepts/maps.h> |
|
| 25 |
#include <lemon/lgf_reader.h> |
|
| 22 | 26 |
#include <lemon/hao_orlin.h> |
| 23 | 27 |
|
| 24 |
#include <lemon/lgf_reader.h> |
|
| 25 | 28 |
#include "test_tools.h" |
| 26 | 29 |
|
| 27 | 30 |
using namespace lemon; |
| 28 | 31 |
using namespace std; |
| 29 | 32 |
|
| 30 | 33 |
const std::string lgf = |
| 31 | 34 |
"@nodes\n" |
| 32 | 35 |
"label\n" |
| 33 | 36 |
"0\n" |
| 34 | 37 |
"1\n" |
| 35 | 38 |
"2\n" |
| 36 | 39 |
"3\n" |
| 37 | 40 |
"4\n" |
| 38 | 41 |
"5\n" |
| 39 | 42 |
"@edges\n" |
| 40 |
" label capacity\n" |
|
| 41 |
"0 1 0 2\n" |
|
| 42 |
"1 2 1 2\n" |
|
| 43 |
"2 0 2 2\n" |
|
| 44 |
"3 4 3 2\n" |
|
| 45 |
"4 5 4 2\n" |
|
| 46 |
"5 3 5 2\n" |
|
| 47 |
"2 3 6 3\n"; |
|
| 43 |
" cap1 cap2 cap3\n" |
|
| 44 |
"0 1 1 1 1 \n" |
|
| 45 |
"0 2 2 2 4 \n" |
|
| 46 |
"1 2 4 4 4 \n" |
|
| 47 |
"3 4 1 1 1 \n" |
|
| 48 |
"3 5 2 2 4 \n" |
|
| 49 |
"4 5 4 4 4 \n" |
|
| 50 |
"5 4 4 4 4 \n" |
|
| 51 |
"2 3 1 6 6 \n" |
|
| 52 |
"4 0 1 6 6 \n"; |
|
| 53 |
|
|
| 54 |
void checkHaoOrlinCompile() |
|
| 55 |
{
|
|
| 56 |
typedef int Value; |
|
| 57 |
typedef concepts::Digraph Digraph; |
|
| 58 |
|
|
| 59 |
typedef Digraph::Node Node; |
|
| 60 |
typedef Digraph::Arc Arc; |
|
| 61 |
typedef concepts::ReadMap<Arc, Value> CapMap; |
|
| 62 |
typedef concepts::WriteMap<Node, bool> CutMap; |
|
| 63 |
|
|
| 64 |
Digraph g; |
|
| 65 |
Node n; |
|
| 66 |
CapMap cap; |
|
| 67 |
CutMap cut; |
|
| 68 |
Value v; |
|
| 69 |
|
|
| 70 |
HaoOrlin<Digraph, CapMap> ho_test(g, cap); |
|
| 71 |
const HaoOrlin<Digraph, CapMap>& |
|
| 72 |
const_ho_test = ho_test; |
|
| 73 |
|
|
| 74 |
ho_test.init(); |
|
| 75 |
ho_test.init(n); |
|
| 76 |
ho_test.calculateOut(); |
|
| 77 |
ho_test.calculateIn(); |
|
| 78 |
ho_test.run(); |
|
| 79 |
ho_test.run(n); |
|
| 80 |
|
|
| 81 |
v = const_ho_test.minCutValue(); |
|
| 82 |
v = const_ho_test.minCutMap(cut); |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
template <typename Graph, typename CapMap, typename CutMap> |
|
| 86 |
typename CapMap::Value |
|
| 87 |
cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut) |
|
| 88 |
{
|
|
| 89 |
typename CapMap::Value sum = 0; |
|
| 90 |
for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
|
|
| 91 |
if (cut[graph.source(a)] && !cut[graph.target(a)]) |
|
| 92 |
sum += cap[a]; |
|
| 93 |
} |
|
| 94 |
return sum; |
|
| 95 |
} |
|
| 48 | 96 |
|
| 49 | 97 |
int main() {
|
| 50 |
SmartGraph graph; |
|
| 51 |
SmartGraph::EdgeMap<int> capacity(graph); |
|
| 98 |
SmartDigraph graph; |
|
| 99 |
SmartDigraph::ArcMap<int> cap1(graph), cap2(graph), cap3(graph); |
|
| 100 |
SmartDigraph::NodeMap<bool> cut(graph); |
|
| 52 | 101 |
|
| 53 |
istringstream lgfs(lgf); |
|
| 54 |
graphReader(graph, lgfs). |
|
| 55 |
|
|
| 102 |
istringstream input(lgf); |
|
| 103 |
digraphReader(graph, input) |
|
| 104 |
.arcMap("cap1", cap1)
|
|
| 105 |
.arcMap("cap2", cap2)
|
|
| 106 |
.arcMap("cap3", cap3)
|
|
| 107 |
.run(); |
|
| 56 | 108 |
|
| 57 |
HaoOrlin<SmartGraph, SmartGraph::EdgeMap<int> > ho(graph, capacity); |
|
| 58 |
ho.run(); |
|
| 109 |
{
|
|
| 110 |
HaoOrlin<SmartDigraph> ho(graph, cap1); |
|
| 111 |
ho.run(); |
|
| 112 |
ho.minCutMap(cut); |
|
| 113 |
|
|
| 114 |
check(ho.minCutValue() == 1, "Wrong cut value"); |
|
| 115 |
check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value"); |
|
| 116 |
} |
|
| 117 |
{
|
|
| 118 |
HaoOrlin<SmartDigraph> ho(graph, cap2); |
|
| 119 |
ho.run(); |
|
| 120 |
ho.minCutMap(cut); |
|
| 59 | 121 |
|
| 60 |
check(ho.minCutValue() == |
|
| 122 |
check(ho.minCutValue() == 1, "Wrong cut value"); |
|
| 123 |
check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value"); |
|
| 124 |
} |
|
| 125 |
{
|
|
| 126 |
HaoOrlin<SmartDigraph> ho(graph, cap3); |
|
| 127 |
ho.run(); |
|
| 128 |
ho.minCutMap(cut); |
|
| 129 |
|
|
| 130 |
check(ho.minCutValue() == 1, "Wrong cut value"); |
|
| 131 |
check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value"); |
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
typedef Undirector<SmartDigraph> UGraph; |
|
| 135 |
UGraph ugraph(graph); |
|
| 136 |
|
|
| 137 |
{
|
|
| 138 |
HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1); |
|
| 139 |
ho.run(); |
|
| 140 |
ho.minCutMap(cut); |
|
| 141 |
|
|
| 142 |
check(ho.minCutValue() == 2, "Wrong cut value"); |
|
| 143 |
check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value"); |
|
| 144 |
} |
|
| 145 |
{
|
|
| 146 |
HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2); |
|
| 147 |
ho.run(); |
|
| 148 |
ho.minCutMap(cut); |
|
| 149 |
|
|
| 150 |
check(ho.minCutValue() == 5, "Wrong cut value"); |
|
| 151 |
check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value"); |
|
| 152 |
} |
|
| 153 |
{
|
|
| 154 |
HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3); |
|
| 155 |
ho.run(); |
|
| 156 |
ho.minCutMap(cut); |
|
| 157 |
|
|
| 158 |
check(ho.minCutValue() == 5, "Wrong cut value"); |
|
| 159 |
check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value"); |
|
| 160 |
} |
|
| 61 | 161 |
|
| 62 | 162 |
return 0; |
| 63 | 163 |
} |
| ... | ... |
@@ -54,94 +54,94 @@ |
| 54 | 54 |
std::vector<concepts::Digraph::Arc> ws; |
| 55 | 55 |
std::vector<concepts::Graph::Edge> uws; |
| 56 | 56 |
|
| 57 | 57 |
kruskal(g, r, ws.begin()); |
| 58 | 58 |
kruskal(ug, ur, uws.begin()); |
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 | 61 |
int main() {
|
| 62 | 62 |
|
| 63 | 63 |
typedef ListGraph::Node Node; |
| 64 | 64 |
typedef ListGraph::Edge Edge; |
| 65 | 65 |
typedef ListGraph::NodeIt NodeIt; |
| 66 | 66 |
typedef ListGraph::ArcIt ArcIt; |
| 67 | 67 |
|
| 68 | 68 |
ListGraph G; |
| 69 | 69 |
|
| 70 | 70 |
Node s=G.addNode(); |
| 71 | 71 |
Node v1=G.addNode(); |
| 72 | 72 |
Node v2=G.addNode(); |
| 73 | 73 |
Node v3=G.addNode(); |
| 74 | 74 |
Node v4=G.addNode(); |
| 75 | 75 |
Node t=G.addNode(); |
| 76 | 76 |
|
| 77 | 77 |
Edge e1 = G.addEdge(s, v1); |
| 78 | 78 |
Edge e2 = G.addEdge(s, v2); |
| 79 | 79 |
Edge e3 = G.addEdge(v1, v2); |
| 80 | 80 |
Edge e4 = G.addEdge(v2, v1); |
| 81 | 81 |
Edge e5 = G.addEdge(v1, v3); |
| 82 | 82 |
Edge e6 = G.addEdge(v3, v2); |
| 83 | 83 |
Edge e7 = G.addEdge(v2, v4); |
| 84 | 84 |
Edge e8 = G.addEdge(v4, v3); |
| 85 | 85 |
Edge e9 = G.addEdge(v3, t); |
| 86 | 86 |
Edge e10 = G.addEdge(v4, t); |
| 87 | 87 |
|
| 88 | 88 |
typedef ListGraph::EdgeMap<int> ECostMap; |
| 89 | 89 |
typedef ListGraph::EdgeMap<bool> EBoolMap; |
| 90 | 90 |
|
| 91 | 91 |
ECostMap edge_cost_map(G, 2); |
| 92 | 92 |
EBoolMap tree_map(G); |
| 93 | 93 |
|
| 94 | 94 |
|
| 95 | 95 |
//Test with const map. |
| 96 | 96 |
check(kruskal(G, ConstMap<ListGraph::Edge,int>(2), tree_map)==10, |
| 97 | 97 |
"Total cost should be 10"); |
| 98 | 98 |
//Test with an edge map (filled with uniform costs). |
| 99 | 99 |
check(kruskal(G, edge_cost_map, tree_map)==10, |
| 100 | 100 |
"Total cost should be 10"); |
| 101 | 101 |
|
| 102 |
edge_cost_map.set(e1, -10); |
|
| 103 |
edge_cost_map.set(e2, -9); |
|
| 104 |
edge_cost_map.set(e3, -8); |
|
| 105 |
edge_cost_map.set(e4, -7); |
|
| 106 |
edge_cost_map.set(e5, -6); |
|
| 107 |
edge_cost_map.set(e6, -5); |
|
| 108 |
edge_cost_map.set(e7, -4); |
|
| 109 |
edge_cost_map.set(e8, -3); |
|
| 110 |
edge_cost_map.set(e9, -2); |
|
| 111 |
edge_cost_map.set(e10, -1); |
|
| 102 |
edge_cost_map[e1] = -10; |
|
| 103 |
edge_cost_map[e2] = -9; |
|
| 104 |
edge_cost_map[e3] = -8; |
|
| 105 |
edge_cost_map[e4] = -7; |
|
| 106 |
edge_cost_map[e5] = -6; |
|
| 107 |
edge_cost_map[e6] = -5; |
|
| 108 |
edge_cost_map[e7] = -4; |
|
| 109 |
edge_cost_map[e8] = -3; |
|
| 110 |
edge_cost_map[e9] = -2; |
|
| 111 |
edge_cost_map[e10] = -1; |
|
| 112 | 112 |
|
| 113 | 113 |
vector<Edge> tree_edge_vec(5); |
| 114 | 114 |
|
| 115 | 115 |
//Test with a edge map and inserter. |
| 116 | 116 |
check(kruskal(G, edge_cost_map, |
| 117 | 117 |
tree_edge_vec.begin()) |
| 118 | 118 |
==-31, |
| 119 | 119 |
"Total cost should be -31."); |
| 120 | 120 |
|
| 121 | 121 |
tree_edge_vec.clear(); |
| 122 | 122 |
|
| 123 | 123 |
check(kruskal(G, edge_cost_map, |
| 124 | 124 |
back_inserter(tree_edge_vec)) |
| 125 | 125 |
==-31, |
| 126 | 126 |
"Total cost should be -31."); |
| 127 | 127 |
|
| 128 | 128 |
// tree_edge_vec.clear(); |
| 129 | 129 |
|
| 130 | 130 |
// //The above test could also be coded like this: |
| 131 | 131 |
// check(kruskal(G, |
| 132 | 132 |
// makeKruskalMapInput(G, edge_cost_map), |
| 133 | 133 |
// makeKruskalSequenceOutput(back_inserter(tree_edge_vec))) |
| 134 | 134 |
// ==-31, |
| 135 | 135 |
// "Total cost should be -31."); |
| 136 | 136 |
|
| 137 | 137 |
check(tree_edge_vec.size()==5,"The tree should have 5 edges."); |
| 138 | 138 |
|
| 139 | 139 |
check(tree_edge_vec[0]==e1 && |
| 140 | 140 |
tree_edge_vec[1]==e2 && |
| 141 | 141 |
tree_edge_vec[2]==e5 && |
| 142 | 142 |
tree_edge_vec[3]==e7 && |
| 143 | 143 |
tree_edge_vec[4]==e9, |
| 144 | 144 |
"Wrong tree."); |
| 145 | 145 |
|
| 146 | 146 |
return 0; |
| 147 | 147 |
} |
| ... | ... |
@@ -350,77 +350,72 @@ |
| 350 | 350 |
solveAndCheck(lp, LpSolver::OPTIMAL, expected_opt); |
| 351 | 351 |
|
| 352 | 352 |
//Erase one constraint and return to maximization |
| 353 | 353 |
lp.erase(upright); |
| 354 | 354 |
lp.sense(lp.MAX); |
| 355 | 355 |
expected_opt=LpSolver::INF; |
| 356 | 356 |
solveAndCheck(lp, LpSolver::UNBOUNDED, expected_opt); |
| 357 | 357 |
|
| 358 | 358 |
//Infeasibilty |
| 359 | 359 |
lp.addRow(x1+x2 <=-2); |
| 360 | 360 |
solveAndCheck(lp, LpSolver::INFEASIBLE, expected_opt); |
| 361 | 361 |
|
| 362 | 362 |
} |
| 363 | 363 |
|
| 364 | 364 |
template<class LP> |
| 365 | 365 |
void cloneTest() |
| 366 | 366 |
{
|
| 367 | 367 |
//Test for clone/new |
| 368 | 368 |
|
| 369 | 369 |
LP* lp = new LP(); |
| 370 | 370 |
LP* lpnew = lp->newSolver(); |
| 371 | 371 |
LP* lpclone = lp->cloneSolver(); |
| 372 | 372 |
delete lp; |
| 373 | 373 |
delete lpnew; |
| 374 | 374 |
delete lpclone; |
| 375 | 375 |
} |
| 376 | 376 |
|
| 377 | 377 |
int main() |
| 378 | 378 |
{
|
| 379 | 379 |
LpSkeleton lp_skel; |
| 380 | 380 |
lpTest(lp_skel); |
| 381 | 381 |
|
| 382 | 382 |
#ifdef HAVE_GLPK |
| 383 | 383 |
{
|
| 384 | 384 |
GlpkLp lp_glpk1,lp_glpk2; |
| 385 | 385 |
lpTest(lp_glpk1); |
| 386 | 386 |
aTest(lp_glpk2); |
| 387 | 387 |
cloneTest<GlpkLp>(); |
| 388 | 388 |
} |
| 389 | 389 |
#endif |
| 390 | 390 |
|
| 391 | 391 |
#ifdef HAVE_CPLEX |
| 392 | 392 |
try {
|
| 393 | 393 |
CplexLp lp_cplex1,lp_cplex2; |
| 394 | 394 |
lpTest(lp_cplex1); |
| 395 | 395 |
aTest(lp_cplex2); |
| 396 | 396 |
cloneTest<CplexLp>(); |
| 397 | 397 |
} catch (CplexEnv::LicenseError& error) {
|
| 398 |
#ifdef LEMON_FORCE_CPLEX_CHECK |
|
| 399 | 398 |
check(false, error.what()); |
| 400 |
#else |
|
| 401 |
std::cerr << error.what() << std::endl; |
|
| 402 |
std::cerr << "Cplex license check failed, lp check skipped" << std::endl; |
|
| 403 |
#endif |
|
| 404 | 399 |
} |
| 405 | 400 |
#endif |
| 406 | 401 |
|
| 407 | 402 |
#ifdef HAVE_SOPLEX |
| 408 | 403 |
{
|
| 409 | 404 |
SoplexLp lp_soplex1,lp_soplex2; |
| 410 | 405 |
lpTest(lp_soplex1); |
| 411 | 406 |
aTest(lp_soplex2); |
| 412 | 407 |
cloneTest<SoplexLp>(); |
| 413 | 408 |
} |
| 414 | 409 |
#endif |
| 415 | 410 |
|
| 416 | 411 |
#ifdef HAVE_CLP |
| 417 | 412 |
{
|
| 418 | 413 |
ClpLp lp_clp1,lp_clp2; |
| 419 | 414 |
lpTest(lp_clp1); |
| 420 | 415 |
aTest(lp_clp2); |
| 421 | 416 |
cloneTest<ClpLp>(); |
| 422 | 417 |
} |
| 423 | 418 |
#endif |
| 424 | 419 |
|
| 425 | 420 |
return 0; |
| 426 | 421 |
} |
| ... | ... |
@@ -98,68 +98,63 @@ |
| 98 | 98 |
mip.colType(x2,MipSolver::INTEGER); |
| 99 | 99 |
expected_opt=1.0/2.0; |
| 100 | 100 |
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt); |
| 101 | 101 |
|
| 102 | 102 |
|
| 103 | 103 |
//Restrict both to integer |
| 104 | 104 |
mip.colType(x1,MipSolver::INTEGER); |
| 105 | 105 |
expected_opt=0; |
| 106 | 106 |
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt); |
| 107 | 107 |
|
| 108 | 108 |
//Erase a variable |
| 109 | 109 |
mip.erase(x2); |
| 110 | 110 |
mip.rowUpperBound(y2, 8); |
| 111 | 111 |
expected_opt=1; |
| 112 | 112 |
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt); |
| 113 | 113 |
|
| 114 | 114 |
} |
| 115 | 115 |
|
| 116 | 116 |
|
| 117 | 117 |
template<class MIP> |
| 118 | 118 |
void cloneTest() |
| 119 | 119 |
{
|
| 120 | 120 |
|
| 121 | 121 |
MIP* mip = new MIP(); |
| 122 | 122 |
MIP* mipnew = mip->newSolver(); |
| 123 | 123 |
MIP* mipclone = mip->cloneSolver(); |
| 124 | 124 |
delete mip; |
| 125 | 125 |
delete mipnew; |
| 126 | 126 |
delete mipclone; |
| 127 | 127 |
} |
| 128 | 128 |
|
| 129 | 129 |
int main() |
| 130 | 130 |
{
|
| 131 | 131 |
|
| 132 | 132 |
#ifdef HAVE_GLPK |
| 133 | 133 |
{
|
| 134 | 134 |
GlpkMip mip1; |
| 135 | 135 |
aTest(mip1); |
| 136 | 136 |
cloneTest<GlpkMip>(); |
| 137 | 137 |
} |
| 138 | 138 |
#endif |
| 139 | 139 |
|
| 140 | 140 |
#ifdef HAVE_CPLEX |
| 141 | 141 |
try {
|
| 142 | 142 |
CplexMip mip2; |
| 143 | 143 |
aTest(mip2); |
| 144 | 144 |
cloneTest<CplexMip>(); |
| 145 | 145 |
} catch (CplexEnv::LicenseError& error) {
|
| 146 |
#ifdef LEMON_FORCE_CPLEX_CHECK |
|
| 147 | 146 |
check(false, error.what()); |
| 148 |
#else |
|
| 149 |
std::cerr << error.what() << std::endl; |
|
| 150 |
std::cerr << "Cplex license check failed, lp check skipped" << std::endl; |
|
| 151 |
#endif |
|
| 152 | 147 |
} |
| 153 | 148 |
#endif |
| 154 | 149 |
|
| 155 | 150 |
#ifdef HAVE_CBC |
| 156 | 151 |
{
|
| 157 | 152 |
CbcMip mip1; |
| 158 | 153 |
aTest(mip1); |
| 159 | 154 |
cloneTest<CbcMip>(); |
| 160 | 155 |
} |
| 161 | 156 |
#endif |
| 162 | 157 |
|
| 163 | 158 |
return 0; |
| 164 | 159 |
|
| 165 | 160 |
} |
| ... | ... |
@@ -39,121 +39,127 @@ |
| 39 | 39 |
"5\n" |
| 40 | 40 |
"6\n" |
| 41 | 41 |
"7\n" |
| 42 | 42 |
"8\n" |
| 43 | 43 |
"9\n" |
| 44 | 44 |
"@arcs\n" |
| 45 | 45 |
" label capacity\n" |
| 46 | 46 |
"0 1 0 20\n" |
| 47 | 47 |
"0 2 1 0\n" |
| 48 | 48 |
"1 1 2 3\n" |
| 49 | 49 |
"1 2 3 8\n" |
| 50 | 50 |
"1 3 4 8\n" |
| 51 | 51 |
"2 5 5 5\n" |
| 52 | 52 |
"3 2 6 5\n" |
| 53 | 53 |
"3 5 7 5\n" |
| 54 | 54 |
"3 6 8 5\n" |
| 55 | 55 |
"4 3 9 3\n" |
| 56 | 56 |
"5 7 10 3\n" |
| 57 | 57 |
"5 6 11 10\n" |
| 58 | 58 |
"5 8 12 10\n" |
| 59 | 59 |
"6 8 13 8\n" |
| 60 | 60 |
"8 9 14 20\n" |
| 61 | 61 |
"8 1 15 5\n" |
| 62 | 62 |
"9 5 16 5\n" |
| 63 | 63 |
"@attributes\n" |
| 64 | 64 |
"source 1\n" |
| 65 | 65 |
"target 8\n"; |
| 66 | 66 |
|
| 67 | 67 |
void checkPreflowCompile() |
| 68 | 68 |
{
|
| 69 | 69 |
typedef int VType; |
| 70 | 70 |
typedef concepts::Digraph Digraph; |
| 71 | 71 |
|
| 72 | 72 |
typedef Digraph::Node Node; |
| 73 | 73 |
typedef Digraph::Arc Arc; |
| 74 | 74 |
typedef concepts::ReadMap<Arc,VType> CapMap; |
| 75 | 75 |
typedef concepts::ReadWriteMap<Arc,VType> FlowMap; |
| 76 | 76 |
typedef concepts::WriteMap<Node,bool> CutMap; |
| 77 | 77 |
|
| 78 | 78 |
typedef Elevator<Digraph, Digraph::Node> Elev; |
| 79 | 79 |
typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev; |
| 80 | 80 |
|
| 81 | 81 |
Digraph g; |
| 82 | 82 |
Node n; |
| 83 | 83 |
Arc e; |
| 84 | 84 |
CapMap cap; |
| 85 | 85 |
FlowMap flow; |
| 86 | 86 |
CutMap cut; |
| 87 |
VType v; |
|
| 88 |
bool b; |
|
| 87 | 89 |
|
| 88 |
Preflow<Digraph, CapMap> |
|
| 89 |
::SetFlowMap<FlowMap> |
|
| 90 |
::SetElevator<Elev> |
|
| 91 |
::SetStandardElevator<LinkedElev> |
|
| 92 |
|
|
| 90 |
typedef Preflow<Digraph, CapMap> |
|
| 91 |
::SetFlowMap<FlowMap> |
|
| 92 |
::SetElevator<Elev> |
|
| 93 |
::SetStandardElevator<LinkedElev> |
|
| 94 |
::Create PreflowType; |
|
| 95 |
PreflowType preflow_test(g, cap, n, n); |
|
| 96 |
const PreflowType& const_preflow_test = preflow_test; |
|
| 93 | 97 |
|
| 94 |
preflow_test.capacityMap(cap); |
|
| 95 |
flow = preflow_test.flowMap(); |
|
| 96 |
preflow_test.flowMap(flow); |
|
| 97 |
preflow_test.source(n); |
|
| 98 |
preflow_test |
|
| 98 |
preflow_test |
|
| 99 |
.capacityMap(cap) |
|
| 100 |
.flowMap(flow) |
|
| 101 |
.source(n) |
|
| 102 |
.target(n); |
|
| 99 | 103 |
|
| 100 | 104 |
preflow_test.init(); |
| 101 | 105 |
preflow_test.init(cap); |
| 102 | 106 |
preflow_test.startFirstPhase(); |
| 103 | 107 |
preflow_test.startSecondPhase(); |
| 104 | 108 |
preflow_test.run(); |
| 105 | 109 |
preflow_test.runMinCut(); |
| 106 | 110 |
|
| 107 |
preflow_test.flowValue(); |
|
| 108 |
preflow_test.minCut(n); |
|
| 109 |
preflow_test.minCutMap(cut); |
|
| 110 |
preflow_test.flow(e); |
|
| 111 |
|
|
| 111 |
v = const_preflow_test.flowValue(); |
|
| 112 |
v = const_preflow_test.flow(e); |
|
| 113 |
const FlowMap& fm = const_preflow_test.flowMap(); |
|
| 114 |
b = const_preflow_test.minCut(n); |
|
| 115 |
const_preflow_test.minCutMap(cut); |
|
| 116 |
|
|
| 117 |
ignore_unused_variable_warning(fm); |
|
| 112 | 118 |
} |
| 113 | 119 |
|
| 114 | 120 |
int cutValue (const SmartDigraph& g, |
| 115 | 121 |
const SmartDigraph::NodeMap<bool>& cut, |
| 116 | 122 |
const SmartDigraph::ArcMap<int>& cap) {
|
| 117 | 123 |
|
| 118 | 124 |
int c=0; |
| 119 | 125 |
for(SmartDigraph::ArcIt e(g); e!=INVALID; ++e) {
|
| 120 | 126 |
if (cut[g.source(e)] && !cut[g.target(e)]) c+=cap[e]; |
| 121 | 127 |
} |
| 122 | 128 |
return c; |
| 123 | 129 |
} |
| 124 | 130 |
|
| 125 | 131 |
bool checkFlow(const SmartDigraph& g, |
| 126 | 132 |
const SmartDigraph::ArcMap<int>& flow, |
| 127 | 133 |
const SmartDigraph::ArcMap<int>& cap, |
| 128 | 134 |
SmartDigraph::Node s, SmartDigraph::Node t) {
|
| 129 | 135 |
|
| 130 | 136 |
for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) {
|
| 131 | 137 |
if (flow[e] < 0 || flow[e] > cap[e]) return false; |
| 132 | 138 |
} |
| 133 | 139 |
|
| 134 | 140 |
for (SmartDigraph::NodeIt n(g); n != INVALID; ++n) {
|
| 135 | 141 |
if (n == s || n == t) continue; |
| 136 | 142 |
int sum = 0; |
| 137 | 143 |
for (SmartDigraph::OutArcIt e(g, n); e != INVALID; ++e) {
|
| 138 | 144 |
sum += flow[e]; |
| 139 | 145 |
} |
| 140 | 146 |
for (SmartDigraph::InArcIt e(g, n); e != INVALID; ++e) {
|
| 141 | 147 |
sum -= flow[e]; |
| 142 | 148 |
} |
| 143 | 149 |
if (sum != 0) return false; |
| 144 | 150 |
} |
| 145 | 151 |
return true; |
| 146 | 152 |
} |
| 147 | 153 |
|
| 148 | 154 |
int main() {
|
| 149 | 155 |
|
| 150 | 156 |
typedef SmartDigraph Digraph; |
| 151 | 157 |
|
| 152 | 158 |
typedef Digraph::Node Node; |
| 153 | 159 |
typedef Digraph::NodeIt NodeIt; |
| 154 | 160 |
typedef Digraph::ArcIt ArcIt; |
| 155 | 161 |
typedef Digraph::ArcMap<int> CapMap; |
| 156 | 162 |
typedef Digraph::ArcMap<int> FlowMap; |
| 157 | 163 |
typedef Digraph::NodeMap<bool> CutMap; |
| 158 | 164 |
|
| 159 | 165 |
typedef Preflow<Digraph, CapMap> PType; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup tools |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief DIMACS problem solver. |
| 22 | 22 |
/// |
| 23 | 23 |
/// This program solves various problems given in DIMACS format. |
| 24 | 24 |
/// |
| 25 | 25 |
/// See |
| 26 |
/// \verbatim |
|
| 27 |
/// dimacs-solver --help |
|
| 28 |
/// \ |
|
| 26 |
/// \code |
|
| 27 |
/// dimacs-solver --help |
|
| 28 |
/// \endcode |
|
| 29 | 29 |
/// for more info on usage. |
| 30 |
/// |
|
| 31 | 30 |
|
| 32 | 31 |
#include <iostream> |
| 33 | 32 |
#include <fstream> |
| 34 | 33 |
#include <cstring> |
| 35 | 34 |
|
| 36 | 35 |
#include <lemon/smart_graph.h> |
| 37 | 36 |
#include <lemon/dimacs.h> |
| 38 | 37 |
#include <lemon/lgf_writer.h> |
| 39 | 38 |
#include <lemon/time_measure.h> |
| 40 | 39 |
|
| 41 | 40 |
#include <lemon/arg_parser.h> |
| 42 | 41 |
#include <lemon/error.h> |
| 43 | 42 |
|
| 44 | 43 |
#include <lemon/dijkstra.h> |
| 45 | 44 |
#include <lemon/preflow.h> |
| 46 | 45 |
#include <lemon/max_matching.h> |
| 47 | 46 |
|
| 48 | 47 |
using namespace lemon; |
| 49 | 48 |
typedef SmartDigraph Digraph; |
| 50 | 49 |
DIGRAPH_TYPEDEFS(Digraph); |
| 51 | 50 |
typedef SmartGraph Graph; |
| 52 | 51 |
|
| 53 | 52 |
template<class Value> |
| 54 | 53 |
void solve_sp(ArgParser &ap, std::istream &is, std::ostream &, |
| 55 | 54 |
DimacsDescriptor &desc) |
| 56 | 55 |
{
|
| 57 | 56 |
bool report = !ap.given("q");
|
| 58 | 57 |
Digraph g; |
| 59 | 58 |
Node s; |
| 60 | 59 |
Digraph::ArcMap<Value> len(g); |
| 61 | 60 |
Timer t; |
| 62 | 61 |
t.restart(); |
| 63 | 62 |
readDimacsSp(is, g, len, s, desc); |
| 64 | 63 |
if(report) std::cerr << "Read the file: " << t << '\n'; |
| 65 | 64 |
t.restart(); |
| 66 | 65 |
Dijkstra<Digraph, Digraph::ArcMap<Value> > dij(g,len); |
| 67 | 66 |
if(report) std::cerr << "Setup Dijkstra class: " << t << '\n'; |
| 68 | 67 |
t.restart(); |
| 69 | 68 |
dij.run(s); |
| 70 | 69 |
if(report) std::cerr << "Run Dijkstra: " << t << '\n'; |
| 71 | 70 |
} |
| 72 | 71 |
|
| 73 | 72 |
template<class Value> |
| 74 | 73 |
void solve_max(ArgParser &ap, std::istream &is, std::ostream &, |
| 75 | 74 |
Value infty, DimacsDescriptor &desc) |
| 76 | 75 |
{
|
| 77 | 76 |
bool report = !ap.given("q");
|
| 78 | 77 |
Digraph g; |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
///\ingroup tools |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief DIMACS to LGF converter. |
| 22 | 22 |
/// |
| 23 | 23 |
/// This program converts various DIMACS formats to the LEMON Digraph Format |
| 24 | 24 |
/// (LGF). |
| 25 | 25 |
/// |
| 26 | 26 |
/// See |
| 27 |
/// \verbatim |
|
| 28 |
/// dimacs-to-lgf --help |
|
| 29 |
/// \endverbatim |
|
| 30 |
/// for more info on usage. |
|
| 31 |
/// |
|
| 27 |
/// \code |
|
| 28 |
/// dimacs-to-lgf --help |
|
| 29 |
/// \endcode |
|
| 30 |
/// for more info on the usage. |
|
| 32 | 31 |
|
| 33 | 32 |
#include <iostream> |
| 34 | 33 |
#include <fstream> |
| 35 | 34 |
#include <cstring> |
| 36 | 35 |
|
| 37 | 36 |
#include <lemon/smart_graph.h> |
| 38 | 37 |
#include <lemon/dimacs.h> |
| 39 | 38 |
#include <lemon/lgf_writer.h> |
| 40 | 39 |
|
| 41 | 40 |
#include <lemon/arg_parser.h> |
| 42 | 41 |
#include <lemon/error.h> |
| 43 | 42 |
|
| 44 | 43 |
using namespace std; |
| 45 | 44 |
using namespace lemon; |
| 46 | 45 |
|
| 47 | 46 |
|
| 48 | 47 |
int main(int argc, const char *argv[]) {
|
| 49 | 48 |
typedef SmartDigraph Digraph; |
| 50 | 49 |
|
| 51 | 50 |
typedef Digraph::Arc Arc; |
| 52 | 51 |
typedef Digraph::Node Node; |
| 53 | 52 |
typedef Digraph::ArcIt ArcIt; |
| 54 | 53 |
typedef Digraph::NodeIt NodeIt; |
| 55 | 54 |
typedef Digraph::ArcMap<double> DoubleArcMap; |
| 56 | 55 |
typedef Digraph::NodeMap<double> DoubleNodeMap; |
| 57 | 56 |
|
| 58 | 57 |
std::string inputName; |
| 59 | 58 |
std::string outputName; |
| 60 | 59 |
|
| 61 | 60 |
ArgParser ap(argc, argv); |
| 62 | 61 |
ap.other("[INFILE [OUTFILE]]",
|
| 63 | 62 |
"If either the INFILE or OUTFILE file is missing the standard\n" |
| 64 | 63 |
" input/output will be used instead.") |
| 65 | 64 |
.run(); |
| 66 | 65 |
|
| 67 | 66 |
ifstream input; |
| 68 | 67 |
ofstream output; |
| 69 | 68 |
|
| 70 | 69 |
switch(ap.files().size()) |
| 71 | 70 |
{
|
| 72 | 71 |
case 2: |
| 73 | 72 |
output.open(ap.files()[1].c_str()); |
| 74 | 73 |
if (!output) {
|
| 75 | 74 |
throw IoError("Cannot open the file for writing", ap.files()[1]);
|
| 76 | 75 |
} |
| 77 | 76 |
case 1: |
| 78 | 77 |
input.open(ap.files()[0].c_str()); |
| 79 | 78 |
if (!input) {
|
| ... | ... |
@@ -44,82 +44,86 @@ |
| 44 | 44 |
-e "s/Edge/_Ar_c_label_/g"\ |
| 45 | 45 |
-e "s/edge/_ar_c_label_/g"\ |
| 46 | 46 |
-e "s/A[Nn]ode/_Re_d_label_/g"\ |
| 47 | 47 |
-e "s/B[Nn]ode/_Blu_e_label_/g"\ |
| 48 | 48 |
-e "s/A-[Nn]ode/_Re_d_label_/g"\ |
| 49 | 49 |
-e "s/B-[Nn]ode/_Blu_e_label_/g"\ |
| 50 | 50 |
-e "s/a[Nn]ode/_re_d_label_/g"\ |
| 51 | 51 |
-e "s/b[Nn]ode/_blu_e_label_/g"\ |
| 52 | 52 |
-e "s/\<UGRAPH_TYPEDEFS\([ \t]*([ \t]*\)typename[ \t]/TEMPLATE__GR_APH_TY_PEDE_FS_label_\1/g"\ |
| 53 | 53 |
-e "s/\<GRAPH_TYPEDEFS\([ \t]*([ \t]*\)typename[ \t]/TEMPLATE__DIGR_APH_TY_PEDE_FS_label_\1/g"\ |
| 54 | 54 |
-e "s/\<UGRAPH_TYPEDEFS\>/_GR_APH_TY_PEDE_FS_label_/g"\ |
| 55 | 55 |
-e "s/\<GRAPH_TYPEDEFS\>/_DIGR_APH_TY_PEDE_FS_label_/g"\ |
| 56 | 56 |
-e "s/_Digr_aph_label_/Digraph/g"\ |
| 57 | 57 |
-e "s/_digr_aph_label_/digraph/g"\ |
| 58 | 58 |
-e "s/_Gr_aph_label_/Graph/g"\ |
| 59 | 59 |
-e "s/_gr_aph_label_/graph/g"\ |
| 60 | 60 |
-e "s/_Ar_c_label_/Arc/g"\ |
| 61 | 61 |
-e "s/_ar_c_label_/arc/g"\ |
| 62 | 62 |
-e "s/_Ed_ge_label_/Edge/g"\ |
| 63 | 63 |
-e "s/_ed_ge_label_/edge/g"\ |
| 64 | 64 |
-e "s/_In_cEd_geIt_label_/IncEdgeIt/g"\ |
| 65 | 65 |
-e "s/_Re_d_label_/Red/g"\ |
| 66 | 66 |
-e "s/_Blu_e_label_/Blue/g"\ |
| 67 | 67 |
-e "s/_re_d_label_/red/g"\ |
| 68 | 68 |
-e "s/_blu_e_label_/blue/g"\ |
| 69 | 69 |
-e "s/_GR_APH_TY_PEDE_FS_label_/GRAPH_TYPEDEFS/g"\ |
| 70 | 70 |
-e "s/_DIGR_APH_TY_PEDE_FS_label_/DIGRAPH_TYPEDEFS/g"\ |
| 71 | 71 |
-e "s/DigraphToEps/GraphToEps/g"\ |
| 72 | 72 |
-e "s/digraphToEps/graphToEps/g"\ |
| 73 | 73 |
-e "s/\<DefPredMap\>/SetPredMap/g"\ |
| 74 | 74 |
-e "s/\<DefDistMap\>/SetDistMap/g"\ |
| 75 | 75 |
-e "s/\<DefReachedMap\>/SetReachedMap/g"\ |
| 76 | 76 |
-e "s/\<DefProcessedMap\>/SetProcessedMap/g"\ |
| 77 | 77 |
-e "s/\<DefHeap\>/SetHeap/g"\ |
| 78 | 78 |
-e "s/\<DefStandardHeap\>/SetStandradHeap/g"\ |
| 79 | 79 |
-e "s/\<DefOperationTraits\>/SetOperationTraits/g"\ |
| 80 | 80 |
-e "s/\<DefProcessedMapToBeDefaultMap\>/SetStandardProcessedMap/g"\ |
| 81 | 81 |
-e "s/\<copyGraph\>/graphCopy/g"\ |
| 82 | 82 |
-e "s/\<copyDigraph\>/digraphCopy/g"\ |
| 83 | 83 |
-e "s/\<HyperCubeDigraph\>/HypercubeGraph/g"\ |
| 84 | 84 |
-e "s/\<IntegerMap\>/RangeMap/g"\ |
| 85 | 85 |
-e "s/\<integerMap\>/rangeMap/g"\ |
| 86 | 86 |
-e "s/\<\([sS]\)tdMap\>/\1parseMap/g"\ |
| 87 | 87 |
-e "s/\<\([Ff]\)unctorMap\>/\1unctorToMap/g"\ |
| 88 | 88 |
-e "s/\<\([Mm]\)apFunctor\>/\1apToFunctor/g"\ |
| 89 | 89 |
-e "s/\<\([Ff]\)orkWriteMap\>/\1orkMap/g"\ |
| 90 | 90 |
-e "s/\<StoreBoolMap\>/LoggerBoolMap/g"\ |
| 91 | 91 |
-e "s/\<storeBoolMap\>/loggerBoolMap/g"\ |
| 92 |
-e "s/\<InvertableMap\>/CrossRefMap/g"\ |
|
| 93 |
-e "s/\<invertableMap\>/crossRefMap/g"\ |
|
| 94 |
-e "s/\<DescriptorMap\>/RangeIdMap/g"\ |
|
| 95 |
-e "s/\<descriptorMap\>/rangeIdMap/g"\ |
|
| 92 | 96 |
-e "s/\<BoundingBox\>/Box/g"\ |
| 93 | 97 |
-e "s/\<readNauty\>/readNautyGraph/g"\ |
| 94 | 98 |
-e "s/\<RevDigraphAdaptor\>/ReverseDigraph/g"\ |
| 95 | 99 |
-e "s/\<revDigraphAdaptor\>/reverseDigraph/g"\ |
| 96 | 100 |
-e "s/\<SubDigraphAdaptor\>/SubDigraph/g"\ |
| 97 | 101 |
-e "s/\<subDigraphAdaptor\>/subDigraph/g"\ |
| 98 | 102 |
-e "s/\<SubGraphAdaptor\>/SubGraph/g"\ |
| 99 | 103 |
-e "s/\<subGraphAdaptor\>/subGraph/g"\ |
| 100 | 104 |
-e "s/\<NodeSubDigraphAdaptor\>/FilterNodes/g"\ |
| 101 | 105 |
-e "s/\<nodeSubDigraphAdaptor\>/filterNodes/g"\ |
| 102 | 106 |
-e "s/\<ArcSubDigraphAdaptor\>/FilterArcs/g"\ |
| 103 | 107 |
-e "s/\<arcSubDigraphAdaptor\>/filterArcs/g"\ |
| 104 | 108 |
-e "s/\<UndirDigraphAdaptor\>/Undirector/g"\ |
| 105 | 109 |
-e "s/\<undirDigraphAdaptor\>/undirector/g"\ |
| 106 | 110 |
-e "s/\<ResDigraphAdaptor\>/ResidualDigraph/g"\ |
| 107 | 111 |
-e "s/\<resDigraphAdaptor\>/residualDigraph/g"\ |
| 108 | 112 |
-e "s/\<SplitDigraphAdaptor\>/SplitNodes/g"\ |
| 109 | 113 |
-e "s/\<splitDigraphAdaptor\>/splitNodes/g"\ |
| 110 | 114 |
-e "s/\<SubGraphAdaptor\>/SubGraph/g"\ |
| 111 | 115 |
-e "s/\<subGraphAdaptor\>/subGraph/g"\ |
| 112 | 116 |
-e "s/\<NodeSubGraphAdaptor\>/FilterNodes/g"\ |
| 113 | 117 |
-e "s/\<nodeSubGraphAdaptor\>/filterNodes/g"\ |
| 114 | 118 |
-e "s/\<ArcSubGraphAdaptor\>/FilterEdges/g"\ |
| 115 | 119 |
-e "s/\<arcSubGraphAdaptor\>/filterEdges/g"\ |
| 116 | 120 |
-e "s/\<DirGraphAdaptor\>/Orienter/g"\ |
| 117 | 121 |
-e "s/\<dirGraphAdaptor\>/orienter/g"\ |
| 118 | 122 |
-e "s/\<LpCplex\>/CplexLp/g"\ |
| 119 | 123 |
-e "s/\<MipCplex\>/CplexMip/g"\ |
| 120 | 124 |
-e "s/\<LpGlpk\>/GlpkLp/g"\ |
| 121 | 125 |
-e "s/\<MipGlpk\>/GlpkMip/g"\ |
| 122 | 126 |
-e "s/\<LpSoplex\>/SoplexLp/g"\ |
| 123 | 127 |
<$i > $TMP |
| 124 | 128 |
mv $TMP $i |
| 125 | 129 |
done |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
/// \ingroup tools |
| 20 | 20 |
/// \file |
| 21 | 21 |
/// \brief Special plane digraph generator. |
| 22 | 22 |
/// |
| 23 | 23 |
/// Graph generator application for various types of plane graphs. |
| 24 | 24 |
/// |
| 25 | 25 |
/// See |
| 26 |
/// \verbatim |
|
| 27 |
/// lgf-gen --help |
|
| 28 |
/// \ |
|
| 26 |
/// \code |
|
| 27 |
/// lgf-gen --help |
|
| 28 |
/// \endcode |
|
| 29 | 29 |
/// for more info on the usage. |
| 30 |
/// |
|
| 31 |
|
|
| 32 | 30 |
|
| 33 | 31 |
#include <algorithm> |
| 34 | 32 |
#include <set> |
| 35 | 33 |
#include <ctime> |
| 36 | 34 |
#include <lemon/list_graph.h> |
| 37 | 35 |
#include <lemon/random.h> |
| 38 | 36 |
#include <lemon/dim2.h> |
| 39 | 37 |
#include <lemon/bfs.h> |
| 40 | 38 |
#include <lemon/counter.h> |
| 41 | 39 |
#include <lemon/suurballe.h> |
| 42 | 40 |
#include <lemon/graph_to_eps.h> |
| 43 | 41 |
#include <lemon/lgf_writer.h> |
| 44 | 42 |
#include <lemon/arg_parser.h> |
| 45 | 43 |
#include <lemon/euler.h> |
| 46 | 44 |
#include <lemon/math.h> |
| 47 | 45 |
#include <lemon/kruskal.h> |
| 48 | 46 |
#include <lemon/time_measure.h> |
| 49 | 47 |
|
| 50 | 48 |
using namespace lemon; |
| 51 | 49 |
|
| 52 | 50 |
typedef dim2::Point<double> Point; |
| 53 | 51 |
|
| 54 | 52 |
GRAPH_TYPEDEFS(ListGraph); |
| 55 | 53 |
|
| 56 | 54 |
bool progress=true; |
| 57 | 55 |
|
| 58 | 56 |
int N; |
| 59 | 57 |
// int girth; |
| 60 | 58 |
|
| 61 | 59 |
ListGraph g; |
| 62 | 60 |
|
| 63 | 61 |
std::vector<Node> nodes; |
| 64 | 62 |
ListGraph::NodeMap<Point> coords(g); |
| 65 | 63 |
|
| 66 | 64 |
|
| 67 | 65 |
double totalLen(){
|
| 68 | 66 |
double tlen=0; |
| 69 | 67 |
for(EdgeIt e(g);e!=INVALID;++e) |
| 70 | 68 |
tlen+=sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare()); |
| 71 | 69 |
return tlen; |
| 72 | 70 |
} |
| 73 | 71 |
|
| 74 | 72 |
int tsp_impr_num=0; |
| 75 | 73 |
|
| 76 | 74 |
const double EPSILON=1e-8; |
| 77 | 75 |
bool tsp_improve(Node u, Node v) |
| 78 | 76 |
{
|
| 79 | 77 |
double luv=std::sqrt((coords[v]-coords[u]).normSquare()); |
0 comments (0 inline)