how to access x,y of graph vertices

33 views
Skip to first unread message

Srirama Bhamidipati

unread,
Feb 6, 2014, 3:11:15 PM2/6/14
to gama-p...@googlegroups.com
Hi,

 is there no way to get directly to vertex[i].x or vertex[i].y  for vertices of a graph ? not as coordinates but as individual x or y

thanks

Srirama Bhamidipati

unread,
Feb 6, 2014, 5:07:19 PM2/6/14
to gama-p...@googlegroups.com
something similar is, i have

[{495.61904761660844,4989.714285714552,0.0,1.0},{895.6190476175398,4989.714285714552,0.0,1.0},{1295.6190476166084,4989.714285714552,0.0,3.0},{1695.6190476175398,4989.714285714552,0.0, 3.0},{2095.6190476166084,4989.714285714552,0.0,3.0}]

how do I access 4989.714285714552 which is 2nd element in first list, and how do I access for example 3.0 which is 4th element in the 3 list 


thanks

Patrick Taillandier

unread,
Feb 7, 2014, 3:38:56 AM2/7/14
to gama-p...@googlegroups.com
Hi,

First it depends what are the nature of your vertices (point, geometry, agent). If you use the as_edge_graph operator, your vertices are points.

So you can just write something like: 

the_graph <- as_edge_graph(road);
point my_node <- one_of (the_graph.vertices);
write "node x:" + my_node.x;

Cheers,

Patrick



2014-02-06 Srirama Bhamidipati <b.sr...@gmail.com>:

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/groups/opt_out.

Srirama Bhamidipati

unread,
Feb 7, 2014, 5:20:41 AM2/7/14
to gama-p...@googlegroups.com
Thank you Patrick

I used something similar (as below) and it works.  But I would like to extend my question into a more broader sense. I am always having problems accessing list of lists.  Lets take the example from above:

[{495.61904761660844,4989.714285714552,0.0,1.0},{895.6190476175398,4989.714285714552,0.0,1.0},{1295.6190476166084,4989.714285714552,0.0,3.0},{1695.6190476175398,4989.714285714552,0.0, 3.0},{2095.6190476166084,4989.714285714552,0.0,3.0}]

The above is a list of lists, the bigger list contains 5 items, and the inner list contains 4 items each. How do I access the yellow items? I all the time tend to use bigList [0,1] for the first yellow and bigList[2,3] for the second yellow and also sometimes use bigList [0][1] or bigList [2][3]  , which obviously is wrong in GAMA.

So what is the best way to access individual elements of List of Lists.

thanks



---

write the_graph.vertices;

loop v over: the_graph.vertices{

vv <- point(v);

vx<- point(v).x;

vy<- point(v).y;

vz<- point(v).z;

write string("x=") + string(vx) +string("  y=") + string(vy)+string("  z=") + string(vz);

write string(" \n---") + vv +string(" ---\n");

-----

Patrick Taillandier

unread,
Feb 7, 2014, 5:38:58 AM2/7/14
to gama-p...@googlegroups.com
Where did you get that: [{495.61904761660844,4989.714285714552,0.0,1.0},{895.6190476175398,4989.714285714552,0.0,1.0},{1295.6190476166084,4989.714285714552,0.0,3.0},{1695.6190476175398,4989.714285714552,0.0, 3.0},{2095.6190476166084,4989.714285714552,0.0,3.0}]

Because, in GAMA, a list is noted "[...]". the symbol "{...}" is used by points and can only have two or three values (x,y,z).

Thus, if you write:

list my_list <-  [[495.61904761660844,4989.714285714552,0.0,1.0],[895.6190476175398,4989.714285714552,0.0,1.0],[1295.6190476166084,4989.714285714552,0.0,3.0],[1695.6190476175398,4989.714285714552,0.0, 3.0],[2095.6190476166084,4989.714285714552,0.0,3.0]];

write "my_list[0][1]: " + my_list[0][1];

write "my_list[2][3]: " + my_list[2][3];


--

You will get: 

my_list[0][1]: 4989.714285714552

my_list[2][3]: 3.0



Cheers,


Patrick




2014-02-07 Srirama Bhamidipati <b.sr...@gmail.com>:

--

Srirama Bhamidipati

unread,
Feb 7, 2014, 6:29:23 AM2/7/14
to gama-p...@googlegroups.com
Sorry If I confused you, I just made the fourth element for the sake of this email discussion. But yes the { brings me to the question. 

My problem is to  access list of lists, especially when it is a list of agent, and then i want to their variables.

for example ( just random fake values for argument only)

-----------------------------------------------

species roads { variable1 <-speed;  variable2 <-lanes;  variable3 <-oneway_yes;} 

and when using some operators (outside the scope of the species) they return you a collection of agents. for example, if I have list<roads> overlapping_roads , this returns [(road1, road2, road3), (road2,road5)] 

Q1. So how do i access/select these elements in the inner list
Q2. and how can i access the variables variable1 for a particular selected road (as selected from Q1) ??

I am unable to access them properly :((

regards,

Patrick Taillandier

unread,
Feb 7, 2014, 9:50:33 AM2/7/14
to gama-p...@googlegroups.com
If you have a list like 

list roads <- [[road1, road2, road3], [road2,road5]];
road one_road <- roads[1][0];
float var1_of_one_road <- road(roads[1][0]).variable1;// or here, you can juste write one_road.variable1


2014-02-07 Srirama Bhamidipati <b.sr...@gmail.com>:

--

Srirama Bhamidipati

unread,
Dec 17, 2014, 9:04:14 AM12/17/14
to gama-p...@googlegroups.com
Hi,

I have a warning "point list assigned unknown type" , I know it is a warning, but I still have a question. I am experimenting on a very basic graph for shortest paths with the following 'part' code. The highlighted part gives me warning, but I wonder why? Vertices are points and I am putting them into a list of points. Why would gaml still say unknown-type for gr.vertices ? Are vertices not points?



global{
graph gr;
geometry gr_geometry;
list<point> gr_nodes;

init{
gr <- as_edge_graph([{1,2}::{40,5},{40,5}::{23,67},{23,67}::{45,78}, {45,78}::{1,2}]);
gr_nodes<-gr.vertices;
write 'first node' + gr_nodes[0].y;
write gr;
gr_geometry<-geometry(gr);
matrix<int> m <- all_pairs_shortest_path(gr);
write m;
}
}


Patrick Taillandier

unread,
Dec 17, 2014, 9:23:38 AM12/17/14
to gama-p...@googlegroups.com
Hi,

It is because the list of vertices is not typed as a vertice (node) can be everything in a graph (an agent, a geometry, a string....). 

For instance : 
graph gr_string <- graph([]);
gr_string <- gr_string add_edge("toto"::"titi");
gr_string <- gr_string add_edge("toto"::"tata");
gr_string <- gr_string add_edge("tata"::"lala");
write gr_string.vertices;

Cheers,

Patrick

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Srirama Bhamidipati

unread,
Dec 17, 2014, 9:56:35 AM12/17/14
to gama-p...@googlegroups.com
Clear. Thank you. Srirama
Reply all
Reply to author
Forward
0 new messages