/// <summary> /// Visits and performs a property count on forall expression. /// </summary> /// <param name="expression">Forall expression.</param> /// <returns>Tuple (property satisfied count, property not satisfied count).</returns> public Tuple <double, double> Visit(ForallExpression expression) { double positiveValue = 0; double negativeValue = 0; IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters); foreach (var localSubstitution in localSubstitutions) { Substitution.AddLocalSubstitution(localSubstitution); var childPropertyCounts = expression.Child.Accept(this); Substitution.RemoveLocalSubstitution(localSubstitution); if (EvaluationStrategy == ForwardCostEvaluationStrategy.ADDITIVE_VALUE) { positiveValue += childPropertyCounts.Item1; negativeValue += childPropertyCounts.Item2; } else { positiveValue = Math.Max(positiveValue, childPropertyCounts.Item1); negativeValue = Math.Max(negativeValue, childPropertyCounts.Item2); } } return(Tuple.Create(positiveValue, negativeValue)); }
/// <summary> /// Checks the equality of objects. /// </summary> /// <param name="obj">Object to be checked.</param> /// <returns>True if the objects are equal, false otherwise.</returns> public override bool Equals(object obj) { ForallExpression other = obj as ForallExpression; if (other == null) { return(false); } return(Parameters.Equals(other.Parameters) && Child.Equals(other.Child)); }
/// <summary> /// Visits and transforms the expression. /// </summary> /// <param name="expression">Source expression.</param> /// <returns>Transformed expression.</returns> public override IExpression Visit(ForallExpression expression) { List <IExpression> arguments = TransformQuantifiedSubExpression(expression.Parameters, expression.Child); if (IsNegating) { return(new OrExpression(arguments)); } return(new AndExpression(arguments)); }
/// <summary> /// Visits the expression. /// </summary> /// <param name="expression">Expression.</param> public void Visit(ForallExpression expression) { expression.Child.Accept(this); foreach (var parameter in expression.Parameters) { if (CollectedParameters.Contains(parameter.ParameterNameId)) { CollectedParameters.Remove(parameter.ParameterNameId); } } }
/// <summary> /// Visits and evaluates forall expression. /// </summary> /// <param name="expression">Forall expression.</param> /// <returns>True if the specified expression evaluates as true, false otherwise.</returns> public bool Visit(ForallExpression expression) { IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters); foreach (var localSubstitution in localSubstitutions) { Substitution.AddLocalSubstitution(localSubstitution); bool subExpressionResult = expression.Child.Accept(this); Substitution.RemoveLocalSubstitution(localSubstitution); if (!subExpressionResult) { return(false); } } return(true); }
/// <summary> /// Visits and performs a property count on forall expression. /// </summary> /// <param name="expression">Forall expression.</param> /// <returns>Tuple (property satisfied count, property not satisfied count).</returns> public Tuple <int, int> Visit(ForallExpression expression) { int fulfilled = 0; int notFulfilled = 0; IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters); foreach (var localSubstitution in localSubstitutions) { Substitution.AddLocalSubstitution(localSubstitution); var childPropertyCounts = expression.Child.Accept(this); Substitution.RemoveLocalSubstitution(localSubstitution); fulfilled += childPropertyCounts.Item1; notFulfilled += childPropertyCounts.Item2; } return(Tuple.Create(fulfilled, notFulfilled)); }
/// <summary> /// Visits and transforms the expression. /// </summary> /// <param name="expression">Source expression.</param> /// <returns>Transformed expression.</returns> public override IExpression Visit(ForallExpression expression) { return(new ForallExpression(expression.Parameters, expression.Child.Accept(this))); }