forked from johwiebe/stn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rolling.py
43 lines (38 loc) · 1.13 KB
/
rolling.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Solve STN model using rolling horizon."""
import sys
import yaml
import dill
from stn import stnModel, stnModelRobust # noqa
# Load config file
with open(sys.argv[1], "r") as f:
y = yaml.load(f)
# Time horizons
TIMEp = range(0, y["Tp"], y["dTp"])
# Solve for each alpha
for n, q in enumerate(y["alphas"]):
with open(y["stn"], "rb") as dill_file:
stn = dill.load(dill_file)
# Initialize model
if y["robust"]:
model = stnModelRobust(stn)
else:
model = stnModel(stn)
for i, t in enumerate(TIMEp):
for p in stn.products:
model.demand(p, t, y[p][i])
# Solve model
model.solve([y["Ts"], y["dTs"], y["Tp"], y["dTp"]],
solver="cplex",
objective="terminal",
periods=y["periods"]["rolling"],
prefix=y["prfx"],
rdir=y["rdir"],
save=True,
alpha=q,
trace=True,
solverparams=y["solverparams"],
tindexed=False)
# Evaluate
model.eval(periods=y["periods"]["eval"], TP=y["TP"])