Пример #1
0
        /// <summary>
        /// 并行获取2-hopNodeLIST
        /// </summary>
        /// <param name="hop1set"></param>
        /// <returns></returns>
        public static Dictionary <KeyValuePair <string, UInt64>, SortedSet <KeyValuePair <string, UInt64> > > GetTwoHopNodeAsync(SortedSet <KeyValuePair <string, UInt64> > hop1set)
        {
            Dictionary <KeyValuePair <string, UInt64>, SortedSet <KeyValuePair <string, UInt64> > > dic = new Dictionary <KeyValuePair <string, ulong>, SortedSet <KeyValuePair <string, ulong> > >();
            //通过id获取one-hop节点集合
            long start, end;
            //
            List <Task> taskList = new List <Task>();
            //
            GetOneHopNodeClass getOneHop = new GetOneHopNodeClass();

            foreach (KeyValuePair <string, UInt64> nodeid in hop1set)
            {
                Task t = Task.Run(() => {
                    //Console.WriteLine("tofind:{0}", nodeid);
                    //start = DateTime.Now.Ticks;
                    SortedSet <KeyValuePair <string, UInt64> > tmp = getOneHop.getNode(nodeid);
                    //end = DateTime.Now.Ticks;
                    //Console.WriteLine("{0}花费时间:{1},set大小:{2}", nodeid,(end - start) / 10000000, tmp.Count());
                    //if(nodeid.Key== "AA.AuId")
                    //    foreach (KeyValuePair<string, UInt64> tmpnode in tmp)
                    //        Console.WriteLine(tmpnode);
                    dic.Add(nodeid, tmp);
                });
                taskList.Add(t);
            }

            Task.WaitAll(taskList.ToArray());
            return(dic);
        }
Пример #2
0
 /// <summary>
 /// 测试用样例
 /// </summary>
 /// <param name="args"></param>
 static void Main(string[] args)
 {
     GetOneHopNodeClass nodeSearch = new GetOneHopNodeClass();
     //SortedSet<KeyValuePair<string, UInt64>> nodeList = nodeSearch.getNextNode(new KeyValuePair<string, ulong>("C.CId", 1192655580));
     //nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("F.FId", 124657808));
     //nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("AA.AfId", 204722609));
     //nodeList = nodeSearch.getLastNode(new KeyValuePair<string, ulong>("AA.AuId", 2100880362));
     //nodeList = nodeSearch.getLastNode(new KeyValuePair<string, ulong>("Id", 2068173719));
     //nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("C.CId", 1123349196));
     //nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("J.JId", 79244937));
 }
Пример #3
0
        public static Dictionary <KeyValuePair <string, UInt64>, SortedSet <KeyValuePair <string, UInt64> > > GetTwoHopNode(SortedSet <KeyValuePair <string, UInt64> > hop1set)
        {
            Dictionary <KeyValuePair <string, UInt64>, SortedSet <KeyValuePair <string, UInt64> > > dic = new Dictionary <KeyValuePair <string, ulong>, SortedSet <KeyValuePair <string, ulong> > >();
            //通过id获取one-hop节点集合
            long start, end;

            foreach (KeyValuePair <string, UInt64> nodeid in hop1set)
            {
                ///Console.WriteLine("find:{0}:{1}", nodeid.Key, nodeid);
                start = DateTime.Now.Ticks;
                GetOneHopNodeClass getOneHop = new GetOneHopNodeClass();
                SortedSet <KeyValuePair <string, UInt64> > tmp = getOneHop.getNode(nodeid);
                end = DateTime.Now.Ticks;
                /// Console.WriteLine("{0}:获取hop1set花费时间", (end - start) / 1000);
                dic.Add(nodeid, tmp);
            }
            return(dic);
        }
Пример #4
0
        public static SortedSet <KeyValuePair <string, UInt64> > GetOneHopNode(KeyValuePair <string, UInt64> nodeid)
        {
            //通过id获取one-hop节点集合
            SortedSet <KeyValuePair <string, UInt64> > retval;

            /*
             * 这里是获取id 的过程,基本上需要两步,第一步通过id获取该id的属性,
             * 第二步通过属性获取有此属性的一跳节点id集合
             */
            /*
             *  获取1-Hop的node list
             *  by Esdreal
             */
            GetOneHopNodeClass getOneHop = new GetOneHopNodeClass();

            retval = getOneHop.getNode(nodeid);
            return(retval);
        }
Пример #5
0
        static void Main(string[] args)
        {
            GetOneHopNodeClass nodeSearch = new GetOneHopNodeClass();
            List <Task>        taskList   = new List <Task>();

            taskList.Add(new Task(() =>
            {
                SortedSet <KeyValuePair <string, UInt64> > nodeList1 = nodeSearch.getNode(new KeyValuePair <string, ulong>("Id", 2274896837));
                Console.WriteLine("nodeList1.end");
            }));
            taskList.Add(new Task(() =>
            {
                SortedSet <KeyValuePair <string, UInt64> > nodeList2 = nodeSearch.getNode(new KeyValuePair <string, ulong>("F.FId", 55004796));
                Console.WriteLine("nodeList2.end");
            }));
            taskList.Add(new Task(() =>
            {
                SortedSet <KeyValuePair <string, UInt64> > nodeList3 = nodeSearch.getNode(new KeyValuePair <string, ulong>("AA.AfId", 204722609));
                Console.WriteLine("nodeList3.end");
            }));
            taskList.Add(new Task(() =>
            {
                SortedSet <KeyValuePair <string, UInt64> > nodeList4 = nodeSearch.getNode(new KeyValuePair <string, ulong>("AA.AuId", 2100880362));
                Console.WriteLine("nodeList4.end");
            }));
            taskList.Add(new Task(() =>
            {
                SortedSet <KeyValuePair <string, UInt64> > nodeList5 = nodeSearch.getNode(new KeyValuePair <string, ulong>("C.CId", 1123349196));
                Console.WriteLine("nodeList5.end");
            }));
            taskList.Add(new Task(() =>
            {
                SortedSet <KeyValuePair <string, UInt64> > nodeList6 = nodeSearch.getNode(new KeyValuePair <string, ulong>("C.CId", 1123349196));
                Console.WriteLine("nodeList6.end");
            }));
            int i = 1;

            foreach (Task t in taskList)
            {
                t.Start();
                Console.WriteLine("nodeList" + i.ToString() + "start");
            }
            Task.WaitAll(taskList.ToArray());
        }
Пример #6
0
        //public static void testGetThreeHopNodeAsync()
        //{
        //    KeyValuePair<string, UInt64> node2 = new KeyValuePair<string, ulong>("AA.AuId", 2273736245);
        //    SortedSet<KeyValuePair<string, UInt64>> hop2set = new SortedSet<KeyValuePair<string, ulong>>(new SortedSetComparer());
        //    hop2set.Add(new KeyValuePair<string, ulong>("Id", 2094437628));
        //    hop2set.Add(new KeyValuePair<string, ulong>("Id", 2088397685));
        //    hop2set.Add(new KeyValuePair<string, ulong>("Id", 2054283902));
        //    SortedSet<KeyValuePair<string, UInt64>> hop3res = GetThreeHopNodeAsync(hop2set, node2);
        //    foreach (KeyValuePair<string, UInt64> lastnode in hop3res)
        //    {
        //        Console.WriteLine(lastnode);
        //    }
        //}
        public static SortedSet <KeyValuePair <string, UInt64> > GetThreeHopNodeAsync(SortedSet <KeyValuePair <string, UInt64> > hop2set, KeyValuePair <string, UInt64> dstNode)
        {
            SortedSet <KeyValuePair <string, UInt64> > res = new SortedSet <KeyValuePair <string, ulong> >(new SortedSetComparer());
            //通过id获取one-hop节点集合
            long start, end;
            //
            List <Task> taskList = new List <Task>();
            //
            GetOneHopNodeClass getOneHop = new GetOneHopNodeClass();

            foreach (KeyValuePair <string, UInt64> nodeid in hop2set)
            {
                if (dstNode.Key == "Id")
                {
                    if (nodeid.Key == "AA.AfId")
                    {
                        continue;
                    }
                }
                if (dstNode.Key == "AA.AuId")
                {
                    if (nodeid.Key != "Id" && nodeid.Key != "AA.AfId")
                    {
                        continue;
                    }
                }
                Task t = Task.Run(() => {
                    //  Console.WriteLine("find:{0}:{1}", nodeid.Key, nodeid);
                    //  start = DateTime.Now.Ticks;
                    if (getOneHop.checkNodeWithCondition(nodeid, dstNode))
                    {
                        res.Add(nodeid);
                    }
                    //   end = DateTime.Now.Ticks;
                    //  Console.WriteLine("{0}:获取hop1set花费时间,{1},set大小:{2}", (end - start) / 1000000,nodeid, tmp.Count());
                });
                taskList.Add(t);
            }

            Task.WaitAll(taskList.ToArray());
            return(res);
        }
Пример #7
0
        /// <summary>
        /// </summary>
        /// <param name="node1">节点1</param>
        /// <param name="node2">节点2</param>

        public static List <List <UInt64> > solve(KeyValuePair <string, UInt64> node1, KeyValuePair <string, UInt64> node2)
        {
            List <List <UInt64> > ans = new List <List <UInt64> >();
            long count = 0;
            long start, end, start_;
            int  chushu = 10000000;

            start_ = DateTime.Now.Ticks;
            GetOneHopNodeClass getOneHop = new GetOneHopNodeClass();
            SortedSet <KeyValuePair <string, UInt64> > lastset = getOneHop.getLastNode(node2);

            Console.WriteLine("lastset大小:{0}", lastset.Count);
            //foreach(KeyValuePair<string, UInt64> tmp in lastset)
            //    Console.WriteLine(tmp);
            ///step1:获取node1和node2是否存在一跳关系
            start = DateTime.Now.Ticks;
            SortedSet <KeyValuePair <string, UInt64> > hop1set = GetOneHopNode(node1);

            Console.WriteLine("hop1set大小:{0}", hop1set.Count);
            end = DateTime.Now.Ticks;
            if (lastset.Contains <KeyValuePair <string, UInt64> >(node1) == true)
            {
                //存在one-hop
                Console.WriteLine("{0}:存在one-hop", count++);
                Console.WriteLine("[{0},{1}]", node1, node2);
                //StreamWriter sw = new StreamWriter("1.txt", true);
                //sw.WriteLine("[{0},{1}]", node1, node2);
                //sw.Flush();
                //sw.Close();
                ans.Add(new List <ulong>()
                {
                    node1.Value, node2.Value
                });
            }
            end = DateTime.Now.Ticks;
            Console.WriteLine("一跳全部花费{0}", (end - start) / chushu);
            ///step2:获取两跳关系
            /// 方式2:根据node1的一跳集合得到node1的两跳集合,看是否包含node2
            start = DateTime.Now.Ticks;
            Dictionary <KeyValuePair <string, UInt64>, SortedSet <KeyValuePair <string, UInt64> > > hop2dic = GetTwoHopNodeAsync(hop1set);

            end = DateTime.Now.Ticks;
            Console.WriteLine("二跳查询花费{0}", (end - start) / chushu);
            SortedSet <KeyValuePair <string, UInt64> > hop2set = new SortedSet <KeyValuePair <string, ulong> >(new SortedSetComparer());

            foreach (KeyValuePair <KeyValuePair <string, UInt64>, SortedSet <KeyValuePair <string, UInt64> > > kv in hop2dic)
            {
                foreach (KeyValuePair <string, UInt64> tmppair in kv.Value)
                {
                    hop2set.Add(tmppair);
                }
                if (kv.Value.Contains(node2))
                {
                    Console.WriteLine("{0}:存在two-hop", count++);
                    Console.WriteLine("[{0},{1},{2}]", node1, kv.Key, node2);
                    ans.Add(new List <ulong> {
                        node1.Value, kv.Key.Value, node2.Value
                    });
                }
            }
            end = DateTime.Now.Ticks;
            Console.WriteLine("二跳全部花费{0}:set大小:{1}", (end - start) / chushu, hop2set.ToList().Capacity);
            //step3:获取三跳关系
            //方式1:从hop2set进行搜索,看是否包含node2
            //start = DateTime.Now.Ticks;
            //SortedSet<KeyValuePair<string, UInt64>> hop3res = GetThreeHopNodeAsync(hop2set, node2);
            //end = DateTime.Now.Ticks;
            //Console.WriteLine("三跳查询花费{0}", (end - start) / chushu);
            //foreach (KeyValuePair<string, UInt64> lastnode in hop3res)
            //{
            //    foreach (KeyValuePair<KeyValuePair<string, UInt64>, SortedSet<KeyValuePair<string, UInt64>>> kv in hop2dic)
            //    {
            //        if (kv.Value.Contains(lastnode))
            //        {
            //            Console.WriteLine("{0}:存在three-hop", count++);
            //            Console.WriteLine("[{0},{1},{2},{3}]", node1, kv.Key, lastnode, node2);
            //        }
            //    }
            //}
            //end = DateTime.Now.Ticks;
            //Console.WriteLine("三跳全部花费{0}", (end - start) / chushu);
            ///方式2:查找hop2set和lastset的交集
            start = DateTime.Now.Ticks;
            int i = 0, j = 0;

            foreach (KeyValuePair <KeyValuePair <string, UInt64>, SortedSet <KeyValuePair <string, UInt64> > > kv in hop2dic)
            {
                foreach (KeyValuePair <string, UInt64> lastNode in lastset)
                {
                    if (kv.Value.Contains(lastNode))
                    {
                        Console.WriteLine("{0}:存在three-hop", count++);
                        Console.WriteLine("[{0},{1},{2},{3}]", node1, kv.Key, lastNode, node2);
                        ans.Add(new List <ulong>()
                        {
                            node1.Value, kv.Key.Value, lastNode.Value, node2.Value
                        });
                    }
                }
            }
            end = DateTime.Now.Ticks;
            Console.WriteLine("三跳全部花费{0}", (end - start) / chushu);
            Console.WriteLine("总时间{0}", (end - start_) / chushu);
            return(ans);
        }
Пример #8
0
        public List <List <UInt64> > solve(KeyValuePair <string, UInt64> srcNode, KeyValuePair <string, UInt64> dstNode)
        {
            List <List <UInt64> > pathList = new List <List <ulong> >();
            //
            SortedSet <KeyValuePair <string, UInt64> > NextNodeOfSrc = null;
            ArrayList nextNodeAttrOfSrcAuid = null;
            Task      getNextNodeOfSrc      = new Task(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        GetOneHopNodeClass getOneHopNode = new GetOneHopNodeClass();
                        NextNodeOfSrc = getOneHopNode.getNextNode(srcNode, ref nextNodeAttrOfSrcAuid);
                        break;
                    }
                    catch (Exception ex)
                    {
                        ;
                    }
                }
            });
            //
            SortedSet <KeyValuePair <string, UInt64> > LastNodeOfdst = null;
            ArrayList LastNodeAttrOfDst = null;
            Task      getLastNodeOfdst  = new Task(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        GetOneHopNodeClass getOneHopNode = new GetOneHopNodeClass();
                        LastNodeOfdst = getOneHopNode.getLastNode(dstNode, ref LastNodeAttrOfDst);
                        break;
                    }
                    catch
                    {
                        ;
                    }
                }
            });

            //
            getNextNodeOfSrc.Start();
            getLastNodeOfdst.Start();
            //search for 1-hop
            #region search for 1-hop
            getNextNodeOfSrc.Wait();
            if (NextNodeOfSrc.Contains(dstNode))
            {
                //Console.WriteLine("1-hop存在:\n{0}-{1}", srcNode, dstNode);
                lock (pathList)
                    pathList.Add(new List <ulong>()
                    {
                        srcNode.Value, dstNode.Value
                    });
            }
            else
            {
                //Console.WriteLine("1-hup不存在");
            }
            #endregion
            #region search for 2-hop
            Task searchOf2hop = new Task(() =>
            {
                getLastNodeOfdst.Wait();
                SortedSet <KeyValuePair <string, UInt64> > instSet = new SortedSet <KeyValuePair <string, ulong> >(new GetOneHopNodeClass.SortedSetComparer());
                foreach (var s in NextNodeOfSrc)
                {
                    instSet.Add(s);
                }
                instSet.IntersectWith(LastNodeOfdst);
                if (instSet.Count != 0)
                {
                    //Console.WriteLine("2-hop存在");
                    foreach (var s in instSet)
                    {
                        //Console.WriteLine("{0}-{1}-{2}", srcNode, s, dstNode);
                        lock (pathList)
                            pathList.Add(new List <ulong>()
                            {
                                srcNode.Value, s.Value, dstNode.Value
                            });
                    }
                }
                else
                {
                    //Console.WriteLine("2-hop不存在");
                }
            });
            #endregion
            searchOf2hop.Start();
            //3-hop
            #region
            List <string> str1L = new List <string>();

            List <string> strLAuId = new List <string>();
            List <string> strLAfId = new List <string>();
            List <string> strRAuId = new List <string>();
            List <string> strRAfId = new List <string>();

            HashSet <UInt64> nextNodeOfSrcHash = new HashSet <ulong>();
            HashSet <UInt64> lastNodeOfDstHash = new HashSet <ulong>();
            #endregion
            #region 遍历nextNodeOfSrc,构造hash
            foreach (KeyValuePair <string, UInt64> s in NextNodeOfSrc)
            {
                nextNodeOfSrcHash.Add(s.Value);
                switch (s.Key)
                {
                case "Id":
                {
                    str1L.Add("Id=" + s.Value.ToString());
                    break;
                }

                case "F.FId":
                {
                    break;
                }

                case "C.CId":
                {
                    break;
                }

                case "J.JId":
                {
                    break;
                }

                case "AA.AuId":
                {
                    string value = s.Value.ToString();
                    strLAuId.Add("composite(AA.AuId=" + value + ')');
                    break;
                }

                case "AA.AfId":
                {
                    break;
                }
                }
            }
            #endregion
            #region 遍历LastNodeOfDst 构造hash
            Task hashOfLastNodeOfDst = new Task(() =>
            {
                getLastNodeOfdst.Wait();
                foreach (KeyValuePair <string, UInt64> s in LastNodeOfdst)
                {
                    lastNodeOfDstHash.Add(s.Value);
                    switch (s.Key)
                    {
                    case "Id":
                        {
                            break;
                        }

                    case "F.FId":
                        {
                            break;
                        }

                    case "C.CId":
                        {
                            break;
                        }

                    case "J.JId":
                        {
                            break;
                        }

                    case "AA.AuId":
                        {
                            strRAuId.Add("composite(AA.AuId=" + s.Value.ToString() + ')');
                            break;
                        }

                    case "AA.AfId":
                        {
                            strRAfId.Add("composite(AA.AfId=" + s.Value.ToString() + ')');
                            break;
                        }
                    }
                }
            });
            hashOfLastNodeOfDst.Start();
            #endregion
            #region threeHop_task_1 Id->Id,F,C,J,A (for src=id)
            Task threeHop_str1 = new Task(() =>
            {
                if (str1L.Count == 0)
                {
                    return;
                }
                int maxExprNum       = 60;
                List <Task> taskList = new List <Task>();
                List <List <string> > taskStrList = new List <List <string> >();
                //ToDo
                for (int iPart = 0; iPart < str1L.Count; iPart += maxExprNum)
                {
                    List <string> str1Lpart = str1L.GetRange(iPart, Math.Min(maxExprNum, str1L.Count - iPart));
                    #region new task
                    Task taskPart = new Task(() =>
                    {
                        UInt64 MaxCount    = 1000000;
                        string str1LT      = string.Join(",or(", str1Lpart.ToArray());
                        StringBuilder str1 = new StringBuilder($"or({str1LT}");
                        str1.Append(',' + str1Lpart.Last().ToString());
                        for (int i = 0; i < str1Lpart.Count(); i++)
                        {
                            str1.Append(')');
                        }
                        //Console.WriteLine("@@@TestAsync:{0}", str1);
                        magApi mag     = new magApi();
                        ArrayList attr = new ArrayList();
                        Dictionary <string, Object> dataJson = null;
                        for (int i = 0; i < 10; i++)
                        {
                            try
                            {
                                dataJson = mag.GetResponse(str: str1.ToString(), count: MaxCount, attributes: "Id,RId,F.FId,C.CId,J.JId,AA.AuId");
                                break;
                            }
                            catch (Exception ex)
                            {
                                ;
                            }
                        }
                        attr = ((ArrayList)dataJson["entities"]);
                        #region 等待hashOfLastNodeOfDst
                        hashOfLastNodeOfDst.Wait();
                        #endregion
                        #region 查找path
                        foreach (Dictionary <string, object> s in attr)
                        {
                            UInt64 selectedId = Convert.ToUInt64((s["Id"]));
                            foreach (KeyValuePair <string, object> h in s)
                            {
                                if (h.Key == "logprob" || h.Key == "Id")
                                {
                                    continue;
                                }
                                if (h.Key == "RId")
                                {
                                    foreach (object t in (ArrayList)h.Value)
                                    {
                                        if (lastNodeOfDstHash.Contains(Convert.ToUInt64(t)))
                                        {
                                            lock (pathList)
                                                pathList.Add(new List <ulong>()
                                                {
                                                    srcNode.Value, selectedId, Convert.ToUInt64(t), dstNode.Value
                                                });
                                            //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("Id", selectedId), new KeyValuePair<string, UInt64>("Id", Convert.ToUInt64(t)), dstNode);
                                        }
                                    }
                                    continue;
                                }
                                if (h.Key == "J" || h.Key == "C")
                                {
                                    foreach (KeyValuePair <string, object> t in (Dictionary <string, object>)h.Value)
                                    {
                                        if (lastNodeOfDstHash.Contains(Convert.ToUInt64(t.Value)))
                                        {
                                            lock (pathList)
                                                pathList.Add(new List <ulong>()
                                                {
                                                    srcNode.Value, selectedId, Convert.ToUInt64(t.Value), dstNode.Value
                                                });
                                            //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("Id", selectedId), t, dstNode);
                                        }
                                    }
                                    continue;
                                }
                                foreach (Dictionary <string, object> h1 in (ArrayList)h.Value)
                                {
                                    foreach (KeyValuePair <string, object> t in h1)
                                    {
                                        if (lastNodeOfDstHash.Contains(Convert.ToUInt64(t.Value)))
                                        {
                                            lock (pathList)
                                                pathList.Add(new List <ulong>()
                                                {
                                                    srcNode.Value, selectedId, Convert.ToUInt64(t.Value), dstNode.Value
                                                });
                                            //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("Id", selectedId), t, dstNode);
                                        }
                                    }
                                }
                            }
                        }
                    }
                                             );
                    #endregion
                    taskList.Add(taskPart);
                }
                foreach (Task t in taskList)
                {
                    t.Start();
                }
                Task.WaitAll(taskList.ToArray());
                #endregion
            });
            #endregion
            #region  threeHop_task_2 F,C,J,A->Id
            Task threeHop_str2 = new Task(() =>
            {
                getLastNodeOfdst.Wait();
                foreach (Dictionary <string, object> s in LastNodeAttrOfDst)
                {
                    UInt64 selectedId = Convert.ToUInt64((s["Id"]));
                    foreach (KeyValuePair <string, object> h in s)
                    {
                        if (h.Key == "logprob" || h.Key == "Id")
                        {
                            continue;
                        }
                        if (h.Key == "J" || h.Key == "C")
                        {
                            foreach (KeyValuePair <string, object> t in (Dictionary <string, object>)h.Value)
                            {
                                if (nextNodeOfSrcHash.Contains(Convert.ToUInt64(t.Value)))
                                {
                                    lock (pathList)
                                        pathList.Add(new List <ulong>()
                                        {
                                            srcNode.Value, Convert.ToUInt64(t.Value), selectedId, dstNode.Value
                                        });
                                    //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, t, new KeyValuePair<string, UInt64>("Id", selectedId), dstNode);
                                }
                            }
                            continue;
                        }

                        foreach (Dictionary <string, object> h1 in (ArrayList)h.Value)
                        {
                            foreach (KeyValuePair <string, object> t in h1)
                            {
                                if (t.Key == "AfId")
                                {
                                    continue;
                                }
                                if (nextNodeOfSrcHash.Contains(Convert.ToUInt64(t.Value)))
                                {
                                    lock (pathList)
                                        pathList.Add(new List <ulong>()
                                        {
                                            srcNode.Value, Convert.ToUInt64(t.Value), selectedId, dstNode.Value
                                        });
                                    //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, (t), new KeyValuePair<string, UInt64>("Id", selectedId), dstNode);
                                }
                            }
                        }
                    }
                }
            });
            #endregion
            #region threeHop_task_1 Id->Id,F,C,J,A(for src = auid)
            Task threeHop_str1_scrAuid = new Task(() =>
            {
                hashOfLastNodeOfDst.Wait();
                foreach (Dictionary <string, object> s in nextNodeAttrOfSrcAuid)
                {
                    UInt64 selectedId = Convert.ToUInt64((s["Id"]));
                    foreach (KeyValuePair <string, object> h in s)
                    {
                        if (h.Key == "logprob" || h.Key == "Id")
                        {
                            continue;
                        }
                        if (h.Key == "RId")
                        {
                            foreach (object t in (ArrayList)h.Value)
                            {
                                if (lastNodeOfDstHash.Contains(Convert.ToUInt64(t)))
                                {
                                    lock (pathList)
                                        pathList.Add(new List <ulong>()
                                        {
                                            srcNode.Value, selectedId, Convert.ToUInt64(t), dstNode.Value
                                        });
                                    //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("Id", selectedId), new KeyValuePair<string, UInt64>("Id", Convert.ToUInt64(t)), dstNode);
                                }
                            }
                            continue;
                        }
                        if (h.Key == "J" || h.Key == "C")
                        {
                            foreach (KeyValuePair <string, object> t in (Dictionary <string, object>)h.Value)
                            {
                                if (lastNodeOfDstHash.Contains(Convert.ToUInt64(t.Value)))
                                {
                                    lock (pathList)
                                        pathList.Add(new List <ulong>()
                                        {
                                            srcNode.Value, selectedId, Convert.ToUInt64(t.Value), dstNode.Value
                                        });
                                    //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("Id", selectedId), t, dstNode);
                                }
                            }
                            continue;
                        }

                        foreach (Dictionary <string, object> h1 in (ArrayList)h.Value)
                        {
                            foreach (KeyValuePair <string, object> t in h1)
                            {
                                if (t.Key == "AfId")
                                {
                                    continue;
                                }
                                if (lastNodeOfDstHash.Contains(Convert.ToUInt64(t.Value)))
                                {
                                    lock (pathList)
                                        pathList.Add(new List <ulong>()
                                        {
                                            srcNode.Value, selectedId, Convert.ToUInt64(t.Value), dstNode.Value
                                        });
                                    //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("Id", selectedId), (t), dstNode);
                                }
                            }
                        }
                    }
                }
            });
            #endregion
            #region id-auid-afid-auid
            Task threeHop_auidAfidForIdSrc = new Task(() =>
            {
                if (strLAuId.Count == 0)
                {
                    return;
                }
                hashOfLastNodeOfDst.Wait();
                UInt64 MaxCount    = 1000000;
                StringBuilder strL = new StringBuilder("or(" + string.Join(",or(", strLAuId.ToArray()));
                strL.Append(',' + strLAuId.Last().ToString());
                for (int i = 0; i < strLAuId.Count(); i++)
                {
                    strL.Append(')');
                }
                StringBuilder strR = new StringBuilder("or(" + string.Join(",or(", strRAfId.ToArray()));
                strR.Append(',' + strRAfId.Last().ToString());
                for (int i = 0; i < strRAfId.Count(); i++)
                {
                    strR.Append(')');
                }
                StringBuilder str = new StringBuilder($"and({strL.ToString()},{strR.ToString()})");
                magApi mag        = new magApi();
                ArrayList attr    = new ArrayList();
                Dictionary <string, Object> dataJson = null;
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        dataJson = mag.GetResponse(str: str.ToString(), count: MaxCount, attributes: "AA.AfId,AA.AuId");
                        break;
                    }
                    catch (Exception ex)
                    {
                        ;
                    }
                }
                attr = ((ArrayList)dataJson["entities"]);
                foreach (Dictionary <string, object> s in attr)
                {
                    foreach (KeyValuePair <string, object> h in s)
                    {
                        if (h.Key == "AA")
                        {
                            foreach (Dictionary <string, object> h1 in (ArrayList)h.Value)
                            {
                                try
                                {
                                    if (nextNodeOfSrcHash.Contains(Convert.ToUInt64(h1["AuId"])) && lastNodeOfDstHash.Contains(Convert.ToUInt64(h1["AfId"])))
                                    {
                                        lock (pathList)
                                            pathList.Add(new List <ulong>()
                                            {
                                                srcNode.Value, Convert.ToUInt64(h1["AuId"]), Convert.ToUInt64(h1["AfId"]), dstNode.Value
                                            });
                                        ////Console.WriteLine("auidAfId");
                                        //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("AuId", Convert.ToUInt64(h1["AuId"])), new KeyValuePair<string, UInt64>("AfId", Convert.ToUInt64(h1["AfId"])), dstNode);
                                    }
                                }
                                catch
                                { }
                            }
                        }
                    }
                }
            });
            #endregion
            #region auid-afid-auid-id
            Task threeHop_afidAuidForIdAuid = new Task(() =>
            {
                hashOfLastNodeOfDst.Wait();
                if (strLAfId.Count == 0)
                {
                    return;
                }
                UInt64 MaxCount    = 1000000;
                StringBuilder strL = new StringBuilder("or(" + string.Join(",or(", strLAfId.ToArray()));
                strL.Append(',' + strLAfId.Last().ToString());
                for (int i = 0; i < strLAfId.Count(); i++)
                {
                    strL.Append(')');
                }
                StringBuilder strR = new StringBuilder("or(" + string.Join(",or(", strRAuId.ToArray()));
                strR.Append(',' + strRAuId.Last().ToString());
                for (int i = 0; i < strRAuId.Count(); i++)
                {
                    strR.Append(')');
                }
                StringBuilder str = new StringBuilder($"and({strL.ToString()},{strR.ToString()})");
                magApi mag        = new magApi();
                ArrayList attr    = new ArrayList();
                Dictionary <string, Object> dataJson = null;
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        dataJson = mag.GetResponse(str: str.ToString(), count: MaxCount, attributes: "AA.AfId,AA.AuId");
                        break;
                    }
                    catch (Exception ex)
                    {
                        ;
                    }
                }
                attr = ((ArrayList)dataJson["entities"]);
                foreach (Dictionary <string, object> s in attr)
                {
                    foreach (KeyValuePair <string, object> h in s)
                    {
                        if (h.Key == "AA")
                        {
                            foreach (Dictionary <string, object> h1 in (ArrayList)h.Value)
                            {
                                try
                                {
                                    if (nextNodeOfSrcHash.Contains(Convert.ToUInt64(h1["AfId"])) && lastNodeOfDstHash.Contains(Convert.ToUInt64(h1["AuId"])))
                                    {
                                        lock (pathList)
                                            pathList.Add(new List <ulong>()
                                            {
                                                srcNode.Value, Convert.ToUInt64(h1["AfId"]), Convert.ToUInt64(h1["AuId"]), dstNode.Value
                                            });
                                        ////Console.WriteLine("auidAfId");
                                        //Console.WriteLine("3-hop:{0}-{1}-{2}-{3}", srcNode, new KeyValuePair<string, UInt64>("AfId", Convert.ToUInt64(h1["AfId"])), new KeyValuePair<string, UInt64>("AuId", Convert.ToUInt64(h1["AuId"])), dstNode);
                                    }
                                }
                                catch
                                { }
                            }
                        }
                    }
                }
            });
            #endregion
            //3-hop
            if (srcNode.Key == "Id")
            {
                threeHop_str1.Start();
            }
            else
            {
                threeHop_str1_scrAuid.Start();
            }
            if (srcNode.Key == "Id" && dstNode.Key == "AA.AuId")
            {
                threeHop_auidAfidForIdSrc.Start();
            }
            if (srcNode.Key == "AA.AuId" && dstNode.Key == "Id")
            {
                threeHop_afidAuidForIdAuid.Start();
            }
            threeHop_str2.Start();
            if (srcNode.Key == "Id")
            {
                threeHop_str1.Wait();
            }
            else
            {
                threeHop_str1_scrAuid.Wait();
            }
            if (srcNode.Key == "Id" && dstNode.Key == "AA.AuId")
            {
                threeHop_auidAfidForIdSrc.Wait();
            }
            if (srcNode.Key == "AA.AuId" && dstNode.Key == "Id")
            {
                threeHop_afidAuidForIdAuid.Wait();
            }
            threeHop_str2.Wait();
            searchOf2hop.Wait();
            Task.WaitAll();
            HashSet <List <UInt64> > hashPathList = new HashSet <List <ulong> >(pathList, new SortedSetComparer());
            return(hashPathList.ToList());
        }