question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with ConstrsGenerator

See original GitHub issue

Hi,

I’m trying to implement lazy constraint generation by extending the ConstrsGenerator class. I’ve been following the docs here https://python-mip.readthedocs.io/en/latest/custom.html and the example here https://github.com/coin-or/python-mip/blob/master/examples/queens-lazy.py, but I can’t seem to get it to work.

I have this small toy example that is failing and I’m not sure why.

import mip

class DelayedConstraintGenerator(mip.ConstrsGenerator):
    def generate_constrs(self, model):
        print("generating_constraints")
        for v in model.vars:
            print(v, v.x)
            model += v >= 5

m = mip.Model()

x = m.add_var('x', var_type=mip.INTEGER)
y = m.add_var('y', var_type=mip.INTEGER)

m += x + y, "objective"
m += x + y <= 10

m.lazy_constrs_generator = DelayedConstraintGenerator()
status = m.optimize()

print(status)
for v in m.vars:
    print(v, v.x)

Output from the example is:

generating_constraints
x 0.0
y 0.0
generating_constraints
x 0.0
y 0.0
OptimizationStatus.INFEASIBLE
x None
y None

I’m on Python-MIP 1.6.2 and Python 3.6.9.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:30 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
h-g-scommented, Dec 17, 2019

You’re welcome ! Thank @stefanhannie and @jooyous for the detailed bug report.

1reaction
h-g-scommented, Dec 16, 2019

hi @jooyous and @stefanhannie , already fixed in master thanks to @jjhforrest ! will release another version tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Classes - Python MIP Documentation - Read the Docs
A cuts generator is an ConstrsGenerator object that receives a fractional solution and tries to generate one or more constraints (cuts) to remove...
Read more >
Mixed Integer Linear Programming with Python - Read the Docs
ConstrsGenerator ] property lp_method. Which method should be used to solve the linear programming problem. If the problem has.
Read more >
coin-or/python-mip 1.11.0 on GitHub - NewReleases.io
Python-MIP 1.11.0. Two additional parameters, three depth and pass number, are now informed to the generage_constrs method in ConstrsGenerator class (which ...
Read more >
Mixed Integer Linear Programming with Python - DocPlayer.net
5 Chapter 1 Introduction The Python-MIP package provides tools for modeling and solving Mixed-Integer Linear Programming Problems (MIPs) [Wols98] in Python.
Read more >
Haroldo G. Santos (@unxusr) / Twitter
... in ConstrsGenerator class (which is used for cut/lazy constraints callb. ... preemption are well-known NP-hard combinatorial optimization problems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found