没有原始可行的解决方案,GLPK

时间:2018-01-18 10:16:39

标签: optimization linear-programming glpk

我无法弄清楚这个模型有什么问题。我不断得到一个没有原始可行解决方案的错误。似乎问题出在Stope_i约束上。我在想这里有一些关于约束的歪曲。有人可以帮忙吗?

#parameters

param n := 13;
param m := 8;
param k := 2;
param l := 2;
param p:= k-1 ;
param q:= l-1;

#set of items

#set I;
#set J;

set I := {1 .. n} ;
set J := {1 .. m} ;
set P := {1 .. n-p};
set Q := {1 .. m-q};


#parameters


param V{I, J};



# Decision variables
var x{I, J} >= 0, <= 1;
#printf (V[3,1]);

#check:      sum {i in I, j in J} V[i, j] * x[i, j] = 12;
maximize z: sum {f in I, g in J} V[f, g] * x[f, g];

subject to StopeB{g in P, h in Q}:
        sum{i in g .. g+p, j in h..h+q} x[i,j] <= 1;

#subject to Stope_i{g in P, h in Q}:
#        x[g,h] - sum{j in h+1..h+q} x[g,j] = 1;

#subject to Stope_j{g in P, h in Q}:
#        x[g,h] - sum{i in g+1..g+p} x[i,h] = 1;

#subject to Stope_ij{g in P, h in Q}:
#        x[g,h] - sum{i in g+1..g+p, j in h+1..h+q} x[i,j] = 1;

#subject to Stope_im{g in P, h in Q}:
#        x[g,h] - sum{i in g+1..g+p, j in h+l..m-1} x[i,j] = 1;

data;

param V: 1 2 3 4 5 6 7 8 :=
1       -25  -9  14   21 50  13   78  37     
2        14  11  14  17  -43  -30  68  75    
3        2   7   18  -44  -63  4   4   72    
4        -8  4   18   -63  -36  60   41   80    
5       -8   6   18   -28  -27  22    52   55   
6        -8  8   18   -8  3  21  30   19 
7       -4   9   17   18  27  16  -45   -58    
8        26  16  7    21 -22  -30   -38   -53  
9        36  11  6   43   -4  -31  78   105   
10       8   -1   -51   -15   50  12   122    154  
11       4  7   -49  -38  30  15   61   71  
12       30  11  0   20   23  21   29   -43   
13       -2   -11  -59  -22   52   -9   -1   -20  ;

end;

1 个答案:

答案 0 :(得分:1)

这是我使用PySCIPOpt的模型的python代码:

select 
  * from (select substr(warpall.clntpm,1,2) as clntwf, 
substr(warpall.pal#pm,1,10) as pal#wf, commpm, substr(warpall.clsspm,1,2) as 
clsswf, warpall.clsqpm * 1 as clsqwf from warpall

where locnpm <> 'ASSEMBLED PALLET'
and commpm <> 'ASSEMBLED PALLET'
and clsqpm <> 0

union all

select substr(clntpq,1,2) as clntwf, substr(pal#Pq,1,10) as pal#wf, null 
commpm, substr(clsspq,1,2) as clsswf, clsqpq * 1 as clsqwf from warpalq
where clsqpq <> 0
) as t9
inner join 
  warcmdt as t3
on 
  t3.clntcd = t9.clntwf  and t3.commcd = t9.commpm

它返回一个最佳解决方案:

from pyscipopt import Model, quicksum

model = Model()

n = 13
m = 8
k = 2
l = 2
p = k-1
q = l-1

I = range(n)
J = range(m)
P = range(n-p)
Q = range(m-q)

x = {}
v = [[-25,-9,14,21,50,13,78,37],
     [14,11,14,17,-43,-30,68,75],
     [2,7,18,-44,-63,4,4,72],
     [-8,4,18,-63,-36,60,41,80],
     [-8,6,18,-28,-27,22,52,55],
     [-8,8,18,-8,3,21,30,19],
     [-4,9,17,18,27,16,-45,-58],
     [26,16,7,21,-22,-30,-38,-53],
     [36,11,6,43,-4,-31,78,105],
     [8,-1,-51,-15,50,12,122,154],
     [4,7,-49,-38,30,15,61,71],
     [30,11,0,20,23,21,29,-43],
     [-2,-11,-59,-22,52,-9,-1,-20]]

for i in I:
    for j in J:
        x[i,j] = model.addVar(vtype = 'BINARY', name = 'x_{}_{}'.format(i,j))

model.setObjective(quicksum([v[i][j] * x[i,j] for i in I for j in J]), sense = 'maximize')

for g in P:
    for h in Q:
        model.addCons(quicksum(x[i,j] for i in range(g,g+p) for j in range(h,h+q)) <= 1)

for g in P:
    for h in Q:
        model.addCons(x[g,h] - quicksum(x[g,j] for j in range(h+1,h+q)) == 1)

for g in P:
    for h in Q:
        model.addCons(x[g,h] - quicksum(x[i,h] for i in range(g+1,g+p)) == 1)

for g in P:
    for h in Q:
        model.addCons(x[g,h] - quicksum(x[i,j] for i in range(g+1,g+p)) == 1)

for g in P:
    for h in Q:
        model.addCons(x[g,h] - quicksum(x[i,j] for i in range(g+1,g+p) for j in range(h+1,m-1)) == 1)

model.optimize()

for i in I:
    print([model.getVal(x[i,j]) for j in J])