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
3 changes: 2 additions & 1 deletion linopy/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,8 @@ def _map_solution(self) -> DataArray:
Replace variable labels by solution values.
"""
m = self.model
sol = pd.Series(m.matrices.sol, m.matrices.vlabels)
M = m.matrices
sol = pd.Series(M.sol, M.vlabels)
Comment on lines +966 to +967
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change that we would want to apply everywhere!

sol[-1] = np.nan
idx = np.ravel(self.vars)
values = np.asarray(sol[idx]).reshape(self.vars.shape)
Expand Down
9 changes: 5 additions & 4 deletions linopy/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, cast

import numpy as np
Expand Down Expand Up @@ -96,7 +97,7 @@ def _build_cons(self) -> None:
np.concatenate(sense_list) if sense_list else np.array([], dtype=object)
)

@property
@cached_property
def c(self) -> ndarray:
"""Objective coefficients aligned with vlabels."""
m = self._parent
Expand All @@ -121,7 +122,7 @@ def c(self) -> ndarray:
np.add.at(result, label_to_pos[var_labels[mask]], coeffs[mask])
return result

@property
@cached_property
def Q(self) -> scipy.sparse.csc_matrix | None:
"""Quadratic objective matrix, shape (n_active_vars, n_active_vars)."""
m = self._parent
Expand All @@ -130,7 +131,7 @@ def Q(self) -> scipy.sparse.csc_matrix | None:
return None
return expr.to_matrix()[self.vlabels][:, self.vlabels]

@property
@cached_property
def sol(self) -> ndarray:
"""Solution values aligned with vlabels."""
if not self._parent.status == "ok":
Expand All @@ -146,7 +147,7 @@ def sol(self) -> ndarray:
result[positions] = var.solution.values.ravel()[mask]
return result

@property
@cached_property
def dual(self) -> ndarray:
"""Dual values aligned with clabels."""
if not self._parent.status == "ok":
Expand Down
Loading