-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerator.py
72 lines (60 loc) · 1.66 KB
/
generator.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
from networkx.utils import py_random_state
@py_random_state("seed")
def generate(generating_function, seed=0):
"""
Convenience wrapper to generate multiple instances.
Parameters
----------
generating_function:
A function that accepts a seed and returns an instance.
seed: int, random state or None
seed for randomization.
Returns
-------
A pyscipopt model.
"""
while True:
yield generating_function(seed)
@py_random_state("seed")
def generate_n(generating_function, n, seed=0):
"""
Convenience wrapper to generate n instances.
Parameters
----------
generating_function:
A function that accepts a seed and returns an instance.
n: int
Number of instances to generate.
seed: int, random state or None
seed for randomization.
Returns
-------
Tuple (instance_number, instance)
"""
for i in range(n):
yield i, generating_function(seed)
@py_random_state("seed")
def common_substructure_generator(
instance_generation_function,
backbone,
expand_params_function,
seed=0,
):
"""
Generates instances that have common substructure
Parameters
----------
instance_generation_function:
base function that defines MIP
backbone:
instance parameters of the common substructure
expand_params_function:
function to expand instance params given a backbone and a seed
seed: int, random object or None
for randomization
Returns
-------
generator object
"""
while True:
yield instance_generation_function(*expand_params_function(backbone, seed=seed))