Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/08/16 23:36:49 (8 years ago)
Author:
abeham
Message:

#2651: worked on igraph integration

Location:
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Graph.cs

    r14244 r14245  
    8686    }
    8787    public Matrix LayoutWithFruchtermanReingold(int niter, double startTemp, Matrix initialCoords = null) {
    88       if (initialCoords != null && (initialCoords.Rows != graph.n || initialCoords.Columns != 2))
     88      if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
    8989        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);
     90      var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);
    9191      DllImporter.igraph_layout_fruchterman_reingold(graph, coords.NativeInstance, initialCoords != null, niter, startTemp, igraph_layout_grid_t.IGRAPH_LAYOUT_AUTOGRID, null, null, null, null, null);
    9292      return coords;
     
    9797    }
    9898    public Matrix LayoutWithKamadaKawai(int maxiter, double epsilon, double kkconst, Matrix initialCoords = null) {
    99       if (initialCoords != null && (initialCoords.Rows != graph.n || initialCoords.Columns != 2))
     99      if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
    100100        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);
     101      var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);
    102102      DllImporter.igraph_layout_kamada_kawai(graph, coords.NativeInstance, initialCoords != null, maxiter, epsilon, kkconst, null, null, null, null, null);
    103103      return coords;
     
    109109    }
    110110    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))
     111      if (initialCoords != null && (initialCoords.Rows != Vertices || initialCoords.Columns != 2))
    112112        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);
     113      var coords = initialCoords != null ? new Matrix(initialCoords) : new Matrix(Vertices, 2);
    114114      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;
     116    }
     117
     118    /// <summary>
     119    /// Use multi-dimensional scaling to layout vertices.
     120    /// A distance matrix can be used to specify the distances between the vertices.
     121    /// Otherwise the distances will be calculated by shortest-path-length.
     122    /// </summary>
     123    /// <remarks>
     124    /// For disconnected graphs, dimension must be 2.
     125    /// </remarks>
     126    /// <param name="dist">The distance matrix to layout the vertices.</param>
     127    /// <param name="dim">How many dimensions should be used.</param>
     128    /// <returns>The coordinates matrix of the aligned vertices.</returns>
     129    public Matrix LayoutWithMds(Matrix dist = null, int dim = 2) {
     130      var coords = new Matrix(Vertices, dim);
     131      DllImporter.igraph_layout_mds(graph, coords.NativeInstance, dist != null ? dist.NativeInstance : null, dim);
    115132      return coords;
    116133    }
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Matrix.cs

    r14244 r14245  
    3939      DllImporter.igraph_matrix_copy(matrix, other.NativeInstance);
    4040    }
     41    public Matrix(double[,] mat) {
     42      if (mat == null) throw new ArgumentNullException("mat");
     43      matrix = new igraph_matrix_t();
     44      var nrows = mat.GetLength(0);
     45      var ncols = mat.GetLength(1);
     46      DllImporter.igraph_matrix_init(matrix, nrows, ncols);
     47      var colwise = new double[ncols * nrows];
     48      for (var j = 0; j < ncols; j++)
     49        for (var i = 0; i < nrows; i++)
     50          colwise[j * nrows + i] = mat[i, j];
     51      DllImporter.igraph_vector_init_copy(matrix.data, colwise);
     52    }
    4153    ~Matrix() {
    4254      DllImporter.igraph_matrix_destroy(matrix);
     
    4860      matrix = null;
    4961      GC.SuppressFinalize(this);
     62    }
     63
     64    public void Fill(double v) {
     65      DllImporter.igraph_matrix_fill(matrix, v);
     66    }
     67
     68    public void Transpose() {
     69      DllImporter.igraph_matrix_transpose(matrix);
     70    }
     71
     72    public void Scale(double by) {
     73      DllImporter.igraph_matrix_scale(matrix, by);
    5074    }
    5175
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Vector.cs

    r14244 r14245  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325
    2426namespace HeuristicLab.IGraph.Wrappers {
     
    3941      DllImporter.igraph_vector_init(vector, length);
    4042    }
    41 
     43    public Vector(IEnumerable<double> data) {
     44      if (data == null) throw new ArgumentNullException("data");
     45      var vec = data.ToArray();
     46      vector = new igraph_vector_t();
     47      DllImporter.igraph_vector_init_copy(vector, vec);
     48    }
    4249    public Vector(Vector other) {
    4350      if (other == null) throw new ArgumentNullException("other");
     
    4552      DllImporter.igraph_vector_copy(vector, other.NativeInstance);
    4653    }
    47 
    4854    ~Vector() {
    4955      DllImporter.igraph_vector_destroy(vector);
     
    5561      vector = null;
    5662      GC.SuppressFinalize(this);
     63    }
     64
     65    public void Fill(double v) {
     66      DllImporter.igraph_vector_fill(vector, v);
     67    }
     68
     69    public void Reverse() {
     70      DllImporter.igraph_vector_reverse(vector);
     71    }
     72
     73    public void Shuffle() {
     74      DllImporter.igraph_vector_shuffle(vector);
     75    }
     76
     77    public void Scale(double by) {
     78      DllImporter.igraph_vector_scale(vector, by);
    5779    }
    5880
     
    6991
    7092    public double[] ToArray() {
    71       var result = new double[Length];
    72       for (var i = 0; i < result.Length; i++) {
    73         result[i] = DllImporter.igraph_vector_e(vector, i);
    74       }
    75       return result;
     93      return DllImporter.igraph_vector_to_array(vector);
    7694    }
    7795  }
Note: See TracChangeset for help on using the changeset viewer.