示例#1
0
        public static string NonRegularGetRandomWord(ArithmeticLanguage language, int n)
        {
            HashSet <Dictionary <VariableType, int> > usedAssigments = new HashSet <Dictionary <VariableType, int> >();
            HashSet <VariableType> vars = language.constraint.GetVariables();

            for (int i = 0; i < Math.Pow(n, vars.Count); i++)
            {
                Dictionary <VariableType, int> newAssigment = new Dictionary <VariableType, int>();
                foreach (VariableType v in vars)
                {
                    newAssigment.Add(v, randInt(0, n));
                }
                if (usedAssigments.Contains(newAssigment))
                {
                    i--;
                }
                else
                {
                    usedAssigments.Add(newAssigment);
                    //check sat
                    HashSet <BooleanExpression> ops = new HashSet <BooleanExpression>();
                    ops.Add(language.constraint);
                    foreach (var entry in newAssigment)
                    {
                        ops.Add(ComparisonExpression.Equal(LinearIntegerExpression.Variable(entry.Key.ToString()), entry.Value));
                    }
                    BooleanExpression expr = LogicalExpression.And(ops);
                    if (expr.isSatisfiable())
                    {
                        return(pumpedWord(language.symbolic_string, newAssigment));
                    }
                }
            }
            return(wordError());
        }
示例#2
0
        private static SymbolicString splitToSymbStr(List <string> alphabet, string start, string mid, string end)
        {
            VariableType          freshVar = VariableType.FreshVariable();
            List <SymbolicString> strings  = new List <SymbolicString>();

            if (!start.Equals(""))
            {
                strings.Add(SymbolicString.FromTextDescription(alphabet, start));
            }
            SymbolicString pumpedMid = SymbolicString.Repeat(SymbolicString.FromTextDescription(alphabet, mid), LinearIntegerExpression.Variable(freshVar.ToString()));

            strings.Add(pumpedMid);
            if (!end.Equals(""))
            {
                strings.Add(SymbolicString.FromTextDescription(alphabet, end));
            }

            SymbolicString matchingString = SymbolicString.Concat(strings);

            return(matchingString);
        }