Advertisement
Guest User

Julia Discourse (53970)

a guest
Jan 26th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 4.34 KB | None | 0 0
  1. using DataFrames
  2. using OrderedCollections
  3. using JuMP
  4.  
  5. H = 8;
  6. d = 0;
  7. N = 4;
  8.  
  9. #Sets
  10. #  i 'tasks' /t1*t5/
  11. #  j 'units' /j1*j5/
  12. #  n 'events' /n0*n3/
  13. #  s 'states' /s1*s4/
  14.  
  15. i = ["t1","t2","t3","t4","t5"];
  16. j = ["j1","j2","j3","j4","j5"];
  17. n = [1:N]
  18. s = ["s1","s2","s3","s4"]
  19.  
  20. #SubSets
  21.  
  22. #Ij1(i) 'tasks which can be performed in unit 1' /task1/
  23. #Ij2(i) 'tasks which can be performed in unit 2' /task2/
  24. #Ij3(i) 'tasks which can be performed in unit 3' /task3/
  25. #Ij4(i) 'tasks which can be performed in unit 4' /task4/
  26. #Ij5(i) 'tasks which can be performed in unit 5' /task5/
  27.  
  28. Ij1 = i[1];
  29. Ij2 = i[2];
  30. Ij3 = i[3];
  31. Ij4 = i[4];
  32. Ij5 = i[5];
  33.  
  34. #Is1(i)'tasks which process state 1 and either produce or consume' /task1,task2/
  35. #Is2(i)'tasks which process state 2 and either produce or consume' /task1,task2,task3/
  36. #Is3(i)'tasks which process state 3 and either produce or consume' /task3,task4,task5/
  37. #Is4(i)'tasks which process state 4 and either produce or consume' /task4,task5/
  38.  
  39. Is1 = i[1:2];
  40. Is2 = i[1:3];
  41. Is3 = i[3:5];
  42. Is4 = i[4:5];
  43.  
  44. #Ips1(i) 'tasks which produce state 2' //
  45. #Ips2(i) 'tasks which produce state 2' /task1,task2/
  46. #Ips3(i) 'tasks which produce state 3' /task3/
  47. #Ips4(i) 'tasks which produce state 4' /task4,task5/
  48.  
  49. Ips1 = [];
  50. Ips2 = i[1:2];
  51. Ips3 = i[3];
  52. Ips4 = i[4:5];
  53.  
  54. #Ics1(i) 'tasks which consume state 1' /task1,task2/
  55. #Ics2(i) 'tasks which consume state 2' /task3/
  56. #Ics3(i) 'tasks which consume state 3' /task4,task5/
  57. #Ics4(i) 'tasks which consume state 4' //
  58.  
  59. Ics1 = i[1:2];
  60. Ics2 = i[3];
  61. Ics3 = i[4:5];
  62. Ics4 = [];
  63.  
  64. Sr =s[1]
  65. Sfis = s[2:3]
  66. Sp = s[4]
  67.  
  68. #alias(i,ip)
  69. #alias(j,jp)
  70. #alias(n,np,npp)
  71.  
  72. ip = i;
  73. jp = j;
  74. np = n;
  75. npp = n;
  76.  
  77. #PARAMETERS
  78. #bmin = [0,0,0,0,0]
  79.  
  80. bmin = OrderedDict(
  81.    "t1" => 0,
  82.    "t2" => 0,
  83.    "t3" => 0,
  84.    "t4" => 0,
  85.    "t5" => 0
  86. )
  87.  
  88. #bmax = [100,150,200,150,150]
  89. bmax = OrderedDict(
  90.    "t1" => 100,
  91.    "t2" => 150,
  92.    "t3" => 200,
  93.    "t4" => 150,
  94.    "t5" => 150
  95. )
  96.  
  97. #STin = [10000, 0, 0, 0]
  98. STin = OrderedDict(
  99.      "s1" => 10000,
  100.      "s2" => 0,
  101.      "s3" => 0,
  102.      "s4" => 0)
  103.  
  104. #STmax = [+inf, 200, 250, +inf ]
  105. STmax = OrderedDict(
  106.      "s1" => Inf,
  107.      "s2" => 200,
  108.      "s3" => 250,
  109.      "s4" => 0
  110. )
  111.  
  112. #alpha = [1.333, 1.333, 1.000, 0.667, 0.667]
  113. alpha = OrderedDict(
  114. "t1" => 1.333,
  115. "t2" => 1.333,
  116. "t3" => 1.000,
  117. "t4" => 0.667,
  118. "t5" => 0.667
  119. )
  120.  
  121. #beta = [0.01333, 0.01333, 0.00500, 0.00445, 0.00445]
  122. beta = OrderedDict(
  123. "t1" => 0.01333,
  124. "t2" => 0.01333,
  125. "t3" => 0.00500,
  126. "t4" => 0.00445,
  127. "t5" => 0.00445
  128. )
  129.  
  130. price = OrderedDict(
  131. "s1" => 0,
  132. "s2" => 0,
  133. "s3" => 0,
  134. "s4" => 5
  135. )
  136.  
  137. demand = OrderedDict(
  138. "s1" => 0,
  139. "s2" => 0,
  140. "s3" => 0,
  141. "s4" => 0
  142. )
  143.  
  144. #rho_table = wsv"""
  145. #i        s1       s2     s3    s4
  146. #t1       -1       +1      0     0
  147. #t2       -1       +1      0     0
  148. #t3        0       -1     +1     0
  149. #t4        0        0     -1    +1
  150. #t5        0        0     -1    +1
  151. #"""
  152.  
  153. rho_table = DataFrame([(i = "t1", s1 = -1, s2 = +1, s3 = 0, s4 = 0 ),
  154.                    (i = "t2", s1 = -1, s2 = +1, s3 = 0, s4 = 0 ),
  155.                    (i = "t3", s1 = 0, s2 = -1, s3 = +1, s4 = 0 ),
  156.                    (i = "t4", s1 = 0, s2 = 0, s3 = -1, s4 = +1 ),
  157.                    (i = "t5", s1 = 0, s2 = 0, s3 = -1, s4 = +1 )]);
  158.  
  159. rho = OrderedDict( (r[:i],states) => r[Symbol(states)] for r in eachrow(rho_table), states in s);
  160.  
  161. example2_netprofit = Model()
  162.  
  163. @variables example2_netprofit begin
  164.     w[i in i, n in n, np in np], Bin
  165.     bs[i in i, n in n, np in np] >= 0
  166.     ST0[s in s, n in n] >= 0
  167.     ST[s in s, n in n] >= 0
  168.     Ts[i in i, n in n] >= 0
  169.     Tf[i in i,n in n] >= 0
  170.     NetP
  171.     MS
  172. end
  173.  
  174. @constraints example2_netprofit begin
  175.     tight1[j in j],
  176.       sum(sum( (alpha[i]*w[i,n,np] + beta[i]*bs[i,n,np] ) for n in 1:length(n) if n <= np <= n+d) for i in Ij1) <= H
  177.  
  178.     tight2[j in j],
  179.       sum(sum( (alpha[i]*w[i,n,np] + beta[i]*bs[i,n,np] ) for n in 1:length(n) if n <= np <= n+d) for i in Ij2) <= H
  180.  
  181.     tight3[j in j],
  182.       sum(sum( (alpha[i]*w[i,n,np] + beta[i]*bs[i,n,np] ) for n in 1:length(n) if n <= np <= n+d) for i in Ij3) <= H
  183.  
  184.     tight4[j in j],
  185.       sum(sum( (alpha[i]*w[i,n,np] + beta[i]*bs[i,n,np] ) for n in 1:length(n) if n <= np <= n+d) for i in Ij4) <= H
  186.  
  187.     tight5[j in j],
  188.       sum(sum( (alpha[i]*w[i,n,np] + beta[i]*bs[i,n,np] ) for n in 1:length(n) if n <= np <= n+d) for i in Ij5) <= H
  189.  
  190. end
  191.  
  192.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement