next

OPL function to return the successor to an element

Purpose

OPL function to return the successor to an element in a set.

type
int, float, string, or a tuple type

Syntax

int next({int},int)
int next({int},int,int)
float next({float},float)
float next({float},float,int)
string next({string},string)
string next({string},string,int)
<tuple type> next({<tuple type>},<tuple type>)
<tuple type> next({<tuple type>},<tuple type>,int)

Description

Returns the successor, or relative successor, to an element in a set if it exists and raises an error otherwise. This function can be generalized to give the i-th successor of a value (i<>0). For instance:

next(Days, “Monday”,3) returns Thursday.

You can use this function within IBM ILOG Script statements by specifying the OPL namespace:


( Opl.xxx() )
Note: This constraint cannot be used in a meta-constraint.

Example

{string} Days ={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

string n1 = next(Days,"Monday");
string n2 = next(Days,"Monday",3);

execute
{
 writeln("next(Days,\"Monday\") gives ",n1);  
 writeln("next(Days,\"Monday\",3) gives ",n2);  
}

Result

next(Days,"Monday") gives Tuesday
next(Days,"Monday",3) gives Thursday

Note that the call next(Days, “Sunday”) raises an error.