| Overview | Group | Tree | Graph | Deprecated | Index | Concepts |
| Arrays in an environment |
| Extensible arrays |
| Arrays as handles |
| Indexing arrays |
| Copying arrays |
| Programming hint: Using arrays efficiently |
For most basic classes (such as IloIntVar or IloConstraint)
in Concert Technology, there is also a corresponding class of arrays where the elements
of the array are instances of that basic class. For example, elements of an instance of
IloConstraintArray are instances of the class
IloConstraint.
Concert Technology arrays are extensible. That is, you can add elements to the array dynamically. You add
elements by means of the add member function of the array class.
You can also remove elements from an array by means of its remove member function.
References to elements of an array change whenever an element is added to or removed from the array. For example,
IloNumArray x; IloNum *x1ptr = &(x[1]); x.add(1.3); *x1ptr no longer valid!
Like other Concert Technology objects, arrays are implemented by means of two classes: a handle class corresponding to an implementation class. An object of the handle class contains a data member (the handle pointer) that points to an object (its implementation object) of the corresponding implementation class. As a Concert Technology user, you will be working primarily with handles.
CPLEX respects the C++ programming convention that enumerates the indices of an array from 0 (zero). For example, the indices of the MIP starts added to a model start at 0 (zero). Likewise, the indices of the filters associated with a model start at 0 (zero).
Many handles may point to the same implementation object. This principle holds true for arrays as well as other handle classes in Concert Technology. When you want to create more than one handle for the same implementation object, you should use either the copy constructor or the assignment operator of the array class. For example,
IloNumArray array(env); // creates a handle pointing to new impl
IloNumArray array1(array); // creates a handle pointing to same impl
IloNumArray array2; // creates an empty handle
array2 = array; // sets impl of handle array2 to impl of arrayTo take another example, the following lines add all elements of
a1 to a2, essentially copying the array.
IloNumArray a1; IloNumArray a2; a2.clear(); a2.add(a1);
If your application only reads an array (that is, if your function does not modify an element of the
array), then we recommend that you pass the array to your function as a const parameter.
This practice forces Concert Technology to access the const conversion of the index operator
(that is, operator[]), which is faster.