From 3e8f6c1f97864a9adf468d674f62fd4d3bc6700e Mon Sep 17 00:00:00 2001 From: smbadiwe Date: Wed, 15 Feb 2017 07:24:36 -0800 Subject: [PATCH] All is still well up to this point, even though memory usage is still bad. Roll-back can be up to this point. --- MODA.Impl/ModaAlgorithms.2.Modified.cs | 21 +++------------- MODA.Impl/ModaAlgorithms.2.cs | 22 ++++------------ MODA.Impl/ModaAlgorithms.cs | 35 +++++++++++++++----------- 3 files changed, 29 insertions(+), 49 deletions(-) diff --git a/MODA.Impl/ModaAlgorithms.2.Modified.cs b/MODA.Impl/ModaAlgorithms.2.Modified.cs index 71d8cff..0840e5e 100644 --- a/MODA.Impl/ModaAlgorithms.2.Modified.cs +++ b/MODA.Impl/ModaAlgorithms.2.Modified.cs @@ -31,7 +31,7 @@ private static List Algorithm2_Modified(QueryGraph queryGraph, Undirect H_NodeNeighbours = new Dictionary>(); G_NodeNeighbours = new Dictionary>(); - var theMappings = new Dictionary>(new MappingNodesComparer()); + var theMappings = new Dictionary(new MappingNodesComparer()); var inputGraphDegSeq = inputGraph.GetDegreeSequence(numberOfSamples); Console.WriteLine("Calling Algo 2-Modified: Number of Iterations: {0}.\n", numberOfSamples); @@ -60,22 +60,9 @@ private static List Algorithm2_Modified(QueryGraph queryGraph, Undirect Mapping mapping = mappings[k]; //Recall: f(h) = g var key = mapping.Function.Values.ToArray(); - //var key = mapping.InducedSubGraph.Vertices.ToArray(); - List mappingsToSearch; - //if (theMappings.TryGetValue(key, out mappingsToSearch)) - //{ - // if (false == mappingsToSearch.Exists(x => x.IsIsomorphicWith(mapping, queryGraph))) - // { - // theMappings[key].Add(mapping); - // } - //} - //else - //{ - // theMappings[key] = new List { mapping }; - //} - if (!theMappings.TryGetValue(key, out mappingsToSearch)) + if (!theMappings.ContainsKey(key)) { - theMappings[key] = new List { mapping }; + theMappings[key] = mapping; } } @@ -91,7 +78,7 @@ private static List Algorithm2_Modified(QueryGraph queryGraph, Undirect var toReturn = new List(); foreach (var mapping in theMappings) { - toReturn.AddRange(mapping.Value); + toReturn.Add(mapping.Value); } //InputSubgraphs = null; inputGraphDegSeq.Clear(); diff --git a/MODA.Impl/ModaAlgorithms.2.cs b/MODA.Impl/ModaAlgorithms.2.cs index 3b67d09..f4f15a1 100644 --- a/MODA.Impl/ModaAlgorithms.2.cs +++ b/MODA.Impl/ModaAlgorithms.2.cs @@ -23,7 +23,8 @@ internal static List Algorithm2(QueryGraph queryGraph, UndirectedGraph< // We do need it. H_NodeNeighbours = new Dictionary>(); - var theMappings = new Dictionary>(new MappingNodesComparer()); + //var theMappings = new Dictionary>(new MappingNodesComparer()); + var theMappings = new Dictionary(new MappingNodesComparer()); var inputGraphDegSeq = inputGraphClone.GetDegreeSequence(numberOfSamples); var queryGraphVertices = queryGraph.Vertices.ToArray(); var subgraphSize = queryGraphVertices.Length; @@ -56,22 +57,9 @@ internal static List Algorithm2(QueryGraph queryGraph, UndirectedGraph< Mapping mapping = mappings[k]; //Recall: f(h) = g var key = mapping.Function.Values.ToArray(); - //var key = mapping.InducedSubGraph.Vertices.ToArray(); - List mappingsToSearch; - //if (theMappings.TryGetValue(key, out mappingsToSearch)) - //{ - // if (false == mappingsToSearch.Exists(x => x.IsIsomorphicWith(mapping, queryGraph))) - // { - // theMappings[key].Add(mapping); - // } - //} - //else - //{ - // theMappings[key] = new List { mapping }; - //} - if (!theMappings.TryGetValue(key, out mappingsToSearch)) + if (!theMappings.ContainsKey(key)) { - theMappings[key] = new List { mapping }; + theMappings[key] = mapping; } } @@ -92,7 +80,7 @@ internal static List Algorithm2(QueryGraph queryGraph, UndirectedGraph< var toReturn = new List(); foreach (var mapping in theMappings) { - toReturn.AddRange(mapping.Value); + toReturn.Add(mapping.Value); } //Console.WriteLine("\nAlgorithm 2: All iteration tasks completed. Number of mappings found: {0}.\n", toReturn.Count); //timer.Stop(); diff --git a/MODA.Impl/ModaAlgorithms.cs b/MODA.Impl/ModaAlgorithms.cs index 05d0463..fd70127 100644 --- a/MODA.Impl/ModaAlgorithms.cs +++ b/MODA.Impl/ModaAlgorithms.cs @@ -122,7 +122,7 @@ private static IList IsomorphicExtension(Dictionary par } return listOfIsomorphisms; } - + /// /// If there is a neighbor d ∈ D of m such that n is NOT neighbors with f(d), /// or if there is a NON-neighbor d ∈ D of m such that n is neighbors with f(d) @@ -147,15 +147,17 @@ private static bool IsNeighbourIncompatible(UndirectedGraph } //If there is a neighbor d ∈ D of m such that n is NOT neighbors with f(d), - string val; // f(d) var neighboursOfN = inputGraph.GetNeighbors(n, true); - + //bool doNext = false; + string val; // f(d) foreach (var d in neighborsOfM) { if (!partialMap.TryGetValue(d, out val)) { neighboursOfN = null; return false; + //doNext = true; + //break; } if (!neighboursOfN.Contains(val)) { @@ -165,25 +167,28 @@ private static bool IsNeighbourIncompatible(UndirectedGraph } //// or if there is a NON - neighbor d ∈ D of m such that n IS neighbors with f(d) - //var nonNeighborOfM = queryGraph.Vertices.Except(neighborsOfM); - //foreach (var d in nonNeighborOfM) + //if (doNext) //{ - // if (!partialMap.TryGetValue(d, out val)) + // var nonNeighborOfM = queryGraph.Vertices.Except(neighborsOfM); + // foreach (var d in nonNeighborOfM) // { - // neighboursOfN = null; - // return false; - // } - // if (neighboursOfN.Contains(val)) - // { - // neighboursOfN = null; - // return true; + // if (!partialMap.TryGetValue(d, out val)) + // { + // neighboursOfN = null; + // return false; + // } + // if (neighboursOfN.Contains(val)) + // { + // neighboursOfN = null; + // return true; + // } // } + // nonNeighborOfM = null; //} - //nonNeighborOfM = null; neighboursOfN = null; return false; } - + ///// ///// /////