Ticket #14434: trac_14434-clean_doc.patch

File trac_14434-clean_doc.patch, 5.8 KB (added by vdelecroix, 6 years ago)
  • sage/graphs/generic_graph.py

    # HG changeset patch
    # User Vincent Delecroix <20100.delecroix at gmail.com>
    # Date 1370414735 -7200
    # Node ID 210523cbe254aa29d2a1e7cd7090d97b04b8dcf0
    # Parent  7eb54e37fcbcd2dd85894f17883479b765e83df2
    trac 14334: clean documentation for feedback_vertex_set
    
    diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
    a b  
    60586058        The minimum feedback vertex set of a (di)graph is a set of vertices that
    60596059        intersect all of its cycles.  Equivalently, a minimum feedback vertex
    60606060        set of a (di)graph is a set `S` of vertices such that the digraph `G-S`
    6061         is acyclic. For more information, see the `Wikipedia article on feedback
    6062         vertex sets <http://en.wikipedia.org/wiki/Feedback_vertex_set>`_.
     6061        is acyclic. For more information, see :wikipedia:`Feedback_vertex_set`.
    60636062
    60646063        INPUT:
    60656064
     
    60916090        (Constraints generation)
    60926091
    60936092        When the parameter ``constraint_generation`` is enabled (default) the
    6094         following MILP formulation is used to solve the problem::
     6093        following MILP formulation is used to solve the problem:
    60956094
    60966095        .. MATH::
    60976096
     
    61016100
    61026101        As the number of circuits contained in a graph is exponential, this LP
    61036102        is solved through constraint generation. This means that the solver is
    6104         sequentially asked to solved the problem, knowing only a portion of the
     6103        sequentially asked to solve the problem, knowing only a portion of the
    61056104        circuits contained in `G`, each time adding to the list of its
    61066105        constraints the circuit which its last answer had left intact.
    61076106
     
    61446143        In a digraph built from a graph, any edge is replaced by arcs going in
    61456144        the two opposite directions, thus creating a cycle of length two.
    61466145        Hence, to remove all the cycles from the graph, each edge must see one
    6147         of its neighbors removed : a feedback vertex set is in this situation a
     6146        of its neighbors removed: a feedback vertex set is in this situation a
    61486147        vertex cover::
    61496148
    6150             sage: cycle=graphs.CycleGraph(5)
    6151             sage: dcycle=DiGraph(cycle)
     6149            sage: cycle = graphs.CycleGraph(5)
     6150            sage: dcycle = DiGraph(cycle)
    61526151            sage: cycle.vertex_cover(value_only=True)
    61536152            3
    61546153            sage: feedback = dcycle.feedback_vertex_set()
     
    61716170            sage: g = digraphs.RandomDirectedGNP(10,.3)
    61726171            sage: x = g.feedback_vertex_set(value_only = True)
    61736172            sage: y = g.feedback_vertex_set(value_only = True,
    6174             ...            constraint_generation = False)
     6173            ....:          constraint_generation = False)
    61756174            sage: x == y
    61766175            True
    61776176
    6178          Bad algorithm::
     6177        Bad algorithm::
    61796178
    61806179            sage: g = graphs.PetersenGraph()
    61816180            sage: g.feedback_vertex_set(constraint_generation = False)
    61826181            Traceback (most recent call last):
    61836182            ...
    61846183            ValueError: The only implementation available for undirected graphs is with constraint_generation set to True.
    6185          """
     6184        """
    61866185        if not constraint_generation and not self.is_directed():
    6187             raise ValueError("The only implementation available for "+
     6186            raise ValueError("The only implementation available for "
    61886187                             "undirected graphs is with constraint_generation "
    61896188                             "set to True.")
    61906189
     
    62056204            p = MixedIntegerLinearProgram(constraint_generation = True,
    62066205                                          maximization = False)
    62076206
    6208             # An variable for each vertex
     6207            # A variable for each vertex
    62096208            b = p.new_variable(binary = True)
    62106209
    62116210            # Variables are binary, and their coefficient in the objective is 1
    62126211
    6213             p.set_objective( p.sum( b[v] for v in self))
     6212            p.set_objective(p.sum( b[v] for v in self))
    62146213
    62156214            p.solve(log = verbose)
    62166215
     
    62386237                # There is a circuit left. Let's add the corresponding
    62396238                # constraint !
    62406239
    6241                 p.add_constraint( p.sum( b[v] for v in certificate), min = 1)
     6240                p.add_constraint(p.sum(b[v] for v in certificate), min = 1)
    62426241
    62436242                obj = p.solve(log = verbose)
    62446243
     
    62566255        # Ordering-based MILP Implementation #
    62576256        ######################################
    62586257
    6259             p = MixedIntegerLinearProgram(maximization=False, solver=solver)
     6258            p = MixedIntegerLinearProgram(maximization = False, solver = solver)
    62606259
    62616260            b = p.new_variable(binary = True)
    62626261            d = p.new_variable(integer = True)
    62636262            n = self.order()
    62646263
    62656264            # The removed vertices cover all the back arcs ( third condition )
    6266             for (u,v) in self.edges(labels=None):
    6267                 p.add_constraint(d[u]-d[v]+n*(b[u]+b[v]),min=1)
     6265            for (u,v) in self.edges(labels = None):
     6266                p.add_constraint(d[u]-d[v]+n*(b[u]+b[v]), min = 1)
    62686267
    62696268            for u in self:
    6270                 p.add_constraint(d[u],max=n)
     6269                p.add_constraint(d[u], max = n)
    62716270
    62726271            p.set_objective(p.sum([b[v] for v in self]))
    62736272
    62746273            if value_only:
    6275                 return Integer(round(p.solve(objective_only=True, log=verbose)))
     6274                return Integer(round(p.solve(objective_only = True, log = verbose)))
    62766275            else:
    62776276                p.solve(log=verbose)
    6278                 b_sol=p.get_values(b)
    6279 
    6280                 return [v for v in self if b_sol[v]==1]
     6277                b_sol = p.get_values(b)
     6278
     6279                return [v for v in self if b_sol[v] == 1]
    62816280
    62826281    def flow(self, x, y, value_only=True, integer=False, use_edge_labels=True, vertex_bound=False, method = None, solver=None, verbose=0):
    62836282        r"""