Changeset 14244 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0pre/HeuristicLab.Igraph0.8.0pre/Wrappers/Graph.cs
 Timestamp:
 08/08/16 20:48:54 (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0pre/HeuristicLab.Igraph0.8.0pre/Wrappers/Graph.cs
r14234 r14244 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 20022016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 4 namespace HeuristicLab. igraph.Wrappers {5 public class Graph : IDisposable {25 namespace HeuristicLab.IGraph.Wrappers { 26 public sealed class Graph : IDisposable { 6 27 private igraph_t graph; 28 internal igraph_t NativeInstance { get { return graph; } } 29 7 30 public int Vertices { get { return graph.n; } } 31 public bool IsDirected { get { return graph.directed; } } 8 32 9 33 public Graph() : this(0) { } … … 39 63 } 40 64 41 public double[,] LayoutWithFruchtermanReingold() { 42 return LayoutWithFruchtermanReingold(500, Math.Sqrt(Vertices)); 65 public double Density() { 66 double density; 67 DllImporter.igraph_density(graph, out density, false); 68 return density; 43 69 } 44 public double[,] LayoutWithFruchtermanReingold(int niter, double startTemp) { 45 using (var coords = new Matrix(graph.n, 2)) { 46 DllImporter.igraph_layout_fruchterman_reingold(graph, coords.NativeInstance, false, niter, startTemp, igraph_layout_grid_t.IGRAPH_LAYOUT_AUTOGRID, null, null, null, null, null); 47 return coords.ToMatrix(); 70 71 public Vector PageRank(double damping = 0.85, Vector weights = null) { 72 var vec = new Vector(Vertices); 73 var all = new igraph_vs_t(); 74 DllImporter.igraph_vs_all(ref all); 75 try { 76 double eigenv = 0; 77 DllImporter.igraph_pagerank(graph, igraph_pagerank_algo_t.IGRAPH_PAGERANK_ALGO_PRPACK, vec.NativeInstance, out eigenv, all, IsDirected, damping, weights != null ? weights.NativeInstance : null); 78 } finally { 79 DllImporter.igraph_vs_destroy(ref all); 48 80 } 81 return vec; 82 } 83 84 public Matrix LayoutWithFruchtermanReingold(Matrix initialCoords = null) { 85 return LayoutWithFruchtermanReingold(500, Math.Sqrt(Vertices), initialCoords); 86 } 87 public Matrix LayoutWithFruchtermanReingold(int niter, double startTemp, Matrix initialCoords = null) { 88 if (initialCoords != null && (initialCoords.Rows != graph.n  initialCoords.Columns != 2)) 89 throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords"); 90 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(graph.n, 2); 91 DllImporter.igraph_layout_fruchterman_reingold(graph, coords.NativeInstance, initialCoords != null, niter, startTemp, igraph_layout_grid_t.IGRAPH_LAYOUT_AUTOGRID, null, null, null, null, null); 92 return coords; 93 } 94 95 public Matrix LayoutWithKamadaKawai(Matrix initialCoords = null) { 96 return LayoutWithKamadaKawai(50 * Vertices, 0, Vertices, initialCoords); 97 } 98 public Matrix LayoutWithKamadaKawai(int maxiter, double epsilon, double kkconst, Matrix initialCoords = null) { 99 if (initialCoords != null && (initialCoords.Rows != graph.n  initialCoords.Columns != 2)) 100 throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords"); 101 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(graph.n, 2); 102 DllImporter.igraph_layout_kamada_kawai(graph, coords.NativeInstance, initialCoords != null, maxiter, epsilon, kkconst, null, null, null, null, null); 103 return coords; 104 } 105 106 public Matrix LayoutWithDavidsonHarel(Matrix initialCoords = null) { 107 var density = Density(); 108 return LayoutWithDavidsonHarel(10, Math.Max(10, (int)Math.Log(Vertices, 2)), 0.75, 1.0, 0.0, density / 10.0, 1.0  Math.Sqrt(density), 0.2 * (1  density), initialCoords); 109 } 110 public Matrix LayoutWithDavidsonHarel(int maxiter, int fineiter, double cool_fact, double weight_node_dist, double weight_border, double weight_edge_lengths, double weight_edge_crossings, double weight_node_edge_dist, Matrix initialCoords = null) { 111 if (initialCoords != null && (initialCoords.Rows != graph.n  initialCoords.Columns != 2)) 112 throw new ArgumentException("Initial coordinate matrix does not contain the required number of rows and columns.", "initialCoords"); 113 var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(graph.n, 2); 114 DllImporter.igraph_layout_davidson_harel(graph, coords.NativeInstance, initialCoords != null, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist); 115 return coords; 49 116 } 50 117 }
Note: See TracChangeset
for help on using the changeset viewer.