Changeset 14247
- Timestamp:
- 08/09/16 13:49:01 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Datatypes.cs
r14245 r14247 128 128 #endregion 129 129 130 #region Delegates 131 [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] 132 internal delegate bool igraph_bfshandler_t(igraph_t graph, int vid, int pred, int succ, int rank, int dist, IntPtr extra); 133 134 [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] 135 internal delegate bool igraph_dfshandler_t(igraph_t graph, int vid, int dist, IntPtr extra); 136 #endregion 137 130 138 #region Enums 131 139 internal enum igraph_layout_grid_t { -
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/DllImporter.cs
r14245 r14247 21 21 22 22 using System; 23 using System.IO; 23 24 using System.Runtime.InteropServices; 24 25 … … 29 30 private readonly static bool X86 = false; 30 31 32 [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 33 private static extern bool SetDllDirectory(string lpPathName); 34 31 35 static DllImporter() { 32 36 X86 = !Environment.Is64BitProcess; 37 // Possible workaround as the builder doesn't execute the tests within the bin directory 38 if (Directory.Exists(Path.Combine(Environment.CurrentDirectory, "bin"))) 39 SetDllDirectory(Path.Combine(Environment.CurrentDirectory, "bin")); 33 40 } 34 41 … … 109 116 internal static int igraph_add_edge(igraph_t graph, int from, int to) { 110 117 return X86 ? igraph_add_edge_x86(graph, from, to) : igraph_add_edge_x64(graph, from, to); 118 } 119 #endregion 120 121 #region igraph visits 122 internal static int igraph_bfs(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, igraph_vector_t order, igraph_vector_t rank, igraph_vector_t father, igraph_vector_t pred, igraph_vector_t succ, igraph_vector_t dist, igraph_bfshandler_t callback, object tag) { 123 return MarshalIfExistsAndCall(tag, ptr => X86 ? igraph_bfs_x86(graph, root, roots, mode, unreachable, restricted, order, rank, father, pred, succ, dist, callback, ptr) : igraph_bfs_x64(graph, root, roots, mode, unreachable, restricted, order, rank, father, pred, succ, dist, callback, ptr)); 124 } 125 internal static int igraph_dfs(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, igraph_vector_t order, igraph_vector_t order_out, igraph_vector_t father, igraph_vector_t dist, igraph_dfshandler_t inWrapper, igraph_dfshandler_t outWrapper, object tag) { 126 return MarshalIfExistsAndCall(tag, ptr => X86 ? igraph_dfs_x86(graph, root, mode, unreachable, order, order_out, father, dist, inWrapper, outWrapper, ptr) : igraph_dfs_x64(graph, root, mode, unreachable, order, order_out, father, dist, inWrapper, outWrapper, ptr)); 111 127 } 112 128 #endregion … … 137 153 [DllImport(X64Dll, EntryPoint = "igraph_pagerank", CallingConvention = CallingConvention.Cdecl)] 138 154 private static extern int igraph_pagerank_x64(igraph_t graph, igraph_pagerank_algo_t algo, [In, Out]igraph_vector_t vector, ref double value, igraph_vs_t vids, bool directed, double damping, igraph_vector_t weights, IntPtr options); 155 [DllImport(X86Dll, EntryPoint = "igraph_bfs", CallingConvention = CallingConvention.Cdecl)] 156 private static extern int igraph_bfs_x86(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t rank, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t pred, [In, Out]igraph_vector_t succ, [In, Out]igraph_vector_t dist, igraph_bfshandler_t callback, IntPtr extra); 157 [DllImport(X64Dll, EntryPoint = "igraph_bfs", CallingConvention = CallingConvention.Cdecl)] 158 private static extern int igraph_bfs_x64(igraph_t graph, int root, igraph_vector_t roots, igraph_neimode_t mode, bool unreachable, igraph_vector_t restricted, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t rank, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t pred, [In, Out]igraph_vector_t succ, [In, Out]igraph_vector_t dist, igraph_bfshandler_t callback, IntPtr extra); 159 [DllImport(X86Dll, EntryPoint = "igraph_dfs", CallingConvention = CallingConvention.Cdecl)] 160 private static extern int igraph_dfs_x86(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t order_out, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t dist, igraph_dfshandler_t in_callback, igraph_dfshandler_t out_callback, IntPtr extra); 161 [DllImport(X64Dll, EntryPoint = "igraph_dfs", CallingConvention = CallingConvention.Cdecl)] 162 private static extern int igraph_dfs_x64(igraph_t graph, int root, igraph_neimode_t mode, bool unreachable, [In, Out]igraph_vector_t order, [In, Out]igraph_vector_t order_out, [In, Out]igraph_vector_t father, [In, Out]igraph_vector_t dist, igraph_dfshandler_t in_callback, igraph_dfshandler_t out_callback, IntPtr extra); 139 163 #endregion 140 164 #endregion … … 348 372 } 349 373 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 } 374 return MarshalIfExistsAndCall(GetDefaultArpackOptions(), ptr => X86 ? igraph_layout_mds_x86(graph, res, dist, dim, ptr) : igraph_layout_mds_x64(graph, res, dist, dim, ptr)); 359 375 } 360 376 … … 399 415 #endregion 400 416 #endregion 417 418 private static int MarshalIfExistsAndCall(object o, Func<IntPtr, int> call) { 419 var ptr = IntPtr.Zero; 420 if (o != null) { 421 try { 422 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(o)); 423 } catch (OutOfMemoryException e) { throw new InvalidOperationException("Not enough memory to perform operation.", e); } 424 Marshal.StructureToPtr(o, ptr, false); 425 } 426 try { 427 return call(ptr); 428 } finally { 429 if (o != null) { 430 Marshal.DestroyStructure(ptr, o.GetType()); 431 Marshal.FreeHGlobal(ptr); 432 } 433 } 434 } 435 436 private static void MarshalIfExistsAndCall(object o, Action<IntPtr> call) { 437 var ptr = IntPtr.Zero; 438 if (o != null) { 439 try { 440 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(o)); 441 } catch (OutOfMemoryException e) { throw new InvalidOperationException("Not enough memory to perform operation.", e); } 442 Marshal.StructureToPtr(o, ptr, false); 443 } 444 try { 445 call(ptr); 446 } finally { 447 if (o != null) { 448 Marshal.DestroyStructure(ptr, o.GetType()); 449 Marshal.FreeHGlobal(ptr); 450 } 451 } 452 } 401 453 } 402 454 } -
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/HeuristicLab.igraph-0.8.0-pre.csproj
r14244 r14247 49 49 <ItemGroup> 50 50 <Compile Include="DllImporter.cs" /> 51 <Compile Include="Wrappers\Datatypes.cs" /> 51 52 <Compile Include="Wrappers\Graph.cs" /> 52 53 <Compile Include="Wrappers\Matrix.cs" /> -
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Igraph/0.8.0-pre/HeuristicLab.Igraph-0.8.0-pre/Wrappers/Graph.cs
r14245 r14247 132 132 return coords; 133 133 } 134 135 public void BreadthFirstWalk(BreadthFirstHandler handler, int root, DirectedWalkMode mode, bool includeUnreachableFromRoot = false, object tag = null) { 136 igraph_bfshandler_t wrapper = (t, vid, pred, succ, rank, dist, extra) => handler != null && handler(this, vid, pred, succ, rank, dist, tag); 137 DllImporter.igraph_bfs(graph, root, null, (igraph_neimode_t)mode, includeUnreachableFromRoot, null, null, null, null, null, null, null, wrapper, tag); 138 } 139 140 public void DepthFirstWalk(DepthFirstHandler inHandler, DepthFirstHandler outHandler, int root, DirectedWalkMode mode, bool includeUnreachableFromRoot = false, object tag = null) { 141 igraph_dfshandler_t inWrapper = (t, vid, dist, extra) => inHandler != null && inHandler(this, vid, dist, tag); 142 igraph_dfshandler_t outWrapper = (t, vid, dist, extra) => outHandler != null && outHandler(this, vid, dist, tag); 143 DllImporter.igraph_dfs(graph, root, (igraph_neimode_t)mode, includeUnreachableFromRoot, null, null, null, null, inWrapper, outWrapper, tag); 144 } 134 145 } 135 146 } -
trunk/sources/HeuristicLab.Tests/Builder.testsettings
r14246 r14247 3 3 <Description>Test settings to run unit tests on the HL build server.</Description> 4 4 <Deployment> 5 <DeploymentItem filename="bin\igraph-0.8.0-pre-x64.dll" />6 5 <DeploymentItem filename="bin\" /> 7 <DeploymentItem filename="bin\igraph-0.8.0-pre-x86.dll" />8 6 </Deployment> 9 7 <Execution hostProcessPlatform="MSIL"> -
trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphLayoutTest.cs
r14245 r14247 32 32 [TestCategory("igraph")] 33 33 [TestProperty("Time", "short")] 34 public void FruchtermanReingoldLayoutTest() {34 public void IGraphWrappersLayoutFruchtermanReingoldTest() { 35 35 var graph = new Graph(5, new[] { 36 36 Tuple.Create(0, 1), -
trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersGraphTest.cs
r14245 r14247 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.IGraph.Wrappers; … … 27 28 namespace HeuristicLab.Tests { 28 29 [TestClass] 30 [DeploymentItem("igraph-0.8.0-pre-x86.dll")] 31 [DeploymentItem("igraph-0.8.0-pre-x64.dll")] 29 32 public class IGraphWrappersGraphTest { 30 33 [TestMethod] … … 32 35 [TestCategory("igraph")] 33 36 [TestProperty("Time", "short")] 34 public void IGraphWrappersGraphConstructionAndFinalization () {37 public void IGraphWrappersGraphConstructionAndFinalizationTest() { 35 38 var graph = new Graph(5, new[] { 36 39 Tuple.Create(0, 1), … … 57 60 [TestCategory("igraph")] 58 61 [TestProperty("Time", "short")] 59 public void TestDensity() {62 public void IGraphWrappersGraphDensityTest() { 60 63 var graph = new Graph(5, new[] { 61 64 Tuple.Create(0, 1), … … 91 94 [TestCategory("igraph")] 92 95 [TestProperty("Time", "short")] 93 public void TestPageRank() {96 public void IGraphWrappersGraphPageRankTest() { 94 97 var graph = new Graph(4, new[] { 95 98 Tuple.Create(0, 1), … … 134 137 Assert.AreEqual(0.173, ranks[3], 0.01); 135 138 } 139 140 [TestMethod] 141 [TestCategory("ExtLibs")] 142 [TestCategory("igraph")] 143 [TestProperty("Time", "short")] 144 public void IGraphWrappersGraphBreadthFirstWalkTest() { 145 var graph = new Graph(4, new[] { 146 Tuple.Create(0, 1), 147 Tuple.Create(0, 2), 148 Tuple.Create(1, 2), 149 Tuple.Create(2, 0), 150 Tuple.Create(3, 2), 151 }, directed: true); 152 var visited = new HashSet<int>(); 153 BreadthFirstHandler handler = (graph1, currentVertexId, previousVertexId, nextVertexId, rank, distance, tag) => { 154 visited.Add(currentVertexId); 155 return false; 156 }; 157 graph.BreadthFirstWalk(handler, 0, DirectedWalkMode.All, true, null); 158 Assert.AreEqual(4, visited.Count); 159 Assert.IsTrue(visited.Contains(0)); 160 Assert.IsTrue(visited.Contains(1)); 161 Assert.IsTrue(visited.Contains(2)); 162 Assert.IsTrue(visited.Contains(3)); 163 } 164 165 [TestMethod] 166 [TestCategory("ExtLibs")] 167 [TestCategory("igraph")] 168 [TestProperty("Time", "short")] 169 public void IGraphWrappersGraphDepthFirstWalkTest() { 170 var graph = new Graph(4, new[] { 171 Tuple.Create(0, 1), 172 Tuple.Create(0, 2), 173 Tuple.Create(1, 2), 174 Tuple.Create(2, 0), 175 Tuple.Create(3, 2), 176 }, directed: true); 177 var visited = new HashSet<int>(); 178 DepthFirstHandler handler = (graph1, vertexId, distance, tag) => { 179 visited.Add(vertexId); 180 return false; 181 }; 182 graph.DepthFirstWalk(handler, handler, 0, DirectedWalkMode.All, true, null); 183 Assert.AreEqual(4, visited.Count); 184 Assert.IsTrue(visited.Contains(0)); 185 Assert.IsTrue(visited.Contains(1)); 186 Assert.IsTrue(visited.Contains(2)); 187 Assert.IsTrue(visited.Contains(3)); 188 } 136 189 } 137 190 } -
trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersMatrixTest.cs
r14245 r14247 30 30 [TestCategory("igraph")] 31 31 [TestProperty("Time", "short")] 32 public void IGraphWrappersMatrixConstructionAndFinalization () {32 public void IGraphWrappersMatrixConstructionAndFinalizationTest() { 33 33 var matrix = new Matrix(3, 2); 34 34 Assert.AreEqual(3, matrix.Rows); … … 86 86 [TestCategory("igraph")] 87 87 [TestProperty("Time", "short")] 88 public void IGraphWrappersMatrixFill () {88 public void IGraphWrappersMatrixFillTest() { 89 89 var matrix = new Matrix(3, 2); 90 90 matrix.Fill(2.6); … … 101 101 [TestCategory("igraph")] 102 102 [TestProperty("Time", "short")] 103 public void IGraphWrappersMatrixTranspose () {103 public void IGraphWrappersMatrixTransposeTest() { 104 104 var matrix = new Matrix(3, 2); 105 105 matrix.Transpose(); … … 112 112 [TestCategory("igraph")] 113 113 [TestProperty("Time", "short")] 114 public void IGraphWrappersMatrixScale () {114 public void IGraphWrappersMatrixScaleTest() { 115 115 var matrix = new Matrix(3, 2); 116 116 matrix[0, 0] = matrix[0, 1] = 4; -
trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersVectorTest.cs
r14245 r14247 31 31 [TestCategory("igraph")] 32 32 [TestProperty("Time", "short")] 33 public void IGraphWrappersVectorConstructionAndFinalization () {33 public void IGraphWrappersVectorConstructionAndFinalizationTest() { 34 34 var vector = new Vector(7); 35 35 Assert.AreEqual(7, vector.Length);
Note: See TracChangeset
for help on using the changeset viewer.