Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Next Release
-----

1.9.1
-----
* expressions for Constraint in the matrix interface are now assembled from only non-zero
coefficients, speeding up JSON conversion as a side effect
* fixed a typo in the matrix interface

1.9.0
-----
* enable Python 3.14
Expand Down
10 changes: 7 additions & 3 deletions src/optlang/matrix_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,11 @@ def _get_expression(self):
if self.problem is not None:
variables = self.problem._variables
all_coefs = self.problem.problem.constraint_coefs
coefs = [(v, all_coefs.get((self.name, v.name), 0.0)) for v in variables]
coefs = [
(variables[vname], coef)
for (cname, vname), coef in all_coefs.items()
if cname == self.name
]
Comment thread
cdiener marked this conversation as resolved.
expression = add([mul((symbolics.Real(co), v)) for (v, co) in coefs])
self._expression = expression
return self._expression
Expand Down Expand Up @@ -823,15 +827,15 @@ def objective(self, value):
(
offset,
linear_coefficients,
quadratic_coeffients,
quadratic_coefficients,
) = parse_optimization_expression(value, quadratic=True, expression=expression)
self._objective_offset = offset
if linear_coefficients:
self.problem.obj_linear_coefs = {
v.name: float(c) for v, c in linear_coefficients.items()
}

for key, coef in quadratic_coeffients.items():
for key, coef in quadratic_coefficients.items():
if len(key) == 1:
var = next(iter(key))
self.problem.obj_quadratic_coefs[(var.name, var.name)] = float(coef)
Expand Down
Loading