Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  java iterator on bidimensional array

    Posted 06/05/13 03:22 AM

    Originally posted by: 4XFR_giorgio_galassi


    I 'm new to cplex so perphas my question could be banal for most .

    I'm able to call from java the solver (opall.jar ilog.cp.jar that are inside  ibm  ilog studio 12.4)  passing an external model and data and solve the problem.

    IloOplFactory.setDebugMode(false);
            IloOplFactory oplF = new IloOplFactory();
            IloOplErrorHandler errHandler = oplF.createOplErrorHandler(System.out);
             //IloOplModelSource  modelSource = oplF.createOplModelSource("Progetto_LOCALIZZAZIONE.mod");
             IloOplModelSource  modelSource = oplF.createOplModelSource("SingolaAzienda.mod");
            IloCplex cplex = oplF.createCplex();
            IloOplSettings settings = oplF.createOplSettings(errHandler);
            IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource, settings);
            IloOplModel opl = oplF.createOplModel(def, cplex);
     
            String inDataFile = "data_prototipo.dat";
            IloOplDataSource dataSource = oplF.createOplDataSource(inDataFile);
            opl.addDataSource(dataSource);
     
            opl.generate();
            opl.convertAllIntVars(); // converts integer bounds into LP compatible format
            if (cplex.solve()) {
            } else {
                System.out.println("Solution could not be achieved, probably insufficient memory or some other weird problem.");
            }
            

    My problem is that I don't know how to access a decision variable defined in "data_prototipo.dat" defined as follow :

    dvar float+ em_ch4_stoc_l[particelle][trattamenti];

    particelle = {
    <"Particella 1">
    };
    trattamenti = {
     <"Alternativa 0","",175000>
     <"Alternativa 1","",175000>
     <"Alternativa 2","",175000>
     
     };

     

    tuple Particella {
      key string nome; 
     };
     
     tuple Trattamento {
      key string nome;
      string modello; 
      float capacita_max;
     
     }   

     

    {Particella} particelle = ... ;
     {Trattamento} trattamenti = ... ;

     

    em_ch4_stoc_l is bidimensional array made of tuples but how to iterate on it ?

    I  have seen iterators.java but I don't  find solution

    The only thing that I have done is to catch the element :

     IloOplElement ch4 = opl.getElement("em_ch4_stoc_l");

    //get it as arrays of float

     IloNumVarMap ch4mappa = ch4.asNumVarMap();   

    //but when i do the following i have a the error:Type schema type expected for element "Particella".

     IloSymbolSet ids = opl.getElement("Particella").asSymbolSet();

    Thanks in advance


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: java iterator on bidimensional array

    Posted 07/04/13 05:36 AM

    Originally posted by: VincentBeraudier


    You have to get the indexers of em_ch4_stoc_l, which are particelle and trattamenti, not Particella.

    So you should do

    <code> IloTupleSet idx1 = opl.getElement("particelle").asTupleSet();

    IloTupleSet idx2 = opl.getElement("trattamenti").asTupleSet();

    </code>

    Then you will be able to iterate accurately on the var array.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer