-
Notifications
You must be signed in to change notification settings - Fork 559
Add Gurobi Direct MINLP solver in contrib.solver #3745
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
Changes from all commits
653f7a6
d2edb21
33ce433
ad3c8a3
7ad1794
4dcb73e
162ab75
16def08
dbac17f
a9f6c3a
62b93d2
01b3a7a
a6d01a6
f8b8709
c362117
8c23638
c3d1350
b53b8ef
536844b
65980c9
ec3aeed
03ba09b
767428f
9eed315
39b7ea1
971f324
4142b2f
51f35ec
7609f09
1cda2fc
598a90c
81caf88
e44530b
a408ceb
9ebea39
5daef08
e91f713
461c64c
850eeca
0e8056b
26b0be3
cee0125
0fa39fa
2c18597
18c3d3a
cc22abc
0b7d03a
520b7a0
0271a12
29f01bd
051a598
585d9e4
a011fa3
70838ed
e784730
bbb27e8
5157c0d
6a78ee5
12848b7
d4e939e
87d2762
3afba1d
410e5c6
d133fe1
8ca6b26
e9e9467
6102cfc
c59b527
350e961
5b45177
a5e3a94
7bc0b7c
4905284
34be2c5
409d32d
6e20d03
9e56f83
9651d0c
864b98a
f017b6d
cf18d8a
b524169
a1f7c8b
383af85
08390a0
bbb1da8
8cc3995
2e84907
bf207e5
02d37db
bc1bfcd
3de977f
f57130a
9e43496
52b331b
4b75ddb
6488881
94db0a9
77ef498
adc46b7
30c2681
984c77c
31c9523
98b3e76
a5dd19e
8e515bc
66b76dd
a789a18
7ccb122
917026b
cacb14e
bf3401c
2a0c67e
ebd031f
a9d049b
dfa97dd
a69dc6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,7 @@ def load_vars(self, vars_to_load=None, solution_number=0): | |
| if self._grb_model.SolCount == 0: | ||
| raise NoSolutionError() | ||
|
|
||
| iterator = zip(self._pyo_vars, self._grb_vars.x.tolist()) | ||
| iterator = zip(self._pyo_vars, map(operator.attrgetter('x'), self._grb_vars)) | ||
| if vars_to_load: | ||
| vars_to_load = ComponentSet(vars_to_load) | ||
| iterator = filter(lambda var_val: var_val[0] in vars_to_load, iterator) | ||
|
|
@@ -130,7 +130,7 @@ def get_primals(self, vars_to_load=None, solution_number=0): | |
| if self._grb_model.SolCount == 0: | ||
| raise NoSolutionError() | ||
|
|
||
| iterator = zip(self._pyo_vars, self._grb_vars.x.tolist()) | ||
| iterator = zip(self._pyo_vars, map(operator.attrgetter('x'), self._grb_vars)) | ||
| if vars_to_load: | ||
| vars_to_load = ComponentSet(vars_to_load) | ||
| iterator = filter(lambda var_val: var_val[0] in vars_to_load, iterator) | ||
|
|
@@ -143,24 +143,26 @@ def get_duals(self, cons_to_load=None): | |
| def dedup(_iter): | ||
| last = None | ||
| for con_info_dual in _iter: | ||
| if not con_info_dual[1] and con_info_dual[0][0] is last: | ||
| if not con_info_dual[1] and con_info_dual[0] is last: | ||
| continue | ||
| last = con_info_dual[0][0] | ||
| last = con_info_dual[0] | ||
| yield con_info_dual | ||
|
|
||
| iterator = dedup(zip(self._pyo_cons, self._grb_cons.getAttr('Pi').tolist())) | ||
| iterator = dedup( | ||
| zip(self._pyo_cons, map(operator.attrgetter('Pi'), self._grb_cons)) | ||
| ) | ||
| if cons_to_load: | ||
| cons_to_load = set(cons_to_load) | ||
| iterator = filter( | ||
| lambda con_info_dual: con_info_dual[0][0] in cons_to_load, iterator | ||
| lambda con_info_dual: con_info_dual[0] in cons_to_load, iterator | ||
| ) | ||
| return {con_info[0]: dual for con_info, dual in iterator} | ||
| return {con_info: dual for con_info, dual in iterator} | ||
|
|
||
| def get_reduced_costs(self, vars_to_load=None): | ||
| if self._grb_model.Status != gurobipy.GRB.OPTIMAL: | ||
| raise NoReducedCostsError() | ||
|
|
||
| iterator = zip(self._pyo_vars, self._grb_vars.getAttr('Rc').tolist()) | ||
| iterator = zip(self._pyo_vars, map(operator.attrgetter('Rc'), self._grb_vars)) | ||
| if vars_to_load: | ||
| vars_to_load = ComponentSet(vars_to_load) | ||
| iterator = filter(lambda var_rc: var_rc[0] in vars_to_load, iterator) | ||
|
|
@@ -374,7 +376,12 @@ def solve(self, model, **kwds) -> Results: | |
| timer, | ||
| config, | ||
| GurobiDirectSolutionLoader( | ||
| gurobi_model, A, x, repn.rows, repn.columns, repn.objectives | ||
| gurobi_model, | ||
| A, | ||
| x.tolist(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why convert x to a list?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of the thing you commented on above, actually. I'm making this look the same as Gurobi MINLP so that they can use an identical SolutionLoader. Gurobi MINLP doesn't have the luxury of declaring the variables as a vector (I don't think? Although if I can dynamically add to one, that's another option, maybe?), so they're a list at this point right now. |
||
| list(map(operator.itemgetter(0), repn.rows)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why de-tupalize rows? aren't both values needed by the loader?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so--the only time we need anything from this at all is to get the duals. And then you have to get the |
||
| repn.columns, | ||
| repn.objectives, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
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.
Is fetching the values one at a time slower than getting them in a single vector? (Same question applies to get_primals, get_duals. and get_redued_costs below)
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.
I don't know? If it is, this is much harder to generalize because the Gurobi MINLP version doesn't have the gurobi vars as a vector--they're already a list.