-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add support for semi-continuous and semi-integer vars #3
Conversation
test/mip_test.rb
Outdated
def test_semi_contious_mip | ||
skip unless Opt.solvers[Opt.default_solvers[:mip]].supports_semi_continuous_variables? | ||
|
||
x1 = Opt::SemiContinuousVariable.new(1.., "x1") | ||
x2 = Opt::SemiContinuousVariable.new(2.., "x2") | ||
|
||
prob = Opt::Problem.new | ||
prob.add(3 * x1 + 2 * x2 >= 60) | ||
prob.minimize(8 * x1 + 6 * x2) | ||
res = prob.solve | ||
assert_equal :optimal, res[:status] | ||
assert_in_delta 160, res[:objective] | ||
assert_equal 20, x1.value | ||
assert_kind_of Float, x1.value | ||
assert_in_delta 0, x2.value | ||
assert_kind_of Float, x2.value | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested by comparing with scipy:
from scipy import optimize
optimize.milp([8, 6],
constraints=optimize.LinearConstraint([3, 2], lb=60),
bounds=optimize.Bounds(lb=[1, 2]),
integrality=[2, 2])
test/mip_test.rb
Outdated
def test_semi_integer_mip | ||
skip unless Opt.solvers[Opt.default_solvers[:mip]].supports_semi_continuous_variables? | ||
|
||
x1 = Opt::SemiIntegerVariable.new(1.., "x1") | ||
x2 = Opt::SemiIntegerVariable.new(2.., "x2") | ||
|
||
prob = Opt::Problem.new | ||
prob.add(3 * x1 + 2 * x2 >= 70) | ||
prob.minimize(8 * x1 + 6 * x2) | ||
res = prob.solve | ||
assert_equal :optimal, res[:status] | ||
assert_in_delta 188, res[:objective] | ||
assert_equal 22, x1.value | ||
assert_kind_of Integer, x1.value | ||
assert_in_delta 2, x2.value | ||
assert_kind_of Integer, x2.value | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested by comparing with scipy:
from scipy import optimize
optimize.milp([8, 6],
constraints=optimize.LinearConstraint([3, 2], lb=70),
bounds=optimize.Bounds(lb=[1, 2]),
integrality=[3, 3])
Hey @jeromepl, thanks for the PR. Looks really great! Two small notes:
|
@ankane Agreed and done! |
Awesome, thanks! Will push a new release later tonight. |
Adds support for semi-continuous and semi-integer variables for the HiGHS solver (the only solver at this point which support these types of variables natively)
Useful for problems where a value can be either 0 or must be greater than or equal to some minimum value.
Closes #2