Skip to content

Commit

Permalink
Make glpk get_linear_coefficients respect variables arg. (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdiener authored and KristianJensen committed Apr 8, 2017
1 parent a4030fa commit 84b432e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion optlang/glpk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ def get_linear_coefficients(self, variables):
ia = intArray(num_cols + 1)
da = doubleArray(num_cols + 1)
nnz = glp_get_mat_row(self.problem.problem, self._index, ia, da)
return {self.problem._variables[ia[i + 1] - 1]: da[i + 1] for i in range(nnz)}
coefs = dict.fromkeys(variables, 0.0)
coefs.update({
self.problem._variables[ia[i + 1] - 1]: da[i + 1]
for i in range(nnz)
if self.problem._variables[ia[i + 1] - 1] in variables})
return coefs
else:
raise Exception("Can't get coefficients from solver if constraint is not in a model")

Expand Down

0 comments on commit 84b432e

Please sign in to comment.