Esempio n. 1
0
        public void UpdateEdges_Test()
        {
            var             service     = new CsvGraphDataService();
            bool            callSuccess = false;
            Exception       er;
            List <DataEdge> list  = new List <DataEdge>();
            var             item1 = new DataVertex(1);
            var             item2 = new DataVertex(2);
            var             edge1 = new DataEdge(item1, item2);

            list.Add(edge1);

            service.UpdateEdges(list, (sucess, error) =>
            {
                er          = error;
                callSuccess = sucess;
            });

            DataEdge item1FromSource = null;

            service.GetEdges((data) =>
            {
                item1FromSource = data.FirstOrDefault();

                callSuccess = true;
            }, (e) => { });

            Assert.IsTrue(callSuccess);
            Assert.IsNotNull(item1FromSource);
            Assert.AreEqual(edge1.Source.Id, item1FromSource.Source.Id);
            Assert.AreEqual(edge1.Target.Id, item1FromSource.Target.Id);
        }
Esempio n. 2
0
        public void Parse()
        {
            this.ReadFromFile();

            this.House_Count = int.Parse(this.ResultString[0]);

            this.Map = new GraphKingdomMap();

            // generate all vertex
            for (int i = 1; i <= this.House_Count; i++)
            {
                DataVertex newVertex = new DataVertex(i);
                this.Map.AddVertex(newVertex);
            }

            // get a list of all vertex for easy access
            var vlist = this.Map.Vertices.ToList();

            // insert edges from input
            for (int i = 1; i < this.House_Count; i++)
            {
                // split input into two strings
                string[] temp = ResultString[i].Split();

                // parse from string to int to get vertex id
                int source      = int.Parse(temp[0]) - 1;
                int destination = int.Parse(temp[1]) - 1;

                // insert bidirectional edges
                var newEdge = new DataEdge(vlist[source], vlist[destination]);
                this.Map.AddVerticesAndEdge(newEdge);
                newEdge = new DataEdge(vlist[destination], vlist[source]);
                this.Map.AddVerticesAndEdge(newEdge);
            }
        }
Esempio n. 3
0
        /*public static QuickGraph.AdjacencyGraph<int, QuickGraph.Edge<int>> GraphToAdjacencyQuickGraph(Graph g)
         * {
         *  var graph = new QuickGraph.AdjacencyGraph<int, QuickGraph.Edge<int>>();
         *  QuickGraph.Edge<int>[] edges = new QuickGraph.Edge<int>[g.order];
         *  for (int i = 0; i < g.order; i++)
         *  {
         *      for (int j = i + 1; j < g.order; j++)
         *      {
         *          if (g.adjacencyMatrix[i, j] == 1) graph.AddEdge(new QuickGraph.Edge<int>(i, j));
         *      }
         *  }
         *  EdmondsKarpMaximumFlowAlgorithm<int, QuickGraph.Edge<int>>()
         *
         *  return graph;
         * }*/



        public static CreateGraph G6toQuickGraph(string g6)
        {
            int[,] adjMatrix = Graph6toAdjMatrix(g6);
            var graph = new CreateGraph();
            int order = adjMatrix.GetLength(0);

            //Create vertices
            for (int i = 0; i < order; i++)
            {
                var vertex = new DataVertex("" + i);
                graph.AddVertex(vertex);
            }

            var vlist = graph.Vertices.ToList();

            //Create edges of graph g

            for (int i = 0; i < order; i++)
            {
                for (int j = i + 1; j < order; j++)
                {
                    if (adjMatrix[i, j] == 1)
                    {
                        var edge  = new DataEdge(vlist[i], vlist[j]);
                        var edge1 = new DataEdge(vlist[j], vlist[i]);
                        graph.AddEdge(edge);
                        graph.AddEdge(edge1);
                    }
                }
            }
            return(graph);
        }
        private bool CheckIfLabelNeeded(DataEdge data)
        {
            if (data.Source.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_VERTEX &&
                data.Target.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_PARTIAL_VERTEX)
            {
                return(false);
            }
            else if (data.Source.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_VERTEX &&
                     data.Target.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_PARTIAL_VERTEX)
            {
                return(false);
            }


            if (data.Target.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_VERTEX &&
                data.Source.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_PARTIAL_VERTEX)
            {
                return(false);
            }
            else if (data.Target.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_VERTEX &&
                     data.Source.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_PARTIAL_VERTEX)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        public static GraphExample GenerateGraphUI <T>(NGramGraphMarkovChain <T> markovChain)
            where T : IEquatable <T>
        {
            var dataGraph = new GraphExample();

            Dictionary <NGram <T>, int> indices = new Dictionary <NGram <T>, int>();
            int i = 0;

            foreach (var item in markovChain)
            {
                var dataVertex = new DataVertex(NGramHelper.ShowNGram <T>(item.Key.AsEnumerableObject()))
                {
                    ID = i
                };
                dataGraph.AddVertex(dataVertex);
                indices.Add(item.Key, i);
                i++;
            }
            var vlist = dataGraph.Vertices.ToList();

            foreach (var item in markovChain)
            {
                foreach (var edge in item.Value)
                {
                    var dataEdge = new DataEdge(vlist[indices[item.Key]], vlist[indices[edge.Edge]], edge.Probability)
                    {
                        Text = edge.Probability.ToString()
                    };
                    dataGraph.AddEdge(dataEdge);
                }
            }

            return(dataGraph);
        }
        public override void UnDo()
        {
            _Edge = new DataEdge(_source, _target);

            _sourceVC = _graph.VertexList.Where(pair => pair.Key == _source).Select(pair => pair.Value).FirstOrDefault();
            _targetVC = _graph.VertexList.Where(pair => pair.Key == _target).Select(pair => pair.Value).FirstOrDefault();

            if (_sourceVC == null || _targetVC == null)
                throw new ArgumentNullException("VertexControl");

            _eCtrl = new EdgeControl(_sourceVC, _targetVC, _Edge)
            {
                ShowArrows = true,
                ShowLabel = true
            };

            _graph.Graph.AddEdge(_Edge);
            _graph.AddEdge(_Edge, _eCtrl);

            HighlightBehaviour.SetIsHighlightEnabled(_eCtrl, false);

            if (_undoCallback != null)
            {
                _undoCallback.Invoke(_eCtrl);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Создает ребро и его визуальную часть.
        /// </summary>
        /// <param name="targetVertex">Вершина, инцидентная ребру.</param>
        private void CreateEdgeControl(VertexControl targetVertex)
        {
            if (sourceVertex == null)
            {
                sourceVertex = targetVertex;
                HighlightBehaviour.SetHighlighted(sourceVertex, true);
                return;
            }
            if (sourceVertex == targetVertex)
            {
                return;
            }
            if (!isUniqueEdge(sourceVertex, targetVertex))
            {
                return;
            }

            var dlg = new AddEdgeWigthDialog(this);

            if (dlg.ShowDialog() == false)
            {
                return;
            }

            double weidthR = dlg.RoadLength;

            var data    = new DataEdge((DataVertex)sourceVertex.Vertex, (DataVertex)targetVertex.Vertex, weidthR);
            var control = new EdgeControl(sourceVertex, targetVertex, data);

            graphArea.InsertEdgeAndData(data, control, 0, false);

            HighlightBehaviour.SetHighlighted(sourceVertex, false);
            sourceVertex = null;
        }
Esempio n. 8
0
        private void CreateEdgeControl(VertexControl vc)
        {
            if (_ecFrom == null)
            {
                _editorManager.CreateVirtualEdge(vc, vc.GetPosition());
                _ecFrom = vc;
                HighlightBehaviour.SetHighlighted(_ecFrom, true);
                return;
            }
            if (_ecFrom == vc)
            {
                return;
            }

            var data = new DataEdge((DataVertex)_ecFrom.Vertex, (DataVertex)vc.Vertex);

            graphArea.LogicCore.Graph.AddEdge(data);
            var ec = new EdgeControl(_ecFrom, vc, data);

            graphArea.InsertEdge(data, ec);

            HighlightBehaviour.SetHighlighted(_ecFrom, false);
            _ecFrom = null;
            _editorManager.DestroyVirtualEdge();
        }
Esempio n. 9
0
        public void GetEdges(Action <IEnumerable <DataEdge> > onSuccess, Action <Exception> onFail)
        {
            if (vlist.Count == 0)
            {
                MakeVertex();
            }

            Random r = new Random();

            List <DataEdge> list = new List <DataEdge>();

            for (var i = 0; i < 10; i++)
            {
                if (i % 3 == 0)
                {
                    continue;
                }

                var e = new DataEdge(vlist[i], vlist[0]);
                list.Add(e);
            }

            if (onSuccess != null)
            {
                onSuccess.Invoke(list);
            }
        }
        private void _DrawAllFrameSubframes(EasyGraph dataGraph, FrameContainer frameContainer, Frame isA_nilFrame, DataVertex isA_nilFrameDataVertex)
        {
            foreach (Slot slot in isA_nilFrame.slots)
            {
                Frame nextFrame = frameContainer.FrameFinder(slot.value);
                if (nextFrame != null)
                {
                    DataVertex nextFrameDataVertex = new DataVertex();
                    if (_GetVertexByItsFrame(nextFrame, dataGraph) == null)
                    {
                        nextFrameDataVertex.Text = nextFrame.name;
                        nextFrameDataVertex.ID   = nextFrame.Id;

                        dataGraph.AddVertex(nextFrameDataVertex);
                    }
                    else
                    {
                        nextFrameDataVertex = _DrawGetVertexById(nextFrame.Id, dataGraph);
                    }
                    var dataEdge = new DataEdge(nextFrameDataVertex, isA_nilFrameDataVertex)
                    {
                    };
                    dataGraph.AddEdge(dataEdge);

                    //TODO: Здесь супер функция по отрисовке всех из-а для этого
                }
            }
        }
Esempio n. 11
0
        public void ToStringShouldReturnNAIfDescriptionNotNullOrEmpty()
        {
            string   expected = "Description: N/A";
            DataEdge edge     = new DataEdge(testNode1, testNode2);
            string   actual   = edge.ToString().Split(',')[1].TrimStart(' ');

            Assert.AreEqual(expected, actual);
        }
 //dispose operation, release reference
 public virtual void Dispose()
 {
     _Edge.Dispose();
     _Edge = null;
     _eCtrl = null;
     _callback = null;
     _undoCallback = null;
     _graph = null;
 }
Esempio n. 13
0
        private GraphExample GraphExample_Setup()
        {
            //Lets make new data graph instance
            var dataGraph = new GraphExample();

            //Now we need to create edges and vertices to fill data graph
            //This edges and vertices will represent graph structure and connections
            //Lets make some vertices
            for (int i = 1; i <= numOfVertices; i++)
            {
                //Create new vertex with specified Text. Also we will assign custom unique ID.
                //This ID is needed for several features such as serialization and edge routing algorithms.
                //If you don't need any custom IDs and you are using automatic Area.GenerateGraph() method then you can skip ID assignment
                //because specified method automaticaly assigns missing data ids (this behavior is controlled by method param).

                var dataVertex = new DataVertex {
                    ID = i, Text = string.Format("{0}", i)
                };
                //Add vertex to data graph

                dataGraph.AddVertex(dataVertex);
            }

            if (matrix == null)
            {
                //Now lets make some edges that will connect our vertices
                //get the indexed list of graph vertices we have already added

                var vlist = dataGraph.Vertices.ToList();

                //Then create two edges optionaly defining Text property to show who are connected

                var dataEdge = new DataEdge(vlist[0], vlist[1], 3)
                {
                    Text = string.Format("{0} -> {1}", vlist[0], vlist[1])
                };
                dataGraph.AddEdge(dataEdge);
                dataEdge = new DataEdge(vlist[2], vlist[3], 3)
                {
                    Text = string.Format("{0} -> {1}", vlist[2], vlist[3])
                };
                dataGraph.AddEdge(dataEdge);
            }
            else
            {
                var vlist = dataGraph.Vertices.ToList();
                for (int i = 0; i < matrix.Count; i++)
                {
                    var dataEdge = new DataEdge(Search(dataGraph, matrix[i][0]), Search(dataGraph, matrix[i][1]), matrix[i][2])
                    {
                        Text = string.Format("{0}", matrix[i][2])
                    };
                    dataGraph.AddEdge(dataEdge);
                }
            }
            return(dataGraph);
        }
Esempio n. 14
0
        private Graph SetupGraph(int selectIndex)
        {
            //Lets make new data graph instance
            var dataGraph = new Graph();
            IDictionary <string, DataVertex> vertexDictionary = new Dictionary <string, DataVertex>();


            foreach (var sentence in _analyzer.Sentences.Skip(selectIndex).Take(1))
            {
                foreach (var chunk in sentence.Chunks)
                {
                    string text = string.Join(string.Empty,
                                              chunk.Morphs.Where(m => m.Pos != Morph.SignPosName).Select(m => m.Surface));
                    if (vertexDictionary.ContainsKey(text))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(text))
                    {
                        continue;
                    }

                    var vertex = new DataVertex(text);
                    vertexDictionary.Add(text, vertex);
                    dataGraph.AddVertex(vertex);
                }

                foreach (var chunk in sentence.Chunks)
                {
                    if (chunk.Dst == -1)
                    {
                        continue;
                    }

                    string from = string.Join(string.Empty,
                                              chunk.Morphs.Where(m => m.Pos != Morph.SignPosName).Select(m => m.Surface));
                    string to = string.Join(string.Empty,
                                            sentence.Chunks[chunk.Dst].Morphs.Where(m => m.Pos != Morph.SignPosName)
                                            .Select(m => m.Surface));
                    if (string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to))
                    {
                        continue;
                    }

                    var dataEdge = new DataEdge(vertexDictionary[from], vertexDictionary[to])
                    {
                        Text = $"{from} -> {to}"
                    };
                    dataGraph.AddEdge(dataEdge);
                }
            }

            return(dataGraph);
        }
Esempio n. 15
0
        public void ToStringShouldReturnIdIfIdNotNullOrEmpty()
        {
            string   expected = "ID: SnagL Test ID";
            DataEdge edge     = new DataEdge(testNode1, testNode2)
            {
                ID = "SnagL Test ID"
            };
            string actual = edge.ToString().Split(',')[0].Replace("[", string.Empty);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 16
0
        public void ToStringShouldReturnDescriptionIfDescriptionNotNullOrEmpty()
        {
            string expected = "Description: SnagL Test Description";
            DataEdge edge = new DataEdge(testNode1, testNode2)
            {
                Description = "SnagL Test Description"
            };
            string actual = edge.ToString().Split(',')[1].TrimStart(' ');

            Assert.AreEqual(expected, actual);
        }
Esempio n. 17
0
        public void ToStringShouldReturnIdNAIfIdNullOrEmpty()
        {
            string expected = "ID: N/A";
            DataEdge edge = new DataEdge(testNode1, testNode2)
            {
                ID = null
            };
            string actual = edge.ToString().Split(',')[0].Replace("[", string.Empty);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 18
0
        public static void AddEdge(BidirectionalGraph<DataVertex, DataEdge> graph, DataVertex source, DataVertex target, int? sourcePoint = null, int? targetPoint = null, int weight = 0)
        {
            var edge = new DataEdge(source, target, weight)
            {
                Text = string.Empty,
                SourceConnectionPointId = sourcePoint,
                TargetConnectionPointId = targetPoint,
                ToolTipText = "Label "+ source.ID
            };

            graph.AddEdge(edge);
        }
Esempio n. 19
0
        public static void AddEdge(BidirectionalGraph <DataVertex, DataEdge> graph, DataVertex source, DataVertex target, int?sourcePoint = null, int?targetPoint = null, int weight = 0)
        {
            var edge = new DataEdge(source, target, weight)
            {
                Text = string.Empty,
                SourceConnectionPointId = sourcePoint,
                TargetConnectionPointId = targetPoint,
                ToolTipText             = "Label " + source.ID
            };

            graph.AddEdge(edge);
        }
 public EdgeConfigurationView(DataVertex dv, Dictionary <string, DataVertex> globalVertices,
                              TestFeederGenerator.Models.GraphX graph, string key, Dictionary <string, List <DataEdge> > globalEdges,
                              bool isUpdate, VertexControl vc, GraphArea area, MainWindow mn,
                              Dictionary <string, Models.CableConfiguration> globalCableConfiguration,
                              EdgeControl ec = null, DataEdge de = null, VertexControl _ecFrom = null)
 {
     InitializeComponent();
     _ec          = ec;
     data         = de;
     this._ecFrom = _ecFrom;
     initializeLocalVariablesNewEdge(dv, graph, globalVertices, key, globalEdges, isUpdate, area, vc, mn, globalCableConfiguration);
     mainWindow = App.Current.MainWindow as MainWindow;
 }
Esempio n. 21
0
        public GraphExample Graph_Setup(string FOCUS = "")
        {
            if (Produit.GrandeurPhysiques == null)
                return null;

            var dataGraph = new GraphExample();
            if (FOCUS == "FOCUS")
            {
                foreach (var GP in Produit.GrandeurPhysiques)
                {
                    if (GP.Value.Selectionne)
                    {
                        var dataVertex = new DataVertex(GP.Key);
                        dataGraph.AddVertex(dataVertex);
                    }
                }  
            }
            else
            {
              foreach (var GP in Produit.GrandeurPhysiques)
                {
                    //if (GP.Value.EstPremier)
                    //{
                        var dataVertex = new DataVertex(GP.Key);
                        dataGraph.AddVertex(dataVertex);
                    //}
                }  
            }
            
            //Now lets make some edges that will connect our vertices
            //get the indexed list of graph vertices we have already added
            var vlist = dataGraph.Vertices.ToList();
            var dataEdge = new DataEdge(); //= new DataEdge(vlist[0], vlist[1]);
            //dataGraph.AddEdge(dataEdge);
            foreach (var R1 in vlist)
            {
                foreach (var R2 in vlist)
                {
                    if (Relation.MatriceRelations[Produit.GrandeurPhysiques[R1.Text].iM][
                            Produit.GrandeurPhysiques[R2.Text].iM] != null)
                        if (Relation.MatriceRelations[Produit.GrandeurPhysiques[R1.Text].iM][
                            Produit.GrandeurPhysiques[R2.Text].iM] !=1 -1)
                            {
                                dataEdge = new DataEdge(R1, R2);
                                dataGraph.AddEdge(dataEdge);
                            }
               }
            }

            return dataGraph;
        }
Esempio n. 22
0
        private void btnHide_Click(object sender, EventArgs e)
        {
            hideOtherEdges = !hideOtherEdges;
            int[]            cycle = Helper.GetRandomCycle(Vertices.Count);
            DataEdge[]       edges = new DataEdge[Vertices.Count];
            DataEdge         edge;
            Tuple <int, int> nodes;

            if (hideOtherEdges)
            {
                for (int i = 0; i < Vertices.Count - 1; i++)
                {
                    nodes = Helper.OrderNodes(cycle[i], cycle[i + 1]);
                    _gArea.LogicCore.Graph.TryGetEdge(Vertices[nodes.Item1], Vertices[nodes.Item2], out edge);
                    edge.EdgeColor = Colors.Green;
                    edges[i]       = edge;
                }
                nodes = Helper.OrderNodes(cycle[0], cycle[Vertices.Count - 1]);
                _gArea.LogicCore.Graph.TryGetEdge(Vertices[nodes.Item1], Vertices[nodes.Item2], out edge);
                edge.EdgeColor            = Colors.Green;
                edges[Vertices.Count - 1] = edge;

                _gArea.GenerateAllEdges();
            }

            foreach (var item in _gArea.EdgesList)
            {
                if (!edges.Contains(item.Key))
                {
                    item.Value.ShowLabel = !hideOtherEdges;
                    item.Key.IsVisible   = !hideOtherEdges;
                    if (item.Key.EdgeColor != Colors.Red)
                    {
                        item.Key.EdgeColor = changeEdgeColor(comboBox1.Text);
                    }
                    if (hideOtherEdges)
                    {
                        item.Value.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        item.Value.Visibility = Visibility.Visible;
                    }
                }
            }

            TestMut();
            TestSplit();
            TestTourney();
        }
        internal void RecreateSerializedEdgeData(DataVertex source, DataVertex target, VertexControl vc, double length)
        {
            DataEdge de = new DataEdge(source, target);

            VertexControl vc1 = GetVertexControlWithDataVertex(source.Element_id);
            VertexControl vc2 = GetVertexControlWithDataVertex(target.Element_id);

            this.length = length;

            EdgeControl ec = new EdgeControl(vc1, vc2, de);


            AddEdge(de, ec, vc1);
        }
        private void ReplaceEdgeTarget(DataVertex dataVertexRegulator, DataVertex dataVertexRegulatorPartial,
                                       string old_value, VertexControl dataVertexRegulatorControl,
                                       VertexControl dataVertexRegulatorPartialControl, string length)
        {
            foreach (DataEdge dataEdge in mainWindow.GlobalEdges[dataVertexRegulator.Element_id])
            {
                if (dataEdge.Target.Element_id == old_value)
                {
                    //setup new data edge
                    DataEdge de = new DataEdge(dataVertexRegulator, dataVertexRegulatorPartial);
                    if (dataEdge.Source.typeOfVertex == DataVertex.TypeOfVertex.REGULATOR_VERTEX || dataEdge.Source.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_VERTEX)
                    {
                        de.Configuration = new CableConfiguration()
                        {
                            Name = "xfm_1"
                        };
                    }
                    de.Length = Double.Parse(length);
                    de.Text   = length;



                    //setup new edge control
                    EdgeControl edgeControl = new EdgeControl(dataVertexRegulatorControl, dataVertexRegulatorPartialControl, de);

                    setEdgesDashStyle(edgeControl, dataVertexRegulator.typeOfVertex);


                    //update area edges
                    mainWindow.graphView.Area.RemoveEdge(dataEdge);
                    mainWindow.graphView.Area.EdgesList.Remove(dataEdge);

                    if (dataVertexRegulator.typeOfVertex == DataVertex.TypeOfVertex.TRANSFORMER_VERTEX)
                    {
                        mainWindow.graphView.Area.AddEdge(de, edgeControl, false);
                    }
                    else
                    {
                        mainWindow.graphView.Area.AddEdge(de, edgeControl, true);
                    }


                    //update global edges
                    mainWindow.GlobalEdges[dataVertexRegulator.Element_id].Remove(dataEdge);
                    mainWindow.GlobalEdges[dataVertexRegulator.Element_id].Add(de);

                    break;
                }
            }
        }
Esempio n. 25
0
        void butVCP_Click(object sender, RoutedEventArgs e)
        {
            CreateNewArea();
            dg_Area.VertexList.Values.ToList().ForEach(a => a.SetConnectionPointsVisibility(true));
            dg_Area.LogicCore.Graph = ShowcaseHelper.GenerateDataGraph(6, false);
            var vlist = dg_Area.LogicCore.Graph.Vertices.ToList();
            var edge  = new DataEdge(vlist[0], vlist[1])
            {
                SourceConnectionPointId = 1, TargetConnectionPointId = 1
            };

            dg_Area.LogicCore.Graph.AddEdge(edge);
            edge = new DataEdge(vlist[0], vlist[0])
            {
                SourceConnectionPointId = 1, TargetConnectionPointId = 1
            };
            dg_Area.LogicCore.Graph.AddEdge(edge);



            dg_Area.LogicCore.DefaultLayoutAlgorithm               = LayoutAlgorithmTypeEnum.ISOM;
            dg_Area.LogicCore.DefaultOverlapRemovalAlgorithm       = OverlapRemovalAlgorithmTypeEnum.FSA;
            dg_Area.LogicCore.DefaultOverlapRemovalAlgorithmParams = dg_Area.LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);
            ((OverlapRemovalParameters)dg_Area.LogicCore.DefaultOverlapRemovalAlgorithmParams).HorizontalGap = 50;
            ((OverlapRemovalParameters)dg_Area.LogicCore.DefaultOverlapRemovalAlgorithmParams).VerticalGap   = 50;
            dg_Area.LogicCore.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.None;

            dg_Area.GenerateGraph(true);
            var vertex = dg_Area.VertexList[edge.Target];

            var newVcp = new StaticVertexConnectionPoint {
                Id = 5, Margin = new Thickness(2, 0, 0, 0)
            };
            var cc = new Border
            {
                Margin  = new Thickness(2, 0, 0, 0),
                Padding = new Thickness(0),
                Child   = newVcp
            };

            edge.TargetConnectionPointId = 5;
            vertex.VCPRoot.Children.Add(cc);
            vertex.VertexConnectionPointsList.Add(newVcp);

            dg_Area.EdgesList[edge].UpdateEdge();
            dg_Area.UpdateAllEdges(true);
        }
Esempio n. 26
0
 private GraphExample GenerateGraph()
 {
     //FOR DETAILED EXPLANATION please see SimpleGraph example project
     var dataGraph = new GraphExample();
     for (int i = 1; i < 10; i++)
     {
         var dataVertex = new DataVertex("MyVertex " + i) { ID = i };
         dataGraph.AddVertex(dataVertex);
     }
     var vlist = dataGraph.Vertices.ToList();
     //Then create two edges optionaly defining Text property to show who are connected
     var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
     dataGraph.AddEdge(dataEdge);
     dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[3]) };
     dataGraph.AddEdge(dataEdge);
     return dataGraph;
 }
Esempio n. 27
0
        /*--------------------------------------------------------------------------------------------*/
        protected void AddEdge <TFrom, TEdge, TTo>(TFrom pOutVertex, TEdge pEdge, TTo pInVertex)
            where TFrom : IVertex where TEdge : IEdge where TTo : IVertex
        {
            if (pEdge.OutVertexType != typeof(TFrom))
            {
                throw new Exception("Incorrect TFrom.");
            }

            if (pEdge.InVertexType != typeof(TTo))
            {
                throw new Exception("Incorrect TTo.");
            }

            Data.AddEdge(
                DataEdge.Create(pOutVertex, pEdge, pInVertex, IsForTestingOnly)
                );
        }
        private bool CheckIfConnectionExists(DataEdge data)
        {
            foreach (DataEdge de in (mainWindow.graphView.DataContext as GraphViewModel).Area.EdgesList.Keys)
            {
                if (de.Source.Element_id == data.Source.Element_id &&
                    de.Target.Element_id == data.Target.Element_id)
                {
                    return(true);
                }
                else if (de.Source.Element_id == data.Target.Element_id &&
                         de.Target.Element_id == data.Source.Element_id)
                {
                    return(true);
                }
            }

            return(false);
        }
        private BidirectionalGraph <DataVertex, DataEdge> GraphPcap_Setup()
        {
            //Lets make new data graph instance
            var dataGraph = new GraphPcap();

            //Now we need to create edges and vertices to fill data graph
            //This edges and vertices will represent graph structure and connections
            //Lets make some vertices
            foreach (NetworkInterface n in interafaces)
            {
                //Create new vertex with specified Text. Also we will assign custom unique ID.
                //This ID is needed for several features such as serialization and edge routing algorithms.
                //If you don't need any custom IDs and you are using automatic Area.GenerateGraph() method then you can skip ID assignment
                //because specified method automaticaly assigns missing data ids (this behavior is controlled by method param).
                var dataVertex = new DataVertex("MAC : " + n.MAC);
                //Add vertex to data graph
                dataGraph.AddVertex(dataVertex);
            }

            //Now lets make some edges that will connect our vertices
            //get the indexed list of graph vertices we have already added
            var vlist = dataGraph.Vertices.ToList();

            //Then create two edges optionaly defining Text property to show who are connected
            foreach (NetworkInterface n in interafaces)
            {
                foreach (Connection connection in n.connections)
                {
                    var dataEdge = new DataEdge(vlist[n.pos], vlist[FindNetworkInteface(FindMacByIP(connection.adress))])
                    {
                        Text = string.Format("{0} Mb", connection.stats.speed)
                    };
                    dataGraph.AddEdge(dataEdge);
                }
            }
            //var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
            //dataGraph.AddEdge(dataEdge);
            //dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[3]) };
            //dataGraph.AddEdge(dataEdge);

            return(dataGraph);
        }
Esempio n. 30
0
        public static GraphExample GenerateGraph()
        {
            //FOR DETAILED EXPLANATION please see SimpleGraph example project
            var dataGraph = new GraphExample();

            if (DSK != null)
            {
                foreach (var key in DSK.Keys)
                {
                    var dataVertex = new DataVertex(key.ToString());
                    dataGraph.AddVertex(dataVertex);
                }
            }

            var vlist = dataGraph.Vertices.ToList();

            //Then create two edges optionaly defining Text property to show who are connected

            DataEdge dataEdge;

            foreach (var p in vlist)
            {
                foreach (var k in DSK)
                {
                    if (k.Key.ToString() == p.ToString())
                    {
                        foreach (var val in k.Value)
                        {
                            foreach (var v in vlist)
                            {
                                if (v.ToString() == val.ToString())
                                {
                                    dataEdge = new DataEdge(v, p);
                                    dataGraph.AddEdge(dataEdge);
                                }
                            }
                        }
                    }
                }
            }
            return(dataGraph);
        }
Esempio n. 31
0
        void CopyDataEdge(ref SerializableGraph serializableGraph, IEnumerable <VFXDataEdgeController> dataEdges)
        {
            serializableGraph.dataEdges = new DataEdge[dataEdges.Count()];
            int cpt = 0;

            foreach (var edge in dataEdges)
            {
                DataEdge copyPasteEdge = new DataEdge();

                var inputController  = edge.input as VFXDataAnchorController;
                var outputController = edge.output as VFXDataAnchorController;

                copyPasteEdge.input.slotPath    = MakeSlotPath(inputController.model, true);
                copyPasteEdge.input.targetIndex = modelIndices[inputController.sourceNode];

                copyPasteEdge.output.slotPath      = MakeSlotPath(outputController.model, false);
                copyPasteEdge.output.targetIndex   = modelIndices[outputController.sourceNode];
                serializableGraph.dataEdges[cpt++] = copyPasteEdge;
            }
        }
Esempio n. 32
0
        public static GraphExample FirstSimpleExample()
        {
            var graph = new GraphExample();

            // 1. add vertexes
            var v1 = new DataVertex(1);
            var v2 = new DataVertex(2);



            graph.AddVertex(v1);
            graph.AddVertex(v2);

            // 2. add edges
            var edge1 = new DataEdge(v1, v2);

            graph.AddEdge(edge1);

            return(graph);
        }
Esempio n. 33
0
        public void TestCreateEdge()
        {
            var graph = new Graph();

            var v1 = new IntVertex(0);

            graph.AddVertex(v1);
            var v2 = new IntVertex(1);

            graph.AddVertex(v2);

            int edgeData = 69;
            var e        = new DataEdge <int>(v1, v2, edgeData);

            graph.AddEdge(e);
            Assert.IsNotNull(e);
            Assert.IsTrue(e.Data == edgeData);
            Assert.IsTrue(v1.Edges.Contains(e));
            Assert.IsTrue(v2.Edges.Contains(e));
        }
        public void GetEdges(Action<IEnumerable<DataEdge>> onSuccess, Action<Exception> onFail)
        {
            if (vlist.Count == 0)
                MakeVertex();

            Random r = new Random();

            List<DataEdge> list = new List<DataEdge>();

            for (var i = 0; i < 10; i++)
            {
                if (i % 3 == 0) continue;

                var e = new DataEdge(vlist[i],vlist[0]);
                list.Add(e);
            }

            if (onSuccess != null)
            {
                onSuccess.Invoke(list);
            }
        }
Esempio n. 35
0
        void dg_addedge_Click(object sender, RoutedEventArgs e)
        {
            if (dg_Area.VertexList.Count() < 2)
            {
                return;
            }
            var vlist = dg_Area.LogicCore.Graph.Vertices.ToList();
            var rnd1  = vlist[ShowcaseHelper.Rand.Next(0, vlist.Count - 1)];

            vlist.Remove(rnd1);
            var rnd2 = vlist[ShowcaseHelper.Rand.Next(0, vlist.Count - 1)];
            var data = new DataEdge(rnd1, rnd2);

            dg_Area.LogicCore.Graph.AddEdge(data);
            var ec = new EdgeControl(dg_Area.VertexList.FirstOrDefault(a => a.Key == rnd1).Value, dg_Area.VertexList.FirstOrDefault(a => a.Key == rnd2).Value, data)
            {
                DataContext = data
            };

            dg_Area.InsertEdge(data, ec);
            //dg_Area.RelayoutGraph(true);
        }
Esempio n. 36
0
        private Graph SetupGraph(int selectIndex)
        {
            //Lets make new data graph instance
            var dataGraph = new Graph();
            IDictionary <int, DataVertex> vertexDictionary = new Dictionary <int, DataVertex>();

            var sentence = _sentenceList.Skip(selectIndex).First();

            foreach (var word in sentence.Words)
            {
                var vertex = new DataVertex(word.Value);
                vertexDictionary.Add(word.Id, vertex);
                dataGraph.AddVertex(vertex);
            }

            foreach (var pair in sentence.DependencyDictionary)
            {
                if (pair.Key == "collapsed-dependencies")
                {
                    foreach (var dependency in pair.Value)
                    {
                        if (dependency.Governor.Index == 0)
                        {
                            continue;
                        }

                        var dataEdge = new DataEdge(vertexDictionary[dependency.Governor.Index],
                                                    vertexDictionary[dependency.Dependent.Index])
                        {
                            Text = $"{dependency.Governor.Index} -> {dependency.Dependent.Index}"
                        };
                        dataGraph.AddEdge(dataEdge);
                    }
                }
            }

            return(dataGraph);
        }
Esempio n. 37
0
        void butEdgeLabels_Click(object sender, RoutedEventArgs e)
        {
            CreateNewArea();

            dg_Area.ShowAllEdgesLabels(true);
            dg_Area.AlignAllEdgesLabels(true);
            dg_Area.ShowAllEdgesArrows(true);

            dg_Area.LogicCore.Graph = ShowcaseHelper.GenerateDataGraph(2, false);

            var vlist = dg_Area.LogicCore.Graph.Vertices.ToList();
            var edge  = new DataEdge(vlist[0], vlist[1])
            {
                Text = "Testing edge labels..."
            };

            dg_Area.LogicCore.Graph.AddEdge(edge);

            dg_Area.PreloadGraph(new Dictionary <DataVertex, Point> {
                { vlist[0], new Point() }, { vlist[1], new Point(0, 200) }
            });
            dg_Area.VertexList.Values.ToList().ForEach(a => a.SetConnectionPointsVisibility(false));
        }
Esempio n. 38
0
        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            DataEdge[] edges = new DataEdge[Vertices.Count];

            foreach (var item in _gArea.EdgesList)
            {
                if (!edges.Contains(item.Key))
                {
                    if (item.Key.EdgeColor == Colors.Red)
                    {
                        item.Key.EdgeColor = Colors.Red;
                    }
                    else
                    {
                        item.Key.EdgeColor = changeEdgeColor(comboBox1.Text);
                    }
                }
            }
            _gArea.GenerateAllEdges();

            TestMut();
            TestSplit();
            TestTourney();
        }
        public override void Do()
        {
            _Edge = new DataEdge(_source, _target);

            _sourceVC = _graph.VertexList.Where(pair => pair.Key.Id == _source.Id).Select(pair => pair.Value).FirstOrDefault();
            _targetVC = _graph.VertexList.Where(pair => pair.Key.Id == _target.Id).Select(pair => pair.Value).FirstOrDefault();

            if (_sourceVC == null || _targetVC == null)
                throw new ArgumentNullException("Vertex Control");

            _eCtrl = new EdgeControl(_sourceVC, _targetVC, _Edge)
            {
                ShowArrows = true,
                ShowLabel = true
            };

            _graph.Graph.AddEdge(_Edge);
            _graph.AddEdge(_Edge, _eCtrl);

            if (_callback != null)
            {
                _callback.Invoke(_eCtrl);
            }
        }
Esempio n. 40
0
        private int createEdgesAndFindMinFeedBack(List<List<string>> list)
        {
            int feedback = 0;
            ///////////
            totalGraph.RemoveEdgeIf(x => x.Text != "");
            totalGraph.RemoveVertexIf(x => x.Text != "");
            ///////////////
            for (int i = list.Count - 1; i >= 0; i--)
            {
                string str = "";
                foreach (string name in list[i])
                {
                    str += name;
                }
                totalGraph.AddVertex(new DataVertex(str));
            }
            ///////////
            foreach(HashSet<string> row in calc.mas)
            {
                for (int i = 0; i < row.Count-1; i++)
                {
                    string nameV1 = nameVertexAndM.First(x => x.Value.Contains(row.ElementAt(i))).Key;
                    string nameV2 = nameVertexAndM.First(x => x.Value.Contains(row.ElementAt(i+1))).Key;

                    int indexV1 = list.FindIndex(x => x.Contains(row.ElementAt(i)));
                    int indexV2 = list.FindIndex(x => x.Contains(row.ElementAt(i + 1)));
                    if(nameV1 != nameV2)
                    {
                        var Edge = new DataEdge(totalGraph.Vertices.First(x => x.Text == nameV1), totalGraph.Vertices.First(x => x.Text == nameV2))
                        { Text = string.Format("{0} -> {1}", totalGraph.Vertices.First(x => x.Text == nameV1), totalGraph.Vertices.First(x => x.Text == nameV2)) };

                        //Перевіряю чи є вже таке ребро
                        DataEdge temp = new DataEdge();
                        if (totalGraph.TryGetEdge(Edge.Source, Edge.Target, out temp) == false)
                        {
                            totalGraph.AddEdge(Edge);
                            if (indexV1 > indexV2)
                            {
                                feedback++;
                            }
                        }
                    }
                }
            }
            return feedback;
        }
Esempio n. 41
0
        private void btnSubmitEdge_Click(object sender, RoutedEventArgs e)
        {
            EdgeInputBox.Visibility = Visibility.Collapsed;

            if (!string.IsNullOrWhiteSpace(EdgeTextBox.Text) && !string.IsNullOrWhiteSpace(NVertexTextBox.Text))
            {
                int weight;
                if (int.TryParse(EdgeTextBox.Text, out weight))
                {
                    var ver = logicCore.Graph.Vertices.Where(x => x.Text == NVertexTextBox.Text);
                    if (ver.Count() != 0)
                    {
                        if (isRegionalCheck.IsChecked.Value)
                        {
                            if (isDuplexCheck.IsChecked.Value)
                            {
                                var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = true, IsDuplex = true };
                                _selectedVertex.Edges.Add(newEdge);
                                ver.First().Edges.Add(newEdge);
                                logicCore.Graph.AddEdge(newEdge);
                                Graph = (NetworkGraph)logicCore.Graph;
                            }
                            else
                            {
                                var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = true, IsDuplex = false };
                                _selectedVertex.Edges.Add(newEdge);
                                ver.First().Edges.Add(newEdge);
                                logicCore.Graph.AddEdge(newEdge);
                                Graph = (NetworkGraph)logicCore.Graph;
                            }
                        }
                        else
                        {
                            if (isDuplexCheck.IsChecked.Value)
                            {
                                var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = false,IsDuplex = true };
                                _selectedVertex.Edges.Add(newEdge);
                                ver.First().Edges.Add(newEdge);
                                logicCore.Graph.AddEdge(newEdge);
                                Graph = (NetworkGraph)logicCore.Graph;
                            }
                            else
                            {
                                var newEdge = new DataEdge(_selectedVertex, ver.First()) { Text = EdgeTextBox.Text, Weight = weight, IsSatelite = false, IsDuplex = false };
                                _selectedVertex.Edges.Add(newEdge);
                                ver.First().Edges.Add(newEdge);
                                logicCore.Graph.AddEdge(newEdge);

                                Graph = (NetworkGraph)logicCore.Graph;
                            }
                        }

                        btnApply_Click(null, null);
                        gg_but_randomgraph_Click(null, null);
                    }
                }
                else
                {
                    WarningBox.Visibility = Visibility.Visible;
                }
            }
            else
            {
                WarningBox.Visibility = Visibility.Visible;
            }
            NVertexTextBox.Text = null;
            EdgeTextBox.Text = null;
        }
Esempio n. 42
0
 void dg_addedge_Click(object sender, RoutedEventArgs e)
 {
     if (dg_Area.VertexList.Count() < 2) return;
     var vlist = dg_Area.LogicCore.Graph.Vertices.ToList();
     var rnd1 = vlist[ShowcaseHelper.Rand.Next(0, vlist.Count -1)];
     vlist.Remove(rnd1);
     var rnd2 = vlist[ShowcaseHelper.Rand.Next(0, vlist.Count - 1)];
     var data = new DataEdge(rnd1, rnd2);
     dg_Area.LogicCore.Graph.AddEdge(data);
     var ec = new EdgeControl(dg_Area.VertexList.FirstOrDefault(a => a.Key == rnd1).Value, dg_Area.VertexList.FirstOrDefault(a => a.Key == rnd2).Value, data) { DataContext = data };
     dg_Area.InsertEdge(data, ec);
     //dg_Area.RelayoutGraph(true);
 }
Esempio n. 43
0
        private GraphModel GraphSetup()
        {
            GraphDB db = new GraphDB();
            var graph = new GraphModel();

            //get all the nodes
            foreach (var node in db.Nodes)
            {
                var dataVertex = new DataVertex() { ID = node.Id, Text = node.label };
                graph.AddVertex(dataVertex);
                nodeList.Add(node.Id,node.label);
            }

            var vlist = graph.Vertices.ToList();

            //add all the edges
            foreach (var node in vlist)
            {
                Dictionary<int,int> edges =  new Dictionary<int, int>();
                foreach (var edge in db.Edges.Where(x => x.FromNode == node.ID))
                {
                    var dataEdge = new DataEdge(node, vlist[vlist.FindIndex(x => x.ID == edge.ToNode)]);
                    graph.AddEdge(dataEdge);
                    edges.Add(edge.ToNode,1);
                }

                vertices.Add(node.ID,edges);

            }

            return graph;
        }
Esempio n. 44
0
        private void CreateEdgeControl(VertexControl vc)
        {
            if(_ecFrom == null)
            {
                _editorManager.CreateVirtualEdge(vc, vc.GetPosition());
                _ecFrom = vc;
                HighlightBehaviour.SetHighlighted(_ecFrom, true);
                return;
            }
            if(_ecFrom == vc) return;

            var data = new DataEdge((DataVertex)_ecFrom.Vertex, (DataVertex)vc.Vertex);
            graphArea.LogicCore.Graph.AddEdge(data);
            var ec = new EdgeControl(_ecFrom, vc, data);
            graphArea.InsertEdge(data, ec);

            HighlightBehaviour.SetHighlighted(_ecFrom, false);
            _ecFrom = null;
            _editorManager.DestroyVirtualEdge();
        }
 public DeleteEdgeOperation(GraphArea graph, DataVertex source, DataVertex target,DataEdge edge, Action<EdgeControl> callback = null, Action<EdgeControl> undoCallback = null)
     : base(graph, source, target, callback, undoCallback)
 {
     _Edge = edge;
     base.Sammary = "Delete Edge";
 }
Esempio n. 46
0
 public void TestCreateDataEdge()
 {
     DataEdge edge = new DataEdge(testNode1, testNode2);
     Assert.IsInstanceOfType(edge, typeof(DataEdge));
 }
Esempio n. 47
0
 private void AddEdge(GraphExample igraph, int index1, int index2, IReadOnlyList<DataVertex> vlist)
 {
     var dataEdge = new DataEdge(vlist[index1], vlist[index2])
     {
         Text = string.Format("Edge {0}{1}", vlist[index1].ID, vlist[index2].ID),
         VisualEdgeThickness = _rnd.Next(1, 4),
         VisualEdgeTransparency = 1.0,
         VisualColor = "#ffffff"
     };
     igraph.AddEdge(dataEdge);
 }
Esempio n. 48
0
        //Створює графи на основі уточнених груп
        private Graph GenerateGraph()
        {
            graphs = new List<Graph>();//Лист графів для кожної групи
            for (int i = 0; i < calc.setElAfterV.Count; i++)
            {
                var Graph = new Graph();

                HashSet<string> tempSet = new HashSet<string>();

                foreach (string k in calc.setElAfterV[i])//Формування вершин
                {
                    var Vertex = new DataVertex(k);
                    Graph.AddVertex(Vertex);
                }

                var vlist = Graph.Vertices.ToList();

                for (int j = 0; j < calc.groupsAfterV[i].Count; j++)//Формування ребер
                {
                    for (int t = 0; t < calc.mas[calc.groupsAfterV[i].ElementAt(j)].Count - 1; t++)
                    {
                        var dataVertex1 = new DataVertex(calc.mas[calc.groupsAfterV[i].ElementAt(j)].ElementAt(t));
                        var dataVertex2 = new DataVertex(calc.mas[calc.groupsAfterV[i].ElementAt(j)].ElementAt(t + 1));

                        var Edge = new DataEdge(vlist.Find(x => x.Text == dataVertex1.Text), vlist.Find(x => x.Text == dataVertex2.Text))
                        { Text = string.Format("{0} -> {1}", vlist.Find(x => x.Text == dataVertex1.Text), vlist.Find(x => x.Text == dataVertex2.Text)) };

                        //Перевіряю чи є вже таке ребро
                        DataEdge temp = new DataEdge();
                        if (Graph.TryGetEdge(Edge.Source, Edge.Target, out temp) == false)
                            Graph.AddEdge(Edge);

                    }

                }
                graphs.Add(Graph);
            }
            totalGraph = new Graph();//Граф для відображення(об'єднує всі графи)
            for (int i = 0; i < graphs.Count; i++)
            {
                totalGraph.AddVertexRange(graphs.ElementAt(i).Vertices.ToList());
                totalGraph.AddEdgeRange(graphs.ElementAt(i).Edges.ToList());
            }
            return totalGraph;
        }
Esempio n. 49
0
 void dg_addedge_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     if (dg_Area.VertexList.Count() < 2) return;
     var vlist = (dg_Area.VertexList as Dictionary<DataVertex, VertexControl>).Keys.ToList();
     var rnd1 = vlist[Rand.Next(0, dg_Area.VertexList.Count() - 1)];
     var rnd2 = vlist[Rand.Next(0, dg_Area.VertexList.Count() - 1)];
     var data = new DataEdge(rnd1, rnd2);
     dg_Area.LogicCore.Graph.AddEdge(data);
     var ec = new EdgeControl(dg_Area.VertexList.FirstOrDefault(a => a.Key == rnd1).Value, dg_Area.VertexList.FirstOrDefault(a => a.Key == rnd2).Value, data) { DataContext = data };
     dg_Area.InsertEdge(data, ec);
     //dg_Area.RelayoutGraph(true);
 }
Esempio n. 50
0
        //Метод для злиття вершин(повертає true, якщо злиття відбулося)
        private bool mergeVertex(Graph graph, int indexOfGraph, params DataVertex[] list)
        {
            //Перевірка чи кількість елементів модуля <=5
            int count = 0;
            for (int n = 0; n < calc.moduls[indexOfGraph].Count; n++)
            {
                string namev = "";
                foreach (string s in calc.moduls[indexOfGraph].ElementAt(n))
                {
                    namev += s;
                }
                if (list.Any(x => x.Text == namev))
                {
                    count += calc.moduls[indexOfGraph].ElementAt(n).Count;
                }
            }
            if (count > 5 || list == null) return false;//Якщо модуль буде містити більше 5 елементів, то злиття не проводимо
            /////////////////////////////////////////////
            for (int i = 1; i < list.Length; i++)
            {
                //Видаляю спільні зв'язки
                _gArea.LogicCore.Graph.RemoveEdgeIf(x => x.Source == list[0] && x.Target == list[i]);
                graph.RemoveEdgeIf(x => x.Source == list[0] && x.Target == list[i]);
                _gArea.LogicCore.Graph.RemoveEdgeIf(x => x.Target == list[0] && x.Source == list[i]);
                graph.RemoveEdgeIf(x => x.Target == list[0] && x.Source == list[i]);
                //Зливаю елементи модулей та видаляю злиті
                for (int j = 0; j < calc.moduls[indexOfGraph].Count; j++)
                {
                    string str = "";
                    foreach (string s in calc.moduls[indexOfGraph].ElementAt(j))//Формую ім'я модуля
                    {
                        str += s;
                    }
                    if (str == list[0].Text)//Знаходжу відповідні вершині модулі
                    {
                        //calc.moduls[indexOfGraph].ElementAt(j).Add(list[i].Text);
                        calc.moduls[indexOfGraph].ElementAt(j).AddRange(nameVertexAndModuls[indexOfGraph][list[i].Text]);
                        //Міняю назву ключа(Створюю новий, а старий видаляю)
                        List<string> l = new List<string>();
                        l.AddRange(nameVertexAndModuls[indexOfGraph][list[i].Text]);

                        nameVertexAndModuls[indexOfGraph].Remove(str);
                        nameVertexAndModuls[indexOfGraph].Add(str + list[i].Text, l);
                        //////
                        nameVertexAndModuls[indexOfGraph][str + list[i]] = calc.moduls[indexOfGraph].ElementAt(j);
                    }
                    if (str == list[i].Text)//Видаляю злитий
                    {
                        calc.moduls[indexOfGraph].RemoveAt(j);
                        nameVertexAndModuls[indexOfGraph].Remove(str);
                        //nameVertexAndModuls[indexOfGraph][list[i].Text].Clear();
                        //nameVertexAndModuls[indexOfGraph][list[i].Text].AddRange(calc.moduls[indexOfGraph].ElementAt(j));
                    }
                }
                //Додаю назву вершини до загальної
                list[0].Text += list[i].Text;
                //Перенаправляю всі зв'язки
                var inE = new List<DataEdge>();
                inE.AddRange(graph.InEdges(list[i]));
                foreach (DataEdge e in inE)
                {
                    //e.Target = list[0];
                    //e.Text = string.Format("{0} -> {1}", e.Source, list[0]);

                    var Edge = new DataEdge(e.Source, list[0]) { Text = string.Format("{0} -> {1}", e.Source, list[0]) };
                    _gArea.LogicCore.Graph.AddEdge(Edge);
                    graph.AddEdge(Edge);
                }

                var outE = new List<DataEdge>();
                outE.AddRange(graph.OutEdges(list[i]));
                foreach (DataEdge e in outE)
                {
                    //e.Source = list[0];
                    //e.Text = string.Format("{0} -> {1}", list[0], e.Target);
                    var Edge = new DataEdge(list[0], e.Target) { Text = string.Format("{0} -> {1}", list[0], e.Target) };
                    _gArea.LogicCore.Graph.AddEdge(Edge);
                    graph.AddEdge(Edge);
                }

                //Видаляю вершини
                if (i == list.Count())
                {
                    _gArea.LogicCore.Graph.RemoveVertex(list[0]);
                    graph.RemoveVertex(list[0]);
                }
                _gArea.LogicCore.Graph.RemoveVertex(list[i]);
                graph.RemoveVertex(list[i]);

            }
            return true;
        }
Esempio n. 51
0
        public void Delete_Vertex_With_Related_Edges_Test()
        {
            //begin setup
            var graph = new Model.GraphArea();

            var v1 = new DataVertex(100) { };
            var v2 = new DataVertex(103) { };
            var v3 = new DataVertex(105) { };
            var vc1 = new VertexControl(v1);
            var vc2 = new VertexControl(v2);
            var vc3 = new VertexControl(v3);

            var e1 = new DataEdge(v1, v2);
            var ec1 = new EdgeControl(vc1, vc2, e1);
            var e2 = new DataEdge(v1, v3);
            var ec2 = new EdgeControl(vc1, vc3, e2);

            graph.Graph.AddVertex(v1);
            graph.AddVertex(v1, vc1);
            graph.Graph.AddVertex(v2);
            graph.AddVertex(v2, vc2);
            graph.Graph.AddVertex(v3);
            graph.AddVertex(v3, vc3);

            graph.Graph.AddEdge(e1);
            graph.AddEdge(e1, ec1);
            graph.Graph.AddEdge(e2);
            graph.AddEdge(e2, ec2);
            //end setup
            bool doCalled = false;
            bool undoCalled = false;
            var dvo = new DeleteVertexOperation(graph, v1, (dv, vc) =>
            {
                doCalled = true;
            },
            (dv) =>
            {
                undoCalled = true;
            });

            dvo.Do();

            Assert.IsTrue(doCalled);
            Assert.IsFalse(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e2));

            dvo.UnDo();

            Assert.IsTrue(undoCalled);
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsTrue(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsTrue(graph.EdgesList.Any(e => e.Key == e2));

            dvo.Do();

            Assert.IsTrue(doCalled);
            Assert.IsFalse(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e2));
        }
Esempio n. 52
0
        public MainWindow()
        {
            InitializeComponent();
            //Customize Zoombox a bit
            //Set minimap (overview) window to be visible by default
            ZoomControl.SetViewFinderVisibility(zoomctrl, Visibility.Visible);
            //Set Fill zooming strategy so whole graph will be always visible
            zoomctrl.ZoomToFill();

            var modes = new List<string>() { "By hopes", "By speed" };
            protocols = new List<string>() { "TCP", "UDP" };
            routingModeBox.ItemsSource = modes;
            routingModeBox.SelectedItem = modes[0];
            protocolBox.ItemsSource = protocols;
            protocolBox.SelectedItem = protocols[0];

            //Lets setup GraphArea settings
            GraphAreaExample_Setup();

            zoomctrl.MouseRightButtonUp += ((o, s) => { VertexInputBox.Visibility = Visibility.Visible; });

            //Vertex settings
            Area.VertexSelected += ((h, j) => {
                _selectedVertexEvent = j;
                _selectedVertex = (DataVertex)j.VertexControl.Vertex;
                VertexBox.Visibility = Visibility.Visible; });

            Area.EdgeSelected += ((h, j) => {
                _selectedEdgeEvent = j;
                _selectedEdge = (DataEdge)j.EdgeControl .Edge;
                EdgeBox.Visibility = Visibility.Visible;
            });

            Area.EdgeMouseEnter += ((h,j) =>
            {

                foreach (var item in logicCore.Graph.Edges)
                {
                    if (item.Equals(j.EdgeControl.Edge))
                    {
                        j.EdgeControl.ToolTip = item.GetEdgeType();
                    }
                }

            });

            //Vertex tooltip
            Area.VertexMouseEnter += ((h,j) =>
            {
                foreach(var item in logicCore.Graph.Vertices)
                {
                    if(item.Text == j.VertexControl.Vertex.ToString())
                    {
                        if (item.IsEnabled)
                        {
                            j.VertexControl.ToolTip = item.Text + "\n\n" + item.Routing;
                            StatsText.Text = "";
                            StatsText.Text += "  " + item.Text + Environment.NewLine;
                            StatsText.Text += "  Recieved TCP" + Environment.NewLine + "  control packets: " + item.RecievedTCPControlPackets + Environment.NewLine;
                            StatsText.Text += "  Recieved TCP" + Environment.NewLine + "  data packets: " + item.RecievedTCPDataPackets + Environment.NewLine;
                            StatsText.Text += "  Sended TCP" + Environment.NewLine + "  control packets: " + item.SendedTCPControlPackets + Environment.NewLine;
                            StatsText.Text += "  Sended TCP" + Environment.NewLine + "  data packets: " + item.SendedTCPDataPackets + Environment.NewLine;
                            StatsText.Text += "  Recieved UDP" + Environment.NewLine + "  data packets: " + item.RecivedUDPPackets + Environment.NewLine;
                            StatsText.Text += "  Sended UDP" + Environment.NewLine + "  data packets: " + item.SendedUDPPackets + Environment.NewLine;
                            CurrentIterBox.Text = "  Current iteration: " + Environment.NewLine + "  " + _iterationNumber;
                        }
                        else
                            j.VertexControl.ToolTip = item.Text;
                    }
                }
            });

            Area.VertexMouseLeave += ((h,j) => { StatsText.Text = "";
                CurrentIterBox.Text = "";
            });

            gg_but_randomgraph.Click += gg_but_randomgraph_Click;

            gg_but_relayout.Click += gg_but_relayout_Click;

            Loaded += MainWindow_Loaded;

            Graph = NetworkGraph.GetDefaultGraph();

            SearchShortestWay(true);
        }
        public void UpdateEdges_Test()
        {
            var service = new CsvGraphDataService();
            bool callSuccess = false;
            Exception er;
            List<DataEdge> list = new List<DataEdge>();
            var item1 = new DataVertex(1);
            var item2 = new DataVertex(2);
            var edge1 = new DataEdge(item1, item2);

            list.Add(edge1);

            service.UpdateEdges(list, (sucess, error) =>
            {
                er = error;
                callSuccess = sucess;
            });

            DataEdge item1FromSource = null;
            service.GetEdges((data) =>
            {
                item1FromSource = data.FirstOrDefault();

                callSuccess = true;

            }, (e) => { });

            Assert.IsTrue(callSuccess);
            Assert.IsNotNull(item1FromSource);
            Assert.AreEqual(edge1.Source.Id, item1FromSource.Source.Id);
            Assert.AreEqual(edge1.Target.Id, item1FromSource.Target.Id);
        }
Esempio n. 54
0
        private GraphExample GraphExample_Setup()
        {
            //Lets make new data graph instance
            var dataGraph = new GraphExample();
            //Now we need to create edges and vertices to fill data graph
            //This edges and vertices will represent graph structure and connections
            //Lets make some vertices
            for (int i = 1; i < 10; i++)
            {
                //Create new vertex with specified Text. Also we will assign custom unique ID.
                //This ID is needed for several features such as serialization and edge routing algorithms.
                //If you don't need any custom IDs and you are using automatic Area.GenerateGraph() method then you can skip ID assignment
                //because specified method automaticaly assigns missing data ids (this behavior controlled by method param).
                var dataVertex = new DataVertex("MyVertex " + i) { ID = i };
                //Add vertex to data graph
                dataGraph.AddVertex(dataVertex);
            }

            //Now lets make some edges that will connect our vertices
            //get the indexed list of graph vertices we have already added
            var vlist = dataGraph.Vertices.ToList();
            //Then create two edges optionaly defining Text property to show who are connected
            var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
            dataGraph.AddEdge(dataEdge);
                dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[3]) };
            dataGraph.AddEdge(dataEdge);

            return dataGraph;
        }
Esempio n. 55
0
        void dg_Area_VertexSelectedForED(object sender, GraphX.Models.VertexSelectedEventArgs args)
        {
            if (_isInEDMode)
            {
                if (_edVertex == null) //select starting vertex
                {
                    _edVertex = args.VertexControl;
                    _edFakeDV = new DataVertex() { ID = -666 };
                    _edGeo = new PathGeometry(new PathFigureCollection() { new PathFigure() { IsClosed = false, StartPoint = _edVertex.GetPosition(), Segments = new PathSegmentCollection() { new PolyLineSegment(new List<Point>() { new Point() }, true) } } });
                    var dedge = new DataEdge(_edVertex.Vertex as DataVertex, _edFakeDV);
                    _edEdge = new EdgeControl(_edVertex, null, dedge) { ManualDrawing = true };
                    dg_Area.AddEdge(dedge, _edEdge);
                    dg_Area.LogicCore.Graph.AddVertex(_edFakeDV);
                    dg_Area.LogicCore.Graph.AddEdge(dedge);
                    _edEdge.SetEdgePathManually(_edGeo);
                }
                else if (_edVertex != args.VertexControl) //finish draw
                {
                    _edEdge.Target = args.VertexControl;
                    var dedge = _edEdge.Edge as DataEdge;
                    dedge.Target = args.VertexControl.Vertex as DataVertex;
                    var fig = _edGeo.Figures[0];
                    var seg = fig.Segments[_edGeo.Figures[0].Segments.Count - 1] as PolyLineSegment;

                    if (seg.Points.Count > 0)
                    {
                        var targetPos = _edEdge.Target.GetPosition();
                        var sourcePos = _edEdge.Source.GetPosition();
                        //get the size of the source
                        var sourceSize = new Size()
                        {
                            Width = _edEdge.Source.ActualWidth,
                            Height = _edEdge.Source.ActualHeight
                        };
                        var targetSize = new Size()
                        {
                            Width = _edEdge.Target.ActualWidth,
                            Height = _edEdge.Target.ActualHeight
                        };

                        var src_start = seg.Points.Count == 0 ? fig.StartPoint : seg.Points[0];
                        var src_end = seg.Points.Count > 1 ? (seg.Points[seg.Points.Count - 1] == targetPos ? seg.Points[seg.Points.Count - 2] : seg.Points[seg.Points.Count - 1]) : fig.StartPoint;
                        Point p1 = GeometryHelper.GetEdgeEndpoint(sourcePos, new Rect(sourceSize), src_start, _edEdge.Source.MathShape);
                        Point p2 = GeometryHelper.GetEdgeEndpoint(targetPos, new Rect(targetSize), src_end, _edEdge.Target.MathShape);

                        fig.StartPoint = p1;
                        if (seg.Points.Count > 1)
                            seg.Points[seg.Points.Count - 1] = p2;
                    }
                    GeometryHelper.TryFreeze(_edGeo);
                    _edEdge.SetEdgePathManually(new PathGeometry(_edGeo.Figures));
                    _isInEDMode = false;
                    clearEdgeDrawing();
                }
            }
        }