prev
OPL function to return the predecessor to an element
Purpose
OPL function to return the predecessor to an element in a set. For the scheduling function on interval variables, see prev (scheduling).
type |
---|
int, float, string, or a tuple type |
Syntax
int prev({int},int) int prev({int},int,int) float prev({float},float) float prev({float},float,int) string prev({string},string) string prev({string},string,int) <tuple type> prev({<tuple type>},<tuple type>) <tuple type> prev({<tuple type>},<tuple type>,int)
Description
Returns
the predecessor, or relative predecessor, to an element in a set if
it exists and raises an error otherwise. This function can be generalized
to give the i-th predecessor of a value (i<>0
).
For instance:
prev(Days, “Thursday”,3)
returns Monday
.
You can use this function within IBM ILOG Script statements by specifying the OPL namespace:
( Opl.xxx() )
Example
{string} Days ={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
string p1 = prev(Days,"Tuesday");
string p2 = prev(Days,"Thursday",3);
execute
{
writeln("prev(Days,\"Tuesday\") gives ",p1);
writeln("prev(Days,\"Thursday\",3) gives ",p2);
}
Result
prev(Days,"Tuesday") gives Monday
prev(Days,"Thursday",3) gives Monday
Note
that prev(Days, “Monday”)
raises an error.