Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Decision variable setting and constraints in CPLEX

  • 1.  Decision variable setting and constraints in CPLEX

    Posted Wed July 06, 2022 09:47 AM
    Dear All,

    I am trying to construct a model to solve for assigning fruits into multi-compartment vehicles to maximize the total weight at the destination calculating from the weight loss rate per hour. I think i'm missing some constraints as the results of three decision variables did not match.


    the current outcome is: 
    a[vehicle][type] and x[vehicle][type][compartment][freshfruits] is'1' when y[vehicle][type][compartment][freshfruits] is '0' 
    (they should be '0' as well)

    the logic should be
    if there's an assignment to any vehicle then a[vehicle][type] and x[vehicle][type][compartment][freshfruits] = 1
    else  equal 0

    Here's the model
    type = (1,2,3)
    numofcompartment = {1,2,3}
    (ie type 1 has 1 compartment, type 2 has 2 compartment)

    dvar boolean a[vehicle][type];                                                     ( if vehicle 'v' with type 't' is  used or not, hence indicate whether the vehicle is activated or not)
    dvar boolean x[vehicle][type][compartment][freshfruits];             ( if fruit is assigned to the compartment in each vehicle) 
    dvar float y[vehicle][type][compartment][freshfruits];                   ( amount of fruits )
    dvar boolean z[vehicle][edges];


    maximize sum(v in vehicle)(sum (f in freshfruits, t in type, c in compartment)((100- (sum(e in edges)z[v][e]*(e.transittime+e.transportime))* fruits[f].WL)/100)*y[v][t][c][f]);
    subject to{



    //vehicle selection//
    ct1:
    forall(v in vehicle)
    sum(t in type) a[v][t] <= 1 ;
    used == sum(v in vehicle, t in type)a[v][t];

    //fruit assignment//
    ct2:
    forall(v in vehicle, t in type, c in compartment)
    sum(f in freshfruits) x[v][t][c][f] <= avail[t][c]*a[v][t];
    ct3:
    forall(v in vehicle, t in type, c in compartment, f in freshfruits)
    y[v][t][c][f] <= capacity[t][c]*x[v][t][c][f];


    ct4:
    forall(f in freshfruits)
    sum(v in vehicle, t in type, c in compartment)y[v][t][c][f] == fruits[f].requirement;


    // route selection//
    ct5:
    forall(n in nodes,v in vehicle, t in type)
    sum(e in edges:e.i==n) z[v][e] - sum(e in edges: e.j==n)z[v][e] == ((n==origin)?1:((n==destination)?(-1):0));

    //transportation time//

    ct6:
    forall(v in vehicle)
    sum(e in edges) z[v][e]*(e.transittime+e.transportime) <= TmaxLB;


    // nonnegativity//
    ct7:
    forall(v in vehicle, t in type, c in compartment, f in freshfruits)
    y[v][t][c][f] >=0 ;


    }


    Can anyone help me, please? Thank you in advance.
    Supisara K

    ------------------------------
    Supisara Krairiksh
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Decision variable setting and constraints in CPLEX

    Posted Mon July 11, 2022 06:05 AM

    Hi @Supisara Krairiksh,

    In this situation, I would change  a and x to depr ​such that:

    dexpr int x[v in Vehicle][t in Type][c in Compartment][f in Freshfruits] = y[v][t][c][f] > 0;

    An other option could use a and x as constraint:

    constrant x[Vehicle][Type][Compartment][Freshfruits];...

    subject to {
    ...
    forall(.....) {
    x[v][t][c][f]: y[v][t][c][f] > 0;
    }

    ...

    }

    Hope this helps



    ------------------------------
    Cédric Doens
    ------------------------------