Search code examples
glpk

GLPK variable not defined


I have the following model.

param nbpdt;
set J;
set I;
param p{i in I, j in J};
var S, integer, >=0;
var O, integer, >=0;
var E, integer, >=0;
#objectif
minimize surface: sum{i in I} p[i,1]-(p[i,2] * S)-(p[i,3] * O)-(p[i,4] * E);

When i try to run it this error comes :

pv.mod:9: i not defined
Context:  ; minimize surface : sum { i in I } p [ i , 1 ] - ( p [ i ,

Anyone has an idea ?


Solution

  • The sum operator has the same operator precedence as the plus and the minus operator.

    So in your term

    sum{i in I} p[i,1] - (p[i,2] * S)
    

    sum is only applied to p[i,1] and not to the following term. Just add parentheses as needed, e.g.

    sum{i in I} ( p[i,1] - (p[i,2] * S) )