Example #1
0
        private void FindCliques(SymmetricBinaryMatrix m)
        {
            Vector v = new Vector(m.Rows);

            for (int i = 0; i < m.Rows; i++)
            {
                v[i]    = m[i, i];
                m[i, i] = 1;
            }

            List <int> Compsub = new List <int>();
            List <int> All     = new List <int>();

            for (int c = 0; c < m.Rows; c++)
            {
                All.Add(c);
            }

            BkExtend(All, 0, m.Rows, Compsub, m);

            for (int i = 0; i < m.Rows; i++)
            {
                m[i, i] = v[i];
            }
        }
Example #2
0
        //public delegate void ParameterizedThreadStart(SymmetricBinaryMatrix obj);
        public CommCollection(SymmetricBinaryMatrix m, int bmin, List <Comm> Comms)
        {
            new_communities = new List <Comm>();
            new_communities = Comms;

            _communities        = new List <Comm>();
            _communities        = Comms;
            _communitiesOverlap = new Matrix(m.Rows);
            _communitiesOverlap.CopyLabelsFrom(m);
            _minCommSize = bmin;

            Vector Z = Vector.Zero(m.Rows);

            //Thread t = new Thread(delegate() { FindCliques(m); });
            // t.Start();
            //  while (!t.IsAlive) ;
            //  Thread.Sleep(100);
            //  t.Join();

            LoadCommunitiesOverlap();

            //bool addMore = false;
            //for (int i = 0; i < m.Rows; ++i)
            //    if (_cliqueOverlap[i, i] != 0)
            //    {
            //        m.SetRowVector(i, Z);
            //    }
            //    else
            //        addMore = true;

            //if (addMore)
            //{
            //
            //    CliqueCollection cc = new CliqueCollection(m, _minCliqueSize);
            //    foreach (Clique c in cc)
            //    {
            //        if (_cliqueOverlap[c[0], c[0]] == 0)
            //            _cliques.Add(c);
            //    }
            //    LoadCliqueOverlap();
            //}

            _communities.Sort();

            //Thread temp = new Thread(LoadCliqueByCliqueOverlap);
            //temp.Start();
            //FindCliques(m);
            //while (!temp.IsAlive) ;
            //Thread.Sleep(100);
            //temp.Join();


            LoadCommByCommOverlap();
        }
Example #3
0
        private void BkExtend(List <int> old, int ne, int ce, List <int> Compsub, SymmetricBinaryMatrix MBinary)
        {
            int        nod = 0, fixp = -1;
            int        newne, newce, i, j, count, pos = 0, p, s = -1, sel, minnod = ce;
            List <int> new_ = new List <int>();

            for (i = 0; i < ce; i++)
            {
                new_.Add(0);
            }

            // Determine each counter value and look for minimum
            for (i = 0; i < ce && minnod != 0; i++)
            {
                p     = old[i];
                count = 0;

                // Count disconnections
                for (j = ne; j < ce && count < minnod; j++)
                {
                    if (!MBinary.GetValue(p, old[j]))
                    {
                        ++count;

                        // Save position of potential candidate
                        pos = j;
                    }
                }

                // Test new minimum
                if (count < minnod)
                {
                    fixp   = p;
                    minnod = count;
                    if (i < ne)
                    {
                        s = pos;
                    }
                    else
                    {
                        s   = i;
                        nod = 1;
                    }
                }
            }

            // If fixed point initially chosen from candidates then
            // number of disconnections will be preincreased by one

            // Backtrackcycle
            for (nod = minnod + nod; nod >= 1; nod--)
            {
                // Interchange
                p      = old[s];
                old[s] = old[ne];
                sel    = old[ne] = p;

                // Fill new set "not"
                newne = 0;
                for (i = 0; i < ne; i++)
                {
                    if (MBinary.GetValue(sel, old[i]))
                    {
                        new_[newne++] = old[i];
                    }
                }

                // Fill new set "cand"
                newce = newne;
                for (i = ne + 1; i < ce; i++)
                {
                    if (MBinary.GetValue(sel, old[i]))
                    {
                        new_[newce++] = old[i];
                    }
                }

                // Add to Compsub
                Compsub.Add(sel);

                if (newce == 0)
                {
                    StoreClique(new Clique(Compsub, MBinary.Rows));
                }
                else
                {
                    if (newne < newce)
                    {
                        BkExtend(new_, newne, newce, Compsub, MBinary);
                    }
                }

                // Remove from Compsub
                if (Compsub.Count > 0)
                {
                    Compsub.RemoveAt(Compsub.Count - 1);
                }

                // Add to "nod"
                ne++;
                if (nod > 1)
                {
                    // Select a candidate disconnected to the fixed point
                    for (s = ne; MBinary.GetValue(fixp, old[s]); s++)
                    {
                        // Nothing
                    }
                }
            }
        }