Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1.  
  2. using JuMP
  3. using GLPKMathProgInterface
  4. m = Model(solver = GLPKSolverMIP())
  5.  
  6. demand = [12,14,16,18,20,22,24,26,28,30]
  7. probs = [0.05,0.1,0.1,0.1,0.15,0.15,0.1,0.1,0.1,0.05]
  8. buy = 21
  9.  
  10. @variable(m,x >= 0, Int)
  11. @variable(m,y[1:10] >= 0, Int)
  12. @variable(m,w[1:10] >= 0,Int)
  13.  
  14. @objective(m, Max, sum(probs[i]*(50*w[i] - 10*y[i]) for i=1:10) )
  15.  
  16. @constraint(m, loop[i=1:10] , w[i] <= x)
  17. @constraint(m, loop[i=1:10] , w[i] <= demand[i])
  18.  
  19. @constraint(m, loop[i=1:10], y[i] == x - w[i])
  20.  
  21. solution = solve(m)
  22. print(m)
  23. println("Objective value: ",getobjectivevalue(m))
  24.  
  25.  
  26. demand = [12,14,16,18,20,22,24,26,28,30]
  27. probs = [0.05,0.1,0.1,0.1,0.15,0.15,0.1,0.1,0.1,0.05]
  28. buy = 21
  29.  
  30. total = sum(probs[i]*(50*min(demand[i],buy)-10*max(buy-demand[i],0)) for i=1:10)
  31. println(total)
  32.  
  33. total2 = sum(probs[i]*50*demand[i] for i=1:10)
  34.  
  35. println(total2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement