returning gap between integer solution and best possible solution

1,659 views
Skip to first unread message

karel

unread,
Sep 16, 2013, 6:39:11 AM9/16/13
to pulp-or...@googlegroups.com
Hallo
 
I’m using PuLP with CBC solver. Is there any easy way how to return gap between integer solution and best possible solution (solution of linear relaxation), when the optimisation is finished on solution limit or time limit.  I would like  solve some  problems in several stages and play with parameters of CBC solver. I would like to use the gap as one of the criterias affecting cbc parameters.
Regards,
Karel

Stuart Mitchell

unread,
Oct 6, 2013, 6:23:44 PM10/6/13
to pulp-or...@googlegroups.com
Hmm I just had a look at the code and there doesn't seem to be this information in the '.sol' file from cbc.

you could use msg=1 and read the information from the cbc stdout manually :-(

Stu


--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/groups/opt_out.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

Jonas C Villumsen

unread,
May 19, 2015, 9:37:56 AM5/19/15
to pulp-or...@googlegroups.com
Hi Stuart,

I have the same question for CPLEX. I would like to retrieve the gap between the best integer and lower bound
returned by cplex when terminating due to timelimit. Do you think the best way is to read from stdout or is
there any other way? I understand that you may not have cplex, but I would very much appreciate your ideas.

Also, is it possible to get the status of the problem as "Feasible, but optimality not guaranteed", when the solver has
found a feasible solution but is terminating on a timelimit before proving optimality?

Thank you!

Jonas

Jonas C Villumsen

unread,
Jun 2, 2015, 5:26:43 AM6/2/15
to pulp-or...@googlegroups.com
Ok, I figured out how to reference the cplex solution object. For future reference (in case someone else wonders) it looks something like this:

solver = pulp.solvers.CPLEX_PY(timeLimit=3600)
#...
#solve problem
#...
gap = solver.solverModel.solution.MIP.get_mip_relative_gap()


Jonas

juan pineros

unread,
Feb 11, 2019, 8:12:35 PM2/11/19
to pulp-or-discuss
I'm also trying to have the Ceplex GAP using the pulp library, but I haven´t been able to. If someone could help me I would appreciate it I have python 3.6


My solution code is the following:

prob.solve(CPLEX())
print("Status:", LpStatus[prob.status])
print (value(prob.objective))


I tried with  "gap = solver.solverModel.solution.MIP.get_mip_relative_gap()" but gave on error.

Stuart Mitchell

unread,
Feb 11, 2019, 8:14:31 PM2/11/19
to pulp-or...@googlegroups.com
you should use the CPLEX_PY() solver which would mean you need to setup the cplex python library

Stu

Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.

juan pineros

unread,
Feb 16, 2019, 10:34:23 AM2/16/19
to pulp-or...@googlegroups.com
Thanks for youe help. But if I use  CPLEX_PY() in python 3 How I must write for have of GAP value ?.

I'm trying the same form wthet you but the window said has mistake.

gap = solver.solverModel.solution.MIP.get_mip_relative_gap() 

------------------------------------------------------------------------------------------------------------------------------------ 

 prob.solve(CPLEX_PY(timeLimit= 3600))
        
        solver = prob.solve(CPLEX_PY(timeLimit= 3600))
        
        gap = solver.solverModel.solution.MIP.get_mip_relative_gap()
        
        print("Status:", LpStatus[prob.status])


Mistake:


 gap = solver.solverModel.solution.MIP.get_mip_relative_gap()

AttributeError: 'int' object has no attribute 'solverModel'


Thanks in advance 

Juliano Correa

unread,
May 21, 2020, 6:37:41 AM5/21/20
to pulp-or-discuss
I have the same problem, How I can collect GAP using prob.solve(PULP_CBC_CM)?

I tried "prob.solverModel.solution.MIP.get_mip_relative_gap()" but return same error told Juan. 

Can you help me?
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or...@googlegroups.com.

To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at https://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.

--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or...@googlegroups.com.

Juliano Correa

unread,
May 21, 2020, 6:53:50 AM5/21/20
to pulp-or...@googlegroups.com
More information....

I need collect GAP information that it showed in log file (self.prob.solve(PULP_CBC_CMD(msg=1))). For exemple:  

Result - Stopped on time limit

Objective value:                2643725.00739212
Lower bound:                    681382.380
Gap:                            2.88
Enumerated nodes:               4993
Total iterations:               289152
Time (CPU seconds):             322.05
Time (Wallclock seconds):       322.05

How can I collect GAP information using methods (get/set)?

To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pulp-or-discuss/90d4f280-bef4-4919-b25e-632a9cbbc7cc%40googlegroups.com.


--
Juliano dos Santos Corrêa
Engenheiro de Controle e Automação

Franco Peschiera

unread,
May 22, 2020, 7:11:16 AM5/22/20
to pulp-or-discuss

Hello Juliano,

I think pulp does not return by defualt the gap. In the other question of this conversation the recommendation was to use the CPLEX_PY api because it uses the cplex library under the hood and it does return the gap. In your case you’re using CBC so not too much luck there.

If you manage to write the log into a file (also check this issue), you can use the orloge package to import the log file into python easily to check the gap info among other things.

cheers,

Franco

To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages