示例#1
0
        public override string ToString()
        {
            switch (elems.Item2)
            {
            case CounterOp.EXIT:
                return(LowerBoundCheck);

            case CounterOp.SET0:
                return(string.Format("{0}{1}0", SpecialCharacters.c(Counter.CounterId), SpecialCharacters.ASSIGN));

            case CounterOp.EXIT_SET0:
                return(string.Format("{2}{3}{0}{1}0", SpecialCharacters.c(Counter.CounterId), SpecialCharacters.ASSIGN, LowerBoundCheck, SpecialCharacters.IMPLIES));

            case CounterOp.SET1:
                return(string.Format("{0}{1}1", SpecialCharacters.c(Counter.CounterId), SpecialCharacters.ASSIGN));

            case CounterOp.EXIT_SET1:
                return(string.Format("{2}{3}{0}{1}1", SpecialCharacters.c(Counter.CounterId), SpecialCharacters.ASSIGN, LowerBoundCheck, SpecialCharacters.IMPLIES));

            case CounterOp.INCR:
                return(string.Format("{2}{3}{0}++", SpecialCharacters.c(Counter.CounterId), SpecialCharacters.ASSIGN, UpperBoundCheck, SpecialCharacters.IMPLIES));

            default:
                throw new NotImplementedException(elems.Item2.ToString());
            }
        }
示例#2
0
 public override string DescribeStartLabel()
 {
     if (IsCountingState(InitialState))
     {
         var c = countingStates[InitialState];
         return(string.Format("{0}{1}0", SpecialCharacters.c(c.CounterId), SpecialCharacters.ASSIGN));
     }
     else
     {
         return("");
     }
 }
示例#3
0
        public override string ToString()
        {
            string s = "";

            for (int i = 0; i < Length; i++)
            {
                if (this[i] != CsUpdate.NOOP)
                {
                    s += string.Format("{0}({1});", this[i], SpecialCharacters.c(i));
                }
            }
            return(s);
        }
示例#4
0
        public string PrettyPrint(Tuple <Maybe <S>, Sequence <CounterOperation> > t)
        {
            if (t.Item1.IsSomething)
            {
                if (t.Item2.Length > 0)
                {
                    char imp  = SpecialCharacters.IMPLIES;
                    char prod = SpecialCharacters.MIDDOT;
                    if (t.Item2.Length == 1)
                    {
                        if (t.Item2[0].OperationKind == CounterOp.SET0 || t.Item2[0].OperationKind == CounterOp.SET1)
                        {
                            return(builder.solver.PrettyPrint(t.Item1.Element) + imp + t.Item2[0].ToString());
                        }
                        else
                        {
                            return(builder.solver.PrettyPrint(t.Item1.Element) + prod + t.Item2[0].ToString());
                        }
                    }
                    else
                    {
                        return(builder.solver.PrettyPrint(t.Item1.Element) + prod + t.Item2.ToString());
                    }
                }
                else
                {
                    return(builder.solver.PrettyPrint(t.Item1.Element));
                }
            }
            else
            {
                string s = "";
                for (int i = 0; i < t.Item2.Length; i++)
                {
                    if (t.Item2[i].OperationKind != CounterOp.EXIT)
                    {
                        throw new AutomataException(AutomataExceptionKind.InternalError);
                    }

                    if (t.Item2[i].Counter.LowerBound > 0)
                    {
                        if (s != "")
                        {
                            s += SpecialCharacters.AND;
                        }
                        s += string.Format("{0}{1}{2}", SpecialCharacters.c(t.Item2[i].Counter.CounterId), SpecialCharacters.GEQ, t.Item2[i].Counter.LowerBound);
                    }
                }
                return((s == "" ? SpecialCharacters.TOP.ToString() : s) + SpecialCharacters.CHECKMARK);
            }
        }
示例#5
0
        /// <summary>
        /// Describe if the initial state is associuated with a counter, if so then set it to {0}
        /// </summary>
        public override string DescribeStartLabel()
        {
            var initcounters = activeCounterMap[InitialState].GetEnumerator();

            if (initcounters.MoveNext())
            {
                var c = initcounters.Current;
                return(string.Format("{0}={{0}}", SpecialCharacters.c(c)));
            }
            else
            {
                return("");
            }
        }
示例#6
0
        /// <summary>
        /// Describe the state information, including original states if determinized, as well as counters.
        /// </summary>
        public override string DescribeState(int state)
        {
            string s;

            if (!stateDescr.TryGetValue(state, out s))
            {
                s = SpecialCharacters.S(stateDescr.Count);
                stateDescr[state] = s;
            }

            var mems = new List <int>(stateBuilder.GetMembers(state));

            mems.Sort();
            if (!__hidePowersets)
            {
                s += "\n" + "{";
                foreach (var q in mems)
                {
                    if (!s.EndsWith("{"))
                    {
                        s += ",";
                    }
                    s += SpecialCharacters.q(q);
                }
                s += "}";
            }
            var state_counters      = GetCountersOfState(state);
            var state_counters_list = new List <int>(state_counters);

            state_counters_list.Sort();
            foreach (var c in state_counters_list)
            {
                s += "\n";
                s += "(" + SpecialCharacters.c(c) + ")";
                //s += "(" + counters[c].LowerBound +
                //    SpecialCharacters.LEQ + SpecialCharacters.Cntr(c) + SpecialCharacters.LEQ + counters[c].UpperBound + ")";
                if (finalCounterSet.Contains(c))
                {
                    s += SpecialCharacters.XI_LOWERCASE + SpecialCharacters.ToSubscript(c);
                    s += SpecialCharacters.CHECKMARK;
                }
            }
            return(s);
        }
示例#7
0
        public override string ToString()
        {
            string s = "";

            if (isAND)
            {
                for (int i = 0; i < Length; i++)
                {
                    if (this[i] != CsCondition.TRUE)
                    {
                        if (s != "")
                        {
                            s += SpecialCharacters.AND;
                        }
                        s += string.Format("{0}({1})", this[i], SpecialCharacters.c(i));
                    }
                }
                if (s == "")
                {
                    s = SpecialCharacters.TOP.ToString();
                }
            }
            else
            {
                for (int i = 0; i < Length; i++)
                {
                    if (this[i] != CsCondition.FALSE)
                    {
                        if (s != "")
                        {
                            s += SpecialCharacters.OR;
                        }
                        s += string.Format("{0}({1})", this[i], SpecialCharacters.c(i));
                    }
                }
                if (s == "")
                {
                    s = SpecialCharacters.BOT.ToString();
                }
            }
            return(s);
        }
示例#8
0
        public override string DescribeState(int state)
        {
            string s;

            if (__hideDerivativesInViewer)
            {
                s = SpecialCharacters.q(state);
            }
            else
            {
                s = stateMap[state].ToString();
            }
            if (countingStates != null)
            {
                if (IsFinalState(state) && IsCountingState(state))
                {
                    s += "\n(";
                    var f = GetFinalStateCondition(state);
                    for (int i = 0; i < f.Length; i++)
                    {
                        if (i > 0)
                        {
                            s += SpecialCharacters.AND;
                        }
                        var op = f[i];
                        s += op.ToString();
                    }
                    s += ")" + SpecialCharacters.CHECKMARK;
                }
                else if (IsCountingState(state))
                {
                    s += "\n(" + SpecialCharacters.c(countingStates[state].CounterId) + ")";
                }
            }
            return(s);
        }
示例#9
0
        public static string DescribeCondition <S>(CsAlgebra <S> algebra, CsCondition cond, int i)
        {
            string c        = SpecialCharacters.c(i);
            string canExit  = SpecialCharacters.XI_LOWERCASE + SpecialCharacters.ToSubscript(i);
            string canIncr  = SpecialCharacters.IOTA_LOWERCASE + SpecialCharacters.ToSubscript(i);
            char   and      = SpecialCharacters.AND;
            char   or       = SpecialCharacters.OR;
            char   not      = SpecialCharacters.NOT;
            string empty    = string.Format("{0}={1}", c, SpecialCharacters.EMPTYSET);
            string nonempty = string.Format("{0}{1}{2}", c, SpecialCharacters.NEQ, SpecialCharacters.EMPTYSET);
            string _true    = SpecialCharacters.TOP.ToString();
            string _false   = SpecialCharacters.BOT.ToString();

            switch (cond)
            {
            case CsCondition.TRUE:
                return(_true);

            case CsCondition.FALSE:
                return(_false);

            case CsCondition.EMPTY:
                return(empty);

            case CsCondition.NONEMPTY:
                return(nonempty);

            case CsCondition.LOW:
                //return string.Format("{0}{2}{3}{4}max({0})<{1}", SpecialCharacters.Cntr(i), algebra.GetCounter(i).LowerBound, SpecialCharacters.NEQ, SpecialCharacters.EMPTYSET, SpecialCharacters.AND);
                //return canIncr + and + not + canExit;
                return(not + canExit);

            case CsCondition.HIGH:
                //return string.Format("{0}={{{1}}}", SpecialCharacters.Cntr(i), algebra.GetCounter(i).UpperBound);
                //return not + canIncr + and + canExit;
                return(not + canIncr);

            case CsCondition.CANEXIT:
                //return string.Format("{0}{1}{2}", SpecialCharacters.Cntr(i), SpecialCharacters.GEQ, algebra.GetCounter(i).LowerBound);
                return(canExit);

            case CsCondition.CANNOTEXIT:
                //return string.Format("{0}{1}{2}", SpecialCharacters.Cntr(i), SpecialCharacters.NOTGEQ, algebra.GetCounter(i).LowerBound);
                return(not + canExit);

            case CsCondition.CANLOOP:
                //return string.Format("{0}+1{1}{2}", SpecialCharacters.Cntr(i), SpecialCharacters.NEQ, SpecialCharacters.EMPTYSET);
                //return string.Format("{0}x{1}{2}(x<{3})", SpecialCharacters.EXISTS, SpecialCharacters.IN, SpecialCharacters.Cntr(i), algebra.GetCounter(i).UpperBound);
                return(canIncr);

            case CsCondition.CANNOTLOOP:
                //return string.Format("{0}+1{1}{2}", SpecialCharacters.Cntr(i), "=", SpecialCharacters.EMPTYSET);
                //return string.Format("{0}x{1}{2}(x<{3})", SpecialCharacters.NOTEXISTS, SpecialCharacters.IN, SpecialCharacters.Cntr(i), algebra.GetCounter(i).UpperBound);
                return(not + canIncr);

            case CsCondition.MIDDLE:
                //return string.Format("{2}{4}{5}{6}{0}{1}max({2})<{3}", algebra.GetCounter(i).LowerBound, SpecialCharacters.LEQ, SpecialCharacters.Cntr(i), algebra.GetCounter(i).UpperBound, SpecialCharacters.NEQ, SpecialCharacters.EMPTYSET, SpecialCharacters.AND);
                return(canIncr + and + canExit);

                #region these cases should not occur
            case CsCondition.LOWorHIGH:
                //return string.Format("({0}{1}{2})", DescribeCondition<S>(algebra, CsCondition.LOW, i), SpecialCharacters.OR, DescribeCondition<S>(algebra, CsCondition.HIGH, i));
                return("(" + not + canIncr + or + not + canExit + ")");

            case CsCondition.EMPTYorCANEXIT:
                return("(" + empty + or + canExit + ")");

            case CsCondition.EMPTYorCANLOOP:
                return("(" + empty + or + canIncr + ")");

            case CsCondition.EMPTYorHIGHorLOW:
                return("(" + empty + or + not + canIncr + or + not + canExit + ")");

            case CsCondition.EMPTYorMIDDLE:
                return("(" + empty + or + canIncr + and + canExit + ")");

            default:
                throw new AutomataException(AutomataExceptionKind.UndefinedEnum);
                #endregion
            }
        }
示例#10
0
        internal string ToString(bool debugmode)
        {
            if (debugmode)
            {
                return(ToString());
            }
            else
            {
                string s = "";
                for (int i = 0; i < Length; i++)
                {
                    string c      = SpecialCharacters.c(i);
                    char   assign = SpecialCharacters.ASSIGN;
                    char   union  = SpecialCharacters.UNION;
                    switch (this[i])
                    {
                    case CsUpdate.INCR:
                    {
                        s += c + "++";
                        break;
                    }

                    case CsUpdate.INCR0:
                    {
                        s += c + "++" + union + "{0}";
                        break;
                    }

                    case CsUpdate.INCR1:
                    {
                        s += c + "++" + union + "{1}";
                        break;
                    }

                    case CsUpdate.INCR01:
                    {
                        s += c + "++" + union + "{0,1}";
                        break;
                    }

                    case CsUpdate.SET0:
                    {
                        s += c + assign + "{0}";
                        break;
                    }

                    case CsUpdate.SET1:
                    {
                        s += c + assign + "{1}";
                        break;
                    }

                    case CsUpdate.SET01:
                    {
                        s += c + assign + "{0,1}";
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
                return(s);
            }
        }