/// <summary>
        /// Rate all possible matches for a single relation
        /// </summary>
        /// <param name="relation">The relation to find matches for</param>
        /// <param name="traits">References to the trait values used by relations</param>
        /// <param name="member1Ratings">Match ratings for the first member</param>
        /// <param name="member2Ratings">Match ratings for the second member</param>
        /// <param name="relationRatings">Output mapping of data pair to match rating</param>
        /// <typeparam name="T">The data type the Relation uses</typeparam>
        /// <returns>True if any matches were found, false otherwise</returns>
        public static bool RateMatches <T>(IRelation <T> relation,
                                           RelationTraitCache.ChildTraits <T> traits,
                                           Dictionary <int, float> member1Ratings,
                                           Dictionary <int, float> member2Ratings,
                                           Dictionary <RelationDataPair, float> relationRatings)
        {
            relationRatings.Clear();
            var child1TraitValues = traits.One;
            var child2TraitValues = traits.Two;

            foreach (var id1 in member1Ratings.Keys)
            {
                if (!child1TraitValues.TryGetValue(id1, out var value1))
                {
                    continue;
                }

                foreach (var id2 in member2Ratings.Keys)
                {
                    // matches for each child must have different IDs
                    if (id2 == id1)
                    {
                        continue;
                    }

                    // Both members must have the trait value present
                    if (!child2TraitValues.TryGetValue(id2, out var value2))
                    {
                        continue;
                    }

                    var relationRating = relation.RateDataMatch(ref value1, ref value2);
                    // if these two pieces of data did not match this relation, they cannot be used
                    if (relationRating <= 0f)
                    {
                        continue;
                    }

                    relationRatings.Add(new RelationDataPair(id1, id2), relationRating);
                }
            }

            return(relationRatings.Count > 0);
        }
示例#2
0
 /// <summary>
 /// Collapses a relation's match rating into a pass/fail.
 /// </summary>
 /// <param name="relation">The relation to evaluate</param>
 /// <param name="value">The data being filtered against</param>
 /// <typeparam name="T">The type of data the relation uses</typeparam>
 /// <returns>True if the given trait data passes the filter function, false otherwise</returns>
 public static bool PassesRelation <T>(this IRelation <T> relation, ref T child1Value, ref T child2Value)
 {
     return(relation.RateDataMatch(ref child1Value, ref child2Value) > 0f);
 }