# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1272442371 -7200
# Node ID 60485faf0c71d23dae5639b1bb140e3413404e69
# Parent  ef74a6ed21179df343f658c015d7b068bb28c0f3
trac 8798 : remove duplicates of feedback_vertex_set and feedback_edge_set from generic_graph.py

diff -r ef74a6ed2117 -r 60485faf0c71 sage/graphs/generic_graph.py
--- a/sage/graphs/generic_graph.py	Fri Apr 16 10:22:00 2010 -0700
+++ b/sage/graphs/generic_graph.py	Wed Apr 28 10:12:51 2010 +0200
@@ -3343,234 +3343,6 @@
         else:
             raise ValueError("Only two algorithms are available : Cliquer and MILP.")
 
-    def feedback_edge_set(self,value_only=False):
-        r"""
-        Computes the minimum feedback edge set of a digraph 
-        ( also called feedback arc set ).
-
-        The minimum feedback edge set of a digraph is a set of edges
-        that intersect all the circuits of the digraph.
-        Equivalently, a minimum feedback arc set of a DiGraph is a set
-        `S` of arcs such that the digraph `G-S` is acyclic.
-
-        For more informations, see 
-        ( http://en.wikipedia.org/wiki/Feedback_arc_set )
-
-        INPUT :
-
-        - ``value_only`` (boolean) --
-            - When set to ``True``, only the minimum 
-              cardinal of a minimum edge set is 
-              returned.
-
-            - When set to ``False``, the ``Set`` of edges
-              of a minimal edge set is returned.
-
-        This problem is solved using Linear Programming, which certainly
-        is not the best way and will have to be updated. The program solved
-        is the following :
-
-        .. MATH:
-            \mbox{Minimize : }&\sum_{(u,v)\in G} b_{(u,v)}\\ 
-            \mbox{Such that : }&\\ 
-            &\forall v\in G, \sum_{i\in [0,\dots,n-1]}x_{v,i}=1\\ 
-            &\forall i\in [0,\dots,n-1], \sum_{v\in G}x_{v,i}=1\\ 
-            &\forall v\in G,\sum_{i\in [0,\dots,n-1]} ix_{v,i}=d_v\\
-            &\forall (u,v)\in G, d_u-d_v+nb_{(u,v)}\geq 0\\
-                        
-        An explanation :
-
-        An acyclic digraph can be seen as a poset, and every poset has
-        a linear extension. This means that in any acyclic digraph 
-        the vertices can be ordered with a total order `<` in such a way 
-        that if `(u,v)\in G`, then `u<v`.
-
-        Thus, this linear program is built in order to assign to each vertex
-        `v` an unique number `d_v\in [0,\dots,n-1]` such that if there exists
-        an edge `(u,v)\in G` such that `d_v<d_u`, then the edge `(u,v)` is
-        removed (`\Rightarrow x_{(u,v)}=1`).
-
-        The number of edges removed is then minimized, which is 
-        the objective.
-
-        EXAMPLE :
-
-        If the digraph is created from a graph, and hence is symmetric 
-        ( if `uv` is an edge, then `vu` is an edge too ), then
-        obviously the cardinality of its feedback arc set is the number
-        of edges in the first graph ::
-
-            sage: cycle=graphs.CycleGraph(5)
-            sage: dcycle=DiGraph(cycle)
-            sage: cycle.size() 
-            5
-            sage: dcycle.feedback_edge_set(value_only=True)    # optional - requires GLPK or CBC
-            5.0
-        
-        And in this situation, for any edge `uv` of the first graph, `uv` of `vu`
-        is in the returned feedback arc set::
-
-           sage: g = graphs.RandomGNP(5,.3)
-           sage: dg = DiGraph(g)
-           sage: feedback = dg.feedback_edge_set()             # optional - requires GLPK or CBC
-           sage: (u,v,l) = g.edge_iterator().next()
-           sage: (u,v) in feedback or (v,u) in feedback        # optional - requires GLPK or CBC
-           True
-        """
-        
-        from sage.numerical.mip import MixedIntegerLinearProgram
-        
-        p=MixedIntegerLinearProgram(maximization=False)
-        
-        b=p.new_variable()
-        x=p.new_variable(dim=2)
-        d=p.new_variable()
-        n=self.order()
-        N=range(n)
-
-        # First and second constraints
-        for v in self:
-            p.add_constraint(sum([x[v][i] for i in N]),min=1,max=1)
-
-        for i in N:
-            p.add_constraint(sum([x[v][i] for v in self]),min=1,max=1)
-        
-        # Definition of d_v
-        for v in self:
-            p.add_constraint(sum([i*x[v][i] for i in N])-d[v],max=0,min=0)
-
-        # The removed vertices cover all the back arcs ( third condition )
-        for (u,v) in self.edges(labels=None):
-            p.add_constraint(d[u]-d[v]+n*(b[(u,v)]),min=0)
-
-        p.set_binary(b)
-        p.set_binary(x)
-
-        p.set_objective(sum([b[(u,v)] for (u,v) in self.edges(labels=None)]))
-
-        if value_only:
-            return p.solve(objective_only=True)
-        else:
-            p.solve()
-
-            b_sol=p.get_values(b)
-
-            from sage.sets.set import Set
-            return Set([(u,v) for (u,v) in self.edges(labels=None) if b_sol[(u,v)]==1])
-
-    def feedback_vertex_set(self,value_only=False):
-        r"""
-        Computes the minimum feedback vertex set of a digraph.
-
-        The minimum feedback vertex set of a digraph is a set of vertices
-        that intersect all the circuits of the digraph.
-        Equivalently, a minimum feedback vertex set of a DiGraph is a set
-        `S` of vertices such that the digraph `G-S` is acyclic.
-
-        For more informations, see 
-        ( http://en.wikipedia.org/wiki/Feedback_vertex_set )
-
-        INPUT :
-
-        - ``value_only`` (boolean) --
-            - When set to ``True``, only the minimum 
-              cardinal of a minimum vertex set is 
-              returned.
-
-            - When set to ``False``, the ``Set`` of vertices
-              of a minimal feedback vertex set is returned.
-
-        This problem is solved using Linear Programming, which certainly
-        is not the best way and will have to be replaced by a better algorithm.
-        The program solved is the following :
-
-        .. MATH:
-            \mbox{Minimize : }&\sum_{v\in G} b_v\\ 
-            \mbox{Such that : }&\\ 
-            &\forall v\in G, \sum_{i\in [0,\dots,n-1]}x_{v,i}=1\\ 
-            &\forall i\in [0,\dots,n-1], \sum_{v\in G}x_{v,i}=1\\ 
-            &\forall v\in G,\sum_{i\in [0,\dots,n-1]} ix_{v,i}=d_v\\
-            &\forall (u,v)\in G, d_u-d_v+nb_u+nb_v\geq 0\\
-                        
-        A brief explanation :
-
-        An acyclic digraph can be seen as a poset, and every poset has
-        a linear extension. This means that in any acyclic digraph 
-        the vertices can be ordered with a total order `<` in such a way 
-        that if `(u,v)\in G`, then `u<v`.
-        Thus, this linear program is built in order to assign to each vertex
-        `v` an unique number `d_v\in [0,\dots,n-1]` such that if there exists
-        an edge `(u,v)\in G` such that `d_v<d_u`, then either `u` is removed
-        (`\Rightarrow b_u=1`) or `v` is removed (`\Rightarrow b_v=1`).
-        The number of vertices removed is then minimized, which is 
-        the objective.
-
-        EXAMPLE:
-
-        In a digraph built from a graph, any edge is replaced by arcs going
-        in the two opposite directions, thus creating a cycle of length two.
-        Hence, to remove all the cycles from the graph, each edge must see
-        one of its neighbors removed : a feedback vertex set is in this
-        situation a vertex cover ::
-
-            sage: cycle=graphs.CycleGraph(5)
-            sage: dcycle=DiGraph(cycle)
-            sage: cycle.vertex_cover(value_only=True)         # optional - requires GLPK or CBC
-            3
-            sage: feedback = dcycle.feedback_vertex_set()     # optional - requires GLPK or CBC
-            sage: feedback.cardinality()                      # optional - requires GLPK or CBC
-            3
-            sage: (u,v,l) = cycle.edge_iterator().next()
-            sage: u in feedback or v in feedback              # optional - requires GLPK or CBC
-            True
-            
-        For a circuit, the minimum feedback arc set is clearly `1` ::
-
-            sage: circuit = digraphs.Circuit(5)
-            sage: circuit.feedback_vertex_set(value_only=True) == 1    # optional - requires GLPK or CBC
-            True
-        """
-        
-        from sage.numerical.mip import MixedIntegerLinearProgram
-        
-        p=MixedIntegerLinearProgram(maximization=False)
-        
-        b=p.new_variable()
-        x=p.new_variable(dim=2)
-        d=p.new_variable()
-        n=self.order()
-        N=range(n)
-
-        # First and second constraints
-        for v in self:
-            p.add_constraint(sum([x[v][i] for i in N]),min=1,max=1)
-
-        for i in N:
-            p.add_constraint(sum([x[v][i] for v in self]),min=1,max=1)
-        
-        # Definition of d_v
-        for v in self:
-            p.add_constraint(sum([i*x[v][i] for i in N])-d[v],max=0,min=0)
-
-        # The removed vertices cover all the back arcs ( third condition )
-        for (u,v) in self.edges(labels=None):
-            p.add_constraint(d[u]-d[v]+n*(b[u]+b[v]),min=0)
-
-        p.set_binary(b)
-        p.set_binary(x)
-
-        p.set_objective(sum([b[v] for v in self]))
-
-        if value_only:
-            return p.solve(objective_only=True)
-        else:
-            p.solve()
-            b_sol=p.get_values(b)
-
-            from sage.sets.set import Set
-            return Set([v for v in self if b_sol[v]==1])
-
-
     def max_cut(self,value_only=True,use_edge_labels=True, vertices=False):
         r"""
         Returns a maximum edge cut of the graph
