Skip to content

Commit

Permalink
Small improvement to Grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
pcanelas committed Oct 25, 2024
1 parent 1bc6787 commit 91196c2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/stl/genetic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def evaluate(self, X):

# Boolean expressions
@dataclass
class Variable:
class Variable(ABC):
var: Annotated[str, VarRange(variables)]

def evaluate(self, X):
Expand All @@ -80,14 +80,14 @@ def __str__(self):
return f"var[{self.var}]"

@dataclass
class Negation:
expression: Union[Operator]
class Negation(ABC):
expression: Operator

def evaluate(self, X):
return not self.expression.evaluate(X)

@dataclass
class Operator:
class Operator(ABC):
left: Union[Variable, Annotated[int, IntRange(-100, 100)]]
op: Annotated[str, VarRange[operators]]
right: Union[Variable, Annotated[int, IntRange(-100, 100)]]
Expand Down Expand Up @@ -132,6 +132,8 @@ def main():
STLFormula
)

print(grammar)

# Run the genetic programming algorithm
gp: SimpleGP = SimpleGP(
fitness_function=fitness_function,
Expand Down

0 comments on commit 91196c2

Please sign in to comment.