如何在Cplex中进行条件求和?像Excel中的sumifs? [英] How is a conditional summation possible in Cplex? like sumifs in Excel?

查看:3681
本文介绍了如何在Cplex中进行条件求和?像Excel中的sumifs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想总结所有使用的资源在我的模型中的时间(它的rcpsp模型)
我如何在CPLEX中做它?
首先我写了:

I want to sum all used resources among times in my model (it's rcpsp model) how can I do it in CPLEX? at first I wrote this:

forall(k in K)
  forall(t in 1..f[nAct])
    sum(i in I:f[i]-d[i]<=t-1 && t<=f[i]) r[i,k] <= aR[k]; 

(注意:K是资源的范围,nAct是活动数,f [i]数组dvar并且指示活动i的完成时间,d [i]是i的持续时间,r [i,k]是活动i的所需资源k,并且aR [k]是k的可用资源。)

(note: K is a range for resources, nAct is number of activities, f[i] is an array dvar and indicates finishing time of activity i, d[i] is duration of i,r[i,k] is required resource of k for activity i and aR[k] is available resources of k.)

问题是cplex不接受sum的条件中的决策变量。
我改为:

The problem is that the cplex doesn't accept decision variable in sum's condition. I changed it to:

forall(k in K)
  forall(t in 1..f[nAct])
    sum(i in I) (f[i]-d[i]<=t-1 && t<=f[i])*r[i,k] <= aR[k]; 

但它没有工作。它在问题浏览器中运行后(我不知道为什么),它使得这个约束无效的真正的约束。

But it didn't work. it made True constraints in Problem Browser after run(I don't know why) and it made this constraint ineffective.

任何想法如何解决它?

Any Idea how to fix it?

推荐答案

您可以使用 dexpr 用于操作决策变量。以下是来自相同资源的示例 IBM知识中心

You can use dexpr for manipulating decision variables. Here is an example from the same resource IBM Knowledge Center.

没有dexpr

dvar int x in 0..20;
dvar int y in 0..20;
dvar int d;
dvar int s;
maximize (d);
subject to {
  d==x-y;
  s==x+y;
  s<=15;
  s<=x-2*y;
  d>=2;
  d<=y+8;
  1<=d;
}

使用dexpr

dvar int x in 0..20;
dvar int y in 0..20;
dexpr int d=x-y;
dexpr int s=x+y;
maximize (d);
subject to {
  s<=15;
  s<=x-2*y;
  d>=2;
  d<=y+8;
  1<=d;
}

这篇关于如何在Cplex中进行条件求和?像Excel中的sumifs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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