diff --git a/dryvr_plus_plus/example/example_agent/car_agent.py b/dryvr_plus_plus/example/example_agent/car_agent.py index d27131c8bf96eb6c798bed33417165815e4b623d..87cc2892fc72283aeb4ab130dc464a6b47259ef4 100644 --- a/dryvr_plus_plus/example/example_agent/car_agent.py +++ b/dryvr_plus_plus/example/example_agent/car_agent.py @@ -1,7 +1,8 @@ # Example agent. from typing import Tuple, List -import numpy as np +import numpy as np +from pkg_resources import EmptyProvider from scipy.integrate import ode from dryvr_plus_plus.scene_verifier.agents.base_agent import BaseAgent @@ -11,10 +12,7 @@ from dryvr_plus_plus.scene_verifier.code_parser.parser import ControllerIR, Stat class NPCAgent(BaseAgent): def __init__(self, id): self.id = id - controller = Lambda(args = [('ego', 'State'),('others', 'State')], body = {}) - state_defs = {'State':StateDef(cont=[], disc=[], static=[])} - mode_defs = {'NullMode':ModeDef(modes=['Null'])} - self.controller = ControllerIR(controller, state_defs, mode_defs) + self.controller:ControllerIR = ControllerIR.EmptyControllerIR() @staticmethod def dynamic(t, state, u): diff --git a/dryvr_plus_plus/example/example_agent/sign_agent.py b/dryvr_plus_plus/example/example_agent/sign_agent.py index 2b97fa273ab00d7df9576fdd17a9fd21cbf2f0aa..71be3f61a8900160bb39d3435ae46c1242edf2a5 100644 --- a/dryvr_plus_plus/example/example_agent/sign_agent.py +++ b/dryvr_plus_plus/example/example_agent/sign_agent.py @@ -1,11 +1,11 @@ from dryvr_plus_plus.scene_verifier.agents.base_agent import BaseAgent import numpy as np -from dryvr_plus_plus.scene_verifier.code_parser.pythonparser import EmptyAst +from dryvr_plus_plus.scene_verifier.code_parser.parser import ControllerIR class SignAgent(BaseAgent): def __init__(self, id): self.id = id - self.controller = EmptyAst() + self.controller:ControllerIR = ControllerIR.EmptyControllerIR() def TC_simulate(self, mode, init, time_horizon, time_step, map=None): number_points = int(np.ceil(float(time_horizon)/time_step)) diff --git a/dryvr_plus_plus/scene_verifier/code_parser/parser.py b/dryvr_plus_plus/scene_verifier/code_parser/parser.py index f919f9167853112fc247f393872a9800419696f8..cab195d96784bee930a3afdc5d4e81d2f6e62aaf 100644 --- a/dryvr_plus_plus/scene_verifier/code_parser/parser.py +++ b/dryvr_plus_plus/scene_verifier/code_parser/parser.py @@ -84,7 +84,7 @@ class ReductionType(Enum): }[self] @dataclass(unsafe_hash=True) -class Reduction(ast.AST): +class Reduction(ast.expr): """A simple reduction. Must be a reduction function (see `ReductionType`) applied to a generator with a single clause over a iterable""" op: ReductionType @@ -169,6 +169,14 @@ class ControllerIR: state_defs: Dict[str, StateDef] mode_defs: Dict[str, ModeDef] + @classmethod + def EmptyControllerIR(cls): + controller = Lambda(args = [('ego', 'State'),('others', 'State')], body = {}) + state_defs = {'State':StateDef(cont=[], disc=[], static=[])} + mode_defs = {'NullMode':ModeDef(modes=['Null'])} + return cls(controller, state_defs, mode_defs) + + @staticmethod def parse(code: Optional[str] = None, fn: Optional[str] = None) -> "ControllerIR": return Env.parse(code, fn).to_ir()