ayePete
ayePete

Reputation: 431

No Primal Feasible Solution, GLPK

I can't figure out what's wrong with this model. I continually get a No primal feasible solution error. It appears the problem is with the Stope_i constraint. I'm thinking there's some misrepresentation of the constraint. Can anyone help?

#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;

Upvotes: 1

Views: 746

Answers (1)

mattmilten
mattmilten

Reputation: 6716

This is my python code for your model using PySCIPOpt:

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])

It returns an optimal solution:

SCIP Status        : problem is solved [optimal solution found]
Solving Time (sec) : 0.01
Solving Nodes      : 1
Primal Bound       : +1.40200000000000e+03 (2 solutions)
Dual Bound         : +1.40200000000000e+03
Gap                : 0.00 %
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -0.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -0.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -0.0]
[-0.0, -0.0, -0.0, -0.0, 1.0, -0.0, -0.0, -0.0]

Upvotes: 2

Related Questions