Skip to content

Commit

Permalink
OA-Systems: Online Adaptive Systems #612
Browse files Browse the repository at this point in the history
  • Loading branch information
laxmikantbaheti committed May 30, 2023
1 parent dd73ffd commit 0292529
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 69 deletions.
54 changes: 26 additions & 28 deletions src/mlpro/bf/ml/systems/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ class ASystem(System, Model):
def __init__(self,
p_mode = Mode.C_MODE_SIM,
p_latency = None,
p_fct_strans: Union[FctSTrans, AFctSTrans] = None,
p_fct_success: Union[FctSuccess, AFctSuccess] = None,
p_fct_broken: Union[FctBroken, AFctBroken] = None,
p_fct_strans: Union[AFctSTrans, FctSTrans] = None,
p_fct_success: Union[AFctSuccess, FctSuccess] = None,
p_fct_broken: Union[AFctBroken, FctBroken] = None,
p_adaptivity: bool = True,
p_visualize: bool = False,
p_logging =Log.C_LOG_ALL):
Expand All @@ -462,28 +462,31 @@ def __init__(self,
p_visualize = p_visualize,
p_logging = p_logging)

Model.__init__(self, p_ada= p_adaptivity)


self._fct_strans = p_fct_strans
self._fct_broken = p_fct_broken
self._fct_success = p_fct_success
self.switch_adaptivity(p_ada = p_adaptivity)

self._fcts = [self._fct_strans, self._fct_success, self._fct_broken]

Model.__init__(self, p_ada= p_adaptivity)

# ## -------------------------------------------------------------------------------------------------
# def _set_adapted(self, p_adapted:bool):
# """
#
# Parameters
# ----------
# p_adapted
#
# Returns
# -------
#
# """
#
# Model._set_adapted(self, p_adapted=p_adapted)

# ## -------------------------------------------------------------------------------------------------
# def _set_adapted(self, p_adapted:bool):
# """
#
# Parameters
# ----------
# p_adapted
#
# Returns
# -------
#
# """
#
# Model._set_adapted(self, p_adapted=p_adapted)


## -------------------------------------------------------------------------------------------------
Expand All @@ -499,17 +502,12 @@ def switch_adaptivity(self, p_ada:bool):
"""
self.log(Log.C_LOG_TYPE_I, 'Switched Adaptivity')
self._adaptivity = p_ada

try: self._fct_strans.switch_adaptivity(p_ada=p_ada)
except: pass

try: self._fct_broken.switch_adaptivity(p_ada=p_ada)
except:pass

try: self._fct_success.switch_adaptivity(p_ada=p_ada)
except: pass
for fct in self._fcts:
try: fct.switch_adaptivity(p_ada=p_ada)
except: pass

Model.switch_adaptivity(self, p_ada=p_ada)

## -------------------------------------------------------------------------------------------------
def _adapt(self, **p_kwargs) -> bool:
Expand Down
66 changes: 25 additions & 41 deletions src/mlpro/oa/systems/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,22 +756,7 @@ def __init__(self,
p_visualize = p_visualize,
p_logging = p_logging)



# ## -------------------------------------------------------------------------------------------------
# def _set_adapted(self, p_adapted:bool):
# """
#
# Parameters
# ----------
# p_adapted
#
# Returns
# -------
#
# """
# Model.set_adapted()

self._workflows = [self._wf, self._wf_success, self._wf_broken]

## -------------------------------------------------------------------------------------------------
def _adapt(self, **p_kwargs) -> bool:
Expand All @@ -793,30 +778,18 @@ def _adapt(self, **p_kwargs) -> bool:

adapted = False

try:
adapted = self._wf.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._wf_success.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._wf_broken.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._fct_strans.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._fct_success.adapt(**p_kwargs)
except:
adapted = False or adapted
try:
adapted = self._fct_broken.adapt(**p_kwargs)
except:
adapted = False or adapted
for workflow in self._workflows:
try:
adapted = workflow.adapt(**p_kwargs) or adapted
except:
pass

for fct in self._fcts:
try:
adapted = fct.adapt(**p_kwargs) or adapted
except:
pass


return adapted

Expand All @@ -833,8 +806,19 @@ def switch_adaptivity(self, p_ada:bool):
-------
"""
pass
for workflow in self._workflows:
try:
workflow.switch_adaptivity(p_ada=p_ada)
except:
pass

for fct in self._fcts:
try:
fct.switch_adaptivity(p_ada = p_ada)
except:
pass

Model.switch_adaptivity(self, p_ada=p_ada)

## -------------------------------------------------------------------------------------------------
def _adapt_on_event(self, p_event_id:str, p_event_object:Event) -> bool:
Expand Down

0 comments on commit 0292529

Please sign in to comment.