【问题标题】:Problems with GAMS modelGAMS 模型的问题
【发布时间】:2020-05-29 15:46:52
【问题描述】:

我一直在使用 GAMS,但我仍然不知道我在做什么。 有人可以看看这个短模型并尝试为我指明正确的方向吗? 我在方程式的编译中遇到了问题,其中有一些: 尺寸不同 - 符号被更多/更少引用 声明的索引 非受控集作为常数输入

Sets
        i months / 1, 2, 3 /
        j months / 1, 2, 3 /;

Parameters
         cp(i)  production cost in month i
         /        1     1.08
                  2     1.11
                  3     1.10
                                   /

         rh(i)  number of necessary workers in month i
         /        1     3
                  2     4
                  3     6
                                     /

        cap(i)  production capacity in month i
         /        1     25
                  2     20
                  3     25
                                       /
         q(j)  number of motors to deliver in month j
         /        1     10
                  2     15
                  3     25
                                 /

Scalar ca  cost to store motors for a month /0.15/ ;

variables
    mc(i,j) cost of production of motors in month i to be delivered in month j
    x(i,j)  number of motors produced in month i to be delivered in month j;


free variables
    wf workforce

    z cost of production
    hr human resources;

Equations
    cost cost 
    human_resources human resources
    r1 restriction1
    r2 restriction2 ;

cost .. z  =e=  sum((i,j), (cp(i)+(j-i)*ca)*x(i,j)) ;
human_resources .. hr =e= sum(i, sum(j, rh(i)*x(i, j))) ;
*lower than
r1..   sum(j, x(i,j))  =l=  cap(i) ;
*greater than
r2.. sum(i, x(i,j))  =g=  q(j) ;

Model
    motors 'temp' /all/;

Solve motors using mip minimizing mc;

Display mc, x;

【问题讨论】:

    标签: gams-math


    【解决方案1】:

    这可行,但请检查解决方案。我添加了正变量 x 因为否则你会产生负数。 主要问题是您正在优化一个已声明但从未在方程式中使用的变量。此外,您正在优化的变量不能有尺寸(我认为)。 然后,对于约束 r1 和 r2,您需要添加一个索引,因为它们必须针对每个月进行验证,因此 r1(i) 和 r2(j)。它们实际上是一个“约束族”。 您不能减去月份的索引(无法解释原因),但可以减去它们在集合中的顺序。
    最后,在获得解后计算 mc(i,j) 作为参数。

    Sets
            i months / 1, 2, 3 /
            j months / 1, 2, 3 /;
    
    Parameters
             cp(i)  production cost in month i
             /        1     1.08
                      2     1.11
                      3     1.10
                                       /
    
             rh(i)  number of necessary workers in month i
             /        1     3
                      2     4
                      3     6
                                         /
    
            cap(i)  production capacity in month i
             /        1     25
                      2     20
                      3     25
                                           /
             q(j)  number of motors to deliver in month j
             /        1     10
                      2     15
                      3     25
                                     /
    
    Scalar ca  cost to store motors for a month /0.15/ ;
    
    variables
    *    mc(i,j) cost of production of motors in month i to be delivered in month j
        x(i,j)  number of motors produced in month i to be delivered in month j;
    
    positive variable x;
    free variables
        wf workforce
    
        z cost of production
        hr human resources;
    
    Equations
        cost cost
        human_resources human resources
        r1(i) restriction1
        r2(j) restriction2 ;
    
    cost .. z  =e=  sum((i,j), (cp(i)+(ord(j)-ord(i))*ca)*x(i,j)) ;
    human_resources .. hr =e= sum(i, sum(j, rh(i)*x(i, j))) ;
    *lower than
    r1(i)..   sum(j, x(i,j))  =l=  cap(i) ;
    *greater than
    r2(j).. sum(i, x(i,j))  =g=  q(j) ;
    
    Model
        motors 'temp' /all/;
    
    Solve motors using mip minimizing z;
    
    Parameter mc(i,j);
    mc(i,j)= (cp(i)+(ord(j)-ord(i))*ca)*x.l(i,j);
    Display mc, x.l;
    
    

    【讨论】:

    • 首先,非常感谢!它确实有帮助。我现在有另一个问题......我认为这是一件简单的事情,但我无法在任何地方找到答案。问题在下面,如果你能快速看一下! stackoverflow.com/questions/62134823/… 再次感谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多