public override void Initialize(SpecificationBase spec)
        {
            //initialize the ModelCheckingOptions
            base.Initialize(spec);

            Specification Spec = spec as Specification;
            ReachableStateCondition = Spec.DeclarationDatabase[ReachableStateLabel];

            List<string> varList = Process.GetGlobalVariables();
            varList.AddRange(ReachableStateCondition.GetVars());
            varList.AddRange(ConstraintCondition.GetVars());

            Valuation GlobalEnv = Spec.SpecValuation.GetVariableChannelClone(varList, Process.GetChannels());

            //Initialize InitialStep
            InitialStep = new Configuration(Process, Constants.INITIAL_EVENT, null, GlobalEnv, false);

            MustAbstract = Process.MustBeAbstracted();

            if (MustAbstract)
            {
                throw new ParsingException(
                    "Process " + StartingProcess +
                    " has infinite states and therefore can not be used to assert reachability with MIN/MAX constraints!",
                    AssertToken);
            }
        }
Пример #2
0
        public override void Initialize(SpecificationBase spec)
        {
            Specification Spec = spec as Specification;
            List<string> varList = Process.GetGlobalVariables();

            BA.Initialize(Spec.DeclarationDatabase);

            foreach (KeyValuePair<string, Expression> pair in BA.DeclarationDatabase)
                varList.AddRange(pair.Value.GetVars());

            Valuation GlobalEnv = Spec.SpecValuation.GetVariableChannelClone(varList, Process.GetChannels());
            InitialStep = new Configuration(Process, Constants.INITIAL_EVENT, null, GlobalEnv, false);

            MustAbstract = Process.MustBeAbstracted();

            base.Initialize(spec);
        }
Пример #3
0
        public override void Initialize(SpecificationBase spec)
        {
            //initialize the ModelCheckingOptions
            base.Initialize(spec);

            Specification Spec = spec as Specification;
            ReachableStateCondition = Spec.DeclarationDatabase[ReachableStateLabel];

            List<string> varList = Process.GetGlobalVariables();
            varList.AddRange(ReachableStateCondition.GetVars());

            Valuation GlobalEnv = Spec.SpecValuation.GetVariableChannelClone(varList, Process.GetChannels());

            //Initialize InitialStep
            InitialStep = new Configuration(Process, Constants.INITIAL_EVENT, null, GlobalEnv, false);

            MustAbstract = Process.MustBeAbstracted();
        }
Пример #4
0
        private void SynchronousChannelInputOutput(List<Configuration> returnList, int i, Valuation GlobalEnv, string evt)
        {
            List<ConfigurationWithChannelData> outputs = new List<ConfigurationWithChannelData>();
                Processes[i].SyncOutput(GlobalEnv,outputs);

            foreach (ConfigurationWithChannelData vm in outputs)
            {
                if(evt != null && vm.Event != evt)
                {
                    continue;
                }

                Process output = vm.Process;

                for (int k = 0; k < Processes.Count; k++)
                {
                    if (k != i)
                    {
                        List<Configuration> syncedProcess = new List<Configuration>();
                        Processes[k].SyncInput(vm, syncedProcess);

                        foreach (Configuration p in syncedProcess)
                        {
                            List<Process> newProcess = new List<Process>(Processes.Count);
                            newProcess.AddRange(Processes);
                            newProcess[i] = output;
                            newProcess[k] = p.Process;

                            IndexParallel interleave = new IndexParallel(newProcess, Alphabets);
                            Configuration newStep = new Configuration(interleave, vm.Event, vm.DisplayName, GlobalEnv, false);
                            newStep.IsAtomic = vm.IsAtomic || p.IsAtomic;

                            if (AssertionBase.CalculateParticipatingProcess)
                            {
                                newStep.ParticipatingProcesses = new string[]{i.ToString(), k.ToString()};
                            }

                            returnList.Add(newStep);
                        }
                    }
                }
            }
        }
Пример #5
0
        public override void MoveOneStep(Valuation GlobalEnv, List<Configuration> list)
        {
            if (Alphabets == null)
            {
                IdentifySharedEventsAndVariables();
            }

            List<string> barrierEnabledEvents = new List<string>();
            List<string> disabled = new List<string>();

            System.Diagnostics.Debug.Assert(list.Count == 0);

            Dictionary<string, List<Configuration>> syncSteps = new Dictionary<string, List<Configuration>>();
            for (int i = 0; i < Processes.Count; i++)
            {
                //Process process = Processes[i];
                List<Configuration> list1 = new List<Configuration>();
                Processes[i].MoveOneStep(GlobalEnv, list1);

                List<string> enabled = new List<string>(list1.Count);

                for (int j = 0; j < list1.Count; j++)
                {
                    Configuration step = list1[j];

                    string evt = step.Event;

                    //if it happens that a data operation shares the same name with the sync event, treat it as an interleave case
                    if (!Alphabets[i].Contains(evt) || step.IsDataOperation)
                    {
                        if (AssertionBase.CalculateParticipatingProcess)
                        {
                            step.ParticipatingProcesses = new string[] { i.ToString() };
                        }

                        List<Process> newProcess = new List<Process>(Processes.Count);
                        newProcess.AddRange(Processes);
                        newProcess[i] = step.Process;

                        step.Process = new IndexParallel(newProcess, Alphabets);
                        list.Add(step);
                    }
                    else
                    {
                        enabled.Add(evt);
                        string key = evt + Constants.SEPARATOR + i;

                        if (!syncSteps.ContainsKey(key))
                        {
                            syncSteps.Add(key, new List<Configuration>());
                        }

                        syncSteps[key].Add(step);

                        if (!barrierEnabledEvents.Contains(evt)) //Alphabets[i].Contains(evt) &&
                        {
                            barrierEnabledEvents.Add(evt);
                        }
                    }
                }

                //int alphabetsCount = Alphabets[i].Count;
                foreach (string s in Alphabets[i])
                {
                    if (!enabled.Contains(s) && !disabled.Contains(s))
                    {
                        disabled.Add(s);
                    }
                }

                //to check whether there are synchoronous channel input/output
                if (Specification.HasSyncrhonousChannel)
                {
                    SynchronousChannelInputOutput(list, i, GlobalEnv, null);
                }
            }

            int disabledCount = disabled.Count;
            for (int i = 0; i < disabledCount; i++)
            {
                barrierEnabledEvents.Remove(disabled[i]);
            }

            List<bool> isAtomic = null;

            //move the barrier synchronization events.
            foreach (string evt in barrierEnabledEvents)
            {
                //maps an event to the list of resulting processes.
                List<List<Process>> moves = new List<List<Process>>();
                moves.Add(new List<Process>());

                if (SpecificationBase.HasAtomicEvent)
                {
                    isAtomic = new List<bool>();
                    isAtomic.Add(false);
                }

                List<string> participatingProcesses = new List<string>();

                for (int i = 0; i < Processes.Count; i++)
                {
                    if (Alphabets[i].Contains(evt))
                    {
                        participatingProcesses.Add(i.ToString());

                        List<Configuration> steps = syncSteps[evt + Constants.SEPARATOR + i]; //Processes[i].MoveOneStep(eStep, evt);

                        List<List<Process>> toAdd = new List<List<Process>>(moves.Count);

                        foreach (Configuration step in steps)
                        {
                            //if it happens that a data operation shares the same name with the sync event, ignore
                            if (!step.IsDataOperation)
                            {
                                if (moves[0].Count == i)
                                {
                                    foreach (List<Process> list2 in moves)
                                    {
                                        list2.Add(step.Process);
                                        if (step.IsAtomic)
                                        {
                                            for (int j = 0; j < isAtomic.Count; j++)
                                            {
                                                isAtomic[j] = true;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //If there non-determinism, clone and then add.

                                    for (int k = 0; k < moves.Count; k++)
                                    {
                                        List<Process> list2 = moves[k];

                                        List<Process> newProcList = new List<Process>();

                                        for (int j = 0; j < list2.Count - 1; j++)
                                        {
                                            newProcList.Add(list2[j]);
                                        }

                                        newProcList.Add(step.Process);
                                        toAdd.Add(newProcList);

                                        if (SpecificationBase.HasAtomicEvent)
                                        {
                                            if (!isAtomic[k])
                                            {
                                                isAtomic.Add(step.IsAtomic);
                                            }
                                            else
                                            {
                                                isAtomic.Add(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        moves.AddRange(toAdd);
                    }
                    else
                    {
                        foreach (List<Process> move in moves)
                        {
                            move.Add(Processes[i]);
                        }
                    }
                }

                for (int i = 0; i < moves.Count; i++)
                {
                    List<Process> list2 = moves[i];
                    IndexParallel para = new IndexParallel(list2, Alphabets);

                    Configuration tmpStep = new Configuration(para, evt, null, GlobalEnv, false);

                    if (SpecificationBase.HasAtomicEvent)
                    {
                        tmpStep.IsAtomic = isAtomic[i];
                    }

                    if (AssertionBase.CalculateParticipatingProcess)
                    {
                        tmpStep.ParticipatingProcesses = participatingProcesses.ToArray();
                    }

                    list.Add(tmpStep);
                }
            }

            //return returnList;
        }
Пример #6
0
        public override void MoveOneStep(Valuation GlobalEnv, List<Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            bool allTerminationCount = true;
            bool hasAtomicTermination = false;

            for (int i = 0; i < Processes.Count; i++)
            {
                Process process = Processes[i];
                List<Configuration> list1 = new List<Configuration>();
                process.MoveOneStep(GlobalEnv, list1);
                bool hasTermination = false;

                for (int j = 0; j < list1.Count; j++)
                {
                    Configuration step = list1[j];

                    if (step.Event == Constants.TERMINATION)
                    {
                        hasTermination = true;

                        if (step.IsAtomic)
                        {
                            hasAtomicTermination = true;
                        }
                    }
                    else
                    {
                        if (AssertionBase.CalculateParticipatingProcess)
                        {
                            step.ParticipatingProcesses = new string[] {i.ToString()};
                        }

                        List<Process> newProcess = new List<Process>(Processes.Count);
                        newProcess.AddRange(Processes);
                        newProcess[i] = step.Process;

                        IndexInterleave interleave = new IndexInterleave(newProcess);
                        step.Process = interleave;
                        list.Add(step);
                    }
                }

                //to check whether there are synchoronous channel input/output
                if (Specification.HasSyncrhonousChannel)
                {
                    SynchronousChannelInputOutput(list, i, GlobalEnv, null);
                }

                if (!hasTermination)
                {
                    allTerminationCount = false;
                }
            }

            if (allTerminationCount)
            {
                Configuration temp = new Configuration(new Stop(), Constants.TERMINATION, null, GlobalEnv, false);

                if (hasAtomicTermination)
                {
                    temp.IsAtomic = true;
                }

                if (AssertionBase.CalculateParticipatingProcess)
                {
                    temp.ParticipatingProcesses = new string[Processes.Count];
                    for (int i = 0; i < Processes.Count; i++)
                    {
                        temp.ParticipatingProcesses[i] = i.ToString();
                    }
                }
                list.Add(temp);
            }

            //return returnList;
        }
Пример #7
0
        private void SynchronousChannelInputOutput(List<Configuration> returnList, int i, Valuation GlobalEnv, string evt)
        {
            List<ConfigurationWithChannelData> outputs = new List<ConfigurationWithChannelData>();
            Processes[i].SyncOutput(GlobalEnv, outputs);

            List<Dictionary<string, int>> nextProcessCounters1 =
                Common.Classes.Ultility.Ultility.ProcessCounterDecrement(Common.Classes.Ultility.Ultility.CutNumber, ProcessesCounter, Processes[i].ProcessID, 1);

            foreach (ConfigurationWithChannelData vm in outputs)
            {
                if (evt != null & vm.Event != evt)
                {
                    continue;
                }

                for (int k = 0; k < Processes.Count; k++)
                {
                    string id = Processes[k].ProcessID;

                    if (k != i || (k == i && (ProcessesCounter[id] > 1 || ProcessesCounter[id] == -1)))
                    {
                        List<Configuration> syncedProcess = new List<Configuration>();
                        Processes[k].SyncInput(vm, syncedProcess);
                        if (syncedProcess.Count > 0)
                        {
                            if (k == i)
                            {
                                List<Dictionary<string, int>> nextProcessCountersInner =
                                    Common.Classes.Ultility.Ultility.ProcessCounterDecrement(Common.Classes.Ultility.Ultility.CutNumber, ProcessesCounter,
                                                                                     Processes[i].ProcessID, 2);
                                foreach (Configuration p in syncedProcess)
                                {
                                    foreach (Dictionary<string, int> ints in nextProcessCountersInner)
                                    {
                                        Dictionary<string, int> dictionaryNew =
                                            new Dictionary<string, int>(ints);

                                        List<Process> newProcess = new List<Process>(Processes);

                                        AddOneProcess(newProcess, p.Process, dictionaryNew);
                                        AddOneProcess(newProcess, vm.Process, dictionaryNew);
                                        Configuration newStep = new Configuration(new IndexInterleaveAbstract(newProcess, dictionaryNew), vm.Event,vm.DisplayName, GlobalEnv, false);
                                        newStep.IsAtomic = vm.IsAtomic || p.IsAtomic;

                                        if (AssertionBase.CalculateParticipatingProcess)
                                        {
                                            newStep.ParticipatingProcesses = new string[]
                                                                             {
                                                                                 Processes[i].ProcessID,
                                                                                 Processes[k].ProcessID
                                                                             };
                                        }

                                        returnList.Add(newStep);
                                    }
                                }
                            }
                            else
                            {
                                foreach (Dictionary<string, int> ints in nextProcessCounters1)
                                {
                                    List<Dictionary<string, int>> nextProcessCountersInner =
                                        Common.Classes.Ultility.Ultility.ProcessCounterDecrement(Common.Classes.Ultility.Ultility.CutNumber, ints, id, 1);

                                    foreach (Configuration p in syncedProcess)
                                    {
                                        foreach (Dictionary<string, int> dictionary in nextProcessCountersInner)
                                        {
                                            List<Process> newProcess = new List<Process>(Processes);

                                            AddOneProcess(newProcess, p.Process, dictionary);
                                            AddOneProcess(newProcess, vm.Process, dictionary);

                                            Configuration newStep =
                                                new Configuration(new IndexInterleaveAbstract(newProcess, dictionary),vm.Event, vm.DisplayName, GlobalEnv, false);
                                            newStep.IsAtomic = vm.IsAtomic || p.IsAtomic;

                                            if (AssertionBase.CalculateParticipatingProcess)
                                            {
                                                newStep.ParticipatingProcesses = new string[]
                                                                             {
                                                                                 Processes[i].ProcessID,
                                                                                 Processes[k].ProcessID
                                                                             };
                                            }

                                            returnList.Add(newStep);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #8
0
        public override void MoveOneStep(Valuation GlobalEnv, List<Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            int TerminationCount = 0;
            bool hasAtomicTermination = false;

            List<Dictionary<string, int>> nextProcessCounters = null;

            for (int i = 0; i < Processes.Count; i++)
            {
                Process process = Processes[i];
                List<Configuration> list1 = new List<Configuration>();
                process.MoveOneStep(GlobalEnv, list1);

                bool hasTermination = false;

                if (list1.Count> 0)
                {
                    nextProcessCounters = Common.Classes.Ultility.Ultility.ProcessCounterDecrement(Common.Classes.Ultility.Ultility.CutNumber, ProcessesCounter, process.ProcessID, 1);
                }

                for (int j = 0; j < list1.Count; j++)
                {
                    Configuration step = list1[j];

                    if (step.Event == Constants.TERMINATION)
                    {
                        hasTermination = true;

                        if (step.IsAtomic)
                        {
                            hasAtomicTermination = true;
                        }
                    }
                    else
                    {
                        foreach (Dictionary<string, int> ints in nextProcessCounters)
                        {
                            Dictionary<string, int> listInstance = new Dictionary<string, int>(ints);

                            List<Process> newProcess = new List<Process>(Processes);

                            AddOneProcess(newProcess, step.Process, listInstance);

                            IndexInterleaveAbstract interleave = new IndexInterleaveAbstract(newProcess, listInstance);
                            Configuration newStep = new Configuration(interleave, step.Event, step.DisplayName, step.GlobalEnv, step.IsDataOperation);
                            newStep.IsAtomic = step.IsAtomic;

                            if (AssertionBase.CalculateParticipatingProcess)
                            {
                                newStep.ParticipatingProcesses = new string[] { process.ProcessID };
                            }

                            list.Add(newStep);
                        }
                    }
                }

                if (hasTermination)
                {
                    TerminationCount++;
                }

                //to check whether there are synchoronous channel input/output
                if (Specification.HasSyncrhonousChannel)
                {
                    SynchronousChannelInputOutput(list, i, GlobalEnv, null);
                }
            }

            if (TerminationCount == Processes.Count)
            {
                Configuration temp = new Configuration(new Stop(), Constants.TERMINATION, null, GlobalEnv, false);

                if(hasAtomicTermination)
                {
                    temp.IsAtomic = true;
                }

                if (AssertionBase.CalculateParticipatingProcess)
                {
                    temp.ParticipatingProcesses = new string[Processes.Count];
                    for (int i = 0; i < Processes.Count; i++)
                    {
                        temp.ParticipatingProcesses[i] = i.ToString();
                    }
                }
                list.Add(temp);
            }

            //return returnList;
        }
Пример #9
0
        public override void SyncInput(ConfigurationWithChannelData eStep, List<Configuration> list)
        {
            //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)
                {
                    Configuration vm;
                    if (mapping.Count > 0)
                    {
                        vm = new Configuration(Process.ClearConstant(mapping), null, null, eStep.GlobalEnv, false);
                    }
                    else
                    {
                        vm = new Configuration(Process, null, null, eStep.GlobalEnv, false);
                    }

                    list.Add(vm);
                }
            }

            //return list;
        }
Пример #10
0
        public override void SyncInput(ConfigurationWithChannelData eStep, List<Configuration> list)
        {
            //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); //.GetID()
                    }
                    else
                    {
                        if (v.ExpressionID != ExpressionList[i].ExpressionID) //.GetID()
                        {
                            return ;
                        }
                    }
                }

                Configuration vm;
                if (mapping.Count > 0)
                {
                    vm = new Configuration(Process.ClearConstant(mapping), null, null, eStep.GlobalEnv, false);
                }
                else
                {
                    vm = new Configuration(Process, null, null, eStep.GlobalEnv, false);
                }

                list.Add(vm);
            }

            //return list;
        }