コード例 #1
0
        /// <summary>
        /// Returns a new table that is the union of the input tables.
        /// </summary>
        /// <param name="parameters">The model's parameters</param>
        /// <param name="first">First table</param>
        /// <param name="second">Second table</param>
        /// <param name="newState">Function to calculate state of merged value combinations</param>
        /// <returns>The new table</returns>
        public static ParameterInteraction Merge <T>(IList <ParameterBase> parameters, ParameterInteraction first, ParameterInteraction second, Func <ValueCombinationState, ValueCombinationState, ValueCombinationState> newState)
            where T : new()
        {
            List <int> parameterIndices = first.Parameters.Union(second.Parameters).ToList();

            parameterIndices.Sort();

            var mergedInteraction = new ParameterInteraction(parameterIndices);

            var valueTable = ParameterInteractionTable <T> .GenerateValueTable(parameters, mergedInteraction);

            foreach (var value in valueTable)
            {
                mergedInteraction.Combinations.Add(new ValueCombination(value, mergedInteraction));
            }

            foreach (var combination in mergedInteraction.Combinations)
            {
                var firstMatch  = first.Combinations.First((c) => ParameterInteractionTable <T> .MatchCombination(c, combination));
                var secondMatch = second.Combinations.First((c) => ParameterInteractionTable <T> .MatchCombination(c, combination));
                combination.State = newState(firstMatch.State, secondMatch.State);
            }

            return(mergedInteraction);
        }
コード例 #2
0
        // helper to implement Constraint.SatisfiesConstraint
        internal static ConstraintSatisfaction SatisfiesContraint <T>(Model <T> model, ValueCombination combination, ParameterInteraction interaction) where T : new()
        {
            Debug.Assert(model != null && combination != null && interaction != null);

            var parameterMap = combination.ParameterToValueMap;

            for (int i = 0; i < interaction.Parameters.Count; i++)
            {
                if (!parameterMap.ContainsKey(interaction.Parameters[i]))
                {
                    return(ConstraintSatisfaction.InsufficientData);
                }
            }

            for (int i = 0; i < interaction.Combinations.Count; i++)
            {
                if (ParameterInteractionTable <T> .MatchCombination(interaction.Combinations[i], combination))
                {
                    if (interaction.Combinations[i].State == ValueCombinationState.Excluded)
                    {
                        return(ConstraintSatisfaction.Unsatisfied);
                    }
                }
            }

            return(ConstraintSatisfaction.Satisfied);
        }
コード例 #3
0
        // helper to implement Constraint.SatisfiesConstraint
        internal static ConstraintSatisfaction SatisfiesContraint(Model model, ValueCombination combination, ParameterInteraction interaction)
        {
            Debug.Assert(model != null && combination != null && interaction != null);

            if (!interaction.Parameters.All((i) => combination.ParameterToVaueMap.ContainsKey(i)))
            {
                return(ConstraintSatisfaction.InsufficientData);
            }

            var matches = interaction.Combinations.Where((c) => ParameterInteractionTable.MatchCombination(c, combination));

            if (matches.Any((c) => c.State == ValueCombinationState.Excluded))
            {
                return(ConstraintSatisfaction.Unsatisfied);
            }

            return(ConstraintSatisfaction.Satisfied);
        }