Topic
  • 3 replies
  • Latest Post - ‏2013-02-25T19:55:33Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic Indexing Arrays with Decision Variables

‏2013-02-21T22:59:58Z |
I am new to CPLEX so my apologies if I am missing something obvious.

Here is a reduced version of my problem:
I would like to index arrays in my objective function with the values of the decision variables. However, when I tried to do it I get: "Indexing array "Q" with type dvar int not supported by this algorithm." error. So, I tried to work around with a separate int variable "t" but this results in an unexpected outcome: instead of a positive value of the objective function (which is expected because we are maximizing a sum of products of positive values) the solver returns zero because all rows and columns are eliminated at the pre-solve stage.

When I tried to force the first value of "t" the solver reported infeasibility.

There will be more constraints imposed on the decision variables once the problem of using it as an index for defined arrays is resolved.

Any help will be much appreciated.

int k = 144;
range time = 1..k;
range time0 = 0..k;

int Qmax = 400;
range states = 0..Qmax;

float Qstatesstates = ...; //non negative values read from the data file
float Ptime=...; //non-negative values read from the data file

int ttime0; //I had to introduce this variable because d can not act as an index for Q
dvar int dtime0 in states;

maximize
sum(k in time) P[k]*Q[tk-1][tk]; //sum of products of positive values
subject to {
forall(k in time0) t[k]==d[k];
}
Updated on 2013-02-25T19:55:33Z at 2013-02-25T19:55:33Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: Indexing Arrays with Decision Variables

    ‏2013-02-22T21:35:12Z  
    When I looked at my question I realized that I did not write it well and I copied the wrong code...

    Here is what I am trying to do:

    int k = 144;
    range time = 1..k;
    range time0 = 0..k;

    int Qmax = 400;
    range states = 0..Qmax;

    float Qstatesstates = ...;
    float Ptime=...;

    dvar int dtime0 in states;

    maximize
    sum(k in time) P[k]*Q[dk-1][dk];
    subject to {
    d[0]==150;
    forall(k in time) d[k]-dk-1 <=13;
    forall(k in time) d[k]-dk-1 >=-13;
    }

    and the objective function will not take d as the index for Q
    Thank you in advance.
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: Indexing Arrays with Decision Variables

    ‏2013-02-23T15:07:04Z  
    When I looked at my question I realized that I did not write it well and I copied the wrong code...

    Here is what I am trying to do:

    int k = 144;
    range time = 1..k;
    range time0 = 0..k;

    int Qmax = 400;
    range states = 0..Qmax;

    float Qstatesstates = ...;
    float Ptime=...;

    dvar int dtime0 in states;

    maximize
    sum(k in time) P[k]*Q[dk-1][dk];
    subject to {
    d[0]==150;
    forall(k in time) d[k]-dk-1 <=13;
    forall(k in time) d[k]-dk-1 >=-13;
    }

    and the objective function will not take d as the index for Q
    Thank you in advance.
    Hi,

    It is not possible to index with decision variables. You need to reformulate the problem to avoid this.

    One way for the reformulation is to change
    dvar int d(time0) in states;
    to
    dvar boolean d(time0)(states);
    where
    forall(t in time0) sum(s in states) d(t)(s) == 1;
    then your objective function becomes quadratic
    sum(k in time)sum(s1 in states)sum(s2 in states) P(k)*Q(s1)(s2)*d(k-1)(s1)*d(k)(s2);
    and the constraint is something like
    forall(k in time) forall(s1 in states) forall(s2 in states : s2-s1 > 13 || s1-s2 > 13) d(k)(s2) <= 1 - d(k-1)(s1);

    The above approach will work only if Q is positive semi-definite

    Regards,
    Zahar
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: Indexing Arrays with Decision Variables

    ‏2013-02-25T19:55:33Z  
    Hi,

    It is not possible to index with decision variables. You need to reformulate the problem to avoid this.

    One way for the reformulation is to change
    dvar int d(time0) in states;
    to
    dvar boolean d(time0)(states);
    where
    forall(t in time0) sum(s in states) d(t)(s) == 1;
    then your objective function becomes quadratic
    sum(k in time)sum(s1 in states)sum(s2 in states) P(k)*Q(s1)(s2)*d(k-1)(s1)*d(k)(s2);
    and the constraint is something like
    forall(k in time) forall(s1 in states) forall(s2 in states : s2-s1 > 13 || s1-s2 > 13) d(k)(s2) <= 1 - d(k-1)(s1);

    The above approach will work only if Q is positive semi-definite

    Regards,
    Zahar
    Thank you, Zahar - this works. The problem becomes quite large in size but this is precisely what I needed.
    It would be great if CPLEX could do this transformation...
    Thank you, again for taking the time to answer my question.