0

I have defined variables Itvs[units][activities][results] as intervals and resAlloc as an integer. The value of resAlloc influences the size of each interval in Itvs. However, when attempting to calculate the total resources allocated to each day using cumulFunction-pulse, I encounter a limitation because resAlloc is declared as a decision variable (dvar), which cannot be directly processed in this context.

int reqRes [u in units][i in activities][r in resources] = sum (t in unitTypes) unitConfig [u][t] * resInAct [t][i][r];
 
 dvar interval resItvs [units][activities][resources] optional;
 dvar int+ allocRes [units][activities][resources];
 
 
 dexpr int resDuration [u in units][i in activities][r in resources] = (reqRes[u][i][r] != 0) ? reqRes[u][i][r] div allocRes[u][i][r]: 0;
 cumulFunction resUsage [r in resources] = 
    sum(u in units, i in activities) pulse(resItvs[u][i][r], allocRes[u][i][r]);

I aim to utilize a cumulative function resUsage that adheres to the constraints imposed by resource availability.

forall (r in resources) resUsage [u] <= resAvail [r]

There might be alternative methods available apart from using pulse or cumulFunction. Thanks.

1 Answer 1

0

You can use alternative to do the multiplication.

using CP;

range r=1..5;

dvar interval it;



dvar interval it_alternatives[r] optional;
cumulFunction c=sum(i in r)pulse(it_alternatives[i],10*i);

dvar int x in r;

maximize x;

subject to
{
 alternative(it,it_alternatives);
 startOf(it)==2;
 endOf(it)==4;
 c<=30;
 x==sum(i in r) (i*presenceOf(it_alternatives[i]));
}

int v[i in 0..5]=cumulFunctionValue(c,i);
execute
{
  writeln(v);
  writeln(x);
}

gives

[0 0 30 30 0 0]
3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.