static void Diff(List <IndexedGraph> rs1, List <IndexedGraph> rs2) { SubGraphTest sgt = new SubGraphTest(); HashSet <int> notin1 = new HashSet <int>(); for (int i = 0; i < rs2.Count; i++) { notin1.Add(i); } Console.WriteLine("1 not in 2:"); foreach (IndexedGraph g1 in rs1) { bool inrs2 = false; for (int i = 0; i < rs2.Count; i++) { IndexedGraph g2 = rs2[i]; if (sgt.MatchNeighborhood(g1, g2, 0) && sgt.MatchNeighborhood(g2, g1, 0)) { inrs2 = true; notin1.Remove(i); break; } } if (!inrs2) { g1.Print(); } } Console.WriteLine("2 not in 1:"); foreach (int i in notin1) { rs2[i].Print(); } }
static void TestPattern(IndexedGraph g) { Graph p = new Graph(); Edge e0 = new Edge(); e0._from = 0; e0._to = 1; e0._eLabel = 0; Edge e1 = new Edge(); e1._from = 0; e1._to = 2; e1._eLabel = 1; Edge e2 = new Edge(); e2._from = 3; e2._to = 2; e2._eLabel = 1; p._edges = new Edge[] { e0, e1, e2 }; Vertex v0 = new Vertex(); v0._inEdge = Vertex.zeroL; v0._outEdge = new int[] { 0, 1 }; v0._vLabel = Vertex.zeroL; Vertex v1 = new Vertex(); v1._inEdge = new int[] { 0 }; v1._outEdge = Vertex.zeroL; v1._vLabel = Vertex.zeroL; Vertex v2 = new Vertex(); v2._inEdge = new int[] { 1, 2 }; v2._outEdge = Vertex.zeroL; v2._vLabel = Vertex.zeroL; Vertex v3 = new Vertex(); v3._inEdge = Vertex.zeroL; v3._outEdge = new int[] { 2 }; v3._vLabel = Vertex.zeroL; p._vertexes = new Vertex[] { v0, v1, v2, v3 }; SubGraphTest sgt = new SubGraphTest(); int cnt = 0; for (int i = 923692; i < 2495971; i++) { if (!sgt.MatchNeighborhood(p, g, i)) { cnt++; Console.WriteLine(1.0 * cnt / (i - 923691)); } } Console.WriteLine(cnt); }
public FrequentNeighborhoodMining(IndexedGraph g) { _g = g; _subGTester = new SubGraphTest(); _niindex = new NodeInvariantIndex(_g); }
public List <Tuple <IndexedGraph, List <int> > > MineEgonet(int minSupp, int maxSize, int maxRadius, int[] constraintVSet) { //bool useVIDList = false; List <int> constraintVSetList = constraintVSet.ToList(); DateTime begin = DateTime.Now; //FrequentPathMining fpm = new FrequentPathMiningDepth(); FrequentPathMining fpm = new FrequentPathMiningBreadth(); fpm.Init(_g, minSupp, maxSize, constraintVSet, true, maxRadius); //fpm.Init(_g, minSupp, maxSize); Console.WriteLine("{0} seconds. {1} path results.", (DateTime.Now - begin).TotalSeconds, fpm._resultCache.Count); List <Tuple <IndexedGraph, List <int> > > ret = new List <Tuple <IndexedGraph, List <int> > >(); Console.WriteLine("Adding {0} paths.", fpm.GetPathAndVID(1).Count); List <Tuple <IndexedGraph, List <int> > > lastResults = fpm.GetPathAndVID(1); ret.AddRange(fpm.GetPathAndVID(1)); //IndexedGraph z = new IndexedGraph(); //z.Read(@"E:\RkNPQ\1.txt"); //SubGraphTest sgt1 = new SubGraphTest(); for (int size = 2; size <= maxSize; size++) { begin = DateTime.Now; Console.WriteLine("Computing Size-{0} Candidate Patterns.", size); List <Tuple <IndexedGraph, List <int> > > tempResults = new List <Tuple <IndexedGraph, List <int> > >(); for (int i = 0; i < lastResults.Count; i++) { for (int j = i; j < lastResults.Count; j++) { List <IndexedGraph> newPatterns = null; List <int> vids = null; if (j == i) { Graph tempG = lastResults[i].Item1.ShallowCopy(); newPatterns = JoinGraphPair(tempG, lastResults[i].Item1); vids = lastResults[i].Item2; } else { vids = Tools.MergeSortedArray(lastResults[i].Item2, lastResults[j].Item2); if (vids.Count < minSupp) { continue; } newPatterns = JoinGraphPair(lastResults[i].Item1, lastResults[j].Item1); } foreach (IndexedGraph pattern in newPatterns) { //if (sgt1.MatchNeighborhood(z, pattern, 0)) //{ // Console.WriteLine(); //} bool hasDup = false; foreach (var pair in tempResults) { if (_subGTester.MatchNeighborhood(pattern, pair.Item1, 0)) { hasDup = true; break; } } if (!hasDup) { tempResults.Add(new Tuple <IndexedGraph, List <int> >(pattern, vids)); } } } } Console.WriteLine("{0} seconds. {1} candidates.", (DateTime.Now - begin).TotalSeconds, tempResults.Count); begin = DateTime.Now; Console.WriteLine("Validating Size-{0} Candidate Patterns.", size); //Compute Zipper Patterns List <Tuple <IndexedGraph, List <int> > > zipperPatterns = new List <Tuple <IndexedGraph, List <int> > >(); if (size > maxRadius + 1 && size <= 2 * maxRadius + 1) { SubGraphTest sgt = new SubGraphTest(true, MapOperationInstances.GetZipperHeads); foreach (var tup in lastResults) { //if(sgt1.MatchNeighborhood(z,tup.Item1,0)) // tup.Item1.Print(); var headPosList = ZipperHandler.DetectPotentialZipper(tup.Item1, maxRadius); if (headPosList == null) { continue; } List <int> vids = null; Dictionary <Tuple <int, int>, List <int> > mapELabel2Vids = new Dictionary <Tuple <int, int>, List <int> >(); vids = tup.Item2; foreach (int i in vids) { sgt.MatchNeighborhood(tup.Item1, _g, i, headPosList); HashSet <Tuple <int, int> > eLabels = new HashSet <Tuple <int, int> >(); sgt._rets.ForEach(e => eLabels.Add((Tuple <int, int>)e)); foreach (var pair in eLabels) { if (!mapELabel2Vids.ContainsKey(pair)) { mapELabel2Vids[pair] = new List <int>(); } mapELabel2Vids[pair].Add(i); } } foreach (var pair in mapELabel2Vids) { if (pair.Value.Count >= minSupp) { Edge newEdge = new Edge(); newEdge._from = headPosList[pair.Key.Item2].Item1; newEdge._to = headPosList[pair.Key.Item2].Item2; newEdge._eLabel = pair.Key.Item1; IndexedGraph g = tup.Item1.ShallowCopy(); Edge[] newEdgeList = new Edge[g._edges.Length + 1]; g._edges.CopyTo(newEdgeList, 0); newEdgeList[newEdgeList.Length - 1] = newEdge; g._edges = newEdgeList; Vertex v1 = g._vertexes[newEdge._from]; int[] newOutEdgeList = new int[v1._outEdge.Length + 1]; v1._outEdge.CopyTo(newOutEdgeList, 0); newOutEdgeList[newOutEdgeList.Length - 1] = newEdgeList.Length - 1; v1._outEdge = newOutEdgeList; Vertex v2 = g._vertexes[newEdge._to]; int[] newInEdgeList = new int[v2._inEdge.Length + 1]; v2._inEdge.CopyTo(newInEdgeList, 0); newInEdgeList[newInEdgeList.Length - 1] = newEdgeList.Length - 1; v2._inEdge = newInEdgeList; g.GenIndex(); zipperPatterns.Add(new Tuple <IndexedGraph, List <int> >(g, pair.Value)); } } } } lastResults.Clear(); foreach (var pair in tempResults) { int supp = 0; List <List <int> > ccands = _niindex.GetCandidatesForeachVertex(pair.Item1); if (ccands.Exists(e => e != null && e.Count == 0)) { continue; } //if (ccands[0].Count < minSupp) //continue; _subGTester._cands = ccands; List <int> vids = null, filteredVids = null; filteredVids = new List <int>(); vids = pair.Item2; foreach (int i in vids) { if (_subGTester.MatchNeighborhood(pair.Item1, _g, i)) { supp++; filteredVids.Add(i); } } _subGTester._cands = null; if (supp >= minSupp) { ret.Add(new Tuple <IndexedGraph, List <int> >(pair.Item1, filteredVids)); //pattern.Print(); //Console.WriteLine(supp+"\n"); lastResults.Add(new Tuple <IndexedGraph, List <int> >(pair.Item1, filteredVids)); } } Console.WriteLine("{0} seconds. {1} results.", (DateTime.Now - begin).TotalSeconds, lastResults.Count); begin = DateTime.Now; if (size <= maxRadius + 1) { var addpath = fpm.GetPathAndVID(size); lastResults.AddRange(addpath); Console.WriteLine("Adding {0} paths.", addpath.Count); //lastResults.Sort((x, y) => x._vertexes.Length - y._vertexes.Length); ret.AddRange(fpm.GetPathAndVID(size)); } else { //add Zipper Patterns Console.WriteLine("Adding {0} Zippers.", zipperPatterns.Count); lastResults.AddRange(zipperPatterns); ret.AddRange(zipperPatterns); } if (lastResults.Count == 0) { break; } } return(ret); }