public virtual Valuation GetClone() { Valuation newEnv = new Valuation(); if (Variables != null) { StringDictionaryWithKey <ExpressionValue> newVars = new StringDictionaryWithKey <ExpressionValue>(Variables); for (int i = 0; i < Variables._entries.Length; i++) { StringDictionaryEntryWithKey <ExpressionValue> pair = Variables._entries[i]; if (pair != null) { newVars._entries[i] = new StringDictionaryEntryWithKey <ExpressionValue>(pair.HashA, pair.HashB, pair.Value.GetClone(), pair.Key); } } newEnv.Variables = newVars; } if (Channels != null) { newEnv.Channels = new Dictionary <string, ChannelQueue>(this.Channels); } return(newEnv); }
public PNValuation GetPNValuationClone() { var newEnv = new PNValuation(); #region Based on Valuation.GetClone() code if (Variables != null) { var newVars = new StringDictionaryWithKey <ExpressionValue>(Variables); for (int i = 0; i < Variables._entries.Length; i++) { StringDictionaryEntryWithKey <ExpressionValue> pair = Variables._entries[i]; if (pair != null) { newVars._entries[i] = new StringDictionaryEntryWithKey <ExpressionValue>(pair.HashA, pair.HashB, pair.Value.GetClone(), pair.Key); } } newEnv.Variables = newVars; } if (Channels != null) { newEnv.Channels = new Dictionary <string, ChannelQueue>(this.Channels); } #endregion newEnv.ValuationToken = new StringDictionaryWithKey <int>(ValuationToken); return(newEnv); }
public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list) { System.Diagnostics.Debug.Assert(list.Count == 0); string name = Event.GetEventName(GlobalEnv); Valuation newGlobleEnv = GlobalEnv.GetVariableClone(); EvaluatorDenotational.Evaluate(AssignmentExpr, newGlobleEnv); //if (LocalVariables != null) if (HasLocalVar) { Valuation tempEnv = GlobalEnv.GetVariableClone(); for (int i = 0; i < tempEnv.Variables._entries.Length; i++) { StringDictionaryEntryWithKey <ExpressionValue> pair = tempEnv.Variables._entries[i]; if (pair != null) { pair.Value = newGlobleEnv.Variables[pair.Key]; } } newGlobleEnv = tempEnv; } string ID = Event.GetEventID(GlobalEnv); if (ID != name) { list.Add(new Configuration(Process, ID, name, newGlobleEnv, true)); } else { list.Add(new Configuration(Process, ID, null, newGlobleEnv, true)); } //return list; }
public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list) { System.Diagnostics.Debug.Assert(list.Count == 0); ChannelQueue Buffer = null; string channelName = this.ChannelName; if (ChannelIndex != null) { int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, GlobalEnv)).Value; if (size >= Specification.ChannelArrayDatabase[ChannelName]) { throw new PAT.Common.Classes.Expressions.ExpressionClass.IndexOutOfBoundsException("Channel index out of bounds for expression " + this.ToString()); } channelName = channelName + "[" + size + "]"; } if (GlobalEnv.Channels.TryGetValue(channelName, out Buffer)) { if (Buffer.Count > 0) { ChannelQueue newBuffer = Buffer.Clone(); ExpressionValue[] values = newBuffer.Dequeue(); if (values.Length == this.ExpressionList.Length) { Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(values.Length); Valuation newChannelEvn = GlobalEnv.GetChannelClone(); newChannelEvn.Channels[channelName] = newBuffer; string eventName = channelName + "?"; string eventID = channelName + "?"; for (int i = 0; i < ExpressionList.Length; i++) { ExpressionValue v = values[i]; if (i == ExpressionList.Length - 1) { eventName += v; eventID += v.ExpressionID; } else { eventName += v + "."; eventID += v.ExpressionID + "."; } if (ExpressionList[i] is Variable) { mapping.Add(ExpressionList[i].ExpressionID, v); } else { if (v.ExpressionID != ExpressionList[i].ExpressionID) { return; //list } } } Expression guard = GuardExpression.ClearConstant(mapping); ExpressionValue value = EvaluatorDenotational.Evaluate(guard, newChannelEvn); if ((value as BoolConstant).Value) { Valuation newGlobleEnv = newChannelEvn.GetVariableClone(); EvaluatorDenotational.Evaluate(AssignmentExpr.ClearConstant(mapping), newGlobleEnv); if (HasLocalVar) { Valuation tempEnv = newChannelEvn.GetVariableClone(); for (int i = 0; i < tempEnv.Variables._entries.Length; i++) { StringDictionaryEntryWithKey <ExpressionValue> pair = tempEnv.Variables._entries[i]; if (pair != null) { pair.Value = newGlobleEnv.Variables[pair.Key]; } } newGlobleEnv = tempEnv; } Process newProcess = mapping.Count > 0 ? Process.ClearConstant(mapping) : Process; if (eventID != eventName) { list.Add(new Configuration(newProcess, eventID, eventName, newGlobleEnv, false)); } else { list.Add(new Configuration(newProcess, eventID, null, newGlobleEnv, false)); } } } } } //return list; }
public override void SyncInput(ConfigurationWithChannelData eStep, List <Configuration> list) { string channelName = this.ChannelName; if (ChannelIndex != null) { int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, eStep.GlobalEnv)).Value; if (size >= Specification.ChannelArrayDatabase[ChannelName]) { throw new PAT.Common.Classes.Expressions.ExpressionClass.IndexOutOfBoundsException("Channel index out of bounds for expression " + this.ToString()); } channelName = channelName + "[" + size + "]"; } //List<Configuration> list = new List<Configuration>(1); if (eStep.ChannelName == channelName && eStep.Expressions.Length == ExpressionList.Length) { Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(eStep.Expressions.Length); for (int i = 0; i < ExpressionList.Length; i++) { Expression v = eStep.Expressions[i]; if (ExpressionList[i] is Variable) { mapping.Add(ExpressionList[i].ExpressionID, v); } else { if (v.ExpressionID != ExpressionList[i].ExpressionID) { return; } } } Expression guard = GuardExpression.ClearConstant(mapping); ExpressionValue value = EvaluatorDenotational.Evaluate(guard, eStep.GlobalEnv); if ((value as BoolConstant).Value) { Valuation newGlobleEnv = eStep.GlobalEnv.GetVariableClone(); EvaluatorDenotational.Evaluate(AssignmentExpr.ClearConstant(mapping), newGlobleEnv); if (HasLocalVar) { Valuation tempEnv = eStep.GlobalEnv.GetVariableClone(); for (int i = 0; i < tempEnv.Variables._entries.Length; i++) { StringDictionaryEntryWithKey <ExpressionValue> pair = tempEnv.Variables._entries[i]; if (pair != null) { pair.Value = newGlobleEnv.Variables[pair.Key]; } } newGlobleEnv = tempEnv; } Configuration vm; if (mapping.Count > 0) { vm = new Configuration(Process.ClearConstant(mapping), null, null, newGlobleEnv, false); } else { vm = new Configuration(Process, null, null, newGlobleEnv, false); } list.Add(vm); } } //return list; }
public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list) { System.Diagnostics.Debug.Assert(list.Count == 0); Valuation globalEnv = GlobalEnv; ChannelQueue Buffer = null; string channelName = this.ChannelName; if (ChannelIndex != null) { int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, GlobalEnv)).Value; if (size >= Specification.ChannelArrayDatabase[ChannelName]) { throw new PAT.Common.Classes.Expressions.ExpressionClass.IndexOutOfBoundsException("Channel index out of bounds for expression " + this.ToString()); } channelName = channelName + "[" + size + "]"; } if (globalEnv.Channels.TryGetValue(channelName, out Buffer)) { if (Buffer.Count < Buffer.Size) { ExpressionValue[] values = new ExpressionValue[ExpressionList.Length]; string eventName = channelName + "!"; string eventID = channelName + "!"; for (int i = 0; i < ExpressionList.Length; i++) { values[i] = EvaluatorDenotational.Evaluate(ExpressionList[i], globalEnv); if (i == ExpressionList.Length - 1) { eventName += values[i].ToString(); eventID += values[i].ExpressionID; } else { eventName += values[i].ToString() + "."; eventID += values[i].ExpressionID + "."; } } ChannelQueue newBuffer = Buffer.Clone(); newBuffer.Enqueue(values); globalEnv = globalEnv.GetChannelClone(); globalEnv.Channels[channelName] = newBuffer; //program update Valuation newGlobleEnv = globalEnv.GetVariableClone(); EvaluatorDenotational.Evaluate(AssignmentExpr, newGlobleEnv); if (HasLocalVar) { Valuation tempEnv = globalEnv.GetVariableClone(); for (int i = 0; i < tempEnv.Variables._entries.Length; i++) { StringDictionaryEntryWithKey <ExpressionValue> pair = tempEnv.Variables._entries[i]; if (pair != null) { pair.Value = newGlobleEnv.Variables[pair.Key]; } } newGlobleEnv = tempEnv; } //program update if (eventID != eventName) { list.Add(new Configuration(Process, eventID, eventName, newGlobleEnv, false)); } else { list.Add(new Configuration(Process, eventID, null, newGlobleEnv, false)); } } } // return list; }
public override void SyncOutput(Valuation GlobalEnv, List <ConfigurationWithChannelData> list) { //List<ConfigurationWithChannelData> list = new List<ConfigurationWithChannelData>(1); string channelName = this.ChannelName; if (ChannelIndex != null) { int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, GlobalEnv)).Value; if (size >= Specification.ChannelArrayDatabase[ChannelName]) { throw new PAT.Common.Classes.Expressions.ExpressionClass.IndexOutOfBoundsException("Channel index out of bounds for expression " + this.ToString()); } channelName = channelName + "[" + size + "]"; } if (SpecificationBase.SyncrhonousChannelNames.Contains(channelName)) { string eventName = channelName; string eventID = channelName; Expression[] newExpressionList = new Expression[ExpressionList.Length]; for (int i = 0; i < ExpressionList.Length; i++) { newExpressionList[i] = EvaluatorDenotational.Evaluate(ExpressionList[i], GlobalEnv); eventName += "." + newExpressionList[i]; eventID += "." + newExpressionList[i].ExpressionID; } Valuation newGlobleEnv = GlobalEnv.GetVariableClone(); EvaluatorDenotational.Evaluate(AssignmentExpr, newGlobleEnv); if (HasLocalVar) { Valuation tempEnv = GlobalEnv.GetVariableClone(); for (int i = 0; i < tempEnv.Variables._entries.Length; i++) { StringDictionaryEntryWithKey <ExpressionValue> pair = tempEnv.Variables._entries[i]; if (pair != null) { pair.Value = newGlobleEnv.Variables[pair.Key]; } } newGlobleEnv = tempEnv; } if (eventID != eventName) { list.Add(new ConfigurationWithChannelData(Process, eventID, eventName, newGlobleEnv, false, channelName, newExpressionList)); } else { list.Add(new ConfigurationWithChannelData(Process, eventID, null, newGlobleEnv, false, channelName, newExpressionList)); } } //return list; }