Exemplo n.º 1
0
        /// <summary>
        /// Line 1-2
        /// </summary>
        /// <returns></returns>
        private static void SetInitPartition(SymbolicLTS actionbasedLTS)
        {
            //Line 1
            partition = new List <Block>();
            relation  = new SimRel(1);

            state2Block = new Block[lts.numStates];

            foreach (var pair in actionbasedLTS.mapOldLoc2NewStates)
            {
                List <State> statesSameLoc = pair.Value;

                if (statesSameLoc.Count > 0)
                {
                    List <int> states   = new List <int>();
                    Block      newBlock = new Block(lts.numSymbols, lts.numStates, states);
                    newBlock.index = relation.NewEntry();

                    foreach (var state in statesSameLoc)
                    {
                        states.Add(stateMapping[state]);
                        state2Block[stateMapping[state]] = newBlock;
                    }

                    partition.Add(newBlock);

                    relation.SetRelation(newBlock.index, newBlock.index, true);
                }
            }

            //Line 2-4
            foreach (var B in partition)
            {
                for (int a = 0; a < lts.numSymbols; a++)
                {
                    List <int>[] post_a = lts.DataPost(a);
                    List <int>[] pre_a  = lts.dataPre[a];

                    //Line 3
                    foreach (var v in delta1[a])
                    {
                        //transition v-a-q
                        foreach (var q in post_a[v])
                        {
                            //q has relation to B
                            if (relation.GetRelation(B.index, GetBlock(q).index))
                            {
                                B.relCount.Incr(a, v);
                            }
                        }
                    }

                    tmp = new bool[lts.numStates];
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        tmp[i] = true;
                    }

                    HashSet <int> remove = new HashSet <int>();
                    foreach (var c in partition)
                    {
                        if (relation.GetRelation(B.index, c.index))
                        {
                            foreach (var r in c.states)
                            {
                                foreach (var q in pre_a[r])
                                {
                                    //q-a-r
                                    //state q has transition a to a state in block c having relation with B
                                    tmp[q] = false;
                                }
                            }
                        }
                    }

                    for (int i = 0; i < tmp.Length; i++)
                    {
                        if (tmp[i])
                        {
                            remove.Add(i);
                        }
                    }

                    B.remove[a] = remove;
                    if (remove.Count > 0)
                    {
                        NewTask(a, B);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// List of states in the same location
        /// </summary>
        /// <param name="states"></param>
        private static void Initalize(List <State> states)
        {
            ResetData();

            //Use integer numbers for state and labels
            List <Transition> transitions          = new List <Transition>();
            List <int>        statesInSameLoc      = new List <int>();
            List <int>        statesInDifferentLoc = new List <int>();

            foreach (var state in states)
            {
                statesInSameLoc.Add(stateMapping.Count);
                stateMapping.Add(state, stateMapping.Count);

                transitions.AddRange(state.OutgoingTransitions);
            }

            foreach (var transition in transitions)
            {
                string label = transition.GetTransitionLabel();

                if (!labelMapping.ContainsKey(label))
                {
                    labelMapping.Add(label, labelMapping.Count);
                }

                if (!stateMapping.ContainsKey(transition.ToState))
                {
                    statesInDifferentLoc.Add(stateMapping.Count);
                    stateMapping.Add(transition.ToState, stateMapping.Count);
                }
            }


            int nStates = stateMapping.Count;
            int nLabels = labelMapping.Count;


            Lts result = new Lts(nLabels, nStates);

            delta  = new HashSet <int> [nLabels];
            delta1 = new HashSet <int> [nLabels];

            for (int i = 0; i < nLabels; i++)
            {
                delta[i]  = new HashSet <int>();
                delta1[i] = new HashSet <int>();
            }

            foreach (var transition in transitions)
            {
                int q = stateMapping[transition.FromState];
                int a = labelMapping[transition.GetTransitionLabel()];
                int r = stateMapping[transition.ToState];
                result.NewTransition(q, a, r);

                //
                delta[a].Add(r);
                delta1[a].Add(q);
            }

            lts = result;

            //
            //Line 1
            state2Block = new Block[lts.numStates];

            Block blockOfStateSameLoc = new Block(lts.numSymbols, lts.numStates, statesInSameLoc);

            blockOfStateSameLoc.index = relation.NewEntry();

            foreach (var state in statesInSameLoc)
            {
                state2Block[state] = blockOfStateSameLoc;
            }

            partition.Add(blockOfStateSameLoc);

            relation.SetRelation(blockOfStateSameLoc.index, blockOfStateSameLoc.index, true);

            foreach (var state in statesInDifferentLoc)
            {
                Block blockSingleState = new Block(lts.numSymbols, lts.numStates, new List <int>()
                {
                    state
                });
                blockSingleState.index = relation.NewEntry();

                state2Block[state] = blockOfStateSameLoc;

                partition.Add(blockSingleState);
                tempParition.Add(blockSingleState);
                relation.SetRelation(blockSingleState.index, blockSingleState.index, true);
            }

            //Line 2-4
            foreach (var B in partition)
            {
                for (int a = 0; a < lts.numSymbols; a++)
                {
                    List <int>[] post_a = lts.DataPost(a);
                    List <int>[] pre_a  = lts.dataPre[a];

                    //Line 3
                    foreach (var v in delta1[a])
                    {
                        //transition v-a-q
                        foreach (var q in post_a[v])
                        {
                            //q has relation to B
                            if (relation.GetRelation(B.index, GetBlock(q).index))
                            {
                                B.relCount.Incr(a, v);
                            }
                        }
                    }

                    tmp = new bool[lts.numStates];
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        tmp[i] = true;
                    }

                    HashSet <int> remove = new HashSet <int>();
                    foreach (var c in partition)
                    {
                        if (relation.GetRelation(B.index, c.index))
                        {
                            foreach (var r in c.states)
                            {
                                foreach (var q in pre_a[r])
                                {
                                    //q-a-r
                                    //state q has transition a to a state in block c having relation with B
                                    tmp[q] = false;
                                }
                            }
                        }
                    }

                    for (int i = 0; i < tmp.Length; i++)
                    {
                        if (tmp[i])
                        {
                            remove.Add(i);
                        }
                    }

                    B.remove[a] = remove;
                    if (remove.Count > 0)
                    {
                        NewTask(a, B);
                    }
                }
            }
        }