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

Getting incumbent solution in callback (highspy) #1856

Open
sertalpbilal opened this issue Jul 26, 2024 · 1 comment
Open

Getting incumbent solution in callback (highspy) #1856

sertalpbilal opened this issue Jul 26, 2024 · 1 comment
Assignees

Comments

@sertalpbilal
Copy link

sertalpbilal commented Jul 26, 2024

I am trying to read the incumbent solution in a user callback whenever an improvement is made in a MIP model. Here is what I have:

import highspy
import numpy as np

hscb = highspy.cb
h = highspy.Highs()
h.readModel('test.mps')

def myfunc(callback_type,
    message,
    data_out,
    data_in,
    user_callback_data):
    if callback_type == hscb.HighsCallbackType.kCallbackMipImprovingSolution:
        print(data_out.mip_solution)

h.setCallback(myfunc, None)
h.startCallback(hscb.HighsCallbackType.kCallbackMipImprovingSolution)
h.run()

It seems like the "mip_solution" is just a numpy array with dimension of 3.
I was trying to investigate why I can't get the solution and have seen this comment here

// XXX: This is clearly wrong, most likely we need to have the

So, I was wondering if there is either a way to get the current solution by fixing the issue in this file, or at least a way to export the current solution to a file.

Thanks
-Sertalp

@jajhall
Copy link
Member

jajhall commented Jul 26, 2024

This is related to #1857 raised by @Thell

Hello!

Consider the following options being passed to HiGHS:

"mip_improving_solution_save=on",
"mip_improving_solution_file=highs_improved_solution_{max_cost}_c.sol",

I can see that they are being accepted because a highs_improved_solution file was created and saved the first of the improved solutions.

That was ~6.5hrs ago. Since then over a dozen improvements have taken place yet none of them got saved. Much to my dismay because I just hit ctrl-c to copy something but my focus was on my terminal 🤦‍♂️ The real sad part was that I had realized this was taking place and the ctrl-c I used was to copy the options pasted above for this ticket. Anyhow, after getting down to a gap of 1.72% and 75.01% explored in those 6.5hrs I really would like to have seen the last incumbent.

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

No branches or pull requests

2 participants