Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14245


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

#2651: worked on igraph integration

Location:
trunk/sources
Files:
9 edited

Legend:

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

    r14244 r14245  
    4949  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    5050  internal class igraph_matrix_t {
    51     igraph_vector_t data = new igraph_vector_t();
     51    internal igraph_vector_t data = new igraph_vector_t();
    5252    internal int nrow;
    5353    internal int ncol;
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/DllImporter.cs

    r14244 r14245  
    8787      arpackoptions.nev = 1;
    8888      arpackoptions.ishift = 1;
    89       arpackoptions.mxiter = 3000;
     89      arpackoptions.mxiter = 1000;
    9090      arpackoptions.nb = 1;
    9191      arpackoptions.mode = 1;
     
    168168      return X86 ? igraph_vector_init_x86(vector, length) : igraph_vector_init_x64(vector, length);
    169169    }
     170    internal static int igraph_vector_init_copy(igraph_vector_t vector, double[] vec) {
     171      return X86 ? igraph_vector_init_copy_x86(vector, vec, vec.Length) : igraph_vector_init_copy_x64(vector, vec, vec.Length);
     172    }
    170173    internal static void igraph_vector_destroy(igraph_vector_t vector) {
    171174      if (X86) igraph_vector_destroy_x86(vector);
     
    175178      return X86 ? igraph_vector_copy_x86(to, from) : igraph_vector_copy_x64(to, from);
    176179    }
     180    internal static double[] igraph_vector_to_array(igraph_vector_t from) {
     181      var len = igraph_vector_size(from);
     182      var result = new double[len];
     183      if (X86) igraph_vector_copy_to_x86(from, result);
     184      else igraph_vector_copy_to_x64(from, result);
     185      return result;
     186    }
    177187
    178188    internal static int igraph_vector_size(igraph_vector_t vector) {
     
    187197      if (X86) igraph_vector_set_x86(vector, index, value);
    188198      else igraph_vector_set_x64(vector, index, value);
     199    }
     200    internal static void igraph_vector_fill(igraph_vector_t vector, double v) {
     201      if (X86) igraph_vector_fill_x86(vector, v);
     202      else igraph_vector_fill_x64(vector, v);
     203    }
     204    internal static void igraph_vector_scale(igraph_vector_t vector, double by) {
     205      if (X86) igraph_vector_scale_x86(vector, by);
     206      else igraph_vector_scale_x64(vector, by);
     207    }
     208
     209    internal static int igraph_vector_reverse(igraph_vector_t vector) {
     210      return X86 ? igraph_vector_reverse_x86(vector) : igraph_vector_reverse_x64(vector);
     211    }
     212    internal static int igraph_vector_shuffle(igraph_vector_t vector) {
     213      return X86 ? igraph_vector_shuffle_x86(vector) : igraph_vector_shuffle_x64(vector);
    189214    }
    190215
     
    194219    [DllImport(X64Dll, EntryPoint = "igraph_vector_init", CallingConvention = CallingConvention.Cdecl)]
    195220    private static extern int igraph_vector_init_x64([In, Out]igraph_vector_t vector, int length);
     221    [DllImport(X86Dll, EntryPoint = "igraph_vector_init_copy", CallingConvention = CallingConvention.Cdecl)]
     222    private static extern int igraph_vector_init_copy_x86([In, Out]igraph_vector_t vector, double[] vec, int length);
     223    [DllImport(X64Dll, EntryPoint = "igraph_vector_init_copy", CallingConvention = CallingConvention.Cdecl)]
     224    private static extern int igraph_vector_init_copy_x64([In, Out]igraph_vector_t vector, double[] vec, int length);
    196225    [DllImport(X86Dll, EntryPoint = "igraph_vector_destroy", CallingConvention = CallingConvention.Cdecl)]
    197226    private static extern void igraph_vector_destroy_x86([In, Out]igraph_vector_t vector);
     
    214243    [DllImport(X64Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)]
    215244    private static extern int igraph_vector_copy_x64([In, Out]igraph_vector_t to, igraph_vector_t from);
     245    [DllImport(X86Dll, EntryPoint = "igraph_vector_copy_to", CallingConvention = CallingConvention.Cdecl)]
     246    private static extern void igraph_vector_copy_to_x86(igraph_vector_t from, [In, Out]double[] to);
     247    [DllImport(X64Dll, EntryPoint = "igraph_vector_copy", CallingConvention = CallingConvention.Cdecl)]
     248    private static extern void igraph_vector_copy_to_x64(igraph_vector_t from, [In, Out]double[] to);
     249    [DllImport(X86Dll, EntryPoint = "igraph_vector_fill", CallingConvention = CallingConvention.Cdecl)]
     250    private static extern int igraph_vector_fill_x86([In, Out]igraph_vector_t vector, double v);
     251    [DllImport(X64Dll, EntryPoint = "igraph_vector_fill", CallingConvention = CallingConvention.Cdecl)]
     252    private static extern int igraph_vector_fill_x64([In, Out]igraph_vector_t vector, double v);
     253    [DllImport(X86Dll, EntryPoint = "igraph_vector_reverse", CallingConvention = CallingConvention.Cdecl)]
     254    private static extern int igraph_vector_reverse_x86([In, Out]igraph_vector_t vector);
     255    [DllImport(X64Dll, EntryPoint = "igraph_vector_reverse", CallingConvention = CallingConvention.Cdecl)]
     256    private static extern int igraph_vector_reverse_x64([In, Out]igraph_vector_t vector);
     257    [DllImport(X86Dll, EntryPoint = "igraph_vector_shuffle", CallingConvention = CallingConvention.Cdecl)]
     258    private static extern int igraph_vector_shuffle_x86([In, Out]igraph_vector_t vector);
     259    [DllImport(X64Dll, EntryPoint = "igraph_vector_shuffle", CallingConvention = CallingConvention.Cdecl)]
     260    private static extern int igraph_vector_shuffle_x64([In, Out]igraph_vector_t vector);
     261    [DllImport(X86Dll, EntryPoint = "igraph_vector_scale", CallingConvention = CallingConvention.Cdecl)]
     262    private static extern void igraph_vector_scale_x86([In, Out]igraph_vector_t vector, double by);
     263    [DllImport(X64Dll, EntryPoint = "igraph_vector_scale", CallingConvention = CallingConvention.Cdecl)]
     264    private static extern void igraph_vector_scale_x64([In, Out]igraph_vector_t vector, double by);
    216265    #endregion
    217266    #endregion
     
    236285      if (X86) igraph_matrix_set_x86(matrix, row, col, value);
    237286      else igraph_matrix_set_x64(matrix, row, col, value);
     287    }
     288
     289    internal static void igraph_matrix_fill(igraph_matrix_t matrix, double v) {
     290      if (X86) igraph_matrix_fill_x86(matrix, v);
     291      else igraph_matrix_fill_x64(matrix, v);
     292    }
     293
     294    internal static int igraph_matrix_transpose(igraph_matrix_t matrix) {
     295      return X86 ? igraph_matrix_transpose_x86(matrix) : igraph_matrix_transpose_x64(matrix);
     296    }
     297
     298    internal static void igraph_matrix_scale(igraph_matrix_t matrix, double by) {
     299      if (X86) igraph_matrix_scale_x86(matrix, by);
     300      else igraph_matrix_scale_x64(matrix, by);
    238301    }
    239302
     
    259322    [DllImport(X64Dll, EntryPoint = "igraph_matrix_copy", CallingConvention = CallingConvention.Cdecl)]
    260323    private static extern int igraph_matrix_copy_x64([In, Out]igraph_matrix_t to, igraph_matrix_t from);
     324    [DllImport(X86Dll, EntryPoint = "igraph_matrix_fill", CallingConvention = CallingConvention.Cdecl)]
     325    private static extern void igraph_matrix_fill_x86([In, Out]igraph_matrix_t matrix, double v);
     326    [DllImport(X64Dll, EntryPoint = "igraph_matrix_fill", CallingConvention = CallingConvention.Cdecl)]
     327    private static extern void igraph_matrix_fill_x64([In, Out]igraph_matrix_t matrix, double v);
     328    [DllImport(X86Dll, EntryPoint = "igraph_matrix_transpose", CallingConvention = CallingConvention.Cdecl)]
     329    private static extern int igraph_matrix_transpose_x86([In, Out]igraph_matrix_t matrix);
     330    [DllImport(X64Dll, EntryPoint = "igraph_matrix_transpose", CallingConvention = CallingConvention.Cdecl)]
     331    private static extern int igraph_matrix_transpose_x64([In, Out]igraph_matrix_t matrix);
     332    [DllImport(X86Dll, EntryPoint = "igraph_matrix_scale", CallingConvention = CallingConvention.Cdecl)]
     333    private static extern int igraph_matrix_scale_x86([In, Out]igraph_matrix_t matrix, double by);
     334    [DllImport(X64Dll, EntryPoint = "igraph_matrix_scale", CallingConvention = CallingConvention.Cdecl)]
     335    private static extern int igraph_matrix_scale_x64([In, Out]igraph_matrix_t matrix, double by);
    261336    #endregion
    262337    #endregion
     
    271346    internal static int igraph_layout_davidson_harel(igraph_t graph, igraph_matrix_t res, bool use_seed, 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) {
    272347      return X86 ? igraph_layout_davidson_harel_x86(graph, res, use_seed, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist) : igraph_layout_davidson_harel_x64(graph, res, use_seed, maxiter, fineiter, cool_fact, weight_node_dist, weight_border, weight_edge_lengths, weight_edge_crossings, weight_node_edge_dist);
     348    }
     349    internal static int igraph_layout_mds(igraph_t graph, igraph_matrix_t res, igraph_matrix_t dist = null, int dim = 2) {
     350      var arpackoptions = GetDefaultArpackOptions();
     351      var options = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(igraph_arpack_options_t)));
     352      Marshal.StructureToPtr(arpackoptions, options, false);
     353      try {
     354        return X86 ? igraph_layout_mds_x86(graph, res, dist, dim, options) : igraph_layout_mds_x64(graph, res, dist, dim, options);
     355      } finally {
     356        Marshal.DestroyStructure(options, typeof(igraph_arpack_options_t));
     357        Marshal.FreeHGlobal(options);
     358      }
    273359    }
    274360
     
    286372    [DllImport(X64Dll, EntryPoint = "igraph_layout_davidson_harel", CallingConvention = CallingConvention.Cdecl)]
    287373    private static extern int igraph_layout_davidson_harel_x64(igraph_t graph, [In, Out]igraph_matrix_t res, bool use_seed, 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);
     374    [DllImport(X86Dll, EntryPoint = "igraph_layout_mds", CallingConvention = CallingConvention.Cdecl)]
     375    private static extern int igraph_layout_mds_x86(igraph_t graph, [In, Out]igraph_matrix_t res, igraph_matrix_t dist, int dim, IntPtr options);
     376    [DllImport(X64Dll, EntryPoint = "igraph_layout_mds", CallingConvention = CallingConvention.Cdecl)]
     377    private static extern int igraph_layout_mds_x64(igraph_t graph, [In, Out]igraph_matrix_t res, igraph_matrix_t dist, int dim, IntPtr options);
    288378    #endregion
    289379    #endregion
  • 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  }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphLayoutTest.cs

    r14244 r14245  
    2929  public class IGraphLayoutTest {
    3030    [TestMethod]
    31     public void TestFruchtermanReingold() {
     31    [TestCategory("ExtLibs")]
     32    [TestCategory("igraph")]
     33    [TestProperty("Time", "short")]
     34    public void FruchtermanReingoldLayoutTest() {
    3235      var graph = new Graph(5, new[] {
    3336        Tuple.Create(0, 1),
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersGraphTest.cs

    r14244 r14245  
    2929  public class IGraphWrappersGraphTest {
    3030    [TestMethod]
     31    [TestCategory("ExtLibs")]
     32    [TestCategory("igraph")]
     33    [TestProperty("Time", "short")]
    3134    public void IGraphWrappersGraphConstructionAndFinalization() {
    3235      var graph = new Graph(5, new[] {
     
    5154
    5255    [TestMethod]
     56    [TestCategory("ExtLibs")]
     57    [TestCategory("igraph")]
     58    [TestProperty("Time", "short")]
    5359    public void TestDensity() {
    5460      var graph = new Graph(5, new[] {
     
    8288
    8389    [TestMethod]
     90    [TestCategory("ExtLibs")]
     91    [TestCategory("igraph")]
     92    [TestProperty("Time", "short")]
    8493    public void TestPageRank() {
    8594      var graph = new Graph(4, new[] {
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersMatrixTest.cs

    r14244 r14245  
    2727  public class IGraphWrappersMatrixTest {
    2828    [TestMethod]
     29    [TestCategory("ExtLibs")]
     30    [TestCategory("igraph")]
     31    [TestProperty("Time", "short")]
    2932    public void IGraphWrappersMatrixConstructionAndFinalization() {
    3033      var matrix = new Matrix(3, 2);
     
    3740      Assert.AreEqual(2, other.Columns);
    3841      Assert.AreEqual(4, other[0, 0]);
     42
     43      var mat = new double[,] {
     44        { 1, 2, 3 },
     45        { 4, 5, 6}
     46      };
     47      matrix = new Matrix(mat);
     48      Assert.AreEqual(2, matrix.Rows);
     49      Assert.AreEqual(3, matrix.Columns);
     50      var test = matrix.ToMatrix();
     51      for (var i = 0; i < matrix.Rows; i++)
     52        for (var j = 0; j < matrix.Columns; j++) {
     53          Assert.AreEqual(mat[i, j], matrix[i, j]);
     54          Assert.AreEqual(mat[i, j], test[i, j]);
     55        }
    3956    }
    4057
    4158    [TestMethod]
     59    [TestCategory("ExtLibs")]
     60    [TestCategory("igraph")]
     61    [TestProperty("Time", "short")]
    4262    public void IGraphWrappersMatrixGetSetTest() {
    4363      var matrix = new Matrix(3, 2);
     
    6181          Assert.AreEqual(matrix[i, j], netmat[i, j]);
    6282    }
     83
     84    [TestMethod]
     85    [TestCategory("ExtLibs")]
     86    [TestCategory("igraph")]
     87    [TestProperty("Time", "short")]
     88    public void IGraphWrappersMatrixFill() {
     89      var matrix = new Matrix(3, 2);
     90      matrix.Fill(2.6);
     91      Assert.AreEqual(2.6, matrix[0, 0]);
     92      Assert.AreEqual(2.6, matrix[0, 1]);
     93      Assert.AreEqual(2.6, matrix[1, 0]);
     94      Assert.AreEqual(2.6, matrix[1, 1]);
     95      Assert.AreEqual(2.6, matrix[2, 0]);
     96      Assert.AreEqual(2.6, matrix[2, 1]);
     97    }
     98
     99    [TestMethod]
     100    [TestCategory("ExtLibs")]
     101    [TestCategory("igraph")]
     102    [TestProperty("Time", "short")]
     103    public void IGraphWrappersMatrixTranspose() {
     104      var matrix = new Matrix(3, 2);
     105      matrix.Transpose();
     106      Assert.AreEqual(2, matrix.Rows);
     107      Assert.AreEqual(3, matrix.Columns);
     108    }
     109
     110    [TestMethod]
     111    [TestCategory("ExtLibs")]
     112    [TestCategory("igraph")]
     113    [TestProperty("Time", "short")]
     114    public void IGraphWrappersMatrixScale() {
     115      var matrix = new Matrix(3, 2);
     116      matrix[0, 0] = matrix[0, 1] = 4;
     117      matrix[1, 0] = 3;
     118      matrix[1, 1] = 2;
     119      matrix[2, 0] = 1.5;
     120      matrix[2, 1] = -0.5;
     121      matrix.Scale(2);
     122      Assert.AreEqual(8, matrix[0, 0]);
     123      Assert.AreEqual(8, matrix[0, 1]);
     124      Assert.AreEqual(6, matrix[1, 0]);
     125      Assert.AreEqual(4, matrix[1, 1]);
     126      Assert.AreEqual(3, matrix[2, 0]);
     127      Assert.AreEqual(-1, matrix[2, 1]);
     128    }
    63129  }
    64130}
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersVectorTest.cs

    r14244 r14245  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.IGraph.Wrappers;
    2324using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    2728  public class IGraphWrappersVectorTest {
    2829    [TestMethod]
     30    [TestCategory("ExtLibs")]
     31    [TestCategory("igraph")]
     32    [TestProperty("Time", "short")]
    2933    public void IGraphWrappersVectorConstructionAndFinalization() {
    3034      var vector = new Vector(7);
     
    3539      Assert.AreEqual(7, other.Length);
    3640      Assert.AreEqual(4, other[0]);
     41
     42      var myvec = new double[] { 1, 2, 3 };
     43      vector = new Vector(myvec);
     44      Assert.AreEqual(3, vector.Length);
     45      Assert.AreEqual(myvec[0], vector[0]);
     46      Assert.AreEqual(myvec[1], vector[1]);
     47      Assert.AreEqual(myvec[2], vector[2]);
    3748    }
    3849
    3950    [TestMethod]
     51    [TestCategory("ExtLibs")]
     52    [TestCategory("igraph")]
     53    [TestProperty("Time", "short")]
    4054    public void IGraphWrappersVectorGetSetTest() {
    4155      var vector = new Vector(5);
     
    5569        Assert.AreEqual(vector[i], netmat[i]);
    5670    }
     71
     72    [TestMethod]
     73    [TestCategory("ExtLibs")]
     74    [TestCategory("igraph")]
     75    [TestProperty("Time", "short")]
     76    public void IGraphWrappersVectorFillTest() {
     77      var vector = new Vector(5);
     78      vector.Fill(2.3);
     79      Assert.IsTrue(new[] { 2.3, 2.3, 2.3, 2.3, 2.3 }.SequenceEqual(vector.ToArray()));
     80    }
     81
     82    [TestMethod]
     83    [TestCategory("ExtLibs")]
     84    [TestCategory("igraph")]
     85    [TestProperty("Time", "short")]
     86    public void IGraphWrappersVectorReverseTest() {
     87      var vector = new Vector(5);
     88      vector[0] = vector[1] = 4;
     89      vector[2] = 3;
     90      vector[3] = 1.5;
     91      vector[4] = -0.5;
     92      vector.Reverse();
     93      Assert.IsTrue(new[] { -0.5, 1.5, 3, 4, 4 }.SequenceEqual(vector.ToArray()));
     94    }
     95
     96    [TestMethod]
     97    [TestCategory("ExtLibs")]
     98    [TestCategory("igraph")]
     99    [TestProperty("Time", "short")]
     100    public void IGraphWrappersVectorShuffleTest() {
     101      var vector = new Vector(5);
     102      vector[0] = vector[1] = 4;
     103      vector[2] = 3;
     104      vector[3] = 1.5;
     105      vector[4] = -0.5;
     106      vector.Shuffle();
     107      Assert.IsFalse(new[] { -0.5, 1.5, 3, 4, 4 }.SequenceEqual(vector.ToArray()));
     108      Assert.IsFalse(new[] { 4, 4, 3, 1.5, -0.5 }.SequenceEqual(vector.ToArray()));
     109    }
     110
     111    [TestMethod]
     112    [TestCategory("ExtLibs")]
     113    [TestCategory("igraph")]
     114    [TestProperty("Time", "short")]
     115    public void IGraphWrappersVectorScaleTest() {
     116      var vector = new Vector(5);
     117      vector[0] = vector[1] = 4;
     118      vector[2] = 3;
     119      vector[3] = 1.5;
     120      vector[4] = -0.5;
     121      vector.Scale(2);
     122      Assert.IsTrue(new double[] { 8, 8, 6, 3, -1 }.SequenceEqual(vector.ToArray()));
     123    }
    57124  }
    58125}
Note: See TracChangeset for help on using the changeset viewer.