I want to find all the sets of nodes in a graph which have
edges between all the nodes in the set....in other words I
want to find all the complete sub-graphs in an
un-directional graph: e.g.
If I have this upper-triangular graph (un-directed graph)
where each
edge is denoted by a 1 (0 is no edge) ... e.g. C is
connected to D:
A B C D E F
A X 1 1 0 0 0
B X X 1 0 0 0
C X X X 1 0 1
D X X X X 0 1
E X X X X X 0
F X X X X X X
If I give the algo this matrix, it should return me two
answer sets -> (A,B,C) and (C,D,F).
Am I looking for finding cliques? If so what is the fastest
way known to compute these quickly? Anybody implemented this
on Matlab? What is the most standard easiest way to compute
these sets. I have heard cliques are 3-SAT (NP complete)?
Please help!!
Thanks
Subject: Re: Graph Problem - Finding all sets of nodes forming complete sub-graphs
"Ahmad " <ahmad.humyn@gmail.com> wrote in message
<fvsvde$sb7$1@fred.mathworks.com>...
> Hi there,
>
> I want to find all the sets of nodes in a graph which have
> edges between all the nodes in the set....in other words I
> want to find all the complete sub-graphs in an
> un-directional graph: e.g.
>
> If I have this upper-triangular graph (un-directed graph)
> where each
> edge is denoted by a 1 (0 is no edge) ... e.g. C is
> connected to D:
> A B C D E F
> A X 1 1 0 0 0
> B X X 1 0 0 0
> C X X X 1 0 1
> D X X X X 0 1
> E X X X X X 0
> F X X X X X X
>
> If I give the algo this matrix, it should return me two
> answer sets -> (A,B,C) and (C,D,F).
>
> Am I looking for finding cliques? If so what is the
fastest
> way known to compute these quickly? Anybody implemented
this
> on Matlab? What is the most standard easiest way to
compute
> these sets. I have heard cliques are 3-SAT (NP complete)?
>
> Please help!!
>
> Thanks
I've played with a couple methods for accomplishing this.
Here is a simple reliable one using recursion. I don't
know if these are called "cliques", but thats a word you
mentioned so thats what I called the function.
There are a few ways to clean this up, but I'm just giving
you what I got at this point. I might clean this up and
post it and/or create a better method if one of my other
methods works out.
function out = clique(A)
[i j] = find(A(:,1:end-1));
for n = 1:length(i)
recurse([i(n) j(n)])
end
function recurse(p)
nPts = length(p) + 1;
q = find(all(A(p,max(p)+1:end),1))+max(p);
if ~isempty(q) && length(out)<nPts-2
out{nPts-2} = zeros(0,nPts);
end
for m = 1:length(q)
out{nPts-2}(end+1,1:nPts) = [p q(m)];
recurse([p q(m)])
end
end
end
Subject: Re: Graph Problem - Finding all sets of nodes forming complete sub-graphs
"helper " <spamless@nospam.com> wrote in message <fvtlpa$sd9
$1@fred.mathworks.com>...
> "Ahmad " <ahmad.humyn@gmail.com> wrote in message
> <fvsvde$sb7$1@fred.mathworks.com>...
> > Hi there,
> >
> > I want to find all the sets of nodes in a graph which
have
> > edges between all the nodes in the set....in other
words I
> > want to find all the complete sub-graphs in an
> > un-directional graph: e.g.
> >
> > If I have this upper-triangular graph (un-directed
graph)
> > where each
> > edge is denoted by a 1 (0 is no edge) ... e.g. C is
> > connected to D:
> > A B C D E F
> > A X 1 1 0 0 0
> > B X X 1 0 0 0
> > C X X X 1 0 1
> > D X X X X 0 1
> > E X X X X X 0
> > F X X X X X X
> >
> > If I give the algo this matrix, it should return me two
> > answer sets -> (A,B,C) and (C,D,F).
> >
> > Am I looking for finding cliques? If so what is the
> fastest
> > way known to compute these quickly? Anybody implemented
> this
> > on Matlab? What is the most standard easiest way to
> compute
> > these sets. I have heard cliques are 3-SAT (NP
complete)?
> >
> > Please help!!
> >
> > Thanks
>
> I've played with a couple methods for accomplishing
this.
> Here is a simple reliable one using recursion. I don't
> know if these are called "cliques", but thats a word you
> mentioned so thats what I called the function.
>
> There are a few ways to clean this up, but I'm just
giving
> you what I got at this point. I might clean this up and
> post it and/or create a better method if one of my other
> methods works out.
>
>
> function out = clique(A)
>
> [i j] = find(A(:,1:end-1));
> for n = 1:length(i)
> recurse([i(n) j(n)])
> end
>
> function recurse(p)
> nPts = length(p) + 1;
> q = find(all(A(p,max(p)+1:end),1))+max(p);
> if ~isempty(q) && length(out)<nPts-2
> out{nPts-2} = zeros(0,nPts);
> end
> for m = 1:length(q)
> out{nPts-2}(end+1,1:nPts) = [p q(m)];
> recurse([p q(m)])
> end
> end
>
> end
I accidentally deleted the first line of code. It should
be:
function out = clique(A)
out = {};
...
Also, any occurrance of max(p) should simply be p(end)
Subject: Re: Graph Problem - Finding all sets of nodes forming complete sub-graphs
"helper " <spamless@nospam.com> wrote in message
<fvuor1$sse$1@fred.mathworks.com>...
> "helper " <spamless@nospam.com> wrote in message <fvtlpa$sd9
> $1@fred.mathworks.com>...
> > "Ahmad " <ahmad.humyn@gmail.com> wrote in message
> > <fvsvde$sb7$1@fred.mathworks.com>...
> > > Hi there,
> > >
> > > I want to find all the sets of nodes in a graph which
> have
> > > edges between all the nodes in the set....in other
> words I
> > > want to find all the complete sub-graphs in an
> > > un-directional graph: e.g.
> > >
> > > If I have this upper-triangular graph (un-directed
> graph)
> > > where each
> > > edge is denoted by a 1 (0 is no edge) ... e.g. C is
> > > connected to D:
> > > A B C D E F
> > > A X 1 1 0 0 0
> > > B X X 1 0 0 0
> > > C X X X 1 0 1
> > > D X X X X 0 1
> > > E X X X X X 0
> > > F X X X X X X
> > >
> > > If I give the algo this matrix, it should return me two
> > > answer sets -> (A,B,C) and (C,D,F).
> > >
> > > Am I looking for finding cliques? If so what is the
> > fastest
> > > way known to compute these quickly? Anybody implemented
> > this
> > > on Matlab? What is the most standard easiest way to
> > compute
> > > these sets. I have heard cliques are 3-SAT (NP
> complete)?
> > >
> > > Please help!!
> > >
> > > Thanks
> >
> > I've played with a couple methods for accomplishing
> this.
> > Here is a simple reliable one using recursion. I don't
> > know if these are called "cliques", but thats a word you
> > mentioned so thats what I called the function.
> >
> > There are a few ways to clean this up, but I'm just
> giving
> > you what I got at this point. I might clean this up and
> > post it and/or create a better method if one of my other
> > methods works out.
> >
> >
> > function out = clique(A)
> >
> > [i j] = find(A(:,1:end-1));
> > for n = 1:length(i)
> > recurse([i(n) j(n)])
> > end
> >
> > function recurse(p)
> > nPts = length(p) + 1;
> > q = find(all(A(p,max(p)+1:end),1))+max(p);
> > if ~isempty(q) && length(out)<nPts-2
> > out{nPts-2} = zeros(0,nPts);
> > end
> > for m = 1:length(q)
> > out{nPts-2}(end+1,1:nPts) = [p q(m)];
> > recurse([p q(m)])
> > end
> > end
> >
> > end
>
> I accidentally deleted the first line of code. It should
> be:
>
> function out = clique(A)
> out = {};
> ...
>
> Also, any occurrance of max(p) should simply be p(end)
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.