Skip to content

Commit

Permalink
5 Node Expansion Tree constructed.
Browse files Browse the repository at this point in the history
  • Loading branch information
smbadiwe committed Aug 10, 2016
1 parent 2fdab58 commit c84173b
Show file tree
Hide file tree
Showing 120 changed files with 855 additions and 396 deletions.
2 changes: 2 additions & 0 deletions MODA.Console/MODA.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MODATest.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecursionHelperTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
56 changes: 56 additions & 0 deletions MODA.Console/MODATest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using MODA.Impl;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace MODA.Console
{
public class MODATest
{
internal static void Run(string[] args)
{
try
{
string graphFolder = args[0]; // @"C:\SOMA\Drive\MyUW\Research\Kim\remodaalgorithmimplementation";
string filename = args[1]; // "QueryGraph.txt"; // "Ecoli20141001CR_idx.txt";
var dotFileFulllName = Path.Combine(graphFolder, filename);
int subGraphSize = int.Parse(args[2]);
int numIterations = int.Parse(args[3]);

var sb = new StringBuilder("Processing Graph...");
sb.AppendFormat("Network File: {0}\nSub-graph Size: {1}\nNumber of Iterations: {2}\n", dotFileFulllName, subGraphSize, numIterations);
sb.AppendLine("==========================================================================\n");
System.Console.WriteLine(sb);
sb.Clear();
for (int i = 0; i < numIterations; i++)
{
var sw = Stopwatch.StartNew();
var newGraphInstance = GraphProcessor.LoadGraph(dotFileFulllName);
System.Console.WriteLine("Iteration {0}:\t Network: Nodes - {1}; Edges: {2}\n", (i + 1), newGraphInstance.VertexCount, newGraphInstance.EdgeCount);

//Visualizer.Visualize(newGraphInstance, dotFileFulllName + ".dot");

var frequentSubgraphs = new ModaAlgorithms().Algorithm1(newGraphInstance, subGraphSize);
sw.Stop();
int totalMappings = 0;
foreach (var queryGraph in frequentSubgraphs)
{
sb.AppendFormat("\tSub-graph: {0}\t Mappings: {1}\n", queryGraph.Key.AsString(), queryGraph.Value);
totalMappings += queryGraph.Value;
}
sb.AppendFormat("\nTime Taken: {0} ({1}ms)\t Network: Nodes - {2}; Edges: {3}; Total Mappings found: {4}\n", sw.Elapsed.ToString(), sw.ElapsedMilliseconds.ToString("N"), newGraphInstance.VertexCount, newGraphInstance.EdgeCount, totalMappings);
sb.AppendLine("-------------------------------------------\n");
newGraphInstance = null;
frequentSubgraphs = null;
}
File.WriteAllText(dotFileFulllName + ".puo", sb.ToString());
}
catch (System.Exception ex)
{
System.Console.WriteLine(ex);
}
System.Console.WriteLine("Done!");
System.Console.ReadKey();
}
}
}
52 changes: 3 additions & 49 deletions MODA.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,11 @@
using MODA.Impl;
using MODA.Impl.Graphics;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace MODA.Console
namespace MODA.Console
{
class Program
{
static void Main(string[] args)
{
try
{
string graphFolder = args[0]; // @"C:\SOMA\Drive\MyUW\Research\Kim\remodaalgorithmimplementation";
string filename = args[1]; // "QueryGraph.txt"; // "Ecoli20141001CR_idx.txt";
var dotFileFulllName = Path.Combine(graphFolder, filename);
int subGraphSize = int.Parse(args[2]);
int numIterations = int.Parse(args[3]);

var sb = new StringBuilder("Processing Graph...");
sb.AppendFormat("Network File: {0}\nSub-graph Size: {1}\nNumber of Iterations: {2}\n", dotFileFulllName, subGraphSize, numIterations);
sb.AppendLine("==========================================================================\n");
System.Console.WriteLine(sb);
sb.Clear();
for (int i = 0; i < numIterations; i++)
{
var sw = Stopwatch.StartNew();
var newGraphInstance = GraphProcessor.LoadGraph(dotFileFulllName);
System.Console.WriteLine("Iteration {0}:\t Network: Nodes - {1}; Edges: {2}\n", (i + 1), newGraphInstance.VertexCount, newGraphInstance.EdgeCount);

//Visualizer.Visualize(newGraphInstance, dotFileFulllName + ".dot");

var frequentSubgraphs = new ModaAlgorithms().Algorithm1(newGraphInstance, subGraphSize);
sw.Stop();
int totalMappings = 0;
foreach (var queryGraph in frequentSubgraphs)
{
sb.AppendFormat("\tSub-graph: {0}\t Mappings: {1}\n", queryGraph.Key.AsString(), queryGraph.Value);
totalMappings += queryGraph.Value;
}
sb.AppendFormat("\nTime Taken: {0} ({1}ms)\t Network: Nodes - {2}; Edges: {3}; Total Mappings found: {4}\n", sw.Elapsed.ToString(), sw.ElapsedMilliseconds.ToString("N"), newGraphInstance.VertexCount, newGraphInstance.EdgeCount, totalMappings);
sb.AppendLine("-------------------------------------------\n");
newGraphInstance = null;
frequentSubgraphs = null;
}
File.WriteAllText(dotFileFulllName + ".puo", sb.ToString());
}
catch (System.Exception ex)
{
System.Console.WriteLine(ex);
}
System.Console.WriteLine("Done!");
System.Console.ReadKey();
MODATest.Run(args);
//RecursionHelperTest.Run();
}
}
}
86 changes: 86 additions & 0 deletions MODA.Console/RecursionHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using MODA.Impl;
using System.Diagnostics;
using System.Threading;

namespace MODA.Console
{
public class RecursionHelperTest
{
public static void Run()
{
var arr = new[] { 1,5,5,5,5,5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
RunRecursionHelper(arr);
RunRecursion(arr);
System.Console.ReadKey();
}

static void RunRecursion(int[] arr)
{
var sw = Stopwatch.StartNew();

var ans = Factorial(20); // Sum(arr);

sw.Stop();
System.Console.WriteLine("RunRecursion done.\n Time taken: {0}s. Ans = {1}", sw.Elapsed, ans);
}

static void RunRecursionHelper(int[] arr)
{
var sw = Stopwatch.StartNew();

var ans = FactorialWithHelper(20); // SumWithHelper(arr);

sw.Stop();
System.Console.WriteLine("RunRecursionHelper done.\n Time taken: {0}s. Ans = {1}", sw.Elapsed, ans);
}

static long Factorial(long n)
{
//This is the termination condition
if (n < 2)
{
//This is the returning value when termination condition is true
Thread.Sleep(3000);
return 1;
}

//This is the recursive call
var fac = Factorial(n - 1);

//This is the work to do with the current item and the
//result of recursive call
return n * fac;
}

static long FactorialWithHelper(long n)
{
return RecursionHelper<long>.CreateSingular(currentParam => currentParam < 2, currentVal => { Thread.Sleep(3000); return 1; })
.RecursiveCall((currentParam, rv) => currentParam - 1)
.Do((i, rv) => i * rv)
.Execute(n);
}

static int Sum(int[] array, int index = 0)
{
//This is the termination condition
if (index >= array.Length)
//This is the returning value when termination condition is true
return 0;

//This is the recursive call
var sumofrest = Sum(array, index + 1);

//This is the work to do with the current item and the
//result of recursive call
return array[index] + sumofrest;
}

static int SumWithHelper(int[] ar)
{
return RecursionHelper<int>.CreateSingular(i => i >= ar.Length, i => 0)
.RecursiveCall((i, rv) => i + 1)
.Do((i, rv) => ar[i] + rv)
.Execute(0);
}
}
}
5 changes: 5 additions & 0 deletions MODA.Impl/ExpansionTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void Build()
case 3:
rootNode = ExpansionTree.BuildThreeNodesTree();
break;
case 5:
rootNode = ExpansionTree.BuildFiveNodesTree();
break;
case 4:
default:
rootNode = ExpansionTree.BuildFourNodesTree();
Expand All @@ -53,6 +56,7 @@ public void Build()

VerticesSorted = bfs.VertexColors;
Graph = bfs.VisitedGraph;
bfs = null;
}
else
{
Expand All @@ -62,6 +66,7 @@ public void Build()

VerticesSorted = dfs.VertexColors;
Graph = dfs.VisitedGraph;
dfs = null;
}
VerticesSorted[rootNode] = GraphColor.White;
}
Expand Down
Loading

0 comments on commit c84173b

Please sign in to comment.