private static UnaryComparison compExprToUnaryComp(ComparisonExpression expr) { if (!expr.isUnary()) { return(null); } if (expr.arithmetic_operand1.isConstant()) { LinearIntegerExpression tmp = expr.arithmetic_operand1; expr.arithmetic_operand1 = expr.arithmetic_operand2; expr.arithmetic_operand2 = tmp; switch (expr.comparison_operator) { case ComparisonExpression.ComparisonOperator.GEQ: expr.comparison_operator = ComparisonExpression.ComparisonOperator.LEQ; break; case ComparisonExpression.ComparisonOperator.GT: expr.comparison_operator = ComparisonExpression.ComparisonOperator.LT; break; case ComparisonExpression.ComparisonOperator.LEQ: expr.comparison_operator = ComparisonExpression.ComparisonOperator.GEQ; break; case ComparisonExpression.ComparisonOperator.LT: expr.comparison_operator = ComparisonExpression.ComparisonOperator.GT; break; default: break; } } VariableType variable = expr.GetVariables().First(); int coefficient = expr.arithmetic_operand1.coefficients[variable]; int constant = expr.arithmetic_operand2.constant; double divided = (double)constant / (double)coefficient; switch (expr.comparison_operator) { case ComparisonExpression.ComparisonOperator.EQ: case ComparisonExpression.ComparisonOperator.NEQ: if (!isInt(divided)) { return(null); } else { expr.arithmetic_operand2 = LinearIntegerExpression.Constant(Convert.ToInt32(divided)); } break; case ComparisonExpression.ComparisonOperator.GEQ: expr.arithmetic_operand2 = LinearIntegerExpression.Constant(Convert.ToInt32(Math.Ceiling(divided))); break; case ComparisonExpression.ComparisonOperator.GT: expr.arithmetic_operand2 = LinearIntegerExpression.Constant(Convert.ToInt32(Math.Floor(divided))); break; case ComparisonExpression.ComparisonOperator.LEQ: expr.arithmetic_operand2 = LinearIntegerExpression.Constant(Convert.ToInt32(Math.Floor(divided))); break; case ComparisonExpression.ComparisonOperator.LT: expr.arithmetic_operand2 = LinearIntegerExpression.Constant(Convert.ToInt32(Math.Ceiling(divided))); break; default: throw new ArgumentException(); } if (expr.comparison_operator == ComparisonExpression.ComparisonOperator.GEQ) { expr.comparison_operator = ComparisonExpression.ComparisonOperator.GT; expr.arithmetic_operand2.constant--; } if (expr.comparison_operator == ComparisonExpression.ComparisonOperator.LEQ) { expr.comparison_operator = ComparisonExpression.ComparisonOperator.LT; expr.arithmetic_operand2.constant++; } switch (expr.comparison_operator) { case ComparisonExpression.ComparisonOperator.EQ: return(UnaryComparison.equal(variable, expr.arithmetic_operand2.constant)); case ComparisonExpression.ComparisonOperator.GT: return(UnaryComparison.greater(variable, expr.arithmetic_operand2.constant, new HashSet <int>())); case ComparisonExpression.ComparisonOperator.LT: return(UnaryComparison.between(variable, -1, expr.arithmetic_operand2.constant, new HashSet <int>())); default: return(null); } }