# How to input three-dimensional data into the concert technology CPLEX with C++

 0 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> 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 9●3 accept rate: 0% fbahr ♦ 4.6k●7●16

 1 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. answered 15 Apr '15, 05:19 Sune 958●4●13 accept rate: 20%
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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