1

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
4

1 に答える 1

1

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);
于 2015-01-19T15:02:10.330 に答える