gym_tl_tools.parser
Functions
Replace special characters in the spec with underscores so that it can be used as a file name. |
Classes
|
|
|
Represents a symbol in the parser with its priority and function. |
- class gym_tl_tools.parser.Parser[source]
Bases:
object- evaluate(parsed_tokens: list[str], var_dict: dict[str, float]) float[source]
Checking from the start, get tokens from the stack and compute there if there is a symbol
- parse(token_list: list[str], var_names: list[str]) list[str][source]
Convert the token to Reverse Polish Notation
- tl2rob(spec: str, var_dict: dict[str, float]) float[source]
Parsing a TL spec to its robustness
- Parameters:
spec (str) – The TL spec to be parsed. e.g. “psi_1 & psi_2 | !psi_3”.
var_dict (dict[str, float]) – A dictionary mapping the variable names used in the TL spec to their current values. The keys should match the names of the atomic predicates defined in the spec. e.g. {“d_robot_goal”: 3.0, “d_robot_obstacle”: 1.0, “d_robot_goal”: 0.5}.
- Returns:
robustness – The robustness value of the TL spec given the variable values. A positive value indicates satisfaction, while a negative value indicates violation.
- Return type:
- class gym_tl_tools.parser.ParserSymbol(*, priority: int, func: Callable[[...], Any])[source]
Bases:
BaseModelRepresents a symbol in the parser with its priority and function.
- func
The function that implements the operation of the symbol. It should take the appropriate number of arguments and return a value.
- Type:
Callable[…, Any]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- gym_tl_tools.parser.replace_special_characters(spec: str) str[source]
Replace special characters in the spec with underscores so that it can be used as a file name.
- Parameters:
spec (str) – spec to be replaced. The spec can contain special characters like spaces, &, |, etc. These characters are replaced with underscores to create a valid file name.
- Returns:
replaced_spec – spec with special characters replaced by underscores
- Return type:
Examples
`python spec = replace_special_characters("F(psi_1 | psi_2) & G(!psi_3)") print(spec) # Output: "F(psi_1_or_psi_2)_and_G(!psi_3)" `