Синтаксис параметров AMPL

Я борюсь с синтаксисом 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

person Sirion    schedule 18.01.2015    source источник


Ответы (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);
person vitaut    schedule 19.01.2015