# Creating a Network from a Output

So I used the locator pane to derive the positions of a vertex on a picture. The picture was the Maryland Power Grid and the vertices were the generators and loads of the power system. When I clicked the vertex and recorded it returned this (Vertex number {x-pos,y-pos}). After recording all the vertices I have a list of data and from this list I would like to graphically plot this network with their relative coordinates. From the output I would like to graphically create a minimum spanning network with the loads as either a certain color/shape and the generators as another distinct color and shape. From this I would like to run calculations such as Monte Carlo Simulations, create an adjacency matrix, and possibly even mess around with Markov Random Fields. I need help figuring out how to graphically represent it with color/shape distinctions between the loads and generators and produce a minimum spanning network from the output I received. The Input code was:

im= Import["http://esm.versar.com/pprp/ceir16/Images/Figure2_20.jpg"];
Module[{picturesize,i,bigger,imagesizes},
picturesize=675;
values={};
i=1;
imagesizes=ImageDimensions[im];bigger=1;
DynamicModule[{pt={0,0}},
If[imagesizes[[1]]<imagesizes[[2]], bigger=2];
TableForm@{
Button["Record!",AppendTo[values,{i,pt}];i++;],
LocatorPane[
Dynamic@pt,
Dynamic@Graphics[
Join[
{Inset[im,{0,0},{0,0},{1,1}]}

],
PlotRange->{{0,imagesizes[[1]]/imagesizes[[bigger]]},{0,imagesizes[[2]]/imagesizes[[bigger]]}},
ImageSize->picturesize]
],
Dynamic[N@pt],
Dynamic[MatrixForm@values]
}]
]


The Output was:

({
{1, {0.0996, 0.4195}},
{2, {0.1046, 0.392}},
{3, {0.1144, 0.468}},
{4, {0.1164, 0.4415}},
{5, {0.1432, 0.4455}},
{6, {0.1442, 0.376}},
{7, {0.147, 0.5085}},
{8, {0.16, 0.4965}},
{9, {0.1628, 0.5305}},
{10, {0.1708, 0.484}},
{11, {0.1776, 0.379}},
{12, {0.1836, 0.4335}},
{13, {0.1856, 0.408}},
{14, {0.1936, 0.4495}},
{15, {0.2034, 0.5295}},
{16, {0.1974, 0.3595}},
{17, {0.2122, 0.4395}},
{18, {0.2152, 0.4465}},
{19, {0.2252, 0.3555}},
{20, {0.229, 0.4415}},
{21, {0.2716, 0.3535}},
{22, {0.2952, 0.313}},
{23, {0.3258, 0.4265}},
{24, {0.3446, 0.475}},
{25, {0.3476, 0.4315}},
{26, {0.3536, 0.408}},
{27, {0.3584, 0.3545}},
{28, {0.3694, 0.3665}},
{29, {0.3732, 0.384}},
{30, {0.393, 0.3535}},
{31, {0.395, 0.4205}},
{32, {0.4028, 0.3625}},
{33, {0.4028, 0.378}},
{34, {0.4088, 0.3525}},
{35, {0.4108, 0.4345}},
{36, {0.4286, 0.4505}},
{37, {0.4336, 0.405}},
{38, {0.4434, 0.247}},
{39, {0.4542, 0.303}},
{40, {0.4532, 0.4415}},
{41, {0.4612, 0.3515}},
{42, {0.469, 0.3455}},
{43, {0.47, 0.3685}},
{44, {0.477, 0.391}},
{45, {0.4888, 0.31}},
{46, {0.4948, 0.3315}},
{47, {0.4958, 0.371}},
{48, {0.4986, 0.217}},
{49, {0.4918, 0.4375}},
{50, {0.5214, 0.376}},
{51, {0.5244, 0.3455}},
{52, {0.5284, 0.4315}},
{53, {0.5294, 0.457}},
{54, {0.5302, 0.471}},
{55, {0.5302, 0.2875}},
{56, {0.554, 0.243}},
{57, {0.554, 0.323}},
{58, {0.554, 0.299}},
{59, {0.559, 0.231}},
{60, {0.559, 0.2575}},
{61, {0.559, 0.2725}},
{62, {0.5628, 0.244}},
{63, {0.5668, 0.221}},
{64, {0.5668, 0.316}},
{65, {0.5708, 0.1755}},
{66, {0.5816, 0.2665}},
{67, {0.5836, 0.224}},
{68, {0.5916, 0.152}},
{69, {0.5806, 0.307}},
{70, {0.5826, 0.3365}},
{71, {0.5876, 0.32}},
{72, {0.5974, 0.242}},
{73, {0.5984, 0.2845}},
{74, {0.6044, 0.2865}},
{75, {0.5856, 0.397}},
{76, {0.5906, 0.3605}},
{77, {0.5916, 0.388}},
{78, {0.6014, 0.3385}},
{79, {0.6054, 0.388}},
{80, {0.6132, 0.299}},
{81, {0.6132, 0.2865}},
{82, {0.6142, 0.2745}},
{83, {0.6182, 0.375}},
{84, {0.6252, 0.245}},
{85, {0.6252, 0.3355}},
{86, {0.629, 0.3605}},
{87, {0.63, 0.371}},
{88, {0.63, 0.388}},
{89, {0.633, 0.474}},
{90, {0.635, 0.3535}},
{91, {0.641, 0.3525}},
{92, {0.639, 0.411}},
{93, {0.6438, 0.3585}},
{94, {0.6458, 0.4355}},
{95, {0.6488, 0.473}},
{96, {0.6548, 0.2695}},
{97, {0.6576, 0.38}},
{98, {0.6646, 0.4455}},
{99, {0.6736, 0.3685}},
{100, {0.6764, 0.4415}},
{101, {0.6774, 0.396}},
{102, {0.6902, 0.402}},
{103, {0.6932, 0.373}},
{104, {0.6962, 0.473}},
{105, {0.6972, 0.453}},
{106, {0.718, 0.389}},
{107, {0.7268, 0.292}},
{108, {0.7228, 0.4335}},
{109, {0.7288, 0.457}},
{110, {0.7426, 0.296}},
{111, {0.7406, 0.4235}},
{112, {0.7644, 0.295}},
{113, {0.7624, 0.457}},
{114, {0.7802, 0.4225}},
{115, {0.7802, 0.2855}},
{116, {0.7822, 0.3355}},
{117, {0.797, 0.4315}},
{118, {0.799, 0.4495}},
{119, {0.8028, 0.4415}},
{120, {0.8168, 0.1235}},
{121, {0.8088, 0.459}},
{122, {0.8226, 0.1045}},
{123, {0.8186, 0.3465}},
{124, {0.8168, 0.468}},
{125, {0.8286, 0.244}},
{126, {0.8256, 0.2825}},
{127, {0.8266, 0.329}},
{128, {0.8226, 0.38}},
{129, {0.8196, 0.4345}},
{130, {0.8394, 0.167}},
{131, {0.8532, 0.291}},
{132, {0.8602, 0.1245}},
{133, {0.8652, 0.1085}},
{134, {0.8898, 0.166}},
{135, {0.8938, 0.133}},
{136, {0.9164, 0.221}},
{137, {0.9244, 0.153}},
{138, {0.9284, 0.1845}},
{139, {0.1076, 0.4125}},
{140, {0.1224, 0.3445}},
{141, {0.15, 0.4205}},
{142, {0.4028, 0.4215}},
{143, {0.4642, 0.33}},
{144, {0.467, 0.3395}},
{145, {0.5362, 0.242}},
{146, {0.548, 0.2525}},
{147, {0.5638, 0.131}},
{148, {0.6102, 0.1775}},
{149, {0.629, 0.3435}},
{150, {0.64, 0.456}},
{151, {0.6458, 0.317}},
{152, {0.6488, 0.3535}},
{153, {0.6508, 0.385}},
{154, {0.6538, 0.3365}},
{155, {0.6636, 0.328}},
{156, {0.6626, 0.161}},
{157, {0.6764, 0.3555}},
{158, {0.6854, 0.456}},
{159, {0.7002, 0.465}},
{160, {0.708, 0.387}},
{161, {0.715, 0.4345}},
{162, {0.716, 0.2635}},
{163, {0.7812, 0.1815}},
{164, {0.8958, 0.1925}}
})


So finally got it to work:

graphicslist =
Table[Rectangle[mpg[[i, 2]] , mpg[[i, 2]] + {.005, .005}], {i, 1, Length@mpg}];
Graphics[graphicslist]


And it returned:

Now I want a way to get the minimum spanning tree and from there get the adjacency matrix. Any Ideas?

• I haven't coded anything because I have this list, or matrix, or vertices positions and want to make a minimum spanning network from this. And from this minimum spanning network I would like to run calculations such as Monte Carlo simulations. Commented Jun 30, 2014 at 0:41
• So for example I don't know what a "minimum spanning network" is. (BTW I didn't downvote you -- not at all trying to be nasty.) This site has a lot of MMA expertise but people's backgrounds are quite different. The more you can tell us about your problem the more likely it is someone will be able to provide constructive input. Commented Jun 30, 2014 at 0:44
• Im trying to use Prim's algorithm if that helps. Commented Jun 30, 2014 at 1:07
• I didn't downvote you, but I can see why that happened. The question doesn't contain enough relevant information, but it does contain a lot of irrelevant information. If you're asking how to create a Graph object, then it is completely irrelevant that afterwards you want to do a Monte Carlo simulation, find a minimum spanning tree or use Prim's algorithm. At the same time you didn't explain clearly what kind of data you have (your input). Give a clear example input and example output. Commented Jun 30, 2014 at 1:10
• @David: Updated my answer with example using points from your update ... is that what you're after?
– ciao
Commented Jun 30, 2014 at 21:19

## 1 Answer

Using Daniel Lichtblau's prim algorithm code :

(* fake some points *)
n = 10;
pts = RandomReal[{0, 50}, {n, 2}];

tree = Prim[pts];

Graph[Range@n, UndirectedEdge @@@ tree[[2]], VertexCoordinates -> pts, VertexLabels -> "Name",
ImageSize -> 500]


Here's your points from your update (I left out labels - image needs to be large so they don't overlap, and wouldn't be appropriate to post):