glpkmathprog

Multiplication of linear forms not allowed error


I am trying to solve a facility location problem. This is my code:

set S;
param prod{i in S};
param distri{i in S};
param fixed{i in S};
param cap{i in S};
param demand{i in S};

var x{i in S, j in S}, >= 0;
var y{i in S}, binary;

minimize obj :
  sum{i in S} fixed[i]*y[i] + 
  sum{i in S, j in S} x[i,j]*(prod[i] + distri[i])*y[i];


s.t. c1{i in S}:
    sum{j in S} x[i,j]*y[i] <= cap[i];
  

s.t. c2{i in S}:
    sum{j in S} x[j,i]*y[j] = demand[i];

display S;

solve;

printf '\n  Solution: \nMinimum Cost = %.2f\n', obj;

display x;
display y;

data;

set S := 0 1 2 3;

param prod :=
  0 20
  1 30
  2 40
  3 50;

param distri :=
  0 60
  1 70
  2 80
  3 90;

param fixed :=
  0 10
  1 15
  2 10
  3 15;

param cap :=
  0 100
  1 110
  2 120
  3 130;

param demand :=
  0 120
  1 60
  2 70
  3 100;

end;

When I run this .mod file, I get the following error:

example.mod:13: multiplication of linear forms not allowed
Context:  S } x [ i , j ] * ( prod [ i ] + distri [ i ] ) * y [ i ] ;
MathProg model processing error

Here x is the fractional demand provided by facility 'i' for client 'j'.

I removed y[i] from the line mentioned and the error was gone. But if I do that, I get the same multiplication error but this time in c1 constraint.

What is the correct approach? Thank you.


Solution

  • gplk is restricted to linear problems.

    It is allowed to multiply parameters and variables. But products of variables are non-linear. You either have to rewrite the model or use a non-linear solver.

    Linearization of products involving a binary variable is discussed in this related answer.