1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.igraph.Wrappers {
|
---|
5 | public class Graph : IDisposable {
|
---|
6 | private igraph_t graph;
|
---|
7 | public int Vertices { get { return graph.n; } }
|
---|
8 |
|
---|
9 | public Graph() : this(0) { }
|
---|
10 | public Graph(int vertices) : this(vertices, false) { }
|
---|
11 | public Graph(int vertices, bool directed) {
|
---|
12 | graph = new igraph_t();
|
---|
13 | DllImporter.igraph_empty(graph, vertices, directed);
|
---|
14 | }
|
---|
15 | public Graph(int vertices, IEnumerable<Tuple<int, int>> edges) : this(vertices, edges, false) { }
|
---|
16 | public Graph(int vertices, IEnumerable<Tuple<int, int>> edges, bool directed) {
|
---|
17 | graph = new igraph_t();
|
---|
18 | DllImporter.igraph_empty(graph, vertices, directed);
|
---|
19 | foreach (var e in edges)
|
---|
20 | DllImporter.igraph_add_edge(graph, e.Item1, e.Item2);
|
---|
21 | }
|
---|
22 | ~Graph() {
|
---|
23 | DllImporter.igraph_destroy(graph);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public void Dispose() {
|
---|
27 | if (graph == null) return;
|
---|
28 | DllImporter.igraph_destroy(graph);
|
---|
29 | graph = null;
|
---|
30 | GC.SuppressFinalize(this);
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void SetSeed(uint seed) {
|
---|
34 | DllImporter.igraph_rng_seed(seed);
|
---|
35 | }
|
---|
36 |
|
---|
37 | public int RandomInteger(int inclLower, int inclUpper) {
|
---|
38 | return DllImporter.igraph_rng_get_integer(inclLower, inclUpper);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public double[,] LayoutWithFruchtermanReingold() {
|
---|
42 | return LayoutWithFruchtermanReingold(500, Math.Sqrt(Vertices));
|
---|
43 | }
|
---|
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();
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|