首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MathProg (AMPL) -由另一个变量调整大小的变量数组

MathProg (AMPL) -由另一个变量调整大小的变量数组
EN

Stack Overflow用户
提问于 2012-03-15 14:12:33
回答 1查看 1.5K关注 0票数 1

我正在编写我的第一个GNU MathProg (AMPL)程序来查找给定基数、主机数量和二等分带宽的HyperX拓扑(图)的最小交换机(顶点)计数实例。这是一个简单的第一个程序,因为所有的方程都在下面的论文中描述过:http://cal.snu.ac.kr/files/2009.sc.hyperx.pdf

我已经阅读了规范和示例程序,但我被一个非常简单的语法错误卡住了。我需要有以下两个变量: L,网络中的维数,以及一个长度为L的数组S,其中S的每个元素都是每个维度中的交换机数量。在我的MathProg程序中,我将其表示为:

代码语言:javascript
复制
var L >= 1, integer;
var S{1 .. L} >= 2, integer;

但是,当我运行$ glpsol --check --math hyperx.mod时,我得到以下错误:

代码语言:javascript
复制
hyperx.mod:28: operand following .. has invalid type
Context: ...isec ; param radix ; var L >= 1 , integer ; var S { 1 .. L }

如果有人能帮助我解释我应该如何恰当地表达这种关系,我将不胜感激。此外,我还包括了我写的整个程序,以供参考和额外的帮助。我预计我的程序中会有许多语法错误,但在修复第一个错误之前,我无法找到其余的错误。

代码语言:javascript
复制
/* 
 * 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;
EN

回答 1

Stack Overflow用户

发布于 2012-05-29 08:05:09

问题中变量的固定数量是求解器和代数建模语言(包括AMPL/MathProg )中的一个常见假设。因此,在索引表达式中只能使用常量表达式,尤其是参数,而不能使用变量。一种可能的解决方案是将L作为参数,解决L的不同值的问题,并选择给出最佳目标值的值。这可以通过一个简单的AMPL脚本来完成。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9714800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档