Skip to content

Commit

Permalink
Merge pull request #13 from pluflou/lastvalequal
Browse files Browse the repository at this point in the history
added LastValEqual component class
  • Loading branch information
bmeyers authored Apr 14, 2023
2 parents fb301bc + 86d0349 commit dbf2126
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions gfosd/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from gfosd.components.finite_set import FiniteSet, Boolean
from gfosd.components.aggregate import Aggregate
from gfosd.components.equality_constraints import (FirstValEqual,
LastValEqual,
AverageEqual,
NoCurvature,
NoSlope)
26 changes: 26 additions & 0 deletions gfosd/components/equality_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,33 @@ def _make_B(self):
def _make_c(self):
self._c = np.concatenate([np.atleast_1d(self._c[0]),
[self._first_val]])

class LastValEqual(GraphComponent):
def __init__(self, value=0, *args, **kwargs):
self._last_val = value
super().__init__(*args, **kwargs)
# always retain helper variable
self._has_helpers = True

def _make_A(self):
super()._make_A()
super()._make_B()
super()._make_c()
self._A = sp.bmat([
[self._A.tocsr()[-1]],
[sp.dok_matrix((1, self._A.shape[1]))]
])

def _make_B(self):
self._B = sp.bmat([
[self._B.tocsr()[-1]],
[sp.coo_matrix(([1], ([0], [self._B.shape[1]-1])), shape=(1, self._B.shape[1]))]
])

def _make_c(self):
self._c = np.concatenate([np.atleast_1d(self._c[-1]),
[self._last_val]])

class AverageEqual(GraphComponent):
def __init__(self, value=0, period=None, *args, **kwargs):
self._avg_val = value
Expand Down

0 comments on commit dbf2126

Please sign in to comment.