pulp icon indicating copy to clipboard operation
pulp copied to clipboard

Status of PuLP-HiGHS interface

Open jajhall opened this issue 2 years ago • 5 comments

In the context of https://github.com/ERGO-Code/HiGHS/issues/897 I saw #548 and had a look at https://github.com/coin-or/pulp/blob/master/pulp/apis/highs_api.py This is very out-of-date. If nothing else, HiGHS can now solve MIPs - rather well! I don't understand the details of highs_api.py, and the fact that an MPS file is generated makes me think that PuLP is using HiGHS via the command line interface. Is this correct? Naturally we'd be happy to coordinate with PuLP to update highs_api.py with respect to developments in HiGHS over the past couple of years.

jajhall avatar Jun 27 '22 10:06 jajhall

Yes, we use the command line interface of HiGHS in HiGHS_CMD. We should probably update the pip version soon. But as the comment in the other issues says, you can install it from github and it should work. Does it work?

pchtsp avatar Jun 27 '22 15:06 pchtsp

I'll try to get it working myself and update the HiGHS API to handle MIPs and QPs in the process

jajhall avatar Jun 27 '22 18:06 jajhall

Thanks to @berkorbay, I've installed PuLP and used it to call HiGHS for

https://coin-or.github.io/pulp/CaseStudies/a_blending_problem.html

and

https://coin-or.github.io/pulp/CaseStudies/a_sudoku_problem.html

I've made some modifications in my highs_api.py highs_api.py.txt and documented these, together with some observations, below.

Hopefully someone in PuLP-land (@samiit ?) can use these to update the current highs_api.py, as I don't know how to open a PR to make these changes.

As for QPs, if PuLP can model them and write them out as MPS files, then they can be solved with the current highs_api.py, although make sure that you don't try to ask HiGHS to solve a MIQP!

MIP

PuLP can call HiGHS to solve MIPs. I was confused by the following line in highs_api.py

warnings.warn("HiGHS_CMD cannot solve the relaxation of a problem")

I guess that this is executed if a user has indicated in PuLP that they want to solve the LP relaxation of a MIP. HiGHS can solve the relaxation by specifying

           cmd += " --solver simplex"

Bug in highs_api.py

Where the solution file commands are set up in highs_api.py

   write_lines = [
        "solution_file = %s\n" % tmpSol,
        "write_solution_to_file = true\n",
        "write_solution_style = 2\n",
    ]

there is an error. It should be

        "write_solution_style = -1\n",

because PuLP reads the old-style (deprecated) HiGHS raw solution file.

The new raw solution file is much easier to parse, so I recommend that highs_api.py is updated so that it reads the new format (because the old format will eventually be removed) - I don't have the Python skills to do this

Documentation of the new raw solution file (and earlier discussion of this issue) can be found in

https://github.com/ERGO-Code/HiGHS/issues/527

Maximization

With respect to

   if lp.sense == constants.LpMaximize:
          # we swap the objectives
          # because it does not handle maximization.
          warnings.warn(
              "HiGHS_CMD does not currently allow maximization, "
             "we will minimize the inverse of the objective function."
          )
          lp += -lp.objective

HiGHS can handle maximization. All PuLP has to do is communicate this via the

OBJSENSE MAX

section in the MPS file.

Name length limit

NB #554

jajhall avatar Jun 28 '22 11:06 jajhall

Thanks @jajhall , I am on it and will try to file a PR soon to PuLP with your solution!

Sam

samiit avatar Jun 28 '22 12:06 samiit

Hi Folks,

Some years ago I asked @stumitchell if I could maintain a copy of PuLP embedded into GridCal (a power systems software I develop) Those were the days when PuLP maintained python 2.7 compatibility and I wanted to modify PuLP's code for my own benefit, extending it and customizing it...

Well, I did add a HiGHS interface that works for me.

Cheers, Santiago

SanPen avatar Jul 28 '22 09:07 SanPen

I'm closing as HiGHS is already available under two APIs.

pchtsp avatar Jan 16 '24 16:01 pchtsp

Thanks!

jajhall avatar Jan 16 '24 16:01 jajhall