Commit 4938fb88 authored by Lars Schieffer's avatar Lars Schieffer
Browse files

update transient

parent 2259db19
......@@ -280,7 +280,7 @@ def selfLoop(label: str, location: str) -> dict:
return {"action": label, "location": location, "destinations": [destination]}
def edgesByLabelOf(edgesByLocation: dict, automaton: str) -> dict:
def edgesByLabelOf(edgesByLocation: dict, automaton: str) -> (dict, set):
"""
Function Description:
Gather edges of jani-model automaton according their labels.
......
......@@ -52,7 +52,10 @@ def createTransientDeclaration(
modelLocations = pinsModel.getLocations()
stateVector = pinsModel.getStateVector()
declaration = ["// Transient Values"]
declaration += [variable for variable in transients.values()]
declaration += [
"{} {} = {};".format("int", identifier, str(int(value)))
for identifier, value in transients.items()
]
if groups:
for index, group in enumerate(pinsModel.getTransitionGroups()):
groupLocations = group.getAutomataLocations()
......
......@@ -161,8 +161,7 @@ class StateVector:
else:
slotType = kind
if transient:
declaration = "{} {} = {};".format("int", identifier, str(int(initial)))
self.__transientVariables[identifier] = declaration
self.__transientVariables[identifier] = initial
else:
self.addSlot(identifier, initial, slotType, SlotMode.VARIABLE)
......
......@@ -274,12 +274,9 @@ class TransitionGroup:
Enabling conditions according long, short or r2w state vector.
"""
stateVectorChanges = {}
occurringTransients = set()
groupCode = []
for edge in self.__edges:
for change in edge["changes"]:
if not stateVector.isSlot(change["ref"]):
occurringTransients.add(change["ref"])
index = str(change["index"])
update = (edge["enable"], change)
if index not in stateVectorChanges:
......@@ -297,14 +294,16 @@ class TransitionGroup:
groupCode += self.__declareVariablesCode(
self.__write, stateVector, modelLocations, readIndex=1
)
groupCode += self.__declareTransientCode(occurringTransients, readIndex=1)
groupCode += self.__declareTransientCode(
stateVector.getTransientVariables(), readIndex=1
)
for changeIndex, index in enumerate(sorted(stateVectorChanges)):
if changeIndex > 0:
groupCode += self.__declareVariablesCode(
self.__write, readIndex=changeIndex + 1
)
groupCode += self.__declareTransientCode(
occurringTransients, readIndex=changeIndex + 1
stateVector.getTransientVariables(), readIndex=changeIndex + 1
)
for condition, change in stateVectorChanges[index]:
enableCondition = self.__edgeEnableCondition(
......@@ -457,14 +456,14 @@ class TransitionGroup:
declaredVariables.append(self.__indent + slotVariableCode)
return declaredVariables
def __declareTransientCode(self, transientIdentifiers: set, readIndex=0) -> list:
def __declareTransientCode(self, transientIdentifiers: dict, readIndex=0) -> list:
"""
Function Description:
Get source code for declaring transient in group implementation
Function Parameters:
transientIdentifier: set
All occurring transient identifier
transientIdentifier: dict
All transient identifier
readIndex= ""
For representing consecutive changes on state vector
"""
......@@ -477,7 +476,9 @@ class TransitionGroup:
)
else:
transientCode = variableDeclareString.format(
"transient_" + transient, readIndex, transient
"transient_" + transient,
readIndex,
str(int(transientIdentifiers[transient])),
)
declaredTransient.append(self.__indent + transientCode)
return declaredTransient
......@@ -40,6 +40,10 @@ def handleIdentifier(
if stateVector and expression in stateVector.getPositions():
return "sourceStateVector[{}]".format(stateVector.getPositions()[expression])
elif stateVector.isTransient(expression):
if readIndex == "0":
initial = str(int(stateVector.getTransientVariables()[expression]))
return initial
else:
return "transient_" + expression + str(readIndex)
elif stateVector.isConstant(expression):
return validIdentifier(expression, "")
......
......@@ -29,7 +29,7 @@ int nextStateLong(model_t model, int group, int *sourceStateVector, TransitionCB
int One_instance_01 = sourceStateVector[0];
int Two_instance_01 = sourceStateVector[1];
int term1 = sourceStateVector[2];
int transient_t1 = t;
int transient_t1 = 0;
if (sourceStateVector[0] == 0){
One_instance_01 = 1;
}
......@@ -69,7 +69,7 @@ int nextStateR2W(model_t model, int group, int *sourceStateVector, TransitionCB
int One_instance_01 = sourceStateVector[0];
int Two_instance_01 = sourceStateVector[1];
int term1 = sourceStateVector[2];
int transient_t1 = t;
int transient_t1 = 0;
if (sourceStateVector[0] == 0){
One_instance_01 = 1;
}
......@@ -108,7 +108,7 @@ int actionsR2W(model_t model, int group, int *sourceStateVector, TransitionCB ca
int One_instance_01 = sourceStateVector[0];
int Two_instance_01 = sourceStateVector[1];
int term1 = sourceStateVector[2];
int transient_t1 = t;
int transient_t1 = 0;
if (sourceStateVector[0] == 0){
One_instance_01 = 1;
}
......
......@@ -30,6 +30,7 @@ int nextStateLong(model_t model, int group, int *sourceStateVector, TransitionCB
int Main_1_instance_01 = sourceStateVector[1];
int Main_instance_01 = sourceStateVector[0];
int term1 = sourceStateVector[2];
int transient_t1 = 0;
if (sourceStateVector[0] == 0){
Main_instance_01 = 1;
}
......@@ -69,6 +70,7 @@ int nextStateR2W(model_t model, int group, int *sourceStateVector, TransitionCB
int Main_1_instance_01 = sourceStateVector[1];
int Main_instance_01 = sourceStateVector[0];
int term1 = sourceStateVector[2];
int transient_t1 = 0;
if (sourceStateVector[0] == 0){
Main_instance_01 = 1;
}
......@@ -107,6 +109,7 @@ int actionsR2W(model_t model, int group, int *sourceStateVector, TransitionCB ca
int Main_1_instance_01 = sourceStateVector[1];
int Main_instance_01 = sourceStateVector[0];
int term1 = sourceStateVector[2];
int transient_t1 = 0;
if (sourceStateVector[0] == 0){
Main_instance_01 = 1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment