Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
|
|
@ -0,0 +1,54 @@
|
|||
# VAM
|
||||
#
|
||||
# Nigel_Galloway
|
||||
# September 1st., 2013
|
||||
COSTS = {W: {A: 16, B: 16, C: 13, D: 22, E: 17},
|
||||
X: {A: 14, B: 14, C: 13, D: 19, E: 15},
|
||||
Y: {A: 19, B: 19, C: 20, D: 23, E: 50},
|
||||
Z: {A: 50, B: 12, C: 50, D: 15, E: 11}}
|
||||
demand = {A: 30, B: 20, C: 70, D: 30, E: 60}
|
||||
supply = {W: 50, X: 60, Y: 50, Z: 50}
|
||||
COLS = demand.keys
|
||||
res = {}; COSTS.each_key{|k| res[k] = Hash.new(0)}
|
||||
g = {}; supply.each_key{|x| g[x] = COSTS[x].keys.sort_by{|g| COSTS[x][g]}}
|
||||
demand.each_key{|x| g[x] = COSTS.keys.sort_by{|g| COSTS[g][x]}}
|
||||
|
||||
until g.empty?
|
||||
d = demand.collect{|x,y| [x, z = COSTS[g[x][0]][x], g[x][1] ? COSTS[g[x][1]][x] - z : z]}
|
||||
dmax = d.max_by{|n| n[2]}
|
||||
d = d.select{|x| x[2] == dmax[2]}.min_by{|n| n[1]}
|
||||
s = supply.collect{|x,y| [x, z = COSTS[x][g[x][0]], g[x][1] ? COSTS[x][g[x][1]] - z : z]}
|
||||
dmax = s.max_by{|n| n[2]}
|
||||
s = s.select{|x| x[2] == dmax[2]}.min_by{|n| n[1]}
|
||||
t,f = d[2]==s[2] ? [s[1], d[1]] : [d[2],s[2]]
|
||||
d,s = t > f ? [d[0],g[d[0]][0]] : [g[s[0]][0],s[0]]
|
||||
v = [supply[s], demand[d]].min
|
||||
res[s][d] += v
|
||||
demand[d] -= v
|
||||
if demand[d] == 0 then
|
||||
supply.reject{|k, n| n == 0}.each_key{|x| g[x].delete(d)}
|
||||
g.delete(d)
|
||||
demand.delete(d)
|
||||
end
|
||||
supply[s] -= v
|
||||
if supply[s] == 0 then
|
||||
demand.reject{|k, n| n == 0}.each_key{|x| g[x].delete(s)}
|
||||
g.delete(s)
|
||||
supply.delete(s)
|
||||
end
|
||||
end
|
||||
|
||||
COLS.each{|n| print "\t", n}
|
||||
puts
|
||||
cost = 0
|
||||
COSTS.each_key do |g|
|
||||
print g, "\t"
|
||||
COLS.each do |n|
|
||||
y = res[g][n]
|
||||
print y if y != 0
|
||||
cost += y * COSTS[g][n]
|
||||
print "\t"
|
||||
end
|
||||
puts
|
||||
end
|
||||
print "\n\nTotal Cost = ", cost
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
COSTS = {S1: {D1: 46, D2: 74, D3: 9, D4: 28, D5: 99},
|
||||
S2: {D1: 12, D2: 75, D3: 6, D4: 36, D5: 48},
|
||||
S3: {D1: 35, D2: 199, D3: 4, D4: 5, D5: 71},
|
||||
S4: {D1: 61, D2: 81, D3: 44, D4: 88, D5: 9},
|
||||
S5: {D1: 85, D2: 60, D3: 14, D4: 25, D5: 79}}
|
||||
demand = {D1: 278, D2: 60, D3: 461, D4: 116, D5: 1060}
|
||||
supply = {S1: 461, S2: 277, S3: 356, S4: 488, S5: 393}
|
||||
Loading…
Add table
Add a link
Reference in a new issue