Ticket #904: clique_ind_set.patch

File clique_ind_set.patch, 1.9 KB (added by jason, 12 years ago)
  • sage/graphs/graph.py

    diff -r 615b8e8fde7f sage/graphs/graph.py
    a b class Graph(GenericGraph): 
    46964696        return networkx.generators.bipartite.is_bipartite(self._nxg)
    46974697       
    46984698       
    4699 
     4699    ### Substructures
     4700
     4701    def is_clique(self, vertices=None):
     4702        """
     4703        Returns True if the set \code{vertices} is a clique, False if not.  A
     4704        clique is a set of vertices such that there is an edge between
     4705        any two vertices.
     4706
     4707        INPUT:
     4708
     4709        vertices -- Vertices can be a single vertex or an iterable
     4710        container of vertices, e.g. a list, set, graph, file or
     4711        numeric array.  If not passed, defaults to the entire graph.
     4712
     4713        EXAMPLE:
     4714
     4715            sage: graphs.CompleteGraph(4).is_clique([1,2,3])
     4716            True
     4717            sage: graphs.CycleGraph(4).is_clique([1,2])
     4718            True
     4719            sage: graphs.CycleGraph(4).is_clique([1,2,3])
     4720            False
     4721        """
     4722
     4723        subgraph=self.subgraph(vertices).to_simple()
     4724        n=subgraph.order()
     4725        return subgraph.size()==n*(n-1)/2
     4726
     4727
     4728    def is_independent_set(self, vertices=None):
     4729        """
     4730        Returns True if the set \code{vertices} is an independent set, False
     4731        if not.  An independent set is a set of vertices such that
     4732        there is no edge between any two vertices.
     4733
     4734        INPUT:
     4735
     4736        vertices -- Vertices can be a single vertex or an iterable
     4737        container of vertices, e.g. a list, set, graph, file or
     4738        numeric array.  If not passed, defaults to the entire graph.
     4739
     4740
     4741        EXAMPLE:
     4742
     4743            sage: graphs.CycleGraph(4).is_independent_set([1,3])
     4744            True
     4745            sage: graphs.CycleGraph(4).is_independent_set([1,2,3])
     4746            False
     4747        """
     4748
     4749        return self.subgraph(vertices).to_simple().size()==0
     4750
     4751   
    47004752
    47014753    ### Automorphism and isomorphism
    47024754