private void SetupVisioTree() { this.VisioTree = new BidirectionalGraph <object, IEdge <object> >(); var overlapRemoval = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapRemoval.HorizontalGap = 50; overlapRemoval.VerticalGap = 50; this.treeLayout.OverlapRemovalParameters = overlapRemoval; this.treeLayout.Graph = null; }
public static GraphLayout overlapRemovalParameters(this GraphLayout graphLayout, float horizontalGap, float verticalGap) { return((GraphLayout)graphLayout.wpfInvoke( () => { var overlapRemovalParameters = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapRemovalParameters.HorizontalGap = horizontalGap; overlapRemovalParameters.VerticalGap = verticalGap; graphLayout.OverlapRemovalParameters = overlapRemovalParameters; return graphLayout; })); }
private void FillVisioGraphWithGraph(Graph graph) { this.VisioGraph = new BidirectionalGraph <object, IEdge <object> >(); foreach (var edge in graph.Edges) { this.VisioGraph.AddVerticesAndEdge(new MyEdge(edge.VerticeFrom, edge.VerticeTo, edge.Weight.ToString(CultureInfo.InvariantCulture), Colors.Silver)); } this.graphLayout.Graph = this.VisioGraph; // get some extra space between vertices var overlapRemoval = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapRemoval.HorizontalGap = 50; overlapRemoval.VerticalGap = 50; this.graphLayout.OverlapRemovalParameters = overlapRemoval; }
private void SetCustomLayout(int V, int E) { double density = (2.0000 * E) / (1.0000 * V * (V - 1.0000)); float mainFactor = (float)(Math.Log(V, 2) * density); /// Set distance between vertices int gapFactor = 50; float vertexGap = mainFactor * gapFactor; var overlapRemoval = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapRemoval.HorizontalGap = vertexGap; overlapRemoval.VerticalGap = vertexGap; this.graphLayout.OverlapRemovalParameters = overlapRemoval; /// Set vertices int vsizeFactor = 10; double esizeFactor = (V < 10)?2:(V < 20?1.5:(V < 50?1:(V < 100?0.6:0.3))); float vertexSize = mainFactor * vsizeFactor; double fsizeFactor = vsizeFactor * 0.8; foreach (Vertex v in GraphToVisualize.Vertices) { VertexControl VC = graphLayout.GetVertexControl(v); VC.FontSize = vertexSize; VC.FontWeight = FontWeights.UltraBold; VC.MinWidth = vertexSize; VC.MinHeight = vertexSize; //VC.Padding = new Thickness(5, 10, 5, 10); } /// Set edges foreach (WeightedEdge <object> e in GraphToVisualize.Edges) { EdgeControl EC = graphLayout.GetEdgeControl(e); EC.FontSize = fsizeFactor; EC.FontWeight = FontWeights.SemiBold; EC.StrokeThickness = esizeFactor; } }
private void FillVisioGraphWithGraph(Graph graph) { this.VisioGraph = new BidirectionalGraph<object, IEdge<object>>(); foreach (var edge in graph.Edges) { this.VisioGraph.AddVerticesAndEdge(new MyEdge(edge.VerticeFrom, edge.VerticeTo, edge.Weight.ToString(CultureInfo.InvariantCulture), Colors.Silver)); } this.graphLayout.Graph = this.VisioGraph; // get some extra space between vertices var overlapRemoval = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapRemoval.HorizontalGap = 50; overlapRemoval.VerticalGap = 50; this.graphLayout.OverlapRemovalParameters = overlapRemoval; }
private void SetupVisioTree() { this.VisioTree = new BidirectionalGraph<object, IEdge<object>>(); var overlapRemoval = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapRemoval.HorizontalGap = 50; overlapRemoval.VerticalGap = 50; this.treeLayout.OverlapRemovalParameters = overlapRemoval; this.treeLayout.Graph = null; }
public MainWindow() { //var g = new BidirectionalGraph<object, IEdge<object>>(); //IList<Object> vertices = new List<Object>(); //for (int i = 0; i < 6; i++) //{ // vertices.Add(i.ToString()); //} //for (int i = 0; i < 5; i++) //{ // Color edgeColor = (i%2 == 0) ? Colors.Black : Colors.Red; // Console.WriteLine(edgeColor); // g.AddVerticesAndEdge(new MyEdge(vertices[i], vertices[i + 1]) // { // Id = i.ToString(), // EdgeColor = edgeColor // }); //} //Graph = g; //Console.WriteLine(Graph.VertexCount); //Console.WriteLine(Graph.EdgeCount); var g = new BidirectionalGraph <object, TaggedEdge <object, object> >(); Graph gr = new Graph("C:\\Users\\Deliany\\Desktop\\AI\\graph_matrix.txt"); List <Edge> pss = new List <Edge>(); foreach (var vert in gr.vertices) { g.AddVertex(vert.Name); } foreach (var edge in gr.edges) { //if (!pss.Contains(new Edge{VerticeFrom = edge.VerticeTo,VerticeTo = edge.VerticeFrom,Weight = edge.Weight})) { g.AddEdge(new TaggedEdge <object, object>(edge.VerticeFrom.Name, edge.VerticeTo.Name, edge.Weight.ToString())); pss.Add(edge); } } //add the vertices to the graph //Person[] vertices = new Person[26]; //for (int i = 0; i < 26; i++) //{ // char letter = (char)(65 + i); // vertices[i] = new Person { FirstName = letter.ToString(), LastName = "" }; // g.AddVertex(vertices[i]); //} //Random r = new Random(); //for (int i = 0; i < 26; i++) //{ // g.AddEdge(new TaggedEdge<object, object>(vertices[i], vertices[r.Next(25)], (300+r.Next(300)).ToString())); //} //add some edges to the graph //g.AddEdge(new TaggedEdge<object, object>(vertices[0], vertices[1], "479")); //g.AddEdge(new TaggedEdge<object, object>(vertices[1], vertices[2], "123")); //g.AddEdge(new TaggedEdge<object, object>(vertices[2], vertices[3], "325")); //g.AddEdge(new TaggedEdge<object, object>(vertices[3], vertices[1], "556")); //g.AddEdge(new TaggedEdge<object, object>(vertices[1], vertices[4], "238")); this.Graph = g; // InitializeComponent(); GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters overlapRemoval = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapRemoval.HorizontalGap = 50; overlapRemoval.VerticalGap = 50; graphLayout.OverlapRemovalParameters = overlapRemoval; }
private void initGraphButton_Click(object sender, EventArgs e) { graph = new NodeGraph(); try { adjmatrix = Helper.MatrixFromString(matrixBox.Text); } catch (FormatException ex) { MessageBox.Show(ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int nodeCount = adjmatrix.GetLength(0); vertices = new Vertex[nodeCount]; for (int k = 0; k < nodeCount; k++) { vertices[k] = new Vertex(k.ToString(), 1.0, 0); graph.AddVertex(vertices[k]); } //dreadnaut für orbits starten string dreadnautcmd = "n=" + nodeCount + " g "; for (int irow = 0; irow < nodeCount; irow++) { for (int icol = 0; icol < nodeCount; icol++) { if (adjmatrix[irow, icol] != 0) { graph.AddEdge(new Edge<Vertex>(vertices[irow], vertices[icol])); dreadnautcmd += icol + " "; } } dreadnautcmd += ";"; } dreadnautcmd += "x o q"; string path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "dreadnaut.exe"); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.UseShellExecute = false; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.FileName = path; Process process = new Process(); process.StartInfo = startInfo; try { System.IO.File.WriteAllBytes(path, ClusterNum.Properties.Resources.dreadnaut); process.Start(); } catch (Exception ex) { MessageBox.Show("dreadnaut konnte nicht gestartet werden", "dreadnaut-Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } process.StandardInput.WriteLine(dreadnautcmd); process.WaitForExit(); System.IO.File.Delete(path); string ergebnis = process.StandardOutput.ReadToEnd(); //cluster auslesen cluster = Helper.dreadnaut2cluster(ergebnis); rmsChart.Series.Clear(); gseries = new Series[nodeCount]; clusterBox.Text = ""; for (int nodenum = 0; nodenum < nodeCount; nodenum++) { gseries[nodenum] = new Series(); gseries[nodenum].IsVisibleInLegend = false; gseries[nodenum].ChartArea = "ChartArea1"; rmsChart.Series.Add(gseries[nodenum]); } for (int i = 0; i < cluster.Length; i++) { clusterBox.Text += "Cluster " + i + " mit Knoten: "; foreach (int k in cluster[i]) { clusterBox.Text += +k + " "; vertices[k].Cluster = i; } clusterBox.Text += "\r\n"; System.Windows.Media.Color coltmp = Vertex.cluster_colors[i % Vertex.cluster_colors.Length]; foreach (int nodenum in cluster[i]) { if (nodenum == cluster[i][0]) { gseries[nodenum].LegendText = "Cluster " + i.ToString(); gseries[nodenum].IsVisibleInLegend = true; } gseries[nodenum].BorderWidth = 2; gseries[nodenum].ChartType = SeriesChartType.FastLine; gseries[nodenum].Color = Color.FromArgb(255, coltmp.R, coltmp.G, coltmp.B); } } //Tmat erstellen if (networkDropdown.SelectedIndex == 3) { //nutze relativkoordinaten wenn custom ausgewählt TMat = Helper.TMat(cluster); } else {//nutze eingespeicherte TMat = Helper.TMat(networkDropdown.SelectedIndex); } //Parameter für die anordnung. einfach irgendwelche genommen. nochmal drüber nachdenken/nachlesen GraphControl = new GraphSharpControl(); GraphControl.layout.LayoutMode = LayoutMode.Simple; GraphControl.layout.LayoutAlgorithmType = "CompoundFDP"; GraphSharp.Algorithms.Layout.Compound.FDP.CompoundFDPLayoutParameters layoutParam = new GraphSharp.Algorithms.Layout.Compound.FDP.CompoundFDPLayoutParameters(); layoutParam.ElasticConstant *= 1.5; GraphControl.layout.LayoutParameters = layoutParam; GraphControl.layout.OverlapRemovalConstraint = AlgorithmConstraints.Must; GraphControl.layout.OverlapRemovalAlgorithmType = "FSA"; GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters overlapParam = new GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters(); overlapParam.HorizontalGap = 25; overlapParam.VerticalGap = 25; GraphControl.layout.OverlapRemovalParameters = overlapParam; GraphControl.layout.HighlightAlgorithmType = "Simple"; GraphControl.layout.Graph = graph; elementHost1.Child = GraphControl; graph_loaded = true; iterator_init(); runButton.Enabled = true; iterateButton.Enabled = true; layoutButton.Enabled = true; betaRunButton.Enabled = true; }