Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

How can i restrict a variable value according to a decision variable?

  • 1.  How can i restrict a variable value according to a decision variable?

    Posted Tue May 26, 2015 06:29 PM

    Originally posted by: RuiCampos


    Hello community, i am working with CPLEX in my master thesis and it is my first time, i'm not very used with the program. However i amtrying to scheduling a machine's start time of work according to some parameters and restrictions of energy and time of work. My code is below:

    int i=...;
    int j=...;
    int k=...;
     
    range maquinas = 1..i;
    range ciclos = 1..j;
    range tempo = 1..k;
     
    //entram na definicao de p[i][k]
    int duracao[maquinas][ciclos]=...;
    float pot[maquinas][ciclos]=...;
    float potencia[maquinas][tempo];
     
    //restricoes dos intervalos das potencias
    int horainicio[maquinas]=...;
    int horafim[maquinas]=...;
    int duracaototal[maquinas]=...;
     
    //restantes variaveis
    float prodliq[tempo]=...;
    float consliq[tempo]=...;
    float tarifa[tempo]=...;
    float precorede[tempo]=...;
    float termofixo = 0.011725;
    float potcontratada = 5;
     
    dvar int+ inicio [maquinas];
    dvar float+ alfaFV [maquinas][tempo];
    dvar float+ alfaRede [maquinas][tempo];
     
    main{
    if(inicio[i]<=k && k<=(inicio[i]+duracao[i][1])){
    potencia[i][k]=pot[i][1];}
    else{
    if((inicio[i]+duracao[i][1])<=k && k<=(inicio[i]+duracao[i][1]+duracao[i][2])){
    potencia[i][k]=pot[i][2];}
    else{
    if((inicio[i]+duracao[i][1]+duracao[i][2])<=k && k<=(inicio[i]+duracao[i][1]+duracao[i][2]+duracao[i][3])){
    potencia[i][k]=pot[i][3];}
    else{
    potencia[i][k]=0;}
    }
      }
    }
     
    dexpr float Prede[k in tempo] = sum(i in maquinas) potencia[i][k]*alfaRede[i][k]+consliq[k];
    dexpr float Fv[k in tempo] = sum(i in maquinas) potencia[i][k]*alfaFV[i][k];
    dexpr float ConsMaq[k in tempo] = sum(i in maquinas) potencia[i][k];
    dexpr float Custo[k in tempo] = Prede[k]*tarifa[k]+termofixo/24*potcontratada;
    dexpr float Remun[k in tempo] = (prodliq[k]-Fv[k])*precorede[k];
     
    minimize sum(k in tempo) Custo[k] - Remun[k];
     
    subject to {
    forall(i in maquinas)
    inicio[i] + duracaototal [i] <= horafim[i];
     
    forall(i in maquinas)
    inicio[i] >= horainicio [i];
     
    forall(k in tempo)
    potencia[i][k] >= 0;
     
    forall(k in tempo)
    Prede[k]>=0;
     
    forall(k in tempo)
    0<=Fv[k]<=prodliq[k];
     
    forall(k in tempo)
    alfaRede[i][k]>=0;
     
    forall(k in tempo)
    alfaFV[i][k]>=0;
     
    forall(k in tempo)
    alfaRede[i][k]+alfaFV[i][k]==1;
    }

    When i run it i got an error message because when i try to define a value to potencia[i][k] according to the value of the inicio[maquinas] which represent the variable decision of the start time of work and the program says that doesnt know inicio[i] because it is a decision variable. How can i do something like that? I will be thankful if you could help with this issue, and congratulations for the tool, altough the problems i'm having because of my inexperience it seems to be really amazing for this kind of problems. Thank you all.


    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: How can i restrict a variable value according to a decision variable?

    Posted Wed May 27, 2015 05:35 AM

    Originally posted by: Philippe_Refalo


    Dear RuiCampos,

    The array potencia[i][k] is a an array of constant because it is defined this way :

    float potencia[maquinas][tempo];

    then you set its values in the main() function. Note that the expressions

    dexpr float Prede[k in tempo] = sum(i in maquinas) potencia[i][k]*alfaRede[i][k]+consliq[k];
    dexpr float Fv[k in tempo] = sum(i in maquinas) potencia[i][k]*alfaFV[i][k];
    dexpr float ConsMaq[k in tempo] = sum(i in maquinas) potencia[i][k];

    will all be constant then. In the model stated in subject to {}  you cannot change these values.

    Note also that the constraints forall(k in tempo) potencia[i][k] >= 0; will make make the whole model infeasible as soon as a value potencia[i][k] is negative, because a model containing -1 <= 0 for instance has no solution. Is that what you want ?

    So you cannot " define a value to potencia[i][k] according to the value of the inicio[maquinas] " but you can state a constraint over potencia[i][k] and the variables inicio[maquinas] so that it will restrict the possibilities of that variables.

     

    Regards

     

    Philippe

     

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: How can i restrict a variable value according to a decision variable?

    Posted Wed May 27, 2015 08:33 AM

    Originally posted by: RuiCampos


    Dear Philippe,

    First of all thank you very much for your answer. In my problem potencia[i][k] is a constant value not defined initially. What i want is that variable to take some different values according to the value of inicio[i] which is a decision variable of my problem. More concretely, i want to do something that allowed me to assign differents values to it. For example the value of potencia[i][k] is equal to the value of pot[i][1] if k is between inicio[i] and inicio[i]+duracao[i][1] and so on for the rest of the conditions. Is there any way to do something like this? The program seems to block because inicio[i] is a decision variable. Thank you for everything,

    Best regards, RuiCampos


    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: How can i restrict a variable value according to a decision variable?

    Posted Mon June 01, 2015 08:32 AM

    Originally posted by: Philippe_Refalo


    In your model, the value of potencia[i][k] depends on the value of a variable inicio[i]  then it cannot be declared as a constant. Declaring it as a constant would means that it is fixed to the same value in any solution of the model a priori. Thus, potencia[i][k]  needs to be an expression or a variable. Declaring it as a variable involves that the logical expressions in the main function needs to be added to the set of constraints of the model. That is in the subject to section.

    For every k value you need to add constraints like this one

    (inicio[i] <= k && k <= (inicio[i]+duracao[i][1])) => potencia[i][k] == pot[i][1];

    The problem with this formulation is that the models gets really big if the horizon (the set of k values) is large. I recommend you to have a look at scheduling capabilities of OPL/CP Optimizer. It seems more suited to your model. You can start to have a look in the user manual here: 

    The application areas>Applications of constraint programming>Modeling and solving a simple problem: house building
    http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.6.1/ilog.odms.ide.help/OPL_Studio/opllanguser/maps/housebuilding1.html

    And to look at the scheduling example provided with OPL, for instance, the example 

    examples/opl/sched_alloc

    Using interval variables could be the adequate approach to your problem.


    #ConstraintProgramming-General
    #DecisionOptimization