Topic
  • 6 replies
  • Latest Post - ‏2015-04-06T08:13:29Z by KenanAghayev
SystemAdmin
SystemAdmin
1883 Posts

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
    1270 Posts

    Re: Read data from text file

    ‏2012-10-18T12:32:57Z  
    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

    Re: Read data from text file

    ‏2013-01-16T23:10:35Z  
    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
    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

    Re: Read data from text file

    ‏2013-01-16T23:11:35Z  
    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
    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

    Re: Read data from text file

    ‏2013-01-17T11:32:12Z  
    • Robop
    • ‏2013-01-16T23:11:35Z
    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?
    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

    Re: Read data from text file

    ‏2013-01-20T20:18:03Z  
    • davidoff
    • ‏2013-01-17T11:32:12Z
    Can you add square brackets to the dat file ?
    The following syntax works fine with your definition of
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">int D[1..2][1..3] = ...; </pre>

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">D=[ [10 10 10] [11 11 11] ]; </pre>

    David
    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
  • KenanAghayev
    KenanAghayev
    1 Post

    Re: Read data from text file

    ‏2015-04-06T08:13:29Z  
    • Robop
    • ‏2013-01-16T23:10:35Z
    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?

    Hi, I also have similar problem as indicated in

     

    https://www.ibm.com/developerworks/community/forums/html/topic?id=78002cd8-4692-4461-bc3a-619f073a638e&ps=25

    any idea?

    regards,