/// <summary>
 /// Apply City to Explore style to many cities
 /// </summary>
 /// <param name="cities"></param>
 /// <param name="graphLayout"></param>
 public void MarkAllCitiesToExplore(List <City> cities, GraphLayoutCity graphLayout)
 {
     foreach (City city in cities)
     {
         MarkCityToExplore(city, graphLayout);
     }
 }
 /// <summary>
 /// Apply City to Explore style to many cities
 /// </summary>
 /// <param name="cities"></param>
 /// <param name="graphLayout"></param>
 public void MarkAllCitiesToExplore(List<City> cities, GraphLayoutCity graphLayout)
 {
     foreach (City city in cities)
     {
         MarkCityToExplore(city, graphLayout);
     }
 }
        /// <summary>
        /// Start A-star algorithm in a separate thread
        /// </summary>
        /// <param name="graphLayout"></param>
        /// <param name="richTextBoxLog"></param>
        /// <param name="window"></param>
        public void StartAlgorithm(ref GraphLayoutCity graphLayout, ref TextBox richTextBoxLog,
                                   MainWindow window)
        {
            // If already running
            if (IsRunningAlg)
            {
                algorithm.WaitMutex.WaitOne();
                algorithm.CanContinue = true;
                algorithm.WaitMutex.ReleaseMutex();
            }
            // If not, then start a new thread
            else
            {
                algorithm = new Algorithm(citiesLocations, citiesConnections,
                                          startCity.City, finalCity.City, algSpeed, algHeuristic,
                                          ref graphLayout, ref richTextBoxLog, resources, graphManager);
                // Set window and create a mutex
                algorithm.Window    = window;
                algorithm.WaitMutex = new Mutex();

                // Null the start and end cities
                startCity = null;
                finalCity = null;

                // Create and start the thread
                algThread = new Thread(new ThreadStart(algorithm.RunAlgThread));
                algThread.SetApartmentState(ApartmentState.STA);
                algThread.Start();

                // Allow the algorithm to continue
                algorithm.WaitMutex.WaitOne();
                algorithm.CanContinue = true;
                algorithm.WaitMutex.ReleaseMutex();
            }
        }
 /// <summary>
 /// Unmark edges
 /// </summary>
 /// <param name="startNode"></param>
 /// <param name="endNodes"></param>
 /// <param name="graphLayout"></param>
 public void UnmarkEdges(City startNode, List <City> endNodes, GraphLayoutCity graphLayout)
 {
     foreach (City endNode in endNodes)
     {
         UnmarkEdge(startNode, endNode, graphLayout);
     }
 }
 /// <summary>
 /// Unmark list of cities
 /// </summary>
 /// <param name="cities"></param>
 /// <param name="graphLayout"></param>
 public void UnmarkCities(List <City> cities, GraphLayoutCity graphLayout)
 {
     foreach (City city in cities)
     {
         UnmarkCity(city, graphLayout);
     }
 }
        // 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;
        }
 /// <summary>
 /// Apply Checked City style to many cities
 /// </summary>
 /// <param name="cities"></param>
 /// <param name="graphLayout"></param>
 public void MarkAllCheckedCities(List <City> cities, GraphLayoutCity graphLayout)
 {
     foreach (City city in cities)
     {
         MarkCheckedCity(city, graphLayout);
     }
 }
        /// <summary>
        /// Updates the vertex internal information.
        /// Maintains consistency between the vertex's position on the
        /// screen and ins internal information.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="graphLayout"></param>
        public void UpdateVertexInfo(ref VertexCity vertex, ref GraphLayoutCity graphLayout)
        {
            if (vertex != null)
            {
                // Get the vertex control
                VertexControl vertexControl = graphLayout.GetVertexControl(vertex);

                // If we could find the verex control
                if (vertexControl != null)
                {
                    double tempXCoord, tempYCoord;

                    // Get the vertex screen coordinates
                    tempXCoord = GraphCanvas.GetX(vertexControl);
                    tempYCoord = GraphCanvas.GetY(vertexControl);

                    // Update the internal information if the coordinates
                    // are in range from 0 to 800
                    if ((tempXCoord > 0) && (tempXCoord < 800) &&
                        (tempYCoord > 0) && (tempYCoord < 800))
                    {
                        vertex.CityCoordinates.setX((int)tempXCoord);
                        vertex.CityCoordinates.setY((int)tempYCoord);
                    }

                    // Set the new screen coordinates
                    GraphCanvas.SetX(vertexControl, vertex.CityCoordinates.getX());
                    GraphCanvas.SetY(vertexControl, vertex.CityCoordinates.getY());
                }
            }
        }
Example #9
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;
        }
 // Mark many cities
 /// <summary>
 /// Apply Found City style to many cities
 /// </summary>
 /// <param name="cities"></param>
 /// <param name="graphLayout"></param>
 public void MarkAllFoundCities(List<City> cities, GraphLayoutCity graphLayout)
 {
     foreach (City city in cities)
     {
         MarkFoundCity(city, graphLayout);
     }
 }
 /// <summary>
 /// Apply style to the list of cities
 /// </summary>
 /// <param name="cities">
 /// List of the target cities
 /// </param>
 /// <param name="style">
 /// The style to apply
 /// </param>
 /// <param name="graphLayout">
 /// Graph layout
 /// </param>
 public void MarkCities(List <City> cities, Style style, GraphLayoutCity graphLayout)
 {
     // For each city apply the chosen style
     foreach (City city in cities)
     {
         MarkCity(city, style, graphLayout);
     }
 }
        // Mark path

        /// <summary>
        /// Mark path that is presented by a sequential list of cities
        /// </summary>
        /// <param name="path"></param>
        /// <param name="graphLayout"></param>
        public void MarkPath(List <City> path, GraphLayoutCity graphLayout)
        {
            for (int i = 0; i < path.Count - 1; i++)
            {
                MarkPathCity(path[i], graphLayout);
                MarkPathCity(path[i + 1], graphLayout);
                MarkEdge(path[i], path[i + 1], graphLayout);
            }
        }
 /// <summary>
 /// Apply style to the city
 /// </summary>
 /// <param name="city">
 /// Target city
 /// </param>
 /// <param name="style">
 /// The style to apply
 /// </param>
 /// <param name="graphLayout">
 /// Graph layout
 /// </param>
 public void MarkCity(City city, Style style, GraphLayoutCity graphLayout)
 {
     // Set style through the UI windows dispatcher
     window.Dispatcher.Invoke(
         new Action(delegate()
     {
         SetStyle(new VertexCity(city), graphLayout, style);
     }),
         DispatcherPriority.Normal, null);
 }
        /// <summary>
        /// Apply the style to the vertex. Must be called from the UI
        /// thread because it does not use a deispatcher.
        /// </summary>
        /// <param name="vertex">
        /// Tartget vertex for the style
        /// </param>
        /// <param name="graphLayout">
        /// Graph layout
        /// </param>
        /// <param name="style">
        /// The style to apply
        /// </param>
        public void SetStyle(VertexCity vertex, GraphLayoutCity graphLayout,
                             Style style)
        {
            // Get vertex control and update style if possible
            VertexControl vertexControl = graphLayout.GetVertexControl(vertex);

            if (vertexControl != null)
            {
                vertexControl.Style = style;
            }
        }
 /// <summary>
 /// Apply Best City style
 /// </summary>
 /// <param name="city"></param>
 /// <param name="graphLayout"></param>
 public void MarkBestCity(City city, GraphLayoutCity graphLayout)
 {
     Style style = null;
     window.Dispatcher.Invoke(
         new Action(delegate()
         {
             style = (Style)window.Resources["BestCityStyle"];
             SetStyle(new VertexCity(city), graphLayout, style);
         }),
             DispatcherPriority.Normal, null);
 }
        /// <summary>
        /// Unmark all cities
        /// </summary>
        /// <param name="graphLayout"></param>
        public void UnmarkAllCities(GraphLayoutCity graphLayout)
        {
            Style style = null;

            window.Dispatcher.Invoke(
                new Action(delegate()
            {
                style = (Style)window.Resources["DefaultCityStyle"];
                SetStyleToAll(graphLayout, style);
            }),
                DispatcherPriority.Normal, null);
        }
        /// <summary>
        /// Apply Found City style
        /// </summary>
        /// <param name="city"></param>
        /// <param name="graphLayout"></param>
        public void MarkFoundCity(City city, GraphLayoutCity graphLayout)
        {
            Style style = null;

            window.Dispatcher.Invoke(
                new Action(delegate()
            {
                style = (Style)window.Resources["FoundCityStyle"];
                SetStyle(new VertexCity(city), graphLayout, style);
            }),
                DispatcherPriority.Normal, null);
        }
 /// <summary>
 /// Verify that the data passed into the algorithm has not been changed.
 /// Is not used. UI is disabled instead.
 /// </summary>
 /// <param name="graphLayout"></param>
 /// <returns></returns>
 private bool VerifyAlgorithmDataConsistency(GraphLayoutCity graphLayout)
 {
     CaptureCurrentGraph(graphLayout);
     if (!citiesLocations.Equals(algCitiesLocations))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        /// <summary>
        /// Unmark edge
        /// </summary>
        /// <param name="startNode"></param>
        /// <param name="endNode"></param>
        /// <param name="graphLayout"></param>
        public void UnmarkEdge(City startNode, City endNode, GraphLayoutCity graphLayout)
        {
            EdgeCity edge = new EdgeCity(
                new VertexCity(startNode), new VertexCity(endNode));

            graphLayout.Dispatcher.Invoke(
                new Action(delegate()
            {
                graphLayout.RemoveHighlightFromEdge(edge);
            }),
                DispatcherPriority.Normal, null);
        }
        /// <summary>
        /// Update the vertex information in the locations file and also update the
        /// vertex internal information
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="graphLayout"></param>
        public void UpdateVertexInfo(VertexCity vertex, ref GraphLayoutCity graphLayout)
        {
            graphManager.UpdateVertexInfo(ref vertex, ref graphLayout);

            if (vertex != null)
            {
                Coordinates tempCityCoordinates;
                if (citiesLocations.locations.TryGetValue(vertex.City, out tempCityCoordinates))
                {
                    tempCityCoordinates.setX(vertex.CityCoordinates.getX());
                    tempCityCoordinates.setY(vertex.CityCoordinates.getY());
                }
            }
        }
 /// <summary>
 /// Reset the graph to the default graph, which was originally downloaded from the
 /// file.
 /// </summary>
 /// <param name="graphLayout"></param>
 public void ResetGraphToDefault(ref GraphLayoutCity graphLayout)
 {
     if (NoDelete())
     {
         ResetGraph(ref graphLayout);
     }
     else
     {
         RecoverGraphData();
         CreateGraph();
         RefreshGraph(ref graphLayout);
         EstablishGraphCoordinates(ref graphLayout);
     }
 }
        /// <summary>
        /// Highlight an edge
        /// </summary>
        /// <param name="startNode">
        /// Edge start node
        /// </param>
        /// <param name="endNode">
        /// Edge end node
        /// </param>
        /// <param name="graphLayout"></param>
        public void MarkEdge(City startNode, City endNode, GraphLayoutCity graphLayout)
        {
            // Create an EdgeCity object
            EdgeCity edge = new EdgeCity(
                new VertexCity(startNode), new VertexCity(endNode));

            // Highligh the edge
            graphLayout.Dispatcher.Invoke(
                new Action(delegate()
            {
                graphLayout.HighlightEdge(edge, null);
            }),
                DispatcherPriority.Normal, null);
        }
        /// <summary>
        /// Apply the style to all vertices in the graph. Must be called from the UI
        /// thread because it does not use a deispatcher.
        /// </summary>
        /// <param name="graphLayout">
        /// Graph layout
        /// </param>
        /// <param name="style">
        /// The style to apply
        /// </param>
        public void SetStyleToAll(GraphLayoutCity graphLayout, Style style)
        {
            VertexControl vertexControl;

            // Apply style for each vertex in the graph
            foreach (VertexCity vertex in graphLayout.Graph.Vertices)
            {
                vertexControl = graphLayout.GetVertexControl(vertex);
                if (vertexControl != null)
                {
                    vertexControl.Style = style;
                }
            }
        }
        /// <summary>
        ///  Unmark all edges
        /// </summary>
        /// <param name="graphLayout"></param>
        public void UnmarkAllEdges(GraphLayoutCity graphLayout)
        {
            EdgeControl edgeControl = new EdgeControl();

            foreach (EdgeCity edge in graphLayout.HighlightedEdges)
            {
                graphLayout.Dispatcher.Invoke(
                    new Action(delegate()
                {
                    graphLayout.RemoveHighlightFromEdge(edge);
                }),
                    DispatcherPriority.Normal, null);
            }
        }
        /// <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>
        /// Mark the city as Final City on the screen
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="graphLayout"></param>
        public void MarkFinalCity(VertexCity vertex, ref GraphLayoutCity graphLayout)
        {
            if (finalCity != null)
            {
                Style oldStyle = (Style)resources["DefaultCityStyle"];
                graphManager.SetStyle(finalCity, graphLayout, oldStyle);
            }

            if ((startCity != null) && (startCity.Equals(vertex)))
            {
                startCity = null;
            }

            finalCity = vertex;

            Style newStyle = (Style)resources["FinalCityStyle"];

            graphManager.SetStyle(vertex, graphLayout, newStyle);
        }
        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;
        }
Example #28
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;
        }
        /// <summary>
        /// Get the data about the current graph's
        /// node, edges and their coordinates. Save this
        /// data to citiesLocations and citiesConnections.
        /// </summary>
        public void GetCurrentGraph(GraphLayoutCity graphLayout,
                                    ref CitiesLocations citiesLocations)
        {
            VertexControl vertexControl = new VertexControl();
            Coordinates   tempVertexCoordinates;
            int           tempXCoord;
            int           tempYCoord;

            foreach (VertexCity vertex in graphLayout.Graph.Vertices)
            {
                // Get the vertex data and a vertex control
                citiesLocations.locations.TryGetValue(vertex.City, out tempVertexCoordinates);
                vertexControl = graphLayout.GetVertexControl(vertex);

                // Get current coordinates
                tempXCoord = (int)GraphCanvas.GetX(vertexControl);
                tempYCoord = (int)GraphCanvas.GetY(vertexControl);

                // Update the information
                tempVertexCoordinates.setX(tempXCoord);
                tempVertexCoordinates.setY(tempYCoord);
            }
        }
        /// <summary>
        /// Set the nodes coordinates to the coordinates from the
        /// locations file.
        /// </summary>
        /// <param name="graphLayout">
        /// Graph layout
        /// </param>
        /// <param name="citiesLocations">
        /// Locations file that has the desired coordinates for the graph's vertices
        /// </param>
        public void EstablishCoordinates(ref GraphLayoutCity graphLayout,
                                         CitiesLocations citiesLocations)
        {
            VertexControl vertexControl = new VertexControl();
            Coordinates   tempVertexCoordinates;

            if (citiesLocations != null)
            {
                foreach (VertexCity vertex in graphLayout.Graph.Vertices)
                {
                    // Get the coordinates from the locations file
                    citiesLocations.locations.TryGetValue(vertex.City, out tempVertexCoordinates);

                    // Update the vertex data
                    vertex.CityCoordinates.setX(tempVertexCoordinates.getX());
                    vertex.CityCoordinates.setY(tempVertexCoordinates.getY());

                    // Update the vertex position on the screen
                    vertexControl = graphLayout.GetVertexControl(vertex);
                    GraphCanvas.SetX(vertexControl, vertex.CityCoordinates.getX());
                    GraphCanvas.SetY(vertexControl, vertex.CityCoordinates.getY());
                }
            }
        }
 /// <summary>
 /// Reset the vertecies locations to the default locations.
 /// </summary>
 /// <param name="graphLayout"></param>
 public void ResetGraph(ref GraphLayoutCity graphLayout)
 {
     ResetCitiesLocations();
     EstablishGraphCoordinates(ref graphLayout);
 }
        /// <summary>
        /// Updates the vertex internal information.
        /// Maintains consistency between the vertex's position on the
        /// screen and ins internal information.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="graphLayout"></param>
        public void UpdateVertexInfo(ref VertexCity vertex, ref GraphLayoutCity graphLayout)
        {
            if (vertex != null)
            {
                // Get the vertex control
                VertexControl vertexControl = graphLayout.GetVertexControl(vertex);

                // If we could find the verex control
                if (vertexControl != null)
                {
                    double tempXCoord, tempYCoord;

                    // Get the vertex screen coordinates
                    tempXCoord = GraphCanvas.GetX(vertexControl);
                    tempYCoord = GraphCanvas.GetY(vertexControl);

                    // Update the internal information if the coordinates
                    // are in range from 0 to 800
                    if ((tempXCoord > 0) && (tempXCoord < 800) &&
                        (tempYCoord > 0) && (tempYCoord < 800))
                    {
                        vertex.CityCoordinates.setX((int)tempXCoord);
                        vertex.CityCoordinates.setY((int)tempYCoord);
                    }

                    // Set the new screen coordinates
                    GraphCanvas.SetX(vertexControl, vertex.CityCoordinates.getX());
                    GraphCanvas.SetY(vertexControl, vertex.CityCoordinates.getY());
                }
            }
        }
 /// <summary>
 /// Apply the style to the vertex. Must be called from the UI 
 /// thread because it does not use a deispatcher.
 /// </summary>
 /// <param name="vertex">
 /// Tartget vertex for the style
 /// </param>
 /// <param name="graphLayout">
 /// Graph layout
 /// </param>
 /// <param name="style">
 /// The style to apply
 /// </param>
 public void SetStyle(VertexCity vertex, GraphLayoutCity graphLayout,
     Style style)
 {
     // Get vertex control and update style if possible
     VertexControl vertexControl = graphLayout.GetVertexControl(vertex);
     if (vertexControl != null)
     {
         vertexControl.Style = style;
     }
 }
        /// <summary>
        /// Set the nodes coordinates to the coordinates from the 
        /// locations file.
        /// </summary>
        /// <param name="graphLayout">
        /// Graph layout
        /// </param>
        /// <param name="citiesLocations">
        /// Locations file that has the desired coordinates for the graph's vertices
        /// </param>
        public void EstablishCoordinates(ref GraphLayoutCity graphLayout,
            CitiesLocations citiesLocations)
        {
            VertexControl vertexControl = new VertexControl();
            Coordinates tempVertexCoordinates;

            if (citiesLocations != null)
            {
                foreach (VertexCity vertex in graphLayout.Graph.Vertices)
                {
                    // Get the coordinates from the locations file
                    citiesLocations.locations.TryGetValue(vertex.City, out tempVertexCoordinates);

                    // Update the vertex data
                    vertex.CityCoordinates.setX(tempVertexCoordinates.getX());
                    vertex.CityCoordinates.setY(tempVertexCoordinates.getY());

                    // Update the vertex position on the screen
                    vertexControl = graphLayout.GetVertexControl(vertex);
                    GraphCanvas.SetX(vertexControl, vertex.CityCoordinates.getX());
                    GraphCanvas.SetY(vertexControl, vertex.CityCoordinates.getY());
                }
            }
        }
 /// <summary>
 /// Set the vertices coordinates according to the locations file
 /// </summary>
 /// <param name="graphLayout"></param>
 public void EstablishGraphCoordinates(ref GraphLayoutCity graphLayout)
 {
     graphManager.EstablishCoordinates(ref graphLayout, citiesLocations);
 }
 /// <summary>
 /// Delete city from the locations and the connections files. Also
 /// delete it from the screen.
 /// </summary>
 /// <param name="cityToDelete"></param>
 /// <param name="graphLayout"></param>
 public void DeleteCity(VertexCity cityToDelete, ref GraphLayoutCity graphLayout)
 {
     graphManager.DeleteCity(cityToDelete, ref graphLayout);
     DeleteCityFromData(cityToDelete.City);
 }
        /// <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>
 /// Delete the city and all connected edges
 /// </summary>
 /// <param name="cityToDelete">
 /// City we want to delete
 /// </param>
 /// <param name="graphLayout">
 /// Graph layout
 /// </param>
 public void DeleteCity(VertexCity cityToDelete, ref GraphLayoutCity graphLayout)
 {
     graphLayout.Graph.RemoveVertex(cityToDelete);
 }
        /// <summary>
        /// Apply style to the city
        /// </summary>
        /// <param name="city">
        /// Target city
        /// </param>
        /// <param name="style">
        /// The style to apply
        /// </param>
        /// <param name="graphLayout">
        /// Graph layout
        /// </param>
        public void MarkCity(City city, Style style, GraphLayoutCity graphLayout)
        {
            // Set style through the UI windows dispatcher
            window.Dispatcher.Invoke(
                new Action(delegate()
                {
                    SetStyle(new VertexCity(city), graphLayout, style);

                }),
                DispatcherPriority.Normal, null);
        }
        /// <summary>
        /// Highlight an edge
        /// </summary>
        /// <param name="startNode">
        /// Edge start node
        /// </param>
        /// <param name="endNode">
        /// Edge end node
        /// </param>
        /// <param name="graphLayout"></param>
        public void MarkEdge(City startNode, City endNode, GraphLayoutCity graphLayout)
        {
            // Create an EdgeCity object
            EdgeCity edge = new EdgeCity(
                new VertexCity(startNode), new VertexCity(endNode));

            // Highligh the edge
            graphLayout.Dispatcher.Invoke(
                new Action(delegate()
                {
                    graphLayout.HighlightEdge(edge, null);
                }),
                DispatcherPriority.Normal, null);
        }
 // Mark path
 /// <summary>
 /// Mark path that is presented by a sequential list of cities
 /// </summary>
 /// <param name="path"></param>
 /// <param name="graphLayout"></param>
 public void MarkPath(List<City> path, GraphLayoutCity graphLayout)
 {
     for (int i = 0; i < path.Count - 1; i++)
     {
         MarkPathCity(path[i], graphLayout);
         MarkPathCity(path[i + 1], graphLayout);
         MarkEdge(path[i], path[i + 1], graphLayout);
     }
 }
 /// <summary>
 /// Unmark all cities
 /// </summary>
 /// <param name="graphLayout"></param>
 public void UnmarkAllCities(GraphLayoutCity graphLayout)
 {
     Style style = null;
     window.Dispatcher.Invoke(
         new Action(delegate()
         {
             style = (Style)window.Resources["DefaultCityStyle"];
             SetStyleToAll(graphLayout, style);
         }),
         DispatcherPriority.Normal, null);
 }
        /// <summary>
        ///  Unmark all edges
        /// </summary>
        /// <param name="graphLayout"></param>
        public void UnmarkAllEdges(GraphLayoutCity graphLayout)
        {
            EdgeControl edgeControl = new EdgeControl();

            foreach (EdgeCity edge in graphLayout.HighlightedEdges)
            {
                graphLayout.Dispatcher.Invoke(
                new Action(delegate()
                {
                    graphLayout.RemoveHighlightFromEdge(edge);
                }),
                DispatcherPriority.Normal, null);
            }
        }
        /// <summary>
        /// Unmark edge
        /// </summary>
        /// <param name="startNode"></param>
        /// <param name="endNode"></param>
        /// <param name="graphLayout"></param>
        public void UnmarkEdge(City startNode, City endNode, GraphLayoutCity graphLayout)
        {
            EdgeCity edge = new EdgeCity(
                new VertexCity(startNode), new VertexCity(endNode));

            graphLayout.Dispatcher.Invoke(
                new Action(delegate()
                {
                    graphLayout.RemoveHighlightFromEdge(edge);
                }),
                DispatcherPriority.Normal, null);
        }
        /// <summary>
        /// Mark start city on the screen
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="graphLayout"></param>
        public void MarkStartCity(VertexCity vertex, ref GraphLayoutCity graphLayout)
        {
            if (startCity != null)
            {
                Style oldStyle = (Style)resources["DefaultCityStyle"];
                graphManager.SetStyle(startCity, graphLayout, oldStyle);
            }

            if ((finalCity != null) && (finalCity.Equals(vertex)))
            {
                finalCity = null;
            }

            startCity = vertex;

            Style newStyle = (Style)resources["StartCityStyle"];
            graphManager.SetStyle(vertex, graphLayout, newStyle);
        }
 /// <summary>
 /// Apply style to the list of cities
 /// </summary>
 /// <param name="cities">
 /// List of the target cities
 /// </param>
 /// <param name="style">
 /// The style to apply
 /// </param>
 /// <param name="graphLayout">
 /// Graph layout
 /// </param>
 public void MarkCities(List<City> cities, Style style, GraphLayoutCity graphLayout)
 {
     // For each city apply the chosen style
     foreach (City city in cities)
     {
         MarkCity(city, style, graphLayout);
     }
 }
 /// <summary>
 /// Set the vertices coordinates according to the locations file
 /// </summary>
 /// <param name="graphLayout"></param>
 public void EstablishGraphCoordinates(ref GraphLayoutCity graphLayout)
 {
     graphManager.EstablishCoordinates(ref graphLayout, citiesLocations);
 }
 /// <summary>
 /// Verify that the data passed into the algorithm has not been changed.
 /// Is not used. UI is disabled instead.
 /// </summary>
 /// <param name="graphLayout"></param>
 /// <returns></returns>
 private bool VerifyAlgorithmDataConsistency(GraphLayoutCity graphLayout)
 {
     CaptureCurrentGraph(graphLayout);
     if (!citiesLocations.Equals(algCitiesLocations))
     {
         return (false);
     }
     else
     {
         return (true);
     }
 }
 /// <summary>
 /// Refresh the graph in the layout
 /// </summary>
 /// <param name="graphLayout"></param>
 public void RefreshGraph(ref GraphLayoutCity graphLayout)
 {
     graphLayout.Graph = graphToVisualize;
 }
        /// <summary>
        /// Update the vertex information in the locations file and also update the 
        /// vertex internal information
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="graphLayout"></param>
        public void UpdateVertexInfo(VertexCity vertex, ref GraphLayoutCity graphLayout)
        {
            graphManager.UpdateVertexInfo(ref vertex, ref graphLayout);

            if (vertex != null)
            {
                Coordinates tempCityCoordinates;
                if (citiesLocations.locations.TryGetValue(vertex.City, out tempCityCoordinates))
                {
                    tempCityCoordinates.setX(vertex.CityCoordinates.getX());
                    tempCityCoordinates.setY(vertex.CityCoordinates.getY());
                }
            }
        }
 /// <summary>
 /// Get current nodes screen coordinates. Is not used. Coordinates are updated
 /// automatically.
 /// </summary>
 /// <param name="graphLayout"></param>
 public void CaptureCurrentGraph(GraphLayoutCity graphLayout)
 {
     graphManager.GetCurrentGraph(graphLayout, ref citiesLocations);
 }
        /// <summary>
        /// Start A-star algorithm in a separate thread
        /// </summary>
        /// <param name="graphLayout"></param>
        /// <param name="richTextBoxLog"></param>
        /// <param name="window"></param>
        public void StartAlgorithm(ref GraphLayoutCity graphLayout, ref TextBox richTextBoxLog,
            MainWindow window)
        {
            // If already running
            if (IsRunningAlg)
            {
                algorithm.WaitMutex.WaitOne();
                algorithm.CanContinue = true;
                algorithm.WaitMutex.ReleaseMutex();
            }
            // If not, then start a new thread
            else
            {

                algorithm = new Algorithm(citiesLocations, citiesConnections,
                    startCity.City, finalCity.City, algSpeed, algHeuristic,
                    ref graphLayout, ref richTextBoxLog, resources, graphManager);
                // Set window and create a mutex
                algorithm.Window = window;
                algorithm.WaitMutex = new Mutex();

                // Null the start and end cities
                startCity = null;
                finalCity = null;

                // Create and start the thread
                algThread = new Thread(new ThreadStart(algorithm.RunAlgThread));
                algThread.SetApartmentState(ApartmentState.STA);
                algThread.Start();

                // Allow the algorithm to continue
                algorithm.WaitMutex.WaitOne();
                algorithm.CanContinue = true;
                algorithm.WaitMutex.ReleaseMutex();
            }
        }
        /// <summary>
        /// Get the data about the current graph's
        /// node, edges and their coordinates. Save this
        /// data to citiesLocations and citiesConnections.
        /// </summary>
        public void GetCurrentGraph(GraphLayoutCity graphLayout,
            ref CitiesLocations citiesLocations)
        {
            VertexControl vertexControl = new VertexControl();
            Coordinates tempVertexCoordinates;
            int tempXCoord;
            int tempYCoord;

            foreach (VertexCity vertex in graphLayout.Graph.Vertices)
            {
                // Get the vertex data and a vertex control
                citiesLocations.locations.TryGetValue(vertex.City, out tempVertexCoordinates);
                vertexControl = graphLayout.GetVertexControl(vertex);

                // Get current coordinates
                tempXCoord = (int)GraphCanvas.GetX(vertexControl);
                tempYCoord = (int)GraphCanvas.GetY(vertexControl);

                // Update the information
                tempVertexCoordinates.setX(tempXCoord);
                tempVertexCoordinates.setY(tempYCoord);
            }
        }
 /// <summary>
 /// Reset the graph to the default graph, which was originally downloaded from the
 /// file.
 /// </summary>
 /// <param name="graphLayout"></param>
 public void ResetGraphToDefault(ref GraphLayoutCity graphLayout)
 {
     if (NoDelete())
     {
         ResetGraph(ref graphLayout);
     }
     else
     {
         RecoverGraphData();
         CreateGraph();
         RefreshGraph(ref graphLayout);
         EstablishGraphCoordinates(ref graphLayout);
     }
 }
        /// <summary>
        /// Apply the style to all vertices in the graph. Must be called from the UI 
        /// thread because it does not use a deispatcher.
        /// </summary>
        /// <param name="graphLayout">
        /// Graph layout
        /// </param>
        /// <param name="style">
        /// The style to apply
        /// </param>
        public void SetStyleToAll(GraphLayoutCity graphLayout, Style style)
        {
            VertexControl vertexControl;

            // Apply style for each vertex in the graph
            foreach (VertexCity vertex in graphLayout.Graph.Vertices)
            {
                vertexControl = graphLayout.GetVertexControl(vertex);
                if (vertexControl != null)
                {
                    vertexControl.Style = style;
                }
            }
        }
 /// <summary>
 /// Reset the vertecies locations to the default locations.
 /// </summary>
 /// <param name="graphLayout"></param>
 public void ResetGraph(ref GraphLayoutCity graphLayout)
 {
     ResetCitiesLocations();
     EstablishGraphCoordinates(ref graphLayout);
 }
 /// <summary>
 /// Delete the city and all connected edges
 /// </summary>
 /// <param name="cityToDelete">
 /// City we want to delete
 /// </param>
 /// <param name="graphLayout">
 /// Graph layout
 /// </param>
 public void DeleteCity(VertexCity cityToDelete, ref GraphLayoutCity graphLayout)
 {
     graphLayout.Graph.RemoveVertex(cityToDelete);
 }
 /// <summary>
 /// Refresh the graph in the layout
 /// </summary>
 /// <param name="graphLayout"></param>
 public void RefreshGraph(ref GraphLayoutCity graphLayout)
 {
     graphLayout.Graph = graphToVisualize;
 }
 /// <summary>
 /// Unmark edges
 /// </summary>
 /// <param name="startNode"></param>
 /// <param name="endNodes"></param>
 /// <param name="graphLayout"></param>
 public void UnmarkEdges(City startNode, List<City> endNodes, GraphLayoutCity graphLayout)
 {
     foreach (City endNode in endNodes)
     {
         UnmarkEdge(startNode, endNode, graphLayout);
     }
 }
 /// <summary>
 /// Unmark list of cities
 /// </summary>
 /// <param name="cities"></param>
 /// <param name="graphLayout"></param>
 public void UnmarkCities(List<City> cities, GraphLayoutCity graphLayout)
 {
     foreach (City city in cities)
     {
         UnmarkCity(city, graphLayout);
     }
 }