Ejemplo n.º 1
0
        public LogicManager(MainWindow _window)
        {
            graphToVisualize = null;

            citiesLocations = null;
            citiesConnections = null;

            defaultCitiesLocations = new CitiesLocations();
            defaultCitiesConnections = new CitiesConnections();

            algCitiesLocations = new CitiesLocations();

            startCity = null;
            finalCity = null;

            algSpeed = Alg_Speed.Fast;
            algHeuristic = Heuristic.Distance;

            resources = _window.Resources;
            window = _window;

            graphManager = new GraphManager(window);

            algorithm = null;
            algThread = null;
            IsRunningAlg = false;
        }
        public GraphCity CreateGraph(
            CitiesLocations citiesLocations, CitiesConnections citiesConnections)
        {
            var         graph = new GraphCity();
            Coordinates tempStartCityCoordinates, tempEndCityCoordinates;

            foreach (City city in citiesLocations.locations.Keys)
            {
                citiesLocations.locations.TryGetValue(city, out tempStartCityCoordinates);
                graph.AddVertex(new VertexCity(new City(city),
                                               new Coordinates(tempStartCityCoordinates)));
            }

            List <City> tempCityConnections = new List <City>();

            foreach (City startCity in citiesConnections.connections.Keys)
            {
                citiesLocations.locations.TryGetValue(startCity, out tempStartCityCoordinates);
                citiesConnections.connections.TryGetValue(startCity, out tempCityConnections);

                foreach (City endCity in tempCityConnections)
                {
                    citiesLocations.locations.TryGetValue(endCity, out tempEndCityCoordinates);
                    graph.AddEdge(new EdgeCity(
                                      new VertexCity(new City(startCity), new Coordinates(tempStartCityCoordinates)),
                                      new VertexCity(new City(endCity), new Coordinates(tempEndCityCoordinates))));
                }
            }

            return(graph);
        }
        private bool result;                         // Result of some operation (used in dialogs)

        #endregion Data

        #region Constructors

        /// <summary>
        /// Main constructor
        /// </summary>
        public OpenGraphWindow()
        {
            citiesLocations   = null;
            citiesConnections = null;

            InitializeComponent();
        }
        public GraphCity CreateGraph(
            CitiesLocations citiesLocations, CitiesConnections citiesConnections)
        {
            var graph = new GraphCity();
            Coordinates tempStartCityCoordinates, tempEndCityCoordinates;

            foreach (City city in citiesLocations.locations.Keys)
            {
                citiesLocations.locations.TryGetValue(city, out tempStartCityCoordinates);
                graph.AddVertex(new VertexCity(new City(city),
                    new Coordinates(tempStartCityCoordinates)));
            }

            List<City> tempCityConnections = new List<City>();
            foreach (City startCity in citiesConnections.connections.Keys)
            {
                citiesLocations.locations.TryGetValue(startCity, out tempStartCityCoordinates);
                citiesConnections.connections.TryGetValue(startCity, out tempCityConnections);

                foreach (City endCity in tempCityConnections)
                {
                    citiesLocations.locations.TryGetValue(endCity, out tempEndCityCoordinates);
                    graph.AddEdge(new EdgeCity(
                        new VertexCity(new City(startCity), new Coordinates(tempStartCityCoordinates)),
                        new VertexCity(new City(endCity), new Coordinates(tempEndCityCoordinates))));
                }
            }

            return (graph);
        }
        // Main constructor that initializes everything except window
        public Algorithm(CitiesLocations _citiesLocations, CitiesConnections _citiesConnectios, 
            City _startCity, City _finalCity, Alg_Speed _algSpeed, Heuristic _algHeuristic,
            ref GraphLayoutCity _graphLayout, ref TextBox _textBoxLog,
            ResourceDictionary _resourceDictionary, GraphManager _graphManager)
        {
            citiesLocations = _citiesLocations;
            citiesConnecitons = _citiesConnectios;

            StartCity = _startCity;
            FinalCity = _finalCity;

            AlgSpeed = _algSpeed;
            AlgHeuristic = _algHeuristic;

            graphLayout = _graphLayout;
            textBoxLog = _textBoxLog;
            resourceDictionary = _resourceDictionary;

            IsRunning = false;

            Window = null;

            CanContinue = false;

            graphManager = _graphManager;
        }
Ejemplo n.º 6
0
        // Main constructor that initializes everything except window
        public Algorithm(CitiesLocations _citiesLocations, CitiesConnections _citiesConnectios,
                         City _startCity, City _finalCity, Alg_Speed _algSpeed, Heuristic _algHeuristic,
                         ref GraphLayoutCity _graphLayout, ref TextBox _textBoxLog,
                         ResourceDictionary _resourceDictionary, GraphManager _graphManager)
        {
            citiesLocations   = _citiesLocations;
            citiesConnecitons = _citiesConnectios;

            StartCity = _startCity;
            FinalCity = _finalCity;

            AlgSpeed     = _algSpeed;
            AlgHeuristic = _algHeuristic;

            graphLayout        = _graphLayout;
            textBoxLog         = _textBoxLog;
            resourceDictionary = _resourceDictionary;

            IsRunning = false;

            Window = null;

            CanContinue = false;

            graphManager = _graphManager;
        }
Ejemplo n.º 7
0
        public LogicManager(MainWindow _window)
        {
            graphToVisualize = null;

            citiesLocations   = null;
            citiesConnections = null;

            defaultCitiesLocations   = new CitiesLocations();
            defaultCitiesConnections = new CitiesConnections();

            algCitiesLocations = new CitiesLocations();

            startCity = null;
            finalCity = null;

            algSpeed     = Alg_Speed.Fast;
            algHeuristic = Heuristic.Distance;

            resources = _window.Resources;
            window    = _window;

            graphManager = new GraphManager(window);

            algorithm    = null;
            algThread    = null;
            IsRunningAlg = false;
        }
        private bool result; // Result of some operation (used in dialogs)

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Main constructor
        /// </summary>
        public OpenGraphWindow()
        {
            citiesLocations = null;
            citiesConnections = null;

            InitializeComponent();
        }
Ejemplo n.º 9
0
 // Constructors
 public AAlgorithm(CitiesLocations newCitiesLocations, CitiesConnections newCitiesConnectios, 
     GraphLayout _graphLayout, int _algSpeed)
 {
     citiesLocations = newCitiesLocations;
     citiesConnecitons = newCitiesConnectios;
     algSpeed = _algSpeed;
     graphLayout = _graphLayout;
 }
Ejemplo n.º 10
0
 // Constructors
 public AAlgorithm(CitiesLocations newCitiesLocations, CitiesConnections newCitiesConnectios,
                   GraphLayout _graphLayout, int _algSpeed)
 {
     citiesLocations   = newCitiesLocations;
     citiesConnecitons = newCitiesConnectios;
     algSpeed          = _algSpeed;
     graphLayout       = _graphLayout;
 }
Ejemplo n.º 11
0
            public void Copy(CitiesConnections newCitiesConnections)
            {
                Reset();
                connections = new Dictionary <City, List <City> >();
                List <City> tempCityConnections;

                foreach (City city in newCitiesConnections.connections.Keys)
                {
                    newCitiesConnections.connections.TryGetValue(city, out tempCityConnections);
                    connections.Add(new City(city), new List <City>(tempCityConnections));
                }
            }
Ejemplo n.º 12
0
        /// <summary>
        /// Load graph from the file
        /// </summary>
        /// <param name="graphLayout"></param>
        public void LoadGraphFromFile(ref GraphLayoutCity graphLayout)
        {
            var openGraphWindow = new OpenGraphWindow();

            openGraphWindow.ShowDialog();

            if (openGraphWindow.getResult())
            {
                citiesLocations   = openGraphWindow.getLocations();
                citiesConnections = openGraphWindow.getConnections();

                defaultCitiesLocations.Copy(citiesLocations);
                defaultCitiesConnections.Copy(citiesConnections);

                CreateGraph();
                RefreshGraph(ref graphLayout);
                EstablishGraphCoordinates(ref graphLayout);
            }
        }
Ejemplo n.º 13
0
        public GraphManager graphManager; // Manager for the graph

        #endregion Data

        #region Constructors

        // Null constructor
        public Algorithm()
        {
            citiesLocations   = null;
            citiesConnecitons = null;

            StartCity = null;
            FinalCity = null;

            AlgSpeed     = Alg_Speed.Fast;
            AlgHeuristic = Heuristic.Distance;

            graphLayout        = null;
            textBoxLog         = null;
            resourceDictionary = null;

            IsRunning = false;

            Window = null;

            CanContinue = false;
        }
        private TextBox textBoxLog; // Textbox for log

        #endregion Fields

        #region Constructors

        // Null constructor
        public Algorithm()
        {
            citiesLocations = null;
            citiesConnecitons = null;

            StartCity = null;
            FinalCity = null;

            AlgSpeed = Alg_Speed.Fast;
            AlgHeuristic = Heuristic.Distance;

            graphLayout = null;
            textBoxLog = null;
            resourceDictionary = null;

            IsRunning = false;

            Window = null;

            CanContinue = false;
        }
        /// <summary>
        /// Load the graph if all the input data is chosen correctly
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLoadGraph_Click(object sender, RoutedEventArgs e)
        {
            // Get the files' paths
            string locationsPath   = this.textBoxLocations.Text;
            string connectionsPath = this.textBoxConnections.Text;

            // Load data if the files are not corrupted
            if (FileManager.VerifyLocationsFile(locationsPath) &&
                FileManager.VerifyConnectionsFile(connectionsPath))
            {
                citiesLocations   = FileManager.ReadLocations(locationsPath);
                citiesConnections = FileManager.ReadConnections(connectionsPath);

                result = true;
                this.Close();
            }
            // If file is corrupted
            else
            {
                result = false;
                MessageBox.Show("ERROR! Chosen files are corrupted. Choose another files.",
                                "Path Finder", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 16
0
        /* DESCRIPTION:
         * Read the cities' connections from the file
         */
        public static CitiesConnections ReadConnections(string filePath)
        {
            // Read if the input file exists
            if (File.Exists(filePath))
            {
                CitiesConnections citiesConnections;             // Cities' connections
                StreamReader      inputFile = null;              // Input file
                char[]            delimeter = " ".ToCharArray(); // Delimeter that separates the data in the input file
                string            nextLine;                      // Currently read line from the input file
                string[]          lineData;                      // Data the contains in the read line
                int         tempNumConnections;                  // Number of connections a city has at each iteration
                List <City> tempConnection;                      // List of connected cities at each iteration

                // Exceptions may arise during the file usage
                try
                {
                    // Initialize
                    inputFile         = new StreamReader(filePath);
                    citiesConnections = new CitiesConnections();

                    // Read till the end of the file
                    while ((nextLine = inputFile.ReadLine()) != null)
                    {
                        // If END flag has discovered that we are done
                        if (nextLine.Equals("END"))
                        {
                            return(citiesConnections);
                        }
                        // If no END flag so far, then read the next line
                        else
                        {
                            // Read the next line
                            lineData = nextLine.Split(delimeter);

                            // Number of connections goes second in the line
                            tempNumConnections = Int32.Parse(lineData[1]);
                            // Read the list of connected cities
                            tempConnection = new List <City>();
                            for (int i = 0; i < tempNumConnections; i++)
                            {
                                // Add city to the connections list
                                tempConnection.Add(new City(lineData[i + 2]));
                            }

                            // Add the city and its connection to cities' connections
                            citiesConnections.connections.Add(new City(lineData[0]), tempConnection);
                        }
                    }

                    // Error if no END flag has been discovered. The input file is corrupted.
                    MessageBox.Show("ERROR! File is corrupted.", "Path Finder", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return(null);
                }
                // In case of exception, output its message
                catch (Exception exc)
                {
                    MessageBox.Show(exc.ToString(), "Path Finder", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return(null);
                }
                // Close the input file in the end
                finally
                {
                    if (inputFile != null)
                    {
                        inputFile.Close();
                    }
                }
            }
            // Error if the input file not found
            else
            {
                MessageBox.Show("ERROR! File not found.", "Path Finder", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return(null);
            }
        }
Ejemplo n.º 17
0
        /* DESCRIPTION:
         * Read the cities' connections from the file
         */
        public static CitiesConnections ReadConnections(string filePath)
        {
            // Read if the input file exists
            if (File.Exists(filePath))
            {
                CitiesConnections citiesConnections;   // Cities' connections
                StreamReader inputFile = null;         // Input file
                char[] delimeter = " ".ToCharArray();  // Delimeter that separates the data in the input file
                string nextLine;                       // Currently read line from the input file
                string[] lineData;                     // Data the contains in the read line
                int tempNumConnections;                // Number of connections a city has at each iteration
                List<City> tempConnection;             // List of connected cities at each iteration

                // Exceptions may arise during the file usage
                try
                {
                    // Initialize
                    inputFile = new StreamReader(filePath);
                    citiesConnections = new CitiesConnections();

                    // Read till the end of the file
                    while ((nextLine = inputFile.ReadLine()) != null)
                    {
                        // If END flag has discovered that we are done
                        if (nextLine.Equals("END"))
                        {
                            return (citiesConnections);
                        }
                        // If no END flag so far, then read the next line
                        else
                        {
                            // Read the next line
                            lineData = nextLine.Split(delimeter);

                            // Number of connections goes second in the line
                            tempNumConnections = Int32.Parse(lineData[1]);
                            // Read the list of connected cities
                            tempConnection = new List<City>();
                            for (int i = 0; i < tempNumConnections; i++)
                            {
                                // Add city to the connections list
                                tempConnection.Add(new City(lineData[i + 2]));
                            }

                            // Add the city and its connection to cities' connections
                            citiesConnections.connections.Add(new City(lineData[0]), tempConnection);
                        }
                    }

                    // Error if no END flag has been discovered. The input file is corrupted.
                    MessageBox.Show("ERROR! File is corrupted.", "Path Finder", MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    return (null);
                }
                // In case of exception, output its message
                catch (Exception exc)
                {
                    MessageBox.Show(exc.ToString(), "Path Finder", MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    return (null);
                }
                // Close the input file in the end
                finally
                {
                    if (inputFile != null)
                    {
                        inputFile.Close();
                    }
                }
            }
            // Error if the input file not found
            else
            {
                MessageBox.Show("ERROR! File not found.", "Path Finder", MessageBoxButton.OK,
                        MessageBoxImage.Error);
                return (null);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Load graph from the file
        /// </summary>
        /// <param name="graphLayout"></param>
        public void LoadGraphFromFile(ref GraphLayoutCity graphLayout)
        {
            var openGraphWindow = new OpenGraphWindow();
            openGraphWindow.ShowDialog();

            if (openGraphWindow.getResult())
            {
                citiesLocations = openGraphWindow.getLocations();
                citiesConnections = openGraphWindow.getConnections();

                defaultCitiesLocations.Copy(citiesLocations);
                defaultCitiesConnections.Copy(citiesConnections);

                CreateGraph();
                RefreshGraph(ref graphLayout);
                EstablishGraphCoordinates(ref graphLayout);
            }
        }
        /// <summary>
        /// Load the graph if all the input data is chosen correctly
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLoadGraph_Click(object sender, RoutedEventArgs e)
        {
            // Get the files' paths
            string locationsPath = this.textBoxLocations.Text;
            string connectionsPath = this.textBoxConnections.Text;

            // Load data if the files are not corrupted
            if (FileManager.VerifyLocationsFile(locationsPath) &&
                FileManager.VerifyConnectionsFile(connectionsPath))
            {
                citiesLocations = FileManager.ReadLocations(locationsPath);
                citiesConnections = FileManager.ReadConnections(connectionsPath);

                result = true;
                this.Close();
            }
            // If file is corrupted
            else
            {
                result = false;
                MessageBox.Show("ERROR! Chosen files are corrupted. Choose another files.",
                    "Path Finder", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }