I want to define some parameters in ampl file, however the software indicates that the parameter is defined when I try to run it. How can I fix this problem?
set N := 1..6;
set N_row := 1..4;
var x{i in N} >= 0, <= 1 default 0;
param alpha{N_row};
param A{N_row,N};
param P{N_row,N};
param alpha := 1 1.0 2 1.2 3 3.0 4 3.2;
param A :=
[1,*] 1 10 2 3 3 17 4 3.5 5 1.7 6 8
[2,*] 1 0.05 2 10 3 17 4 0.1 5 8 6 14
[3,*] 1 3 2 3.5 3 1.7 4 10 5 17 6 8
[4,*] 1 17 2 8 3 0.05 4 10 5 0.1 6 14;
param P :=
[1,*] 1 0.1312 2 0.1696 3 0.5569 4 0.0124 5 0.8283 6 0.5886
[2,*] 1 0.2329 2 0.4135 3 0.8307 4 0.3736 5 0.1004 6 0.9991
[3,*] 1 0.2348 2 0.1451 3 0.3522 4 0.2883 5 0.3047 6 0.6650
[4,*] 1 0.4047 2 0.8828 3 0.8732 4 0.5743 5 0.1091 6 0.0381;
minimize Obj: sum {i in N_row} (alpha[i]*exp(-1*(sum{j in N} A[i,j]*(x[j]-P[i,j])**2)));
option solver scip;
solve;
display x;
display Obj;
display alpha;
display A;
display P;
It's generally good practice to keep model and data separate, but if you really want to do this, you can use the "data" statement to switch into data mode and then "model" to switch back. Like this:
set N := 1..6;
set N_row := 1..4;
var x{i in N} >= 0, <= 1 default 0;
param alpha{N_row};
param A{N_row,N};
param P{N_row,N};
data;
param alpha := 1 1.0 2 1.2 3 3.0 4 3.2;
param A :=
[1,*] 1 10 2 3 3 17 4 3.5 5 1.7 6 8
[2,*] 1 0.05 2 10 3 17 4 0.1 5 8 6 14
[3,*] 1 3 2 3.5 3 1.7 4 10 5 17 6 8
[4,*] 1 17 2 8 3 0.05 4 10 5 0.1 6 14;
param P :=
[1,*] 1 0.1312 2 0.1696 3 0.5569 4 0.0124 5 0.8283 6 0.5886
[2,*] 1 0.2329 2 0.4135 3 0.8307 4 0.3736 5 0.1004 6 0.9991
[3,*] 1 0.2348 2 0.1451 3 0.3522 4 0.2883 5 0.3047 6 0.6650
[4,*] 1 0.4047 2 0.8828 3 0.8732 4 0.5743 5 0.1091 6 0.0381;
model;
# etc.