public void ConditionRatingsData_ConstructsCorrectSizeArray_ForConditionCount() { AddOneOfEachConditionType(m_GameObject); m_GameObject.AddTestFloatCondition(); m_GameObject.AddTestFloatCondition(); m_GameObject.AddComponent <TestConditions.Pose>(); var ratings = new ConditionRatingsData(ProxyConditions.FromGenericIMRObject(m_ConditionsRoot)); Assert.AreEqual(10, ratings.totalConditionCount); Assert.AreEqual(3, ratings[typeof(float)].Count); Assert.AreEqual(2, ratings[typeof(Pose)].Count); Assert.AreEqual(1, ratings[typeof(bool)].Count); Assert.AreEqual(1, ratings[typeof(Vector2)].Count); Assert.AreEqual(1, ratings[typeof(Vector3)].Count); Assert.AreEqual(1, ratings[typeof(int)].Count); Assert.AreEqual(1, ratings[typeof(string)].Count); ratings[typeof(int)].AssertCollectionsCreated(); ratings[typeof(float)].AssertCollectionsCreated(); ratings[typeof(bool)].AssertCollectionsCreated(); ratings[typeof(Vector2)].AssertCollectionsCreated(); ratings[typeof(Vector3)].AssertCollectionsCreated(); ratings[typeof(string)].AssertCollectionsCreated(); ratings[typeof(Pose)].AssertCollectionsCreated(); }
/// <summary> /// Use this overload to get arguments for the next instance of a replicated Proxy /// </summary> /// <param name="original">The original / previous spawn's arguments</param> public TryBestMatchArguments(TryBestMatchArguments original) { conditions = original.conditions; exclusivity = original.exclusivity; // we can re-use the internal ratings structure for all instances of a spawn ratings = original.ratings; }
int Add(QueryMatchID matchId, IMRObject objectRef, Exclusivity exclusivity, int bestMatchDataId, bool isRequired, CachedTraitCollection traitCache, ProxyConditions condition, ProxyTraitRequirements requirements, ConditionRatingsData rating, HashSet <int> matchSet, Dictionary <int, float> flatRatings, QueryResult result) { var index = GetInsertionIndex(); QueryMatchIds[index] = matchId; ObjectReferences[index] = objectRef; Exclusivities[index] = exclusivity; Required[index] = isRequired; BestMatchDataIds[index] = bestMatchDataId; CachedTraits[index] = traitCache; Conditions[index] = condition; TraitRequirements[index] = requirements; RelationMemberships[index] = null; ConditionRatings[index] = rating; ReducedConditionRatings[index] = flatRatings; ConditionMatchSets[index] = matchSet; QueryResults[index] = result; m_Count++; ValidIndices.Add(index); return(index); }
void SetupObject(GameObject go) { var rwo = go.AddComponent <Proxy>(); m_Conditions = ProxyConditions.FromGenericIMRObject(rwo); m_ConditionRatings = new ConditionRatingsData(m_Conditions); m_TraitCache = new CachedTraitCollection(m_Conditions); m_Db.FindTraitCollections(m_Conditions, m_TraitCache); }
internal static ConditionRatingsData Setup() { var go = new GameObject(); go.AddComponent <Proxy>(); go.AddTestFloatCondition(); go.AddComponent <TestConditions.Pose>(); var conditions = ProxyConditions.FromGameObject <Proxy>(go); var ratings = new ConditionRatingsData(conditions); ratings[typeof(float)][0] = floatRatings; ratings[typeof(Pose)][0] = poseRatings; return(ratings); }
internal static bool RateConditionMatches(ProxyConditions conditions, CachedTraitCollection traitCache, ConditionRatingsData resultData) { if (conditions.Count <= 0) { return(false); } conditions.TryGetType(out ISemanticTagCondition[] semanticTagConditions); traitCache.TryGetType(out List <Dictionary <int, bool> > semanticTagTraits); var semanticTagsMatched = RateSemanticTagConditionMatches(semanticTagConditions, semanticTagTraits, resultData[typeof(bool)], resultData.MatchRuleIndexes); return(semanticTagsMatched && RateConditionMatchesInternal(conditions, traitCache, resultData)); }
[TestCase(0.05f, 0.06f, 0.08f, 0.1f, 0.05f, 0.1f)] // 4 near-failures public void GetRatingForId_ImplementsInversePowerReduction( float one, float two, float three, float four, // condition ratings float minBound, float maxBound) // expected boundaries { const int dataId = 3; var rwo = m_GameObject.AddComponent <Proxy>(); m_GameObject.AddTestFloatCondition(); m_GameObject.AddTestFloatCondition(); m_GameObject.AddTestVector2Condition(); m_GameObject.AddSemanticTagCondition(); var conditions = ProxyConditions.FromGenericIMRObject(rwo); var proposal = new ConditionRatingsData(conditions); proposal[typeof(float)][0].Add(dataId, one); proposal[typeof(float)][1].Add(dataId, two); proposal[typeof(Vector2)][0].Add(dataId, three); proposal[typeof(bool)][0].Add(dataId, four); AssertBetween(proposal.RatingForId(dataId), minBound, maxBound); }
internal static void Execute(ConditionRatingsData rawRatings, HashSet <int> matchSet, Dictionary <int, float> flatRatings) { s_Counter = 0; foreach (var dataId in matchSet) { s_RatingPairBuffer[s_Counter] = new KeyValuePair <int, float>(dataId, rawRatings.RatingForId(dataId)); s_Counter++; } // later stages will assume that the dictionary of ratings is sorted by value, so we sort here. // this call will only sort the members of the array up to s_Counter, because we're only using those. Array.Sort(s_RatingPairBuffer, 0, s_Counter, k_Comparer); flatRatings.Clear(); for (var i = 0; i < s_Counter; i++) { var kvp = s_RatingPairBuffer[i]; flatRatings.Add(kvp.Key, kvp.Value); } }
public void ExcludedTagsNotUsedAsIntersectionStartingPoint() { var tagConditions = new ISemanticTagCondition[2]; tagConditions[0] = m_TestObject.AddSemanticTagCondition("exclude", SemanticTagMatchRule.Exclude); tagConditions[1] = m_TestObject.AddSemanticTagCondition("match"); var conditions = new ProxyConditions(tagConditions); var ratings = new ConditionRatingsData(conditions) { MatchRuleIndexes = { SemanticTagMatchRule.Exclude, SemanticTagMatchRule.Match } }; // fake like we rated conditions var excludeRuleSet = new [] { 0, 1 }; var excludeRuleRatings = ratings[typeof(bool)][0]; foreach (var t in excludeRuleSet) { excludeRuleRatings.Add(t, 1); } var matchRuleSet = new [] { 2, 3, 4 }; var matchRuleRatings = ratings[typeof(bool)][1]; foreach (var t in matchRuleSet) { matchRuleRatings.Add(t, 1); } var matchSet = new HashSet <int>(); FindMatchProposalsTransform.GetStartingIdSet(ratings, matchSet); // because we can't use the excluding tag ratings as the starting set for intersection, // it should skip them & use another set, even though they come first in the ratings in our setup Assert.True(matchSet.SetEquals(matchRuleSet)); }
static bool FindQueryCandidateIntersection(ConditionRatingsData data, HashSet <int> matchSet) { // semantic tags need special handling because of tag exclusion - all other types are in generated code k_IDsMatchingCondition.Clear(); var tagRatingIndex = 0; var tagRatings = data[typeof(bool)]; if (tagRatings != null) { foreach (var dictionary in tagRatings) { k_IDsMatchingCondition.Clear(); if (data.MatchRuleIndexes[tagRatingIndex] == SemanticTagMatchRule.Exclude) { // exclusive tags fill out a list of what should be excluded, not included foreach (var kvp in dictionary) { var id = kvp.Key; matchSet.Remove(id); } } else { foreach (var kvp in dictionary) { k_IDsMatchingCondition.Add(kvp.Key); } matchSet.IntersectWith(k_IDsMatchingCondition); } tagRatingIndex++; } } return(matchSet.Count != 0 && FindIntersection(data, matchSet)); }
public TryBestMatchArguments(ProxyConditions conditions, Exclusivity exclusivity) { this.conditions = conditions; this.exclusivity = exclusivity; ratings = new ConditionRatingsData(conditions); }
static bool FindIntersection(ConditionRatingsData data, HashSet <int> matchSet) { var intData = data[typeof(System.Int32)]; if (intData != null) { foreach (var dictionary in intData) { k_IDsMatchingCondition.Clear(); foreach (var kvp in dictionary) { k_IDsMatchingCondition.Add(kvp.Key); } matchSet.IntersectWith(k_IDsMatchingCondition); } } if (matchSet.Count == 0) { return(false); } var floatData = data[typeof(System.Single)]; if (floatData != null) { foreach (var dictionary in floatData) { k_IDsMatchingCondition.Clear(); foreach (var kvp in dictionary) { k_IDsMatchingCondition.Add(kvp.Key); } matchSet.IntersectWith(k_IDsMatchingCondition); } } if (matchSet.Count == 0) { return(false); } var stringData = data[typeof(System.String)]; if (stringData != null) { foreach (var dictionary in stringData) { k_IDsMatchingCondition.Clear(); foreach (var kvp in dictionary) { k_IDsMatchingCondition.Add(kvp.Key); } matchSet.IntersectWith(k_IDsMatchingCondition); } } if (matchSet.Count == 0) { return(false); } var poseData = data[typeof(UnityEngine.Pose)]; if (poseData != null) { foreach (var dictionary in poseData) { k_IDsMatchingCondition.Clear(); foreach (var kvp in dictionary) { k_IDsMatchingCondition.Add(kvp.Key); } matchSet.IntersectWith(k_IDsMatchingCondition); } } if (matchSet.Count == 0) { return(false); } var vector2Data = data[typeof(UnityEngine.Vector2)]; if (vector2Data != null) { foreach (var dictionary in vector2Data) { k_IDsMatchingCondition.Clear(); foreach (var kvp in dictionary) { k_IDsMatchingCondition.Add(kvp.Key); } matchSet.IntersectWith(k_IDsMatchingCondition); } } if (matchSet.Count == 0) { return(false); } return(true); }
internal static void GetStartingIdSet(ConditionRatingsData data, HashSet <int> idSet) { idSet.Clear(); var tagRatings = data[typeof(bool)]; if (tagRatings != null && tagRatings.Count > 0) { for (var i = 0; i < tagRatings.Count; i++) { // If we're excluding, we can't use this set as the starting point if (data.MatchRuleIndexes[i] == SemanticTagMatchRule.Exclude) { continue; } var dictionary = tagRatings[i]; foreach (var kvp in dictionary) { idSet.Add(kvp.Key); } return; } } var intRatings = data[typeof(System.Int32)]; if (intRatings != null && intRatings.Count > 0) { foreach (var kvp in intRatings[0]) { idSet.Add(kvp.Key); } return; } var floatRatings = data[typeof(System.Single)]; if (floatRatings != null && floatRatings.Count > 0) { foreach (var kvp in floatRatings[0]) { idSet.Add(kvp.Key); } return; } var stringRatings = data[typeof(System.String)]; if (stringRatings != null && stringRatings.Count > 0) { foreach (var kvp in stringRatings[0]) { idSet.Add(kvp.Key); } return; } var poseRatings = data[typeof(UnityEngine.Pose)]; if (poseRatings != null && poseRatings.Count > 0) { foreach (var kvp in poseRatings[0]) { idSet.Add(kvp.Key); } return; } var vector2Ratings = data[typeof(UnityEngine.Vector2)]; if (vector2Ratings != null && vector2Ratings.Count > 0) { foreach (var kvp in vector2Ratings[0]) { idSet.Add(kvp.Key); } return; } }
public static bool RateConditionMatchesInternal(Conditions conditions, CachedTraitCollection traits, ConditionRatingsData ratings) { conditions.TryGetType(out ICondition <System.Int32>[] intConditions); if (!RateConditionType(intConditions, traits, ratings[typeof(System.Int32)])) { return(false); } conditions.TryGetType(out ICondition <System.Single>[] floatConditions); if (!RateConditionType(floatConditions, traits, ratings[typeof(System.Single)])) { return(false); } conditions.TryGetType(out ICondition <System.String>[] stringConditions); if (!RateConditionType(stringConditions, traits, ratings[typeof(System.String)])) { return(false); } conditions.TryGetType(out ICondition <UnityEngine.Pose>[] poseConditions); if (!RateConditionType(poseConditions, traits, ratings[typeof(UnityEngine.Pose)])) { return(false); } conditions.TryGetType(out ICondition <UnityEngine.Vector2>[] vector2Conditions); if (!RateConditionType(vector2Conditions, traits, ratings[typeof(UnityEngine.Vector2)])) { return(false); } return(true); }
internal static bool Execute(ConditionRatingsData ratings, HashSet <int> matchSet) { GetStartingIdSet(ratings, matchSet); return(FindQueryCandidateIntersection(ratings, matchSet)); }