コード例 #1
0
        void solve()
        {
            Color lastc = Color.Black;

            Misc.Vertex <int> curr;

            for (int i = 0; i < g.VertexCount; i++)// initialize vertices colors
            {
                curr        = g.GetVertex(i);
                curr._inner = Color.Gray;
            }
            for (int i = 0; i < g.VertexCount; i++)
            {
                lastc = Color.Black;
                curr  = g.GetVertex(i);
                ColorRoute(curr, Color.White);
            }
        }
コード例 #2
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");
            }
        }