Skip to content

Commit

Permalink
minor updates, added script for paper and configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Brendel committed May 18, 2021
1 parent b61af35 commit c1610c2
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 6 deletions.
72 changes: 72 additions & 0 deletions configs/easy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
####################
# initial settings #
####################
t_0: '10:30' # initial clock time
T: 2.0 # [h]
delta_t: 0.25 # [h]
c_init: 1.0 # initial soc of nodes
p_init: 0.0 # initial soc of producers
vehicle_init: 0.1 # initial soc of vehicles


##################
# Data locations #
##################
vehicle_dir: 'data/vehicles'
depot_dir: 'data/depots'
consumer_dir: 'data/paper/c_easy.csv'
producer_dir: 'data/paper/p_all.csv'
other_dir: 'data/others'


#####################
# Data restrictions #
#####################
v_max: 40
c_max: 1
p_max: 1
o_max: 0
d_max: 1
lat: [49.00, 49.90] # min and max vals
lon: [7.50, 7.90]


##################
# Model settings #
##################
objective: 0
constr_j: True # (1j) valid inequality
min_vehicles: True # toggle obj and constraints connected to z
limit_vehicles: True # (1l) limit charging vehicles at locations
visualize: False # visualize solution
constrain_vehicles: 12 # only allow leq this many vehicles being used

######################
# Heuristic settings #
######################
h_init_time_limit: 120
h_time_limit: 60
h_init: quick # [quick, greedy]


###################
# Gurobi settings #
###################
TimeLimit: 100000
threads: 1
# multiple threads for parallel work
# can be restricted in order to save RAM
method: -1
# method used to solve root relaxation (only root!)
# -1: default 1: dual-simplex 2: barrier
MIPFocus: 0
# 0: default, balance between both
# 1: focus on finding feasible solutions
# 2: more attention on proving optimality
# 3: if best bound is barely moving
MIPGap: 0.0001
# default: 0.0001
CutPasses: -1
# default: -1
write_lp: False
LogToConsole: True
72 changes: 72 additions & 0 deletions configs/extreme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
####################
# initial settings #
####################
t_0: '10:30' # initial clock time
T: 2.0 # [h]
delta_t: 0.25 # [h]
c_init: 1.0 # initial soc of nodes
p_init: 0.0 # initial soc of producers
vehicle_init: 0.1 # initial soc of vehicles


##################
# Data locations #
##################
vehicle_dir: 'data/vehicles'
depot_dir: 'data/depots'
consumer_dir: 'data/paper/c_extreme.csv'
producer_dir: 'data/paper/p_all.csv'
other_dir: 'data/others'


#####################
# Data restrictions #
#####################
v_max: 40
c_max: 1
p_max: 1
o_max: 0
d_max: 1
lat: [49.00, 49.90] # min and max vals
lon: [7.50, 7.90]


##################
# Model settings #
##################
objective: 0
constr_j: True # (1j) valid inequality
min_vehicles: True # toggle obj and constraints connected to z
limit_vehicles: True # (1l) limit charging vehicles at locations
visualize: False # visualize solution
constrain_vehicles: 12 # only allow leq this many vehicles being used

######################
# Heuristic settings #
######################
h_init_time_limit: 120
h_time_limit: 60
h_init: quick # [quick, greedy]


###################
# Gurobi settings #
###################
TimeLimit: 100000
threads: 1
# multiple threads for parallel work
# can be restricted in order to save RAM
method: -1
# method used to solve root relaxation (only root!)
# -1: default 1: dual-simplex 2: barrier
MIPFocus: 0
# 0: default, balance between both
# 1: focus on finding feasible solutions
# 2: more attention on proving optimality
# 3: if best bound is barely moving
MIPGap: 0.0001
# default: 0.0001
CutPasses: -1
# default: -1
write_lp: False
LogToConsole: True
72 changes: 72 additions & 0 deletions configs/moderate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
####################
# initial settings #
####################
t_0: '10:30' # initial clock time
T: 2.0 # [h]
delta_t: 0.25 # [h]
c_init: 1.0 # initial soc of nodes
p_init: 0.0 # initial soc of producers
vehicle_init: 0.1 # initial soc of vehicles


##################
# Data locations #
##################
vehicle_dir: 'data/vehicles'
depot_dir: 'data/depots'
consumer_dir: 'data/paper/c_moderate.csv'
producer_dir: 'data/paper/p_all.csv'
other_dir: 'data/others'


#####################
# Data restrictions #
#####################
v_max: 40
c_max: 1
p_max: 1
o_max: 0
d_max: 1
lat: [49.00, 49.90] # min and max vals
lon: [7.50, 7.90]


##################
# Model settings #
##################
objective: 0
constr_j: True # (1j) valid inequality
min_vehicles: True # toggle obj and constraints connected to z
limit_vehicles: True # (1l) limit charging vehicles at locations
visualize: False # visualize solution
constrain_vehicles: 12 # only allow leq this many vehicles being used

######################
# Heuristic settings #
######################
h_init_time_limit: 120
h_time_limit: 60
h_init: quick # [quick, greedy]


###################
# Gurobi settings #
###################
TimeLimit: 100000
threads: 1
# multiple threads for parallel work
# can be restricted in order to save RAM
method: -1
# method used to solve root relaxation (only root!)
# -1: default 1: dual-simplex 2: barrier
MIPFocus: 0
# 0: default, balance between both
# 1: focus on finding feasible solutions
# 2: more attention on proving optimality
# 3: if best bound is barely moving
MIPGap: 0.0001
# default: 0.0001
CutPasses: -1
# default: -1
write_lp: False
LogToConsole: True
2 changes: 1 addition & 1 deletion greedy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, config):
self.sk = my_sk(config)
self.logfile = os.path.join('output',
self.sk.time_str+'_hlog.txt')
log_str = 'Instance: {}'.format(self.sk.instance_name)
log_str = 'Instance: {}'.format(self.sk.instance_str)
log_str += '\nProblem parameters: \n{} vehicles'.format(
len(range(self.sk.vehicle_data.shape[0])))
log_str += '\n{} consumers\n{} producers'.format(
Expand Down
67 changes: 67 additions & 0 deletions paper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# execute python file

import os
import glob
import logging
from sys import platform
import yaml

from utils import *
from smart_krit import my_sk


# Read configs
if platform in ['linux','linux2']:
configs = glob.glob(os.path.join('configs', '*.YAML')) + glob.glob(os.path.join('configs', '*.yaml'))
elif platform == 'win32':
configs = glob.glob(os.path.join('configs', '*.YAML'))
else:
print('Unknown platform!')
exit()

# logging
# TODO:


for config in configs:
with open(config) as config_file:
yaml_dict = yaml.load(config_file,
Loader=yaml.FullLoader)
print(f'Config file: {config}')

for t in [2.0, 3.0, 4.0, 5.0, 10.0]:
# Part B: objective 0
yaml_dict['objective'] = 0
yaml_dict['T'] = t
best_limit = None
best_res = None
for v_limit in [40, 30, 20, 15, 10, 5, 4, 3, 2, 1]:
print(f'Limit: {v_limit}')
yaml_dict['constrain_vehicles'] = v_limit
sk = my_sk(yaml_dict)
sk.preprocess()
grb_mod = sk.solve()
sk.postprocess(grb_mod)

# Check feasibility
if grb_mod.status == 2:
best_limit = v_limit
best_res = sk.instance_str + '.txt'
print('Feasible')
else:
print('Infeasible')

print(f'Finished part B: Best Limit: {v_limit} in file {best_res}')
#exit()

# Part C: warm-start with remaining time
yaml_dict['constrain_vehicles'] = best_limit
yaml_dict['objective'] = 1
sk = my_sk(yaml_dict)
sk.preprocess()
w, s_n, s_v, f, z, e = read_results(os.path.join('output', best_res))
grb_mod = sk.solve(w_start=w, s_n_start=s_n, s_v_start=s_v,
f_start=f, z_start=z, e_start=e)
sk.postprocess(grb_mod)

exit()
17 changes: 12 additions & 5 deletions smart_krit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@

class my_sk():
def __init__(self, config):
'''
config: path to YAML or yaml_dict
'''
# create output folder and read config
if not os.path.exists('output'):
os.makedirs('output')
self.time_str = datetime.now().strftime("%m_%d-%H_%M_%S")
with open(config) as config_file:
yaml_dict = yaml.load(config_file,
Loader=yaml.FullLoader)
base_name = os.path.basename(config)
self.instance_name = os.path.splitext(base_name)[0]

if isinstance(config, str):
with open(config) as config_file:
yaml_dict = yaml.load(config_file,
Loader=yaml.FullLoader)
# base_name = os.path.basename(config)
# self.instance_name = os.path.splitext(base_name)[0]
elif isinstance(config, dict):
yaml_dict = config

# model settings
self.obj = yaml_dict['objective']
Expand Down

0 comments on commit c1610c2

Please sign in to comment.