Decision Optimization

Decision Optimization

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

 View Only
  • 1.  shadow prices, dual values of constraints

    Posted Thu June 26, 2008 06:55 PM

    Originally posted by: SystemAdmin


    [cwinter said:]

    Hello. I am running a timetabling problem of OPL version 5.5.1. I have 55000 constraints and i need to know the shadow prices of each one in order to make changes, and get to a better solution. How do i do this?. I´ve tried changing the decision variable from int in 0..1 to float+ and naming the contraints like forall(......)
    CT:
    Constraint <=W for example but it only shows "open values", "open slacks".<br />
    I am very new at this, even though the programming is great.

    Thank you very much.
    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: shadow prices, dual values of constraints

    Posted Thu June 26, 2008 08:10 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,

    are you sure you are not including in your model something that makes it a MIP (integer variable or  logical constraint) ?

    I just tried with :
    range r = 1..10;
    dvar float+ x[r];

    minimize sum (i in r) i*x[i];
    subject to  {
      forall(i in r)
      ct:x[i] >= i;
      }

    and I get the duals as a choice in the ocntextual menu of the constraints in the problem browser.


    Alain
    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: shadow prices, dual values of constraints

    Posted Thu June 26, 2008 08:47 PM

    Originally posted by: SystemAdmin


    [cwinter said:]

    Alain, thank you. I´ve seen examples and i´m sure its MIP. I will attach the code at night because i don´t have it with me right know.

    Is the any code i can write after the execute {  command that would show me the shadow costs or dual values of the constraints on the console?

    thank you
    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: shadow prices, dual values of constraints

    Posted Thu June 26, 2008 08:49 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    If it is a MIP you will not have dual values, it needs to be an LP.

    Alain
    #ConstraintProgramming-General
    #DecisionOptimization


  • 5.  Re: shadow prices, dual values of constraints

    Posted Fri June 27, 2008 05:18 AM

    Originally posted by: SystemAdmin


    [cwinter said:]

    It is LP. Here is the code.

    {string} Cursos = ...; //total de cursos a programar
    {string} Dias = ...; //total de dias
    int cruces[Cursos][Cursos] =...; //numero de alumnos que toman par de cursos
    //int cruces1[Cursos][Cursos] =...;
    int creditos[Cursos][Cursos]=...;
    range Semestres = 1..12;
    int CurT[Cursos][Semestres] = ...;//1 si el curso pertenece al semestre

    tuple structCursosCursos {string c1; string c2;};
    //tuple cursoDiaType {string Cursos; string Dias;};
    float duals[Cursos] ;
    int SiVariable[Cursos][Cursos] = ...;//parametro auxiliar para contruir las tuplas cursos cursos para las cuales existira la variable y que indica si tienen examen el mismo dia
    int SiDia[Cursos][Dias] = ...; //binaria que indica si curso puede ser dictado en un dia por disponibilidad de profesor
    float horashoras[Cursos][Dias]=...;
    //int SiSa2[Cursos] = ...; //binario si profesor puede tomar examen sabado2

    {structCursosCursos} CursosCursos = {<c1,c2> | c1,c2 in Cursos: SiVariable[c1][c2] == 1};

    {structCursosCursos} CursosCursosSemestre = {<c1,c2> | c1 in Cursos,c2 in Cursos, t in Semestres: (CurT[c1][t]*CurT[c2][t] == 1) && ord(Cursos, c1) < ord(Cursos,c2) };<br />
    {structCursosCursos} CursosCursosSemestreB[t in Semestres] = {<c1,c2> | c1 in Cursos,c2 in Cursos: (CurT[c1][t]*CurT[c2][t] == 1) && ord(Cursos, c1) < ord(Cursos,c2) };<br />
    dvar float x[Cursos][Dias] in 0..1; //si curso se dicta en dia
    //dvar boolean y[CursosCursos]; //si pares de cursos tienen examen el mismo dia
    dvar boolean l[CursosCursos]; //si dos pares de cursos tiene examen en dias consecutivos
    dvar float+ g[CursosCursos]; //nuemro de horas diff entre par de cursos
    dvar float+ h; //total de horas entre cursos para un solucion especifica
    dvar float+ horastotales;
    dvar int d[Semestres]; //Cuenta de Alumnos de un mismo semestre con exámenes en días sucesivos
    dvar int m; //Cuenta de Alumnos con exámenes en días sucesivos
    dvar int c;
    dvar int horas[CursosCursos];
    dvar boolean w[CursosCursosSemestre]; //si dos pares de curos de un mismo semestre tiene examen en dias consecutivos
    dvar int a[Semestres] in 0..1; //una posibilidad de cursos de un mismo semestre consecutivos muy penalisada
    //{cursoDiaType} CursosDiasCombinations = {<i,d> | t in Semestres, d in Dias, i in Cursos: x[i][d] > 0 && CurT[i][t] == 1};



    minimize ( m //+c/64
    +sum (t in Semestres) a[t] 
    //+sum (t in Semestres) d[t]
    //+h
    );

    subject to{

      //todos los cursoso tienen un solo examen
      forall (i in Cursos)
      CT:
        sum(d in Dias) x[i][d] == 1;
     
      //Cursos que no se pueden dar un sabdo
      sum(i in Cursos, d in Dias) x[i][d]*(1-SiDia[i][d]) == 0;

      //Cursos con cruces no pueden tener examen un mismo dia
      forall (i in CursosCursos, d in Dias: cruces[i.c1][i.c2]> 0)
        CT2:
            x[i.c1][d] + x[i.c2][d] <= 1;<br />        //CT2[x].dual;
       
        //No mas de una pareja de cursos de un mismo semestre con Pruebas en dias consecutivos
      forall (i in CursosCursosSemestre, d in Dias: ord(Dias, d) < 19)<br />CT3:       
    x[i.c1][d] + x[i.c1][next(Dias, d)] + x[i.c2][d]+ x[i.c2][next(Dias, d)]<=1 + w[i];  <br />  forall (t in Semestres)
    CT4:   
        sum (i in CursosCursosSemestreB[t]: cruces[i.c1][i.c2]> 0) w[i]<= a[t];<br />  forall (t in Semestres)
            sum (i in CursosCursosSemestreB[t]: cruces[i.c1][i.c2]> 0) w[i]*cruces[i.c1][i.c2]<= d[t];<br />
        //Nueva: Cuenta Alumnos con pruebas en dias consecutivos
      forall (i in CursosCursos, d in Dias: ord(Dias, d) < 19)<br />        x[i.c1][d] + x[i.c1][next(Dias, d)] + x[i.c2][d]+ x[i.c2][next(Dias, d)]<=1 + l[i];  <br />       
        sum (i in CursosCursos) l[i]*cruces[i.c1][i.c2]<= m;<br />    sum (i in CursosCursos) l[i]*cruces[i.c1][i.c2]*creditos[i.c1][i.c2]<=c;<br />
      //Suma de diff de horas entre pares de pruebas/  forall (i in CursosCursos, d in Dias: ord(Dias, d) < 19 && cruces&#91;i.c1&#93;&#91;i.c2&#93;> 0)
        Ct5: 
        ((x[i.c1][d]/(-horashoras[i.c1][d]+24+horashoras[i.c2][next(Dias,d)])) + x[i.c2][next(Dias,d)]/(-horashoras[i.c1][d]+24+horashoras[i.c2][next(Dias,d)]))  <= g[i] +(1-l[i])*999999; <br />
      sum (i in CursosCursos) 6*(g[i])*cruces[i.c1][i.c2]<= h;<br />
    forall (i in CursosCursos, d in Dias: ord(Dias, d) < 19 && cruces&#91;i.c1&#93;&#91;i.c2&#93;> 0)
          (-horashoras[i.c1][d]+24+horashoras[i.c2][next(Dias,d)])  <= horas[i] +(1-l[i])*999999;<br />      sum (i in CursosCursos) horas[i]<=horastotales;<br />
    forall(i in CursosCursos)
    g[i]>=0;
    forall(i in CursosCursos)
    horas[i]>=0;
    };

    I saw somewhere that when namignt eh constraints i would need to name it like CT[x]; and then CT[x].duals or something like that, but i keep getting so many problems.

    Please help me out..

    Thank you very much
    #ConstraintProgramming-General
    #DecisionOptimization


  • 6.  Re: shadow prices, dual values of constraints

    Posted Fri June 27, 2008 12:39 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hello,

    indeed you have lots of integere variables in your model.
    e.g.

    dvar int d[Semestres]; //Cuenta de Alumnos de un mismo semestre con exámenes en días sucesivos
    dvar int m; //Cuenta de Alumnos con exámenes en días sucesivos
    dvar int c;
    dvar int horas[CursosCursos];
    dvar boolean w[CursosCursosSemestre]; //si dos pares de curos de un mismo semestre tiene examen en dias consecutivos

    With integer variables, you will get a MIP (Mixed Integer Problem) for which you cannot get any dual variables or reduced costs.
    This is not a limitation of the product, this is mathematical programming fact.

    Alain
    #ConstraintProgramming-General
    #DecisionOptimization


  • 7.  Re: shadow prices, dual values of constraints

    Posted Fri June 27, 2008 08:35 PM

    Originally posted by: SystemAdmin


    [cwinter said:]

    Would i be able to see the duals if i change the integers to floats?. There is only one variable which i cannot change to float, which is W[CursosCursosSemestres]. I can leave this one out of the model. Would that work ok??
    #ConstraintProgramming-General
    #DecisionOptimization


  • 8.  Re: shadow prices, dual values of constraints

    Posted Fri June 27, 2008 09:30 PM

    Originally posted by: SystemAdmin


    [Didier Vidal said:]

    If you have an LP model, you can see the reduced costs, in OPL 5.5, by right-clicking on the variable in the problem browser (see screenshot).

    However, changing integers to floats might change the meaning of your model.... Especially if you have boolean variables.
    #ConstraintProgramming-General
    #DecisionOptimization