Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using JuMP
- using GLPKMathProgInterface
- m = Model(solver = GLPKSolverMIP())
- demand = [12,14,16,18,20,22,24,26,28,30]
- probs = [0.05,0.1,0.1,0.1,0.15,0.15,0.1,0.1,0.1,0.05]
- buy = 21
- @variable(m,x >= 0, Int)
- @variable(m,y[1:10] >= 0, Int)
- @variable(m,w[1:10] >= 0,Int)
- @objective(m, Max, sum(probs[i]*(50*w[i] - 10*y[i]) for i=1:10) )
- @constraint(m, loop[i=1:10] , w[i] <= x)
- @constraint(m, loop[i=1:10] , w[i] <= demand[i])
- @constraint(m, loop[i=1:10], y[i] == x - w[i])
- solution = solve(m)
- print(m)
- println("Objective value: ",getobjectivevalue(m))
- demand = [12,14,16,18,20,22,24,26,28,30]
- probs = [0.05,0.1,0.1,0.1,0.15,0.15,0.1,0.1,0.1,0.05]
- buy = 21
- total = sum(probs[i]*(50*min(demand[i],buy)-10*max(buy-demand[i],0)) for i=1:10)
- println(total)
- total2 = sum(probs[i]*50*demand[i] for i=1:10)
- println(total2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement