Skip to content
Snippets Groups Projects
Commit 5ebe532b authored by Jaime Arias's avatar Jaime Arias
Browse files

add discrete variables

parent 9353a440
No related branches found
No related tags found
No related merge requests found
......@@ -853,6 +853,27 @@ class InterpreterParser(Parser):
return params_constraints
def _get_discrete_constraints(self, model) -> list[str]:
"""Get the initial constraints of discrete variables
Parameters
----------
model : Model
Imitator model
Returns
-------
list[str]
"""
vars = model.discrete_vars
var_constraints = []
for c in model.initial_constraints:
v1, _, v2 = self._normalize_constraints(c).split(" ")
if v1 in vars:
var_constraints.append(f"{v1} : {v2}")
return var_constraints
def _normalize_constraints(self, constraint: str) -> str:
"""
Normalize the string represention of a constraint. For instance, adding
......@@ -871,7 +892,7 @@ class InterpreterParser(Parser):
new_constr = "true" if constraint == "True" else constraint
# add space around binary operators
c_with_spaces = re.sub(r"((?!\.|\/)\W+)", r" \1 ", new_constr)
c_with_spaces = re.sub(r"((?!\.|\/)[^\w-]+)", r" \1 ", new_constr)
# remove more than one space
no_spaces = re.sub(" +", " ", c_with_spaces)
......@@ -962,8 +983,7 @@ class InterpreterParser(Parser):
params_str = f"({', '.join(params)})" if len(params) else "empty"
# variables
# TODO: add variables to the imitator parser (antlr)
variables = []
variables = self._get_discrete_constraints(model)
vars_str = f"({', '.join(variables)})" if len(variables) else "empty"
# constraints
......
......@@ -45,7 +45,7 @@ mod MODEL is
locs: (proc1 @ idle1, proc2 @ idle2, observer @ obswaiting)
clocks: (x1 : 0, x2 : 0)
parameters: (delta : rr(var(delta)), gamma : rr(var(gamma)))
dvariables: turn : -1
dvariables: (turn : -1)
constraint: rr(var(delta)) >= 0 and rr(var(gamma)) >= 0
n: 1 >
.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment