-1

I am trying to run a MINLP problem on Pyomo. I have formulated an objective function and one of my constraints is this:

model.c2 = Constraint(expr = sum(model.x[i] for i in blocks) <= 4560)

I want something like this:

x+y+z<=3 with x not equal to y not equal to z.

How do I write a constraint for this?

1 Answers1

1

The answer depends a bit on the details (are the variables integers, are all values in the domain covered). Here is a reference that may be of interest:

Williams, H. Paul and Yan, Hong (2001), Representations of the 'all_different' predicate of constraint satisfaction in integer programming, Informs Journal on Computing, 13 (2). 96-103.

Let's define the problem more precisely. Say we have n integers, x[i], that take unique values between 1,...,n. We can implement this as:

We can introduce binary variables

 y[i,k] = 1 if x[i]=k
          0 otherwise

With this, we can write:

 x[i] = sum(k, k*y[i,k])   (1)
 sum(k, y[i,k]) = 1   ∀i   (2)
 sum(i, y[i,k]) = 1   ∀k   (3)
 y[i,k] ∈ {0,1}  

where i ∈ {1,..,n} and k ∈ {1,..,n}.

If you have fewer variables than n, say i ∈ {1,..,m} with m < n, then we need to replace (3) by:

 sum(i, y[i,k]) ≤ 1   ∀k   (3a)
Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39