Opened 9 years ago

# Fix chaining of MILP constraints — at Version 21

Reported by: Owned by: ncohen ncohen major sage-7.2 linear programming vbraun, dimpase, mkoeppe, vdelecroix, tscrim Jeroen Demeyer N/A u/jdemeyer/milp_constraints_do_no_deal_with_python_ints_properly f41c195c520c10eede129873dd047fd6bc85ba95 #20478

```sage: p = MixedIntegerLinearProgram()
sage: b = p.new_variable()
sage: int(1) <= b[0] <= int(2)
x_0 <= 2
```
```sage: p = MixedIntegerLinearProgram()
sage: b = p.new_variable()
sage: float(0) <= b[0] <= int(1) <= b[1] <= float(2)
1 <= x_1 <= 2
```
```sage: p = MixedIntegerLinearProgram()
sage: b = p.new_variable()
sage: b[0] <= 555*b[1] >= 2
2 <= x_0 <= 555*x_1
```

This can never work due to the way Python handles chained comparisons:

```sage: p = MixedIntegerLinearProgram()
sage: b = p.new_variable()
sage: b[0] <= 3 <= 4
True
```

### comment:1 Changed 9 years ago by dimpase

`In a script` - do you mean a Python script, not Sage script, right?

### comment:2 follow-up: ↓ 3 Changed 9 years ago by ncohen

Well, in any script that does not wrap integers with `Integer()`. So a .py that you load with `%runfile` is ok !

Nathann

### comment:3 in reply to: ↑ 2 Changed 9 years ago by dimpase

Well, in any script that does not wrap integers with `Integer()`. So a .py that you load with `%runfile` is ok !

Nathann

and it's not only `int`, but `float`, too, that gives this problem.

### comment:4 Changed 8 years ago by jdemeyer

• Milestone changed from sage-5.11 to sage-5.12

### comment:5 Changed 8 years ago by vbraun_spam

• Milestone changed from sage-6.1 to sage-6.2

### comment:6 Changed 8 years ago by vbraun_spam

• Milestone changed from sage-6.2 to sage-6.3

### comment:7 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.3 to sage-6.4

### comment:8 Changed 6 years ago by jdemeyer

• Description modified (diff)
• Milestone changed from sage-6.4 to sage-7.2
• Summary changed from MILP constraints are silently misunderstood to MILP constraints do no deal with Python ints properly

### comment:9 Changed 6 years ago by jdemeyer

• Description modified (diff)

### comment:10 Changed 6 years ago by jdemeyer

I'm investigating this.

### comment:11 Changed 6 years ago by jdemeyer

• Description modified (diff)
• Summary changed from MILP constraints do no deal with Python ints properly to MILP constraints do no deal with Python types properly

### comment:12 Changed 6 years ago by jdemeyer

• Authors set to Jeroen Demeyer

### comment:13 Changed 6 years ago by jdemeyer

• Branch set to u/jdemeyer/milp_constraints_do_no_deal_with_python_ints_properly

### comment:14 Changed 6 years ago by jdemeyer

• Commit set to ba7613b12a717f7ca72137d9c91d7edca5f6cbbb
• Status changed from new to needs_review

New commits:

 ​ba7613b `Fix chained inequalities with non-Sage types`

### comment:15 Changed 6 years ago by dimpase

New commits:

 ​ba7613b `Fix chained inequalities with non-Sage types`

### comment:16 Changed 6 years ago by mkoeppe

• Status changed from needs_review to needs_work

It's not completely fixed. Example:

```sage: p = MixedIntegerLinearProgram()
sage: b = p.new_variable()
sage: float(0) <= b[0] <= int(1) <= b[1] <= float(2)
1 <= x_1 <= 2
```
Last edited 6 years ago by jdemeyer (previous) (diff)

### comment:17 Changed 6 years ago by jdemeyer

• Description modified (diff)
• Summary changed from MILP constraints do no deal with Python types properly to Fix complicated MILP constraints

Allright, let's fix everything on this ticket...

### comment:18 Changed 6 years ago by jdemeyer

• Dependencies set to #20478

### comment:19 Changed 6 years ago by git

• Commit changed from ba7613b12a717f7ca72137d9c91d7edca5f6cbbb to f41c195c520c10eede129873dd047fd6bc85ba95

Branch pushed to git repo; I updated commit sha1. New commits:

 ​f41c195 `14540 WIP`

### comment:20 Changed 6 years ago by jdemeyer

• Summary changed from Fix complicated MILP constraints to Fix chaining of MILP constraints

### comment:21 Changed 6 years ago by jdemeyer

• Description modified (diff)
Note: See TracTickets for help on using tickets.