GAM中的内联指数增加

发布于 01-21 12:02 字数 400 浏览 2 评论 0原文

我想使用索引方程在张张器上进行迭代,而我总是想在索引I和索引I+1处提取值。一个示例:

Variable x; x.up = 10;

Parameter T /1=1,2=2,3=3,4=4,5=5/;
Set a /1,2,4/;

equation eq(a); eq(a).. x =g= T[a+1];
*x ist restricted by the values of T at the indices 2,3 and 5.

Model dummy /all/;
solve dummy min x use lp;

我知道GAMS将这些索引视为字符串键而不是数字键,因此添加不是故意的。反正这可能吗?可以通过定义另一个张量来解决此EG,不幸的是,我给定的条件需要索引操作内联(即不允许我定义其他参数或集合。

I want to use an index equation to iterate over a tensors, whereas I always want to extract the value at index i and index i+1. An example:

Variable x; x.up = 10;

Parameter T /1=1,2=2,3=3,4=4,5=5/;
Set a /1,2,4/;

equation eq(a); eq(a).. x =g= T[a+1];
*x ist restricted by the values of T at the indices 2,3 and 5.

Model dummy /all/;
solve dummy min x use lp;

I am aware that gams sees the indices as string-keys rather than numerical ones, so the addition is not intended. Is this possible anyway? This e.g. can be solved by defining another tensor, unfortunaly my given conditions require the index operation inline (i.e. I am not allowed to define additional parameters or sets.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹2025-01-28 12:02:24

这个适合您吗?

Variable x; x.up = 10;

Set aa /1*6/;
Parameter T(aa) /1=1,2=2,3=3,4=4,5=5/;
Set a(aa) /1,2,4/;

equation eq(a); eq(a(aa)).. x =g= T[aa+1];
*x ist restricted by the values of T at the indices 2,3 and 5.

Model dummy /all/;
solve dummy min x use lp;

Does this work for you?

Variable x; x.up = 10;

Set aa /1*6/;
Parameter T(aa) /1=1,2=2,3=3,4=4,5=5/;
Set a(aa) /1,2,4/;

equation eq(a); eq(a(aa)).. x =g= T[aa+1];
*x ist restricted by the values of T at the indices 2,3 and 5.

Model dummy /all/;
solve dummy min x use lp;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文