# HG changeset patch
# User Robert L. Miller <rlm@rlmiller.org>
# Date 1276903266 25200
# Node ID 0239cc2433639437bbd17c179724f92250b227e3
# Parent 6164f5b70f7415c9d7bd35b3cb49d7ce2fb159d7
#7289: multiway cut, part 2 (editing etc.)
diff -r 6164f5b70f74 -r 0239cc243363 sage/graphs/generic_graph.py
a
|
b
|
|
3361 | 3361 | represented by a list of edges. |
3362 | 3362 | |
3363 | 3363 | A multiway cut for a vertex set `S` in a graph or a digraph |
3364 | | `G` if a set `C` of edges such that any two vertices `u,v` |
3365 | | in `S` are disconnected when removing from `G` the edges from |
3366 | | `C`. |
| 3364 | `G` is a set `C` of edges such that any two vertices `u,v` |
| 3365 | in `S` are disconnected when removing the edges from `C` from `G`. |
3367 | 3366 | |
3368 | 3367 | Such a cut is said to be minimum when its cardinality |
3369 | 3368 | (or weight) is minimum. |
… |
… |
|
3397 | 3396 | to a minimum edge cut :: |
3398 | 3397 | |
3399 | 3398 | sage: g = graphs.PetersenGraph() |
3400 | | sage: g.edge_cut(0,3) == g.multiway_cut([0,3], value_only = True) # optional - requires GLPK, CBC or CPLEX |
| 3399 | sage: g.edge_cut(0,3) == g.multiway_cut([0,3], value_only = True) # optional - GLPK, CBC |
3401 | 3400 | True |
3402 | 3401 | |
3403 | 3402 | As Petersen's graph is `3`-regular, a minimum multiway cut |
… |
… |
|
3405 | 3404 | (which could correspond to the neighborhood of 2 |
3406 | 3405 | vertices):: |
3407 | 3406 | |
3408 | | sage: g.multiway_cut([0,3,9], value_only = True) == 2*3 # optional - requires GLPK, CBC or CPLEX |
| 3407 | sage: g.multiway_cut([0,3,9], value_only = True) == 2*3 # optional - GLPK, CBC |
3409 | 3408 | True |
3410 | 3409 | |
3411 | 3410 | In this case, though, the vertices are an independent set. |
3412 | 3411 | If we pick instead vertices `0,9,` and `7`, we can save `4` |
3413 | 3412 | edges in the multiway cut :: |
3414 | 3413 | |
3415 | | sage: g.multiway_cut([0,7,9], value_only = True) == 2*3 - 1 # optional - requires GLPK, CBC or CPLEX |
| 3414 | sage: g.multiway_cut([0,7,9], value_only = True) == 2*3 - 1 # optional - GLPK, CBC |
3416 | 3415 | True |
3417 | 3416 | |
3418 | 3417 | This example, though, does not work in the directed case anymore, |
3419 | 3418 | as it is not possible in Petersen's graph to mutualise edges :: |
3420 | 3419 | |
3421 | 3420 | sage: g = DiGraph(g) |
3422 | | sage: g.multiway_cut([0,7,9], value_only = True) == 3*3 # optional - requires GLPK, CBC or CPLEX |
| 3421 | sage: g.multiway_cut([0,7,9], value_only = True) == 3*3 # optional - GLPK, CBC |
3423 | 3422 | True |
3424 | 3423 | |
3425 | 3424 | Of course, a multiway cut between the whole vertex set |
3426 | 3425 | contains all the edges of the graph:: |
3427 | 3426 | |
3428 | | sage: C = g.multiway_cut(g.vertices()) # optional - requires GLPK, CBC or CPLEX |
3429 | | sage: set(C) == set(g.edges()) # optional - requires GLPK, CBC or CPLEX |
| 3427 | sage: C = g.multiway_cut(g.vertices()) # optional - GLPK, CBC |
| 3428 | sage: set(C) == set(g.edges()) # optional - GLPK, CBC |
3430 | 3429 | True |
3431 | 3430 | """ |
3432 | 3431 | from sage.numerical.mip import MixedIntegerLinearProgram |