From 98b5e7c0f9fe8273d9ffbd05e1af5bb2e2567b7e Mon Sep 17 00:00:00 2001 From: smbadiwe Date: Fri, 17 Feb 2017 10:30:08 -0800 Subject: [PATCH] All is well up to this point. The race is now about bringing memory usage down and good successes are being made. Rollback can be to this point --- MODA.Console/MODATest.cs | 1 + MODA.Console/Program.cs | 2 +- MODA.Impl/Mapping.cs | 3 +-- MODA.Impl/MappingNodesComparer.cs | 15 ++++++++++++--- MODA.Impl/ModaAlgorithms.2.cs | 2 +- MODA.Impl/ModaAlgorithms.cs | 26 ++++++++++++++++++++++---- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/MODA.Console/MODATest.cs b/MODA.Console/MODATest.cs index e824844..1060007 100644 --- a/MODA.Console/MODATest.cs +++ b/MODA.Console/MODATest.cs @@ -107,6 +107,7 @@ internal static void Run(string[] args) if (queryGraph == null) { + ModaAlgorithms.UsingAlgo3 = true; ModaAlgorithms.BuildTree(subGraphSize); } #endregion diff --git a/MODA.Console/Program.cs b/MODA.Console/Program.cs index fa9dc74..d48eebf 100644 --- a/MODA.Console/Program.cs +++ b/MODA.Console/Program.cs @@ -6,7 +6,7 @@ static void Main(string[] args) { //For args values, see ReadMe.txt #if DEBUG - args = "../Debug QueryGraph.txt 4 0 y y".Split(' '); + args = "../Debug QueryGraph.txt 4 0 y n".Split(' '); //args = "../Debug Scere20141001CR_idx.txt 3 0 y n".Split(' '); ../Debug/qg_3v_3e.txt //args = "../Debug Ecoli20141001CR_idx.txt 4 0 y n".Split(' '); #else diff --git a/MODA.Impl/Mapping.cs b/MODA.Impl/Mapping.cs index d2a412f..d95b1c2 100644 --- a/MODA.Impl/Mapping.cs +++ b/MODA.Impl/Mapping.cs @@ -10,7 +10,6 @@ public sealed class Mapping public Mapping(Dictionary function) { Function = function; - InducedSubGraphEdges = new HashSet>(); } /// @@ -26,7 +25,7 @@ public Mapping(Dictionary function) /// /// All the edges in the input subgraph G that fit the query graph (---Function.Keys) /// - public HashSet> InducedSubGraphEdges { get; private set; } + public HashSet> InducedSubGraphEdges { get; set; } /// /// Only for when (InducedSubGraph.EdgeCount == currentQueryGraphEdgeCount) diff --git a/MODA.Impl/MappingNodesComparer.cs b/MODA.Impl/MappingNodesComparer.cs index c434999..ed35f2a 100644 --- a/MODA.Impl/MappingNodesComparer.cs +++ b/MODA.Impl/MappingNodesComparer.cs @@ -1,16 +1,25 @@ using System.Collections.Generic; +using System.Linq; namespace MODA.Impl { /// /// This compares two nodes are equal. Used in dictionary where these nodes form the key. - /// The node set of interest is that of the mapping images on G; i.e. the set that form the nodes in the Mapping's InducedSubGraph + /// The node set of interest is that of the mapping images on G; i.e. the set that form the nodes in the Mapping's InducedSubGraph. + /// The parameters to be compared are guaranteed to be distinct and of the same length /// - public sealed class MappingNodesComparer : EqualityComparer + internal sealed class MappingNodesComparer : EqualityComparer { public override bool Equals(string[] x, string[] y) { - return new HashSet(x).SetEquals(y); + for (int i = 0; i < x.Length; i++) + { + if (!y.Contains(x[i])) + { + return false; + } + } + return true; } public override int GetHashCode(string[] obj) diff --git a/MODA.Impl/ModaAlgorithms.2.cs b/MODA.Impl/ModaAlgorithms.2.cs index fe49e34..c57ddd6 100644 --- a/MODA.Impl/ModaAlgorithms.2.cs +++ b/MODA.Impl/ModaAlgorithms.2.cs @@ -59,7 +59,7 @@ internal static List Algorithm2(QueryGraph queryGraph, UndirectedGraph< List mapSet; if (!theMappings.TryGetValue(key, out mapSet)) { - theMappings[key] = new List { mapping }; + theMappings[key] = new List (1) { mapping }; } else { diff --git a/MODA.Impl/ModaAlgorithms.cs b/MODA.Impl/ModaAlgorithms.cs index a6396df..593bc19 100644 --- a/MODA.Impl/ModaAlgorithms.cs +++ b/MODA.Impl/ModaAlgorithms.cs @@ -15,6 +15,7 @@ public partial class ModaAlgorithms /// If true, the program will use my modified Grochow's algorithm (Algo 2) /// public static bool UseModifiedGrochow { get; set; } + public static bool UsingAlgo3 { get; set; } #region Useful mainly for the Algorithm 2 versions @@ -78,6 +79,7 @@ private static IList IsomorphicExtension(Dictionary par g_nodes.Add(item.Value); } Edge edge_g = null; + HashSet> inducedSubGraphEdges = new HashSet>(); var qEdges = queryGraph.Edges; for (int i = 0; i < subgraphSize - 1; i++) { @@ -90,6 +92,10 @@ private static IList IsomorphicExtension(Dictionary par { g_nodes.Clear(); h_nodes.Clear(); + inducedSubGraphEdges.Clear(); + g_nodes = null; + h_nodes = null; + inducedSubGraphEdges = null; return new Mapping[0]; } } @@ -101,26 +107,38 @@ private static IList IsomorphicExtension(Dictionary par { if (inputGraph.TryGetEdge(g_nodes[i], g_nodes[j], out edge_g)) { - map.InducedSubGraphEdges.Add(edge_g); + inducedSubGraphEdges.Add(edge_g); } } else { if (edge_g != null) { - map.InducedSubGraphEdges.Add(edge_g); + inducedSubGraphEdges.Add(edge_g); } } } } g_nodes.Clear(); h_nodes.Clear(); + g_nodes = null; + h_nodes = null; edge_g = null; - if (queryGraph.EdgeCount > map.InducedSubGraphEdges.Count) // this shouuld never happen; but just in case + if (queryGraph.EdgeCount > inducedSubGraphEdges.Count) // this shouuld never happen; but just in case { + inducedSubGraphEdges.Clear(); + inducedSubGraphEdges = null; return new Mapping[0]; } - + if (UsingAlgo3) + { + map.InducedSubGraphEdges = inducedSubGraphEdges; + } + else + { + inducedSubGraphEdges.Clear(); + inducedSubGraphEdges = null; + } return new List(1) { map }; #endregion