Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Set integer variable in .dat file from .net

    Posted 08/18/10 10:58 AM

    Originally posted by: BKRORC


    Hello,

    I want to set a new value to integer variable in .dat file from .Net application

    here is varible declaration in .mod file
    int threshold= ...;

    here is varible declaration in .dat file
    threshold= 33 ;
    this is my test from .net C# line
    dataElements.GetElement("threshold").AsNumMap().Set("0", 15);
    but not works?

    How to correct assignment line?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Set integer variable in .dat file from .net

    Posted 08/18/10 11:32 AM

    Originally posted by: BKRORC


    Hello,

    Here is my whole .dat file
    threshold=55
    DBConnection db("oledb","SERKAN/pass/IsZekasi/temaoltp");
    Veri from DBRead(db,"Select * from tb_Personel where ID=?", threshold);

    ************
    I want to change "threshold=55" before model run from VS2008 C#
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Set integer variable in .dat file from .net

    Posted 08/18/10 12:31 PM

    Originally posted by: SystemAdmin


    Try something like: dataElements.SetElement(dataElements.MakeElement("threshold", 15));
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Set integer variable in .dat file from .net

    Posted 08/19/10 01:43 AM

    Originally posted by: BKRORC


    thank you
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Set integer variable in .dat file from .net

    Posted 08/23/10 11:04 AM

    Originally posted by: BKRORC


    Hello ,

    There is a problem.

    Set a variable but model did not use new value. where is the problem?
    Varible name is CozulecekOptionId

    here is my .dat file and .not .cs file

    /*********************************************
    * OPL 12.2 Data
    * Authors: Serkan Ulukaya, Yunus Emre Koc
    * Creation: Aug, 2010
    *********************************************/

    DBConnection db("oledb","SERKAN/denem/Planlama/temaoltp");

    CozulecekOptionId = 65;//model use 65 always.But I want to set a new varible and mosel use it.
    SKUBazindaVeriler from DBRead(db,"SELECT RTRIM(CAST(OptionRef AS CHAR(20))), RTRIM(CAST(UrunRef AS CHAR(10))), Sablon, MinKoliIci FROM Planlama.BA.tb_KisitUrun WHERE CozulecekOptionId = ? ")(CozulecekOptionId);
    OPTIONBazindaVeriler from DBRead(db,"SELECT RTRIM(CAST(OptionRef AS CHAR(20))), MaxBrutAsorti, MinBrutAsorti,RTRIM(CAST(CozulecekOptionID AS CHAR(20))) FROM Planlama.BA.tb_KisitOption WHERE CozulecekOptionId = ? ")(CozulecekOptionId);
    Sonuc to DBUpdate(db,"INSERT INTO Planlama.BA.tb_SonucAraTablo (OptionRef,UrunRef,KoliIciAdet,CozulecekOptionID) VALUES(?,?,?,?)");
    ********************************************
    *********************************************

    private int RunBedenAnaliz(int Id , string ILogFileName)
    {

    int status = 127;
    const string DATADIR = @"C:\ILOG\Asorti_2Basamakli\";
    try
    {

    OplFactory oplF = new OplFactory();

    OplErrorHandler handler = oplF.CreateOplErrorHandler(Console.Out);

    OplModelSource modelSource = oplF.CreateOplModelSource(DATADIR + ILogFileName+".mod");

    OplSettings settings = oplF.CreateOplSettings(handler);
    OplModelDefinition def = oplF.CreateOplModelDefinition(modelSource, settings);
    CP cplex = oplF.CreateCP();
    OplModel opl = oplF.CreateOplModel(def, cplex);
    OplDataSource dataSource = oplF.CreateOplDataSource(DATADIR + ILogFileName+".dat");
    opl.AddDataSource(dataSource);
    OplDataElements dataElements = opl.MakeDataElements();
    dataElements.SetElement(dataElements.MakeElement("CozulecekOptionId", Id));//I set varible here
    //dataElements.AddElement(dataElements.MakeElement("CozulecekOptionId", Id));

    opl.Generate();

    if (cplex.Solve())
    {
    opl.PostProcess();
    //opl.PrintSolution(Console.Out);
    status = 0;
    }
    else
    {
    status = 1;
    }
    oplF.End();
    }
    catch (IloException ex)
    {
    status = 2;
    }
    catch (System.Exception ex)
    {
    status = 3;

    }
    return status;
    }
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Set integer variable in .dat file from .net

    Posted 08/23/10 12:13 PM

    Originally posted by: SystemAdmin


    You didn't add your modified dataElements to OplModel instance. I believe what you want is:

    //opl.AddDataSource(dataSource);
    OplDataElements dataElements = opl.MakeDataElements();
    dataElements.SetElement(dataElements.MakeElement("CozulecekOptionId", Id));//I set varible here 
    opl.AddDataSource(dataElements);
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Set integer variable in .dat file from .net

    Posted 08/23/10 12:48 PM

    Originally posted by: SystemAdmin


    Actually,
    opl.AddDataSource(dataSource);
    
    should be un-commented. You might also need an opl.Generate() after that line and before creating your dataElements. Have a look at standard example: Cutstock_change.cs that illustrates usage of data elements.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Set integer variable in .dat file from .net

    Posted 08/23/10 02:02 PM

    Originally posted by: SystemAdmin


    I tried replicating what you are doing i.e., using data elements to modify data of a single opl model instance rather than getting data elements from one model and using with another model after some modification (usage illustrated in the examples).

    For your use case; the only thing that worked is something like below (note that you will need to comment out initialization of "CozulecekOptionId" in .dat file):

    OplModel opl = oplF.CreateOplModel(def, cplex);
     
    OplDataElements dataElements = oplF.CreateOplDataElements();
    dataElements.AddElement(dataElements.MakeElement("CozulecekOptionId", Id));
    opl.AddDataSource(dataElements);
     
    OplDataSource dataSource = oplF.CreateOplDataSource(DATADIR + ILogFileName+".dat");
    opl.AddDataSource(dataSource);
     
    opl.Generate();
    


    For running your model within OPL IDE, you could create another .dat file that initializes: "CozulecekOptionId". This .dat file would not be needed from C# code.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer