# Ticket #8892: trac_8892.patch

File trac_8892.patch, 7.8 KB (added by ncohen, 11 years ago)
• ## sage/graphs/generic_graph.py

```# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1273280136 14400
# Node ID 8c51f0d9a582bdf03502c7ffdc430cbf66c36cda
# Parent  263f1caae32dd7ac94a108e8b279a9872b56f260
trac 8892 - Fixing broken docstring

diff -r 263f1caae32d -r 8c51f0d9a582 sage/graphs/generic_graph.py```
 a "Please convert it to a Graph if you really mean it.") if use_edge_labels: weight = lambda u,v : self.edge_label(u,v) if self.edge_label(u,v)!=None else 1 from sage.rings.real_mpfr import RR weight = lambda u,v : self.edge_label(u,v) if self.edge_label(u,v) in RR else 1 else: weight = lambda u,v : 1 The edge cut between the two ends is the edge of minimum weight:: sage: minimum = min([l for u,v,l in g.edge_iterator()]) sage: minimum == g.edge_cut(0, 14, use_edge_labels=True) # optional - requires GLPK or COIN-OR/CBC sage: abs(minimum - g.edge_cut(0, 14, use_edge_labels=True)) < 10**(-5) # optional - requires GLPK or COIN-OR/CBC or CPLEX True sage: [value,[[u,v]]] = g.edge_cut(0, 14, use_edge_labels=True, value_only=False) # optional - requires GLPK or COIN-OR/CBC sage: g.edge_label(u, v) == minimum # optional - requires GLPK or COIN-OR/CBC if vertices: value_only = False if use_edge_labels: weight = lambda x: 1 if x == None else x from sage.rings.real_mpfr import RR weight = lambda x: x if x in RR else 1 else: weight = lambda x: 1 sage: [ value, edges, [ setA, setB ]] = g.max_cut(vertices=True)                  # optional - requires Glpk or COIN-OR/CBC sage: value == 5*6                                                                # optional - requires Glpk or COIN-OR/CBC True sage: bsetA, bsetB  = g.bipartite_sets() sage: bsetA, bsetB  = map(list,g.bipartite_sets()) sage: (bsetA == setA and bsetB == setB ) or ((bsetA == setB and bsetB == setA ))  # optional - requires Glpk or COIN-OR/CBC True value_only=False if use_edge_labels: weight=lambda x: 1 if x==None else x from sage.rings.real_mpfr import RR weight = lambda x: x if x in RR else 1 else: weight=lambda x: 1 weight = lambda x: 1 if g.is_directed(): reorder_edge = lambda x,y : (x,y) flow=p.new_variable(dim=2) if use_edge_labels: capacity=lambda x: x if x!=None else 1 from sage.rings.real_mpfr import RR capacity=lambda x: x if x in RR else 1 else: capacity=lambda x: 1 # returns the weight of an edge considering it may not be # weighted ... weight=lambda x: 1 if x==None else x from sage.rings.real_mpfr import RR weight=lambda x: x if x in RR else 1 p=MixedIntegerLinearProgram(maximization=True) value_only=False if use_edge_labels: weight=lambda x: 1 if x==None else x from sage.rings.real_mpfr import RR weight=lambda x: x if x in RR else 1 else: weight=lambda x: 1
• ## sage/graphs/graph.py

`diff -r 263f1caae32d -r 8c51f0d9a582 sage/graphs/graph.py`
 a sage: g = graphs.CycleGraph(6) sage: bounds = lambda x: [1,1] sage: m = g.degree_constrained_subgraph(bounds=bounds) # optional - requires GLPK or CBC sage: m.size() #optional sage: m = g.degree_constrained_subgraph(bounds=bounds) # optional - requires GLPK or CBC or CPLEX sage: m.size() # optional - requires GLPK CBC or CPLEX 3 """ p = MixedIntegerLinearProgram(maximization=False) b = p.new_variable() reorder = lambda x: (min(x[0],x[1]),max(x[0],x[1]),x[2]) reorder = lambda x,y: (x,y) if x
• ## sage/graphs/graph_coloring.py

`diff -r 263f1caae32d -r 8c51f0d9a582 sage/graphs/graph_coloring.py`
 a obj = {} k = max(g.degree()) # reorders the edge if necessary... R = lambda x: x if (x[0] <= x[1]) else (x[1], x[0], x[2]) R = lambda x: x if (x[0] <= x[1]) else (x[1], x[0]) # Vizing's coloring uses Delta + 1 colors if vizing: value_only = False k += 1 #  A vertex can not have two incident edges with the same color. [p.add_constraint( sum([color[R(e)][i] for e in g.edges_incident(v)]), max=1) sum([color[R(e)][i] for e in g.edges_incident(v, labels=False)]), max=1) for v in g.vertex_iterator() for i in xrange(k)] # an edge must have a color [p.add_constraint(sum([color[R(e)][i] for i in xrange(k)]), max=1, min=1) for e in g.edge_iterator()] for e in g.edge_iterator(labels=False)] # anything is good as an objective value as long as it is satisfiable e = g.edge_iterator().next() e = g.edge_iterator(labels=False).next() p.set_objective(color[R(e)][0]) p.set_binary(color) try: color = p.get_values(color) classes = [[] for i in xrange(k)] [classes[i].append(e) for e in g.edge_iterator() for e in g.edge_iterator(labels = False) for i in xrange(k) if color[R(e)][i] == 1] # if needed, builds a dictionary from the color classes adding colors