派生变量停留在 0(无法求解固定变量)

Derived variable stuck at 0 (unable to solve for fixed variable)

我正在监督关于 LINGO 和 LP 的练习,今天有一个关于投资的练习。这是预期的解决方案:

MODEL:

SETS:
    year /t0 t1 t2 t3/: capital;
    investment /A B C D E/: allocated;
    table(investment, year): cash_flow;
ENDSETS

DATA:
    cash_flow = -1 0.5 1 0
            0 -1 0.5 1
            -1 1.2 0 0
            -1 0 0 1.9
            0 0 -1 1.5;
ENDDATA

max = capital(4);

! Capital(i) indicates the amount of money left after time i;

! Initial capital;
capital(1) = 100000 + @SUM(investment(j): allocated(j)*cash_flow(j, 1));

! Capital after one year is last year's capital plus interest
and the cash flows times investments of the current year;
@FOR(year(i) | i #GT# 1: capital(i) = 1.08*capital(i - 1)
    + @SUM(investment(j): allocated(j)*cash_flow(j, i)));

! Capital must be positive after each time period;
@FOR(year: capital >= 0);

! No more than 000 may be invested in a single investment;
@FOR(investment: allocated <= 75000);
@FOR(investment: allocated >= 0);

END

一名学生试图用一个变量代替每年的净现金流量以消除一些代码重复。但是,只需将变量 net_cashflow 添加到 sets-section 中年份的派生集,并将以下约束添加到正文中:

@FOR(year(i): net_cashflow(i) = @SUM(investment(j): cash_flow(j, i)*allocated(j)));

LINGO 的解决方案现在是错误的。所有 net_cashflow(i) 都设置为 0,因此所有分配的 (j) 也都为 0。当我尝试使用此约束强制 net_cashflow(1) = -100000(因为它应该在最佳解决方案中)时:

net_cashflow(1) = -100000;

我收到以下错误:

 [Error Code: 72]

    Unable to solve for fixed variable:
    NET_CASHFLOW( T0)
  in constraint:
    10
  Loosening the variable's bounds may help.

  The error occurred on or near the following line:
     31]net_cashflow(1) = -100000;

但即使我用非常松散的边界(如 net_cashflow(1) <= -1)替换此约束,LINGO 告诉我没有可行的解决方案,就好像 0 是唯一可行的值一样所有 net_cashflow。我已经研究这个问题一个多小时了,但仍然不明白发生了什么。谁能解释一下?

(由于没有人回应,我终于找到了解决方案,可能对以后的读者自己post答案有用:)

显然 LINGO 变量默认是非负的。此问题已通过添加约束(或更确切地说是放宽)得到解决:

@FOR(year: @FREE(net_cashflow));