Ejemplo n.º 1
0
        public bool Equals(ConfigurationBase other)
        {
            if ((object)other == null)
                return false;

            return this.GlobalEnv.GetID() == other.GlobalEnv.GetID();
        }
Ejemplo n.º 2
0
 public TarjanThread(ConfigurationBase initialStep, BuchiAutomata ba, PATThreadPool threadPool, FairnessType FairnessType)
 {
     this.initialStep = initialStep;
     this.VerificationResult = VerificationResultType.UNKNOWN;
     this.BA = ba;
     this.ThreadPool = threadPool;
     this.FairnessType = FairnessType;
     this.FairSCC = null;
     this.JobFinished = false;
 }
Ejemplo n.º 3
0
        public void GetCounterxampleString(StringBuilder sb)
        {
            if (GenerateCounterExample)
            {
                sb.Append("<");

                bool hasVisibleEvent = false;
                for (int i = 0; i < CounterExampleTrace.Count; i++)
                {
                    ConfigurationBase step = CounterExampleTrace[i];
                    if (step.Event == Constants.INITIAL_EVENT)
                    {
                        sb.Append(step.Event);
                    }
                    else
                    {
                        sb.Append(" -> ");

                        if (LoopIndex >= 0 && i == LoopIndex)
                        {
                            sb.Append("(");
                        }

                        sb.Append(step.GetDisplayEvent());

                        if (step.Event != Constants.TAU && i >= LoopIndex && LoopIndex >= 0)
                        {
                            hasVisibleEvent = true;
                        }
                    }
                }

                if (LoopIndex >= 0 && !hasVisibleEvent)
                {
                    sb.Append(" -> (" + Constants.TAU + " -> ");
                }

                if (LoopIndex >= 0)
                {
                    sb.Append(")*");
                }

                sb.AppendLine(">");
            }
            else
            {
                sb.AppendLine("Counterexample generation is ignored.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// To get all states which can be reached by tau-transitions only; meanwhile, identify which of them are divergent states.
        /// </summary>
        /// <param name="States"></param>
        /// <returns></returns>
        private static bool IsDivergent(ConfigurationBase States)
        {
            Dictionary<string, int[]> DFSData = new Dictionary<string, int[]>();
            Dictionary<string, List<string>> transitions = new Dictionary<string, List<string>>();
            List<string> StronglyConnectedComponets = new List<string>();

            Stack<ConfigurationBase> TaskStack = new Stack<ConfigurationBase>();

            TaskStack.Push(States);
            DFSData.Add(States.GetID(), new int[] { VISITED_NOPREORDER, 0 });

            transitions.Add(States.GetID(), new List<string>());

            Stack<ConfigurationBase> stepStack = new Stack<ConfigurationBase>();

            //# Preorder counter
            int ii = 0;

            //store the expended event step of a node to avoid multiple invocation of the make one move.
            Dictionary<string, List<ConfigurationBase>> ExpendedNode = new Dictionary<string, List<ConfigurationBase>>();

            do
            {
                ConfigurationBase pair = TaskStack.Peek();
                string v = pair.GetID();

                List<string> outgoing = transitions[v];

                int[] nodeData = DFSData[v];

                if (nodeData[0] == VISITED_NOPREORDER)
                {
                    nodeData[0] = ii;
                    ii++;
                }

                bool done = true;

                if (ExpendedNode.ContainsKey(v))
                {
                    List<ConfigurationBase> list = ExpendedNode[v];
                    if (list.Count > 0)
                    {
                        //transverse all steps
                        for (int k = list.Count - 1; k >= 0; k--)
                        {
                            ConfigurationBase step = list[k];

                            string tmp = step.GetID();

                            //if the step is a unvisited step
                            //if (!preorder.ContainsKey(t))
                            if (DFSData[tmp][0] == VISITED_NOPREORDER)
                            {
                                //only add the first unvisited step
                                //for the second or more unvisited steps, ignore at the monent
                                if (done)
                                {
                                    TaskStack.Push(step);

                                    //procPath.Add(step.GetID());

                                    done = false;
                                    list.RemoveAt(k);
                                }
                            }
                            else
                            {
                                list.RemoveAt(k);
                            }
                        }
                    }
                }
                else
                {
                    List<ConfigurationBase> product = new List<ConfigurationBase>(pair.MakeOneMove(Constants.TAU));
                        //.AmpleTau(procPath, false);

                    for (int k = product.Count - 1; k >= 0; k--)
                    {
                        ConfigurationBase step = product[k];

                        string tmp = step.GetID();

                        //if (DFSData.ContainsKey(tmp))
                        int[] data;
                        if (DFSData.TryGetValue(tmp, out data))
                        {
                            //int t = visited[stateString];
                            outgoing.Add(tmp);

                            //if this node is still not visited
                            //if (!preorder.ContainsKey(tmp))
                            if (data[0] == VISITED_NOPREORDER)
                            {
                                //only put the first one to the work list stack.
                                //if there are more than one node to be visited,
                                //simply ignore them and keep its event step in the list.
                                if (done)
                                {
                                    TaskStack.Push(step);
                                    done = false;
                                    product.RemoveAt(k);
                                }
                                else
                                {
                                    product[k] = step;
                                }
                            }
                                //this node is truly visited. can be removed
                            else
                            {
                                product.RemoveAt(k);
                            }
                        }
                        else
                        {
                            DFSData.Add(tmp, new int[] { VISITED_NOPREORDER, 0 });

                            transitions.Add(tmp, new List<string>(8));
                            outgoing.Add(tmp);
                            //only put the first one into the stack.
                            if (done)
                            {
                                TaskStack.Push(step);

                                done = false;
                                product.RemoveAt(k);
                            }
                            else
                            {
                                product[k] = step;
                            }
                        }
                    }

                    //create the remaining steps as the expending list for v
                    ExpendedNode.Add(v, product);
                }

                if (done)
                {
                    int lowlinkV = nodeData[0];
                    int preorderV = lowlinkV;

                    bool selfLoop = false;
                    for (int j = 0; j < outgoing.Count; j++)
                    {
                        string w = outgoing[j];
                        if (w == v)
                        {
                            selfLoop = true;
                        }

                        int[] wdata = DFSData[w];
                        if (wdata[0] != SCC_FOUND)
                        {
                            if (wdata[0] > preorderV)
                            {
                                lowlinkV = Math.Min(lowlinkV, wdata[1]);
                            }
                            else
                            {
                                lowlinkV = Math.Min(lowlinkV, wdata[0]);
                            }
                        }
                    }
                    nodeData[1] = lowlinkV;

                    TaskStack.Pop();

                    if (lowlinkV == preorderV)
                    {
                        StronglyConnectedComponets.Add(v);
                        nodeData[0] = SCC_FOUND;

                        while (stepStack.Count > 0 && DFSData[stepStack.Peek().GetID()][0] > preorderV)
                        {
                            ConfigurationBase s = stepStack.Pop();
                            string tmp = s.GetID();
                            //int k = visited[tmp];
                            StronglyConnectedComponets.Add(tmp);
                            //scc_found.Add(tmp);
                        }

                        //outgoing.Count == 0 --> deadlock, we need to check //outgoing.Count == 0
                        //StronglyConnectedComponets.Count > 1 || selfLoop -> non-trivial case, we need to check
                        if (StronglyConnectedComponets.Count > 1 || selfLoop)
                        {
                            return true;
                        }

                        foreach (string componet in StronglyConnectedComponets)
                        {
                            ExpendedNode.Remove(componet);
                        }

                        StronglyConnectedComponets.Clear();
                    }
                    else
                    {
                        stepStack.Push(pair);
                    }
                }
            } while (TaskStack.Count > 0);

            foreach (string key in DFSData.Keys)
            {
                VisitedNonDivStates.Add(key);
            }

            return false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Given one environment, get the initial states of the product of the system and the automata. Notice that the automata 
        /// is allowed to make one move first. This is necessary to check the very first state of the system. 
        /// </summary>
        /// <param name="initialStep"></param>
        /// <returns></returns>
        public static List<LocalPair> GetInitialPairsLocal(BuchiAutomata BA, ConfigurationBase initialStep)
        {
            List<LocalPair> toReturn = new List<LocalPair>();
            HashSet<string> existed = new HashSet<string>();

            foreach (string s in BA.InitialStates)
            {
                List<string> next = BA.MakeOneMove(s, initialStep);

                foreach (string var in next)
                {
                    if (existed.Add(var))
                    {
                        toReturn.Add(new LocalPair(initialStep, var));
                    }
                }
            }

            return toReturn;
        }
Ejemplo n.º 6
0
 //public List<string> Engaged;
 public LocalPair(ConfigurationBase e, string s)
 {
     configuration = e;
     state = s;
     Enabled = new List<string>();
 }
Ejemplo n.º 7
0
 public bool EqualsV(ConfigurationBase input)
 {
     return(GlobalEnv.GetID() == input.GlobalEnv.GetID());
 }
Ejemplo n.º 8
0
        private void AddCounterExamplePrefixPathNode(ref string sourceProcess, ConfigurationBase stepOld, bool firstSCC)
        {
            Node n = null;
            Edge edge = null;

            //EventStepSim fromStep = CounterExampleTrace[j-1];

            EventStepSim step = new EventStepSim(stepOld);

            step.SourceProcess = sourceProcess;

            //change all nodes to white node!
            foreach (Node mapN in g.NodeMap.Values)
            {
                if (mapN.Attr.FillColor == Color.Red)
                {
                    mapN.Attr.FillColor = Color.White;
                }
            }

            string stepString;
            ////string nextState = step.ToFullString();

            if (step.StepVisited(visited, out stepString))
            {
                Node srcNode = g.FindNode(step.SourceProcess);

                edge = null;
                foreach (Edge outEdge in srcNode.OutEdges)
                {
                    if (outEdge.LabelText == step.Event && outEdge.Target == stepString)
                    {
                        //duplicate edge is found
                        edge = outEdge;
                        break;
                    }
                }

                if (edge == null)
                {
                    edge = g.AddEdge(step.SourceProcess, step.Event, stepString);
                }

                n = edge.TargetNode; // g.NodeMap[stepString] as Node;

                AddToTrace(edge.SourceNode.LabelText, step, edge.TargetNode.LabelText, stepString);
            }
            else
            {
                visited.Add(stepString, null);

                //add the new node and set it to red.
                n = g.AddNode(stepString);
                n.LabelText = (g.NodeCount - 1).ToString();
                n.UserData = step; //// nextState;

                edge = g.AddEdge(step.SourceProcess, step.Event, stepString);

                AddToTrace(edge.SourceNode.LabelText, step, n.LabelText, stepString);
            }

            if (firstSCC)
            {
                n.Attr.FillColor = Color.LightGreen;
            }
            else
            {
                n.Attr.FillColor = Color.Red;
            }

            sourceProcess = stepString;

            string key = GetTraceEvent(this.ListView_Trace.Items.Count) + stepString;
            if (!Mapping.ContainsKey(key))
            {
                Mapping.Add(key, new ProcessData(step, CloneGraph(g), CloneEnabledEvent()));
            }

            UpdateStore(step);
        }
Ejemplo n.º 9
0
        private void AddAllTauReachableSteps(ConfigurationBase step, List<EventStepSim> listResutlt)
        {
            NormalizedState NState = NormalizedState.TauReachable(new List<ConfigurationBase>() {step});

            foreach (ConfigurationBase state in NState.States)
            {
                //for each step in this
                IEnumerable<ConfigurationBase> templist = state.MakeOneMove();

                bool hasNonTauEvent = false;
                foreach (ConfigurationBase step1 in templist)
                {
                    if (step1.Event != Common.Classes.Ultility.Constants.TAU)
                    {
                        hasNonTauEvent = true;
                        break;
                    }
                }

                //if the step has non-tau transition, this should be a boundary step, and we need to keep it
                if (hasNonTauEvent || state.IsDeadLock)
                {
                    if (state.Event == Common.Classes.Ultility.Constants.TAU)
                    {
                        //do we need to add the *
                        state.Event = step.Event; //+ "*"
                        state.DisplayName = null;
                    }

                    EventStepSim step1Sim = new EventStepSim(state);

                    bool contains = false;
                    foreach (EventStepSim sim in listResutlt)
                    {
                        if (sim.Event == step1Sim.Event && sim.StepID == step1Sim.StepID)
                        {
                            contains = true;
                            break;
                        }
                    }

                    //duplicated steps should not be added in.
                    if (!contains)
                    {
                        listResutlt.Add(step1Sim);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public List<string> MakeOneMove(string state, ConfigurationBase config)
        {
            List<string> returnList = new List<string>();
            Transition[] trans = fromTransitions[state];
            string evt = config.Event;

            foreach (Transition tran in trans)
            {
                bool toAdd = true;
                foreach (Proposition label in tran.labels)
                {
                    //If the transition is labelled with Sigma, there should not be any other labels.
                    if (label.IsSigmal)
                    {
                        returnList.Add(tran.ToState);
                        break;
                    }

                    string labelstring = label.Label;

                    Expression exp;

                    //If the labed is negated, e.g., !eat0.
                    if (label.Negated)
                    {
                        //if (!DeclarationDatabase.ContainsKey(labelstring)) //If the label is an event.
                        if(!DeclarationDatabase.TryGetValue(labelstring, out exp))
                        {
                            //if the label says that this event can not happen, the event is eat0 and the label is !eat0.
                            if (labelstring == evt)
                            {
                                toAdd = false;
                                break;
                            }
                        }
                        else //If the label is a proposition.
                        {
                            //if (config.ImplyCondition(DeclarationDatabase[labelstring]))
                            if (config.ImplyCondition(exp))
                            {
                                toAdd = false;
                                break;
                            }
                        }
                    }
                    else //if (!label.Negated)
                    {
                        //if (!DeclarationDatabase.ContainsKey(labelstring)) //If the label is an event.
                        if (!DeclarationDatabase.TryGetValue(labelstring, out exp))
                        {
                            if (labelstring != evt)
                            {
                                toAdd = false;
                                break;
                            }
                        }
                        else //If the label is a proposition.
                        {
                            if (!config.ImplyCondition(exp))
                            {
                                toAdd = false;
                                break;
                            }
                        }
                    }
                }

                if (toAdd && !returnList.Contains(tran.ToState))
                {
                    returnList.Add(tran.ToState);
                }
            }

            return returnList;
        }
Ejemplo n.º 11
0
        private List<ConfigurationBase> MakeOneMove(ConfigurationBase currentStep)
        {
            List<ConfigurationBase> listResult = new List<ConfigurationBase>();
            IEnumerable<ConfigurationBase> list = currentStep.MakeOneMove();

            foreach (ConfigurationBase step in list)
            {
                bool contains = false;
                foreach (ConfigurationBase dest in listResult)
                {
                    if (dest.Event == step.Event)
                    {
                        contains = true;
                        break;
                    }
                }

                //duplicated steps should not be added in.
                if (!contains)
                {
                    listResult.Add(step);
                }
            }

            return listResult;
        }
Ejemplo n.º 12
0
 public bool EqualsV(ConfigurationBase input)
 {
     return GlobalEnv.GetID() == input.GlobalEnv.GetID();
 }
Ejemplo n.º 13
0
        public bool IsDivergent()
        {
            Stack <ConfigurationBase> working = new Stack <ConfigurationBase>();
            List <string>             path    = new List <string>(100);
            StringHashTable           visited = new StringHashTable(100);

            //The following are for identifying the current path.
            Stack <int> depthStack = new Stack <int>(1024);

            depthStack.Push(0);
            List <int> depthList = new List <int>(1024);

            //The above are for identifying the current path.

            working.Push(this);
            visited.Add(GetID());

            while (working.Count > 0)
            {
                ConfigurationBase current = working.Pop();
                IEnumerable <ConfigurationBase> nextStates = current.MakeOneMove(Constants.TAU);

                //The following are for identifying the current path.
                int depth = depthStack.Pop();

                if (depth > 0)
                {
                    while (depthList[depthList.Count - 1] >= depth)
                    {
                        int lastIndex = depthList.Count - 1;
                        depthList.RemoveAt(lastIndex);
                        path.RemoveAt(lastIndex);
                    }
                }

                path.Add(current.GetID());
                depthList.Add(depth);

                if (nextStates != null)
                {
                    //for (int i = 0; i < nextStates.Length; i++)
                    foreach (ConfigurationBase next in nextStates)
                    {
                        //ConfigurationBase next = nextStates[i];
                        string ID = next.GetID();
                        if (path.Contains(ID))
                        {
                            return(true);
                        }
                        else
                        {
                            if (!visited.ContainsKey(ID))
                            {
                                visited.Add(ID);
                                working.Push(next);
                                depthStack.Push(depth + 1);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 14
0
 public static DeterministicAutomata BuildDeterministicAutomataWithRefusalsAndDiv(ConfigurationBase initStep)
 {
     return BuildAutomataWithRefusalsAndDiv(initStep).DeterminizeWithRefusalsAndDiv();
 }
Ejemplo n.º 15
0
 public EventBAPairSafety(ConfigurationBase e, List<string> s)
 {
     configuration = e;
     States = s;
 }
Ejemplo n.º 16
0
        private static Automata BuildAutomataWithRefusalsAndDiv(ConfigurationBase InitSpecStep)
        {
            Dictionary<string, FAState> visited = new Dictionary<string, FAState>();
            Stack<ConfigurationBase> working = new Stack<ConfigurationBase>(1024);
            working.Push(InitSpecStep);
            Automata auto = new Automata();
            FAState init = auto.AddState();
            auto.SetInitialState(init);
            visited.Add(InitSpecStep.GetID(), init);

            do
            {
                ConfigurationBase current = working.Pop();
                FAState currentState = visited[current.GetID()];

                if (current.IsDivergent())
                {
                    currentState.IsDiv = true;
                }
                else
                {
                    IEnumerable<ConfigurationBase> list = current.MakeOneMove();
                    List<string> negateRefusal = new List<string>();
                    bool hasTau = false;

                    //for (int i = 0; i < list.Length; i++)
                    foreach (ConfigurationBase step in list)
                    {
                        //ConfigurationBase step = list[i];

                        if (step.Event == Constants.TAU)
                        {
                            hasTau = true;
                        }
                        else
                        {
                            negateRefusal.Add(step.Event);
                        }

                        FAState target;
                        string nextID = step.GetID();
                        if (visited.ContainsKey(nextID))
                        {
                            target = visited[nextID];
                        }
                        else
                        {
                            target = auto.AddState();
                            working.Push(step);
                            visited.Add(nextID, target);
                        }

                        auto.AddTransition(currentState, step.Event, target);
                    }

                    if (hasTau)
                    {
                        currentState.NegatedRefusal = null;
                    }
                    else
                    {
                        currentState.NegatedRefusal = negateRefusal;
                    }
                }
            }
            while (working.Count > 0);

            return auto;
        }
Ejemplo n.º 17
0
        public static EventBAPairSafety GetInitialPairs(BuchiAutomata BA, ConfigurationBase initialStep)
        {
            List<string> intialBAStates = new List<string>();
            //List<string> existed = new List<string>();

            foreach (string s in BA.InitialStates)
            {
                List<string> next = BA.MakeOneMove(s, initialStep);

                foreach (string var in next)
                {
                    if (!intialBAStates.Contains(var))
                    {
                        //existed.Add(var);
                        intialBAStates.Add(var);
                    }
                }
            }

            return new EventBAPairSafety(initialStep, intialBAStates);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// This method checks whether the found counterexample is spurious or not.
        /// This checking only works for abstraction for parameterized systems.
        /// </summary>
        /// <returns></returns>
        protected virtual bool IsCounterExampleSpurious()
        {
            Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024);
            List <ConfigurationBase>  ConcreteCounterExampleTrace = new List <ConfigurationBase>(64);

            working.Push(InitialStep);
            Stack <int> depthStack = new Stack <int>(1024);

            depthStack.Push(0);
            List <int>      depthList = new List <int>(1024);
            StringHashTable visited   = new StringHashTable(1024);

            visited.Add("0-" + InitialStep.GetID());

            do
            {
                ConfigurationBase current = working.Pop();
                int depth = depthStack.Pop();

                if (depth > 0)
                {
                    while (depthList[depthList.Count - 1] >= depth)
                    {
                        int lastIndex = depthList.Count - 1;
                        depthList.RemoveAt(lastIndex);
                        ConcreteCounterExampleTrace.RemoveAt(lastIndex);
                    }
                }

                ConcreteCounterExampleTrace.Add(current);
                depthList.Add(depth);

                if (ConcreteCounterExampleTrace.Count == VerificationOutput.CounterExampleTrace.Count)
                {
                    VerificationOutput.CounterExampleTrace = ConcreteCounterExampleTrace;
                    Ultility.Ultility.CutNumber            = 2;
                    return(false);
                }
                else
                {
                    ConfigurationBase abstractStep = VerificationOutput.CounterExampleTrace[depth + 1];

                    IEnumerable <ConfigurationBase> steps = current.MakeOneMove(abstractStep.Event);
                    //for (int j = 0; j < steps.Length; j++)
                    foreach (ConfigurationBase step in steps)
                    {
                        if (abstractStep.EqualsV(step))
                        {
                            string tmp = (depth + 1) + "-" + step.GetID();
                            if (!visited.ContainsKey(tmp))
                            {
                                working.Push(step);
                                depthStack.Push(depth + 1);
                                visited.Add(tmp);
                            }
                        }
                    }
                }
            } while (working.Count > 0);

            return(true);
        }
Ejemplo n.º 19
0
        public EventBAPairSafety[] Next(BuchiAutomata BA, ConfigurationBase[] steps)
        {
            EventBAPairSafety[] product = new EventBAPairSafety[steps.Length]; // * BA.States.Length);

            for (int i = 0; i < steps.Length; i++)
            {
                List<string> targetStates = new List<string>();

                foreach (string state in States)
                {
                    List<string> states = BA.MakeOneMove(state, steps[i]);
                    Ultility.Ultility.Union(targetStates, states);
                }

                product[i] = new EventBAPairSafety(steps[i], targetStates);
            }

            return product;
        }
Ejemplo n.º 20
0
 public EventStepSim(ConfigurationBase configuration)
 {
     Config = configuration;
 }
Ejemplo n.º 21
0
 public virtual Bitmap MapConfigurationToImage(ConfigurationBase config, int imageSize)
 {
     return null;
 }
Ejemplo n.º 22
0
 public virtual Bitmap MapConfigurationToImage(ConfigurationBase config, int imageSize)
 {
     return(null);
 }
Ejemplo n.º 23
0
        protected List<ConfigurationBase> GetConcreteTrace(ConfigurationBase init, List<string> trace)
        {
            System.Diagnostics.Debug.Assert(trace.Count == 0 || init.GetIDWithEvent() == GetConfigID(trace[0]));

            List<ConfigurationBase> toReturn = new List<ConfigurationBase>(64);
            ConfigurationBase currentConfig = init;
            toReturn.Add(currentConfig);

            for (int i = 1; i < trace.Count; i++)
            {
                string id = GetConfigID(trace[i]);
                IEnumerable<ConfigurationBase> next = currentConfig.MakeOneMove();

                foreach (ConfigurationBase configurationBase in next)
                {
                    if (configurationBase.GetIDWithEvent() == id)
                    {
                        toReturn.Add(configurationBase);
                        currentConfig = configurationBase;
                        break;
                    }
                }
            }

            return toReturn;
        }