pulp icon indicating copy to clipboard operation
pulp copied to clipboard

If a duplicate variable name is used the error message is unhelpful

Open khalida opened this issue 4 years ago • 1 comments
trafficstars

Describe the new feature

More helpful error message when duplicate variable names used within PuLP model.

Additional info

Is your feature request related to an issue?

No. Below is a minimum-broken-example - here the duplicate name error is obvious but I've seen quite a few users with this problem burried within their model asking questions on SO:

from pulp import *
x = LpVariable('x', 0, 1)
y = LpVariable('x', 0, 1)

mdl = LpProblem('broken_eg', LpMinimize)
mdl += lpSum(x + y) # Objective
mdl.solve()

This returns error as follows (at least for me on Windows 10, Python 3.7.3)

pulp.apis.core.PulpSolverError: Pulp: Error while executing C:\Users\...\Python37\lib\site-packages\pulp\apis\..\solverdir\cbc\win\64\cbc.exe

Which isn't very useful for debugging.

Does this feature exist in another product or project?

Not that I'm aware of. I'd be happy to dig into the source and have a go at making a more user-friendly error message if there's some agreement it'd be useful.

khalida avatar Jan 25 '21 23:01 khalida

Thanks! There's two things:

  1. Users should be able to create variables with duplicated names (at least that's was the design decision).
  2. 100% agree they should be better notified.

In fact, I thought this was handled better. There are already functions that detect duplicates before writing an LP (or a MPS I'm not sure).I just checked the source code and, in theory, we rename the variable names before creating the mps that is fed to cbc. There's probably a bug there.

If you want to check it, that's great!

Some places to look are: pulp/apis/coin_api.py => solve_CBC method pulp/pulp.py => writeMPS and checkDuplicateVars methods

Franco

pchtsp avatar Jan 26 '21 00:01 pchtsp