-
Notifications
You must be signed in to change notification settings - Fork 2
/
machine.py
115 lines (69 loc) · 2.14 KB
/
machine.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import commentjson
import linprog as lp
import utils
class Machine:
def __init__ (
self,
pretty_name,
overclock_exponent,
somersloop_slots,
required_somersloops
):
self . pretty_name = pretty_name
self . overclock_exponent = overclock_exponent
self . somersloop_slots = somersloop_slots
self . required_somersloops = required_somersloops
def supports_overclocking (self):
return self . overclock_exponent != None
def supports_productivity (self):
return self . somersloop_slots != None
def requires_somersloops (self):
return self . required_somersloops != None
def add_constraints (self, constraints, using_recipes):
pass
def total_count (self, using_recipes):
return sum (
recipe . machine_count () for recipe in using_recipes
)
def interpret (self, model, precision, interpreted_using_recipes):
total_count = self . total_count (interpreted_using_recipes)
if total_count == 0:
return None
return utils . format_value (total_count, precision)
def load_machine (pretty_name, machine_data):
if 'overclock_exponent' in machine_data:
overclock_exponent = utils . real (machine_data ['overclock_exponent'])
else:
overclock_exponent = None
if 'somersloop_slots' in machine_data:
somersloop_slots = utils . real (machine_data ['somersloop_slots'])
else:
somersloop_slots = None
if 'required_somersloops' in machine_data:
required_somersloops = utils . real (
machine_data ['required_somersloops']
)
else:
required_somersloops = None
return Machine (
pretty_name,
overclock_exponent,
somersloop_slots,
required_somersloops
)
def load_machines (machines_file_name):
with open (machines_file_name, 'r') as machines_file:
machines_data = commentjson . load (machines_file)
machines = dict ()
for machine_pretty_name, machine_data in machines_data . items ():
machines [machine_pretty_name] = load_machine (
machine_pretty_name,
machine_data
)
return machines
def get_machine (machine_name, machines):
if machine_name not in machines:
raise ValueError (
'\'' + machine_name + '\' does not name a valid machine'
)
return machines [machine_name]