internal override ConstraintSatisfaction SatisfiesContraint(Model <T> model, ValueCombination combination) { if (CachedInteraction == null) { GetExcludedCombinations(model); } if (CachedInteraction.Parameters.Any((index) => combination.ParameterToValueMap.ContainsKey(index))) { // supplied combination is a superset if (CachedInteraction.Parameters.All((index) => combination.ParameterToValueMap.ContainsKey(index))) { var combo = CachedInteraction.Combinations.First((c) => ParameterInteractionTable <T> .MatchCombination(c, combination)); return(combo.State == ValueCombinationState.Excluded ? ConstraintSatisfaction.Unsatisfied : ConstraintSatisfaction.Satisfied); } else { return(new ConstraintSatisfactionExpressionVisitor(mapExpressionsToRequiredParams).SatisfiesConstraint(Condition, model, combination)); } } else { // supplied combination is disjoint return(ConstraintSatisfaction.InsufficientData); } }
internal override ConstraintSatisfaction SatisfiesContraint(Model model, ValueCombination combination) { if (CachedInteraction == null) { GetExcludedCombinations(model); } return(InternalConstraintHelpers.SatisfiesContraint(model, combination, CachedInteraction)); }
internal override ConstraintSatisfaction SatisfiesContraint(Model model, ValueCombination combination) { ConstraintSatisfaction ifSatisfaction = If.SatisfiesContraint(model, combination); if (ifSatisfaction == ConstraintSatisfaction.InsufficientData) { return(ConstraintSatisfaction.InsufficientData); } if (ifSatisfaction == ConstraintSatisfaction.Unsatisfied) { return(ConstraintSatisfaction.Satisfied); } return(Then.SatisfiesContraint(model, combination)); }
internal override ConstraintSatisfaction SatisfiesContraint(Model model, ValueCombination combination) { ConstraintSatisfaction first = First.SatisfiesContraint(model, combination); ConstraintSatisfaction second = Second.SatisfiesContraint(model, combination); if (first == ConstraintSatisfaction.Satisfied || second == ConstraintSatisfaction.Satisfied) { return(ConstraintSatisfaction.Satisfied); } if (first == ConstraintSatisfaction.Unsatisfied && second == ConstraintSatisfaction.Unsatisfied) { return(ConstraintSatisfaction.Unsatisfied); } return(ConstraintSatisfaction.InsufficientData); }
internal override ConstraintSatisfaction SatisfiesContraint(Model model, ValueCombination combination) { var satisfaction = Condition.SatisfiesContraint(model, combination); if (satisfaction == ConstraintSatisfaction.InsufficientData) { return(ConstraintSatisfaction.InsufficientData); } if (satisfaction == ConstraintSatisfaction.Satisfied) { return(ConstraintSatisfaction.Unsatisfied); } else { return(ConstraintSatisfaction.Satisfied); } }
internal override ParameterInteraction GetExcludedCombinations(Model <T> model) { if (CachedInteraction == null) { var taggedValues = GetParametersWithTaggedValues(model); CachedInteraction = new ParameterInteraction(taggedValues.Select((p) => p.ParameterIndex)); var combinationIndices = ParameterInteractionTable <T> .GenerateValueTable(model.Parameters, CachedInteraction); foreach (var combinationIndex in combinationIndices) { int tagCount = 0; ValueCombination combination = new ValueCombination(combinationIndex, CachedInteraction); combination.State = ValueCombinationState.Covered; for (int i = 0; i < taggedValues.Count; i++) { if (taggedValues[i].ValueIndices.BinarySearch(combinationIndex[i]) >= 0) { tagCount++; } if (tagCount > 1) { break; } } if (tagCount > 1) { combination.State = ValueCombinationState.Excluded; } CachedInteraction.Combinations.Add(combination); } } return(new ParameterInteraction(CachedInteraction)); }
internal override ConstraintSatisfaction SatisfiesContraint(Model <T> model, ValueCombination combination) { return(InnerConstraint.SatisfiesContraint(model, combination)); }
public ConstraintSatisfaction SatisfiesConstraint <T>(Expression expression, Model <T> model, ValueCombination combination) where T : new() { switch (expression.NodeType) { case ExpressionType.AndAlso: { var andAlso = (BinaryExpression)expression; ConstraintSatisfaction left = SatisfiesConstraint(andAlso.Left, model, combination); if (left == ConstraintSatisfaction.Unsatisfied) { return(ConstraintSatisfaction.Unsatisfied); } ConstraintSatisfaction right = SatisfiesConstraint(andAlso.Right, model, combination); if (right == ConstraintSatisfaction.Unsatisfied) { return(ConstraintSatisfaction.Unsatisfied); } if (left == right) { return(left); } else { return(ConstraintSatisfaction.InsufficientData); } } case ExpressionType.Conditional: var conditional = (ConditionalExpression)expression; ConstraintSatisfaction test = SatisfiesConstraint(conditional.Test, model, combination); if (test == ConstraintSatisfaction.InsufficientData) { return(ConstraintSatisfaction.InsufficientData); } if (test == ConstraintSatisfaction.Satisfied) { return(SatisfiesConstraint(conditional.IfTrue, model, combination)); } else { return(SatisfiesConstraint(conditional.IfFalse, model, combination)); } case ExpressionType.Lambda: return(SatisfiesConstraint(((LambdaExpression)expression).Body, model, combination)); case ExpressionType.OrElse: { var orElse = (BinaryExpression)expression; ConstraintSatisfaction left = SatisfiesConstraint(orElse.Left, model, combination); if (left == ConstraintSatisfaction.Satisfied) { return(ConstraintSatisfaction.Satisfied); } ConstraintSatisfaction right = SatisfiesConstraint(orElse.Right, model, combination); if (right == ConstraintSatisfaction.Satisfied) { return(ConstraintSatisfaction.Satisfied); } if (left == right) { return(left); } else { return(ConstraintSatisfaction.InsufficientData); } } default: if (!mapExpressionsToRequiredParams.ContainsKey(expression)) { throw new InternalVariationGenerationException("Expected data for expression not found."); } return(InternalConstraintHelpers.SatisfiesContraint(model, combination, mapExpressionsToRequiredParams[expression].Interaction)); } }
/// <summary> /// Calcultes whether the specified value satisfies the constraint or has insufficient data to do so. /// </summary> /// <param name="model">The model.</param> /// <param name="combination">The value.</param> /// <returns>The calculated result.</returns> internal abstract ConstraintSatisfaction SatisfiesContraint(Model model, ValueCombination combination);