Exemplo n.º 1
0
        /// <summary>
        /// 从文件打开地铁线路图。
        /// </summary>
        /// <param name="fileName">文件名。</param>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="FileNotFoundException"/>
        public void OpenFromFile(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException();
            }

            m_map = JsonConvert.DeserializeObject <SubwayMap>(File.ReadAllText(fileName));

            for (int i = 0; i < Map.Stations.Count; i++)
            {
                m_stationIds[Map.Stations[i].Name] = i;
            }

            for (int i = 0; i < Map.Lines.Count; i++)
            {
                m_lineIds[Map.Lines[i].Name] = i;
            }

            foreach (SubwayLine line in Map.Lines)
            {
                for (int i = 1; i < line.Path.Count; i++)
                {
                    int from = m_stationIds[line.Path[i - 1]];
                    int to   = m_stationIds[line.Path[i]];
                    Graph.AddEdge(from, to, m_lineIds[line.Name]);
                }
            }
        }
 public SubwayGraph()
 {
     InitializeComponent();
     IntializeStationFlash();
     this.subwayMap            = BackgroundCore.GetBackgroundCore().SubwayMap;
     this.displayRouteUnitList = ((App)App.Current).DisplayRouteUnitList;
 }
Exemplo n.º 3
0
        public static void InitMap()
        {
            map        = LoadMap("BeijingSubwayMap.json");
            stationIds = new Dictionary <string, int>();
            lineIds    = new Dictionary <string, int>();
            graph      = new UndirectedGraph();

            for (int i = 0; i < map.Stations.Count; i++)
            {
                stationIds[map.Stations[i].Name] = i;
            }

            for (int i = 0; i < map.Lines.Count; i++)
            {
                lineIds[map.Lines[i].Name] = i;
            }

            foreach (SubwayLine line in map.Lines)
            {
                for (int i = 1; i < line.Path.Count; i++)
                {
                    int from = stationIds[line.Path[i - 1]];
                    int to   = stationIds[line.Path[i]];
                    graph.AddEdge(from, to, lineIds[line.Name]);
                }
            }
        }
Exemplo n.º 4
0
        public MainWindow()
        {
            InitializeComponent();
            this.subwayMap                         = BackgroundCore.GetBackgroundCore().SubwayMap;
            this.displayRouteUnitList              = ((App)App.Current).DisplayRouteUnitList;
            this.listView_Route.ItemsSource        = displayRouteUnitList;
            this.comboBox_StartStation.ItemsSource = displayStationsName;
            this.comboBox_EndStation.ItemsSource   = displayStationsName;
            ((App)App.Current).IsShortestPlaning   = (bool)radioButton_Shortest.IsChecked;

            BackgroundCore.GetBackgroundCore().SelectFunction(this, ((App)App.Current).Args);
        }
Exemplo n.º 5
0
 private void comboBox_Cities_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (this.comboBox_Cities.SelectedItem != null)
     {
         BackgroundCore.GetBackgroundCore().RefreshMap((string)this.comboBox_Cities.SelectedItem);
         subwayGraph.IsEnabled = true;
         subwayGraph.SetSubwayMap();
         this.subwayMap = BackgroundCore.GetBackgroundCore().SubwayMap;
         displayStationsName.Clear();
         foreach (Station station in subwayMap.Stations)
         {
             displayStationsName.Add(station.Name);
         }
         subwayGraph.InvalidateVisual();
     }
 }
Exemplo n.º 6
0
        public FormMain()
        {
            map        = LoadMap("BeijingSubwayMap.json");
            stationIds = new Dictionary <string, int>();
            lineIds    = new Dictionary <string, int>();
            graph      = new UndirectedGraph();

            for (int i = 0; i < map.Stations.Count; i++)
            {
                stationIds[map.Stations[i].Name] = i;
            }

            for (int i = 0; i < map.Lines.Count; i++)
            {
                lineIds[map.Lines[i].Name] = i;
            }

            foreach (SubwayLine line in map.Lines)
            {
                for (int i = 1; i < line.Path.Count; i++)
                {
                    int from = stationIds[line.Path[i - 1]];
                    int to   = stationIds[line.Path[i]];
                    graph.AddEdge(from, to, lineIds[line.Name]);
                }
            }

            path = new List <Point>();

            InitializeComponent();
            this.BackgroundImageLayout = ImageLayout.Zoom;

            this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
            this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);

            this.pictureBox1.MouseUp    += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
            this.pictureBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseWheel);
        }
 public void SetSubwayMap()
 {
     this.subwayMap = BackgroundCore.GetBackgroundCore().SubwayMap;
 }
Exemplo n.º 8
0
    public static void Main(string[] args)
    {
        SubwayMap s;

        s = new SubwayMap();

        // try-catch block to catch exceptions
        try{
            Console.WriteLine("\nHere are your options:\n1. Add Station\n2. Remove Station\n3. Insert Connection\n4. Remove Connection\n5. Fastest Route between 2 stations\n6. Critical Connections\n7. Print Connections\n8. Print Stations\n9. Exit");
            int choice = Convert.ToInt32(Console.ReadLine());

            Console.Clear();
            while (choice != 9)                 // exit loop when 9 is selected as the option
            {
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter name");
                    s.InsertStation(Console.ReadLine());
                    break;

                case 2:
                    Console.WriteLine("Enter name");
                    s.RemoveStation(Console.ReadLine());
                    break;

                case 3:
                    string name1, name2;
                    Colour c;
                    Console.Write("Enter Station 1 : ");
                    name1 = Console.ReadLine();
                    Console.Write("Enter Station 2: ");
                    name2 = Console.ReadLine();
                    Console.WriteLine("Colour options are;");
                    Console.WriteLine("1.{0}", Colour.BLUE);
                    Console.WriteLine("2.{0}", Colour.GREEN);
                    Console.WriteLine("3.{0}", Colour.RED);
                    Console.WriteLine("4.{0}", Colour.YELLOW);

                    Console.WriteLine("\nPlease enter the colour(number) you want");
                    int p = Convert.ToInt32(Console.ReadLine());

                    switch (p)
                    {
                    case 1:
                        s.InsertConnection(name1, name2, Colour.BLUE);
                        break;

                    case 2:
                        s.InsertConnection(name1, name2, Colour.GREEN);
                        break;

                    case 3:
                        s.InsertConnection(name1, name2, Colour.RED);
                        break;

                    case 4:
                        s.InsertConnection(name1, name2, Colour.YELLOW);
                        break;

                    default:
                        Console.WriteLine("Invalid choice");

                        break;
                    }
                    break;

                case 4:
                    Console.WriteLine("Enter Station 1");
                    name1 = Console.ReadLine();

                    Console.WriteLine("Enter Station 2");
                    name2 = Console.ReadLine();

                    Console.WriteLine("Colour options are;");
                    Console.WriteLine("1.{0}", Colour.BLUE);
                    Console.WriteLine("2.{0}", Colour.GREEN);
                    Console.WriteLine("3.{0}", Colour.RED);
                    Console.WriteLine("4.{0}", Colour.YELLOW);

                    Console.WriteLine("\nPlease enter the colour(number) you wish to remove");
                    p = Convert.ToInt32(Console.ReadLine());

                    switch (p)
                    {
                    case 1:
                        s.RemoveConnection(name1, name2, Colour.BLUE);
                        break;

                    case 2:
                        s.RemoveConnection(name1, name2, Colour.GREEN);
                        break;

                    case 3:
                        s.RemoveConnection(name1, name2, Colour.RED);
                        break;

                    case 4:
                        s.RemoveConnection(name1, name2, Colour.YELLOW);
                        break;

                    default:
                        Console.WriteLine("Invalid choice");

                        break;
                    }

                    break;

                case 5:
                    Console.WriteLine("Enter Origin");
                    name1 = Console.ReadLine();
                    Console.WriteLine("Enter Destination");
                    name2 = Console.ReadLine();
                    s.FastestRoute(name1, name2);
                    break;

                case 6:
                    s.findCritical();
                    break;

                case 7:
                    s.printConnections();
                    break;

                case 8:
                    s.printStations();
                    break;

                case 9:
                    return;

                default:
                    Console.WriteLine("Not a valid option");
                    break;
                }
                Console.WriteLine("\nHere are your options:\n1. Add Station\n2. Remove Station\n3. Insert Connection\n4. Remove Connection\n5. Fastest Route between 2 stations\n6. Critical Connections\n7. Print Connections\n8. Print Stations\n9. Exit");
                choice = Convert.ToInt32(Console.ReadLine());
                Console.Clear();
            }
        }
        catch (FormatException e)
        {
            Console.WriteLine(e.Message);
            Console.ReadLine();
        }
        Console.WriteLine("See you next time!");
        Console.ReadLine();
    }