-
Notifications
You must be signed in to change notification settings - Fork 11
/
reanalyse.py
56 lines (45 loc) · 1.7 KB
/
reanalyse.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
52
53
54
55
56
import glob
import os
import pandas as pd
from rivus.main import rivus
import sys
def reanalyse(directory):
"""Return constants for all pickled rivus results in directory
Args:
directory: a directory with 1 or multiple pickled rivus instances
Returns:
tuple (demand, cost, Pmax, Kappa_hub, Kappa_process) of concatenated
DataFrames
"""
glob_pattern = os.path.join(directory, '*.pgz')
pickle_filenames = glob.glob(glob_pattern)
demand = {}
cost = {}
Pmax = {}
Kappa_hub = {}
Kappa_process = {}
for pf in pickle_filenames:
# load original problem object including solution
prob = rivus.load(pf)
# truncate directory name and extension from pickle filename
# remove 'scenario_' prefix, if present
scenario_name = os.path.splitext(os.path.basename(pf))[0]
scenario_name = scenario_name.replace('scenario_', '')
# retrieve costs and capacities from result
constants = rivus.get_constants(prob)
# assign dict values per scenario
cost[scenario_name] = constants[0]
Pmax[scenario_name] = constants[1]
Kappa_hub[scenario_name] = constants[2]
Kappa_process[scenario_name] = constants[3]
demand[scenario_name] = prob.peak
# merge into single dataframe
demand = pd.concat(demand, axis=1)
cost = pd.concat(cost, axis=1)
Pmax = pd.concat(Pmax, axis=1)
Kappa_hub = pd.concat(Kappa_hub, axis=1)
Kappa_process = pd.concat(Kappa_process, axis=1)
return demand, cost, Pmax, Kappa_hub, Kappa_process
if __name__ == '__main__':
for directory in sys.argv[1:]:
demand, cost, Pmax, Kappa_hub, Kappa_process = reanalyse(directory)