Skip to content

Commit

Permalink
More memory optimizations. Still giving correct results. Rollback can…
Browse files Browse the repository at this point in the history
… be up to this point.
  • Loading branch information
smbadiwe committed Feb 15, 2017
1 parent 3e8f6c1 commit cd98ec8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
12 changes: 4 additions & 8 deletions MODA.Impl/ModaAlgorithms.2.Modified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ private static List<Mapping> Algorithm2_Modified(QueryGraph queryGraph, Undirect
//sw.Stop();
//Console.WriteLine(".");
//sw.Restart();

for (int k = 0; k < mappings.Count; k++)
for (int k = mappings.Count - 1; k >= 0; k--)
{
Mapping mapping = mappings[k];
//Recall: f(h) = g
Expand All @@ -64,22 +64,18 @@ private static List<Mapping> Algorithm2_Modified(QueryGraph queryGraph, Undirect
{
theMappings[key] = mapping;
}
mappings.RemoveAt(k);
}

}
//sw.Stop();
//logGist.AppendFormat("Map: {0}.\tTime to set:\t{1:N}s.\th = {2}. g = {3}\n", mappings.Count, sw.Elapsed.ToString(), h, g);
//sw = null;
mappings.Clear();
#endregion
}
}

var toReturn = new List<Mapping>();
foreach (var mapping in theMappings)
{
toReturn.Add(mapping.Value);
}
var toReturn = theMappings.Values.ToList();
//InputSubgraphs = null;
inputGraphDegSeq.Clear();
theMappings.Clear();
Expand Down
13 changes: 4 additions & 9 deletions MODA.Impl/ModaAlgorithms.2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ internal static List<Mapping> Algorithm2(QueryGraph queryGraph, UndirectedGraph<
if (mappings.Count > 0)
{
//sw.Restart();

for (int k = 0; k < mappings.Count; k++)
for (int k = mappings.Count - 1; k >= 0; k--)
{
Mapping mapping = mappings[k];
//Recall: f(h) = g
Expand All @@ -61,12 +61,11 @@ internal static List<Mapping> Algorithm2(QueryGraph queryGraph, UndirectedGraph<
{
theMappings[key] = mapping;
}
mappings.RemoveAt(k);
}

//sw.Stop();
//Console.WriteLine("Map: {0}.\tTime to set:\t{1:N}s.\th = {2}. g = {3}\n", mappings.Count, sw.Elapsed.ToString(), queryGraphVertices[j], inputGraphDegSeq[i]);
//sw = null;
mappings.Clear();
}
#endregion
}
Expand All @@ -77,11 +76,7 @@ internal static List<Mapping> Algorithm2(QueryGraph queryGraph, UndirectedGraph<
G_NodeNeighbours.Clear();
}

var toReturn = new List<Mapping>();
foreach (var mapping in theMappings)
{
toReturn.Add(mapping.Value);
}
var toReturn = theMappings.Values.ToList();
//Console.WriteLine("\nAlgorithm 2: All iteration tasks completed. Number of mappings found: {0}.\n", toReturn.Count);
//timer.Stop();
Console.WriteLine("Algorithm 2: All tasks completed. Number of mappings found: {0}.", toReturn.Count);
Expand Down
10 changes: 5 additions & 5 deletions MODA.Impl/ModaAlgorithms.3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private static IList<Mapping> Algorithm3(QueryGraph queryGraph,
// Remove mappings from the parent qGraph that are found in this qGraph
// This is because we're only interested in induced subgraphs
var dict = parentGraphMappings.ToDictionary(x => x.Id);
parentGraphMappings.Clear();
for (int i = 0; i < list.Count; i++)
{
if (dict.ContainsKey(list[i].Id))
Expand All @@ -67,12 +68,11 @@ private static IList<Mapping> Algorithm3(QueryGraph queryGraph,
}
//parentGraphMappings.RemoveBySwap(list[i]);
}
parentGraphMappings.Clear();
foreach (var item in dict)
{
parentGraphMappings.Add(item.Value);
}

dict.Clear();
}
Console.WriteLine("Algorithm 3: All tasks completed. Number of mappings found: {0}.\n", list.Count);

Expand All @@ -81,10 +81,10 @@ private static IList<Mapping> Algorithm3(QueryGraph queryGraph,

//timer = null;
var toReturn = new List<Mapping>(list.Count);
for (int i = 0; i < list.Count; i++)
for (int i = list.Count - 1; i >= 0; i--)
{
var map = list[i];
toReturn.Add(new Mapping(map.Function));
toReturn.Add(new Mapping(list[i].Function));
list.RemoveAt(i);
}
return toReturn;
}
Expand Down

0 comments on commit cd98ec8

Please sign in to comment.