Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using DataFrames
- using OrderedCollections
- using JuMP
- H = 8;
- d = 0;
- N = 4;
- #Sets
- # i 'tasks' /t1*t5/
- # j 'units' /j1*j5/
- # n 'events' /n0*n3/
- # s 'states' /s1*s4/
- i = ["t1","t2","t3","t4","t5"];
- j = ["j1","j2","j3","j4","j5"];
- n = [1:N]
- s = ["s1","s2","s3","s4"]
- #SubSets
- #Ij1(i) 'tasks which can be performed in unit 1' /task1/
- #Ij2(i) 'tasks which can be performed in unit 2' /task2/
- #Ij3(i) 'tasks which can be performed in unit 3' /task3/
- #Ij4(i) 'tasks which can be performed in unit 4' /task4/
- #Ij5(i) 'tasks which can be performed in unit 5' /task5/
- Ij1 = i[1];
- Ij2 = i[2];
- Ij3 = i[3];
- Ij4 = i[4];
- Ij5 = i[5];
- #Is1(i)'tasks which process state 1 and either produce or consume' /task1,task2/
- #Is2(i)'tasks which process state 2 and either produce or consume' /task1,task2,task3/
- #Is3(i)'tasks which process state 3 and either produce or consume' /task3,task4,task5/
- #Is4(i)'tasks which process state 4 and either produce or consume' /task4,task5/
- Is1 = i[1:2];
- Is2 = i[1:3];
- Is3 = i[3:5];
- Is4 = i[4:5];
- #Ips1(i) 'tasks which produce state 2' //
- #Ips2(i) 'tasks which produce state 2' /task1,task2/
- #Ips3(i) 'tasks which produce state 3' /task3/
- #Ips4(i) 'tasks which produce state 4' /task4,task5/
- Ips1 = [];
- Ips2 = i[1:2];
- Ips3 = i[3];
- Ips4 = i[4:5];
- #Ics1(i) 'tasks which consume state 1' /task1,task2/
- #Ics2(i) 'tasks which consume state 2' /task3/
- #Ics3(i) 'tasks which consume state 3' /task4,task5/
- #Ics4(i) 'tasks which consume state 4' //
- Ics1 = i[1:2];
- Ics2 = i[3];
- Ics3 = i[4:5];
- Ics4 = [];
- Sr =s[1]
- Sfis = s[2:3]
- Sp = s[4]
- #alias(i,ip)
- #alias(j,jp)
- #alias(n,np,npp)
- ip = i;
- jp = j;
- np = n;
- npp = n;
- #PARAMETERS
- #bmin = [0,0,0,0,0]
- bmin = OrderedDict(
- "t1" => 0,
- "t2" => 0,
- "t3" => 0,
- "t4" => 0,
- "t5" => 0
- )
- #bmax = [100,150,200,150,150]
- bmax = OrderedDict(
- "t1" => 100,
- "t2" => 150,
- "t3" => 200,
- "t4" => 150,
- "t5" => 150
- )
- #STin = [10000, 0, 0, 0]
- STin = OrderedDict(
- "s1" => 10000,
- "s2" => 0,
- "s3" => 0,
- "s4" => 0)
- #STmax = [+inf, 200, 250, +inf ]
- STmax = OrderedDict(
- "s1" => Inf,
- "s2" => 200,
- "s3" => 250,
- "s4" => 0
- )
- #alpha = [1.333, 1.333, 1.000, 0.667, 0.667]
- alpha = OrderedDict(
- "t1" => 1.333,
- "t2" => 1.333,
- "t3" => 1.000,
- "t4" => 0.667,
- "t5" => 0.667
- )
- #beta = [0.01333, 0.01333, 0.00500, 0.00445, 0.00445]
- beta = OrderedDict(
- "t1" => 0.01333,
- "t2" => 0.01333,
- "t3" => 0.00500,
- "t4" => 0.00445,
- "t5" => 0.00445
- )
- price = OrderedDict(
- "s1" => 0,
- "s2" => 0,
- "s3" => 0,
- "s4" => 5
- )
- demand = OrderedDict(
- "s1" => 0,
- "s2" => 0,
- "s3" => 0,
- "s4" => 0
- )
- #rho_table = wsv"""
- #i s1 s2 s3 s4
- #t1 -1 +1 0 0
- #t2 -1 +1 0 0
- #t3 0 -1 +1 0
- #t4 0 0 -1 +1
- #t5 0 0 -1 +1
- #"""
- rho_table = DataFrame([(i = "t1", s1 = -1, s2 = +1, s3 = 0, s4 = 0 ),
- (i = "t2", s1 = -1, s2 = +1, s3 = 0, s4 = 0 ),
- (i = "t3", s1 = 0, s2 = -1, s3 = +1, s4 = 0 ),
- (i = "t4", s1 = 0, s2 = 0, s3 = -1, s4 = +1 ),
- (i = "t5", s1 = 0, s2 = 0, s3 = -1, s4 = +1 )]);
- rho = OrderedDict( (r[:i],states) => r[Symbol(states)] for r in eachrow(rho_table), states in s);
- example2_netprofit = Model()
- @variables example2_netprofit begin
- w[i in i, n in n, np in np], Bin
- bs[i in i, n in n, np in np] >= 0
- ST0[s in s, n in n] >= 0
- ST[s in s, n in n] >= 0
- Ts[i in i, n in n] >= 0
- Tf[i in i,n in n] >= 0
- NetP
- MS
- end
- @constraints example2_netprofit begin
- tight1[j in j],
- 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
- tight2[j in j],
- 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
- tight3[j in j],
- 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
- tight4[j in j],
- 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
- tight5[j in j],
- 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
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement