-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.coffee
175 lines (158 loc) · 3.65 KB
/
demo.coffee
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env coffee
Products =
A:
'LT': 1
'ST': 0
'SS': 25
'LLC': 0
'LS': 1
'Comp':
'C': 2
'D': 1
'OH': 20
'AL': 0
'OO': [0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
'GR': [0, 80, 50, 100, 60, 100, 70, 100, 60, 100, 50, 100, 50]
'SR': [0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
'POR': [0, 35, 100, 60, 100, 70, 100, 60, 100, 50, 100, 50, 0]
B:
'LT': 1
'ST': 0
'SS': 20
'LLC': 0
'LS': 1
'Comp':
'C': 1
'E': 1
'OH': 40
'AL': 0
'OO': [0, 50, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
'GR': [0, 70, 100, 50, 90, 60, 110, 60, 100, 50, 100, 50, 100]
'SR': [0, 50, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
'POR': [0, 0, 50, 90, 60, 110, 60, 100, 50, 100, 50, 100, 0]
C:
'LT': 1
'ST': 0
'SS': 5
'LLC': 2
'LS': 500
'Comp':
'E': 1
'F': 1
'OH': 60
'AL': 0
'OO': [0, 200, 150, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
'SR': [0, 200, 150, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
D:
'LT': 1
'ST': 0
'SS': 5
'LLC': 1
'LS': 200
'Comp':
'C': 1
'E': 2
'OH': 60
'AL': 20
'OO': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
'SR': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
E:
'LT': 2
'ST': 0
'SS': 50
'LLC': 3
'LS': 3
'Comp': {}
'OH': 100
'AL': 0
'OO': [0, 1500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
'SR': [0, 1500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
F:
'LT': 2
'ST': 1
'SS': 100
'LLC': 3
'LS': 2
'Comp': {}
'OH': 100
'AL': 0
'OO': [0, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
'SR': [0, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
dump_array = (title, arr) ->
process.stdout.write "#{title}:\t"
arr.forEach (d) ->
process.stdout.write "#{d}\t"
process.stdout.write "\n"
pretty_print = (p) ->
dump_array "GR", p.GR
dump_array "SR", p.SR
dump_array "POH", p.POH
dump_array "PAB", p.PAB
dump_array "NR", p.NR
dump_array "PORcpt", p.PORcpt
dump_array "POR", p.POR
return true
get_product_by_llc = (productcs) ->
levels = []
for name, p of productcs
if levels[p.LLC] is undefined
levels[p.LLC] = []
levels[p.LLC].push name
return levels
expand_product = (parent, productcs) ->
for name, count of parent.Comp
t = productcs[name]
if not t.hasOwnProperty 'GR'
t.GR = [0]
if not parent.hasOwnProperty 'POR'
return
for i in [0...12]
if not t.GR.hasOwnProperty i
t.GR[i] = 0
t.GR[i] += parent.POR[i] * parent.Comp[name]
return
do_level_iteration = (productcs, func) ->
level = get_product_by_llc productcs
for l in [0...level.length]
level_products = level[l]
for p in level_products
obj = this
func.call obj, p, productcs
return
get_FOR_PORcpt = (NR, LS) ->
if NR % LS is 0
(NR / LS) * LS
else
(NR // LS + 1) * LS
do_mrp = (p, productcs) ->
p.PAB = [0]
p.POH = [0]
p.PORcpt = [0]
p.NR = [0]
if not p.hasOwnProperty 'POR'
p.POR = [0]
p.PAB[0] = p.OH + Math.max(p.SR[0], 0) - p.AL
for t in [1...12]
if t == 1
p.POH[t] = p.PAB[t - 1] + p.SR[t] - p.GR[t] - Math.max(p.GR[t - 1], 0)
else
p.POH[t] = p.PAB[t - 1] + p.SR[t] - p.GR[t]
if p.POH[t] < p.SS
p.NR[t] = p.SS - p.POH[t]
p.PORcpt[t] = get_FOR_PORcpt p.NR[t], p.LS
else
p.NR[t] = 0
p.PORcpt[t] = 0
p.PAB[t] = p.POH[t] + p.PORcpt[t]
p.POR[t - p.LT] = p.PORcpt[t];
for j in [0...12]
if not p.POR.hasOwnProperty j
p.POR[j] = 0
expand_product p, productcs
pretty_print p
console.log '\n'
return
do_level_iteration Products, (p, productcs) ->
parent = productcs[p]
do_mrp parent, productcs
return