Initializing help system before first use

exists

exists


Purpose
Check if a given entry in a dynamic array has been created.
Synopsis
function exists(x):boolean
Argument
Array reference ( e.g. t(1))
Return value
true if the entry exists, false otherwise.
Example
The following, a dynamic array of decision variables only has its even elements created, which is checked by displaying the existing variables:
declarations
 S=1..8
 x: dynamic array(S) of mpvar
end-declarations

forall(i in S| not isodd(i)) create(x(i))
forall(i in S| exists(x(i)))
 writeln("x(", i, ") exists")
Further information
1. If an array is declared dynamic its elements are not created at its declaration. This function indicates if a given element has been created.
2. Under certain conditions, the exists function call is optimized by the compiler when used for filtering an aggregate operator: the loop is only performed for the existing entries instead of enumerating all possible tuples of indices for finding the relevant ones.
Related topics