How to programmatically locate new agents within the boundary of an existing agent with 4 or 5 sided polygon geometry

126 views
Skip to first unread message

predic...@gmail.com

unread,
Nov 6, 2014, 1:39:23 AM11/6/14
to gama-p...@googlegroups.com
Hello

This is my first post so appreciate your understanding......

Some context to my question: 
1) I am proposing to have an Agent representing a building (with 4 or 5 point polygon geometry ) derived from a shapefile.
2) Various shop agents (geometry "squares" for simplicity) are located within this building.
3) Rather than using an externally defined shapefile to create the shop agents can I create/locate the shop agents programmatically
within the building agent geometry?

Detail:
I wish to create/locate a set of new agents within an existing Agent 4-5 sided polygon geometry at defined locations. Specifically the new agents (assumed to be represented by small squares ) need to be positioned (located):
(i) one set of agents (shops) at a defined distance "inside" but not "on" all polylines  that make up the polygon. The location of the shop agents is further defined by splitting the distance between polygon points into equal parts
(ii) another set of agents (shops) arranged in vertical rows across the centroid of the polygon.

My question: How can I do this programmatically without having to resort to a shapefile for each instance of a new polygon based building?

I have researched existing GAMA models but from what I have concluded they "randomly" locate new Agents within an existing Agent geometry. 
My first thought was to utilize the clockwise definition of the polygon points (minx,miny, minx, maxy, etc ....) [Presumably this is standard] but
I am not sure what operators to use next to divide the distance between polygon points into equal parts and offset inwards from the polyline.  

I am very much a novice at using GAMA's capabilities and I have limited programming experience but keen to learn! 
I would appreciate some guidance on a proposed algorithm  and/or reference to some example code that could assist me.  Can someone help?

Chris 

Patrick Taillandier

unread,
Nov 6, 2014, 5:16:42 AM11/6/14
to gama-p...@googlegroups.com
Hi,

I have some ideas but I am not sure to get exactly what you want. Can you provides us with a figure....;) .

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,
Nov 6, 2014, 7:39:03 AM11/6/14
to gama-p...@googlegroups.com
Yes, slightly unclear for me as well, especially - "vertical rows across centroid"

I guess figure will be like this ?

regards,
Srirama
shop_agents.JPG

predic...@gmail.com

unread,
Nov 7, 2014, 4:13:24 AM11/7/14
to gama-p...@googlegroups.com
Hello Patrick and Srirama

Thank you for your response. Apologies for the cryptic description. Srirama your visual interpretation of my words is very close.  I have edited your figure a little to show more detail. (Incidentally can you me tell what programme you used to create this image!?) 

I realise I have confused you both by using the term "row" when I should have simply used the term columns of shops in regard to the centroid area of the building geometry. Note that the building polygon shapes in reality don't conform to hexagonal shapes but have various internal angles. Some are simple narrow rectangles -  others complex polygons. Hence my interest in attempting  a generalised  "location algorithm approach" rather than using say a grid overlay - though of course very open to any suggestions....... 

FYI: I have gone through the process of obtaining or creating a CAD drawing in DXF, DWF format and converted them to "Shops" shape files but I have two reservations for this approach:
1)  it is labour intensive for any new building model
2) my lack of experience scaling the shops shapefile to fit the building shape file geometry.

I note the shop agents in the central part of the building are laid out in more of a "rectangular" pattern  so would the "location algorithm" need to be different here? or is it simpler to represent this area with another dedicated Agent geometry  called say "InnerShops " as an "overlay"  to distinguish the "outerShops" that are located adjacent the perimeter of the building geometry? 

Appreciate your help...

Regards

Chris
Shopsv2A.jpg

Patrick Taillandier

unread,
Nov 7, 2014, 4:50:37 AM11/7/14
to gama-p...@googlegroups.com
Hi,

If you do not need a "perfect" solution, here an example of what can be done.

Cheers,

Patrick

PS: I am bit disappointed by the results of the "points_on" operator (that I have implemented :p ). I should improve it one day.

--
shop_location.gaml
shoplocation_model_display_map_size_895x1001_cycle_0_time_1415353529231.png

Srirama Bhamidipati

unread,
Nov 7, 2014, 7:46:22 AM11/7/14
to
If you need a perfect (improved) solution, you can use law of proportions in a triangle to get accurate locations for the edge-shops ( i shall explain if need be) and hold on to Patrick's solution for central-area-shops. If Patrick's solution suffices, I rest my case :)


I used powerpoint for my drawing. :)

regards,
Srirama

predic...@gmail.com

unread,
Nov 8, 2014, 3:45:43 AM11/8/14
to gama-p...@googlegroups.com
Thanks Patrick! for taking the time to give the code example.  Accuracy is secondary at the moment so really appreciate having the capability.... Understanding the concepts is my focus at the moment.  To that end I wish to make sure I understand the algorithm behind your example code.. :-)
I summarise below:
 
For the "outer "shops
1) Create "virtual perimeter" polylines from polygon geometry - Using "shape - 3 "as offset
2)  Compile list of location points. Define a location point (x, y) for each shop agent. 
This is where I got lost. Can you explain how the X and Y parameters are derived? What is the significance of the divisor 7? I wish to have perimeter shops it equidistant to each other along the virtual perimeter - say 10 of them
3) Create shop agents from list  

For the inner shops
1) Create virtual perimeter polyline from a default rectangle geometry. No offset?
2) Compile list of location points. Again this is where I got lost. Can you explain how the x, y parameters are derived? I am assuming here that the shops agent are already equidistant from each other.
3) Create shop agents from list

Three further questions :-)
a) The common parameters for each building polygon are the dimensions  order (minX,minY, MinX, MaxY etc etc) and the centroid.Is it possible to derive the inner shop location points with reference to the centroid? My reasoning here is that I could create multiple inner shop "groups "with the same algorithm by simply changing the distance to and angle from the centroid? is this possible or is this getting too complicated?
b) I would like to have the shop number identified as a text box inside the shop geometry. I recall there has been a question/topic on this already in the group. I will look this up.  
c) Related to b) what is the naming numerical order convention for the shop Agents. i.e In my case where is shop agent 1 located on the building geometry? Will this consistently be at this location for every polygon shape?

FYI:  My ultimate goal for this model is to simulate shopper visits to shops within various buildings. Each shop within a building will be assigned an "attractiveness score" based on shop proximity, types of shops adjacent each side to the target shop, shoppers needs/preference, weather . The score will be scaled to give a probability that a shopper will visit the shop. I am proposing to use the Promethee function in GAMA to rate the shops.. :-)   

Thank for your help. ..

Regards
Chris

predic...@gmail.com

unread,
Nov 8, 2014, 4:00:01 AM11/8/14
to gama-p...@googlegroups.com
Thanks Srirama for your additional advice. I will keep it in mind. As I mentioned to Patrick concepts are more important than accuracy at the moment. I would like to prototype the simulation and move on from there. My immediate challenge is I don't have a strong programming background  (I am an old Systems Engineer by training ) so I suspect it will be a slow process but as I said I am willing to learn.

Noted about your use of PowerPoint . Certainly appreciated that you took your time to draw up a diagram.

Thanks again

Regards

Chris

Srirama Bhamidipati

unread,
Nov 8, 2014, 5:54:38 AM11/8/14
to gama-p...@googlegroups.com
Below is my understanding.


On Saturday, November 8, 2014 9:45:43 AM UTC+1, predic...@gmail.com wrote:
Thanks Patrick! for taking the time to give the code example.  Accuracy is secondary at the moment so really appreciate having the capability.... Understanding the concepts is my focus at the moment.  To that end I wish to make sure I understand the algorithm behind your example code.. :-)
I summarise below:
 
For the "outer "shops
1) Create "virtual perimeter" polylines from polygon geometry - Using "shape - 3 "as offset  // this is actually negative buffer of the whole shape, in your case, a building, so you get a polygon that is 3 meters into the shape.
2)  Compile list of location points. Define a location point (x, y) for each shop agent. // for the negative-buffered shape in step1, you will have a perimeter, and the points (shops) are placed equidistant at every 1/7th position of the whole perimeter. so 7 shops. No need to worry about coordinates.
This is where I got lost. Can you explain how the X and Y parameters are derived? What is the significance of the divisor 7? I wish to have perimeter shops it equidistant to each other along the virtual perimeter - say 10 of them  
3) Create shop agents from list  

For the inner shops
1) Create virtual perimeter polyline from a default rectangle geometry. No offset? // virtual shape (rectangle) not perimeter. of course the shape will then have a perimeter. Patrick defines a rectangle of width 10m and length 20m. And he generalised it for all possible shapes of building by taking a minimum of 10m or minimum of shape of the building if less than 10; same with length/ height. So the rectangle is now 10x20. Then with to_squares, he divides the 10x20 rectangle into squares of size 5. this will result in 10/5 = 2 columns, and 20/5 =4 rows. That is what you see with the 8 shops in the center. As Patrick is asking (ask building) each building, the inner rectangle will form at the core/ center/ centroid of the building in concern. Again skipping the explicit definition/need for coordinates. 
2) Compile list of location points. Again this is where I got lost. Can you explain how the x, y parameters are derived? I am assuming here that the shops agent are already equidistant from each other.
3) Create shop agents from list

Three further questions :-)
a) The common parameters for each building polygon are the dimensions  order (minX,minY, MinX, MaxY etc etc) and the centroid.Is it possible to derive the inner shop location points with reference to the centroid? My reasoning here is that I could create multiple inner shop "groups "with the same algorithm by simply changing the distance to and angle from the centroid? is this possible or is this getting too complicated?
b) I would like to have the shop number identified as a text box inside the shop geometry. I recall there has been a question/topic on this already in the group. I will look this up.  // you can use draw statement "inside aspect" along with name, size and color. So it will be something like draw name size: 20 color:#black
c) Related to b) what is the naming numerical order convention for the shop Agents. i.e In my case where is shop agent 1 located on the building geometry? Will this consistently be at this location for every polygon shape? // The naming depends on the sequence of shops in the list. As this list is based on the perimeter of the inner or negative buffered shape, it will basically depend on the location of the very first starting point of the very first segment of your polygon (building), meaning it will depending on the first drawn segment of the polygon. I am not very sure, but this should be the case. Otherwise, the coordinate space in GAMA starts from top left.

predic...@gmail.com

unread,
Nov 8, 2014, 4:05:26 PM11/8/14
to gama-p...@googlegroups.com
Thanks Srirama

Some brief followup comments below in green... regards Chris


On Saturday, November 8, 2014 11:54:38 PM UTC+13, Srirama Bhamidipati wrote:
Below is my understanding.

On Saturday, November 8, 2014 9:45:43 AM UTC+1, predic...@gmail.com wrote:
Thanks Patrick! for taking the time to give the code example.  Accuracy is secondary at the moment so really appreciate having the capability.... Understanding the concepts is my focus at the moment.  To that end I wish to make sure I understand the algorithm behind your example code.. :-)
I summarise below:
 
For the "outer "shops
1) Create "virtual perimeter" polylines from polygon geometry - Using "shape - 3 "as offset  // this is actually negative buffer of the whole shape, in your case, a building, so you get a polygon that is 3 meters into the shape.
2)  Compile list of location points. Define a location point (x, y) for each shop agent. // for the negative-buffered shape in step1, you will have a perimeter, and the points (shops) are placed equidistant at every 1/7th position of the whole perimeter. so 7 shops. No need to worry about coordinates. /// Hmm Will this approach work for non symmetrical polygons? My reasoning is the various polyline lengths that make up the building agent polygon are mathematically independent so the equidistant algorithm would need to treat each polyline separately.Hence the need to go down to the coordinate level.
This is where I got lost. Can you explain how the X and Y parameters are derived? What is the significance of the divisor 7? I wish to have perimeter shops it equidistant to each other along the virtual perimeter - say 10 of them  
3) Create shop agents from list  

For the inner shops
1) Create virtual perimeter polyline from a default rectangle geometry. No offset? // virtual shape (rectangle) not perimeter. of course the shape will then have a perimeter. Patrick defines a rectangle of width 10m and length 20m. And he generalised it for all possible shapes of building by taking a minimum of 10m or minimum of shape of the building if less than 10; same with length/ height. So the rectangle is now 10x20. Then with to_squares, he divides the 10x20 rectangle into squares of size 5. this will result in 10/5 = 2 columns, and 20/5 =4 rows. That is what you see with the 8 shops in the center. As Patrick is asking (ask building) each building, the inner rectangle will form at the core/ center/ centroid of the building in concern. Again skipping the explicit definition/need for coordinates. /// Ok. This explanation is helpful. I note your comment about the inner rectangle geometry forming at the centroid of the building polygon. Does this fact lead to answering my question a) below if I wished to create multiple rectangular geometries ("enclosing" the shop agents)? In this case the rectangular geometries could  be offset by various distances  and angles from the single centroid coordinates.

2) Compile list of location points. Again this is where I got lost. Can you explain how the x, y parameters are derived? I am assuming here that the shops agent are already equidistant from each other.
3) Create shop agents from list

Three further questions :-)
a) The common parameters for each building polygon are the dimensions  order (minX,minY, MinX, MaxY etc etc) and the centroid.Is it possible to derive the inner shop location points with reference to the centroid? My reasoning here is that I could create multiple inner shop "groups "with the same algorithm by simply changing the distance to and angle from the centroid? is this possible or is this getting too complicated?
b) I would like to have the shop number identified as a text box inside the shop geometry. I recall there has been a question/topic on this already in the group. I will look this up.  // you can use draw statement "inside aspect" along with name, size and color. So it will be something like draw name size: 20 color:#black /// Thanks!
c) Related to b) what is the naming numerical order convention for the shop Agents. i.e In my case where is shop agent 1 located on the building geometry? Will this consistently be at this location for every polygon shape? // The naming depends on the sequence of shops in the list. As this list is based on the perimeter of the inner or negative buffered shape, it will basically depend on the location of the very first starting point of the very first segment of your polygon (building), meaning it will depending on the first drawn segment of the polygon. I am not very sure, but this should be the case. Otherwise, the coordinate space in GAMA starts from top left. /// That was my conclusion too. I was looking more for assurance that there would be consistency across multiple building polygons. I note from Patricks' example using the "hover  mouse" display inspection that the numbering goes anticlockwise for the perimeter shop agents for one building then goes to the next building geometry to number the second set of  perimeter shop  agents then comes back to the first building geometry to number the "inner shops" of the first building geometry. My preference is to keep the shop agent numbering sequential within each building geometry. Whew that took more to explain than I expected....!

Srirama Bhamidipati

unread,
Nov 8, 2014, 11:31:10 PM11/8/14
to gama-p...@googlegroups.com
Hallo,

1. For what you call asymmetric polygons, is what I call increase in accuracy. Yes, what you ask can be done (for each side of the polygon) using a algorithm you triangulate (similar to a TIN surface) each side from the centroid, offset it, and then take help of law of proportions of a triangle, and then divide the resulting side equidistant to place the shops. Again no need of coordinates. Please refer, one and two

2. You can draw any shape anywhere and with reference to the centroid by using "at" and defining the shape. For example in your case, draw rectangle (10,20) at:building23.location //( = at centroid)

3. GAMA team can answer better on the numbering convention .
 
regards,
Srirama
Reply all
Reply to author
Forward
Message has been deleted
0 new messages