Usually the data describing an optimization problem must be collected before or during the creation of the Concert Technology representation of the model. Though in principle modeling does not depend on how the data is generated and represented, this task may be facilitated by using the array or set classes provided by Concert Technology.
For example, objects of class IloNumArray can be used to store numerical data in arrays. Elements of the class IloNumArray can be accessed like elements of standard C++ arrays, but the class also offers a wealth of additional functions. For example, Concert Technology arrays are extensible; in other words they transparently adapt to the required size when new elements are added using the method add(). Conversely, elements can be removed from anywhere in the array with the method remove(). Concert Technology arrays also provide debugging support when compiled in debug mode by using assert to ensure that no element beyond the array bounds is accessed. Input and output operators (that is, operator << and operator >>) are provided for arrays. For example, the code:
IloNumArray
add()
remove()
assert
operator <<
operator >>)
IloNumArray data(env, 3, 1.0, 2.0, 3.0); cout << data << endl;
produces the following output:
[1.0, 2.0, 3.0]
When you are done using an array and want to reclaim its memory, call method end(), for example, data.end(). However, when ending the environment, all memory of arrays belonging to the same environment is returned to the system as well. Thus, in practice you do not call end() on an array (or any other Concert Technology object) just before calling env.end().
end()
data.end()
env.end()
The constructor for arrays specifies that an array of size 3 with elements 1.0, 2.0, and 3.0 is constructed. This output format can be read back in with, for example:
cin >> data;
The example at the end of this chapter takes advantage of this function and reads the problem data from a file.
Finally, we want to point out that Concert Technology provides the template class IloArray<X> to create array classes for your own type X. This can be used to generate multidimensional arrays. All the functions described above are supported for IloArray classes except for input/output, which depends on the input and output operator being defined for type X.
IloArray<X>
IloArray