Ejemplo n.º 1
0
        /// <summary>
        /// Draw result edge onto the result graph
        /// </summary>
        /// <param name="resultGraph"></param>
        /// <param name="canvasEdge"></param>
        private void DrawOutputEdge(ResultGraph resultGraph, CanvasEdge canvasEdge)
        {
            resultGraph.ResultCanvas.Children.Add(canvasEdge);
            Canvas.SetZIndex(canvasEdge, -1);

            CanvasNode tempSrcNode  = resultGraph.CGraph[canvasEdge.Impl.From];
            CanvasNode tempDestNode = resultGraph.CGraph[canvasEdge.Impl.To];

            tempSrcNode.OutLines.Add(canvasEdge);
            tempDestNode.InLines.Add(canvasEdge);

            resultGraph.ResultCanvas.UpdateLines(tempSrcNode);
            resultGraph.ResultCanvas.UpdateLines(tempDestNode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add result edge onto the result graph
        /// </summary>
        /// <param name="resultGraph"></param>
        /// <param name="srcNode"></param>
        /// <param name="destNode"></param>
        /// <param name="fullyObserved"></param>
        private void AddOutputEdge(ResultGraph resultGraph, CanvasNode srcNode, CanvasNode destNode, bool fullyObserved)
        {
            CanvasEdge edge = new CanvasEdge(isResult: true)
            {
                Stroke = fullyObserved ? Brushes.Green : Brushes.DarkOrange,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                StrokeThickness     = 3,
                X1         = srcNode.X,
                Y1         = srcNode.Y,
                X2         = destNode.X,
                Y2         = destNode.Y,
                IsDirected = ArcType.SelectedItem == DirectedArc,
            };

            resultGraph.CGraph.Call(g =>
            {
                g.ConnectNodeToWith(srcNode.Impl, destNode.Impl, edge.Impl);
            });
            resultGraph.CGraph[edge.Impl] = edge;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Display constraint window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Start_Click(object sender, RoutedEventArgs e)
        {
            // Create a resultGraph instance
            StartWindow startWindow = new StartWindow(graph.CommonAttributes);

            if (startWindow.ShowDialog() != true)
            {
                MessageBox.Show("Task imcompleted.\nAborted.", "Algorithm not running.");
            }
            else
            {
                logTab.IsSelected = true;
                logger.Content    = "";
                logger.Content   += "\nStart Checking observability....\n";

                var observers = graph.Call(graph => graph.AllNodes.Values.Where(node => node.IsObserver)).ToArray();

                AllPaths algorithm = new AllPaths();
                var      result    = new ConnectivityObserver().Observe(graph.Impl, observers, startWindow.returnValue, algorithm);

                logger.Content += "Observation Completed.\n";
                ResultGraph resultGraph = new ResultGraph();

                foreach (var pair in result)
                {
                    INode from = pair.Key.From, to = pair.Key.To;
                    IEnumerable <Route> observedRoutes = pair.Value.Item1;
                    IEnumerable <Route> unobservedRoutes = pair.Value.Item2;
                    if (observedRoutes.Count() > 0)
                    {
                        Route      shortestObRoute = observedRoutes.OrderBy(p => p.PathCost).First();
                        CanvasNode tempSrcNode     = new CanvasNode(graph[from]);
                        CanvasNode tempDestNode    = new CanvasNode(graph[to]);
                        if (resultGraph.CGraph.Call(graph => !graph.Contains(from)))
                        {
                            resultGraph.CGraph.Call(graph => graph.Add(from));
                            resultGraph.CGraph[from] = tempSrcNode;
                        }
                        else
                        {
                            tempSrcNode = resultGraph.CGraph[from];
                        }

                        if (resultGraph.CGraph.Call(graph => !graph.Contains(to)))
                        {
                            resultGraph.CGraph.Call(graph => graph.Add(to));
                            resultGraph.CGraph[to] = tempDestNode;
                        }
                        else
                        {
                            tempDestNode = resultGraph.CGraph[to];
                        }

                        double shortestDistance = Double.MaxValue;
                        if (unobservedRoutes.Count() > 0)
                        {
                            Route shortestUnobRoute = unobservedRoutes.OrderBy(p => p.PathCost).First();
                            shortestDistance = shortestUnobRoute.PathCost;
                        }

                        if ((from.IsVisible && to.IsVisible) && shortestObRoute.PathCost < shortestDistance)
                        {
                            //resultGraph.logger.Content += String.Format("\nNode {0} to Node {1} : observed\n", from.Id, to.Id);
                            //logger.Content += String.Format("The path from Node {0} to Node {1} is : {2}\n", from.Id, to.Id, shortestObRoute);
                            resultGraph.observedLog.Content += String.Format("{0} (This is the shortest path)\n", shortestObRoute);
                            AddOutputEdge(resultGraph, tempSrcNode, tempDestNode, unobservedRoutes.Count() == 0);
                        }
                        else
                        {
                            resultGraph.observedLog.Content += String.Format("{0}\n", shortestObRoute);
                        }
                    }

                    //               foreach (Route through in observedRoutes)
                    //{
                    //	logger.Content += String.Format("Node {0} to Node {1} : observed\n", from.Id, to.Id);
                    //	logger.Content += String.Format("The path from Node {0} to Node {1} is : {2}\n", from.Id, to.Id, through);

                    //CanvasNode tempSrcNode = new CanvasNode(graph[from]);
                    //CanvasNode tempDestNode = new CanvasNode(graph[to]);

                    //DrawNode(tempSrcNode, resultGraph.ResultCanvas);
                    //DrawNode(tempDestNode, resultGraph.ResultCanvas);
                    //                  if (from.IsVisible && to.IsVisible)
                    //                  {
                    //                      DrawOutputEdge(resultGraph, tempSrcNode, tempDestNode);
                    //                  }
                    //}

                    foreach (Route through in unobservedRoutes)
                    {
                        //		logger.Content += String.Format("\nNode {0} to Node {1} : not observed\n", from.Id, to.Id);
                        resultGraph.unobservedLog.Content += String.Format("{0}\n", through);
                    }
                }

                foreach (var node in resultGraph.CGraph.Call(graph => graph.AllNodes.Values))
                {
                    var cnode = resultGraph.CGraph[node];
                    DrawNode(cnode, resultGraph.ResultCanvas);
                }
                foreach (var edge in resultGraph.CGraph.Call(graph => graph.AllEdges.Values))
                {
                    var cedge = resultGraph.CGraph[edge];

                    DrawOutputEdge(resultGraph, cedge);
                }


                logger.Content += "Task Finished.";
                // Display the resultGraph window
                resultGraph.Show();
            }
        }