# Ordering constraints and joker values in Contraint Programming

 0 (The question focuses in particular on the solver Gecode, but I think it is general enough for CP). Given a vector of variables x[0], ..., x[n], all with domain {0,...,m} where m>>n, I would like to model the following constraint: (i < j) <=> (x[i] < x[j]) for all i,j = 0,..,n. I think this constraint must come up quite often, so there might be some well-known way to model it, or even a pre-made constraint among those offered by Gecode, but I am unable to find any suitable one here. (I cannot really understand the documentation of odered_nvector, which has a name that suggests something similar to what I am looking for, but it doesn't look like it does what I want, right?) If the value 0 in the domain is used as a joker value, and the constraint should be limited only to those variables which are not mapped to the joker value, what would be the best way to proceed? To be clear, the constraint would then be: (x[i] == 0) || (x[j] == 0) || ((i < j) <=> (x[i] < x[j])). (For example, for alldifferent there is the corresponding alldifferent_except_0.) Is there a standard way to generalise this constraint when the relationship is not necessarily "<"? For example, given a binary relation R on the set {0,...,n} and a binary relation S on {0,...,m}, is there a standard way to model the constraint ((i,j) in R) <=> ((x[i],x[j]) in S)? (In particular, if using Gecode, are there pre-made global constraints which are useful in this case?) asked 19 Feb '18, 12:40 Alberto Santini 1●1 accept rate: 0%

 0 For the first part, I think you want the strictly_increasing constraint (increasing if you use weak rather than strong inequalities). Sorry, can't answer the other two parts. answered 19 Feb '18, 15:50 Paul Rubin ♦♦ 14.6k●5●13 accept rate: 19% Thanks, Paul. You are right about the first part. I am having a hard time figuring out the other two parts. In general it seems to me that gecode has a lot of constraints, but poor support for mixing them and a weird API, while CPLEX CPO has few pre-built constraints, but combining them is as easy as using some overloaded operator (C++), plus their API is really straightforward. Both could use some better documentation and tutorials at a level beyond "Solve SEND+MORE=MONEY". If I manage to figure out any of them, I pledge to write one! :-) (20 Feb '18, 05:13) Alberto Santini
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags: