Skip to content

Commit

Permalink
Things are still fine. Rollback can be up to this point
Browse files Browse the repository at this point in the history
  • Loading branch information
smbadiwe committed Feb 17, 2017
1 parent cd98ec8 commit 79a911a
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 235 deletions.
58 changes: 17 additions & 41 deletions MODA.Console/MODATest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static void Run(string[] args)
//MinimizeFootprint(); //MinimizeMemory();

#region Process input parameters
if (args == null || args.Length != 6)
if (args == null || args.Length < 6)
{
StdConsole.ForegroundColor = ConsoleColor.Red;
try
Expand Down Expand Up @@ -49,57 +49,36 @@ internal static void Run(string[] args)
{
throw new ArgumentException("Invalid input for <threshold> argument (arg[3])");
}
//string getOnlyMappingCounts = args[4];
if (args[4] == "y" || args[4] == "Y")
{
ModaAlgorithms.GetOnlyMappingCounts = true;
}
//string useModifiedGrochow = args[5];
if (args[5] == "y" || args[5] == "Y")
{
ModaAlgorithms.UseModifiedGrochow = true;
}
//string queryGraphFile = null;
QueryGraph queryGraph = null;
if (args.Length > 6)
{
//arg[6] - queryGraphFile
//queryGraphFile = args[6];
queryGraph = GraphProcessor.LoadGraph(args[6], true) as QueryGraph;
if (queryGraph.VertexCount != subGraphSize)
{
throw new ArgumentException("The specified subgraph size does not match with the query graph size. \nDo you want to use the size of the specified query graph instead? Y/N");
}
}
var sb = new StringBuilder("Processing Graph...");
sb.AppendFormat("Network File: {0}\nSub-graph Size: {1}\n", inputGraphFile, subGraphSize);
sb.AppendLine("==============================================================\n");
StdConsole.WriteLine(sb);
sb.Clear();

var inputGraph = GraphProcessor.LoadGraph(inputGraphFile);
if (subGraphSize > 5)
if (subGraphSize > 5 && queryGraph == null)
{
StdConsole.WriteLine("You need a query graph to proceed. To supply the query graph file, type 'y' and press Enter.");
}
else
{
StdConsole.WriteLine("Do you have a particular size {0} query graph in mind? Y/N", subGraphSize);
}
string queryGraphFile = null;
QueryGraph queryGraph = null;
var resp = StdConsole.ReadLine();
if (resp == "y" || resp == "Y" || subGraphSize > 5)
{
while (true)
{
StdConsole.WriteLine("Enter the (relative or absolute) path to the query graph file");
queryGraphFile = StdConsole.ReadLine();
queryGraph = GraphProcessor.LoadGraph(queryGraphFile, true) as QueryGraph;
if (queryGraph.VertexCount != subGraphSize)
{
StdConsole.WriteLine("The specified subgraph size does not match with the query graph size. \nDo you want to use the size of the specified query graph instead? Y/N");
resp = StdConsole.ReadLine();
if (resp == "y" || resp == "Y")
{
subGraphSize = queryGraph.VertexCount;
break;
}
// else contiue;
}
else // we're good. So,
{
break;
}
}
throw new ArgumentException("You need a query graph to proceed.");
}

if (subGraphSize >= inputGraph.VertexCount)
Expand Down Expand Up @@ -152,7 +131,7 @@ internal static void Run(string[] args)
}
else
{
int count = qGraph.Value.Count; //int.Parse(qGraph.Value.Split('#')[0]); // qGraph.Value.Count; //
int count = qGraph.Value.Count; //int.Parse(qGraph.Value.Split('#')[0]); //
sb.AppendFormat("\tSub-graph: {0}\t Mappings: {1}\t Is Frequent Subgraph? {2}\n", qGraph.Key.ToString(), count, qGraph.Key.IsFrequentSubgraph);
totalMappings += count;
}
Expand All @@ -168,7 +147,7 @@ internal static void Run(string[] args)
}
else
{
int count = qGraph.Value.Count; //int.Parse(qGraph.Value.Split('#')[0]); // qqGraph.Value.Count;
int count = qGraph.Value.Count; //int.Parse(qGraph.Value.Split('#')[0]); //
sb.AppendFormat("\tSub-graph: {0}\t Mappings: {1}\t Is Frequent Subgraph? {2}\n", qGraph.Key.ToString(), count, qGraph.Key.IsFrequentSubgraph);
foreach (var mapping in qGraph.Value)
{
Expand Down Expand Up @@ -204,9 +183,6 @@ internal static void Run(string[] args)
StdConsole.WriteLine(ex);
StdConsole.ForegroundColor = ConsoleColor.White;
}
#if !DEBUG
StdConsole.ReadKey();
#endif
}

private static void MinimizeMemory()
Expand Down
4 changes: 2 additions & 2 deletions MODA.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ static void Main(string[] args)
{
//For args values, see ReadMe.txt
#if DEBUG
args = "../Debug QueryGraph.txt 4 0 y n".Split(' ');
//args = "../Debug Scere20141001CR_idx.txt 3 0 y n".Split(' ');
args = "../Debug QueryGraph.txt 4 0 y y".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
//args = "C:\\SOMA\\Deeds\\UWFinaProjectWorks\\MODA\\MODA.Console\\bin\\Debug\\ QueryGraph.txt 3 0 y n".Split(' ');
Expand Down
54 changes: 16 additions & 38 deletions MODA.Impl/ExpansionTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,20 @@

namespace MODA.Impl
{
public class ExpansionTreeBuilder<TEdge> where TEdge : IEdge<string>
public class ExpansionTreeBuilder<TVertex>
{
public enum TreeTraversalType
{
BFS,
DFS
}

public int NumberOfQueryGraphs { get; private set; }
private int _numberOfNodes;
private TreeTraversalType _traversalType;
private IVertexListGraph<ExpansionTreeNode, Edge<ExpansionTreeNode>> _graph;

public IDictionary<ExpansionTreeNode, GraphColor> VerticesSorted { get; set; }
public AdjacencyGraph<ExpansionTreeNode, Edge<ExpansionTreeNode>> ExpansionTree { get; set; }
public int NumberOfQueryGraphs { get; private set; }
public Queue<ExpansionTreeNode> VerticesSorted { get; private set; }
public AdjacencyGraph<ExpansionTreeNode, Edge<ExpansionTreeNode>> ExpansionTree { get; private set; }

/// <summary>
///
/// </summary>
/// <param name="numberOfNodes"></param>
/// <param name="traversalType"></param>
public ExpansionTreeBuilder(int numberOfNodes, TreeTraversalType traversalType = TreeTraversalType.BFS)
public ExpansionTreeBuilder(int numberOfNodes)
{
_numberOfNodes = numberOfNodes;
_traversalType = traversalType;
NumberOfQueryGraphs = 1;
ExpansionTree = new AdjacencyGraph<ExpansionTreeNode, Edge<ExpansionTreeNode>>();

Expand All @@ -52,35 +41,24 @@ public void Build()
rootNode = ExpansionTree.BuildFiveNodesTree();
NumberOfQueryGraphs = 21;
break;
default:
default:
throw new System.NotSupportedException("Subgraph sizes below 3 and above 5 are not supported, unless you supply a query graph.");
}
//TODO: Construct the tree.
// It turns out there's yet no formula to determine the number of isomorphic trees that can be formed
// from n nodes; hence no way(?) of writing a general code

if (_traversalType == TreeTraversalType.BFS)
{
var bfs = new BreadthFirstSearchAlgorithm<ExpansionTreeNode, Edge<ExpansionTreeNode>>(ExpansionTree);
bfs.SetRootVertex(rootNode);
bfs.Compute();

VerticesSorted = bfs.VertexColors;
_graph = bfs.VisitedGraph;
bfs = null;
}
else
var bfs = new BreadthFirstSearchAlgorithm<ExpansionTreeNode, Edge<ExpansionTreeNode>>(ExpansionTree);
bfs.SetRootVertex(rootNode);
bfs.Compute();

VerticesSorted = new Queue<ExpansionTreeNode>(bfs.VertexColors.Count);
foreach (var item in bfs.VertexColors)
{
var dfs = new DepthFirstSearchAlgorithm<ExpansionTreeNode, Edge<ExpansionTreeNode>>(ExpansionTree);
dfs.SetRootVertex(rootNode);
dfs.Compute();

VerticesSorted = dfs.VertexColors;
_graph = dfs.VisitedGraph;
dfs = null;
VerticesSorted.Enqueue(item.Key);
}
VerticesSorted[rootNode] = GraphColor.White;
bfs.VertexColors.Clear();
bfs = null;
VerticesSorted.Dequeue(); // remove the root
}

}
}
87 changes: 41 additions & 46 deletions MODA.Impl/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,54 +68,49 @@ public Edge<string> GetImage(Edge<string> newlyAddedEdge)
/// <returns></returns>
public bool IsIsomorphicWith(Mapping otherMapping, QueryGraph queryGraph)
{
//if (queryGraph.EdgeCount > InducedSubGraph.EdgeCount)
//{
// //NB: This comdition being true means that the query graph cannot be mapped to the induced subgraph.
// // Recall that image node set (hence induced subgraph) is guaranteed to be same for both this and other mapping.
// // So, I'm returning true here so that the mapping can be ignored, ie, not added to the list of mappings
// return true;

// #region This is what was here before. Review, even though the app gives correct results based on the test data - largely because this code never runs
// ////Test 2 - check if the two are same
// //string[] mapSequence, otherMapSequence;
// //var thisSequence = GetStringifiedMapSequence(out mapSequence);
// //var otherSequence = otherMapping.GetStringifiedMapSequence(out otherMapSequence);
// //if (thisSequence == otherSequence)
// //{
// // //System.Console.WriteLine("thisSequence == otherSequence. Return true");
// // return true;
// //}
//if (true)
{
#region This is what was here before. Review, even though the app gives correct results based on the test data - largely because this code never runs
////Test 2 - check if the two are same
//string[] mapSequence, otherMapSequence;
//var thisSequence = GetStringifiedMapSequence(out mapSequence);
//var otherSequence = otherMapping.GetStringifiedMapSequence(out otherMapSequence);
//if (thisSequence == otherSequence)
//{
// //System.Console.WriteLine("thisSequence == otherSequence. Return true");
// return true;
//}

// ////Test 3 - check if one is a reversed reading of the other
// //bool isIso = true;
// //int index = mapSequence.Length;
// //for (int i = 0; i < index; i++)
// //{
// // if (mapSequence[i] != otherMapSequence[index - i - 1])
// // {
// // isIso = false;
// // break;
// // }
// //}
// //if (isIso)
// //{
// // //System.Console.WriteLine("isAlso == true. Return true");
// // return true;
// //}
////Test 3 - check if one is a reversed reading of the other
//bool isIso = true;
//int index = mapSequence.Length;
//for (int i = 0; i < index; i++)
//{
// if (mapSequence[i] != otherMapSequence[index - i - 1])
// {
// isIso = false;
// break;
// }
//}
//if (isIso)
//{
// //System.Console.WriteLine("isAlso == true. Return true");
// return true;
//}

// ////Test 4 - compare corresponding edges
// //foreach (var edge in queryGraph.Edges)
// //{
// // var edgeImage = new Edge<string>(Function[edge.Source], Function[edge.Target]);
// // var otherEdgeImage = new Edge<string>(otherMapping.Function[edge.Source], otherMapping.Function[edge.Target]);
// // if (edgeImage != otherEdgeImage)
// // {
// // System.Console.WriteLine("edgeImage != otherEdgeImage. Return false");
// // return false;
// // }
// //}
// #endregion
//}
////Test 4 - compare corresponding edges
//foreach (var edge in queryGraph.Edges)
//{
// var edgeImage = new Edge<string>(Function[edge.Source], Function[edge.Target]);
// var otherEdgeImage = new Edge<string>(otherMapping.Function[edge.Source], otherMapping.Function[edge.Target]);
// if (edgeImage != otherEdgeImage)
// {
// System.Console.WriteLine("edgeImage != otherEdgeImage. Return false");
// return false;
// }
//}
#endregion
}

// let it go
return true;
Expand Down
19 changes: 12 additions & 7 deletions MODA.Impl/ModaAlgorithms.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace MODA.Impl
{
public partial class ModaAlgorithms
{
private static ExpansionTreeBuilder<Edge<string>> _builder;
private static ExpansionTreeBuilder<string> _builder;
public static void BuildTree(int subgraphSize)
{
_builder = new ExpansionTreeBuilder<Edge<string>>(subgraphSize);
_builder = new ExpansionTreeBuilder<string>(subgraphSize);
_builder.Build();
}

Expand Down Expand Up @@ -191,6 +191,7 @@ public static Dictionary<QueryGraph, IList<Mapping>> Algorithm1(UndirectedGraph<
qGraph.IsFrequentSubgraph = true;
}
// Save mappings. Do we need to save to disk? Maybe not!

allMappings.Add(qGraph, mappings);

mappings = null; //.Clear();
Expand Down Expand Up @@ -232,13 +233,17 @@ public static Dictionary<QueryGraph, IList<Mapping>> Algorithm1(UndirectedGraph<
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ExpansionTreeNode GetNextNode()
{
foreach (var node in _builder.VerticesSorted)
if (_builder.VerticesSorted.Count > 0)
{
if (node.Value == GraphColor.White) continue;

_builder.VerticesSorted[node.Key] = GraphColor.White;
return node.Key;
return _builder.VerticesSorted.Dequeue();
}
//foreach (var node in _builder.VerticesSorted)
//{
// if (node.Value == GraphColor.White) continue;

// _builder.VerticesSorted[node.Key] = GraphColor.White;
// return node.Key;
//}
return null;
}
}
Expand Down
18 changes: 13 additions & 5 deletions MODA.Impl/ModaAlgorithms.2.Modified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static List<Mapping> Algorithm2_Modified(QueryGraph queryGraph, Undirect

H_NodeNeighbours = new Dictionary<string, HashSet<string>>();
G_NodeNeighbours = new Dictionary<string, HashSet<string>>();
var theMappings = new Dictionary<string[], Mapping>(new MappingNodesComparer());
var theMappings = new Dictionary<string[], List<Mapping>>(new MappingNodesComparer());
var inputGraphDegSeq = inputGraph.GetDegreeSequence(numberOfSamples);

Console.WriteLine("Calling Algo 2-Modified: Number of Iterations: {0}.\n", numberOfSamples);
Expand Down Expand Up @@ -60,9 +60,17 @@ private static List<Mapping> Algorithm2_Modified(QueryGraph queryGraph, Undirect
Mapping mapping = mappings[k];
//Recall: f(h) = g
var key = mapping.Function.Values.ToArray();
if (!theMappings.ContainsKey(key))
List<Mapping> mapSet;
if (!theMappings.TryGetValue(key, out mapSet))
{
theMappings[key] = mapping;
theMappings[key] = new List<Mapping> { mapping };
}
else
{
if (false == mapSet.Exists(x => x.IsIsomorphicWith(mapping, queryGraph)))
{
mapSet.Add(mapping);
}
}
mappings.RemoveAt(k);
}
Expand All @@ -75,10 +83,10 @@ private static List<Mapping> Algorithm2_Modified(QueryGraph queryGraph, Undirect
}
}

var toReturn = theMappings.Values.ToList();
var toReturn = new List<Mapping>(theMappings.Values.SelectMany(x => x));
//InputSubgraphs = null;
inputGraphDegSeq.Clear();
theMappings.Clear();
inputGraphDegSeq.Clear();
H_NodeNeighbours.Clear();
G_NodeNeighbours.Clear();
//timer = null;
Expand Down
Loading

0 comments on commit 79a911a

Please sign in to comment.