/usr/share/polymake/demo/matching_polytopes.ipynb is in polymake-common 3.2r2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | {
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Matching Polytopes\n",
"\n",
"In this tutorial we will use `polymake` to construct and analyse matching polytopes.\n",
"\n",
"First we construct a graph, the complete graph on four nodes:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
">\n"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"$K4=new props::Graph(4);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for (my $i=0; $i<4; ++$i) {\n",
" for (my $j=$i+1; $j<4; ++$j) {\n",
" $K4->edge($i,$j);\n",
" }\n",
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"(See also the [Tutorial on Graphs](apps_graph) for more on the construction of graphs.)\n",
"\n",
"Next we like to have the node-edge-incidence matrix of our graph. Since the latest release of `polymake` does not yet support this, we have to write the function ourselves:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sub node_edge_incidences {\n",
" my $g=shift;\n",
" my $A=new Matrix<Int>($g->nodes, $g->edges);\n",
" my $k=0;\n",
" for (my $i=0; $i<$g->nodes-1; ++$i) {\n",
" foreach (@{$g->adjacent_nodes($i)}) {\n",
" if ($_>$i) {\n",
" $A->[$i]->[$k]=1;\n",
" $A->[$_]->[$k]=1;\n",
" ++$k;\n",
" }\n",
" }\n",
" }\n",
" return $A;\n",
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Now we can construct the node-edge-incidence matrix of our graph `K4`:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1 1 1 0 0 0\n",
"1 0 0 1 1 0\n",
"0 1 0 1 0 1\n",
"0 0 1 0 1 1\n",
"\n"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"$A=node_edge_incidences($K4);\n",
"print $A;"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"With this we can now construct the constraint matrix consisting of an upper part for the nonnegativity constraints x<sub>e</sub><html>≥</html>0 ...\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$I=new Matrix<Int>([[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0],[0,0,0,1,0,0],[0,0,0,0,1,0],[0,0,0,0,0,1]]);\n",
"$Block1=new Matrix<Int>(new Vector<Int>([0,0,0,0,0,0]) | $I);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"... and a lower part for the constraints <html>Σ</html><sub>e</sub> x<sub>e</sub><html>≤</html>1 for each vertex v<html>∈</html>V, where the sum is over all edges e containing v:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$Block2=new Matrix<Int>(new Vector<Int>([1,1,1,1]) | -$A);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"Now we can put both parts together and define the polytope:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$Ineqs=new Matrix<Rational>($Block1 / $Block2);\n",
"$P=new Polytope<Rational>(INEQUALITIES=>$Ineqs);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"The matching polytope of `K4` is the integer hull of `P`:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$P_I=new Polytope<Rational>(POINTS=>$P->LATTICE_POINTS);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"We can analyse some elementary properties of `P_I` ...\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1 0 0 0 0 0 0\n",
"1 0 0 0 0 0 1\n",
"1 0 0 0 0 1 0\n",
"1 0 0 0 1 0 0\n",
"1 0 0 1 0 0 0\n",
"1 0 0 1 1 0 0\n",
"1 0 1 0 0 0 0\n",
"1 0 1 0 0 1 0\n",
"1 1 0 0 0 0 0\n",
"1 1 0 0 0 0 1\n",
" \n"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P_I->POINTS;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 0 0 0 0 0 1\n",
"0 1 0 0 0 0 0\n",
"1 0 0 0 -1 -1 -1\n",
"1 -1 0 0 -1 -1 0\n",
"1 0 -1 0 -1 0 -1\n",
"1 -1 -1 0 -1 0 0\n",
"1 0 0 -1 0 -1 -1\n",
"1 -1 0 -1 0 -1 0\n",
"1 0 -1 -1 0 0 -1\n",
"1 -1 -1 -1 0 0 0\n",
"0 0 0 0 0 1 0\n",
"0 0 1 0 0 0 0\n",
"0 0 0 0 1 0 0\n",
"0 0 0 1 0 0 0\n",
" \n"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P_I->FACETS;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14\n",
"\n"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P_I->N_FACETS;"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"... and compare them with the according properties of the defining polytope `P`:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1 0 0 0 1 0 0\n",
"1 0 1 0 0 0 0\n",
"1 1/2 1/2 0 1/2 0 0\n",
"1 0 0 0 0 0 0\n",
"1 1 0 0 0 0 0\n",
"1 1/2 0 1/2 0 1/2 0\n",
"1 0 1/2 1/2 0 0 1/2\n",
"1 0 0 0 1/2 1/2 1/2\n",
"1 0 0 0 0 1 0\n",
"1 0 0 1 0 0 0\n",
"1 0 0 0 0 0 1\n",
"1 1 0 0 0 0 1\n",
"1 0 1 0 0 1 0\n",
"1 0 0 1 1 0 0\n",
" \n"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P->VERTICES;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1/72\n",
" \n"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P->VOLUME;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1/90\n",
"\n"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P_I->VOLUME;"
]
},
{
"attachments": {
"gale.png": {
"image/png": [
"Tm90IEZvdW5k"
]
}
},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Next we analyse the combinatorics of `P_I`:\n",
"![{{ :tutorial:ilp:gale.png?300|The Gale diagram of `facet0`}}](attachment:gale.png)\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6 6\n",
" \n"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P_I->AMBIENT_DIM, \" \", $P_I->DIM;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10 39 78 86 51 14\n",
" \n"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P_I->F_VECTOR;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8 8 6 6 6 6 6 6 6 6 8 8 8 8\n",
" \n"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $P_I->FACET_SIZES;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$facet0=facet($P_I,0);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6 5\n",
" \n"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $facet0->AMBIENT_DIM, \" \", $facet0->DIM;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0:0 1 2 3 4 5 6\n",
"1:1 2 4 6 7\n",
"2:2 4 5 6 7\n",
"3:1 3 4 6 7\n",
"4:3 4 5 6 7\n",
"5:0 2 3 4 5 7\n",
"6:0 1 2 3 4 7\n",
"7:0 1 3 5 6 7\n",
"8:0 1 2 5 6 7\n",
" \n"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print rows_labeled($facet0->VERTICES_IN_FACETS);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$facet0->GALE;"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"The Gale diagram of `facet0` is depicted on the right.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "polymake",
"language": "polymake",
"name": "polymake"
},
"language_info": {
"codemirror_mode": "perl",
"file_extension": ".pm",
"mimetype": "text/x-polymake",
"name": "polymake"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|