Skip to content

Commit

Permalink
simplify the example
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhanwei-Liu committed Jun 29, 2024
1 parent 5f9ff48 commit a2e274f
Show file tree
Hide file tree
Showing 22 changed files with 16 additions and 21 deletions.
10 changes: 5 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"general_parameters": {
"input_folder": "southeast_asia",
"input_folder": "singapore",
"output_folder": "output",
"output_filename": "year",
"hour": 2190,
"hour": 8760,
"month": 1,
"dt": 1,
"hours_in_year": 8760,
"price": 0.01,

"isinflow": true,
"isinflow": false,
"error_threshold": 0.001,
"iteration_number": 1,
"fixed_head": true
},
"solver_parameters": {
"solver": "gurobi",
"TimeLimit": 0
"solver": "highs",
"solver_path": "/Users/energy/miniconda3/envs/prep-shot/lib/python3.9/site-packages/highsbox/highs_dist/lib/libhighs.1.7.dylib"
},
"data_parameters":{
"historical_capacity": {
Expand Down
14 changes: 7 additions & 7 deletions prepshot/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ def timer(func):
def wrapper(*args, **kwargs):
# logging.info("Start solving model ...")
start_time = time.time()
tracemalloc.start()
# tracemalloc.start()
result = func(*args, **kwargs)
_, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
# _, peak = tracemalloc.get_traced_memory()
# tracemalloc.stop()
run_time = time.time() - start_time
logging.info(
"Finished %s in %.2f seds", repr(func.__name__),
run_time
)
logging.info(
"Memory used %s in %.2f MB", repr(func.__name__),
peak / 10**6
)
# logging.info(
# "Memory used %s in %.2f MB", repr(func.__name__),
# peak / 10**6
# )
return result
return wrapper
10 changes: 3 additions & 7 deletions prepshot/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,9 @@ def create_model(para):
define_complex_sets(model, para)
define_variables(model, para)
# Define objective function for the model.
obj = poi.ExprBuilder()
obj += model.cost
model.set_objective(obj, sense=poi.ObjectiveSense.Minimize)
model.obj = poi.ExprBuilder(model.cost)
model.set_objective(model.obj, sense=poi.ObjectiveSense.Minimize)
define_constraints(model, para)
# [debug]
# set solving time
# model.set_raw_parameter("TimeLimit", 0)
model.optimize()
# model.write('prep-shot.lp')

return model
1 change: 0 additions & 1 deletion prepshot/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ def trans_capacity_rule(self, y, z, z1):
lhs -= model.cap_lines_existing[y, z, z1]
return model.add_linear_constraint(lhs, poi.Eq, 0)


def trans_balance_rule(self, h, m, y, z, z1):
"""Transmission balance, i.e., the electricity imported from zone z1
to zone z should be equal to the electricity exported from zone z
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def run_model(parameters, output_filename, args):
Arguments parsed by argparse.
"""
model = create_model(parameters)
exit() # debug to speed up create_model
output_filename = update_output_filename(output_filename, args)
solved = solve_model(model, parameters)
exit()
if solved:
ds = extract_result(model, isinflow=parameters['isinflow'])
ds.to_netcdf(f'{output_filename}.nc')
Expand Down
Binary file modified southeast_asia/capacity_factor.xlsx
Binary file not shown.
Binary file modified southeast_asia/carbon_emission_limit.xlsx
Binary file not shown.
Binary file modified southeast_asia/charge_efficiency.xlsx
Binary file not shown.
Binary file modified southeast_asia/demand.xlsx
Binary file not shown.
Binary file modified southeast_asia/discharge_efficiency.xlsx
Binary file not shown.
Binary file modified southeast_asia/discount_factor.xlsx
Binary file not shown.
Binary file modified southeast_asia/emission_factor.xlsx
Binary file not shown.
Binary file modified southeast_asia/fuel_price.xlsx
Binary file not shown.
Binary file modified southeast_asia/inflow.xlsx
Binary file not shown.
Binary file modified southeast_asia/lifetime.xlsx
Binary file not shown.
Binary file modified southeast_asia/predefined_hydropower.xlsx
Binary file not shown.
Binary file modified southeast_asia/reservoir_storage_lower_bound.xlsx
Binary file not shown.
Binary file modified southeast_asia/reservoir_storage_upper_bound.xlsx
Binary file not shown.
Binary file modified southeast_asia/technology_fixed_OM_cost.xlsx
Binary file not shown.
Binary file modified southeast_asia/technology_investment_cost.xlsx
Binary file not shown.
Binary file modified southeast_asia/technology_variable_OM_cost.xlsx
Binary file not shown.
Binary file added southeast_asia/~$predefined_hydropower.xlsx
Binary file not shown.

0 comments on commit a2e274f

Please sign in to comment.