Originally posted by: SystemAdmin
Hello,
Could you be more precise about what you want to do.
> I want declare a variable with this indices 1..5 U 7..16 U 26 U 29..33
> I want use this variable with another variable in inverse function in CP
Which function do you want to inverse?
The one that maps some index of the possible values (21 values => index in [1..21]) to the values themselves (1..5 U 7..16 U 26 U 29..33) ?
You can do that with a constraint
x==ARRAY[y] where x is a variable describing the value and y an index variable.
using CP;
{
int
} domain = union(v in 1..5)
{v
} union union(v in 7..16)
{v
} union union(v in 26..26)
{v
} union union(v in 29..33)
{v
};
int n = card(domain);
int vmin = min(v in domain) v;
int vmax = max(v in domain) v;
int val[i in 1..n] = item(domain, i-1); dvar
int x in vmin..vmax;
// Value dvar
int y in 1..n;
// Index constraints
{ x in domain; x == val[y];
};
Philippe
#DecisionOptimization#OPLusingCPOptimizer