From 6bb636ea23fdfe960ea5f69b93e097233cc54e4b Mon Sep 17 00:00:00 2001
From: "christoph.von.oy" <christoph.von.oy@rwth-aachen.de>
Date: Mon, 24 Jun 2024 12:50:37 +0200
Subject: [PATCH] Enable logics use boolean profiles now

---
 dynamics.py | 4 +++-
 topology.py | 8 ++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/dynamics.py b/dynamics.py
index cdce0e9..862cd1a 100644
--- a/dynamics.py
+++ b/dynamics.py
@@ -1611,7 +1611,9 @@ class Profile:
         if dynamic == self.dynamic:
             return self
         if self.is_bool and not is_view_resample(self.dynamic, dynamic):
-            raise ValueError(f"A bool profile can only be resampled with a view resampling!")
+            raise ValueError(
+                f"A bool profile can only be resampled with a view resampling!"
+            )
         return Profile(
             resample(np.expand_dims(self.values, axis=0), self.dynamic, dynamic)[0],
             dynamic,
diff --git a/topology.py b/topology.py
index 7b985e9..d19298c 100644
--- a/topology.py
+++ b/topology.py
@@ -441,12 +441,12 @@ class Topology:
 
         for logic_name, logic in self._additional_model_logic.items():
             if logic["type"] == "ConnectorEnable":
-                enable = logic["enable"]
+                enable = logic["enable"].resample(o_block.dynamic).values
                 for i, connector in enumerate(logic["connectors"]):
                     connector_var = o_block.component_dict[connector]
 
                     def rule(m, t):
-                        if enable[t] == 0:
+                        if not enable[t]:
                             return connector_var[t] == 0
                         else:
                             return pyo.Constraint.Skip
@@ -457,7 +457,7 @@ class Topology:
                     )
 
             if logic["type"] == "ConnectionEnable":
-                enable = logic["enable"]
+                enable = logic["enable"].resample(o_block.dynamic).values
                 for i, connection in enumerate(logic["connections"]):
                     flow_from = connection["from"]
                     flow_to = connection["to"]
@@ -470,7 +470,7 @@ class Topology:
                         flow_var = o_block.component_dict[connection.in_flows[0]]
 
                         def rule(m, t):
-                            if enable[t] == 0:
+                            if not enable[t]:
                                 return flow_var[t] == 0
                             else:
                                 return pyo.Constraint.Skip
-- 
GitLab