Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  .NET API Simple question - multi-dimensional array

    Posted 03/18/08 05:35 PM

    Originally posted by: SystemAdmin


    [jasonhe said:]

    I could find how to do this:

    In .NET environment, I am using the following:

                OplFactory oplF = new OplFactory();
                OplErrorHandler errHandler = oplF.CreateOplErrorHandler(Console.Out);
                OplFactory.DebugMode = true;
                Cplex cplex = oplF.CreateCplex();
               
                string getmodel = mdl; (Passed from caller)
                string getdata = dat; (Passed from caller)

                OplModelSource modelSource = oplF.CreateOplModelSource(getmodel);
                OplSettings settings = oplF.CreateOplSettings(errHandler);
                OplModelDefinition def = oplF.CreateOplModelDefinition(modelSource, settings);
                OplModel opl = oplF.CreateOplModel(def, cplex);
                OplDataSource dataSource = oplF.CreateOplDataSource(getdata);
                opl.AddDataSource(dataSource);
                opl.Generate();

                //Mapping the OPL variables
                IIntVarMap x = opl.GetElement("x").AsIntVarMap();

    In the outer OPL model, I have defined variable "x" as following:
                int i = ...;
                int j = ...;
                int k = ...;

                range r_i = 1..i;
                range r_j = 1..j;
                range r_k = 1..k;

                dvar int+ x[r_i,r_j,r_k];

    If cplex.Solve, then how can I call x[i,j,k] in the .NET environment?

    Thanks for your help.

    Jason

               

               



    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: .NET API Simple question - multi-dimensional array

    Posted 03/19/08 12:50 AM

    Originally posted by: SystemAdmin


    [dgravot@noos.fr said:]

    Sorry to write the answer with JAVA cause I'm not that familiar with the .NET API, but I assume the logic is exactly the same.

    You can access to your decision variable both as a IntVarMap in the model and as a IloNumMap once the solution has been computed

    Here in my model, I have declared :
    dvar float+ Commande[Items,Periodes];

    Now, in my JAVA code, I wrote the following to access all solution values for these variables as following :

    IloNumMap commandesMap = opl.getElement("Commande").asNumMap();
           
            for(int i=0;i<params.getNbItems();i++)<br />        {
            for(int t=0;t<params.getNbPeriodes();t++)<br />        {
            double solValue  = commandesMap.getSub(i+1).get(t+1);
                      log.info("at item "+(i+1)+" periode "+(t+1)+" : "+solValue  );     
                    }
            }

    Hope this helps


    David Gravot
    ROSTUDEL - Recherche Opérationnelle, Etudes et Développement
    57, rue d'Alleray 75015 Paris - France
    (33)1 45 31 19 06 / (33) 6 13 46 07 63
    dgravot@rostudel.com
    www.rostudel.com 






    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: .NET API Simple question - multi-dimensional array

    Posted 03/20/08 07:23 PM

    Originally posted by: SystemAdmin


    [jasonhe said:]

    Thank you very much for your reply.

    Following your code, I believe it will be much similar in .NET. But one more thing, since I have 3 dimensions, in the loop, you are using indices "i" and "t" and your script is:

    double solValue  = commandesMap.getSub(i+1).get(t+1);

    In my case should it be

    x.getSub(i+1).get(j+1).get(k+1) or x.getSub(i+1).getSub(j+1).get(k+1)

    Merci beaucoup

    [quote author=dgravot@noos.fr link=topic=197.msg507#msg507 date=1205873374]
    Sorry to write the answer with JAVA cause I'm not that familiar with the .NET API, but I assume the logic is exactly the same.

    You can access to your decision variable both as a IntVarMap in the model and as a IloNumMap once the solution has been computed

    Here in my model, I have declared :
    dvar float+ Commande[Items,Periodes];

    Now, in my JAVA code, I wrote the following to access all solution values for these variables as following :

    IloNumMap commandesMap = opl.getElement("Commande").asNumMap();
           
            for(int i=0;i<params.getNbItems();i++)<br />        {
            for(int t=0;t<params.getNbPeriodes();t++)<br />        {
            double solValue  = commandesMap.getSub(i+1).get(t+1);
                      log.info("at item "+(i+1)+" periode "+(t+1)+" : "+solValue  );     
                    }
            }

    Hope this helps


    David Gravot
    ROSTUDEL - Recherche Opérationnelle, Etudes et Développement
    57, rue d'Alleray 75015 Paris - France
    (33)1 45 31 19 06 / (33) 6 13 46 07 63
    dgravot@rostudel.com
    www.rostudel.com 







    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: .NET API Simple question - multi-dimensional array

    Posted 03/23/08 03:56 PM

    Originally posted by: SystemAdmin


    [dgravot@noos.fr said:]

    x.getSub(i+1).getSub(j+1).get(k+1)

    In the doc of C++ API or JAVA one (unfortunately, the doc for .NET IIntMap is not as detailed), you will find that getSub "... function returns the submap index from the map. The invoking map should have more than one dimension" whereas get "... function returns the element idx from the map. The invoking map should be of one dimension only."

    David Gravot
    ROSTUDEL - Operations Research
    57, rue d'Alleray 75015 Paris - France
    (33)1 45 31 19 06 / (33) 6 13 46 07 63
    dgravot@rostudel.com
    www.rostudel.com 
    #DecisionOptimization
    #OPLusingCPLEXOptimizer