This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
generated from ortec/euro-neurips-vrp-2022-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_dynamic_parameters.py
86 lines (59 loc) · 2.1 KB
/
make_dynamic_parameters.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
74
75
76
77
78
79
80
81
82
83
84
85
86
import argparse
from dataclasses import dataclass
from random import seed, uniform
import tomli_w
from scipy.stats import qmc
from strategies.config import Config
@dataclass
class Integer:
interval: tuple[int, int]
default: int
def ppf(self, q: float) -> int:
lo, hi = self.interval
return round(lo + q * (hi - lo))
@dataclass
class Float:
interval: tuple[float, float]
default: float
def ppf(self, q: float) -> float:
lo, hi = self.interval
return lo + q * (hi - lo)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--num_samples", type=int, default=100)
parser.add_argument("--seed", type=int, default=1)
parser.add_argument("--out_dir", default="data/tune")
return parser.parse_args()
def write(where: str, params, exp: int):
default = Config.from_file("configs/benchmark_dynamic.toml").dynamic()
default["strategy_params"].update(**params)
with open(where + f"/{exp}.toml", "wb") as fh:
tomli_w.dump(dict(dynamic=default), fh)
def main():
args = parse_args()
seed(args.seed)
space = dict(
simulate_tlim_factor=Float((0.5, 0.9), 0.7),
n_cycles=Integer((1, 3), 1),
n_simulations=Integer((25, 100), 50),
n_lookahead=Integer((1, 5), 1),
n_requests=Integer((50, 100), 100),
)
default = {name: val.default for name, val in space.items()}
default["postpone_thresholds"] = [0.65]
write(args.out_dir, default, 1)
sampler = qmc.LatinHypercube(d=len(space), centered=True, seed=args.seed)
samples = sampler.random(args.num_samples - 1)
for exp, sample in enumerate(samples, 2):
values = [param.ppf(val) for param, val in zip(space.values(), sample)]
scenario = {name: val for name, val in zip(space.keys(), values)}
thresholds = [
uniform(0.5, 0.8),
uniform(0.6, 0.9),
uniform(0.70, 0.95),
uniform(0.80, 0.95),
]
scenario["postpone_thresholds"] = thresholds
write(args.out_dir, scenario, exp)
if __name__ == "__main__":
main()