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