[gecode-users] Constraints on "wave" form
Mikael Zayenz Lagerkvist
zayenz at gmail.com
Thu Jun 12 11:50:35 CEST 2014
Richard Portelli skrev 12/06/14 10:32:
> Hello Christian,
> I would like to know if there is an easy way to implement a special
> constraint.
> I have an array with 10 numbers.
> My constraint would be : if you plot the array values in function of
> the index, you should have a wave aspect /\.
> For example with 10 numbers
>
> 1 3 5 9 11 7 6 5 4 2 0 (increasing then decreasing) There is no
> importance at witch index there is the inflexion point.
>
> Would you have an idea how to implement that in a clean way?
>
For reference, this is similar to the inflexion constraint
(http://www.emn.fr/z-info/sdemasse/gccat/Cinflexion.html) with the
number of inflexions set to 1 (assuming that valleys are also ok).
The simplest way in my opinion to model this constraint would be the
following.
Assume the sequence of numbers is called x and has n entries.
Define a new boolean array of variables y with n-1 values.
For each place i in y, add the constraint
y[i] = (x[i] < y[i])
(that is, reified ordering).
On the y variables, add the constraint regular(y, 1*0*)
The ordering constraint and the regular expression can be modified to
suit your particular needs.
Cheers,
Mikael
More information about the users
mailing list