Thanks for the attention.

Yes, I already took a look at the mentioned file, however, the script discretizes the floating magnitudes, cf. the lines 217 to 221 of the mentioned file.

Obviously, I could do the same for my case, however I would like to know if it is possible to model a distance limit constraint (*salesman_distance_limit*) without the discretization, by using CPO. And, without creating variables for the arcs, i.e., keeping the variables number linear wrt the number of nodes.

Precisely, I am trying to express the following reasoning through CPO.

Note that, in the above code, whenever all the integer variables assume some integer value, there will be only one possible assignment of values for the floating variables (the incremental incurred distance at each node), and thus, the statement give at the 4th comment given in this thread, is respected.

Thanks for the attention, and BR.

Original Message:

Sent: Tue August 22, 2023 10:50 AM

From: Olivier Lhomme

Subject: If then CPO Java

Have a look at the Cvrptw.java example:

the total distance is simply a sum of terms like "distance[i][next[i]]", where "next" is the intExprArray passed to the subCircuit constraint.

Note the useful CP construct: the array distance[i] is indexed by the intExp, distance[i][next[i]]

If your question is about how to force each partial sum to be less than *salesman_distance_limit:*

just add a constraint in the loop that builds the sum to constrain the current partial sum.

(not needed if you have non-negative distances only)

------------------------------

Olivier Lhomme

Original Message:

Sent: Tue August 22, 2023 07:09 AM

From: Matheus Andrade

Subject: If then CPO Java

Thank you very much.

However, in my case the MTZ has also another purpose, it is being also used for delimiting the maximum spent time, specifically I am working with a max-profit TSP, So, when I state that if **next[i] = j** then **mtz[j] = mtz[i] + distance[i, j]**, I am aiming to also impose the constraint

**mtz[i] <= salesman_distance_limit, forall i**

Let me know case any additional clarificaion is required.

Thanks and regards.

------------------------------

Matheus Andrade

Original Message:

Sent: Tue August 22, 2023 06:49 AM

From: Olivier Lhomme

Subject: If then CPO Java

Hello,

it seems that you expect that in CP Optimizer Interval Variables are continuous variables, but they are a different kind of variables, typically used to modelize tasks in scheduling.

In CP, instead of using MTZ constraints as in MIP, one can use a subCircuit constraint: it has been introduced in the last release of CP Optimizer (see https://www.ibm.com/docs/en/icos/22.1.1?topic=2211-new-circuit-subcircuit-constraint) and an example of use is given in the release (for Java, see cpoptimizer/examples/src/java/Cvrptw.java)

------------------------------

Olivier Lhomme

Original Message:

Sent: Tue August 22, 2023 05:28 AM

From: Matheus Andrade

Subject: If then CPO Java

Thanks for saving my day once more!

So, if we impose the constraint (**q-start <= p + 5 < q-end**), the **q** would have multiple values as solutions, and based on the 4th comment given in this thread:

CP Optimizer can solve problems on integer decision variables **only**. Floatting points variables **are admitted but** they **must** behave as **an expression**. That is they **must be fixed to a value once all the integer variables are fixed**. They cannot be decision variables.

That is why I am forcing the fixing over **q**. For a more detailed description of my intentions, I am trying to model an MTZ constraint, so my end goal would be

if **next[i] = j** then **mtz[j] = mtz[i] + distance[i, j]**

Of course we could simply create a variable **x[i, j]** telling whether the arc between **i** and **j** exists, but I am trying to scape from this modeling in order to have a model with less variables.

Case you have any other insight in this regard, please, let me know.

Thanks and BR.

------------------------------

Matheus Andrade

Original Message:

Sent: Mon August 21, 2023 10:41 PM

From: Paul Rubin

Subject: If then CPO Java

If p is an integer and q is an interval, I don't think the statement p + 5 = q makes sense. Do you mean that p + 5 should be in the interval given by q (q-start <= p + 5 < q-end)?

------------------------------

Paul Rubin

Professor Emeritus

Michigan State University

Original Message:

Sent: Mon August 21, 2023 04:16 PM

From: Matheus Andrade

Subject: If then CPO Java

Hello everyone.

I would like to know how to express the sentence if x = 10 then p + 5 = q. However, I am struggling to accomplish this, specifically, I do not know how to express p - q in Java. Below follows my code:

`import ilog.cp.*;import ilog.concert.*;public class Color { public static void main(String[] args) { try { IloCP cp = new IloCP(); IloIntVar x = cp.intVar(10, 10); IloIntVar p = cp.intVar(0, 10); IloIntervalVar q = cp.intervalVar(0, 10); IloConstraint eq = cp.eq(x, 10); IloNumExpr ex = p - q; ??????????????????? IloConstraint eq1 = cp.eq(ex, -5); IloConstraint ifThen = cp.ifThen(eq, eq1); cp.add(ifThen); if (cp.solve()) { System.out.println("Solved"); } else System.out.println("Error"); } catch (IloException e) { System.err.println("Error " + e); } }}`

Thanks and regards.

------------------------------

Matheus Andrade

------------------------------