예제 #1
0
        // adds an interaction generated from a constraint to the table
        private void MergeConstraintInteraction(int order, ParameterInteraction constraintInteraction)
        {
            // is the constraint already in the table
            if (!Interactions.Contains(constraintInteraction))
            {
                // if the interaction has more parameters than the order we can't mark any of the existing combinations excluded
                // if the interaction is shorter we need to mark the existing combinations excluded
                if (constraintInteraction.Parameters.Count > order)
                {
                    Interactions.Add(constraintInteraction);
                }
                else
                {
                    var excludedValues = constraintInteraction.Combinations.Where((c) => c.State == ValueCombinationState.Excluded);

                    var candidateInteractions =
                        from interaction in Interactions
                        where constraintInteraction.Parameters.All((i) => interaction.Parameters.Contains(i))
                        select interaction;

                    var excludedCombinations =
                        from interaction in candidateInteractions
                        from combination in interaction.Combinations
                        where excludedValues.Any((c) => MatchCombination(c, combination))
                        select combination;

                    foreach (var combination in excludedCombinations)
                    {
                        combination.State = ValueCombinationState.Excluded;
                    }
                }
            }
            else
            {
                // mark combinations excluded by the constraint excluded in the table
                var interaction = Interactions.First((i) => i.Equals(constraintInteraction));

                var excludedValues = constraintInteraction.Combinations.Where((c) => c.State == ValueCombinationState.Excluded);

                var combinations = interaction.Combinations.Where((c) => excludedValues.Any((excluded) => MatchCombination(excluded, c)));
                foreach (var combination in combinations)
                {
                    combination.State = ValueCombinationState.Excluded;
                }
            }
        }