Skip to content

Commit

Permalink
Sundry changes
Browse files Browse the repository at this point in the history
  • Loading branch information
smbadiwe committed Aug 13, 2016
1 parent c84173b commit 5c9d96f
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 207 deletions.
10 changes: 10 additions & 0 deletions MODA.Console/MODA.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseModified|AnyCPU'">
<OutputPath>bin\ReleaseModified\</OutputPath>
<DefineConstants>TRACE;MODIFIED</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
41 changes: 20 additions & 21 deletions MODA.Console/MODATest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@ internal static void Run(string[] args)
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]);
int vertexCountDividend = 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");
sb.AppendFormat("Network File: {0}\nSub-graph Size: {1}\n", dotFileFulllName, subGraphSize);
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 sw = Stopwatch.StartNew();
var newGraphInstance = GraphProcessor.LoadGraph(dotFileFulllName);
System.Console.WriteLine("Iteration {0}:\t Network: Nodes - {1}; Edges: {2}\n", 1, newGraphInstance.VertexCount, newGraphInstance.EdgeCount);

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;
//Visualizer.Visualize(newGraphInstance, dotFileFulllName + ".dot");
ModaAlgorithms.VertexCountDividend = vertexCountDividend;
var frequentSubgraphs = 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)
Expand Down
21 changes: 20 additions & 1 deletion MODA.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
namespace MODA.Console
using MODA.Impl;
using System.Collections.Generic;

namespace MODA.Console
{
class Program
{
static void Main(string[] args)
{
//var list1 = new HashSet<string>(new[] { "1", "2", "3" });
//var list2 = new HashSet<string>(new[] { "1", "2", "3" });

//System.Console.WriteLine("{0}", list1 == list2);
//System.Console.WriteLine("{0}", list1.GetHashCode() == list2.GetHashCode());
//System.Console.WriteLine("{0}", list1.Equals(list2));
//System.Console.WriteLine("{0}", list1.SetEquals(list2));

//List<Mapping> mappingsToSearch = new List<Mapping>();
////{
//// "a", "b", "c"
////};
//var item = mappingsToSearch.Find(x => x.Equals(new Mapping(new Dictionary<string, string>())));

//System.Console.ReadKey();

MODATest.Run(args);
//RecursionHelperTest.Run();
}
Expand Down
23 changes: 11 additions & 12 deletions MODA.Impl/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static List<string> GetNonNeighbors(this UndirectedGraph<string, Edge<str
}
return nonNeighbors;
}

public static List<string> GetNeighbors(this UndirectedGraph<string, Edge<string>> graph, string vertex, bool isG = true)
{
List<string> neighbors;
Expand Down Expand Up @@ -90,30 +90,29 @@ public static UndirectedGraph<string, Edge<string>> Clone(this UndirectedGraph<s
/// </summary>
/// <typeparam name="string"></typeparam>
/// <param name="graph"></param>
/// <param name="count">The expected number of items to return.</param>
/// <returns></returns>
public static List<string> GetDegreeSequence(this UndirectedGraph<string, Edge<string>> graph)
public static string[] GetDegreeSequence(this UndirectedGraph<string, Edge<string>> graph, int count)
{
if (graph.IsVerticesEmpty) return new List<string>(0);
if (graph.IsVerticesEmpty) return new string[0];

var vertices = graph.Vertices.ToList();
var tempList = new Dictionary<string, int>(vertices.Count);
var vertices = graph.Vertices.Take(count).ToArray();
var tempList = new Dictionary<string, int>(vertices.Length);

vertices.ForEach(node =>
foreach (var node in vertices)
{
tempList.Add(node, graph.AdjacentDegree(node));
}
);
var listToReturn = new List<string>(vertices.Count);
//int index = 0;

var listToReturn = new List<string>(vertices.Length);
foreach (var item in tempList.OrderByDescending(x => x.Value))
{
//listToReturn[index] = item.Key;
//index++;
listToReturn.Add(item.Key);
}

vertices = null;
tempList = null;
return listToReturn;
return listToReturn.ToArray();
}

}
Expand Down
11 changes: 11 additions & 0 deletions MODA.Impl/MODA.Impl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseModified|AnyCPU'">
<OutputPath>bin\ReleaseModified\</OutputPath>
<DefineConstants>TRACE;MODIFIED</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="MsgPack, Version=0.1.4298.15470, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MsgPack.0.1.0.2011042300\lib\net40\MsgPack.dll</HintPath>
Expand Down Expand Up @@ -60,12 +69,14 @@
<Compile Include="GraphProcessor.cs" />
<Compile Include="Map.cs" />
<Compile Include="Mapping.cs" />
<Compile Include="ModaAlgorithms.2.cs" />
<Compile Include="ModaAlgorithms.3.cs" />
<Compile Include="ModaAlgorithms.2.Modified.cs" />
<Compile Include="ModaAlgorithms.1.cs" />
<Compile Include="MySerializer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecursionHelper.cs" />
<Compile Include="MappingNodesComparer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\QuickGraph.Graphviz\QuickGraph.Graphviz.csproj">
Expand Down
48 changes: 36 additions & 12 deletions MODA.Impl/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Mapping(Dictionary<string, string> function)
Function = function;
}

public Dictionary<string, string> Function { get; }
public Dictionary<string, string> Function { get; private set; }

/// <summary>
/// The subgraph (with all edges) in the input graph G that fit the query graph (---Function.Values)
Expand All @@ -32,19 +32,37 @@ public override bool Equals(object obj)
var other = obj as Mapping;
if (other == null) return false;

//Test 1 - Vertices
var test = (new HashSet<string>(this.Function.Keys).SetEquals(other.Function.Keys)
&& new HashSet<string>(this.Function.Values).SetEquals(other.Function.Values));
if (test == false)
try
{
return false;
}
//Test 1 - Vertices
var test = (new HashSet<string>(this.Function.Keys).SetEquals(other.Function.Keys)
&& new HashSet<string>(this.Function.Values).SetEquals(other.Function.Values));
if (test == false)
{
return false;
}

//Test 2 - Edge count
test = this.MapOnInputSubGraph.EdgeCount == other.MapOnInputSubGraph.EdgeCount;
if (test == false)
//Test 2 - Edge count
test = this.MapOnInputSubGraph.EdgeCount == other.MapOnInputSubGraph.EdgeCount;
if (test == false)
{
return false;
}
}
catch //(Exception ex)
{
return false;
var sb = new StringBuilder("Somebody's Function or MapOnInputSubGraph is null here!\n");
sb.AppendFormat("\tthis.Function == null? {0}\n", this.Function == null);
sb.AppendFormat("\tthis.MapOnInputSubGraph == null? {0}\n", this.MapOnInputSubGraph == null);
sb.AppendFormat("\tother.Function == null? {0}\n", other.Function == null);
sb.AppendFormat("\tother.MapOnInputSubGraph == null? {0}\n", other.MapOnInputSubGraph == null);

var defaultColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(sb.ToString());
Console.ForegroundColor = defaultColor;

throw;
}

//Test 3 - Node degrees.
Expand All @@ -53,7 +71,7 @@ public override bool Equals(object obj)

//var any = MapOnInputSubGraph.Vertices.ToList().Find(node =>
// this.MapOnInputSubGraph.AdjacentDegree(node) != other.MapOnInputSubGraph.AdjacentDegree(node));

//if (any != null) return false;
//foreach (var node in MapOnInputSubGraph.Vertices)
//{
Expand All @@ -66,6 +84,12 @@ public override bool Equals(object obj)
return true;
}

/// <summary>
/// With the way the code is now, you don't need this; but if you're
/// going to do something with this object, see if you need to provide
/// implementation.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode();
Expand Down
25 changes: 25 additions & 0 deletions MODA.Impl/MappingNodesComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace MODA.Impl
{
/// <summary>
/// This compares two <seealso cref="Mapping"/> nodes are equal. Used in dictionary where these nodes form the key
/// </summary>
public class MappingNodesComparer : EqualityComparer<string[]>
{
public override bool Equals(string[] x, string[] y)
{
return new HashSet<string>(x).SetEquals(y);
}

public override int GetHashCode(string[] obj)
{
int hash = 0;
for (int i = 0; i < obj.Length; i++)
{
hash += obj[i].GetHashCode();
}
return hash;
}
}
}
20 changes: 15 additions & 5 deletions MODA.Impl/ModaAlgorithms.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ namespace MODA.Impl
{
public partial class ModaAlgorithms
{
public static string MapFolder = @"C:\SOMA\Drive\MyUW\Research\Kim\Capstone\ExperimentalNetworks\MapFolder";
public static int VertexCountDividend { get; set; }
//public ModaAlgorithms(int vertexCountDividend = 1)
//{
// VertexCountDividend = vertexCountDividend;
//}

public const string MapFolder = @"C:\SOMA\Drive\MyUW\Research\Kim\Capstone\ExperimentalNetworks\MapFolder";
/// <summary>
/// Algo 1: Find subgraph frequency
/// </summary>
/// <param name="inputGraph"></param>
/// <param name="subgraphSize"></param>
/// <param name="thresholdValue"></param>
/// <returns>Fg, frequent subgraph list</returns>
public Dictionary<UndirectedGraph<string, Edge<string>>, int> Algorithm1(UndirectedGraph<string, Edge<string>> inputGraph, int subgraphSize, int thresholdValue = 0)
public static Dictionary<UndirectedGraph<string, Edge<string>>, int> Algorithm1(UndirectedGraph<string, Edge<string>> inputGraph, int subgraphSize, int thresholdValue = 0)
{
var builder = new ExpansionTreeBuilder<Edge<string>>(subgraphSize);
builder.Build();
Expand All @@ -28,7 +34,11 @@ public Dictionary<UndirectedGraph<string, Edge<string>>, int> Algorithm1(Undirec
if (qGraph.EdgeCount == (subgraphSize - 1))
{
// Modified Mapping module - MODA and Grockow & Kellis
mappings = Algorithm2_Modified(qGraph, inputGraph); //Algorithm2_Original
#if MODIFIED
mappings = Algorithm2_Modified(qGraph, inputGraph);
#else
mappings = Algorithm2(qGraph, inputGraph);
#endif
}
else
{
Expand All @@ -37,7 +47,7 @@ public Dictionary<UndirectedGraph<string, Edge<string>>, int> Algorithm1(Undirec
}
if (mappings.Count > 0)
{
//Save mappings. Do we need to save to disk?
// Save mappings. Do we need to save to disk? Yes!
allMappings.Add(qGraph, mappings.Count);
File.WriteAllBytes(Path.Combine(MapFolder, qGraph.AsString().Replace(">", "&lt;") + ".map"), MySerializer.Serialize(new Map
{
Expand Down Expand Up @@ -67,7 +77,7 @@ public Dictionary<UndirectedGraph<string, Edge<string>>, int> Algorithm1(Undirec
/// </summary>
/// <param name="extTreeNodesQueued"></param>
/// <returns></returns>
private ExpansionTreeNode<Edge<string>> GetNextNode(IDictionary<ExpansionTreeNode<Edge<string>>, GraphColor> extTreeNodesQueued)
private static ExpansionTreeNode<Edge<string>> GetNextNode(IDictionary<ExpansionTreeNode<Edge<string>>, GraphColor> extTreeNodesQueued)
{
foreach (var node in extTreeNodesQueued)
{
Expand Down
Loading

0 comments on commit 5c9d96f

Please sign in to comment.