# [AMPL 24993] AMPL ERRORS

Hello I have a lot of problems with my AMPL code, but I would like you to help me or correct it, or advise me with that.

``````# Conjuntos
set T := 1..3;
set N := 1..24;
set L := 1..38;

# Parámetros
param d{N,T} >= 0;
param gmax {i in N} >= 0;
param gmin {i in N} >= 0;
param Gmax {i in N} >= 0;
param Gmin {i in N} >= 0;
param R{L} >= 0;
param X{L} >= 0;
param COg{N} >= 0;
param nmax{L,T} integer >= 0; # Definición de nmax

# Variables
var g{i in N, t in T} >= gmin[i], <= gmax[i];
var G{i in N, t in T} >= Gmin[i], <= Gmax[i];
var n{l in L, t in T} integer >= 0, <= nmax[l,t];
var f{i in N, j in N, t in T};

# Función Objetivo
minimize costo:
sum{t in T} (
sum{i in N} (Cg[i]*G[i,t] + COg[i]*G[i,t]) +
sum{l in L} c0[l]*n[l,t] +
sum{i in N} 100*g[i,t]
);

subject to balance{i in N, t in T}:
sum{j in N: (i,j) in L} f[i,j,t] - sum{k in N: (k,i) in L} f[k,i,t] + g[i,t] + G[i,t] = d[i,t];

subject to fmax{i in N, j in N, t in T}:
f[i,j,t] <= Fmax[i,t]*n0[i] + Fmax[i,t]*n[i,j,t];

# Datos

data;

param gmax :=
1 1.3796
2 1.3796
3 0
4 0
5 0
6 0
7 2.7231
8 0
9 0
10 0
11 0
12 0
13 4.6406
14 0
15 1.4069
16 1.4069
17 0
18 3.6307
19 0
20 0
21 3.6307
22 2.7228
23 5.9907
24 0;

param gmin :=
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0;

param Gmax :=
1 1
2 0
3 0
4 1
5 0.4
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0;

param Gmin :=
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0;

param Cg :=
1 200
2 0
3 0
4 200
5 100
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0;

param COg :=
1 100
2 0
3 0
4 200
5 100
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0;

param R :=
1 0.0026
2 0.0546
3 0.0218
4 0.0328
5 0.0497
6 0.0308
7 0.0023
8 0.0268
9 0.0228
10 0.0139
11 0.0023
12 0.0023
13 0.0061
14 0.0054
15 0.0022
16 0.0033
17 0.0018
18 0.0033
19 0.0030
20 0.0051
21 0.0063
22 0.0135
23 0.0111
24 0.0028
25 0.0063
26 0.0063
27 0.0067
28 0.0033
29 0.0030
30 0.0018
31 0.0087
32 0.0033
33 0.0033
34 0.0051
35 0.0051
36 0.0028
37 0.0028
38 0.0087;

param X :=
1 0.0139
2 0.2112
3 0.0845
4 0.1267
5 0.1920
6 0.1190
7 0.0839
8 0.1037
9 0.0883
10 0.0605
11 0.0839
12 0.0839
13 0.0476
14 0.0418
15 0.0173
16 0.0259
17 0.0144
18 0.0259
19 0.0231
20 0.0396
21 0.0490
22 0.1053
23 0.0865
24 0.0216
25 0.0490
26 0.0490
27 0.0519
28 0.0259
29 0.0231
30 0.0144
31 0.0678
32 0.0259
33 0.0259
34 0.0396
35 0.0396
36 0.0216
37 0.0216
38 0.0678;

# Resolver el modelo
option solver cplex;
solve;

display PG;
display DELTA;
display P;
display Total_Cost;``````

When I put these statements in a file named amplerrors.txt, and then read that file into AMPL, I see this error message:

``````ampl: include amplerrors.txt;

..\amplerrors.txt, line 27 (offset 578):
Cg is not defined
context:  sum{i in N}  >>> (Cg[i]*G <<< [i,t] + COg[i]*G[i,t]) +
``````

This error occurs because `Cg` is used in your objective function, but there is no definition of `Cg` in any param or var statement in your model. Usually the reason for this error is one of the following:

• You used a param or var but forgot to define it.
• There is a mistake in typing a param or var name, either in its definition or in the place where it is used.

Your question has been moved to our new user forum at discuss.ampl.com, and a response has been posted. To see the response, use this link:

To reply, click the red “Reply” button that follows the response. (Do not send an email reply to this message.)