Ticket #11944: trac_11944.patch

File trac_11944.patch, 2.3 KB (added by ncohen, 8 years ago)
  • sage/graphs/graph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1319209256 -7200
    # Node ID 297282833ed918a052ed25207f6fc79df5187e00
    # Parent  856eabddb023ed30678c3bc85a6f378914ff68dc
    trac 11944 -- Update Graph.clique_maximum to use MILP
    
    diff --git a/sage/graphs/graph.py b/sage/graphs/graph.py
    a b  
    35693569        from sage.graphs.cliquer import all_max_clique
    35703570        return sorted(all_max_clique(self))
    35713571
    3572     def clique_maximum(self):
     3572    def clique_maximum(self,  algorithm="Cliquer"):
    35733573        """
    35743574        Returns the vertex set of a maximal order complete subgraph.
     3575
     3576        INPUT:
     3577       
     3578        - ``algorithm`` -- the algorithm to be used :
     3579       
     3580           - If ``algorithm = "Cliquer"`` (default) - This wraps the C program
     3581             Cliquer [NisOst2003]_.
     3582       
     3583           - If ``algorithm = "MILP"``, the problem is solved through a Mixed
     3584             Integer Linear Program.
     3585
     3586             (see :class:`MixedIntegerLinearProgram <sage.numerical.mip>`)
    35753587       
    35763588        .. NOTE::
    35773589       
     
    35823594       
    35833595        This function is based on Cliquer [NisOst2003]_.
    35843596           
    3585         EXAMPLES::
     3597        EXAMPLES:
     3598
     3599        Using Cliquer (default)::
    35863600       
    35873601            sage: C=graphs.PetersenGraph()
    35883602            sage: C.clique_maximum()
     
    35913605            sage: C.clique_maximum()
    35923606            [1, 2, 3, 4]
    35933607
     3608        Through a Linear Program::
     3609
     3610            sage: len(C.clique_maximum(algorithm = "MILP"))
     3611            4
     3612
     3613        TESTS:
     3614
     3615        Wrong algorithm::
     3616
     3617            sage: C.clique_maximum(algorithm = "BFS")
     3618            Traceback (most recent call last):
     3619            ...
     3620            NotImplementedError: Only 'MILP' and 'Cliquer' are supported.
    35943621        """
    3595         from sage.graphs.cliquer import max_clique
    3596         return max_clique(self)
     3622        if algorithm=="Cliquer":
     3623            from sage.graphs.cliquer import max_clique
     3624            return max_clique(self)
     3625        elif algorithm == "MILP":
     3626            return self.complement().independent_set(algorithm = algorithm)
     3627        else:
     3628            raise NotImplementedError("Only 'MILP' and 'Cliquer' are supported.")
    35973629
    35983630    def clique_number(self, algorithm="Cliquer", cliques=None):
    35993631        r"""