6

I'm trying to find all independent vertex sets for a given graph. Note that they may not be maximal independent sets.

There is a function in Mathematica called FindIndependentVertexSet. But I noticed that it actually gives the maximum sets, not just the independent ones.

In the reference there is also IndependentVertexSetQ that test vertices. BUT it does not test for maximal sets.

The first question is if such behaviour is intended. I mean that one function works for Maximal sets and the other does not.

Another question is whether I have to manually find the independent sets or there is already a built in function.

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Andrew S.
  • 465
  • 3
  • 7
  • 1
    You may be interested in the "Background & Context" section of the documentation of FindIndependentVertexSet. Among other things, it states that: "Not-necessarily-maximal independent vertex sets cannot be found directly using FindIndependentVertexSet but can be simplistically enumerated by taking the union over the collection of all subsets of all maximal independent vertex sets." – MarcoB Feb 16 '16 at 22:11
  • Unfo, this is said only in online version. Or at least not in 10.3.| Thanks for this note. – Andrew S. Feb 16 '16 at 23:44

1 Answers1

5

Here's a closely related question:

Based on Ralph Dratman's solution there, we can write (with slight modifications):

findAllCliques[g_] := 
 DeleteDuplicates[Sort /@ Join @@ Subsets /@ FindClique[g, Infinity, All]]

findAllIndependentVertexSets[g_] := findAllCliques@GraphComplement[g]

This will often be faster than the naive approach in the documentation that MarcoB mentioned.


Alternatively, the IGraph/M package has a function to find all (not just maximal) independent vertex sets.

?IGIndependentVertexSets

IGIndependentVertexSets[graphs] finds all independent vertex sets of graph.
IGIndependentVertexSets[graphs, {min, max}]
IGIndependentVertexSets[graphs, max]
IGIndependentVertexSets[graphs, {n}]

You can restrict the search to independent vertex sets between sizes min and max, or up to max, or size precisely n.

?IGMaximalIndependentVertexSets

IGMaximalIndependentVertexSets[graph] finds the maximal independent vertex sets of graph.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 1
    Disclosure: I'm the author of IGraph/M. – Szabolcs Feb 16 '16 at 22:18
  • Thanks! This works, should spend some time to understand HOW it works.

    Will as well check your package.

    However, should the in-built function work the way it does atm? As the name and description implies that it finds NOT the maximum set. Should this be reported?

    – Andrew S. Feb 16 '16 at 23:28
  • Edit: NVM the previous question, as MarcoB noted about this being said in Backgroung section of reference. – Andrew S. Feb 16 '16 at 23:36
  • @AndrewS. I see no point in reporting it. It is clearly by design, and the behaviour is clearly documented. They just made the function name a bit shorter by leaving out "maximal". It's the same with FindCliques. – Szabolcs Feb 16 '16 at 23:40
  • They as well added a note that Marco showed. But as I said in another comment, it's not in the 10.3 version (at least).

    Thanks for help!

    – Andrew S. Feb 16 '16 at 23:49
  • @AndrewS. That's strange, I can see it in the builtin documentation. I have 10.3.1. Do you have documentation updates disabled in preferences? – Szabolcs Feb 17 '16 at 08:11
  • @AndrewS. Just to clarify: I was annoyed by this too when I discovered it first with FindClique. I was looking to get all cliques. At that time they didn't even have the Background & Context section in the documentation. You are right about the inconsistency with IndependentVertexSetQ. And you can report it to support. My point was just that it seems clear that these naming choices are deliberate, and I don't think reporting it will change anything. – Szabolcs Feb 17 '16 at 10:13
  • Yeah, seems like updates are disabled on this PC. I've stumbled upon a couple other inconsistencies like this in other parts as well. But I think you are right though. (Will try to report this nevertheless). THanks again for help! – Andrew S. Feb 17 '16 at 13:27