Skip to content

Commit

Permalink
dynamic paths
Browse files Browse the repository at this point in the history
  • Loading branch information
laatabix committed Jun 2, 2020
1 parent 56ab941 commit d61e37b
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 62 deletions.
1 change: 1 addition & 0 deletions empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

10 changes: 10 additions & 0 deletions includes/cliff_coast/levers.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#
# The available levers for this case study : levers.conf
# The file is structured as ";" separated columns and contains :
# - lever : the name (code) of the lever
# - active : whether the lever is active (=1) or not (=0) for a distrit. The order is the same order of districts in MAP_DIST_SNAMES (study_area.conf)
# - type : whether the lever is of type Builder, soft defense, or strategic withdrawal
# - threshold : when corresponding actions cross this threshold, the lever is activated
# - cost : the impact cost (% of the action cost) of the lever. If it is positive, the action cost is increased, otherwise it will be decreased
# - delay : the impact delay (number of round) of the lever. If it is positive, the action cost is delayed, otherwise it will be accelerated
#
lever;active;type;threshold;cost;delay

[Builder]
Expand Down
10 changes: 5 additions & 5 deletions includes/config/littosim.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
# - cliff_coast
# Only one line should be activated. Comment (by #) the other lines
#STUDY_AREA_FILE;../includes/overflow_coast_v/study_area.conf
#STUDY_AREA_FILE;../includes/overflow_coast_h/study_area.conf
STUDY_AREA_FILE;../includes/estuary_coast/study_area.conf
STUDY_AREA_FILE;../includes/overflow_coast_h/study_area.conf
#STUDY_AREA_FILE;../includes/estuary_coast/study_area.conf
#STUDY_AREA_FILE;../includes/cliff_coast/study_area.conf

##########################################################################################
[Network]
#
# Parameters of network (ActiveMQ)
#
# SERVER_ADDRESS : the address of the machine where ActiveMQ is running
# The address of the machine where ActiveMQ is running
SERVER_ADDRESS;localhost

##########################################################################################
Expand All @@ -47,8 +47,8 @@ LANGUAGE_FILE;../includes/config/langs.conf
# IS_OSX : this param is set to true if the used machine is under MAC OSX. If it is under Windows, the parameter is set to false
IS_OSX;true
#
# The absolute path towards the LISFLOOD executable file. The path depends on the used OS
# The absolute path towards the directory of the LISFLOOD executable file. The path depends on the used OS and must ends with a "/"
# Only one line should be uncommented
LISFLOOD_PATH;/Applications/littosim/lisflood/
LISFLOOD_PATH;/Applications/littosim⁩/⁨lisflood/
#LISFLOOD_PATH;C:/littosim/lisflood/

10 changes: 10 additions & 0 deletions includes/estuary_coast/levers.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#
# The available levers for this case study : levers.conf
# The file is structured as ";" separated columns and contains :
# - lever : the name (code) of the lever
# - active : whether the lever is active (=1) or not (=0) for a distrit. The order is the same order of districts in MAP_DIST_SNAMES (study_area.conf)
# - type : whether the lever is of type Builder, soft defense, or strategic withdrawal
# - threshold : when corresponding actions cross this threshold, the lever is activated
# - cost : the impact cost (% of the action cost) of the lever. If it is positive, the action cost is increased, otherwise it will be decreased
# - delay : the impact delay (number of round) of the lever. If it is positive, the action cost is delayed, otherwise it will be accelerated
#
lever;active;type;threshold;cost;delay

[Builder]
Expand Down
10 changes: 10 additions & 0 deletions includes/overflow_coast_h/levers.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#
# The available levers for this case study : levers.conf
# The file is structured as ";" separated columns and contains :
# - lever : the name (code) of the lever
# - active : whether the lever is active (=1) or not (=0) for a distrit. The order is the same order of districts in MAP_DIST_SNAMES (study_area.conf)
# - type : whether the lever is of type Builder, soft defense, or strategic withdrawal
# - threshold : when corresponding actions cross this threshold, the lever is activated
# - cost : the impact cost (% of the action cost) of the lever. If it is positive, the action cost is increased, otherwise it will be decreased
# - delay : the impact delay (number of round) of the lever. If it is positive, the action cost is delayed, otherwise it will be accelerated
#
lever;active;type;threshold;cost;delay

[Builder]
Expand Down
10 changes: 10 additions & 0 deletions includes/overflow_coast_v/levers.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#
# The available levers for this case study : levers.conf
# The file is structured as ";" separated columns and contains :
# - lever : the name (code) of the lever
# - active : whether the lever is active (=1) or not (=0) for a distrit. The order is the same order of districts in MAP_DIST_SNAMES (study_area.conf)
# - type : whether the lever is of type Builder, soft defense, or strategic withdrawal
# - threshold : when corresponding actions cross this threshold, the lever is activated
# - cost : the impact cost (% of the action cost) of the lever. If it is positive, the action cost is increased, otherwise it will be decreased
# - delay : the impact delay (number of round) of the lever. If it is positive, the action cost is delayed, otherwise it will be accelerated
#
lever;active;type;threshold;cost;delay

[Builder]
Expand Down
127 changes: 73 additions & 54 deletions models/LittoSIM-GEN_Manager.gaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,35 @@
* The project aims at modeling effects of coastal flooding on urban areas and at enabling the transfer of scientific
* findings to risk managers, as well as awareness of those concerned by the risk of coastal flooding.
*
* LittoSIM_GEN_Manager : this module reprsents the game manager.
* LittoSIM_GEN_Manager : this model reprsents the game manager.
*/

model Manager

import "params_models/params_manager.gaml"

global {
// put to false to omit saving data on the Manager machine
bool save_data <- false;

// files sent to LISFLOOD
/*
* General parameters
*/
bool save_data <- false; // put to false to omit saving data on the Manager machine
string project_path; // the absolete path of the current project for further use in file paths
/*
* Files and paths of LISFLOOD
*/
string lisflood_start_file <- study_area_def["LISFLOOD_START"];
string lisflood_bci_file <- study_area_def["LISFLOOD_BCI"];
string lisflood_bdy_file ->{floodEventType = HIGH_FLOODING ? study_area_def ["LISFLOOD_BDY_HIGH"] // scenario1 : HIGH
:(floodEventType = LOW_FLOODING ? study_area_def ["LISFLOOD_BDY_LOW"] // scenario2 : LOW
:(floodEventType = MEDIUM_FLOODING ? study_area_def ["LISFLOOD_BDY_MEDIUM"] // scenario3 : MEDIUM
:get_message('MSG_FLOODING_TYPE_PROBLEM')))};
// paths to Lisflood
string lisfloodPath <- littosim_def["LISFLOOD_PATH"]; // absolute path to Lisflood ex: "C:/littosim/lisflood"
string results_lisflood_rep <- my_flooding_path + "results"; // Lisflood results folder
string lisflood_par_file -> {my_flooding_path + "inputs/" + application_name + "_par" + timestamp + ".par"}; // parameter file
string lisflood_DEM_file -> {my_flooding_path + "inputs/" + application_name + "_dem" + timestamp + ".asc"}; // DEM file
string lisflood_rugosity_file -> {my_flooding_path + "inputs/" + application_name + "_rug" + timestamp + ".asc"}; // rugosity file
string lisflood_bat_file <- "LittoSIM_GEN_Lisflood.bat"; // Lisflood executable

// variables for Lisflood calculs
string results_lisflood_rep <- my_flooding_path + "results"; // Lisflood results folder
string lisflood_par_file -> {my_flooding_path + "inputs/" + application_name + "_par" + timestamp + ".par"}; // parameter file
string lisflood_DEM_file -> {my_flooding_path + "inputs/" + application_name + "_dem" + timestamp + ".asc"}; // DEM file
string lisflood_rugosity_file -> {my_flooding_path + "inputs/" + application_name + "_rug" + timestamp + ".asc"}; // rugosity file
/*
* Additional variables for Lisflood calculations
*/
map<string,string> list_flooding_events; // list of submersions of a round
string floodEventType <- LOW_FLOODING;
int lisfloodReadingStep <- 9999; // to indicate to which step of Lisflood results, the current cycle corresponds
Expand All @@ -41,20 +43,43 @@ global {
string flood_results <- ""; // text of flood results per district // saved as a txt file
list<int> submersions; // list of events
int sub_event <- 0; // if it's a new flooding event or an existing one (to add it to populations/budgets graphs and to save or not ruptures file)

// parameters for saving submersion results
string output_data_rep <- "../includes/"+ application_name +"/manager_data-" + EXPERIMENT_START_TIME; // folder to save main model results
/*
* Parameters for saving simulation results
*/
string output_data_rep <- "../includes/"+ application_name +"/manager_data-" + EXPERIMENT_START_TIME; // folder to save main model results
string shapes_export_path <- output_data_rep + "/shapes/"; // shapefiles to save
string csvs_export_path <- output_data_rep + "/csvs/"; // shapefiles to save

// operation variables
geometry shape <- envelope(convex_hull_shape); // world geometry
/*
* Shape and simulation variables
*/
float EXPERIMENT_START_TIME <- machine_time; // machine time at simulation initialization
string stateSimPhase <- SIM_NOT_STARTED; // state variable of current simulation state
int messageID <- 0; // network communication
geometry shape <- envelope(convex_hull_shape); // world geometry
int population_still_to_dispatch <- 0; // remaining population to distribute to districts

geometry all_flood_risk_area; // geometry agrregating risked area polygons
geometry all_protected_area; // geometry agrregating protected area polygons
geometry all_coastal_border_area; // geometry aggregating coastal border areas
// budget tables to draw evolution graphs

bool show_max_water_height <- false; // defines if the water_height displayed on the map should be the max one or the current one
bool show_protected_areas <- false;
int show_river_flooded_area <- 0;
bool show_risked_areas <- false;
bool show_grid <- false;

int game_round <- 0;
bool game_paused <- false;
point play_b;
point pause_b;
list<District> districts_in_game;
bool display_ruptures <- false; // display or not ruptures
bool submersion_ok <- false; // the submersion is calculated successfully by Lisflood, and can be displayed
bool send_flood_results <- true; // send or not results to players
point button_size;
/*
* Budget lists to draw evolution graphs
*/
list<list<int>> districts_budgets <- [[],[],[],[]];
list<list<int>> districts_taxes <- [[],[],[],[]];
list<list<int>> districts_given_money <- [[0],[0],[0],[0]];
Expand All @@ -67,30 +92,14 @@ global {
list<list<int>> districts_soft_strategies <- [[0],[0],[0],[0]];
list<list<int>> districts_withdraw_strategies<- [[0],[0],[0],[0]];
list<list<int>> districts_other_strategies <- [[0],[0],[0],[0]];

// Actions costs by strategy
list<list<float>> districts_build_costs <- [[0],[0],[0],[0]];
list<list<float>> districts_soft_costs <- [[0],[0],[0],[0]];
list<list<float>> districts_withdraw_costs<- [[0],[0],[0],[0]];
list<list<float>> districts_other_costs <- [[0],[0],[0],[0]];

int population_still_to_dispatch <- 0; // remaining population to distribute to districts
// other variables
bool show_max_water_height <- false; // defines if the water_height displayed on the map should be the max one or the current one
bool show_protected_areas <- false;
int show_river_flooded_area <- 0;
bool show_risked_areas <- false;
bool show_grid <- false;
string stateSimPhase <- SIM_NOT_STARTED; // state variable of current simulation state
int game_round <- 0;
bool game_paused <- false;
point play_b;
point pause_b;
list<District> districts_in_game;
bool display_ruptures <- false; // display or not ruptures
bool submersion_ok <- false;
bool send_flood_results <- true;
point button_size;

/*
* Fonts
*/
font bold20 <- font('Helvetica Neue', 20, #bold);
font bold40 <- font('Helvetica Neue', 40, #bold);

Expand Down Expand Up @@ -263,17 +272,25 @@ global {

do init_buttons;
stateSimPhase <- SIM_NOT_STARTED;
do read_lisflood_files (true); // read sumbersion 0 files
do read_lisflood_files (true); // read sumbersion 0 files with ruptures
do add_element_in_list_flooding_events (INITIAL_SUBMERSION, results_lisflood_rep);
last_played_event <- 0;

/*
* Create Legens and network agents
*/
create Legend_Planning;
create Legend_Map;
create Legend_Flood_Map;
create Legend_Flood_Plan;
create Network_Game_Manager;
create Network_Listener_To_Leader;
create Network_Control_Manager;
/*
* Create a dummy file to get the project path
*/
save "" rewrite: true to: "../empty.txt";
project_path <- text_file("../empty.txt").path;
project_path <- copy_between(project_path, 0, length(project_path)-9);
}
//------------------------------ End of init -------------------------------//

Expand Down Expand Up @@ -464,7 +481,7 @@ global {
stateSimPhase <- SIM_EXEC_LISFLOOD;
write stateSimPhase;
do execute_lisflood;
do read_lisflood_files (false);
do read_lisflood_files (false); // read flood files but without reading ruptures file (ruptures are already known because it's a new submersion
lisfloodReadingStep <- 0;
last_played_event <- length(list_flooding_events.keys) - 1;
send_flood_results <- true;
Expand Down Expand Up @@ -534,15 +551,17 @@ global {
return;
}
do clear_map;
// if the requested event is the last one played (already in memory), ok, we just display it
// if not, we read flood files
/*
* if the requested event is the last one played (already in memory), ok, we just display it (without ruptures that were removed at "new round"
* if not, we read flood files
*/
if last_played_event != fe {
last_played_event <- fe;
results_lisflood_rep <- list_flooding_events at list_flooding_events.keys[fe];
ask Cell {
max_water_height <- 0.0; // reset of max_water_height
}
do read_lisflood_files (true);
do read_lisflood_files (true); // reading files of an previous submersions + ruptures
send_flood_results <- true;
}
lisfloodReadingStep <- 0;
Expand All @@ -565,18 +584,18 @@ global {
}

action save_lf_launch_files {
save ("DEMfile ../workspace/LittoSIM-GEN/" + lisflood_DEM_file +
save ("DEMfile " + project_path + lisflood_DEM_file +
"\nresroot res\ndirroot results\nsim_time " + LISFLOOD_SIM_TIME + "\ninitial_tstep " + LISFLOOD_INIT_TSTEP +
"\nmassint " + LISFLOOD_MASSINT + "\nsaveint " + LISFLOOD_SAVEINT + "\nmanningfile ../workspace/LittoSIM-GEN/"
+ lisflood_rugosity_file + "\nbcifile ../workspace/LittoSIM-GEN/" + my_flooding_path + lisflood_bci_file +
"\nbdyfile ../workspace/LittoSIM-GEN/" + my_flooding_path + lisflood_bdy_file + "\nstartfile ../workspace/LittoSIM-GEN/"
"\nmassint " + LISFLOOD_MASSINT + "\nsaveint " + LISFLOOD_SAVEINT + "\nmanningfile " + project_path
+ lisflood_rugosity_file + "\nbcifile " + project_path + my_flooding_path + lisflood_bci_file +
"\nbdyfile " + project_path + my_flooding_path + lisflood_bdy_file + "\nstartfile " + project_path
+ my_flooding_path + lisflood_start_file + "\nstartelev\nelevoff\nacceleration\nSGC_enable\n") rewrite: true to: "../"+lisflood_par_file type: "text";

if IS_OSX {
save ("cd " + lisfloodPath + ";\n./lisflood -dir " + "../workspace/LittoSIM-GEN/"+ results_lisflood_rep + " ../workspace/LittoSIM-GEN/"+ lisflood_par_file + ";\nexit") rewrite: true to: lisfloodPath+lisflood_bat_file type: "text";
save ("cd " + lisfloodPath + ";\n./lisflood -dir " + project_path + results_lisflood_rep + " " + project_path + lisflood_par_file + ";\nexit") rewrite: true to: lisfloodPath+lisflood_bat_file type: "text";
}
else {
save ("cd " + lisfloodPath + "\nlisflood.exe -dir " + "../workspace/LittoSIM-GEN/"+ results_lisflood_rep + " ../workspace/LittoSIM-GEN/"+ lisflood_par_file + "\nexit") rewrite: true to: lisfloodPath+lisflood_bat_file type: "text";
save ("cd " + lisfloodPath + "\nlisflood.exe -dir " + project_path + results_lisflood_rep + " " + project_path + lisflood_par_file + "\nexit") rewrite: true to: lisfloodPath+lisflood_bat_file type: "text";
}
}
// read dem and rugosity from files to the GAMA grid (Cell)
Expand Down Expand Up @@ -2901,8 +2920,8 @@ experiment LittoSIM_GEN_Manager type: gui schedules:[]{
species Land_Use aspect: base;
species Road aspect: base;
species River aspect: base;
species Coastal_Defense aspect: base;
species Polycell aspect: base;
species Coastal_Defense aspect: base;
species River_Flood_Cell aspect: base;
species River_Flood_Cell_1m aspect: base;
species Water_Gate aspect: base;
Expand Down
6 changes: 3 additions & 3 deletions models/generic.gaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ global {
map<string,map> levers <- store_csv_data_into_map_of_map("../includes/estuary_coast/levers.conf", ";");

init {

loop lev over: levers.keys {
/*loop lev over: levers.keys {
create Lever {
code <- lev;
name <- levers at lev at 'fr';
Expand All @@ -26,7 +26,7 @@ global {

ask Lever {
write ""+code+" : " + name + " : " + type + " : " + threshold + " : " + added_cost;
}
}*/

}

Expand Down
2 changes: 2 additions & 0 deletions models/params_models/params_manager.gaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ global{
/*
* LISFLOOD simulation parameters
*/
string lisfloodPath <- littosim_def["LISFLOOD_PATH"]; // absolute path to Lisflood ex: "C:/littosim/lisflood"
string lisflood_bat_file <- "LittoSIM_GEN_Lisflood.bat";// the Lisflood executable that will be run by DOS/SH
string my_flooding_path <- "includes/" + application_name + "/floodfiles/";
bool IS_OSX <- bool(littosim_def["IS_OSX"]); // wether the manager is running on MAC OSX or Windows
/*
Expand Down

0 comments on commit d61e37b

Please sign in to comment.