Agents at certain distance from a path

108 views
Skip to first unread message

Chintan Pathak

unread,
Dec 21, 2018, 2:09:02 AM12/21/18
to GAMA
Dear all,

I am trying to find agents that are at a certain distance from a path between two points. I am trying to use at_distance, but the part about calling agent is not clear. The calling agent should be the 'path' from which I want the list of agents that are within a certain distance.

Attached is the gama model describing the problem and my attempt. Below is the code:

/***
* Name: agentsatdist
* Author: chintan
* Description:
* Tags: Tag1, Tag2, TagN
***/


model agentsatdist

/* Insert your model definition here */

global {
   
    graph the_graph
;
    file roads_shapefile
<- file("../includes/SpatialJoin/WA_roads.shp");
    file od_csvfile
<-  csv_file("../includes/zipcodes_OD_WA.csv", ",");
   
    file WA_EVSE_DCFC_Public_csv_file
<- csv_file("../includes/WA_EVSE_DCFCSC.csv", ",");
    path shortest_path
;

    geometry shape
<- envelope(roads_shapefile);
   
    list all_chargers of
: charging_station;

    list chargers_nearby of
:charging_station;
   
    matrix od_pairs
<- matrix(od_csvfile);
    matrix
EVSEData <- matrix(WA_EVSE_DCFC_Public_csv_file);
   
int od_count <- od_pairs.rows;
   
    point source
;
    point target
;
   
   
float lookup_distance <- 10 / 0.000621371;  // convert miles to m
   
    init
{    

        create road
from: roads_shapefile ;
       
        the_graph
<- as_edge_graph(road);
       
        loop j
from: 0 to: EVSEData.rows - 1 {
            create charging_station number
: 1
           
with: [shape ::to_GAMA_CRS({float(EVSEData[10,j]),float(EVSEData[9,j])}, "EPSG:4326"),
                station_id
:: int(EVSEData[11, j]),
                zip
:: int(EVSEData[2,j]),
                dcfc_plug_count
:: int(EVSEData[6, j]),
                ev_network
:: string(EVSEData[7, j]),
                ev_connector_types
:: string(EVSEData[12, j]),
                max_power
:: float(EVSEData[13, j]),
                ev_connector_code
:: int(EVSEData[14, j]),
                charging_cost
:: float(EVSEData[15, j])];
               
       
}
        all_chargers
<- (charging_station as list);  
       
       
         loop i
from: 150 to: 150  {
                 source
<- point(the_graph.vertices closest_to (point(to_GAMA_CRS({float(od_pairs[3,i]),float(od_pairs[2,i])}, "EPSG:4326"))));
                target
<- point(the_graph.vertices closest_to (point(to_GAMA_CRS({float(od_pairs[6,i]),float(od_pairs[5,i])}, "EPSG:4326"))));
                shortest_path
<- path_between (the_graph, source,target);
               
// write(shortest_path);
               
               
if (shortest_path.shape = nil) {
 
               
} else {
                     ask road
(shortest_path) {
                        chargers_nearby
<- (all_chargers at_distance lookup_distance) closest_to self ;
                        write
(chargers_nearby);
                   
}
                   
               
}
         
}
   
}
}

species road  
{
   
    geometry display_shape
<- line(shape.points, 2.0);
    aspect
default {
        draw shape color
: #black ;
   
}
}

species charging_station
{
   
int station_id; // station_id as in AFDC dataset
   
int dcfc_plug_count;  // Number of DCFC plugs at the location
   
string ev_network;  // Network company that the charging station belongs to, for ex: Blink, ChargePoint etc.
   
string ev_connector_types; // Type of connector - CHADEMO (1), COMBO (2), BOTH (3), TESLA (4)
   
float max_power;  // max charging power per charging station in kWhr
   
float charging_cost; // charging cost in $ per kWhr
   
int ev_connector_code; // Codes as indicated in connector_type parenthesis
    rgb cs_color
<- #red;
   
int zip;
   
float energy_consumed <- 0.0;
   
bool in_use <- false;
       
// aspect definitions
    aspect circle
{
        draw square
(1000) color: cs_color;
   
}
}
       

experiment goto_network type
: gui {

    output
{
        display objects_display type
: opengl {
            species road aspect
: default;
           
            graphics points_display
{
                draw circle
(1000) color: #red at: source;
                draw circle
(1000) color: #blue at: target;
               
                loop ii
from:0 to: length(all_chargers collect each.location) {
                    draw square
(1000) color: #magenta at: all_chargers[ii].location;
               
}
                loop jj
from:0 to: length(chargers_nearby collect each.location) {
                    draw square
(1000) color: #yellow at: chargers_nearby[jj].location;
               
}
               
           
}

         
}
   
}
}

An guidance in this regard would be helpful. I am trying to achieve something similar to ST_DWithin from PostGIS.

Thanks

Srirama Bhamidipati

unread,
Dec 21, 2018, 10:10:18 AM12/21/18
to GAMA
hi

Your question is more or less clear, but can you draw a picture perhaps for clarity?

Srirama

Chintan Pathak

unread,
Dec 21, 2018, 10:49:49 PM12/21/18
to GAMA
Dear Srirama,

Attaching a picture to demonstrate the concept. In the picture, the lines represent the network. The blue triangles are origin and destination. The squares represent the stations (agents of type charging_station in my code). And black filled squares are the stations that are "near" the path between origin A and destination B. Here, the distance is Euclidean distance between path and stations. Ideally, it should be the distance along the network between the path and stations (assume there are other paths in the network not shown in the image, that lead to the stations).

Thanks

network_stations_near_path.jpg

Patrick Taillandier

unread,
Jan 2, 2019, 4:49:52 AM1/2/19
to gama-p...@googlegroups.com
Hi,

You can compute a buffer around the shortest path geometry (by just using the "+" operator) and use the overlapping operator:   

chargers_nearby <- ((charging_station overlapping (shortest_path.shape + lookup_distance)) ;

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 https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Srirama Bhamidipati

unread,
Jan 2, 2019, 4:52:18 AM1/2/19
to gama-p...@googlegroups.com
Hi

This is a bit complex. First you should look at the topology context of each spatial operator, so for example, if you want distance along a network, you should give the operator an environment ..ie., inside { } , and this environment is under " using topology_type" , so in your case, you will be "using graph { ...... } " 

And you might have to do this for each segment of the path to achieve what you want. Let us know if that works

Srirama

Chintan Pathak

unread,
Jan 4, 2019, 2:23:09 AM1/4/19
to GAMA
Dear Patrick,

Thanks a lot. This worked perfectly and exactly what I was looking for.

Thanks

Chintan Pathak

unread,
Jan 4, 2019, 2:23:09 AM1/4/19
to GAMA
Dear Srirama,

Just using 'using topology' did not work. For example, I tried:

                using topology(the_graph) {
                    chargers_nearby
<- (charging_station overlapping (shortest_path.shape + lookup_distance));
                    write
(chargers_nearby);
                    write
(length(chargers_nearby));
               
}

and I get zero chargers. I think that 'overlapping' might not work with 'using'. One would need some way to measure the 'lookup_distance' along the network.

Thanks

Srirama Bhamidipati

unread,
Jan 4, 2019, 3:51:20 AM1/4/19
to GAMA
My reply was independent of Patricks reply, you mixed up both :) 
No problem, glad one solution worked for you.

Srirama
Reply all
Reply to author
Forward
0 new messages