【问题标题】:AMPL: Subscript out of boundAMPL:下标超出范围
【发布时间】:2014-10-15 11:39:10
【问题描述】:

各位优化师们好!

我在以下约束方面遇到了一些问题:

#The supply at node i equals what was present at the last time period + any new supply and      subtracted by what has been extracted from the node.    
subject to Constraint1 {i in I, t in T, c in C}:
    l[i,t-1,c] + splus[i,t] - sum{j in J, v in V, a in A} x[i,j,v,t,c,a]= l[i,t,c];

这自然会导致此约束在第一次循环时提供错误,因为未定义 t-1(对我来说,未定义 l[i,0,c]。在哪里

  var l{I,T,C} >= 0;    # Supply at supply node I in time period T for company C.
  param splus{I,T};     # Additional supply at i.
  var x{N,N,V,T,C,A} integer >= 0;  #Flow from some origin within N to a destination within N using vehicle V, in time T, for company C and product A.

并设置T; (在 .mod 中)是一组定义为:

 set T := 1 2 3 4 5 6 7; in the .dat file

我已经尝试过:

subject to Constraint1 {i in I, t in T: t >= 2, c in C}:
all else same

这给了我一个语法错误。我还尝试为所有可能的组合包含“let l[1,0,1] := 0”,这让我出错了

  error processing var l[...]:
  no data for set I

我也试过

subject to Constraint1 {i in I, t in T, p in TT: p>t, c in C}:
   l[i,t,c] + splus[i,p] - sum{j in J, v in V, a in A} x[i,j,v,p,c,a]= l[i,p,c];

在哪里

set TT := 2 3 4 5 6;

在 .dat 文件中(并且仅在 .mod 中设置 TT;),这也给出了错误。有人知道如何做到这一点吗?

【问题讨论】:

    标签: ampl neos-server


    【解决方案1】:

    解决此问题的一种方法是在索引表达式的末尾指定条件t >= 2

    subject to Constraint1 {i in I, t in T, c in C: t >= 2}:
      ...
    

    有关索引表达式语法的更多详细信息,另请参阅Section A.3 Indexing expressions and subscripts

    【讨论】:

    • 明天我有电脑的时候试试。从某种意义上说,我尝试了同样的事情,但在不同的地方,这会有点有趣。呵呵。感谢您的回答!
    猜你喜欢
    • 2021-05-02
    • 2015-05-27
    • 2021-09-18
    • 2012-04-28
    • 2017-01-18
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多