Decision Optimization

Decision Optimization

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

 View Only
  • 1.  How to find non dominated solutions with multi objective (MCDA)

    Posted Fri September 15, 2017 04:22 PM

    Hi,

     

    at https://www.ibm.com/developerworks/community/forums/html/topic?id=193ecefc-757c-4c66-9905-7ac0dd81dc8f&ps=25

    we addressed MCDA by using lexicographic order which could be not enough.

    If lexicographic objective is not valid, we can mix solution enumerating and filtering in order to get non dominated solutions.

    For example with solution pools you would write:

    /*********************************************
     * OPL 12.7.1.0 Model
     * Author: AlexFleischer
     * Creation Date: Sep 15, 2017 at 7:19:28 PM
     *********************************************/
    int n=10;
    int m=25;

    range position = 1..n;

    dvar boolean x[position][position];
    dvar int obj1 in position;
    dvar int obj2 in position;

    minimize obj1+obj2;

    subject to
    {
      sum(i,j in position) x[i][j]==m;
     
      obj1==max(i,j in position) i*x[i][j];
      obj2==max(i,j in position) j*x[i][j];
    }

    execute
    {
    writeln("objectives : ",obj1," ",obj2);

    writeln("-----------------------------");
    writeln();

    for(var i in position)
    {
     for(j in position) write((x[i][j]==1)?"+":" ");
     writeln();
    }
    }

     main

    {

       writeln("solution pools")

       thisOplModel.generate();
       cplex.solnpoolintensity=4;
       cplex.solnpoolcapacity=1000;
       cplex.solnpoolreplace=2;
       cplex.populatelim=20000;
       
       cplex.solve();
       var nsolns = cplex.solnPoolNsolns;
       writeln("n sol ",nsolns);
       
       var obj1=new Array(nsolns);
       var obj2=new Array(nsolns);;
       
       for(var s = 0; s < nsolns; s++)
       {
          thisOplModel.setPoolSolution(s);
          thisOplModel.postProcess();
          obj1[s]=thisOplModel.obj1.solutionValue;
          obj2[s]=thisOplModel.obj2.solutionValue;
          
       }
       
       writeln("not dominated solutions");
       
       for(var s = 0; s < nsolns; s++)
       for(var s2 = s+1; s2 < nsolns; s2++) if ((obj1[s]==obj1[s2]) && (obj2[s]==obj2[s2]))
       {
          obj1[s2]=thisOplModel.n+1;  
          obj2[s2]=thisOplModel.n+1;  
       }
       
       
       for(var s = 0; s < nsolns; s++)
       {
          var dominated=0;
          for(var s2 = 0; s2 < nsolns; s2++) if (s!=s2) if ((obj1[s2]<=obj1[s]) && (obj2[s2]<=obj2[s]))
                dominated=1;
          if (dominated==0)
          {
              thisOplModel.setPoolSolution(s);
                  thisOplModel.postProcess();  
          }
          
       }
       cplex.clearModel();
    }

    which would give

    not dominated solutions
    objectives : 5 5
    -----------------------------

    +++++     
    +++++     
    +++++     
    +++++     
    +++++     
              
              
              
              
              
    objectives : 3 9
    -----------------------------

    +++++ + +
    +++++++++
    +++++++++
              
              
              
              
              
              
              
    objectives : 4 7
    -----------------------------

    +++ + +   
    +++ +++   
    +++++++   
    +++++++   
              
              
              
              
              
              
    objectives : 8 4
    -----------------------------

    +++       
    ++++      
    ++++      
    ++++      
     ++       
    ++++      
    +         
    +++      

    regards

     

    NB:

    You could also use other enumerate options such as https://www.ibm.com/developerworks/community/forums/html/topic?id=d8d12e36-3150-4e1c-a956-d707d17f274c&ps=25

    and

    https://www.ibm.com/developerworks/community/forums/html/topic?id=fad149da-5bf8-4624-a88a-4444ad3702f8&ps=25


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to find non dominated solutions with multi objective (MCDA)

    Posted Wed July 18, 2018 10:58 AM

    PS:

    And then I got the question about showing the Pareto graph.

    So let me share that too.

    visu.mod

     

        execute
        {

        // turn an OPL array into a python list
            function getPythonListOfArray(_array)
            {

            var quote="\"";
            var nextline="\\\n";


            var res="[";
            for(var i =1;i< _array.length;i++)
            {
            var value=_array[i];

            if (typeof(value)=="string") res+=quote;
            res+=value;
            if (typeof(value)=="string") res+=quote;
            res+=",";
            res+=nextline;
            }
            res+="]";
            return res;
            }

            // Display a function with points with x and y arrays of x and y
            function displayXY(x,y,pythonpath,pythonfile,graphName,xName,yName)
            {
            writeln("displayXY ",x," ",y," ",pythonpath," ",pythonfile);

            var python=new IloOplOutputFile(pythonfile);
            python.writeln("import matplotlib.pyplot as plt");
            python.writeln("x = ",getPythonListOfArray(x))
            python.writeln("y = ",getPythonListOfArray(y))
            python.writeln("plt.plot(x, y)");
            python.writeln("plt.xlabel('",xName,"')");
            python.writeln("plt.ylabel('",yName,"')");
            python.writeln("plt.title('",graphName,"')");
            python.writeln("plt.show()");
            python.close();
            IloOplExec(pythonpath+" "+ pythonfile,true);        
            }
            }

     

    and then

    include "visu.mod";

    int n=10;
    int m=25;

    range position = 1..n;

    tuple t
    {
    int obj1;
    int obj2;
    }

    sorted {t} nonDominatedSolutions;

    dvar boolean x[position][position];
    dvar int obj1 in position;
    dvar int obj2 in position;

    minimize obj1+obj2;

    subject to
    {
      sum(i,j in position) x[i][j]==m;
     
      obj1==max(i,j in position) i*x[i][j];
      obj2==max(i,j in position) j*x[i][j];
    }

    execute
    {
    writeln("objectives : ",obj1," ",obj2);

    writeln("-----------------------------");
    writeln();

    for(var i in position)
    {
     for(j in position) write((x[i][j]==1)?"+":" ");
     writeln();
    }
    }

     main

    {

       writeln("solution pools")

       thisOplModel.generate();
       cplex.solnpoolintensity=4;
       cplex.solnpoolcapacity=1000;
       cplex.solnpoolreplace=2;
       cplex.populatelim=20000;
       
       cplex.solve();
       var nsolns = cplex.solnPoolNsolns;
       writeln("n sol ",nsolns);
       
       var obj1=new Array(nsolns);
       var obj2=new Array(nsolns);;
       
       for(var s = 0; s < nsolns; s++)
       {
          thisOplModel.setPoolSolution(s);
          thisOplModel.postProcess();
          obj1[s]=thisOplModel.obj1.solutionValue;
          obj2[s]=thisOplModel.obj2.solutionValue;
          
       }
       
       writeln("not dominated solutions");
       
       for(var s = 0; s < nsolns; s++)
       for(var s2 = s+1; s2 < nsolns; s2++) if ((obj1[s]==obj1[s2]) && (obj2[s]==obj2[s2]))
       {
          obj1[s2]=thisOplModel.n+1;  
          obj2[s2]=thisOplModel.n+1;  
       }
       
       
       for(var s = 0; s < nsolns; s++)
       {
          var dominated=0;
          for(var s2 = 0; s2 < nsolns; s2++) if (s!=s2) if ((obj1[s2]<=obj1[s]) && (obj2[s2]<=obj2[s]))
                dominated=1;
          if (dominated==0)
          {
              thisOplModel.setPoolSolution(s);
              thisOplModel.nonDominatedSolutions.add(obj1[s],obj2[s]);
              thisOplModel.postProcess();  
          }
          
       }
       cplex.clearModel();
       writeln(thisOplModel.nonDominatedSolutions);
       
       var x2=new Array(thisOplModel.nonDominatedSolutions.size);
       var y2=new Array(thisOplModel.nonDominatedSolutions.size);
       for(var i=1;i<=thisOplModel.nonDominatedSolutions.size;i++)
       {
         x2[i]=Opl.item(thisOplModel.nonDominatedSolutions,i-1).obj1;   
         y2[i]=Opl.item(thisOplModel.nonDominatedSolutions,i-1).obj2;
       }
       var pythonpath="C:\\Users\\IBM_ADMIN\\AppData\\Local\\Programs\\Python\\Python36\\python.exe";
       var pythonfile="C:\\displayXY.py";
       displayXY(x2,y2,pythonpath,pythonfile,"pareto","obj1","obj2");
    }

    gives

     

    regards


    #DecisionOptimization


  • 3.  RE: Re: How to find non dominated solutions with multi objective (MCDA)

    Posted 3 days ago

    Recent example at https://dmcommunity.org/wp-content/uploads/2025/10/challenge2025oct.opl_.pdf



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------