-
Notifications
You must be signed in to change notification settings - Fork 51
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
Model vector access #101
Merged
KristianJensen
merged 7 commits into
opencobra:devel
from
matthiaskoenig:model_vector_access
Apr 8, 2017
Merged
Model vector access #101
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a1c3133
vector methods in interface implemented
matthiaskoenig 9f191ee
cplex interface updated
matthiaskoenig d1019e5
glpk interface updated
matthiaskoenig 6dc6b71
no vector functions exisiting glpk, updated interface
matthiaskoenig 744fa82
glpk vector functions added
matthiaskoenig 4810997
primal rounding moved to interface
matthiaskoenig bc03c03
refactored primal rounding back to subinterfaces, property fixes
matthiaskoenig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,8 @@ | |
glp_set_mat_row, glp_set_col_bnds, glp_set_row_bnds, GLP_FR, GLP_UP, GLP_LO, GLP_FX, GLP_DB, glp_del_rows, \ | ||
glp_get_mat_row, glp_get_row_ub, glp_get_row_type, glp_get_row_lb, glp_get_row_name, glp_get_obj_coef, \ | ||
glp_get_obj_dir, glp_scale_prob, GLP_SF_AUTO, glp_get_num_int, glp_get_num_bin, glp_mip_col_val, \ | ||
glp_mip_obj_val, glp_mip_status, GLP_ETMLIM, glp_adv_basis, glp_read_lp, glp_mip_row_val | ||
glp_mip_obj_val, glp_mip_status, GLP_ETMLIM, glp_adv_basis, glp_read_lp, glp_mip_row_val, \ | ||
get_col_primals, get_col_duals, get_row_primals, get_row_duals | ||
|
||
|
||
|
||
|
@@ -585,45 +586,37 @@ def objective(self, value): | |
|
||
@property | ||
def primal_values(self): | ||
primal_values = collections.OrderedDict() | ||
is_mip = self._glpk_is_mip() | ||
for index, variable in enumerate(self.variables): | ||
if is_mip: | ||
value = glp_mip_col_val(self.problem, index + 1) | ||
else: | ||
value = glp_get_col_prim(self.problem, index + 1) | ||
primal_values[variable.name] = variable._round_primal_to_bounds(value) | ||
return primal_values | ||
# round primals | ||
primal_values = [variable._round_primal_to_bounds(primal) | ||
for variable, primal in zip(self.variables, self._get_primal_values())] | ||
return collections.OrderedDict( | ||
zip(self._get_variables_names(), primal_values) | ||
) | ||
|
||
@property | ||
def reduced_costs(self): | ||
def _get_primal_values(self): | ||
if self._glpk_is_mip(): | ||
# no vector function (element wise) | ||
return [glp_mip_col_val(self.problem, index + 1) | ||
for index in range(len(self.variables))] | ||
else: | ||
return get_col_primals(self.problem) | ||
|
||
def _get_reduced_costs(self): | ||
if self.is_integer: | ||
raise ValueError("Dual values are not well-defined for integer problems") | ||
reduced_costs = collections.OrderedDict( | ||
(var.name, glp_get_col_dual(self.problem, index + 1)) for index, var in enumerate(self.variables) | ||
) | ||
return reduced_costs | ||
return get_col_duals(self.problem) | ||
|
||
@property | ||
def constraint_values(self): | ||
dual_values = collections.OrderedDict() | ||
is_mip = self._glpk_is_mip() | ||
for index, constraint in enumerate(self.constraints): | ||
if is_mip: | ||
value = glp_mip_row_val(self.problem, index + 1) | ||
else: | ||
value = glp_get_row_prim(self.problem, index + 1) | ||
dual_values[constraint.name] = value | ||
return dual_values | ||
def _get_constraint_values(self): | ||
if self._glpk_is_mip(): | ||
# no vector function (element wise) | ||
return [glp_mip_row_val(self.problem, index + 1) for index in range(len(self.constraints))] | ||
else: | ||
return get_row_primals(self.problem) | ||
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. Same as before. Already handled by the swiglpk function. No need for glp_mip_row_val here as this is used already anyways. |
||
|
||
@property | ||
def shadow_prices(self): | ||
def _get_shadow_prices(self): | ||
if self.is_integer: | ||
raise ValueError("Dual values are not well-defined for integer problems") | ||
shadow_prices = collections.OrderedDict( | ||
(constraint.name, glp_get_row_dual(self.problem, index + 1)) for index, constraint in enumerate(self.constraints) | ||
) | ||
return shadow_prices | ||
return get_row_duals(self.problem) | ||
|
||
def to_lp(self): | ||
self.update() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
get_col_primals will return the mip values via glp_mip_col_val automatically if the problem is a MIP. That is done in C so no need for the if-statement.