Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 83a50ea

Browse files
author
Joshua Reich
committed
tweaks to classifier __add__
1 parent debb8cc commit 83a50ea

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pyretic/core/classifier.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def __invert__(self):
140140
### PARALLEL COMPOSITION
141141

142142
def __add__(c1, c2):
143+
from pyretic.core.language import drop, identity
143144
def _cross(r1,r2):
144-
from pyretic.core.language import drop
145145
intersection = r1.match.intersect(r2.match)
146146
if intersection != drop:
147147
# TODO (josh) logic for detecting when sets of actions can't be combined
@@ -156,17 +156,19 @@ def _cross(r1,r2):
156156

157157
# start with an empty set of rules for the output classifier
158158
c3 = Classifier()
159-
# JOSH - this check shouldn't be needed (I think)
160-
if c2 is None:
161-
return None
159+
assert(not (c1 is None and c2 is None))
162160
# then cross all pairs of rules in the first and second classifiers
163161
for r1 in c1.rules:
164162
for r2 in c2.rules:
165163
crossed_r = _cross(r1,r2)
166164
if crossed_r:
167165
c3.append(crossed_r)
166+
# if the classifier is empty, add a drop-all rule
167+
if len(c3) == 0:
168+
c3.append(Rule(identity,[drop]))
168169
# and optimize the classifier
169-
c3 = c3.optimize()
170+
else:
171+
c3 = c3.optimize()
170172
return c3
171173

172174

0 commit comments

Comments
 (0)