Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Using date and time variable in OPL

    Posted 11/20/14 07:25 AM

    Originally posted by: TapanDey


    Hi,

    I have input data with Date (e.g. 2014-04-09) variable as well as with Time (e.g. 05:30:00 AM, 03:45:00 PM) variable in the excel file.

    Is there any facility in OPL to import the input data with date and time variable and then use in the mathematical model?

    Any link and/or document will help me a lot for the same.

    Appreciate your help.

    Thanks,

    Tapan Dey


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Using date and time variable in OPL

    Posted 11/20/14 07:58 AM

    Hi

    let me give you an example:

    string s="11/20/2014";
     execute
     
     {
      var a=new Date(s);
      writeln(a);
      writeln(a.getMonth());
     }

    which gives

    11/20/2014 00:00:00 000
    10

    If this object is not enough you may also use string functions

     

    They are listed in the doc at IDE and OPL > Optimization Programming Language (OPL) > Language Reference Manual > IBM ILOG Script for OPL > Built-in values and functions > IBM ILOG Script strings

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Using date and time variable in OPL

    Posted 04/01/16 05:11 AM

    Originally posted by: DavidGravot


     

    string s="02/23/2016";//expected format for OPL
     string test = "2016-02-23";//input format
     
     execute {
    
      var b = new Date(s);
      writeln(s,"\t#days\t",b.getDate(),"\t",b.getMonth(),"\t",b.getYear());
      
      var testYear = test.substring(0,4);
      var testMonth  = test.substring(5,7);
      var testDay = test.substring(8,10);
      var testMMDDYYYY = testMonth+"/"+testDay+"/"+testYear;
      var d = new Date(testMMDDYYYY);
      writeln(d,"\t#days\t",d.getDate(),"\t",d.getMonth(),"\t",d.getYear());
      //var r = d.getTime()/1000/86400;
      //var aday = Opl.ftoi(Opl.round(r)); 
     }
    

    Hi

    Are String format available ?

    Suppose I get a date with a format like 2016-02-23, standing for 23d February 2016

    I'm afraid I can't construct a date with this format, can I ?

    One workaround is to split the string in 3 pieces and rebuilt a date with the correct expected format

     

     

    David


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Using date and time variable in OPL

    Posted 04/01/16 05:41 AM

    Hi

    let me give you an example:

    string s="2016-02-23";
    string syear;
    string smonth;
    string sday;
    int day;
    int year;
    int month;


     execute
    {
    syear=s.substring(0,4);
    smonth= s.substring(5,7);
    sday=s.substring(8,10);
    year=parseInt(syear);
    month=parseInt(smonth);
    day=parseInt(sday);

    var d=new Date(year,month-1,day);
    writeln(d)
    }

    which gives

    02/23/2016 00:00:00 000

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Using date and time variable in OPL

    Posted 04/01/16 05:42 AM

    Originally posted by: DavidGravot


    thanks. We had the same workaround :-)


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Using date and time variable in OPL

    Posted 11/10/18 12:23 AM

    Originally posted by: BabyBone


    I have a similar question. 

    In the model file, the main routine, I have got some scripting runtime error. Does anyone know what was wrong? 

    Thanks. 

     

    Description    Resource    Path    Location    Type
    Scripting runtime error: cannot convert to an integer, "01/01/2010 00:00:00 000".    TAVRN_Model_1.mod    /TAVRN    118:0 /Users/vickymak/opl/TAVRN/TAVRN_Model_1.mod    OPL Problem Marke

     

        for (var k in opl.CourseSessions){

            k.startDate = new Date(k.startYear,k.startMonth-1,k.startDay);

            k.endDate = new Date(k.endYear,k.endMonth-1,k.endDay);    

        }

     

    the tuple defined was

      tuple courseSession {

         string    courseName

        int        idCourse

        int        idSession;

        int        startYear;

        int        startMonth;

        int        startDay;

        int        endYear;

        int        endMonth;

        int        endDay;

        int     startDate; //Sigma_ij, i = course, j = session 

        int        endDate; //Epsilon_ij, i = course, j = session 

        int        minSize;

        int        maxSize

        float    passrate;               

     };

     {courseSession} CourseSessions = ...;

     

    and the data look like this... 

     

     

     

     CourseSessions = {

    <SOURCE, 0    ,  1       , 2010,01,01, 2010,01,01,  0, 0,  0      ,   24     ,  1.0>, 

    <NEOC, 1    ,  1       , 2017,01,30, 2017,06,19,  0, 0,  1   ,  12  ,  0.9>, 

    <NEOC, 1    ,  2       , 2017,07,31, 2017,12,18,  0, 0,  1   ,  13  ,  0.9>, 

    <NEOC, 1    ,  3       , 2018,01,29, 2018,06,18,  0, 0,  1   ,   8  ,  0.9>,


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Using date and time variable in OPL

    Posted 11/12/18 02:46 AM

    Hi

     

    do not hesitate to start new threads for new questions.

    .mod

    tuple courseSession {

         string    courseName;

        int        idCourse;

        int        idSession;

        int        startYear;

        int        startMonth;

        int        startDay;

        int        endYear;

        int        endMonth;

        int        endDay;

        float     startDate; //Sigma_ij, i = course, j = session

        float        endDate; //Epsilon_ij, i = course, j = session

        int        minSize;

        int        maxSize;

        float    passrate;               

     };

     {courseSession} CourseSessions = ...;
     
     range r=0..card(CourseSessions)-1;
     
     execute
     {
      for (var i in r){
     
            k=Opl.item(CourseSessions,i)  
     

            k.startDate = new Date(k.startYear,k.startMonth-1,k.startDay);

            k.endDate = new Date(k.endYear,k.endMonth-1,k.endDay);    

        }  
     }

    .dat

    CourseSessions = {

    <SOURCE, 0    ,  1       , 2010,01,01, 2010,01,01,  0, 0,  0      ,   24     ,  1.0>,

    <NEOC, 1    ,  1       , 2017,01,30, 2017,06,19,  0, 0,  1   ,  12  ,  0.9>,

    <NEOC, 1    ,  2       , 2017,07,31, 2017,12,18,  0, 0,  1   ,  13  ,  0.9>,

    <NEOC, 1    ,  3       , 2018,01,29, 2018,06,18,  0, 0,  1   ,   8  ,  0.9>,
    };

    work fine

    regards

    https://www.linkedin.com/pulse/which-aml-gpl-do-you-use-call-cplex-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Using date and time variable in OPL

    Posted 11/19/18 06:19 PM

    Originally posted by: BabyBone


    Thanks, Alex. :-)


    #DecisionOptimization
    #OPLusingCPLEXOptimizer