GreedyClique - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

GraphTheory

 GreedyClique
 find clique using greedy algorithm
 GreedyIndependentSet
 find independent set using greedy algorithm

 Calling Sequence GreedyClique(G, opts) GreedyIndependentSet(G, opts)

Parameters

 G - graph opts - (optional) equation of the form iterations = n or thresholds = t, where n is a positive integer and t is a non-empty list of numerical values in the closed interval $\left[0,1\right]$

Description

 • GreedyClique attempts to find a large clique of the graph G. It returns the set of vertex labels corresponding to the clique it finds.
 • GreedyIndependentSet attempts to find a large independent set of the graph G. It returns the set of vertex labels corresponding to the independent set it finds. It does this by calling GreedyClique on the complement of G.
 • The problem of finding a maximum clique for a graph is NP-complete, meaning that no polynomial-time algorithm is presently known that can return a clique of the largest possible size for a given graph. An exhaustive search is implemented in the MaximumClique command, which will take an exponential time on some graphs. By contrast, the algorithm implemented in GreedyClique takes polynomial time, but it may return a clique that is not of maximum size.
 • The algorithm is a so-called GRASP process, which stands for greedy randomized adaptive search procedure. It consists of an outer loop, of which each iteration tries to find a large clique; the procedure then returns the largest clique found. A single iteration of this outer loop consists of two steps:
 – In step 1, the procedure finds a clique that is maximal, i.e., a clique that cannot be extended to a larger clique. (This is different from a maximum clique, as discussed in a bullet point above.) This is done in a loop, by starting with the empty set of vertices, and then in each iteration, selecting a vertex to add that is connected to all previously selected vertices. Among all such vertices connected to all previously selected vertices, let $d$ and $\mathrm{D}$ be the minimal and maximal degrees; the procedure will select a vertex whose degree is at least $d+\mathrm{\theta }\left(\mathrm{D}-d\right)$, where $\mathrm{\theta }$ is a numerical constant between 0 and 1 that is a parameter for the algorithm. The value of $\mathrm{\theta }$ can be controlled by the thresholds option: its value is a list of such constants, one for each iteration of the outer loop.
 – In step 2, the process tries to find a larger clique by finding a vertex it can remove from the clique and replace by two vertices that can be added. It continues doing this (and extending the clique to a maximal clique, if necessary) until no such change can be made anymore.
 • As explained above, you can increase or decrease the number of iterations of the outer loop by passing the thresholds parameter, specifying the values for the parameter $\mathrm{\theta }$ in each iteration. If the thresholds parameter is not specified, then the number of iterations of the outer loop is specified by the iterations parameter; the thresholds used are then equally spread out from 0 to 1 - they are the numbers $\frac{i}{\mathrm{iterations}-1}$, as $i$ ranges from 0 to $\mathrm{iterations}-1$. If the iterations parameter is also not specified, its default value is 5, so the thresholds used are by default $\left[0,\frac{1}{4},\frac{1}{2},\frac{3}{4},1\right]$. If both the thresholds and iterations parameters are specified, then the iterations parameter is ignored.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{with}\left(\mathrm{RandomGraphs}\right):$

Here we have a random graph that is quite dense. Each possible edge of this graph with 1000 vertices is included with probability 0.95.

 > $\mathrm{G1}≔\mathrm{RandomGraph}\left(1000,0.95\right):$
 > $\mathrm{c1}≔\mathrm{GreedyClique}\left(\mathrm{G1}\right)$
 ${\mathrm{c1}}{≔}\left\{{25}{,}{26}{,}{42}{,}{86}{,}{96}{,}{105}{,}{115}{,}{150}{,}{154}{,}{166}{,}{172}{,}{176}{,}{177}{,}{191}{,}{204}{,}{206}{,}{207}{,}{219}{,}{229}{,}{230}{,}{236}{,}{238}{,}{243}{,}{262}{,}{296}{,}{304}{,}{313}{,}{314}{,}{316}{,}{324}{,}{336}{,}{355}{,}{356}{,}{366}{,}{375}{,}{385}{,}{391}{,}{399}{,}{406}{,}{412}{,}{420}{,}{422}{,}{431}{,}{432}{,}{442}{,}{462}{,}{474}{,}{482}{,}{487}{,}{488}{,}{494}{,}{506}{,}{518}{,}{522}{,}{525}{,}{526}{,}{552}{,}{557}{,}{565}{,}{572}{,}{584}{,}{593}{,}{595}{,}{604}{,}{622}{,}{627}{,}{659}{,}{668}{,}{673}{,}{688}{,}{696}{,}{704}{,}{716}{,}{727}{,}{759}{,}{794}{,}{803}{,}{808}{,}{818}{,}{845}{,}{851}{,}{862}{,}{902}{,}{906}{,}{917}{,}{924}{,}{926}{,}{937}{,}{944}{,}{965}{,}{984}{,}{985}{,}{986}\right\}$ (1)
 > $\mathrm{IsClique}\left(\mathrm{G1},\mathrm{c1}\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{numelems}\left(\mathrm{c1}\right)$
 ${93}$ (3)

Theoretical considerations show that the expected number of cliques of size $k$ in this graph is $\left(\genfrac{}{}{0}{}{1000}{k}\right){0.95}^{\left(\genfrac{}{}{0}{}{k}{2}\right)}$. This number dips below 1 around $k=120$, which suggests that the maximum clique should be of size around 120.

We try the same thing with a very sparse graph. We specify that Maple should run 50 iterations instead of the normal 5.

 > $\mathrm{G2}≔\mathrm{RandomGraph}\left(3000,0.01\right):$
 > $\mathrm{c2}≔\mathrm{GreedyClique}\left(\mathrm{G2},\mathrm{iterations}=50\right)$
 ${\mathrm{c2}}{≔}\left\{{260}{,}{1557}{,}{2405}\right\}$ (4)
 > $\mathrm{IsClique}\left(\mathrm{G2},\mathrm{c2}\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{numelems}\left(\mathrm{c2}\right)$
 ${3}$ (6)

The same argument as above, now with the formula $\left(\genfrac{}{}{0}{}{3000}{k}\right){0.01}^{\left(\genfrac{}{}{0}{}{k}{2}\right)}$, suggests that the maximum clique in this graph should be of size about 4.

Finally, we try a regular graph.

 > $\mathrm{G3}≔\mathrm{RandomRegularGraph}\left(100,30\right)$
 ${\mathrm{G3}}{≔}{\mathrm{Graph 1: an undirected graph with 100 vertices and 1500 edge\left(s\right)}}$ (7)

By setting the infolevel entry for GreedyClique (or for GraphTheory), we can see what happens for each iteration. We specify different thresholds to see if this has any effect: we run twenty iterations with threshold 0 (pick any suitable vertex) and twenty with threshold 1 (pick only vertices with the maximal degree).

 > ${\mathrm{infolevel}}_{\mathrm{GreedyClique}}≔4$
 ${{\mathrm{infolevel}}}_{{\mathrm{GreedyClique}}}{≔}{4}$ (8)
 > $\mathrm{c3}≔\mathrm{GreedyClique}\left(\mathrm{G3},\mathrm{thresholds}=\left[0$20,1$20\right]\right)$
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 3 with parameter 0
 GreedyClique: step 2: clique grown to size 4
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 6
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 4
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 4
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 6
 GreedyClique: step 1: found clique of size 6 with parameter 0
 GreedyClique: step 2: clique grown to size 6
 GreedyClique: step 1: found clique of size 4 with parameter 0
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 4
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 4
 GreedyClique: step 1: found clique of size 5 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 3 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 6 with parameter 1
 GreedyClique: step 2: clique grown to size 6
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 4
 GreedyClique: step 1: found clique of size 3 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 6 with parameter 1
 GreedyClique: step 2: clique grown to size 6
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 4
 GreedyClique: step 1: found clique of size 4 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 3 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 GreedyClique: step 1: found clique of size 5 with parameter 1
 GreedyClique: step 2: clique grown to size 5
 ${\mathrm{c3}}{≔}\left\{{38}{,}{45}{,}{50}{,}{54}{,}{60}{,}{87}\right\}$ (9)

We can also find an independent set in the same graph.

 > $\mathrm{i3}≔\mathrm{GreedyIndependentSet}\left(\mathrm{G3},\mathrm{iterations}=8\right)$
 GreedyClique: step 1: found clique of size 9 with parameter 0
 GreedyClique: step 2: clique grown to size 11
 GreedyClique: step 1: found clique of size 10 with parameter 1/7
 GreedyClique: step 2: clique grown to size 10
 GreedyClique: step 1: found clique of size 9 with parameter 2/7
 GreedyClique: step 2: clique grown to size 11
 GreedyClique: step 1: found clique of size 9 with parameter 3/7
 GreedyClique: step 2: clique grown to size 12
 GreedyClique: step 1: found clique of size 11 with parameter 4/7
 GreedyClique: step 2: clique grown to size 12
 GreedyClique: step 1: found clique of size 11 with parameter 5/7
 GreedyClique: step 2: clique grown to size 11
 GreedyClique: step 1: found clique of size 9 with parameter 6/7
 GreedyClique: step 2: clique grown to size 10
 GreedyClique: step 1: found clique of size 11 with parameter 1
 GreedyClique: step 2: clique grown to size 11
 ${\mathrm{i3}}{≔}\left\{{6}{,}{9}{,}{20}{,}{30}{,}{35}{,}{49}{,}{65}{,}{68}{,}{71}{,}{77}{,}{89}{,}{91}\right\}$ (10)

We show the resulting clique and independent set.

 > $\mathrm{HighlightSubgraph}\left(\mathrm{G3},\mathrm{InducedSubgraph}\left(\mathrm{G3},\mathrm{c3}\right),\mathrm{edgestylesheet}=\left[\mathrm{color}=\mathrm{red}\right],\mathrm{vertexstylesheet}=\left[\mathrm{color}=\mathrm{red}\right]\right)$
 > $\mathrm{HighlightSubgraph}\left(\mathrm{G3},\mathrm{InducedSubgraph}\left(\mathrm{G3},\mathrm{i3}\right),\mathrm{edgestylesheet}=\left[\mathrm{color}=\mathrm{green}\right],\mathrm{vertexstylesheet}=\left[\mathrm{color}=\mathrm{green}\right]\right)$
 > $\mathrm{DrawGraph}\left(\mathrm{G3},\mathrm{style}=\mathrm{spring}\right)$

References

 T.A. Feo, M.G.C. Resende, and S.H. Smith. A greedy randomized adaptive search procedure for maximum independent set. Operations Research, 42:860–878, 1994.

Compatibility

 • The GraphTheory[GreedyClique] and GraphTheory[GreedyIndependentSet] commands were introduced in Maple 2019.
 • For more information on Maple 2019 changes, see Updates in Maple 2019.