예제 #1
0
 public Cvor(int c, Cvor p, int d)
 {
     this.c      = c;
     this.parent = p;
     this.dubina = d;
     matched     = false;
     this.susedi = new List <Cvor>();
 }
예제 #2
0
 public bool contains(Cvor c)
 {
     if (c.c == a.c || c.c == b.c)
     {
         return(true);
     }
     return(false);
 }
예제 #3
0
 public Cvor vratiPara(Cvor a)
 {
     foreach (Grana g in grane)
     {
         if (g.contains(a) && g.matched)
         {
             return(g.vratidrugi(a));
         }
     }
     return(null);
 }
예제 #4
0
 public Cvor vrati(Cvor v)
 {
     foreach (Cvor c in cvorovi)
     {
         if (c.c == v.c)
         {
             return(c);
         }
     }
     return(null);
 }
예제 #5
0
 public bool contains(Cvor v)
 {
     foreach (Cvor c in cvorovi)
     {
         if (c.c == v.c)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #6
0
 public void Add(Cvor v1)
 {
     foreach (Grana gr in g.grane)
     {
         if (gr.contains(v1) && cvorovi.Contains(gr.vratidrugi(v1)))
         {
             grane.Add(gr);
             v1.parent = gr.vratidrugi(v1);
         }
     }
     v1.dubina = dubina;
     cvorovi.Add(v1);
 }
예제 #7
0
 public Cvor vratidrugi(Cvor c)
 {
     if (this.contains(c))
     {
         if (c.c == a.c)
         {
             return(b);
         }
         else
         {
             return(a);
         }
     }
     return(null);
 }
예제 #8
0
        static void Blossom(Graf g)
        {
            List <Cvor> slobodni = g.cvorovi;

            while (slobodni.Count > 0)
            {
                Cvor r = slobodni.First <Cvor>();
                slobodni.Remove(r);
                Queue <Cvor> q = new Queue <Cvor>();
                q.Enqueue(r);
                Drvo t = new Drvo(g);
                while (q.Count > 0)
                {
                    bool uslov = true;
                    Cvor v     = q.Dequeue();
                    foreach (Cvor w in v.susedi)
                    {
                        if (!t.contains(w) && w.matched)
                        {
                            t.Add(w);
                            t.Add(t.g.vratiPara(w));
                            q.Enqueue(t.g.vratiPara(w));
                            if (uslov)
                            {
                                t.dubina++;
                                uslov = false;
                            }
                        }
                        else if (t.contains(w) && t.dubina == t.vrati(w).dubina)
                        {
                            q.Enqueue(t.nciklus(w, t.vrati(w)));
                        }
                        else if (slobodni.Contains(w))
                        {
                            t.Add(w);
                            slobodni.Remove(w);
                            t.procvetaj();
                        }
                    }
                }
            }
            g.stampaj();
        }
예제 #9
0
        public void skupi(List <Cvor> ciklus, int koren, int super, List <Grana> gr)
        {
            prviPut();
            pup.Push(new Pupoljak(koren, super, ciklus, gr));
            foreach (Cvor v in ciklus)
            {
                if (cvorovi.Contains(v))
                {
                    cvorovi.Remove(v);
                    g.cvorovi.Remove(v);
                }
            }
            Cvor ss = new Cvor(super);

            cvorovi.Add(ss);
            g.cvorovi.Add(ss);
            foreach (Grana gg in gr)
            {
                foreach (Cvor cc in ciklus)
                {
                    Grana asdf = new Grana(ss, gg.vratidrugi(cc));
                    if (gg.contains(cc) && !grane.Contains(asdf))
                    {
                        grane.Add(asdf);
                        g.grane.Add(asdf);
                    }
                }
            }
            foreach (Grana gg in gr)
            {
                if (grane.Contains(gg))
                {
                    grane.Remove(gg);
                    g.grane.Remove(gg);
                }
            }
        }
예제 #10
0
 public new void Add(Cvor c)
 {
     this.cvorovi.Add(c);
 }
예제 #11
0
 public Grana(Cvor a, Cvor b)
 {
     this.a  = a;
     this.b  = b;
     matched = false;
 }
예제 #12
0
 public void procvetaj()
 {
     while (pup.Count > 0)
     {
         Pupoljak    temp  = pup.Pop();
         List <Cvor> p1    = new List <Cvor>();
         List <Cvor> p2    = new List <Cvor>();
         bool        uslov = true;
         foreach (Cvor cc in put.cvorovi)
         {
             if (cc.c != temp.super)
             {
                 if (uslov)
                 {
                     p1.Add(cc);
                 }
                 else
                 {
                     p2.Add(cc);
                 }
             }
         }
         ;
         List <Cvor> util = new List <Cvor>();
         foreach (Grana grn in temp.grane)
         {
             if (grn.contains(p2[0]))
             {
                 util.Add(grn.vratidrugi(p2[0]));
             }
         }
         int  max = -1;
         Cvor uu  = new Cvor(max);
         foreach (Cvor cc in util)
         {
             if (max < cc.dubina)
             {
                 max = cc.dubina;
                 uu  = cc;
             }
         }
         int smer = 0;
         foreach (Grana grn in temp.grane)
         {
             if (grn.contains(uu) && grn.matched)
             {
                 smer = temp.cvorovi.IndexOf(uu) - temp.cvorovi.IndexOf(grn.vratidrugi(uu));
             }
         }
         List <Cvor> util2 = new List <Cvor>();
         int         i     = temp.cvorovi.IndexOf(uu);
         while (uu.c != temp.koren)
         {
             util2.Add(uu);
             i += smer;
             if (i < 0)
             {
                 i = temp.cvorovi.Count - 1;
             }
             else if (i == temp.cvorovi.Count)
             {
                 i = 0;
             }
             uu = temp.cvorovi[i];
         }
         util2.Reverse();
         put.prilagodi(p1, util2, p2);
         put.invert();
     }
 }
예제 #13
0
        public Cvor nciklus(Cvor a, Cvor b)
        {
            List <Cvor> r  = new List <Cvor>();
            List <Cvor> p1 = new List <Cvor>();

            p1.Add(a);
            List <Cvor> p2 = new List <Cvor>();

            p2.Add(b);
            bool u1 = true;
            bool u2 = true;

            while (u1 || u2)
            {
                if (p1.Last <Cvor>().parent != null)
                {
                    p1.Add(p1.Last <Cvor>().parent);
                }
                else
                {
                    u1 = false;
                }
                if (p2.Last <Cvor>().parent != null)
                {
                    p2.Add(p2.Last <Cvor>().parent);
                }
                else
                {
                    u2 = false;
                }
            }
            List <Cvor> presek = new List <Cvor>();

            foreach (Cvor v1 in p1)
            {
                if (p2.Contains(v1))
                {
                    presek.Add(v1);
                }
            }
            int  max = -1;
            Cvor zr  = presek[0];

            foreach (Cvor v1 in presek)
            {
                if (max < v1.c)
                {
                    max = v1.c;
                    zr  = v1;
                }
            }
            List <Cvor> putt = new List <Cvor>();

            putt.Add(a);
            for (int i = 0; i < p1.Count; i++)
            {
                if (p1[i].dubina > zr.dubina)
                {
                    putt.Add(p1[i]);
                }
            }
            for (int i = p2.Count - 1; i > 0; i++)
            {
                if (p2[i].dubina > zr.dubina)
                {
                    putt.Add(p2[i]);
                }
            }
            putt.Add(b);
            List <Grana> gt1 = new List <Grana>();

            foreach (Grana gr in grane)
            {
                foreach (Cvor cc in putt)
                {
                    if (gr.contains(cc) && !gt1.Contains(gr))
                    {
                        gt1.Add(gr);
                    }
                }
            }
            max = -1;
            foreach (Cvor cc in cvorovi)
            {
                if (cc.c > max)
                {
                    max = cc.c;
                }
            }
            skupi(putt, zr.c, max + 1, gt1);
            return(new Cvor(max + 1));
        }