AMPL 参数语法

AMPL param syntax

我正在为 AMPL 语法苦苦挣扎(这是我的第一个项目)。 在我的模型中,我有:

set GRID; # a grid represented by a sequence of integer
param W; # width of the grid
param d{i in GRID, j in GRID}; # distance between point of the grid

在我的数据中我有:

set GRID = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16;
param W = 4;
param d{i in GRID, j in GRID} = sqrt( (abs(i-j) mod W)**2 + (abs(i-j) div W)**2 ); # I want to calculate the distance between each pair of points

但在最后一行我得到错误:

 (offset 7)
 expected ; ( [ : or symbol

AMPL数据格式不允许表达式,所以需要在模型本身指定d参数的初始化:

set GRID; # a grid represented by a sequence of integer
param W; # width of the grid
param d{i in GRID, j in GRID} = sqrt((abs(i-j) mod W)**2 + (abs(i-j) div W)**2);