如何在OPL的替代函数中进行if and else? [英] How to make a if and else in alternative function in OPL?

查看:115
本文介绍了如何在OPL的替代函数中进行if and else?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要确定挣值是否与计划不同,然后选择替代2,如果相同,然后选择替代1.我使用元组模式使用CP(约束编程)确定OPL中的2个替代我仍然坚持到这部分为止

I want to make if the earn value is not same with the plan then choose alternative 2, if same then choose alternative 1. I used tuple mode to determine the 2 alternative in OPL using CP(constraint programming) I still stuck until this part

**subject to {
  forall (p in Precedences, m in Modes) {
 alternative(Tasks[p], all(m in Modes: m.taskId==p.id) mode[m]);**

谢谢,我需要这部分来完成我的硕士论文,因为我没有编程的基本知识

thanks, I need this part to finish my master thesis, because I don't have a basic about programming

推荐答案

感谢您回答我的问题,我感到很幸运.此代码适用于使用元组吗?因为我将模式设置为元组?当我尝试使用范围1..2时,dvar错误.这是我的原始代码

thanks for response my question, I felt bless. this code plicable to using tuple? because I make my mode at tuple? when I tried using range 1..2 the dvar was error. this is my original code

tuple Mode {
  key int taskId;
  key int id;
  int pt;
  int costprod;
  int dmdIntRes [IntRes];
  int dmdExtRes [ExtRes];
}
{Mode} Modes = ...;

dvar interval Tasks [p in Precedences]in p.RelDate..EndMax   ; //in p.RelDate..EndMax in 0..EndMax
dvar interval mode[m in Modes] optional  size m.pt;

cumulFunction IntResUsage[r in IntRes] = 
  sum (m in Modes: m.dmdIntRes[r]>0) pulse(mode[m], m.dmdIntRes[r]);
  
cumulFunction ExtResUsage[r in ExtRes] = 
  sum (m in Modes: m.dmdExtRes[r]>0) pulse(mode[m], m.dmdExtRes[r]);
  
execute {
        cp.param.FailLimit = 10000;
}
 
minimize max(p in Precedences) endOf(Tasks[p]);
subject to {
  forall (p in Precedences, m in Modes) {
 
    alternative(Tasks[p], all(m in Modes: m.taskId==p.id) mode[m]);

这篇关于如何在OPL的替代函数中进行if and else?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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