AMPL参数语法

时间:2015-01-18 10:57:59

标签: 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

1 个答案:

答案 0 :(得分: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);
相关问题