private static void buildReWritingVariables(KPsystem kpSystem, KpCore.MType kpType, NuSMV.Module module, int strategyIndex, KpCore.Rule kpRule) { RewritingRule rwr = (RewritingRule)kpRule; string varName = ""; VariableOrigin origin = VariableOrigin.Original; bool isLeft = true; foreach (var leftHRule in rwr.Lhs) { varName = leftHRule.Key; origin = VariableOrigin.Original; isLeft = true; buildReWritingVariable(kpSystem, kpType, module, strategyIndex, kpRule, varName, origin, isLeft); } foreach (var rigthHRule in rwr.Rhs) { varName = rigthHRule.Key; origin = VariableOrigin.Original; isLeft = false; //first generate original one, then its copy if (!module.isVariableExist(varName)) { buildReWritingVariable(kpSystem, kpType, module, strategyIndex, kpRule, varName, origin, isLeft); } string copyVarName = varName + SMVPreFix.COPY; origin = VariableOrigin.Copy; buildReWritingVariable(kpSystem, kpType, module, strategyIndex, kpRule, copyVarName, origin, isLeft); } }
public static void SetVariableValue(BaseEvent baseEvent, System.Object value, VariableOrigin origin, bool useObject, EventObjectSetting variableObject, string objectID, StringValue key) { if (value is string || value is bool || value is int || value is float || value is Vector3) { if (VariableOrigin.Local.Equals(origin)) { if (debug) { Debug.Log("Setting local variable " + key + " to " + value); } SetVariableValue(baseEvent.Variables, value, key); } else if (VariableOrigin.Global.Equals(origin)) { if (debug) { Debug.Log("Setting global variable " + key + " to " + value); } SetVariableValue(ORK.Game.Variables, value, key); } else if (VariableOrigin.Object.Equals(origin)) { if (useObject) { List <GameObject> list2 = variableObject.GetObject(baseEvent); for (int j = 0; j < list2.Count; j++) { if (list2[j] != null) { ObjectVariablesComponent[] comps = list2[j]. GetComponentsInChildren <ObjectVariablesComponent>(); for (int k = 0; k < comps.Length; k++) { if (debug) { Debug.Log("Setting object variable " + key + " to " + value); } SetVariableValue(comps[k].GetHandler(), value, key); } } } } else { if (debug) { Debug.Log("Setting scene object variable " + key + " to " + value); } SetVariableValue(ORK.Game.Scene.GetObjectVariables(objectID), value, key); } } } }
public BuildVariable AddVariable(Sort sort, ISymbol symbol, VariableOrigin origin) { var variableId = this.variableIdProvider.GenerateNewId(); var variable = new BuildVariable(variableId, sort, symbol, origin); this.Variables.Add(variable); Contract.Assert(variableId.Value == this.Variables.IndexOf(variable)); return(variable); }
public BuildVariable( BuildVariableId id, Sort sort, ISymbol symbol, VariableOrigin origin) : base(sort) { this.Id = id; this.Symbol = symbol; this.Origin = origin; }
private ITypeModel CreateVariableModel( ITypeModelFactory factory, ITypeSymbol type, ISymbol symbol, VariableOrigin origin) { var variables = factory.GetExpressionSortRequirements(type) .Select(sort => this.Graph.AddVariable(sort, symbol, origin)) .ToArray(); return(factory.GetExpressionModel(type, variables)); }
public static void SetVariableValue(BaseEvent baseEvent, System.Object value, VariableOrigin origin, bool useObject, EventObjectSetting variableObject, string objectID, StringValue key) { //--- Allow any value. Convert to string if not a recognized type: //--- if (value is string || value is bool || value is int || value is float || value is Vector3) { if (VariableOrigin.Local.Equals(origin)) { SetVariableValue(baseEvent.Variables, value, key); } else if (VariableOrigin.Global.Equals(origin)) { SetVariableValue(ORK.Game.Variables, value, key); } else if (VariableOrigin.Object.Equals(origin)) { if (useObject) { List <GameObject> list2 = variableObject.GetObject(baseEvent); for (int j = 0; j < list2.Count; j++) { if (list2[j] != null) { ObjectVariablesComponent[] comps = list2[j]. GetComponentsInChildren <ObjectVariablesComponent>(); for (int k = 0; k < comps.Length; k++) { SetVariableValue(comps[k].GetHandler(), value, key); } } } } else { SetVariableValue(ORK.Game.Scene.GetObjectVariables(objectID), value, key); } } } }
private static void buildCommunicationVariables(SMVModel nuSMV, NuSMV.Module module, KPsystem kpSystem, KpCore.MType type, int strategyIndex, KpCore.Rule rule) { RewriteCommunicationRule rcr = (RewriteCommunicationRule)rule; string varName = ""; VariableOrigin origin = VariableOrigin.Original; bool isLeft = true; //regular left hand-side rules foreach (var leftHRule in rcr.Lhs) { varName = leftHRule.Key; isLeft = true; buildReWritingVariable(kpSystem, type, module, strategyIndex, rule, varName, origin, isLeft); } //regular right hand-side rules foreach (var rigthHRule in rcr.Rhs) { varName = rigthHRule.Key; origin = VariableOrigin.Original; isLeft = false; //first generate original one, then its copy if (!module.isVariableExist(varName)) { buildReWritingVariable(kpSystem, type, module, strategyIndex, rule, varName, origin, isLeft); } string copyVarName = varName + SMVPreFix.COPY; origin = VariableOrigin.Copy; buildReWritingVariable(kpSystem, type, module, strategyIndex, rule, copyVarName, origin, isLeft); } //Targeted rules foreach (var target in rcr.TargetRhs.Values) { TargetedMultiset targetMultiSet = (TargetedMultiset)target; InstanceIdentifier targetTypeIdentifier = (InstanceIdentifier)targetMultiSet.Target; MType targetType = null; foreach (var tempType in kpSystem.Types) { if (tempType.Name == targetTypeIdentifier.Value) { targetType = tempType; } } //for each connected instance of the target type, create a copy variable foreach object in the multiset foreach (var connectedInstance in module.Instance.ConnectedTo) { if (connectedInstance.Module.Type == targetType.Name) { Module targetModule = connectedInstance.Module; Multiset ms = targetMultiSet.Multiset; foreach (var obj in ms.Objects) { varName = obj; Variable targetVariable = new Variable(varName); string currentCpVarName = SMVPreFix.getConnectedCopyCommVarName(varName, targetModule); Variable currentCpVar = new Variable(currentCpVarName); //create original variable inside target module if (!targetModule.isVariableExist(varName)) { setBoundIntType(kpSystem, targetType, targetModule, targetVariable); targetVariable.Behaviour = VariableBehaviour.COMMUNICATION; targetVariable.Origin = VariableOrigin.OriginalCommVar; targetVariable.Init = setOrUpdateInit(targetModule, targetVariable); targetModule.Variables.Add(targetVariable); } else { //if variable is already in target module, then make sure, it is set as communication var. targetVariable = (Variable)targetModule.Variables.First(item => item.Name.Equals(varName)); targetVariable.Behaviour = VariableBehaviour.COMMUNICATION; targetVariable.Origin = VariableOrigin.OriginalCommVar; targetVariable.Init = setOrUpdateInit(targetModule, targetVariable); } //create a varName_InstanceName_TargetModule, variable (as copy) inside current module. if (!module.isVariableExist(currentCpVarName)) { Variable orginalVariable = (Variable)targetModule.getVariable(varName); currentCpVar.Type = orginalVariable.Type; currentCpVar.Behaviour = VariableBehaviour.REWRITING; currentCpVar.Origin = VariableOrigin.CopyOfCommVar; currentCpVar.Init = "0"; module.Variables.Add(currentCpVar); } else { //if variable exists then update the values. currentCpVar = (Variable)module.Variables.First(item => item.Name.Equals(currentCpVarName)); } //add result of rule to caseline BRulesComVar.addCaseLineToCurrentCopyCommVar(targetVariable, currentCpVar, rule, module, targetModule, strategyIndex); } } } } }
private static void buildReWritingVariable(KPsystem kpSystem, KpCore.MType kpType, NuSMV.Module module, int strategyIndex, KpCore.Rule kpRule, string newVarName, VariableOrigin origin, bool isLeft) { Variable newVar = null; //if variable does not exist then create it, if (!module.isVariableExist(newVarName)) { if (origin == VariableOrigin.Original) { newVar = new Variable(newVarName); setBoundIntType(kpSystem, kpType, module, newVar); newVar.Behaviour = VariableBehaviour.REWRITING; newVar.Init = setOrUpdateInit(module, newVar); newVar.Origin = VariableOrigin.Original; if (isLeft) { //if it is on left then add it, but do not add rules to first not-copy variable on right. BRulesStandardVar.addCaseLineToStandardVariable(newVar, kpRule, module, strategyIndex); } } else if (origin == VariableOrigin.Copy) { newVar = new Variable(newVarName); Variable orginalVariable = (Variable)module.getVariable(newVarName.Replace(SMVPreFix.COPY, "")); newVar.Type = orginalVariable.Type; newVar.Behaviour = VariableBehaviour.REWRITING; newVar.Init = "0"; newVar.Origin = VariableOrigin.Copy; //add result of rule to caseline BRulesStandardVar.addCaseLineToStandardVariable(newVar, kpRule, module, strategyIndex); } if (newVar != null) { module.Variables.Add(newVar); } else { throw new Exception("Cannot create variable : " + newVarName); } } else { //bring variable to add new rules. newVar = (Variable)module.Variables.First(item => item.Name.Equals(newVarName)); BRulesStandardVar.addCaseLineToStandardVariable(newVar, kpRule, module, strategyIndex); } }