In[]:=
distanceData=If[#[[1;;2]]{"Vernino","Panachee"},{"Vernino","Panachee",1000.},#]&/@Import["http://geneticdistance.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}
{VerninoPanachee,VerninoM.C. Smyrnay,VerninoUCR 291}
{1000.,20.6984,22.6046}
{VerninoPanachee1000.,VerninoM.C. Smyrnay20.6984,VerninoUCR 29122.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,EdgeWeightedgeWeightsList]];​​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,EdgeWeightedgeWeightsRules]];​​adjWbyRule=WeightedAdjacencyMatrix[gWbyRule];​​Print[tWbyRule];
1.78146
In[]:=
{gWbyAdjgWbyList,gWbyAdjgWbyRule,gWbyListgWbyRule}
Out[]=
{False,False,True}
In[]:=
{adjWbyAdjadjWbyList,adjWbyAdjadjWbyRule,adjWbyListadjWbyRule}
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}