是否可以在 CPLEX OPL 中为决策变量预分配值 [英] Is it possible to pre-assign values to decision variables in CPLEX OPL

查看:46
本文介绍了是否可以在 CPLEX OPL 中为决策变量预分配值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量变量(二进制和连续).因此,我确定了一个逻辑,将一些变量设置为 0,这样它们就不会成为优化过程的一部分.

I have a large number of variables ( both Binary and Continuous). Therefore I have determined a logic to assign some variables set to 0 so that they do not become part of the optimisation process.

例如我有一个二元决策变量 y[b][t]:其中 b 从 1 到 100 不等和 t 从 1 到 5.

For example I have a binary decision variable y[b][t]: where b varies from 1 to 100 and t from 1 to 5.

我可以使用一些逻辑来确定 y[20][2] 到 y[100][2] 将是 0.我想将 0 的固定值分配给这些变量 y[20][2] 以后到 y[100][2] 从而减少了我的优化问题中的变量数量.虽然 y 是一个二元决策变量,但我还有其他连续变量,我想提前将其设置为 0.

I could determine using some logic that y[20][2] onwards to y[100][2] would be 0. I want to assign the fixed value of 0 to these variables y[20][2] onwards to y[100][2] thereby reducing the number of variables in my optimisation problem. While y is a binary decision variable I have other continuous variable as well which I would like to similarly set to 0 in advance.

有没有办法做到这一点?我没有将 Python 与 CPEX 一起使用,但听说这可能可以通过设置变量的下限和上限来实现.OPL中是否有类似的方法.

Is there a way how this can be achieved ? I haven't used Python with CPEX but hear that this can be probably be achieved by setting a lower and upper bound of the variables. Is there a similar method in OPL.

----添加于 8 月 13 日可能是我不是很清楚,或者我无法理解建议的解决方案.

----Added 13th Aug May be I was not very clear or I could not understand the solution suggested.

我想要的是说我有以下决策变量 Xbmt ...(我有几个)

What I wanted is say I have the following decision variable Xbmt ...(I have a few of them)

最初声明为:

dvar float+ Xbmt[PitBlocks][Plants][TimePeriods];

dvar float+ Xbmt[PitBlocks][Plants][TimePeriods];

但是对于某些 PitBlocks 和某些时间段,我想将此决策变量定义为 0.我想将决策变量设置为 0 的那些时间段在元组 nullVariables 中定义.它具有与 PitBlocks 相同的块 id,并且具有与 TimePeriod 相同的 time_period.因此我想要像下面这样的东西.但是我不能两次声明决策变量.我只需要 nullVariable 集中的那些 id 才需要它 0.

But for some of the PitBlocks and some time periods I want to define this decision variable as 0. Those time periods for which I want to set the decision variable as 0 are defined in a tuple nullVariables. It has block id same as PitBlocks, and it has time_period same as TimePeriod. Hence I want something like below. But I cannot declare the decision variable twice. I need it 0 only for those ids in the nullVariable set.

dvar float+ Xbmt[NullVariablesSet.block_id][Plants][NullVariablesSet.time_period] in 0..0;


如果一些 Xbmt 保留为决策变量,而通过设置为 0 删除一些 Xbmt,如何实现这一点


How can this be achieved where some of Xbmt remain as decision variables where as some are removed by setting as 0

推荐答案

参见 https://github.com/AlexFleischerParis/zooopl/blob/master/zoopreassign.mod

让决策优化变得简单

int nbKids=300;

{int} seats={40,30}; // how many seats, {} means this is a set
float costBus[seats]=[500,400];

// Now let s see how preassign some decision variables
// Suppose we know that we have exactly 6 buses 40 seats

{int} preassignedseats={40};
int preassignedvalues[preassignedseats]=[6];

     
dvar int+ nbBus[s in seats] 
in 
((s in preassignedseats)?preassignedvalues[s]:0) 
.. 
((s in preassignedseats)?preassignedvalues[s]:maxint);

minimize sum(b in seats) costBus[b]*nbBus[b];
     
subject to
{
    sum(b in seats) b*nbBus[b]>=nbKids;
}

这篇关于是否可以在 CPLEX OPL 中为决策变量预分配值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆