“alwaysIn”(状态函数)是否可以从一组值中进行选择?

问题描述 投票:0回答:1

状态函数看起来是对我的情况进行建模的最佳选择。 enter image description here 现在区间变量 X 可能处于状态函数 from 'vmin' to 'vmax' 的范围内。 但在我的情况下,任何区间变量都与状态集相关,并且这些状态不是按顺序进行的。 例如,间隔“product_1_Interval”与状态 1 和 3 相关。并且在状态 2 中不允许。 但间隔“product_2_Interval”与状态 2 和 3 相关。 我理想的情况是这样的: enter image description here

OPL 代码示例:

stateFunction myStateFunction;
dvar interval product_1_Interval;
dvar interval product_2_Interval;

subject to
{
alwaysConstant (myStateFunction, 0, 155);
alwaysConstant (myStateFunction, 156, 310);

/* Below need constraint that interval variable product_1_Interval might be in state 1 or 3 */
/* Below need constraint that interval variable product_2_Interval might be in state 2 or 3 */

}

我试着写一些类似的东西:

alwaysEqual(myStateFunction, product_1_Interval,  1) or alwaysEqual(myStateFunction, product_1_Interval,  3);

但是我收到错误“预求解中的异常:约束'alwaysEqual'是顶级约束,它不能在表达式中使用..”。

我的问题:当区间变量与某些不按顺序进行的状态集(stateFunction)相关时,CPLEX Solver 现在是否可以对情况进行建模?

mathematical-optimization cplex solver constraint-programming docplex
1个回答
0
投票

我会使用替代方案并写

using CP;

{int} options={1,3};

stateFunction myStateFunction;
dvar interval product_1_Interval;
dvar interval product_1_Interval_v[options] optional in 0..100 size 100 ;

dvar interval product_2_Interval in 0..10;


subject to
{
alwaysConstant (myStateFunction, 0, 155);
alwaysConstant (myStateFunction, 156, 310);

alternative(product_1_Interval,all(v in options)product_1_Interval_v[v]);

/* Below need constraint that interval variable product_1_Interval might be in state 1 or 3 */
/* Below need constraint that interval variable product_2_Interval might be in state 2 or 3 */


//alwaysEqual(myStateFunction, product_1_Interval,  1) or alwaysEqual(myStateFunction, product_1_Interval,  3);

forall(v in options)alwaysEqual(myStateFunction,product_1_Interval_v[v],  v);


}

execute
{
  writeln(myStateFunction);
}
© www.soinside.com 2019 - 2024. All rights reserved.