For 2d data. (e.g. dist[i][j])

what is written in Notepad is (column i and row j)

[[ 2 , 3 , 5 , 2 , 9 ], 
[4 , 1 , 2 , 7 , 5 ],
...
[5 , 10 , 1 , 3 , 5 ]]

How about 3-dimension data like y[i][j][t]?

let's say for t=1, (column i and row j)

[[ 2 , 3 , 5 , 2 , 9 ],
[4 , 1 , 2 , 7 , 5 ],
...
[5 , 10 , 1 , 3 , 5 ]]

and t=2,

[[ 2 , 3 , 5 , 2 , 9 ],
[4 , 1 , 2 , 7 , 5 ],
...
[5 , 10 , 1 , 3 , 5 ]]

and so on.

while in the program, Is the following correct?

typedef IloArray<IloArray<IloNumVarArray>> IloNumVarArray3;  
IloNumArray3 y(env, T);
const char* filename1="yijt result.txt";
if(argc>=2)
    filename1=argv[1];
ifstream file3(filename1);
if(!file3) {
    cerr << "No such file: " << filename1 << endl;
    throw(-1);
}
for(int t=1; t<=T; t++)
    for(int c1=0; c1<=N; c1++)
        for(int c2=0; c2<=N; c2++)
        file3>>y;
file3.close();

Thanks!

asked 15 Apr '15, 01:26

dickylim's gravatar image

dickylim
93
accept rate: 0%

edited 15 Apr '15, 04:21

fbahr's gravatar image

fbahr ♦
4.6k716


First of all, you should not use an IloNumVarArray to store data - it's for variables.

Secondly, you need to initialize the second level IloArrays as well as the IloNumArrays:

typedef IloArray'<'IloArray'<'IloNumArray>> IloNumArray3;  // Changed IloNumVarArray to IloNumArray
IloNumArray3 y(env);
double anyNum; // Added a double to store the data
const char* filename1="yijt result.txt";
if(argc>=2)
    filename1=argv[1];
ifstream file3(filename1);
if(!file3) {
    cerr << "No such file: " << filename1 << endl;
    throw(-1);
}
for(int t=1; t<=T; t++){
    y.add(IloArray(env); // Add an IloArray to the IloNumArray3
    for(int c1=0; c1<=N; c1++){
        y[t].add(IloNumArray(env)); // Add an IloNumArray to the t'th entry in the IloNumArray3
        for(int c2=0; c2<=N; c2++){
            if(file3>>anyNum); // Check if the stream is good
            else throw(42);
            y[t][c2].add(anyNum); // Add the numbers to the IloNumArray
        }
    }
}
file3.close();

I must admit I have not tested it, but it looks like something that would work.

link

answered 15 Apr '15, 05:19

Sune's gravatar image

Sune
958413
accept rate: 20%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×191
×30
×21

Asked: 15 Apr '15, 01:26

Seen: 1,907 times

Last updated: 15 Apr '15, 05:19

OR-Exchange! Your site for questions, answers, and announcements about operations research.