Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  read from a file text

    Posted 12/20/17 09:42 AM

    Originally posted by: Rym


    Hi

     

    I would like to extract data from a text file. Suppose that i have .txt:

     

    5

    10

    12

    14

     

    Suppose that i would  like to fill the array CPU with the data from the text

     

    for (var i in CPU)

    {

    CPU[i]=  line by line from the text

    }

    In C language i did

    int =4;

    char cpus[n];

    int cpu[n];

    cur_posc=ic;
    fseek(fichierc, cur_posc,0);

    i=0;
    while(i<n)
    {
    fgets(cpus,1000,fichierc);
    cpu[i]=atoi(cpus);
    cur_posc = ftell(fichierc);
    i++;

    }
     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: read from a file text

    Posted 12/20/17 09:48 AM

    suppose you have your data in f.txt

    then in OPL

    execute {
       var f = new IloOplInputFile("f.txt");
       if (f.exists) {
         writeln("the file output.txt exists");
         var s;
         while (!f.eof) {
          s=f.readline();
          writeln(s);
         }
         f.close();
       } else {
         writeln("the file output.txt doesn't exist");
       }
    }

    will give

    the file output.txt exists
    5

    10

    12

    14

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: read from a file text

    Posted 12/20/17 10:25 AM

    Originally posted by: Rym


    It is ok for the extraction of file. But i want to generate for each "i", 1<i<=2; an array of 5 integers.

     

    For example my  f.txt

     

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    for i=1

    CPU=[1,2,3,4,5]

    for i =2

    CPU=[6,7,8,9,10]

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: read from a file text

    Posted 12/20/17 11:21 AM

    Then you could have a look at

    IloOplOutputFile

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: read from a file text

    Posted 12/20/17 12:36 PM

    Originally posted by: Rym


    I can't find a notions of cursor  and fseek function like in C language.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: read from a file text

    Posted 12/20/17 12:41 PM

    Hi

    if you do not find what you need within opl 

    and you feel c is easier for you

    then you could use IloOplExec 

    https://www.ibm.com/developerworks/community/forums/html/topic?id=4bef7847-9ac0-4402-bd3d-74eba89a03f8&ps=25

    to call your c program from opl

    regardd


    #DecisionOptimization
    #OPLusingCPLEXOptimizer