Skip to content

Commit

Permalink
Merge pull request #110 from chrhansk/hotfix-bound-projection
Browse files Browse the repository at this point in the history
Ensure steps are always projected to bounds
  • Loading branch information
chrhansk authored Aug 20, 2024
2 parents beb9ae3 + d69aede commit 3c55f19
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
project = "pygradflow"
copyright = "2023, Christoph Hansknecht"
author = "Christoph Hansknecht"
release = "0.5.15"
release = "0.5.16"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
31 changes: 28 additions & 3 deletions pygradflow/step/solver/step_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,45 @@
class StepResult:
def __init__(self, orig_iterate, dx, dy, active_set, rcond=None):
self.orig_iterate = orig_iterate
self.dx = dx
self.dy = dy
self.active_set = active_set
self.rcond = rcond

self._compute_xn(dx)

def _compute_xn(self, dx):
iterate = self.orig_iterate
problem = iterate.problem

var_lb = problem.var_lb
var_ub = problem.var_ub

xn = iterate.x - dx
dx = np.copy(dx)

at_lb = xn < var_lb
xn[at_lb] = var_lb[at_lb]
dx[at_lb] = iterate.x[at_lb] - var_lb[at_lb]

at_ub = xn > var_ub
xn[at_ub] = var_ub[at_ub]
dx[at_ub] = iterate.x[at_ub] - var_ub[at_ub]

self.dx = dx
self.xn = xn

@functools.cached_property
def iterate(self):
iterate = self.orig_iterate

xn = self.xn.astype(iterate.x.dtype, copy=False)
yn = iterate.y - self.dy

return Iterate(
iterate.problem,
iterate.params,
iterate.x - self.dx,
iterate.y - self.dy,
xn,
yn,
iterate.eval,
)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pygradflow"
version = "0.5.15"
version = "0.5.16"
description = "PyGradFlow is a simple implementation of the sequential homotopy method to be used to solve general nonlinear programs."
authors = ["Christoph Hansknecht <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 3c55f19

Please sign in to comment.