When you define a param to equal an expression, as in
param X_S {0..a,VS} := L*Uniform01();
then the value of the param is determined by that expression in the rest of the model. Thus you cannot assign some other value to the param, and when you try to do that with "let X_S[1,i]:=avg_x[1,i];" you get an error message. If you want to set an initial value for a param that can be changed later, you can use "default" instead:
param X_S {0..a,VS} default L*Uniform01();
Or, just define "param X_S {0..a,VS};" in the model and initialize it later with a "let" statement.
Subject: Re: [AMPL 14065] error in 1 subscript
Thank for your answer. But I have problem yet!!
May you answer this question? Why I receive this error about code below?!
param avg_x {0..a, VS} default 0;
param X_S {0..a,VS }:=( L*Uniform01());
for {i in VS}{
repeat {
let distance [1,i,j]:=sqrt((X_S[1,i]-X_CH[j])^2+(Y_S[1,i]-Y_CH[j])^2);
let X_S[1,i]:=avg_x[1,i];
........}}
THE ERROR= Error at _cmdno 9 executing "let" command
(file Kmeans.mod, line 31, offset 843):
X_S has an = assignment in the model.