Managing data
Describes C++ classes to manage data.
Usually the data of 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 the array classes or set classes, such asIloNumSet,
provided by Concert Technology.
For example, objects of class IloNumArray
can be used to store numeric 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 features.
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
statements to make sure 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 data(env, 3, 1.0, 2.0, 3.0);
cout << data << endl;
produces the following output:
[1.0, 2.0, 3.0]
When you have finished using an array and want to reclaim
its memory, call the method end; for example, data.end. When the environment ends, all memory
of arrays belonging to the same environment is returned to the system
as well. Thus, in practice you do not need to call end
on an array (or any other Concert Technology object) just before calling 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: optimizing the diet problem in C++ takes advantage of this function and reads the problem data from a file.
Finally, Concert Technology provides the template class IloArray<X> to create array classes for your
own type X. This technique can be used to generate multidimensional
arrays. All the functions mentioned here are supported for IloArray classes except for input/output, which
depends on the input and output operator being defined for type X.