Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

How to find all the different solutions of the decision variable corresponding to the optimal value

  • 1.  How to find all the different solutions of the decision variable corresponding to the optimal value

    Posted Thu May 03, 2018 07:51 AM

    Originally posted by: skyskyhuanghuang


    Hi,everyone.I encountered a problem.

      

    using CP;
    int M=...;
    float P=...;
    float H[1..M][1..M]=...;
    float B0=...;
    float n0=...;
    dvar int Yji[1..M][1..M] in 0..1 ;
    execute
    {
    var p=cp.param;
    p.LogPeriod=80000;
    p.TimeLimit=300;
    p.Workers=40;
    p.searchType="Restart";
    p.OptimalityTolerance=1;
    }
     
     
     
    maximize
    B0*sum(i in 1..M)(
         log(1+P*sum(j in 1..M:j!=i)(
                 H[j][i]*Yji[j][i]/ //fenzi
                   (n0+P*sum(n in 1..M:n!=j)(
                            sum(q in 1..M)H[n][i]*Yji[n][q]
                          )
                   )
               )
             )/log(2)
       );
       
    subject to
    {
    forall(i in 1..M)
    {
    Hangyueshu:
     sum(j in 1..M)
         Yji[i][j]<=1;   
    }
    forall(i in 1..M)
    {
    Lieyueshu:  
        sum(j in 1..M)
         Yji[j][i]<=1;   
    }
    forall(i in 1..M)
    Zishenyueshu:
      Yji[i][i]==0;
    forall(i in 1..M)
    {
    FDRLimiation:
      sum(j in 1..M)
        (Yji[i][j]+Yji[j][i])-Yji[i][i]<=2;
    }
    }
    execute
    {
    writeln("Yji=",Yji);
    writeln("Objective= ",cp.getObjValue());
     
    }
    main
    {
    var nbsol=0;
    thisOplModel.generate();
    cp.startNewSearch();
    while(cp.next())
    {
    nbsol++;
     
    writeln("solution ",nbsol);
    thisOplModel.postProcess();
    }
     
    }

    The data file is as follows

    M=3;
    P=0.126;//21dbm 0126w
    H=[
    [0 5 0]
    [0 0 6]
    [0 0 0]

    ];
    B0=20e6;
    n0=6.3e-13;

    The result is as follows:

    solution 1
    Yji= [[0 1 0]
             [0 0 1]
             [1 0 0]]
    Objective= 1.59978617e+09

    However, the decision variable can have other values. The target value is also 1.59978617e+09. For example, the decision variable can be as follows:

    Yji= [[0 1 0]
             [0 0 1]
             [0 0 0]]

    How to find all the different solutions of the decision variable corresponding to the optimal value?

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to find all the different solutions of the decision variable corresponding to the optimal value

    Posted Thu May 03, 2018 09:07 AM

    Hi,

    you simply need another .mod without any objective and with a constraint that you achieve the optimal value.

     

     

    with the same .dat

    using CP;
    int M=...;
    float P=...;
    float H[1..M][1..M]=...;
    float B0=...;
    float n0=...;
    dvar int Yji[1..M][1..M] in 0..1 ;
    execute
    {
    var p=cp.param;
    p.LogPeriod=80000;
    p.TimeLimit=300;
    p.Workers=40;
    p.searchType="Restart";
    p.OptimalityTolerance=1;
    }
     
    dvar int obji;
     
    dexpr float obj=
    B0*sum(i in 1..M)(
         log(1+P*sum(j in 1..M:j!=i)(
                 H[j][i]*Yji[j][i]/ //fenzi
                   (n0+P*sum(n in 1..M:n!=j)(
                            sum(q in 1..M)H[n][i]*Yji[n][q]
                          )
                   )
               )
             )/log(2)
       );

     

     
    subject to
    {
    obji==floor(obj);


    forall(i in 1..M)
    {
    Hangyueshu:
     sum(j in 1..M)
         Yji[i][j]<=1;   
    }
    forall(i in 1..M)
    {
    Lieyueshu:  
        sum(j in 1..M)
         Yji[j][i]<=1;   
    }
    forall(i in 1..M)
    Zishenyueshu:
      Yji[i][i]==0;
    forall(i in 1..M)
    {
    FDRLimiation:
      sum(j in 1..M)
        (Yji[i][j]+Yji[j][i])-Yji[i][i]<=2;
    }
    }
    execute
    {
    writeln("Yji=",Yji);
    writeln("Objective= ",obj);
     
    }
    main
    {
    thisOplModel.generate();
    thisOplModel.obji.LB=1599786173 ;

     


    var nbsol=0;
    cp.param.SearchType=24;
    cp.startNewSearch();
    while(cp.next())
    {
    nbsol++;
     
    writeln("solution ",nbsol);
    thisOplModel.postProcess();
    }
     
    }

    gives

    solution 1
    Yji= [[0 1 0]
             [0 0 1]
             [0 0 0]]
    Objective= 1599786173.662662983
    solution 2
    Yji= [[0 1 0]
             [0 0 1]
             [1 0 0]]
    Objective= 1599786173.662662983

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to find all the different solutions of the decision variable corresponding to the optimal value

    Posted Sat May 05, 2018 02:52 AM

    Originally posted by: skyskyhuanghuang


    Thank you, your method is correct.But how to solve the value of all decision variables corresponding to the optimal solution in the same model?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to find all the different solutions of the decision variable corresponding to the optimal value

    Posted Sat May 05, 2018 04:21 AM

    Hi,

    why do not you use 2 models ?

    One with the objective and one without ?

    Are you a student ?

    But if you really need to have only one model:

    sub.mod

    using CP;

    dvar boolean x[1..4];
    dvar int obj;

    include "obj.mod";

    subject to
    {
    obj==sum(i in 1..4) x[i];

    sum(i in 1..4) x[i]<=2;
    }

    execute
    {
    writeln("x=",x);
    }

    and then

    main
    {

    var o=new IloOplOutputFile("obj.mod");
    o.writeln("maximize obj;");
    o.close();

    var source = new IloOplModelSource("sub.mod");
    var cp = new IloCP();
    var def = new IloOplModelDefinition(source);
    var opl = new IloOplModel(def,cp);
    opl.generate();
    if (cp.solve()) {
         writeln("OBJ = " + cp.getObjValue());
         opl.postProcess();

      } else {
         writeln("No solution");
      }
     
    writeln();
    writeln("and now all the solutions with that objective");
    writeln();  

    var o2=new IloOplOutputFile("obj.mod");
    o2.writeln("//maximize obj;");
    o2.close();

    var source2 = new IloOplModelSource("sub.mod");
    var cp2 = new IloCP();
    var def2 = new IloOplModelDefinition(source2);
    var opl2 = new IloOplModel(def2,cp2);
    opl2.generate();
    opl2.obj.UB=cp.getObjValue();
    opl2.obj.LB=cp.getObjValue();


    var nbsol=0;
    cp2.param.SearchType=24;
    cp2.startNewSearch();
    while(cp2.next())
    {
    nbsol++;
     
    writeln("solution ",nbsol);
    opl2.postProcess();
    }
    }

    gives

    OBJ = 2
    x= [0 1 1 0]

    and now all the solutions with that objective

    solution 1
    x= [1 1 0 0]
    solution 2
    x= [0 1 1 0]
    solution 3
    x= [1 0 1 0]
    solution 4
    x= [0 1 0 1]
    solution 5
    x= [0 0 1 1]
    solution 6
    x= [1 0 0 1]

     

    regards

    https://www.linkedin.com/pulse/model-building-oplcplex-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: How to find all the different solutions of the decision variable corresponding to the optimal value

    Posted Mon May 07, 2018 09:14 PM

    Originally posted by: skyskyhuanghuang


    Thank you, I am a student


    #DecisionOptimization
    #OPLusingCPLEXOptimizer