Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulp print wrong objective value #803

Open
zxt5 opened this issue Feb 22, 2025 · 4 comments
Open

pulp print wrong objective value #803

zxt5 opened this issue Feb 22, 2025 · 4 comments

Comments

@zxt5
Copy link

zxt5 commented Feb 22, 2025

I am using pulp calling PULP_CBC_CMD to solve this problem seed.mps.txt. It seems the solver gets the correct objective but pulp return the wrong value. This doesn't happen in other cases I have tried.
The code I am using:

  vars, prob = LpProblem.fromMPS("seed.mps")
  solver = PULP_CBC_CMD()
  prob.solve(solver=solver)
  objective = value(prob.objective)
  print("Objective:", objective)

The output:

Welcome to the CBC MILP Solver 
Version: 2.10.3 
Build Date: Dec 15 2019 

...

At line 2 NAME          MODEL
At line 3 ROWS
At line 296 COLUMNS
At line 4689 RHS
At line 4981 BOUNDS
At line 5012 ENDATA
Problem MODEL has 291 rows, 15 columns and 4363 elements
Coin0008I MODEL read with 0 errors
Option for timeMode changed from cpu to elapsed
Continuous objective value is -47653.2 - 0.00 seconds
Cgl0004I processed model has 291 rows, 15 columns (7 integer (0 of which binary)) and 4363 elements
Cbc0012I Integer solution of -47286.631 found by DiveCoefficient after 0 iterations and 0 nodes (0.03 seconds)
Cbc0012I Integer solution of -47286.912 found by DiveCoefficient after 217 iterations and 0 nodes (0.19 seconds)
Cbc0031I 5 added rows had average density of 15
Cbc0013I At root node, 5 cuts changed objective from -47653.243 to -47610.265 in 100 passes
Cbc0014I Cut generator 0 (Probing) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.021 seconds - new frequency is -100
Cbc0014I Cut generator 1 (Gomory) - 241 row cuts average 15.0 elements, 0 column cuts (0 active)  in 0.012 seconds - new frequency is 1
Cbc0014I Cut generator 2 (Knapsack) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.008 seconds - new frequency is -100
Cbc0014I Cut generator 3 (Clique) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.000 seconds - new frequency is -100
Cbc0014I Cut generator 4 (MixedIntegerRounding2) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.021 seconds - new frequency is -100
Cbc0014I Cut generator 5 (FlowCover) - 0 row cuts average 0.0 elements, 0 column cuts (0 active)  in 0.030 seconds - new frequency is -100
Cbc0010I After 0 nodes, 1 on tree, -47286.912 best solution, best possible -47610.265 (0.20 seconds)
Cbc0012I Integer solution of -47431.131 found by DiveCoefficient after 230 iterations and 1 nodes (0.20 seconds)
Cbc0012I Integer solution of -47519.768 found by DiveCoefficient after 233 iterations and 2 nodes (0.21 seconds)
Cbc0012I Integer solution of -47539.757 found by DiveCoefficient after 266 iterations and 4 nodes (0.22 seconds)
Cbc0012I Integer solution of -47540.695 found by DiveCoefficient after 291 iterations and 9 nodes (0.23 seconds)
Cbc0016I Integer solution of -47576.217 found by strong branching after 418 iterations and 14 nodes (0.26 seconds)
Cbc0001I Search completed - best objective -47576.21726990087, took 430 iterations and 16 nodes (0.26 seconds)
Cbc0032I Strong branching done 86 times (234 iterations), fathomed 3 nodes and fixed 6 variables
Cbc0035I Maximum depth 4, 7 variables fixed on reduced cost
0  Obj -47653.243 Primal inf 2.4002514 (6) Dual inf 6.0303144e+10 (7)
7  Obj -47576.217 Primal inf 6.064645e-07 (1)
7  Obj -47576.217 Primal inf 6.064645e-07 (1)
Primal infeasible - objective value -47576.217
Cuts at root node changed objective from -47653.2 to -47610.3
Probing was tried 100 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.021 seconds)
Gomory was tried 155 times and created 367 cuts of which 0 were active after adding rounds of cuts (0.017 seconds)
Knapsack was tried 100 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.008 seconds)
Clique was tried 100 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 100 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.021 seconds)
FlowCover was tried 100 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.030 seconds)
TwoMirCuts was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.001 seconds)
ZeroHalf was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
0  Obj -106434.51 Primal inf 39488.533 (119) Dual inf 3361.2645 (3)
18  Obj -47576.217 Primal inf 1.3401913e-06 (1)
18  Obj -47914.51 Primal inf 1.3401913e-06 (1)
Primal infeasible - objective value -47914.51
Cgl0013I Postprocessed model is infeasible - possible tolerance issue - try without preprocessing
103 relaxed row infeasibilities - summing to 749784
103 relaxed row infeasibilities - summing to 749784
103 relaxed row infeasibilities - summing to 749784

Result - Optimal solution found

Objective value:                -47576.21726990
Enumerated nodes:               16
Total iterations:               430
Time (CPU seconds):             0.23
Time (Wallclock seconds):       0.27

Option for printingOptions changed from normal to all
Total time (CPU seconds):       0.24   (Wallclock seconds):       0.28

Objective: 12715540.93236
@pchtsp
Copy link
Collaborator

pchtsp commented Feb 22, 2025

If you check the log on detail the problem is infeasible. Meaning there is no valid solution. I think.

@pchtsp
Copy link
Collaborator

pchtsp commented Feb 22, 2025

You probably have numeric instability. Try using less significant digits in your problem (less decimals in variables, constraints and objective)

@zxt5
Copy link
Author

zxt5 commented Feb 22, 2025

Sorry I didn't get it. I think pulp just reads the output of the solver and return the value to user. Since cbc (and other solvers such as gurobi) say there is an optimal solution of -47576.21.., I don't understand why pulp print 12715540.93236...
Sorry if I was wrong.

@pchtsp
Copy link
Collaborator

pchtsp commented Feb 22, 2025

Focus on the following lines in the log:

Primal infeasible - objective value -47914.51
Cgl0013I Postprocessed model is infeasible - possible tolerance issue - try without preprocessing

I suspect you have a numeric /tolerance issue in your model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants