This repository was archived by the owner on Feb 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
73 lines (46 loc) · 1.79 KB
/
utils.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
import pandas as pd
from os.path import abspath, join
def load_json(path):
return json.load(open(path, encoding='utf-8'))
def save_json(path, data):
with open(path, 'w', encoding='utf-8') as out:
json.dump(data, out, ensure_ascii=False, indent=4)
def load_solution(path):
# Loads a solution from a json file to 2 pandas DataFrames.
solution = load_json(path)
fleet = pd.DataFrame(solution['fleet'])
pricing_strategy = pd.DataFrame(solution['pricing_strategy'])
return fleet, pricing_strategy
def save_solution(fleet, pricing_strategy, path):
# Saves a solution into a json file.
fleet = fleet.to_dict('records')
pricing_strategy = pricing_strategy.to_dict('records')
solution = {'fleet': fleet,
'pricing_strategy': pricing_strategy}
return save_json(path, solution)
def load_problem_data(path=None):
if path is None:
path = './data/'
# LOAD DEMAND
p = abspath(join(path, 'demand.csv'))
demand = pd.read_csv(p)
# LOAD DATACENTERS DATA
p = abspath(join(path, 'datacenters.csv'))
datacenters = pd.read_csv(p)
# LOAD SERVERS DATA
p = abspath(join(path, 'servers.csv'))
servers = pd.read_csv(p)
# LOAD SELLING PRICES DATA
p = abspath(join(path, 'selling_prices.csv'))
selling_prices = pd.read_csv(p)
# LOAD ELASTICITY DATA
p = abspath(join(path, 'price_elasticity_of_demand.csv'))
elasticity = pd.read_csv(p)
return demand, datacenters, servers, selling_prices, elasticity
if __name__ == '__main__':
# Load solution
path = './data/solution_example.json'
fleet, pricing_strategy = load_solution(path)
print(fleet)
print(pricing_strategy)