Skip to content

Commit

Permalink
最后一跳优化
Browse files Browse the repository at this point in the history
  • Loading branch information
BigHeadCatWo committed May 6, 2016
1 parent 3b09ef6 commit c2410ad
Show file tree
Hide file tree
Showing 80 changed files with 84 additions and 37 deletions.
Binary file modified .vs/Brute-force1/v14/.suo
Binary file not shown.
Binary file modified .vs/GetOneHopNode/v14/.suo
Binary file not shown.
48 changes: 34 additions & 14 deletions Brute-force1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static void Main(string[] args)
///两跳测试
///id--id
node1 = new KeyValuePair<string, UInt64>("Id", 2094437628);
node2 = new KeyValuePair<string, UInt64>("AA.AuId", 2273736245);
node2 = new KeyValuePair<string, UInt64>("Id", 2088397685);
Solution.solve(node1, node2);
//Solution.testGetThreeHopNodeAsync();

Console.ReadLine();
}
}
Expand Down Expand Up @@ -110,18 +110,26 @@ public static Dictionary<KeyValuePair<string, UInt64>, SortedSet<KeyValuePair<st
foreach (KeyValuePair<string, UInt64> nodeid in hop1set)
{
Task t=Task.Run(()=>{
// Console.WriteLine("find:{0}:{1}", nodeid.Key, nodeid);
// start = DateTime.Now.Ticks;
Console.WriteLine("tofind:{0}", nodeid);
start = DateTime.Now.Ticks;
SortedSet<KeyValuePair<string, UInt64>> tmp = getOneHop.getNode(nodeid);
// end = DateTime.Now.Ticks;
// Console.WriteLine("{0}:获取hop1set花费时间,{1},set大小:{2}", (end - start) / 1000000,nodeid, tmp.Count());
end = DateTime.Now.Ticks;
Console.WriteLine("{0}花费时间:{1},set大小:{2}", nodeid,(end - start) / 1000000, tmp.Count());
dic.Add(nodeid, tmp); });
taskList.Add(t);
}

Task.WaitAll(taskList.ToArray());
return dic;
}
public static void testGetTwoHopNodeAsync()
{
SortedSet<KeyValuePair<string, UInt64>> hop2set = new SortedSet<KeyValuePair<string, ulong>>(new SortedSetComparer());
hop2set.Add(new KeyValuePair<string, ulong>("F.FId", 124657808));

Dictionary<KeyValuePair<string, UInt64>, SortedSet<KeyValuePair<string, UInt64>>> hop3res = GetTwoHopNodeAsync(hop2set);

}
public static void testGetThreeHopNodeAsync()
{
KeyValuePair<string, UInt64> node2 = new KeyValuePair<string, ulong>("AA.AuId", 2273736245);
Expand All @@ -146,6 +154,16 @@ public static SortedSet<KeyValuePair<string, UInt64>> GetThreeHopNodeAsync(Sorte
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;
Expand Down Expand Up @@ -178,10 +196,12 @@ public static SortedSet<KeyValuePair<string, UInt64>> GetThreeHopNodeAsync(Sorte
/// </summary>
/// <param name="node1">节点1</param>
/// <param name="node2">节点2</param>

public static void solve(KeyValuePair<string, UInt64> node1, KeyValuePair<string, UInt64> node2)
{
long count = 0;
long start, end,start_;
int chushu = 100000000;
start_ = DateTime.Now.Ticks;
///step1:获取node1和node2是否存在一跳关系
///方式1:使用and来直接判断,可以避免json序列化过长
Expand All @@ -202,8 +222,8 @@ public static void solve(KeyValuePair<string, UInt64> node1, KeyValuePair<string
start = DateTime.Now.Ticks;
SortedSet<KeyValuePair<string, UInt64>> hop1set = GetOneHopNode(node1);
end = DateTime.Now.Ticks;
Console.WriteLine("一跳查询花费{0}:set大小:{1}", (end - start) / 100000000, hop1set.ToList().Capacity);
if (!(node1.Key.Equals("AA.AuId") && node2.Key.Equals("AA.AuId")))
Console.WriteLine("一跳查询花费{0}:set大小:{1}", (end - start) / chushu, hop1set.ToList().Capacity);
if (!(node1.Key=="AA.AuId" && node2.Key=="AA.AuId"))
{
///当两个节点都是AA.AuId时,不可能存在一跳关系
if (hop1set.Contains<KeyValuePair<string, UInt64>>(node2) == true)
Expand All @@ -218,7 +238,7 @@ public static void solve(KeyValuePair<string, UInt64> node1, KeyValuePair<string
}
}
end = DateTime.Now.Ticks;
Console.WriteLine("一跳全部花费{0}", (end - start) / 100000000);
Console.WriteLine("一跳全部花费{0}", (end - start) / chushu);
///step2:获取两跳关系
///方式1:根据node1的一跳集合用or进行聚合,用and来直接判断,有问题
//start = DateTime.Now.Ticks;
Expand All @@ -235,7 +255,7 @@ public static void solve(KeyValuePair<string, UInt64> node1, KeyValuePair<string
start = DateTime.Now.Ticks;
Dictionary<KeyValuePair<string, UInt64>, SortedSet<KeyValuePair<string, UInt64>>> hop2dic = GetTwoHopNodeAsync(hop1set);
end = DateTime.Now.Ticks;
Console.WriteLine("二跳查询花费{0}", (end - start) / 100000000);
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)
{
Expand All @@ -248,7 +268,7 @@ public static void solve(KeyValuePair<string, UInt64> node1, KeyValuePair<string
}
}
end = DateTime.Now.Ticks;
Console.WriteLine("二跳全部花费{0}:set大小:{1}", (end - start) / 100000000, hop2set.ToList().Capacity);
Console.WriteLine("二跳全部花费{0}:set大小:{1}", (end - start) / chushu, hop2set.ToList().Capacity);
//step3:获取三跳关系
///方式1:根据node1的一跳集合用or进行聚合,用and来直接判断
//start = DateTime.Now.Ticks;
Expand All @@ -262,7 +282,7 @@ public static void solve(KeyValuePair<string, UInt64> node1, KeyValuePair<string
start = DateTime.Now.Ticks;
SortedSet<KeyValuePair<string, UInt64>> hop3res = GetThreeHopNodeAsync(hop2set,node2);
end = DateTime.Now.Ticks;
Console.WriteLine("三跳查询花费{0}", (end - start) / 1000000);
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)
Expand All @@ -275,8 +295,8 @@ public static void solve(KeyValuePair<string, UInt64> node1, KeyValuePair<string
}
}
end = DateTime.Now.Ticks;
Console.WriteLine("三跳全部花费{0}", (end - start) / 1000000);
Console.WriteLine("总时间{0}", (end - start_) / 1000000);
Console.WriteLine("三跳全部花费{0}", (end - start) / chushu);
Console.WriteLine("总时间{0}", (end - start_) / chushu);
}
}
}
Binary file modified Brute-force1/bin/Debug/Brute-force1.exe
Binary file not shown.
Binary file modified Brute-force1/bin/Debug/Brute-force1.pdb
Binary file not shown.
11 changes: 0 additions & 11 deletions Brute-force1/bin/Debug/Brute-force1.vshost.exe.manifest

This file was deleted.

Binary file modified Brute-force1/bin/Debug/GetOneHopNode.dll
Binary file not shown.
Binary file modified Brute-force1/bin/Debug/GetOneHopNode.pdb
Binary file not shown.
Binary file added Brute-force1/bin/Release/Brute-force1.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions Brute-force1/bin/Release/Brute-force1.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Binary file added Brute-force1/bin/Release/Brute-force1.pdb
Binary file not shown.
Binary file added Brute-force1/bin/Release/Brute-force1.vshost.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions Brute-force1/bin/Release/Brute-force1.vshost.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Binary file added Brute-force1/bin/Release/GetOneHopNode.dll
Binary file not shown.
Binary file added Brute-force1/bin/Release/GetOneHopNode.pdb
Binary file not shown.
Binary file added Brute-force1/bin/Release/magApiCs.dll
Binary file not shown.
Binary file added Brute-force1/bin/Release/magApiCs.pdb
Binary file not shown.
Binary file not shown.
Binary file modified Brute-force1/obj/Debug/Brute-force1.exe
Binary file not shown.
Binary file modified Brute-force1/obj/Debug/Brute-force1.pdb
Binary file not shown.
10 changes: 10 additions & 0 deletions Brute-force1/obj/Release/Brute-force1.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
I:\github\tmpqts\Brute-force1\bin\Release\Brute-force1.exe.config
I:\github\tmpqts\Brute-force1\bin\Release\Brute-force1.exe
I:\github\tmpqts\Brute-force1\bin\Release\Brute-force1.pdb
I:\github\tmpqts\Brute-force1\bin\Release\GetOneHopNode.dll
I:\github\tmpqts\Brute-force1\bin\Release\magApiCs.dll
I:\github\tmpqts\Brute-force1\bin\Release\GetOneHopNode.pdb
I:\github\tmpqts\Brute-force1\bin\Release\magApiCs.pdb
I:\github\tmpqts\Brute-force1\obj\Release\Brute-force1.csprojResolveAssemblyReference.cache
I:\github\tmpqts\Brute-force1\obj\Release\Brute-force1.exe
I:\github\tmpqts\Brute-force1\obj\Release\Brute-force1.pdb
Binary file not shown.
Binary file added Brute-force1/obj/Release/Brute-force1.exe
Binary file not shown.
Binary file added Brute-force1/obj/Release/Brute-force1.pdb
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
19 changes: 12 additions & 7 deletions GetOneHopNode/GetOneHopNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public int Compare(KeyValuePair<string, UInt64> x, KeyValuePair<string, UInt64>
/// </summary>
/// <param name="sourceNode"></param>
/// <returns></returns>

public SortedSet<KeyValuePair<string, UInt64>> getNode(KeyValuePair<string, UInt64> sourceNode)
{
ArrayList attr =new ArrayList();
Expand Down Expand Up @@ -92,7 +93,7 @@ public SortedSet<KeyValuePair<string, UInt64>> getNode(KeyValuePair<string, UInt
StringBuilder str = new StringBuilder("Composite(F.FId=");
str.Append(sourceNode.Value.ToString());
str.Append(')');
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: "Id");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 100000, attributes: "Id");
attr = ((ArrayList)dataJson["histograms"]);
break;
}
Expand All @@ -107,6 +108,8 @@ public SortedSet<KeyValuePair<string, UInt64>> getNode(KeyValuePair<string, UInt
}
}
//构造1-hop node列表
Console.WriteLine("hehe");
long start = DateTime.Now.Ticks;
foreach (Dictionary<string, object> s in attr)
{
foreach (Dictionary<string, object> h in (ArrayList)s["histogram"])
Expand All @@ -133,6 +136,8 @@ public SortedSet<KeyValuePair<string, UInt64>> getNode(KeyValuePair<string, UInt
nodeList.Add(new KeyValuePair<string, UInt64>(key, idValue));
}
}
long end = DateTime.Now.Ticks;
Console.WriteLine("cost:{0}", (end - start) / 100000000);
return nodeList;
}
public bool checkNodeWithCondition(KeyValuePair<string, UInt64> sourceNode, KeyValuePair<string, UInt64> dstNode)
Expand All @@ -155,7 +160,7 @@ public bool checkNodeWithCondition(KeyValuePair<string, UInt64> sourceNode, KeyV
else if (!dstNode.Key.Equals("AA.AfId"))
{
str.Append(",Composite(" + dstNode.Key + "=" + dstNode.Value + "))");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: "Id");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: dstNode.Key);
attr = ((ArrayList)dataJson["histograms"]);
}

Expand All @@ -174,7 +179,7 @@ public bool checkNodeWithCondition(KeyValuePair<string, UInt64> sourceNode, KeyV
if (dstNode.Key.Equals("AA.AfId"))
{
str.Append("),Composite(" + dstNode.Key + "=" + dstNode.Value + "))");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: "Id");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: dstNode.Key);
attr = ((ArrayList)dataJson["histograms"]);
}
break;
Expand All @@ -186,7 +191,7 @@ public bool checkNodeWithCondition(KeyValuePair<string, UInt64> sourceNode, KeyV
if (dstNode.Key.Equals("AA.AuId"))
{
str.Append("),Composite(" + dstNode.Key + "=" + dstNode.Value + "))");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: "Id");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: dstNode.Key);
attr = ((ArrayList)dataJson["histograms"]);
}
break;
Expand All @@ -198,7 +203,7 @@ public bool checkNodeWithCondition(KeyValuePair<string, UInt64> sourceNode, KeyV
if (dstNode.Key.Equals("Id"))
{
str.Append(")," + dstNode.Key + "=" + dstNode.Value + ")");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: "Id");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: dstNode.Key);
attr = ((ArrayList)dataJson["histograms"]);
}
break;
Expand All @@ -210,7 +215,7 @@ public bool checkNodeWithCondition(KeyValuePair<string, UInt64> sourceNode, KeyV
if (dstNode.Key.Equals("Id"))
{
str.Append(")," + dstNode.Key + "=" + dstNode.Value + ")");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: "Id");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: dstNode.Key);
attr = ((ArrayList)dataJson["histograms"]);
}
break;
Expand All @@ -222,7 +227,7 @@ public bool checkNodeWithCondition(KeyValuePair<string, UInt64> sourceNode, KeyV
if (dstNode.Key.Equals("Id"))
{
str.Append(")," + dstNode.Key + "=" + dstNode.Value + ")");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: "Id");
Dictionary<string, object> dataJson = mag.GetResponse(str: str.ToString(), count: 10000000, attributes: dstNode.Key);
attr = ((ArrayList)dataJson["histograms"]);
}
break;
Expand Down
Binary file modified GetOneHopNode/bin/Debug/GetOneHopNode.dll
Binary file not shown.
Binary file modified GetOneHopNode/bin/Debug/GetOneHopNode.pdb
Binary file not shown.
Binary file added GetOneHopNode/bin/Release/GetOneHopNode.dll
Binary file not shown.
Binary file added GetOneHopNode/bin/Release/GetOneHopNode.pdb
Binary file not shown.
Binary file added GetOneHopNode/bin/Release/magApiCs.dll
Binary file not shown.
Binary file added GetOneHopNode/bin/Release/magApiCs.pdb
Binary file not shown.
Binary file modified GetOneHopNode/obj/Debug/GetOneHopNode.dll
Binary file not shown.
Binary file modified GetOneHopNode/obj/Debug/GetOneHopNode.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
I:\github\tmpqts\GetOneHopNode\bin\Release\GetOneHopNode.dll
I:\github\tmpqts\GetOneHopNode\bin\Release\GetOneHopNode.pdb
I:\github\tmpqts\GetOneHopNode\bin\Release\magApiCs.dll
I:\github\tmpqts\GetOneHopNode\bin\Release\magApiCs.pdb
I:\github\tmpqts\GetOneHopNode\obj\Release\GetOneHopNode.csprojResolveAssemblyReference.cache
I:\github\tmpqts\GetOneHopNode\obj\Release\GetOneHopNode.dll
I:\github\tmpqts\GetOneHopNode\obj\Release\GetOneHopNode.pdb
Binary file not shown.
Binary file added GetOneHopNode/obj/Release/GetOneHopNode.dll
Binary file not shown.
Binary file added GetOneHopNode/obj/Release/GetOneHopNode.pdb
Binary file not shown.
Empty file.
Empty file.
Empty file.
10 changes: 5 additions & 5 deletions GetOneHopNodeTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ static void Main(string[] args)
{
GetOneHopNodeClass nodeSearch = new GetOneHopNodeClass();
SortedSet<KeyValuePair<string, UInt64>> nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("C.CId", 1192655580));
nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("F.FId", 55004796));
nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("AA.AfId", 204722609));
nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("AA.AuId", 2100880362));
nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("C.CId", 1123349196));
nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("J.JId", 79244937));
nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("F.FId", 124657808));
//nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("AA.AfId", 204722609));
//nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("AA.AuId", 2100880362));
//nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("C.CId", 1123349196));
//nodeList = nodeSearch.getNode(new KeyValuePair<string, ulong>("J.JId", 79244937));
}
}
}
Empty file.
Binary file not shown.
Empty file.
Empty file.
Binary file not shown.
Empty file.
Binary file added magApiCs/bin/Release/magApiCs.dll
Binary file not shown.
Binary file added magApiCs/bin/Release/magApiCs.pdb
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions magApiCs/obj/Release/magApiCs.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
I:\github\tmpqts\magApiCs\bin\Release\magApiCs.dll
I:\github\tmpqts\magApiCs\bin\Release\magApiCs.pdb
I:\github\tmpqts\magApiCs\obj\Release\magApiCs.dll
I:\github\tmpqts\magApiCs\obj\Release\magApiCs.pdb
Binary file added magApiCs/obj/Release/magApiCs.dll
Binary file not shown.
Binary file added magApiCs/obj/Release/magApiCs.pdb
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Binary file modified restServer/bin/magApiCs.dll
Binary file not shown.
Empty file.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit c2410ad

Please sign in to comment.