Skip to content

Commit

Permalink
Merge pull request #17 from biosustain/pickling-speed
Browse files Browse the repository at this point in the history
Speed up unpickling
  • Loading branch information
phantomas1234 committed May 30, 2016
2 parents 196b427 + 7eafce7 commit 75696b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion optlang/cplex_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,10 @@ def __init__(self, problem=None, *args, **kwargs):
variables = self._variables
for name, row, sense, rhs in zipped_constr_args:
constraint_variables = [variables[i - 1] for i in row.ind]
lhs = _unevaluated_Add(*[val * variables[i - 1] for i, val in zip(row.ind, row.val)])

# Since constraint expressions are lazily retrieved from the solver they don't have to be built here
# lhs = _unevaluated_Add(*[val * variables[i - 1] for i, val in zip(row.ind, row.val)])
lhs = 0
if isinstance(lhs, int):
lhs = sympy.Integer(lhs)
elif isinstance(lhs, float):
Expand Down
12 changes: 9 additions & 3 deletions optlang/glpk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,12 @@ def __init__(self, problem=None, *args, **kwargs):
da = doubleArray(col_num + 1)
nnz = glp_get_mat_row(self.problem, j, ia, da)
constraint_variables = [variables[ia[i] - 1] for i in range(1, nnz + 1)]
lhs = _unevaluated_Add(*[da[i] * constraint_variables[i - 1]
for i in range(1, nnz + 1)])

# Since constraint expressions are lazily retrieved from the solver they don't have to be built here
# lhs = _unevaluated_Add(*[da[i] * constraint_variables[i - 1]
# for i in range(1, nnz + 1)])
lhs = 0

glpk_row_type = glp_get_row_type(self.problem, j)
if glpk_row_type == GLP_FX:
row_lb = glp_get_row_lb(self.problem, j)
Expand Down Expand Up @@ -462,7 +466,9 @@ def __init__(self, problem=None, *args, **kwargs):
self._variables_to_constraints_mapping[variable.name] = set([constraint_id])

super(Model, self)._add_constraints(
[Constraint(lhs, lb=row_lb, ub=row_ub, name=constraint_id, problem=self)], sloppy=True)
[Constraint(lhs, lb=row_lb, ub=row_ub, name=constraint_id, problem=self, sloppy=True)],
sloppy=True
)

term_generator = (
(glp_get_obj_coef(self.problem, index), variables[index - 1])
Expand Down

0 comments on commit 75696b6

Please sign in to comment.