-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (41 loc) · 2.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -----------------------------------------------------------------------------
# Example of a main script to run the model, with the necessary instructions
#
# - Requires a GAMS license including the PATH MCP Solver (MCP Model), alternatively you
# can edit the MCP/model.gms file to use IPOPT or another solver non-linear solver.
# - Requires the GAMS Python API to be installed.
#
# Barbosa, J. (2024)
# mail@juliabarbosa.net
# ----------------------------------------------------------------------------
from src.utils import *
from src.gams_input import *
import shutil
if __name__ == "__main__":
# -- Parameters -- #
mapname = "input_template" # .xlsx file with the data of the model you want to run located at MAPS_DIR
scenario = "summer"
# ModelType.QP -> Social Welfare Maximization ; ModelType.MCP -> Cournot Competition Model
model_type = ModelType.QP
agent_multiplier = 1 # Agent multiplier for the MCP model
results_file = "results.gdx" # File to save the results of the model
# -- Start Simulations -- #
print(f'\n## -- Starting simulations for map {mapname} -- ## \n')
fname = os.path.join(MAPS_DIR, mapname+".xlsx")
# -- Create Results Dir at RUNS_DIR and copy the Input Map for later reference -- #
print(f'Creating Results Dir for: {fname} - scenario: {scenario}')
sim_id = scenario
results_dir = os.path.join(RUNS_DIR,mapname, sim_id)
os.makedirs(results_dir, exist_ok=True)
shutil.copy(fname, results_dir)
# -- Run the Model -- #
print(f'Running Model for {fname} - scenario: {scenario}')
t = time.time()
if model_type == ModelType.QP:
set_up_model(fname, ModelType.QP, am = agent_multiplier, scenario=scenario)
run_gams_model(get_qp_dir(), solutions_file = os.path.join("..", results_dir, results_file))
elif model_type == ModelType.MCP:
set_up_model(fname, ModelType.MCP, am = agent_multiplier, scenario=scenario)
run_gams_model(get_mcp_dir(), solutions_file = os.path.join("..", results_dir, results_file))
print(f" Time elapsed: {time.time() - t}")
print("## -- All Simulations Completed -- ##")