Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
6 replies Latest Post - ‏2015-04-06T08:13:29Z by KenanAghayev
SystemAdmin
SystemAdmin
1883 Posts
ACCEPTED ANSWER

Pinned topic Read data from text file

‏2012-10-16T17:24:26Z |
Hello everyone.

I would like to read binary data from a txt file. I am using Cplex optimization studio 12.2.

I suppose I would need some script?

Could someone help me with this?

The file is formated like this:

1000000010010010 0000100010010010 0000100010010010 0000100010010010 0000100010010010 0010000010010010 0010010000010010 0010010000010010

0010010000010010 0100000100100010 0100000100000010 0100000100000010 0010000000001000 0010000000000001 0010000000000001 0010000000000001

0000100010010010 0100000010010010 0000100010010010 0000100010010010 0000100010010010 0010010000010010 0010001000010010 0010010000010010

0010010000010010 0100000100000010 0100000100010010 0100000100000010 0010000000000001 0010000000000100 0010000000000001 0010000000000001
0000100010010010 0000100010010010 0000100010010010 0001000010010010 0000100010010010 0010010000010010 0010010000010010 0010010000010010

0010010000010010 0100000100000010 0100000100000010 0100000100000010 0010000000000001 0010000000000001 0010000000000001 0010000000000001
... and so on

Thank you!

Bruno
Updated on 2013-01-20T20:18:03Z at 2013-01-20T20:18:03Z by Robop
  • AlexFleischer
    AlexFleischer
    1126 Posts
    ACCEPTED ANSWER

    Re: Read data from text file

    ‏2012-10-18T12:32:57Z  in response to SystemAdmin
    Hi,

    what you could do is adapt the example in

    opl\examples\opl_interfaces\java\externaldataread

    in order to read your data.

    Or you could use IloOplInputFile in the OPL scripting part in order to read your data

    regards
    • Robop
      Robop
      9 Posts
      ACCEPTED ANSWER

      Re: Read data from text file

      ‏2013-01-16T23:10:35Z  in response to AlexFleischer
      Hi, I have the same question.

      However with the IloOplInputFile I can only read the string, right?
      So if I have: int D 1..2 1..3
      and want to load it from data.txt, which is:
      10 10 10
      11 11 11

      I have to read each line with IloOplInputFile, split it by " " and then call "parseInt"? So there is no easier way?
    • Robop
      Robop
      9 Posts
      ACCEPTED ANSWER

      Re: Read data from text file

      ‏2013-01-16T23:11:35Z  in response to AlexFleischer
      Hi, I have the same question.

      However with the IloOplInputFile I can only read the string, right?
      So if I have: int D 1..2 1..3
      and want to load it from data.txt, which is:
      10 10 10
      11 11 11

      I have to read each line with IloOplInputFile, split it by " " and then call "parseInt"? So there is no easier way?
      • davidoff
        davidoff
        55 Posts
        ACCEPTED ANSWER

        Re: Read data from text file

        ‏2013-01-17T11:32:12Z  in response to Robop
        Can you add square brackets to the dat file ?
        The following syntax works fine with your definition of
        int D[1..2][1..3] = ...;
        


        D=[
                [10 10 10]
                [11 11 11]
                ];
        


        David
        Updated on 2014-03-26T05:51:08Z at 2014-03-26T05:51:08Z by iron-man
        • Robop
          Robop
          9 Posts
          ACCEPTED ANSWER

          Re: Read data from text file

          ‏2013-01-20T20:18:03Z  in response to davidoff
          Thanks David,

          you are absolutely right. It is one of the ways. My question was answered here
          https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14930978&#14930978