In[]:=
distanceData=If[#[[1;;2]]{"Vernino","Panachee"},{"Vernino","Panachee",1000.},#]&/@Import["http://geneticdistance.org/DFIC%202010,%20Spatial,%20Spectral%20Radius%20Angle,%20Distances.csv"];Print[Head[#]&/@distanceData[[1]]];vertices=DeleteDuplicates[Flatten[distanceData[[;;,1;;2]]]];testVertex="Vernino";testTargets=Select[vertices,(#≠testVertex)&];edges=(#[[1]]#[[2]])&/@distanceData;edgeWeightsList=distanceData[[;;,3]];edgeWeightsRules=((#[[1]]#[[2]])#[[3]])&/@distanceData;edgeWeightsHash=CreateDataStructure["HashTable"];edgeWeightsHash["Insert",{#[[1]],#[[2]]}#[[3]]]&/@distanceData;edgeWeightsHash["Insert",{#[[2]],#[[1]]}#[[3]]]&/@distanceData;edgeWeightsHash["Insert",{#,#}∞]&/@vertices;weightedAdjacency=Table[Table[edgeWeightsHash["Lookup",{iv,jv}],{jv,vertices}],{iv,vertices}];Print[{Length[vertices],Length[edges]}];Print[vertices[[1;;3]]];Print[edges[[1;;3]]];Print[edgeWeightsList[[1;;3]]];Print[edgeWeightsRules[[1;;3]]];Print[weightedAdjacency[[1;;4,1;;4]]//MatrixForm];
{String,String,Real}
{125,7750}
{Vernino,Panachee,M.C. Smyrnay}
{VerninoPanachee,VerninoM.C. Smyrnay,VerninoUCR 291}
{1000.,20.6984,22.6046}
{VerninoPanachee1000.,VerninoM.C. Smyrnay20.6984,VerninoUCR 29122.6046}
∞ | 1000. | 20.6984 | 22.6046 |
1000. | ∞ | 20.1668 | 25.6787 |
20.6984 | 20.1668 | ∞ | 20.4529 |
22.6046 | 25.6787 | 20.4529 | ∞ |
In[]:=
{tUnweighted,gUnweighted}=AbsoluteTiming[Graph[edges]];Print[tUnweighted];
0.0057683
In[]:=
{tWbyList,gWbyList}=AbsoluteTiming[Graph[vertices,edges,EdgeWeightedgeWeightsList]];adjWbyList=WeightedAdjacencyMatrix[gWbyList];Print[tWbyList];
0.00572
In[]:=
{tWbyAdj,gWbyAdj}=AbsoluteTiming[WeightedAdjacencyGraph[vertices,weightedAdjacency]];adjWbyAdj=WeightedAdjacencyMatrix[gWbyAdj];Print[tWbyAdj];
0.0515591
In[]:=
{tWbyRule,gWbyRule}=AbsoluteTiming[Graph[vertices,edges,EdgeWeightedgeWeightsRules]];adjWbyRule=WeightedAdjacencyMatrix[gWbyRule];Print[tWbyRule];
1.78146
In[]:=
{gWbyAdjgWbyList,gWbyAdjgWbyRule,gWbyListgWbyRule}
Out[]=
{False,False,True}
In[]:=
{adjWbyAdjadjWbyList,adjWbyAdjadjWbyRule,adjWbyListadjWbyRule}
Out[]=
{True,True,True}
In[]:=
testPaths=FindShortestPath[gWbyAdj,testVertex,#]&/@testTargets;Print[testPaths[[1;;3]]//Column];
{Vernino,Green Panachee,Panachee} |
{Vernino,M.C. Smyrnay} |
{Vernino,UCR 291} |