我正在监督关于 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 $75000 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 的唯一可行值。我已经看了这个问题一个多小时了,但仍然不明白发生了什么。谁能解释一下?