Exemplo n.º 1
0
        private void SettingsForm_Load(object sender, EventArgs e)
        {
            //graphCreator1 = new GraphViewer(

            try
            {
                 throw new NotImplementedException();

                Point p1 = new Point(20, 20, Settings1.Default.NodeSize,0, Color.Black);
                Point p2 = new Point(40, 40, Settings1.Default.NodeSize,1, Color.Black);

                Route r1 = new Route(new int[] { 0, 1 });
                Route r2 = new Route(new int[] { 0, 1 });
                Route r3 = new Route(new int[] { 0, 1 });
                Graph g = new Graph(new System.Collections.ArrayList() { p1, p2 }, new Route[] { r1, r2, r3 });

                //graphCreator1 = new GraphViewer(g) as GraphCreator;
                //graphCreator1.points.Add(p1);
                //graphCreator1.points.Add(p2);

                /*graphCreator1.edges.Add(new Edge(p1, p2, 0, 0));
                graphCreator1.edges.Add(new Edge(p1, p2, 1, 1));
                graphCreator1.edges.Add(new Edge(p1, p2, 2, 2));
                 */

                //graphCreator1.r
                //graphCreator1.Redraw(true);
                //graphCreator1.DrawRoutes(new Route[] { r1, r2, r3 });
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }
Exemplo n.º 2
0
 public void DrawRoutes(Route[] routes)
 {
     foreach (Route r in routes)
     {
         DrawRoute(r,false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Рисует одно ребро из маршрута
        /// </summary>
        /// <param name="r"></param>
        public void DrawRouteEdge(Route r,Point p1, Point p2)
        {
            if (r.rs.Contains(" " + p1.N + " " + p2.N + " "))
            {
                // прямой порядок

                for (int i = 0; i < r.Length; i++)
                {
                    if (r.nodes[i] == p1.N)
                    {
                        DrawDirectEdge(p1, p2, r.color);
                    }
                }
            }

            if (r.rs.Contains(" " + p2.N + " " + p1.N + " "))
            {
                // обратный порядок

                for (int i = 0; i < r.Length; i++)
                {
                    if (r.nodes[i] == p2.N)
                    {
                        DrawDirectEdge(p2, p1, r.color);
                    }
                }

            }
        }
Exemplo n.º 4
0
        public void DrawRoute(Route r, bool clear)
        {
            //Graphics g = this.CreateGraphics();
            if (clear) g.Clear(Color.White);
            DrawNodes(true);

            for (int i = 0; i < r.Length - 1; i++)
            {
                DrawEdge((Point)points[r.nodes[i]], (Point)points[r.nodes[i + 1]],r.color);
            }
        }
Exemplo n.º 5
0
 public void RouteVisit(Route r)
 {
     Console.WriteLine("у {0} route = {1}",this.n, r.n);
     route = r;
 }
Exemplo n.º 6
0
        public bool NewRouteValue(Route r, int value)
        {
            if (routesValues.Keys.Contains(r)){
                // уже есть с таким ключом

                if (routesValues[r]>value){

                    routesValues[r] = value;

                    route = r;
                    len = value;
                }
                return false;
            }
            else {
                routesValues.Add(r,value);
                if (routesValues.Values.Min() > value)
                {
                    Console.WriteLine("\tНо найдено меньшее значение");
                    route = r;
                    len = value;
                }
                return true;
            }
        }
Exemplo n.º 7
0
        public Graph(ArrayList p, Route[] r)
        {
            points = p;
                routes = r;
                int n = p.Count;
                nodes = new Node[n];

                for (int i = 0; i < n; i++)
                {
                    nodes[i] = new Node(this, i);
                }

                for (int i = 0; i < r.Length; i++)
                {
                    for (int j = 0; j < r[i].Length - 1; j++)
                    {
                        // инициализация смежных

                        Node n1 = nodes[r[i].nodes[j]];
                        Node n2 = nodes[r[i].nodes[j + 1]];

                        n1.AddAdj(r[i].nodes[j + 1], i);
                        n2.AddAdj(r[i].nodes[j], i);

                        try
                        {
                            Console.WriteLine("node{0}.routes.Add({1})", n1.n, r[i]);
                            n1.routes.Add(r[i]);
                            n1.routesValues.Add(r[i], int.MaxValue/2);

                        }

                        catch (Exception ex) { Console.WriteLine(ex.Message); }

                        try {
                            Console.WriteLine("node{0}.routes.Add({1})", n2.n, r[i]);
                            n2.routes.Add(r[i]);
                            n2.routesValues.Add(r[i], int.MaxValue/2);
                        }

                        catch (Exception ex) { Console.WriteLine(ex.Message); }
                        /*
                        if (j == r[i].Length - 2)
                        {
                            for (int h = 0; h < r.Length; h++)
                            {
                                for (int g = 0; g < r[h].nodes.Length - 1; g++)
                                {

                                    if (r[h].nodes[g] == r[i].nodes[j])
                                    {
                                        nodes[r[h].nodes[g + 1]].routesValues.Add(GetRoute(h), int.MaxValue / 2);
                                    }
                                }
                            }
                            //r[i].nodes[j]
                        }*/

                    }
                    try
                    {
                        for (int h = 0; h < r.Length; h++)
                        {
                            for (int g = 0; g < r[h].nodes.Length - 1; g++)
                            {

                                if (r[h].nodes[g] == r[i].nodes[r[i].Length - 1])
                                {
                                    nodes[r[h].nodes[g + 1]].routesValues.Add(GetRoute(i), int.MaxValue / 2);
                                }
                            }
                        }
                    }
                    catch { }

                    nodes[r[i].nodes[0]].routesValues[r[i]] = 0;

                }
        }
Exemplo n.º 8
0
        private void endRoute_Click(object sender, EventArgs e)
        {
            try
            {
                Route r = new Route(graphcreator.crs);
                //routes.Add(r);
                Status.Routes.Add(r);
                Status.myRoutes.Add(r);
            #if DEBUG
                MessageBox.Show(graphcreator.crs);
            #endif
                graphcreator.ResetRouteInfo();

                RefreshRoutesAndPoints();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }