Exemplo n.º 1
0
 private void button10_Click(object sender, EventArgs e)//next
 {
     if (test.MoveNext())
     {
         SetLastOperationState(true, "Moved next");
     }
     else
     {
         SetLastOperationState(false, "Cant move");
     }
     DrawIncremental();
 }
Exemplo n.º 2
0
        Color ColorRoute(Misc.Vertex <int> curr, Color inpc) // inpc, income predicted color
        {
            Color newpc = Color.OrangeRed;                   // some mess to make compiler happy

            if (inpc == Color.White)
            {
                newpc = Color.Black;
            }
            else
            {
                newpc = Color.White;
            }
            List <Color> currlist = new List <Color>();
            Color        back;
            int          i = 0;

            if (curr._inner != Color.Gray)
            {
                return(curr._inner);
            }
            curr._inner = Color.Red;
            g.CreateIterator(curr.id);
            while (g.IsValid())
            {
                Misc.Vertex <int> newcurr;
                newcurr = g.GetVertex(g.Current());    // get linked vertex
                back    = ColorRoute(newcurr, newpc);
                if (back == Color.Red)
                {
                    newcurr._inner = newpc; back = newpc;
                }
                currlist.Add(back);
                g.CreateIterator(curr.id);
                for (int j = 0; j < i; j++)
                {
                    g.MoveNext();
                }
                g.MoveNext();
                i++;
            }

            if (currlist.Count > 0)
            {
                bool iswhite = (currlist[0] == Color.White);
                for (int j = 0; j < currlist.Count; j++)
                {
                    if (currlist[j] == Color.Red)
                    {
                        continue;
                    }
                    bool localcc = (currlist[j] == Color.White);
                    if (localcc != iswhite)
                    {
                        throw new Exception("Cant find solution");
                    }
                }
                if (iswhite)
                {
                    curr._inner = Color.Black;
                }
                else
                {
                    curr._inner = Color.White;
                }
            }
            else
            {
                curr._inner = inpc;
            }
            //  check bypassed, things are looking good, now able to color current vertex
            return(curr._inner);
        }
Exemplo n.º 3
0
        //-- internal part of class code

        // vertex data filelds mapping:    distance-->value;


        void MapGraph()                // perfoms distance mapping
        {
            Misc.Vertex <int> cv, vcv; // current vertex, very current vertex xD
            for (int i = 0; i < g.VertexCount; i++)
            {
                cv = g.GetVertex(i);
                if (cv.id == basevertex)
                {
                    cv.value = 0;
                }
                else
                {
                    cv.value = 100500;                                        // asuming this is infinity
                }
            }
            // second stage: distance calculating

            for (int inu = 0; inu < g.VertexCount; inu++)// inu - Index is Never Used
            {
                for (int i = 0; i < g.VertexCount; i++)
                {
                    g.CreateIterator(i);
                    cv = g.GetVertex(i);

                    while (g.IsValid())
                    {
                        vcv = g.GetVertex(g.Current());

                        if (cv.value + g.GetEdgeWeight(cv.id, vcv.id) < vcv.value)
                        {
                            vcv.value = cv.value + g.GetEdgeWeight(cv.id, vcv.id);
                        }
                        g.MoveNext();
                    }
                }
            }
            // now its time for 3rd stage: "searching for route cheats"

            for (int inu = 0; inu < g.VertexCount; inu++)// inu - Index is Never Used
            {
                for (int i = 0; i < g.VertexCount; i++)
                {
                    g.CreateIterator(i);
                    cv = g.GetVertex(i);

                    while (g.IsValid())
                    {
                        vcv = g.GetVertex(g.Current());

                        if (cv.value + g.GetEdgeWeight(cv.id, vcv.id) < vcv.value)
                        {
                            bg = true;
                        }
                        g.MoveNext();
                    }
                }
            }
            if (bg)
            {
                throw new Exception("Result may be incorrect due to negative weight function");
            }
        }