예제 #1
0
        /// <summary> Builds the output objects from the internal state list.</summary>
        /// <throws>  IllegalArgumentException if formula has invalid syntax  </throws>
        private static BuchiAutomata BuildBA()
        {
            List <string> initial = new List <string>(4);

            PAT.Common.Classes.DataStructure.Set <string> states = new PAT.Common.Classes.DataStructure.Set <string>();
            List <Transition> transitions = new List <Transition>();
            List <string>     accept      = new List <string>();

            Dictionary <String, string> statesHash = new Dictionary <String, string>();

            //in the following, all "System.IntPtr" values are actually pointers in C !
            //dummy node in the circular list of states
            BState root = ltl2ba.main.GetBstates();

            //int count = 0;
            //if there was no error and so we have states
            if (root != null)
            {
                int      id        = ltl2ba.main.GetSymtemID();
                string[] allLabels = new string[id];

                for (int i = 0; i < id; i++)
                {
                    allLabels[i] = ltl2ba.main.GetSystemString(i).Trim('"');
                }

                //iterate over state list
                for (BState pSourceState = root.nxt; pSourceState != ltl2ba.main.GetBstates(); pSourceState = pSourceState.nxt)
                {
                    bool isInitial = (pSourceState.id == STATE_ID_INITIAL_STATE);

                    bool isFinal = pSourceState.final == ltl2ba.main.GetAccept();

                    string label = pSourceState.id + (isInitial ? Constants.INIT_STATE : "") + (isFinal ? Constants.ACCEPT_STATE : "");

                    string sourceState;

                    //take care that equal states are unique
                    if (statesHash.ContainsKey(label))
                    {
                        sourceState = statesHash[label];
                    }
                    else
                    {
                        sourceState = label; //new State(, isFinal, isInitial);
                        statesHash.Add(label, sourceState);

                        states.Add(sourceState);

                        if (isInitial)
                        {
                            initial.Add(sourceState);
                        }

                        if (isFinal)
                        {
                            accept.Add(sourceState);
                        }
                    }

                    BTrans troot = pSourceState.trans;

                    for (BTrans pTransition = troot.nxt; pTransition != troot; pTransition = pTransition.nxt)
                    {
                        BState pTargetState = pTransition.to;

                        isInitial = (pTargetState.id == STATE_ID_INITIAL_STATE);
                        isFinal   = (pTargetState.final == ltl2ba.main.GetAccept());

                        label = pTargetState.id + (isInitial ? Constants.INIT_STATE : "") + (isFinal ? Constants.ACCEPT_STATE : "");

                        string targetState;

                        //take care that equal states are unique
                        if (statesHash.ContainsKey(label))
                        {
                            targetState = statesHash[label];
                        }
                        else
                        {
                            targetState = label; // new State(label, isFinal, isInitial);
                            statesHash.Add(label, targetState);
                            states.Add(targetState);

                            if (isInitial)
                            {
                                initial.Add(targetState);
                            }

                            if (isFinal)
                            {
                                accept.Add(targetState);
                            }
                        }

                        //it is hashset in java before
                        PAT.Common.Classes.DataStructure.Set <Proposition> labels = new PAT.Common.Classes.DataStructure.Set <Proposition>();

                        if (ltl2ba.main.BtransPos(pTransition) == 0 && ltl2ba.main.BtransNeg(pTransition) == 0)
                        {
                            // we have a "Sigma" edge
                            labels.Add(SIGMA_PROPOSITION);
                        }
                        else
                        {
                            for (int i = 0; i < allLabels.Length; i++)
                            {
                                if ((ltl2ba.main.BtransPos(pTransition) & (1 << i)) > 0)
                                {
                                    labels.Add(new Proposition(allLabels[i], false));
                                }
                                if ((ltl2ba.main.BtransNeg(pTransition) & (1 << i)) > 0)
                                {
                                    Proposition l = new Proposition(allLabels[i], true);
                                    labels.Add(l);
                                }
                            }
                        }

                        PersonComparer p = new PersonComparer();
                        labels.Sort(p);

                        Transition transition = new Transition(labels, sourceState, targetState);
                        transitions.Add(transition);
                    }
                }
            }
            else
            {
                throw new ArgumentException("invalid formula");
            }

            //fair.Add(accept);
            return(new BuchiAutomata(initial, states.ToArray(), transitions.ToArray(), accept.ToArray()));
        }
예제 #2
0
        private LTLNode createNodeFromLabel(Proposition p)
        {
            if (p.IsSigmal)
            {
                return new LTLNode(type_t.T_TRUE, null, null);
            }

            if (p.Negated)
            {
                int ap_i = _nba.nba_i_getAPSet().find(p.Label);
                return new LTLNode(type_t.T_NOT, new LTLNode(ap_i));
            }
            else
            {
                int ap_i = _nba.nba_i_getAPSet().find(p.Label);
                return new LTLNode(ap_i);
            }
        }