Skip to content

Commit

Permalink
添加一种暴力方法
Browse files Browse the repository at this point in the history
  • Loading branch information
BigHeadCatWo committed May 5, 2016
1 parent 3ec1fb9 commit faaf9d7
Show file tree
Hide file tree
Showing 69 changed files with 1,348 additions and 0 deletions.
Binary file added .vs/Brute-force1/v14/.suo
Binary file not shown.
Binary file added .vs/GetOneHopNode/v14/.suo
Binary file not shown.
1,038 changes: 1,038 additions & 0 deletions .vs/config/applicationhost.config

Large diffs are not rendered by default.

Binary file added .vs/magApiCs/v14/.suo
Binary file not shown.
Binary file added .vs/magApiPython/v14/.suo
Binary file not shown.
Binary file added .vs/restServer/v14/.suo
Binary file not shown.
Binary file added .vs/ympqts/v14/.suo
Binary file not shown.
156 changes: 156 additions & 0 deletions Brute-force1/Program2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GetOneHopNode;
using System.Collections;

namespace Brute_force1
{

class Program2
{
static void Main(string[] args)
{
KeyValuePair<string, UInt64> node1;
KeyValuePair<string, UInt64> node2;
// ///一跳测试
// ///id--id
// node1 = new KeyValuePair<string, UInt64>("Id", 2140251882);
// node2 = new KeyValuePair<string, UInt64>("Id", 2143554828);
// Solution2.solve(node1, node2);
// ///id--AA.AuId
// node1 = new KeyValuePair<string, UInt64>("Id", 2140251882);
// node2 = new KeyValuePair<string, UInt64>("AA.AuId", 2145115012);
// Solution2.solve(node1, node2);
// ///AA.AuId--id
// node1 = new KeyValuePair<string, UInt64>("AA.AuId", 2145115012);
// node2 = new KeyValuePair<string, UInt64>("Id", 2140251882);
// Solution2.solve(node1, node2);
// ///AA.AuId--AA.AuId
// node1 = new KeyValuePair<string, UInt64>("AA.AuId", 2145115012);
// node2 = new KeyValuePair<string, UInt64>("AA.AuId", 2145115015);
///id to id 1970381522 to 2162351023 大家算出来多少? 36
///[id, AA.AuId]=[2273736245,2094437628]有多少对啊? 41 19
///大家看看这组数据有多少边,我这里出来2584条,感觉有点虚:2126125555,2153635508
///两跳测试
///id--id
node1 = new KeyValuePair<string, UInt64>("Id", 2126125555);
node2 = new KeyValuePair<string, UInt64>("Id", 2153635508);
Solution2.solve(node1, node2);

Console.ReadLine();
}
}
class Solution2
{
private class SortedSetComparer : IComparer<KeyValuePair<string, UInt64>>
{
public int Compare(KeyValuePair<string, UInt64> x, KeyValuePair<string, UInt64> y)
{
if (x.Key != y.Key)
return x.Key.CompareTo(y.Key);
else
return x.Value.CompareTo(y.Value);
}
}

/// <summary>
/// pair比较函数,小于号
/// </summary>
/// <param name="o1">操作数1</param>
/// <param name="o2">操作数2</param>
/// <returns></returns>
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;
}
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;
}
/// <summary>
/// </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;
///step1:获取node1和node2是否存在一跳关系
start = DateTime.Now.Ticks;
SortedSet <KeyValuePair<string, UInt64>> hop1set = GetOneHopNode(node1);
end = DateTime.Now.Ticks;
Console.WriteLine("时间{0}:set大小:{1}",(end-start)/1000000, hop1set.ToList().Capacity);
if (!(node1.Key.Equals("AA.AuId") && node2.Key.Equals("AA.AuId")))
{
///当两个节点都是AA.AuId时,不可能存在一跳关系
if (hop1set.Contains<KeyValuePair<string, UInt64>>(node2) == true)
{
//存在one-hop
Console.WriteLine("{0}:存在one-hop", count++);
Console.WriteLine("[{0},{1}]", node1, node2);
}
}
///step2:获取两跳关系
start = DateTime.Now.Ticks;
Dictionary<KeyValuePair<string, UInt64>, SortedSet<KeyValuePair<string, UInt64>>> hop2dic = GetTwoHopNode(hop1set);
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);
}
}

end = DateTime.Now.Ticks;
Console.WriteLine("时间{0}:set大小:{1}", (end - start) / 1000000, hop2set.ToList().Capacity);
//step3:获取三跳关系
start = DateTime.Now.Ticks;
Dictionary<KeyValuePair<string, UInt64>, SortedSet<KeyValuePair<string, UInt64>>> hop3dic = GetTwoHopNode(hop2set);
SortedSet<KeyValuePair<string, UInt64>> hop3set = new SortedSet<KeyValuePair<string, ulong>>(new SortedSetComparer());
foreach (KeyValuePair<KeyValuePair<string, UInt64>, SortedSet<KeyValuePair<string, UInt64>>> kv in hop3dic)
{
hop3set.Union(kv.Value);
if (kv.Value.Contains(node2))
{
Console.WriteLine("{0}:存在three-hop", count++);
Console.WriteLine("[{0},{1},{2}]", node1, kv.Key, node2);
}

}
end = DateTime.Now.Ticks;
Console.WriteLine("时间{0}:set大小:{1}", (end - start) / 1000000, hop3set.ToList().Capacity);
}
}
}
Binary file added Brute-force1/bin/Debug/Brute-force1.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions Brute-force1/bin/Debug/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/Debug/Brute-force1.pdb
Binary file not shown.
Binary file added Brute-force1/bin/Debug/Brute-force1.vshost.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions Brute-force1/bin/Debug/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>
11 changes: 11 additions & 0 deletions Brute-force1/bin/Debug/Brute-force1.vshost.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file added Brute-force1/bin/Debug/GetOneHopNode.dll
Binary file not shown.
Binary file added Brute-force1/bin/Debug/GetOneHopNode.pdb
Binary file not shown.
Binary file added Brute-force1/bin/Debug/magApiCs.dll
Binary file not shown.
Binary file added Brute-force1/bin/Debug/magApiCs.pdb
Binary file not shown.
10 changes: 10 additions & 0 deletions Brute-force1/obj/Debug/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\Debug\Brute-force1.exe.config
I:\github\tmpqts\Brute-force1\bin\Debug\Brute-force1.exe
I:\github\tmpqts\Brute-force1\bin\Debug\Brute-force1.pdb
I:\github\tmpqts\Brute-force1\bin\Debug\GetOneHopNode.dll
I:\github\tmpqts\Brute-force1\bin\Debug\magApiCs.dll
I:\github\tmpqts\Brute-force1\bin\Debug\GetOneHopNode.pdb
I:\github\tmpqts\Brute-force1\bin\Debug\magApiCs.pdb
I:\github\tmpqts\Brute-force1\obj\Debug\Brute-force1.csprojResolveAssemblyReference.cache
I:\github\tmpqts\Brute-force1\obj\Debug\Brute-force1.exe
I:\github\tmpqts\Brute-force1\obj\Debug\Brute-force1.pdb
Binary file not shown.
Binary file added Brute-force1/obj/Debug/Brute-force1.exe
Binary file not shown.
Binary file added Brute-force1/obj/Debug/Brute-force1.pdb
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file added GetOneHopNode/bin/Debug/GetOneHopNode.dll
Binary file not shown.
Binary file added GetOneHopNode/bin/Debug/GetOneHopNode.pdb
Binary file not shown.
Binary file added GetOneHopNode/bin/Debug/magApiCs.dll
Binary file not shown.
Binary file added GetOneHopNode/bin/Debug/magApiCs.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\Debug\GetOneHopNode.dll
I:\github\tmpqts\GetOneHopNode\bin\Debug\GetOneHopNode.pdb
I:\github\tmpqts\GetOneHopNode\bin\Debug\magApiCs.dll
I:\github\tmpqts\GetOneHopNode\bin\Debug\magApiCs.pdb
I:\github\tmpqts\GetOneHopNode\obj\Debug\GetOneHopNode.csprojResolveAssemblyReference.cache
I:\github\tmpqts\GetOneHopNode\obj\Debug\GetOneHopNode.dll
I:\github\tmpqts\GetOneHopNode\obj\Debug\GetOneHopNode.pdb
Binary file not shown.
Binary file added GetOneHopNode/obj/Debug/GetOneHopNode.dll
Binary file not shown.
Binary file added GetOneHopNode/obj/Debug/GetOneHopNode.pdb
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file not shown.
Binary file added UpgradeLog.htm
Binary file not shown.
Binary file added bin/Debug/ConsoleApplication.vshost.exe
Binary file not shown.
11 changes: 11 additions & 0 deletions bin/Debug/ConsoleApplication.vshost.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file added magApiCs/bin/Debug/magApiCs.dll
Binary file not shown.
Binary file added magApiCs/bin/Debug/magApiCs.pdb
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions magApiCs/obj/Debug/magApiCs.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
I:\github\tmpqts\magApiCs\bin\Debug\magApiCs.dll
I:\github\tmpqts\magApiCs\bin\Debug\magApiCs.pdb
I:\github\tmpqts\magApiCs\obj\Debug\magApiCs.csprojResolveAssemblyReference.cache
I:\github\tmpqts\magApiCs\obj\Debug\magApiCs.dll
I:\github\tmpqts\magApiCs\obj\Debug\magApiCs.pdb
Binary file not shown.
Binary file added magApiCs/obj/Debug/magApiCs.dll
Binary file not shown.
Binary file added magApiCs/obj/Debug/magApiCs.pdb
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
73 changes: 73 additions & 0 deletions ympqts.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{AF931A15-2C11-42CF-8FCB-9F12F1BE1E23}</ProjectGuid>
<OutputType>Exe</OutputType>
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>ConsoleApplication</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup>
<RootNamespace>ympqts</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Content Include=".gitattributes" />
<Content Include=".gitignore" />
<Content Include="magApiPython\magApiPython.py" />
<Content Include="restServer\restServer.csproj" />
<Content Include="restServer\Service1.svc" />
<Content Include="新建文本文档.txt" />
</ItemGroup>
<ItemGroup>
<None Include="magApiPython\magApiPython.pyproj" />
<None Include="restServer\Web.config" />
<None Include="restServer\Web.Debug.config" />
<None Include="restServer\Web.Release.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="restServer\IService1.cs" />
<Compile Include="restServer\Properties\AssemblyInfo.cs" />
<Compile Include="restServer\Service1.svc.cs">
<DependentUpon>Service1.svc</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include=".git\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
<VisualStudio AllowExistingFolder="true" />
</ProjectExtensions>
</Project>
3 changes: 3 additions & 0 deletions ympqts.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
22 changes: 22 additions & 0 deletions ympqts.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ympqts", "ympqts.csproj", "{AF931A15-2C11-42CF-8FCB-9F12F1BE1E23}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AF931A15-2C11-42CF-8FCB-9F12F1BE1E23}.Debug|x86.ActiveCfg = Debug|x86
{AF931A15-2C11-42CF-8FCB-9F12F1BE1E23}.Debug|x86.Build.0 = Debug|x86
{AF931A15-2C11-42CF-8FCB-9F12F1BE1E23}.Release|x86.ActiveCfg = Release|x86
{AF931A15-2C11-42CF-8FCB-9F12F1BE1E23}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Empty file added 新建文本文档.txt
Empty file.

0 comments on commit faaf9d7

Please sign in to comment.