How is a conditional summation possible in Cplex? like sumifs in Excel?

后端 未结 2 494
再見小時候
再見小時候 2021-01-26 12:55

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[n         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-26 13:56

    There are several ways to put your problem into an integer programming framework. There are books written on this subject. I think this is the simplest formulation.

    I assume that in your problem, r[i,k] and d[i] are known and that the time horizon is broken into discrete time periods.

    • on[i,t] indicator that activity i is active at time t
    • start[i,t] indicator that activity i starts at the start of period t
    • end[i,t] indicator that activity i finishes at the end of period t

    So in[i,t] replaces the condition f[i]-d[i]<=t-1 && t<=f[i])*r[i,k] Your constraint becomes

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

    You also need to add constraints to enforce the definition of on, start and off.

       forall(t in 2..f[nAct])
          forall(i in I)
             on[i,t-1] - on[i,t] = end[i,t-1] - start[i,t];
    
       forall(i in I)
          on[i,0] = start[i,0];
    
       forall(i in I)
          sum(t in 1..f[nAct]) start[i,t] = 1;
       forall(i in I)
          sum(t in 1..f[nAct]) end[i,t] = 1;
       forall(i in I)
          sum(t in 1..f[nAct]) on[i,t] = d[i];
    

提交回复
热议问题