/***
* 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;
}
}
}
}
}