Ticket #9312: trac_9312-optional.patch

File trac_9312-optional.patch, 47.0 KB (added by ncohen, 9 years ago)
  • sage/graphs/digraph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1278367001 -7200
    # Node ID d43977d32b09dca9b9e8f744e3464bf71d3e46db
    # Parent  ebb57e653f5047bee03c0c92a681ee99889ec2fd
    [mq]: remove_optional
    
    diff -r ebb57e653f50 -r d43977d32b09 sage/graphs/digraph.py
    a b  
    11641164            sage: dcycle=DiGraph(cycle)
    11651165            sage: cycle.size()
    11661166            5
    1167             sage: dcycle.feedback_edge_set(value_only=True)    # optional - GLPK, CBC
     1167            sage: dcycle.feedback_edge_set(value_only=True)
    11681168            5.0
    11691169       
    11701170        And in this situation, for any edge `uv` of the first graph, `uv` of `vu`
     
    11721172
    11731173           sage: g = graphs.RandomGNP(5,.3)
    11741174           sage: dg = DiGraph(g)
    1175            sage: feedback = dg.feedback_edge_set()             # optional - GLPK, CBC
     1175           sage: feedback = dg.feedback_edge_set()
    11761176           sage: (u,v,l) = g.edge_iterator().next()
    1177            sage: (u,v) in feedback or (v,u) in feedback        # optional - GLPK, CBC
     1177           sage: (u,v) in feedback or (v,u) in feedback
    11781178           True
    11791179        """
    11801180       
     
    12841284
    12851285            sage: cycle=graphs.CycleGraph(5)
    12861286            sage: dcycle=DiGraph(cycle)
    1287             sage: cycle.vertex_cover(value_only=True)         # optional - GLPK, CBC
     1287            sage: cycle.vertex_cover(value_only=True)
    12881288            3
    1289             sage: feedback = dcycle.feedback_vertex_set()     # optional - GLPK, CBC
    1290             sage: feedback.cardinality()                      # optional - GLPK, CBC
     1289            sage: feedback = dcycle.feedback_vertex_set()
     1290            sage: feedback.cardinality()
    12911291            3
    12921292            sage: (u,v,l) = cycle.edge_iterator().next()
    1293             sage: u in feedback or v in feedback              # optional - GLPK, CBC
     1293            sage: u in feedback or v in feedback
    12941294            True
    12951295           
    12961296        For a circuit, the minimum feedback arc set is clearly `1`::
    12971297
    12981298            sage: circuit = digraphs.Circuit(5)
    1299             sage: circuit.feedback_vertex_set(value_only=True) == 1    # optional - GLPK, CBC
     1299            sage: circuit.feedback_vertex_set(value_only=True) == 1
    13001300            True
    13011301        """
    13021302       
  • sage/graphs/generic_graph.py

    diff -r ebb57e653f50 -r d43977d32b09 sage/graphs/generic_graph.py
    a b  
    18571857            sage: g = graphs.ClawGraph()
    18581858            sage: g
    18591859            Claw graph: Graph on 4 vertices
    1860             sage: edge_coloring(g, value_only=True)  # optional - requires GLPK, CBC, or CPLEX
     1860            sage: edge_coloring(g, value_only=True)
    18611861            3
    18621862            sage: g.is_overfull()
    18631863            False
     
    19061906            sage: g.is_overfull()
    19071907            False
    19081908            sage: from sage.graphs.graph_coloring import edge_coloring
    1909             sage: max(g.degree()) + 1 ==  edge_coloring(g, value_only=True) # optional - requires GLPK CBC or CPLEX
     1909            sage: max(g.degree()) + 1 ==  edge_coloring(g, value_only=True)
    19101910            True
    19111911        """
    19121912        # # A possible optimized version. But the gain in speed is very little.
     
    21592159        Given a complete bipartite graph `K_{n,m}`, the maximum out-degree
    21602160        of an optimal orientation is `\left\lceil \frac {nm} {n+m}\right\rceil`::
    21612161
    2162             sage: g = graphs.CompleteBipartiteGraph(3,4)   # optional - GLPK, CBC
    2163             sage: o = g.minimum_outdegree_orientation()    # optional - GLPK, CBC
    2164             sage: max(o.out_degree()) == ceil((4*3)/(3+4)) # optional - GLPK, CBC
     2162            sage: g = graphs.CompleteBipartiteGraph(3,4)
     2163            sage: o = g.minimum_outdegree_orientation()
     2164            sage: max(o.out_degree()) == ceil((4*3)/(3+4))
    21652165            True
    21662166
    21672167        REFERENCES:
     
    32743274        of course, always a tree ::
    32753275
    32763276            sage: g = graphs.RandomGNP(30,.5)
    3277             sage: st = g.steiner_tree(g.vertices()[:5])              # optional - GLPK, CBC
    3278             sage: st.is_tree()                                       # optional - GLPK, CBC
     3277            sage: st = g.steiner_tree(g.vertices()[:5])
     3278            sage: st.is_tree()
    32793279            True
    32803280
    32813281        And all the 5 vertices are contained in this tree ::
    32823282
    3283             sage: all([v in st for v in g.vertices()[:5] ])          # optional - GLPK, CBC
     3283            sage: all([v in st for v in g.vertices()[:5] ])
    32843284            True
    32853285
    32863286        An exception is raised when the problem is impossible, i.e.
     
    34093409        The Petersen Graph does have a spanning tree (it is connected)::
    34103410
    34113411            sage: g = graphs.PetersenGraph()
    3412             sage: [T] = g.edge_disjoint_spanning_trees(1)       # optional - GLPK, CBC
    3413             sage: T.is_tree()                                   # optional - GLPK, CBC
     3412            sage: [T] = g.edge_disjoint_spanning_trees(1)
     3413            sage: T.is_tree()
    34143414            True
    34153415
    34163416        Though, it does not have 2 edge-disjoint trees (as it has less
    34173417        than `2(|V|-1)` edges)::
    34183418
    3419             sage: g.edge_disjoint_spanning_trees(2)              # optional - GLPK, CBC
     3419            sage: g.edge_disjoint_spanning_trees(2)
    34203420            Traceback (most recent call last):
    34213421            ...
    34223422            ValueError: This graph does not contain the required number of trees/arborescences !
     
    34253425        arborescences, regardless of the root we pick::
    34263426
    34273427            sage: g = digraphs.RandomDirectedGNP(30,.3)
    3428             sage: k = Integer(g.edge_connectivity())                            # optional - GLPK, CBC
    3429             sage: arborescences = g.edge_disjoint_spanning_trees(k)             # optional - GLPK, CBC
    3430             sage: all([a.is_directed_acyclic() for a in arborescences])         # optional - GLPK, CBC
    3431             True
    3432             sage: all([a.is_connected() for a in arborescences])                # optional - GLPK, CBC
     3428            sage: k = Integer(g.edge_connectivity())
     3429            sage: arborescences = g.edge_disjoint_spanning_trees(k)
     3430            sage: all([a.is_directed_acyclic() for a in arborescences])
     3431            True
     3432            sage: all([a.is_connected() for a in arborescences])
    34333433            True           
    34343434
    34353435        In the undirected case, we can only ensure half of it::
    34363436
    34373437            sage: g = graphs.RandomGNP(30,.3)
    3438             sage: k = floor(Integer(g.edge_connectivity())/2)                   # optional - GLPK, CBC
    3439             sage: trees = g.edge_disjoint_spanning_trees(k)                     # optional - GLPK, CBC
    3440             sage: all([t.is_tree() for t in trees])                             # optional - GLPK, CBC
     3438            sage: k = floor(Integer(g.edge_connectivity())/2)
     3439            sage: trees = g.edge_disjoint_spanning_trees(k)
     3440            sage: all([t.is_tree() for t in trees])
    34413441            True
    34423442
    34433443        REFERENCES:
     
    36143614        A basic application in the Pappus graph::
    36153615       
    36163616           sage: g = graphs.PappusGraph()
    3617            sage: g.edge_cut(1, 2, value_only=True) # optional - GLPK, CBC
     3617           sage: g.edge_cut(1, 2, value_only=True)
    36183618           3.0
    36193619
    36203620        If the graph is a path with randomly weighted edges::
     
    36263626        The edge cut between the two ends is the edge of minimum weight::
    36273627
    36283628           sage: minimum = min([l for u,v,l in g.edge_iterator()])
    3629            sage: abs(minimum - g.edge_cut(0, 14, use_edge_labels=True)) < 10**(-5) # optional - GLPK, CBC
     3629           sage: abs(minimum - g.edge_cut(0, 14, use_edge_labels=True)) < 10**(-5)
    36303630           True
    3631            sage: [value,[[u,v]]] = g.edge_cut(0, 14, use_edge_labels=True, value_only=False) # optional - GLPK, CBC
    3632            sage: g.edge_label(u, v) == minimum # optional - GLPK, CBC
     3631           sage: [value,[[u,v]]] = g.edge_cut(0, 14, use_edge_labels=True, value_only=False)
     3632           sage: g.edge_label(u, v) == minimum
    36333633           True
    36343634
    36353635        The two sides of the edge cut are obviously shorter paths::
    36363636
    3637            sage: value,edges,[set1,set2] = g.edge_cut(0, 14, use_edge_labels=True, vertices=True)  # optional - GLPK, CBC
    3638            sage: g.subgraph(set1).is_isomorphic(graphs.PathGraph(len(set1))) # optional - GLPK, CBC
     3637           sage: value,edges,[set1,set2] = g.edge_cut(0, 14, use_edge_labels=True, vertices=True)
     3638           sage: g.subgraph(set1).is_isomorphic(graphs.PathGraph(len(set1)))
    36393639           True
    3640            sage: g.subgraph(set2).is_isomorphic(graphs.PathGraph(len(set2))) # optional - GLPK, CBC
     3640           sage: g.subgraph(set2).is_isomorphic(graphs.PathGraph(len(set2)))
    36413641           True
    3642            sage: len(set1) + len(set2) == g.order() # optional - GLPK, CBC
     3642           sage: len(set1) + len(set2) == g.order()
    36433643           True
    36443644        """
    36453645        from sage.numerical.mip import MixedIntegerLinearProgram
     
    37473747        A basic application in the Pappus graph::
    37483748       
    37493749           sage: g = graphs.PappusGraph()
    3750            sage: g.vertex_cut(1, 16, value_only=True) # optional - GLPK, CBC
     3750           sage: g.vertex_cut(1, 16, value_only=True)
    37513751           3.0
    37523752
    37533753        In the bipartite complete graph `K_{2,8}`, a cut between the two
    37543754        vertices in the size `2` part consists of the other `8` vertices::
    37553755
    37563756           sage: g = graphs.CompleteBipartiteGraph(2, 8)
    3757            sage: [value, vertices] = g.vertex_cut(0, 1, value_only=False) # optional - GLPK, CBC
    3758            sage: print value # optional - GLPK, CBC
     3757           sage: [value, vertices] = g.vertex_cut(0, 1, value_only=False)
     3758           sage: print value
    37593759           8.0
    3760            sage: vertices == range(2,10) # optional - GLPK, CBC
     3760           sage: vertices == range(2,10)
    37613761           True
    37623762
    37633763        Clearly, in this case the two sides of the cut are singletons ::
    37643764
    3765            sage: [value, vertices, [set1, set2]] = g.vertex_cut(0,1, vertices=True) # optional - GLPK, CBC
    3766            sage: len(set1) == 1 # optional - GLPK, CBC
     3765           sage: [value, vertices, [set1, set2]] = g.vertex_cut(0,1, vertices=True)
     3766           sage: len(set1) == 1
    37673767           True
    3768            sage: len(set2) == 1 # optional - GLPK, CBC
     3768           sage: len(set2) == 1
    37693769           True
    37703770        """
    37713771        from sage.numerical.mip import MixedIntegerLinearProgram
     
    38713871        to a minimum edge cut ::
    38723872
    38733873            sage: g = graphs.PetersenGraph()
    3874             sage: g.edge_cut(0,3) == g.multiway_cut([0,3], value_only = True) # optional - GLPK, CBC
     3874            sage: g.edge_cut(0,3) == g.multiway_cut([0,3], value_only = True)
    38753875            True
    38763876
    38773877        As Petersen's graph is `3`-regular, a minimum multiway cut
     
    38793879        (which could correspond to the neighborhood of 2
    38803880        vertices)::
    38813881
    3882             sage: g.multiway_cut([0,3,9], value_only = True) == 2*3          # optional - GLPK, CBC
     3882            sage: g.multiway_cut([0,3,9], value_only = True) == 2*3
    38833883            True
    38843884
    38853885        In this case, though, the vertices are an independent set.
    38863886        If we pick instead vertices `0,9,` and `7`, we can save `4`
    38873887        edges in the multiway cut ::
    38883888
    3889             sage: g.multiway_cut([0,7,9], value_only = True) == 2*3 - 1      # optional - GLPK, CBC
     3889            sage: g.multiway_cut([0,7,9], value_only = True) == 2*3 - 1
    38903890            True
    38913891
    38923892        This example, though, does not work in the directed case anymore,
    38933893        as it is not possible in Petersen's graph to mutualise edges ::
    38943894       
    38953895            sage: g = DiGraph(g)
    3896             sage: g.multiway_cut([0,7,9], value_only = True) == 3*3           # optional - GLPK, CBC
     3896            sage: g.multiway_cut([0,7,9], value_only = True) == 3*3
    38973897            True
    38983898
    38993899        Of course, a multiway cut between the whole vertex set
    39003900        contains all the edges of the graph::
    39013901
    3902             sage: C = g.multiway_cut(g.vertices())                            # optional - GLPK, CBC
    3903             sage: set(C) == set(g.edges())                                    # optional - GLPK, CBC
     3902            sage: C = g.multiway_cut(g.vertices())
     3903            sage: set(C) == set(g.edges())
    39043904            True
    39053905        """
    39063906        from sage.numerical.mip import MixedIntegerLinearProgram
     
    40364036        The two algorithms should return the same result::
    40374037
    40384038           sage: g = graphs.RandomGNP(10,.5)
    4039            sage: vc1 = g.vertex_cover(algorithm="MILP") # optional - GLPK, CBC
    4040            sage: vc2 = g.vertex_cover(algorithm="Cliquer") # optional - GLPK, CBC
    4041            sage: len(vc1) == len(vc2) # optional - GLPK, CBC
     4039           sage: vc1 = g.vertex_cover(algorithm="MILP")
     4040           sage: vc2 = g.vertex_cover(algorithm="Cliquer")
     4041           sage: len(vc1) == len(vc2)
    40424042           True
    40434043        """
    40444044        if algorithm == "Cliquer":
     
    41204120        are the the two sides ::
    41214121
    41224122            sage: g = graphs.CompleteBipartiteGraph(5,6)
    4123             sage: [ value, edges, [ setA, setB ]] = g.max_cut(vertices=True)                  # optional - GLPK, CBC
    4124             sage: value == 5*6                                                                # optional - GLPK, CBC
     4123            sage: [ value, edges, [ setA, setB ]] = g.max_cut(vertices=True)
     4124            sage: value == 5*6
    41254125            True
    41264126            sage: bsetA, bsetB  = map(list,g.bipartite_sets())
    4127             sage: (bsetA == setA and bsetB == setB ) or ((bsetA == setB and bsetB == setA ))  # optional - GLPK, CBC
     4127            sage: (bsetA == setA and bsetB == setB ) or ((bsetA == setB and bsetB == setA ))
    41284128            True
    41294129
    41304130        The max cut of a Petersen graph::
    41314131       
    41324132           sage: g=graphs.PetersenGraph()
    4133            sage: g.max_cut()                                                                  # optional - GLPK, CBC
     4133           sage: g.max_cut()
    41344134           12.0
    41354135
    41364136        """
     
    42664266        The Heawood graph is known to be hamiltonian::
    42674267
    42684268            sage: g = graphs.HeawoodGraph()
    4269             sage: tsp = g.traveling_salesman_problem()   # optional - GLPK, CBC
    4270             sage: tsp                                     # optional - GLPK, CBC
     4269            sage: tsp = g.traveling_salesman_problem()
     4270            sage: tsp
    42714271            TSP from Heawood graph: Graph on 14 vertices
    42724272
    42734273        The solution to the TSP has to be connected ::
    42744274
    4275             sage: tsp.is_connected()                      # optional - GLPK, CBC
     4275            sage: tsp.is_connected()
    42764276            True
    42774277
    42784278        It must also be a `2`-regular graph::
    42794279
    4280             sage: tsp.is_regular(k=2)                     # optional - GLPK, CBC
     4280            sage: tsp.is_regular(k=2)
    42814281            True
    42824282
    42834283        And obviously it is a subgraph of the Heawood graph::
    42844284
    4285             sage: all([ e in g.edges() for e in tsp.edges()])    # optional - GLPK, CBC
     4285            sage: all([ e in g.edges() for e in tsp.edges()])
    42864286            True
    42874287
    42884288        On the other hand, the Petersen Graph is known not to
    42894289        be hamiltonian::
    42904290
    4291             sage: g = graphs.PetersenGraph()                     # optional - GLPK, CBC
    4292             sage: tsp = g.traveling_salesman_problem()          # optional - GLPK, CBC
     4291            sage: g = graphs.PetersenGraph()
     4292            sage: tsp = g.traveling_salesman_problem()
    42934293            Traceback (most recent call last):
    42944294            ...
    42954295            ValueError: The given graph is not hamiltonian
     
    43114311            ...          g.add_edge(u,v)
    43124312            ...      g.set_edge_label(u,v,2)
    43134313
    4314             sage: tsp = g.traveling_salesman_problem(weighted = True)   # optional - GLPK, CBC
    4315             sage: sum( tsp.edge_labels() ) < 2*10                       # optional - GLPK, CBC
     4314            sage: tsp = g.traveling_salesman_problem(weighted = True)
     4315            sage: sum( tsp.edge_labels() ) < 2*10
    43164316            True
    43174317
    43184318        If we pick `1/2` instead of `2` as a cost for these new edges,
     
    43214321            sage: for u,v in cycle.edges(labels = None):
    43224322            ...      g.set_edge_label(u,v,1/2)
    43234323
    4324             sage: tsp = g.traveling_salesman_problem(weighted = True)   # optional - GLPK, CBC
    4325             sage: sum( tsp.edge_labels() ) == (1/2)*10                   # optional - GLPK, CBC
     4324            sage: tsp = g.traveling_salesman_problem(weighted = True)
     4325            sage: sum( tsp.edge_labels() ) == (1/2)*10
    43264326            True
    43274327
    43284328        """
     
    44784478        The Heawood Graph is known to be hamiltonian ::
    44794479
    44804480            sage: g = graphs.HeawoodGraph()
    4481             sage: g.hamiltonian_cycle()         # optional - GLPK, CBC
     4481            sage: g.hamiltonian_cycle()
    44824482            TSP from Heawood graph: Graph on 14 vertices
    44834483
    44844484        The Petergraph, though, is not ::
    44854485
    44864486            sage: g = graphs.PetersenGraph()
    4487             sage: g.hamiltonian_cycle()         # optional - GLPK, CBC
     4487            sage: g.hamiltonian_cycle()
    44884488            Traceback (most recent call last):
    44894489            ...
    44904490            ValueError: The given graph is not hamiltonian
     
    45634563        ``ButterflyGraph`` with parameter `2` ::
    45644564       
    45654565           sage: g=graphs.PappusGraph()
    4566            sage: g.flow(1,2) # optional - GLPK, CBC
     4566           sage: g.flow(1,2)
    45674567           3.0
    45684568
    45694569        ::
    45704570
    45714571           sage: b=digraphs.ButterflyGraph(2)
    4572            sage: b.flow(('00',1),('00',2)) # optional - GLPK, CBC
     4572           sage: b.flow(('00',1),('00',2))
    45734573           1.0
    45744574
    45754575        The flow method can be used to compute a matching in a bipartite graph
     
    45814581            sage: g.add_edges([('s',i) for i in range(4)])
    45824582            sage: g.add_edges([(i,4+j) for i in range(4) for j in range(4)])
    45834583            sage: g.add_edges([(4+i,'t') for i in range(4)])
    4584             sage: [cardinal, flow_graph] = g.flow('s','t',integer=True,value_only=False) # optional - GLPK, CBC
    4585             sage: flow_graph.delete_vertices(['s','t'])                                  # optional - GLPK, CBC
    4586             sage: len(flow_graph.edges(labels=None))                                     # optional - GLPK, CBC   
     4584            sage: [cardinal, flow_graph] = g.flow('s','t',integer=True,value_only=False)
     4585            sage: flow_graph.delete_vertices(['s','t'])
     4586            sage: len(flow_graph.edges(labels=None))
    45874587            4
    45884588       
    45894589        """
     
    47104710        as terminals ::
    47114711 
    47124712            sage: g = graphs.PetersenGraph()
    4713             sage: matching = [(u,v) for u,v,_ in g.matching()]               # optional - GLPK, CBC
    4714             sage: h = g.multicommodity_flow(matching)                        # optional - GLPK, CBC
    4715             sage: len(h)                                                     # optional - GLPK, CBC
     4713            sage: matching = [(u,v) for u,v,_ in g.matching()]
     4714            sage: h = g.multicommodity_flow(matching)
     4715            sage: len(h)
    47164716            5
    47174717 
    47184718        We could also have considered ``g`` as symmetric and computed
    47194719        the multiflow in this version instead. In this case, however
    47204720        edges can be used in both directions at the same time::
    47214721 
    4722             sage: h = DiGraph(g).multicommodity_flow(matching)               # optional - GLPK, CBC
    4723             sage: len(h)                                                     # optional - GLPK, CBC
     4722            sage: h = DiGraph(g).multicommodity_flow(matching)
     4723            sage: len(h)
    47244724            5
    47254725 
    47264726        An exception is raised when the problem has no solution ::
    47274727 
    4728             sage: h = g.multicommodity_flow([(u,v,3) for u,v in matching])   # optional - GLPK, CBC
     4728            sage: h = g.multicommodity_flow([(u,v,3) for u,v in matching])
    47294729            Traceback (most recent call last):
    47304730            ...
    47314731            ValueError: The multiflow problem has no solution
     
    49374937        is ... easy ::
    49384938
    49394939            sage: g = graphs.GridGraph([5,5])
    4940             sage: p1,p2 = g.disjoint_routed_paths( [((0,0), (0,4)), ((4,4), (4,0))]) # optional - requires GLPK CBC or CPLEX
     4940            sage: p1,p2 = g.disjoint_routed_paths( [((0,0), (0,4)), ((4,4), (4,0))])
    49414941
    49424942        Though there is obviously no solution to the problem
    49434943        in which each corner is sending information to the opposite
    49444944        one::
    49454945
    49464946            sage: g = graphs.GridGraph([5,5])
    4947             sage: p1,p2 = g.disjoint_routed_paths( [((0,0), (4,4)), ((0,4), (4,0))]) # optional - requires GLPK CBC or CPLEX
     4947            sage: p1,p2 = g.disjoint_routed_paths( [((0,0), (4,4)), ((0,4), (4,0))])
    49484948            Traceback (most recent call last):
    49494949            ...
    49504950            ValueError: The disjoint routed paths do not exist.
     
    49784978        In a complete bipartite graph ::
    49794979
    49804980            sage: g = graphs.CompleteBipartiteGraph(2,3)
    4981             sage: g.edge_disjoint_paths(0,1) # optional - GLPK, CBC
     4981            sage: g.edge_disjoint_paths(0,1)
    49824982            [[0, 2, 1], [0, 3, 1], [0, 4, 1]]
    49834983        """
    49844984
     
    50185018        In a complete bipartite graph ::
    50195019
    50205020            sage: g = graphs.CompleteBipartiteGraph(2,3)
    5021             sage: g.vertex_disjoint_paths(0,1) # optional - GLPK, CBC
     5021            sage: g.vertex_disjoint_paths(0,1)
    50225022            [[0, 2, 1], [0, 3, 1], [0, 4, 1]]
    50235023        """
    50245024
     
    51045104        Same test with the Linear Program formulation::
    51055105
    51065106           sage: g = graphs.PappusGraph()
    5107            sage: g.matching(algorithm="LP", value_only=True) # optional - GLPK, CBC
     5107           sage: g.matching(algorithm="LP", value_only=True)
    51085108           9.0
    51095109
    51105110        TESTS:
     
    52155215        A basic illustration on a ``PappusGraph``::
    52165216       
    52175217           sage: g=graphs.PappusGraph()
    5218            sage: g.dominating_set(value_only=True)    # optional - GLPK, CBC
     5218           sage: g.dominating_set(value_only=True)
    52195219           5.0
    52205220
    52215221        If we build a graph from two disjoint stars, then link their centers
     
    52245224
    52255225           sage: g = 2 * graphs.StarGraph(5)
    52265226           sage: g.add_edge(0,6)
    5227            sage: len(g.dominating_set())                       # optional - GLPK, CBC
     5227           sage: len(g.dominating_set())
    52285228           2
    5229            sage: len(g.dominating_set(independent=True))       # optional - GLPK, CBC
     5229           sage: len(g.dominating_set(independent=True))
    52305230           6
    52315231   
    52325232        """
     
    53045304        A basic application on the PappusGraph::
    53055305       
    53065306           sage: g = graphs.PappusGraph()
    5307            sage: g.edge_connectivity() # optional - GLPK, CBC
     5307           sage: g.edge_connectivity()
    53085308           3.0
    53095309
    53105310        The edge connectivity of a complete graph ( and of a random graph )
     
    53135313        Star graph::
    53145314
    53155315           sage: g = graphs.CompleteGraph(5)
    5316            sage: [ value, edges, [ setA, setB ]] = g.edge_connectivity(vertices=True) # optional - GLPK, CBC
    5317            sage: print value                                                          # optional - GLPK, CBC
     5316           sage: [ value, edges, [ setA, setB ]] = g.edge_connectivity(vertices=True)
     5317           sage: print value
    53185318           4.0
    5319            sage: len(setA) == 1 or len(setB) == 1                                     # optional - GLPK, CBC
     5319           sage: len(setA) == 1 or len(setB) == 1
    53205320           True
    53215321           sage: cut = Graph()
    5322            sage: cut.add_edges(edges)                                                 # optional - GLPK, CBC
    5323            sage: cut.is_isomorphic(graphs.StarGraph(4))                               # optional - GLPK, CBC
     5322           sage: cut.add_edges(edges)
     5323           sage: cut.is_isomorphic(graphs.StarGraph(4))
    53245324           True
    53255325
    53265326        Even if obviously in any graph we know that the edge connectivity
    53275327        is less than the minimum degree of the graph::
    53285328
    53295329           sage: g = graphs.RandomGNP(10,.3)
    5330            sage: min(g.degree()) >= g.edge_connectivity()                             # optional - GLPK, CBC
     5330           sage: min(g.degree()) >= g.edge_connectivity()
    53315331           True
    53325332
    53335333        If we build a tree then assign to its edges a random value, the
     
    53385338           sage: tree.add_edges(g.min_spanning_tree())
    53395339           sage: for u,v in tree.edge_iterator(labels=None):
    53405340           ...        tree.set_edge_label(u,v,random())
    5341            sage: minimum = min([l for u,v,l in tree.edge_iterator()])                                       # optional - GLPK, CBC
    5342            sage: [value, [(u,v,l)]] = tree.edge_connectivity(value_only=False, use_edge_labels=True)        # optional - GLPK, CBC
    5343            sage: l == minimum                                                                               # optional - GLPK, CBC
     5341           sage: minimum = min([l for u,v,l in tree.edge_iterator()])
     5342           sage: [value, [(u,v,l)]] = tree.edge_connectivity(value_only=False, use_edge_labels=True)
     5343           sage: l == minimum
    53445344           True
    53455345
    53465346        When ``value_only = True``, this function is optimized for small
     
    55025502        A basic application on a ``PappusGraph``::
    55035503       
    55045504           sage: g=graphs.PappusGraph()
    5505            sage: g.vertex_connectivity() # optional - GLPK, CBC
     5505           sage: g.vertex_connectivity()
    55065506           3.0
    55075507
    55085508        In a grid, the vertex connectivity is equal to the
     
    55105510        of cardinality `1`::
    55115511
    55125512           sage: g = graphs.GridGraph([ 3,3 ])
    5513            sage: [value, cut, [ setA, setB ]] = g.vertex_connectivity(sets=True) # optional - GLPK, CBC
    5514            sage: len(setA) == 1 or len(setB) == 1                                # optional - GLPK, CBC
     5513           sage: [value, cut, [ setA, setB ]] = g.vertex_connectivity(sets=True)
     5514           sage: len(setA) == 1 or len(setB) == 1
    55155515           True
    55165516
    55175517        A vertex cut in a tree is any internal vertex::
     
    55195519           sage: g = graphs.RandomGNP(15,.5)
    55205520           sage: tree = Graph()
    55215521           sage: tree.add_edges(g.min_spanning_tree())
    5522            sage: [val, [cut_vertex]] = tree.vertex_connectivity(value_only=False) # optional - GLPK, CBC
    5523            sage: tree.degree(cut_vertex) > 1                                      # optional - GLPK, CBC
     5522           sage: [val, [cut_vertex]] = tree.vertex_connectivity(value_only=False)
     5523           sage: tree.degree(cut_vertex) > 1
    55245524           True
    55255525
    55265526        When ``value_only = True``, this function is optimized for small
     
    73137313        degree::
    73147314
    73157315            sage: g = graphs.RandomGNP(20,.3)
    7316             sage: mad_g = g.maximum_average_degree()                       # optional - GLPK, CBC
    7317             sage: g.average_degree() <= mad_g                              # optional - GLPK, CBC
     7316            sage: mad_g = g.maximum_average_degree()
     7317            sage: g.average_degree() <= mad_g
    73187318            True
    73197319
    73207320        Unlike the average degree, the `Mad` of the disjoint
     
    73227322        graphs::
    73237323
    73247324            sage: h = graphs.RandomGNP(20,.3)
    7325             sage: mad_h = h.maximum_average_degree()                      # optional - GLPK, CBC
    7326             sage: (g+h).maximum_average_degree() == max(mad_g, mad_h)     # optional - GLPK, CBC
     7325            sage: mad_h = h.maximum_average_degree()
     7326            sage: (g+h).maximum_average_degree() == max(mad_g, mad_h)
    73277327            True
    73287328
    73297329        The subgraph of a regular graph realizing the maximum
    73307330        average degree is always the whole graph ::
    73317331
    73327332            sage: g = graphs.CompleteGraph(5)
    7333             sage: mad_g = g.maximum_average_degree(value_only=False)      # optional - GLPK, CBC
    7334             sage: g.is_isomorphic(mad_g)                                  # optional - GLPK, CBC
     7333            sage: mad_g = g.maximum_average_degree(value_only=False)
     7334            sage: g.is_isomorphic(mad_g)
    73357335            True
    73367336
    73377337        This also works for complete bipartite graphs ::
    73387338
    7339             sage: g = graphs.CompleteBipartiteGraph(3,4)                  # optional - GLPK, CBC
    7340             sage: mad_g = g.maximum_average_degree(value_only=False)      # optional - GLPK, CBC
    7341             sage: g.is_isomorphic(mad_g)                                  # optional - GLPK, CBC
     7339            sage: g = graphs.CompleteBipartiteGraph(3,4)
     7340            sage: mad_g = g.maximum_average_degree(value_only=False)
     7341            sage: g.is_isomorphic(mad_g)
    73427342            True           
    73437343        """
    73447344
     
    1325713257        The Heawood Graph is known to be hamiltonian ::
    1325813258
    1325913259            sage: g = graphs.HeawoodGraph()
    13260             sage: g.is_hamiltonian()         # optional - GLPK, CBC
     13260            sage: g.is_hamiltonian()
    1326113261            True
    1326213262
    1326313263        The Petergraph, though, is not ::
    1326413264
    1326513265            sage: g = graphs.PetersenGraph()
    13266             sage: g.is_hamiltonian()         # optional - GLPK, CBC
     13266            sage: g.is_hamiltonian()
    1326713267            False
    1326813268
    1326913269        TESTS:
  • sage/graphs/graph.py

    diff -r ebb57e653f50 -r d43977d32b09 sage/graphs/graph.py
    a b  
    17061706
    17071707            sage: g = graphs.CycleGraph(6)
    17081708            sage: bounds = lambda x: [1,1]
    1709             sage: m = g.degree_constrained_subgraph(bounds=bounds) # optional - GLPK, CBC
    1710             sage: m.size() # optional - GLPK, CBC
     1709            sage: m = g.degree_constrained_subgraph(bounds=bounds)
     1710            sage: m.size()
    17111711            3
    17121712        """
    17131713
     
    19851985            sage: G = Graph({0: [1, 2, 3], 1: [2]})
    19861986            sage: G.chromatic_number(algorithm="DLX")
    19871987            3
    1988             sage: G.chromatic_number(algorithm="MILP") # optional - GLPK, CBC
     1988            sage: G.chromatic_number(algorithm="MILP")
    19891989            3
    19901990            sage: G.chromatic_number(algorithm="CP")
    19911991            3
     
    20442044        EXAMPLES::
    20452045       
    20462046            sage: G = Graph("Fooba")
    2047             sage: P = G.coloring(algorithm="MILP"); P  # optional - GLPK, CBC
     2047            sage: P = G.coloring(algorithm="MILP"); P
    20482048            [[2, 1, 3], [0, 6, 5], [4]]
    20492049            sage: P = G.coloring(algorithm="DLX"); P
    20502050            [[1, 2, 3], [0, 5, 6], [4]]
    20512051            sage: G.plot(partition=P)
    2052             sage: H = G.coloring(hex_colors=True, algorithm="MILP") # optional - GLPK, CBC
    2053             sage: for c in sorted(H.keys()):                        # optional - GLPK, CBC
    2054             ...       print c, H[c]                                 # optional - GLPK, CBC
     2052            sage: H = G.coloring(hex_colors=True, algorithm="MILP")
     2053            sage: for c in sorted(H.keys()):
     2054            ...       print c, H[c]
    20552055            #0000ff [4]
    20562056            #00ff00 [0, 6, 5]
    20572057            #ff0000 [2, 1, 3]
     
    21212121       
    21222122           sage: g = graphs.CompleteBipartiteGraph(3,3)
    21232123           sage: g.delete_edge(1,4)
    2124            sage: g.independent_set_of_representatives([[0,1,2],[3,4,5]]) # optional - GLPK, CBC
     2124           sage: g.independent_set_of_representatives([[0,1,2],[3,4,5]])
    21252125           [1, 4]
    21262126
    21272127        The Petersen Graph is 3-colorable, which can be expressed as an
     
    21342134            sage: g = 3 * graphs.PetersenGraph()
    21352135            sage: n = g.order()/3
    21362136            sage: f = [[i,i+n,i+2*n] for i in xrange(n)]
    2137             sage: isr = g.independent_set_of_representatives(f)   # optional - GLPK, CBC
    2138             sage: c = [floor(i/n) for i in isr]                   # optional - GLPK, CBC
    2139             sage: color_classes = [[],[],[]]                      # optional - GLPK, CBC
    2140             sage: for v,i in enumerate(c):                        # optional - GLPK, CBC
    2141             ...     color_classes[i].append(v)                    # optional - GLPK, CBC
    2142             sage: for classs in color_classes:                    # optional - GLPK, CBC
    2143             ...     g.subgraph(classs).size() == 0                # optional - GLPK, CBC
     2137            sage: isr = g.independent_set_of_representatives(f)
     2138            sage: c = [floor(i/n) for i in isr]
     2139            sage: color_classes = [[],[],[]]
     2140            sage: for v,i in enumerate(c):
     2141            ...     color_classes[i].append(v)
     2142            sage: for classs in color_classes:
     2143            ...     g.subgraph(classs).size() == 0
    21442144            True
    21452145            True
    21462146            True
     
    22652265       
    22662266            sage: g = graphs.GridGraph([4,4])
    22672267            sage: h = graphs.CompleteGraph(4)
    2268             sage: L = g.minor(h)                                                 # optional - GLPK, CBC
    2269             sage: gg = g.subgraph(flatten(L.values(), max_level = 1))            # optional - GLPK, CBC
    2270             sage: _ = [gg.merge_vertices(l) for l in L.values() if len(l)>1]     # optional - GLPK, CBC
    2271             sage: gg.is_isomorphic(h)                                            # optional - GLPK, CBC
     2268            sage: L = g.minor(h)
     2269            sage: gg = g.subgraph(flatten(L.values(), max_level = 1))
     2270            sage: _ = [gg.merge_vertices(l) for l in L.values() if len(l)>1]
     2271            sage: gg.is_isomorphic(h)
    22722272            True
    22732273
    22742274        We can also try to prove this way that the Petersen graph
    22752275        is not planar, as it has a `K_5` minor::
    22762276
    22772277            sage: g = graphs.PetersenGraph()
    2278             sage: K5_minor = g.minor(graphs.CompleteGraph(5))                    # long, optional - GLPK, CBC
     2278            sage: K5_minor = g.minor(graphs.CompleteGraph(5))                    # long
    22792279
    22802280        And even a `K_{3,3}` minor::
    22812281
    2282             sage: K33_minor = g.minor(graphs.CompleteBipartiteGraph(3,3))        # long, optional - GLPK, CBC
     2282            sage: K33_minor = g.minor(graphs.CompleteBipartiteGraph(3,3))        # long
    22832283           
    22842284        (It is much faster to use the linear-time test of
    22852285        planarity in this situation, though.)
     
    22912291            sage: g = g.subgraph(edges = g.min_spanning_tree())
    22922292            sage: g.is_tree()
    22932293            True
    2294             sage: L = g.minor(graphs.CompleteGraph(3))                           # optional - GLPK, CBC
     2294            sage: L = g.minor(graphs.CompleteGraph(3))
    22952295            Traceback (most recent call last):
    22962296            ...
    22972297            ValueError: This graph has no minor isomorphic to H !
     
    32033203        example is only present to have a doctest coverage of 100%.
    32043204
    32053205            sage: g = graphs.PetersenGraph()
    3206             sage: t = g._gomory_hu_tree()      # optional - GLPK, CBC
     3206            sage: t = g._gomory_hu_tree()
    32073207        """
    32083208        from sage.sets.set import Set
    32093209       
     
    33223322        Taking the Petersen graph::
    33233323
    33243324            sage: g = graphs.PetersenGraph()
    3325             sage: t = g.gomory_hu_tree() # optional - GLPK, CBC
     3325            sage: t = g.gomory_hu_tree()
    33263326
    33273327        Obviously, this graph is a tree::
    33283328
    3329             sage: t.is_tree()  # optional - GLPK, CBC
     3329            sage: t.is_tree()
    33303330            True
    33313331
    33323332        Note that if the original graph is not connected, then the
    33333333        Gomory-Hu tree is in fact a forest::
    33343334
    3335             sage: (2*g).gomory_hu_tree().is_forest() # optional - GLPK, CBC
     3335            sage: (2*g).gomory_hu_tree().is_forest()
    33363336            True
    3337             sage: (2*g).gomory_hu_tree().is_connected() # optional - GLPK, CBC
     3337            sage: (2*g).gomory_hu_tree().is_connected()
    33383338            False
    33393339
    33403340        On the other hand, such a tree has lost nothing of the initial
    33413341        graph connectedness::
    33423342
    3343             sage: all([ t.flow(u,v) == g.flow(u,v) for u,v in Subsets( g.vertices(), 2 ) ]) # optional - GLPK, CBC
     3343            sage: all([ t.flow(u,v) == g.flow(u,v) for u,v in Subsets( g.vertices(), 2 ) ])
    33443344            True
    33453345
    33463346        Just to make sure, we can check that the same is true for two vertices
    33473347        in a random graph::
    33483348
    33493349            sage: g = graphs.RandomGNP(20,.3)
    3350             sage: t = g.gomory_hu_tree() # optional - GLPK, CBC
    3351             sage: g.flow(0,1) == t.flow(0,1) # optional - GLPK, CBC
     3350            sage: t = g.gomory_hu_tree()
     3351            sage: g.flow(0,1) == t.flow(0,1)
    33523352            True
    33533353
    33543354        And also the min cut::
    33553355
    3356             sage: g.edge_connectivity() == min(t.edge_labels()) # optional - GLPK, CBC
     3356            sage: g.edge_connectivity() == min(t.edge_labels())
    33573357            True
    33583358        """
    33593359        return self._gomory_hu_tree()
     
    33843384        be edge-partitionned into `2`-regular graphs::
    33853385   
    33863386            sage: g = graphs.CompleteGraph(7)
    3387             sage: classes = g.two_factor_petersen()  # optional - GLPK, CBC
    3388             sage: for c in classes:                  # optional - GLPK, CBC
    3389             ...     gg = Graph()                     # optional - GLPK, CBC
    3390             ...     gg.add_edges(c)                  # optional - GLPK, CBC
    3391             ...     print max(gg.degree())<=2        # optional - GLPK, CBC
     3387            sage: classes = g.two_factor_petersen()
     3388            sage: for c in classes:
     3389            ...     gg = Graph()
     3390            ...     gg.add_edges(c)
     3391            ...     print max(gg.degree())<=2
    33923392            True
    33933393            True
    33943394            True
    3395             sage: Set(set(classes[0]) | set(classes[1]) | set(classes[2])).cardinality() == g.size() # optional - GLPK, CBC
     3395            sage: Set(set(classes[0]) | set(classes[1]) | set(classes[2])).cardinality() == g.size()
    33963396            True
    33973397
    33983398        ::
    33993399
    34003400            sage: g = graphs.CirculantGraph(24, [7, 11])
    3401             sage: cl = g.two_factor_petersen()                     # optional - GLPK or CBC
    3402             sage: g.plot(edge_colors={'black':cl[0], 'red':cl[1]}) # optional - GLPK or CBC
     3401            sage: cl = g.two_factor_petersen()
     3402            sage: g.plot(edge_colors={'black':cl[0], 'red':cl[1]})
    34033403
    34043404        """
    34053405   
  • sage/graphs/graph_coloring.py

    diff -r ebb57e653f50 -r d43977d32b09 sage/graphs/graph_coloring.py
    a b  
    299299
    300300       sage: from sage.graphs.graph_coloring import vertex_coloring
    301301       sage: g = graphs.PetersenGraph()
    302        sage: vertex_coloring(g, value_only=True) # optional - GLPK, CBC
     302       sage: vertex_coloring(g, value_only=True)
    303303       3
    304304    """
    305305    from sage.numerical.mip import MixedIntegerLinearProgram
     
    518518
    519519       sage: from sage.graphs.graph_coloring import edge_coloring
    520520       sage: g = graphs.PetersenGraph()
    521        sage: edge_coloring(g, value_only=True) # optional - GLPK, CBC
     521       sage: edge_coloring(g, value_only=True)
    522522       4
    523523
    524524    Complete graphs are colored using the linear-time round-robin coloring::
     
    731731    are an admissible partition::
    732732
    733733        sage: from sage.graphs.graph_coloring import linear_arboricity
    734         sage: g = graphs.GridGraph([4,4])                                 # optional - GLPK, CBC
    735         sage: g1,g2 = linear_arboricity(g, k=0)                           # optional - GLPK, CBC
     734        sage: g = graphs.GridGraph([4,4])
     735        sage: g1,g2 = linear_arboricity(g, k=0)
    736736
    737737    Each graph is of course a forest::
    738738
    739         sage: g1.is_forest() and g2.is_forest()                           # optional - GLPK, CBC
     739        sage: g1.is_forest() and g2.is_forest()
    740740        True
    741741
    742742    Of maximum degree 2::
    743743
    744         sage: max(g1.degree()) <= 2 and max(g2.degree()) <= 2             # optional - GLPK, CBC
     744        sage: max(g1.degree()) <= 2 and max(g2.degree()) <= 2
    745745        True
    746746
    747747    Which constitutes a partition of the whole edge set::
    748748
    749         sage: all([g1.has_edge(e) or g2.has_edge(e) for e in g.edges(labels = None)])  # optional - GLPK, CBC
     749        sage: all([g1.has_edge(e) or g2.has_edge(e) for e in g.edges(labels = None)])
    750750        True
    751751
    752752    REFERENCES:
     
    910910
    911911        sage: from sage.graphs.graph_coloring import acyclic_edge_coloring
    912912        sage: g = graphs.CompleteGraph(8)   
    913         sage: colors = acyclic_edge_coloring(g)                                     # optional - GLPK, CBC
     913        sage: colors = acyclic_edge_coloring(g)
    914914
    915915    Each color class is of course a matching ::
    916916
    917         sage: all([max(gg.degree())<=1 for gg in colors])                           # optional - GLPK, CBC
     917        sage: all([max(gg.degree())<=1 for gg in colors])
    918918        True
    919919
    920920    These matchings being a partition of the edge set::
    921921
    922         sage: all([ any([gg.has_edge(e) for gg in colors]) for e in g.edges(labels = False)])     # optional - GLPK, CBC
     922        sage: all([ any([gg.has_edge(e) for gg in colors]) for e in g.edges(labels = False)])
    923923        True
    924924
    925925    Besides, the union of any two of them is a forest ::
    926926
    927         sage: all([g1.union(g2).is_forest() for g1 in colors for g2 in colors])     # optional - GLPK, CBC
     927        sage: all([g1.union(g2).is_forest() for g1 in colors for g2 in colors])
    928928        True
    929929
    930930    If one wants to acyclically color a cycle on `4` vertices,
     
    932932    an exception when asked to color it with only 2::
    933933
    934934        sage: g = graphs.CycleGraph(4)
    935         sage: acyclic_edge_coloring(g, k=2)                                         # optional - GLPK, CBC
     935        sage: acyclic_edge_coloring(g, k=2)
    936936        Traceback (most recent call last):
    937937        ...
    938938        ValueError: This graph can not be colored with the given number of colors.
    939939
    940940    The optimal coloring give us `3` classes::
    941941
    942         sage: colors = acyclic_edge_coloring(g, k=None)                             # optional - GLPK, CBC
    943         sage: len(colors)                                                           # optional - GLPK, CBC
     942        sage: colors = acyclic_edge_coloring(g, k=None)
     943        sage: len(colors)
    944944        3
    945945
    946946    """
  • sage/numerical/mip.pyx

    diff -r ebb57e653f50 -r d43977d32b09 sage/numerical/mip.pyx
    a b  
    4141         sage: for (u,v) in g.edges(labels=None):
    4242         ...       p.add_constraint(b[u] + b[v], max=1)
    4343         sage: p.set_binary(b)
    44          sage: p.solve(objective_only=True)     # optional - GLPK, CBC
     44         sage: p.solve(objective_only=True)
    4545         4.0
    4646    """
    4747   
     
    486486            sage: x = p.new_variable()
    487487            sage: p.set_objective(x[1] + x[2])
    488488            sage: p.add_constraint(-3*x[1] + 2*x[2], max=2,name="OneConstraint")
    489             sage: p.write_mps(SAGE_TMP+"/lp_problem.mps") # optional - GLPK
     489            sage: p.write_mps(SAGE_TMP+"/lp_problem.mps")
    490490
    491491        For information about the MPS file format :
    492492        http://en.wikipedia.org/wiki/MPS_%28format%29
     
    519519            sage: x = p.new_variable()
    520520            sage: p.set_objective(x[1] + x[2])
    521521            sage: p.add_constraint(-3*x[1] + 2*x[2], max=2)
    522             sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") # optional - GLPK
     522            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")
    523523
    524524        For more information about the LP file format :
    525525        http://lpsolve.sourceforge.net/5.5/lp-format.htm
     
    558558            sage: y = p.new_variable(dim=2)
    559559            sage: p.set_objective(x[3] + 3*y[2][9] + x[5])
    560560            sage: p.add_constraint(x[3] + y[2][9] + 2*x[5], max=2)
    561             sage: p.solve() # optional - GLPK, CBC
     561            sage: p.solve()
    562562            6.0
    563563           
    564564        To return  the optimal value of ``y[2][9]``::
    565565
    566             sage: p.get_values(y[2][9]) # optional - GLPK, CBC
     566            sage: p.get_values(y[2][9])
    567567            2.0
    568568
    569569        To get a dictionary identical to ``x`` containing optimal
     
    642642            sage: p.set_objective(x[1] + 5*x[2])
    643643            sage: p.add_constraint(x[1] + 2/10*x[2], max=4)
    644644            sage: p.add_constraint(1.5*x[1]+3*x[2], max=4)
    645             sage: round(p.solve(),5)     # optional - GLPK, CBC
     645            sage: round(p.solve(),5)
    646646            6.66667
    647647            sage: p.set_objective(None)
    648             sage: p.solve() #optional - GLPK, CBC
     648            sage: p.solve()
    649649            0.0
    650650        """
    651651
     
    707707            sage: p.set_objective(x[1] + 5*x[2])
    708708            sage: p.add_constraint(x[1] + 0.2*x[2], max=4)
    709709            sage: p.add_constraint(1.5*x[1] + 3*x[2], max=4)
    710             sage: round(p.solve(),6)     # optional - GLPK, CBC
     710            sage: round(p.solve(),6)
    711711            6.666667
    712712
    713713        There are two different ways to add the constraint
     
    737737            sage: p.set_objective(x[1] + 5*x[2])
    738738            sage: p.add_constraint(x[1] + 0.2*x[2] <= 4)
    739739            sage: p.add_constraint(1.5*x[1] + 3*x[2] <= 4)
    740             sage: p.solve()     # optional - GLPK, CBC
     740            sage: p.solve()
    741741            6.6666666666666661
    742742
    743743
     
    10501050            sage: p.set_objective(x[1] + 5*x[2])
    10511051            sage: p.add_constraint(x[1] + 0.2*x[2], max=4)
    10521052            sage: p.add_constraint(1.5*x[1] + 3*x[2], max=4)
    1053             sage: round(p.solve(),6)  # optional - GLPK, CBC
     1053            sage: round(p.solve(),6)
    10541054            6.666667
    1055             sage: p.get_values(x)     # optional random - GLPK, CBC
     1055            sage: p.get_values(x)
    10561056            {0: 0.0, 1: 1.3333333333333333}
    10571057
    10581058         Computation of a maximum stable set in Petersen's graph::
     
    10641064            sage: for (u,v) in g.edges(labels=None):
    10651065            ...       p.add_constraint(b[u] + b[v], max=1)
    10661066            sage: p.set_binary(b)
    1067             sage: p.solve(objective_only=True)     # optional - GLPK, CBC
     1067            sage: p.solve(objective_only=True)
    10681068            4.0
    10691069        """
    10701070
     
    12621262
    12631263         Tests of GLPK's Exceptions::
    12641264
    1265             sage: p.solve(solver="GLPK") # optional - GLPK
     1265            sage: p.solve(solver="GLPK")
    12661266            Traceback (most recent call last):
    12671267            ...
    12681268            MIPSolverException: 'GLPK : Solution is undefined'
     
    12781278
    12791279         Tests of GLPK's Exceptions::
    12801280
    1281             sage: p.solve(solver="GLPK") # optional - GLPK
     1281            sage: p.solve(solver="GLPK")
    12821282            Traceback (most recent call last):
    12831283            ...
    12841284            MIPSolverException: 'GLPK : Solution is undefined'
  • sage/numerical/mip_glpk.pyx

    diff -r ebb57e653f50 -r d43977d32b09 sage/numerical/mip_glpk.pyx
    a b  
    3838    Solving a simple Linear Program using Coin as a solver
    3939    ( Computation of a maximum stable set in Petersen's graph )::
    4040
    41         sage: from sage.numerical.mip_glpk import solve_glpk    # optional - GLPK
     41        sage: from sage.numerical.mip_glpk import solve_glpk
    4242        sage: g = graphs.PetersenGraph()
    4343        sage: p = MixedIntegerLinearProgram(maximization=True)
    4444        sage: b = p.new_variable()
     
    4646        sage: for (u,v) in g.edges(labels=None):
    4747        ...       p.add_constraint(b[u] + b[v], max=1)
    4848        sage: p.set_binary(b)
    49         sage: solve_glpk(p, objective_only=True)     # optional - GLPK
     49        sage: solve_glpk(p, objective_only=True)
    5050        4.0
    5151    """
    5252
     
    120120        sage: x = p.new_variable()
    121121        sage: p.set_objective(x[1] + x[2])
    122122        sage: p.add_constraint(-3*x[1] + 2*x[2], max=2,name="OneConstraint")
    123         sage: p.write_mps(SAGE_TMP+"/lp_problem.mps") # optional - GLPK
     123        sage: p.write_mps(SAGE_TMP+"/lp_problem.mps")
    124124
    125125
    126126    For information about the MPS file format :
     
    161161        sage: x = p.new_variable()
    162162        sage: p.set_objective(x[1] + x[2])
    163163        sage: p.add_constraint(-3*x[1] + 2*x[2], max=2)
    164         sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") # optional - GLPK
     164        sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")
    165165
    166166    For more information about the LP file format :
    167167    http://lpsolve.sourceforge.net/5.5/lp-format.htm