Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 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 05/26/15 03:51 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.


    #CPLEXOptimizers
    #DecisionOptimization


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

    Posted 05/29/15 04:33 AM

    Hi

    You should not use a main here.

    You should turn the constraints you wrote in your main in constraints in the subject to block.

    For example, instead of

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

    you should try something like

    forall(i in Maquinas,k in Tempo)
    (inicio[i]<=k && k<=(inicio[i]+duracao[i][1]))
    =>
    (potencia[i][k]=pot[i][1]);

    regards

     


    #CPLEXOptimizers
    #DecisionOptimization