coin-or / Cbc

COIN-OR Branch-and-Cut solver
Other
814 stars 116 forks source link

Inconsistent signs when maximizing #519

Open GeorgAnegg opened 2 years ago

GeorgAnegg commented 2 years ago

Describe the bug When maximizing, the presolve reports positive (intended) solution values, whereas the MIP optimization reports negative (reversed) values. This is (sometimes?) passed on to the ProgressLog from python-mip.

To Reproduce Take the first example from the python-mip documentation. The CBC output is below.

The faulty ProgressLog can be reproduced with

from mip import Model, xsum, maximize, BINARY, CBC
p = [10, 13, 18, 31, 7, 15]
w = [11, 15, 20, 35, 10, 33]
c, I = 47, range(len(w))

m = Model(solver_name=CBC)
m.store_search_progress_log = True

x = [m.add_var(var_type=BINARY) for i in I]

m.objective = maximize(xsum(p[i] * x[i] for i in I))

m += xsum(w[i]* x[i] for i in I) <= c

m.optimize()
print([(dual_bound, primal_bound) for _, (dual_bound, primal_bound) in m.search_progress_log.log])

This gives

[(42.17142857142857, 1.7976931348623157e+308),
(42.17142857142857, -1.7976931348623157e+308),
(-42.17142857142857, 28.0)]

(The primal bound of the first entry should be negative and the dual bound of the last entry should be positive.)

The CBC output is

Coin0506I Presolve 1 (0) rows, 6 (0) columns and 6 (0) elements
Clp1000I sum of infeasibilities 0 - average 0, 6 fixed columns
Coin0506I Presolve 0 (-1) rows, 0 (-6) columns and 0 (-6) elements
Clp0000I Optimal - objective value -0
Clp0000I Optimal - objective value -0
Coin0511I After Postsolve, objective 0, infeasibilities - dual 0 (0), primal 0 (0)
Clp0006I 0  Obj -0 Dual inf 165.0606 (6)
Clp0000I Optimal - objective value 42.171429
Clp0000I Optimal - objective value 42.171429
Clp0000I Optimal - objective value 42.171429
Clp0032I Optimal objective 42.17142857 - 0 iterations time 0.002, Idiot 0.00

Starting MIP optimization
Cgl0004I processed model has 1 rows, 6 columns (6 integer (6 of which binary)) and 6 elements
Coin3009W Conflict graph built in 0.000 seconds, density: 14.103%
Cgl0015I Clique Strengthening extended 0 cliques, 0 were dominated
Cbc0045I Nauty did not find any useful orbits in time 2.7e-05
Cbc0038I Initial state - 1 integers unsatisfied sum - 0.457143
Cbc0038I Solution found of -28
Cbc0038I Before mini branch and bound, 5 integers at bound fixed and 0 continuous
Cbc0038I Full problem 1 rows 6 columns, reduced to 0 rows 0 columns
Cbc0038I Mini branch and bound did not improve solution (0.00 seconds)
Cbc0038I Round again with cutoff of -30.3171
Cbc0038I Reduced cost fixing fixed 1 variables on major pass 2
Cbc0038I Pass   1: suminf.    0.07474 (1) obj. -30.3171 iterations 1
Cbc0038I Pass   2: suminf.    0.45714 (1) obj. -42.1714 iterations 1
Cbc0038I Pass   3: suminf.    0.07474 (1) obj. -30.3171 iterations 1
Cbc0038I Pass   4: suminf.    0.45714 (1) obj. -42.1714 iterations 1
Cbc0038I Pass   5: suminf.    0.34461 (1) obj. -30.3171 iterations 2
Cbc0038I Solution found of -41
Cbc0038I Before mini branch and bound, 4 integers at bound fixed and 0 continuous
Cbc0038I Full problem 1 rows 6 columns, reduced to 1 rows 2 columns
Cbc0038I Mini branch and bound did not improve solution (0.00 seconds)
Cbc0038I Round again with cutoff of -42.0342
Cbc0038I Reduced cost fixing fixed 5 variables on major pass 3
Cbc0038I After 0.00 seconds - Feasibility pump exiting with objective of -41 - took 0.00 seconds
Cbc0012I Integer solution of -41 found by feasibility pump after 0 iterations and 0 nodes (0.00 seconds)
Cbc0038I Full problem 1 rows 6 columns, reduced to 0 rows 0 columns
Cbc0001I Search completed - best objective -41, took 0 iterations and 0 nodes (0.00 seconds)

Desktop:

jjhforrest commented 2 years ago

A long time ago the messages might have been correct - BUT bugs kept creeping in for maximisation problems, so it was decided to flip the objective at the start of branch and bound and then back at end. It would be straightforward to fix the printing (well messages that go via the message handler), but is quite a bit of tedious work to fix stable and master. I would welcome input as to how important this is.

jjhforrest commented 2 years ago

I think I have fixed messages in master. Feedback is welcome. I will probably do stable early next week.

jjhforrest commented 2 years ago

Should be fixed in stable/1.10