Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem with modeling constraints

    Posted 09/05/08 04:00 PM

    Originally posted by: SystemAdmin


    [Simon said:]

    Hello!

    I'm trying to model a CLSD with Concert Technology and Java. The CLSD is a modified version of the CLSP (cf. [url=http://www.palgrave-journals.com/jors/journal/v54/n5/full/2601525a.html]http://www.palgrave-journals.com/jors/journal/v54/n5/full/2601525a.html[/url]).

    I've modeled all constraints except one. The CSLD is based on a TSP and I've problems to model the constraint, which eliminates subtours. The constraint is given formely as follows:

    [img]http://www.4ballerz.de/cplex11/constraint3_10.jpg[/img]

    with: J is a set of products, T is a set of periods. F[sub]jt[/sub] is a integer variable, Y[sub]ijt[/sub] is a binary varible.

    My first approach to model this would be as follows:


    for(int j = 0; j < nPeriod; j++)<br />{
    for(int t = 0; t < nProduct; t++)<br /> {
    IloLinearNumExpr rhs1 = cplex.linearNumExpr();
    for(int i = 0; i <nProduct; i++)<br /> {
    rhs1.addTerm(1., F_jt[i][t]);
    //How to model -J*(1-Y_ijt[i][j][t])
    }
    cplex.addGe(F_jt[j][t], null);
    }
    }


    But I don't know how to model the expressions [tt]-J*(1-Y[sub]ijt[/sub])[/tt] and [tt]J{i}[/tt].

    Can somebody help me?


    A second extension, I try to model , is that a product has to start in a specific period. Therefor I initialize the Array [tt]int periodStart[nProduct][/tt] with nProduct = count of products. In every cell is the start period of a product saved.

    Now I would extend my objective function and constraints (only one is given as an example) as follows:

    [img]http://www.4ballerz.de/cplex11/obj_fun.jpg[/img]


    //objective function
    IloLinearNumExpr objf_a = cplex.linearNumExpr();
    IloLinearNumExpr objf_b = cplex.linearNumExpr();

    for(int j=0; j < nProduct;j++)<br />{
    for(int t = 0; t < nPeriod; t++)<br /> {
    objf_b.addTerm(pv.getO_h_jt()[j][t], I_jt[j][t]);
    for(int i = 0; i < nProduct; i++)<br /> {
    //The modification to start in a later period is here.
    if(j!=i && t > periodStart[j] ) objf_b.addTerm(pv.getO_sc_ij()[i][j], Y_ijt[i][j][t]);
    }
    }
    }

    cplex.addMinimize(cplex.sum(objf_a, objf_b));


    and

    [img]http://www.4ballerz.de/cplex11/constraint3_9.jpg[/img]


    for(int t = 0; t < nPeriod; t++)<br />{
    for(int k = 0; k < nProduct; k++)<br /> {
    IloLinearNumExpr res_3_8a = cplex.linearNumExpr();
    IloLinearNumExpr res_3_8b = cplex.linearNumExpr();

    for(int i = 0; i < nProduct; i++)<br /> {
    if(i!=k && t > periodStart[j] )
    res_3_8a.addTerm(1., Y_ijt[i][k][t]);

    for(int j = 0; j < nProduct; j++)<br /> {
    if(j!=k && t > periodStart[j] )
    res_3_8b.addTerm(1., Y_ijt[k][j][t]);;
    }
    }
    cplex.addEq(cplex.sum(res_3_8a, Z_jt[k][t-1]),
    cplex.sum(res_3_8b, Z_jt[k][t]));
    }
    }


    Would be this approuch correct?

    I know, it's a lot of text, but I hope somebody can help me! Thank you!

    Best Regards

    Simon

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with modeling constraints

    Posted 09/05/08 11:21 PM

    Originally posted by: SystemAdmin


    [prubin said:]

    You first code segment is a bit muddled. Do you really mean j < nPeriod and t < nProduct, or do you have these reversed?&nbsp; Do you really mean addGe(F..., null), or should null be rhs1?<br />
    Let's say that we reverse the loop indexing, so that the outer loop indexes of time (t) and the inner loop over product (j).  In the innermost loop (i), add a term to rhs1 only if i j (in other words, insert an if block).  That handles j \in J{i}.  Also, do not forget to add 1 to rhs1 (which you can do when you declare it).

    The term -J(1-Y...) should actually be -|J|(1-Y...), where |J| is the cardinality of the set J.  So in this case, I think |J| = nProduct, and you can just add the constant term -nProduct to rhs1 and then add nProduct*Y... to it.

    Your approach to the second part looks generally to be on the right track, assuming that the function pv.getO_h_jt() returns a two-dimensional matrix.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problem with modeling constraints

    Posted 09/07/08 12:22 AM

    Originally posted by: SystemAdmin


    [Simon said:]

    Hello!

    Thank you, for your answer, Paul!

    [quote author=prubin link=topic=537.msg1609#msg1609 date=1220638856]
    You first code segment is a bit muddled. Do you really mean j < nPeriod and t < nProduct, or do you have these reversed?&nbsp; <br />

    You are right, I've reversed the bounds, it was just a little slip.

    [quote author=prubin link=topic=537.msg1609#msg1609 date=1220638856]
    Do you really mean addGe(F..., null), or should null be rhs1?


    "null" was just a placeholder. Otherwise Eclipse shows me a fault. It should be rhs1.

    [quote author=prubin link=topic=537.msg1609#msg1609 date=1220638856]
    Let's say that we reverse the loop indexing, so that the outer loop indexes of time (t) and the inner loop over product (j).  In the innermost loop (i), add a term to rhs1 only if i j (in other words, insert an if block).  That handles j \in J{i}.  Also, do not forget to add 1 to rhs1 (which you can do when you declare it).

    The term -J(1-Y...) should actually be -|J|(1-Y...), where |J| is the cardinality of the set J.  So in this case, I think |J| = nProduct, and you can just add the constant term -nProduct to rhs1 and then add nProduct*Y... to it.


    I've tried to trasfer your hints into code. This is my result:


    for(int j = 0; j < nProduct; j++)<br />{
    for(int t = 0; t < nPeriod; t++)<br /> {
    for(int i = 0; i <nProduct; i++)<br /> {
    if(i!=j)
    model.addGe(F_jt[j][t], model.diff(model.sum(1, F_jt[i][t]),
    model.prod(-nProduct, model.diff(1, Y_ijt[i][j][t]))));
    }
    }
    }


    Does it look good? And more important, does it look correct?

    Best Regards

    Simon
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Problem with modeling constraints

    Posted 09/07/08 01:33 AM

    Originally posted by: SystemAdmin


    [prubin said:]

    [quote author=Simon link=topic=537.msg1614#msg1614 date=1220728903]


    for(int j = 0; j < nProduct; j++)<br />{
    for(int t = 0; t < nPeriod; t++)<br /> {
    for(int i = 0; i <nProduct; i++)<br /> {
    if(i!=j)
    model.addGe(F_jt[j][t], model.diff(model.sum(1, F_jt[i][t]),
    model.prod(-nProduct, model.diff(1, Y_ijt[i][j][t]))));
    }
    }
    }



    I think you need either to drop the '-' from '-nProduct' or to change the outer model.diff to model.sum.  Otherwise, it looks about right to my (less than discerning) eye.

    /Paul

    #CPLEXOptimizers
    #DecisionOptimization