Advertisement
Guest User

Untitled

a guest
May 1st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.83 KB | None | 0 0
  1. using JuMP
  2. using MathProgBase
  3. using GLPKMathProgInterface
  4.  
  5. m = Model(solver = GLPKSolverMIP())
  6. @variable(m, 0 <= x[i=1:8] <= 9, Int)
  7. @variable(m, y[i=1:8,j=0:9], Bin)
  8.  
  9. @constraint(m, 1000*x[1] + 100x[2] + 10x[3] + 1x[4] + 1000x[5] + 100x[6] + 10x[7] + 1x[2] == 10000x[5] + 1000x[6] + 100x[7] + 10x[2] + 1x[8])
  10.  
  11. @constraint(m, [i=1:8], sum([j*y[i,j] for j=0:9]) == x[i])
  12. @constraint(m, [i=1:8], sum([y[i,j] for j=0:9]) == 1)
  13. @constraint(m, [j=0:9], sum([y[i,j] for i=1:8]) <= 1)
  14.  
  15. @constraint(m, x[1] >= 1)
  16. @constraint(m, x[5] >= 1)
  17.  
  18. print(m)
  19.  
  20. status = solve(m)
  21.  
  22. println("S = ", getvalue(x[1]))
  23. println("E = ", getvalue(x[2]))
  24. println("N = ", getvalue(x[3]))
  25. println("D = ", getvalue(x[4]))
  26.  
  27. println("M = ", getvalue(x[5]))
  28. println("O = ", getvalue(x[6]))
  29. println("R = ", getvalue(x[7]))
  30.  
  31. println("Y = ", getvalue(x[8]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement