Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Variable access

    Posted 02/28/12 08:48 AM

    Originally posted by: Paul_Diaz


    Hi,

    I'm working on a project where I need to access decision variable values. They are represented as dvar int+ work[A][B][C], where A, B and C are range types.

    At the moment, I've written the following code that presents some errors.

    if (cplex.solve())  {
                        IloIntMap var = opl.getElement("works").asIntMap();
                        IloIntRange s1 = opl.getElement("A").asIntRange();
                        IloIntRange s2 = opl.getElement("B").asIntRange();
                        IloIntRange s3 = opl.getElement("C").asIntRange();
                        for (int i  = 1; i <= s1.getSize(); i++ )        {
                            IloIntMap sub = var.getSub(i);
                            for (int j = 1; j <= s2.getSize(); j++)      {
                                    sub = var.getSub(j);
                                    for (int k = 1; k <= s3.getSize(); k++)      {
                                            int bl = sub.get(k);
                                            System.out.println(bl);
                                    }
                            }
                        }
                    }
    


    The code presents errors. Can anyone help me with this final part?

    Thanks.

    Paul.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Variable access

    Posted 02/28/12 09:08 AM

    Originally posted by: SystemAdmin


    I would do something like:

    
    
    
    if (cplex.solve()) 
    { IloIntVarMap var = opl.getElement(
    "works").asIntVarMap(); IloIntRange s1 = opl.getElement(
    "A").asIntRange(); IloIntRange s2 = opl.getElement(
    "B").asIntRange(); IloIntRange s3 = opl.getElement(
    "C").asIntRange(); 
    
    for (
    
    int i = s1.getLB(); i <= s1.getUB(); i++ )       
    { 
    
    for (
    
    int j = s2.getLB(); j <= s2.getUB(); j++)       
    { 
    
    for (
    
    int k = s3.getLB(); k <= s3.getUB(); k++)       
    { IloIntVar x = var.getSub(i).getSub(j).get(k); 
    
    int bl = cplex.getValue(x); System.out.println(bl); 
    } 
    } 
    } 
    }
    


    or
    
    IloOplFactory oplF = 
    
    new IloOplFactory(); ... 
    
    if (cplex.solve())      
    { IloIntVarMap var = opl.getElement(
    "works").asIntVarMap(); IloIntRange s1 = opl.getElement(
    "A").asIntRange(); IloIntRange s2 = opl.getElement(
    "B").asIntRange(); IloIntRange s3 = opl.getElement(
    "C").asIntRange(); IloMapIndexArray indices = oplF.mapIndexArray(3); 
    
    for (
    
    int i = s1.getLB(); i <= s1.getUB(); i++ )     
    { indices[0] = i; 
    
    for (
    
    int j = s2.getLB(); j <= s2.getUB(); j++)      
    { indices[1] = j; 
    
    for (
    
    int k = s3.getLB(); k <= s3.getUB(); k++)      
    { indices[2] = k; IloIntVar x = var.getAt(indices); 
    
    int bl = cplex.getValue(x); System.out.println(bl); 
    } 
    } 
    } 
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Variable access

    Posted 02/28/12 10:25 AM

    Originally posted by: Paul_Diaz


    Hey Vincent, I tried what you've suggested, but I changed x type and commented one line. Look, what do you think? I think it's ok.

    if (cplex.solve())  {
                        IloIntMap var = opl.getElement("variavel").asIntMap();
                        IloIntRange s1 = opl.getElement("M").asIntRange();
                        IloIntRange s2 = opl.getElement("tamDeX").asIntRange();
                        IloIntRange s3 = opl.getElement("tamDeY").asIntRange();
                        for (int i = s1.getLB(); i <= s1.getUB(); i++ )  {
                            for (int j = s2.getLB(); j <= s2.getUB(); j++)       {
                                    for (int k = s3.getLB(); k <= s3.getUB(); k++)       {
                                                    int x = var.getSub(i).getSub(j).get(k);
                                                    //int bl = cplex.getValue(x);
                                                    System.out.println("variavel["+i+"]["+j+"]["+k+"] = " + x);
                                    }
                            }
                        }
                            result = opl.getCplex().getObjValue();
                    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer