public ArithmeticLanguage CheckUnaryConstraints() { if (!constraint.isSatisfiable()) { throw new PumpingLemmaException("Constraints of Arithmentic Language are not satisfiable"); } //makes all constraints unary if possible and returns the resulting language //throws PumpingLemmaException if not possible HashSet <ComparisonExpression> allExpr = getComparisonExpressions(constraint); HashSet <VariableType> VarsSeen = new HashSet <VariableType>(); HashSet <string> variables = new HashSet <string>(); //enumerate all variables foreach (ComparisonExpression constr in allExpr) { HashSet <VariableType> varTypeSet = new HashSet <VariableType>(constr.arithmetic_operand1.GetVariables()); varTypeSet.UnionWith(constr.arithmetic_operand1.GetVariables()); foreach (VariableType t in varTypeSet) { variables.Add(t.ToString()); } /* * if (constr.arithmetic_operand1.GetVariables().Count == 1 || constr.arithmetic_operand2.GetVariables().Count > 1) * { * * } */ if (constr.arithmetic_operand1.GetVariables().Count > 1 || constr.arithmetic_operand2.GetVariables().Count > 1) { throw new PumpingLemmaException("Cannot make constraints unary - several variables on one side of the comparison"); } //if there it is an comparison with a constant, we are done if (!constr.isUnary()) { VariableType v1 = constr.arithmetic_operand1.GetVariables().First(); VariableType v2 = constr.arithmetic_operand2.GetVariables().First(); IEnumerable <ComparisonExpression> comparisonsContainingSecondVar = allExpr.Where(comp => comp.containsVariable(v2)); //try to substitute second variable bool substituted = false; foreach (ComparisonExpression cexp in comparisonsContainingSecondVar) { if (cexp.comparison_operator == ComparisonExpression.ComparisonOperator.EQ && cexp.isUnary()) { //unfinished } } } } foreach (string v in variables) { } throw new NotImplementedException(); }
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()); }