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

Generating a simple problem that reliably triggers hits :UserLimit #342

Closed
vtjeng opened this issue Jul 19, 2020 · 2 comments · Fixed by #346
Closed

Generating a simple problem that reliably triggers hits :UserLimit #342

vtjeng opened this issue Jul 19, 2020 · 2 comments · Fixed by #346

Comments

@vtjeng
Copy link
Contributor

vtjeng commented Jul 19, 2020

I'm on Julia 1.4 but using an older version of the JuMP and Gurobi packages (I'm planning to upgrade soon, but one of my other packages constrains me to using JuMP v0.18.6.):

  [2e9cd046] Gurobi v0.8.1
  [4076af6c] JuMP v0.18.6

When solving an MILP via JuMP using the GurobiSolver, I've found that getobjbound appears to ignore any constant term (perhaps related to this issue) if the objective is a JuMP.AffExpr when my solve hits a :UserLimit. I haven't been able to confirm whether this is an issue if a) my solve does not hit a :UserLimit or b) for getobjectivevalue. (I can get around this issue by adding an additional variable constrained to be equal to the objective and optimizing over the variable instead.)

I wanted to add a test (although I'm still not sure which package that test should go into) to ensure that this is no longer the case, but I haven't been able to reproduce this with a simple example as I can't figure out how to reliably trigger :UserLimit with a small problem. Does anyone have a suggestion for a problem that is simple to understand but for which I can get the :UserLimit status?

@odow
Copy link
Member

odow commented Jul 19, 2020

You could do something like:

function callback_knapsack_model()
model = Gurobi.Optimizer(
GUROBI_ENV,
OutputFlag = 0,
Cuts = 0,
Presolve = 0,
PreCrush = 1,
Heuristics = 0
)
N = 30
x = MOI.add_variables(model, N)
MOI.add_constraints(model, MOI.SingleVariable.(x), MOI.ZeroOne())
MOI.set.(model, MOI.VariablePrimalStart(), x, 0.0)
Random.seed!(1)
item_weights, item_values = rand(N), rand(N)
MOI.add_constraint(
model,
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(item_weights, x), 0.0),
MOI.LessThan(10.0)
)
MOI.set(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(item_values, x), 0.0)
)
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
return model, x, item_weights

but set a time limit of 0 seconds or a solution limit of 1 or something.

@vtjeng
Copy link
Contributor Author

vtjeng commented Sep 29, 2020

For users who simply want to trigger a particular termination status from the optimizer for testing purposes (but are not interested in it being a Gurobi.Optimizer in particular), you can use the suggestion by @mlubin here.

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

Successfully merging a pull request may close this issue.

2 participants