invalid subscript

15 views
Skip to first unread message

Esteban Cáceres

unread,
Nov 24, 2022, 12:12:16 PM11/24/22
to AMPL Modeling Language
I have this error 
Error at _cmdno 2 executing "solve" command
(file T1_a.run, line 9, offset 71):
error processing objective costo_total:
    invalid subscript S['A','A',1]

My model is:
# CONJUNTOS
set P;        # Tipos de petróleo
set I;        # Tipos de producto
set R;        # Refinerías
set J;        # Clientes

# PARÁMETROS
param cp {P}     >= 0;        # Costo de procesar p
param op {P}     >= 0;         # Disponibilidad de p
param qip {P,I}    >= 0;        # Proporciones de productos i para procesar p
param d {J,I}    >= 0;        # Demandas del producto i del cliente j
param u {R,I}    >= 0;        # Costo de adquirir i en r
param t {R,J}    >= 0;        # Costo de transporte desde r a j

# VARIABLES
var X {P}         >= 0;        # Barriles de p comprados
var A {I,R}        >= 0;        # Barriles de i adquiridos en r
var S {I,R,J}    >= 0;        # Barriles transportados de i desde r a j

# FUNCIÓN OBJETIVO
minimize costo_total:
    sum {p in P} cp[p]*X[p] +
    sum {r in R, i in I} u[r,i]*A[i,r] +
    sum {i in R, r in R, j in J} t[r,j]*S[i,r,j];
   
# RESTRICCIONES
subject to Disponible {p in P}:
    X[p] <= op[p];

subject to Oferta {i in I}:
    sum {p in P} qip[p,i]*X[p] + sum {r in R} A[i,r] =
    sum {j in J} d[j,i];
   
subject to Demanda {i in I, j in J}:
    sum {r in R} S[i,r,j] = d[i,i];

My data is:
# CONJUNTOS
set P := LIGERO PESADO;
set I := GASOLINA KEROSENE AVIACIÓN;
set J := 1 2 3;
set R := A B;

# PARÁMETROS
param u: GASOLINA KEROSENE AVIACIÓN :=
    A    60    50    55
    B    60    50    55;

param t:    1    2    3 :=
    A    1.60    1.40    1.50
    B    1.35    1.80    1.30;

param d:    GASOLINA KEROSENE AVIACIÓN :=
    1    200000    400000    0
    2    300000    200000    600000
    3    500000    100000    300000;

param qip: GASOLINA KEROSENE AVIACIÓN :=
    LIGERO    0.40    0.20    0.35
    PESADO    0.32    0.40    0.20;
   
param op :=
    LIGERO    2000000
    PESADO    1000000;

param cp :=
    LIGERO    38
    PESADO    30;

Help me please!

AMPL Google Group

unread,
Nov 25, 2022, 1:06:26 PM11/25/22
to AMPL Modeling Language
You have defined "var S {I,R,J} >= 0;" and AMPL is giving you this error message:

error processing objective costo_total:
invalid subscript S['A','A',1]

This means that your objective function costo_total makes a reference to a variable S['A','A',1] that does not exist -- because either 'A' is not in I, or 'A' is not in R, or 1 is not in J.

Probably the cause of this error is that you write "sum {i in R, r in R, j in J}" in the definition of your objective function, when you mean to write "sum {i in I, r in R, j in J}".


--
Robert Fourer
am...@googlegroups.com
{#HS:2077775872-112960#}
Reply all
Reply to author
Forward
0 new messages