我正在编写我的第一个GNU MathProg(AMPL)程序,以查找给定基数、主机数量和平分带宽的HyperX拓扑(图)的最小开关(顶点)计数实例。这是一个简单的第一个程序,因为所有方程都已在以下论文中描述:http://cal.snu.ac.kr/files/2009.sc.hyperx.pdf
我已经阅读了规范和示例程序,但我遇到了一个非常简单的语法错误。我需要有以下两个变量:L,网络中维度的数量,和长度为L的数组S,其中S的每个元素都是每个维度中交换机的数量。在我的MathProg程序中,我将其表示为:
var L >= 1, integer;
var S{1 .. L} >= 2, integer;
然而,当我运行$ glpsol --check --math hyperx.mod
时,我会得到以下错误:
hyperx.mod:28: operand following .. has invalid type
Context: ...isec ; param radix ; var L >= 1 , integer ; var S { 1 .. L }
如果有人能帮我解释一下我应该如何恰当地表达这种关系,我将不胜感激。此外,我还包括了我写的整个程序,以供参考和额外帮助。我预计我的程序中会有很多语法错误,但在修复第一个之前,我无法找到其余的
/*
* A MathProg linear program to find an optimal HyperX topology of a
* given network size, switch radix, and bisection bandwidth. Optimal
* is simplistically defined as minimum switch count network.
*
* A HyperX topology is a multi-dimensional network (graph) where, in
* each dimension, the switches are fully connected. Every switch
* (vertex) is a point in an L-dimensional integer lattic. Each switch
* is identified by a multi-index I = (I_1, ..., I_L) where 0 <= I_k <
* S_k for each k = 1..L, where S_k is the number of switches in each
* dimension. A switch connects to all others whose multi-index is the
* same in all but one coordinate.
*/
/* Network size in number of hosts. */
param hosts;
/* Desired bisection bandwidth. */
param bisec;
/* Maximum switch radix. */
param radix;
/* The number of dimensions in the HyperX. */
var L >= 1, integer;
/* The number of switches in each dimension. */
var S{1 .. L} >= 2, integer;
/*
* Relative bandwidth of the dimension, i.e., the number of links in a
* given dimension.
*/
var K{1 .. L} >= 1, integer;
/* The number Terminals (hosts) per switch */
var T >= 1, integer;
/* Minimize the total number of switches. */
minimize cost: prod{i in 1..L} S[i];
/* The total number of links must be less than the switch radix. */
s.t. Radix: T + sum{i in 1..L} K[i] * (S[i] - 1) <= radix;
/* There must be enough hosts in the network. */
s.t. Hosts: T * prod{i in 1..L} S[i] >= hosts;
/* There must be enough bandwidth. */
s.t. Bandwidth: min{K[i]*S[i]} / (2 * T) >= bisec;
/* The order of the dimensions doesn't matter, so constrain them */
s.t. SwitchDimen: forall{i in 1..(L-1)} S[i] <= S[i+1];
/*
* Bisection bandwidth depends on the smallest S_i * K_i, so we know
* that the smallest switch count dimension needs the most links.
*/
s.t. LinkDimen: forall{i in 1..(L-1)} K[i] >= K[i+1];
# TODO: I would like to constrain the search such that the number of
# terminals, T, is bounded to T >= (hosts / O), where O is the switch
# count of the smallest switch count topology discovered so far, but I
# don't know how to do this.
/* Data section */
data;
param hosts := 32
param bisec := 0.5
param radix := 64
end;
在求解器和代数建模语言(包括AMPL/MathProg)中,问题中变量的固定数量是一种常见的假设。因此,在索引表达式中只能使用常量表达式,尤其是参数,而不能使用变量。一种可能的解决方案是将L
设为参数,针对不同的L
值解决问题,并选择一个给出最佳目标值的值。这可以通过一个简单的AMPL脚本来完成。