# Ticket #9230: trac_9230.patch

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

```# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1276380631 -7200
# Node ID 7e3018d36e85b1b50e4424b8c07f607dbd8dd298
# Parent  556bb66e4c6dbb92a4ee37c1750d82a5c6298eeb
trac 9230 -- Broken docstrings in Graph.traveling_salesman_poblem

diff -r 556bb66e4c6d -r 7e3018d36e85 sage/graphs/generic_graph.py```
 a p = MixedIntegerLinearProgram(maximization = False) f = p.new_variable() r = p.new_variable() # If the graph has multiple edges if self.has_multiple_edges(): g = self.copy() # the weights of the parallel edges #  new value *if* ( none other        *or*   new==None and last > 1     *else*  change nothing e[(u,v)] = l if (not e.has_key((u,v)) or ( l is None and e[(u,v)] > 1 )) else e[(u,v)] e[(u,v)] = l if (not e.has_key((u,v)) or ( (l is None or l == {}) and e[(u,v)] > 1 )) else e[(u,v)] g.add_edges([(u,v) for (u,v),l in e.iteritems()]) p.add_constraint( sum([ r[(u,v)] for u in g.neighbors(v)]),max = 1-eps) weight = lambda u,v : g.edge_label(u,v) if g.edge_label(u,v) is not None else 1 weight = lambda u,v : g.edge_label(u,v) if (g.edge_label(u,v) is not None and g.edge_label(u,v) != {}) else 1 if weighted: p.set_objective( sum([ weight(u,v)*E(u,v) for u,v in g.edges(labels=None)]) )