private void RaycastBlockEvaluator(float[] mapToModify, CombiningMethod combiningMethod, Vector3 origin, float radius) { int count = mapToModify.Length; Vector3[] directions = ContextMap.GetDiscreteUnitCircleDirections(count); RaycastHit hit; for (int i = 0; i < count; i++) { bool didHit = Physics.Raycast(origin, directions [i], out hit, radius); float hitFraction; if (!didHit) { hitFraction = 1f; } else { hitFraction = hit.distance / radius; } ContextMap.CombineMapValues(mapToModify, hitFraction * hitFraction, i, combiningMethod); } }
private ContextMap ObstructionAvoidanceMap() { ContextMap map = new ContextMap(_steer.DirectionsCount); Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, VisionRadius, _danger_mask); foreach (Collider2D collider in colliders) { if (DangerIdentification(collider)) { RaycastHit2D[] hits = Physics2D.LinecastAll(transform.position, collider.transform.position); float distance = Vector2.Distance(transform.position, hits[hits.Length - 1].point); float weight = (VisionRadius - distance) / VisionRadius; if (weight < 0) { continue; } Vector2 danger = collider.transform.position - transform.position; map.AddInterestToVectorWithDesirableDot(-danger, weight, 0.65f); map.AddDangerToVectorWithThreshold(danger, weight, 0.65f); } } return(map); }
private void UpdateBehaviors() { if (_contextMap == null) { _contextMap = new float[_contextMapLOD]; } System.Array.Clear(_contextMap, 0, _contextMap.Length); // if have goal GenericEvaluators.ConstantEvaluator(_contextMap, CombiningMethod.Set, value: 0.5f); GenericEvaluators.TargetEvaluator(_contextMap, CombiningMethod.KeepLargest, origin: RaycastOrigin, target: _currDest); ContextMap.VisualizeMap(_contextMap, RaycastOrigin + Vector3.up * 5f, Color.green); ContextMap.NormalizeMap(_contextMap); // ContextMap.VisualizeMap (_contextMap, RaycastOrigin + Vector3.up * 1f, Color.yellow); RaycastBlockEvaluator(_contextMap, CombiningMethod.Multiply, origin: RaycastOrigin, radius: _collisionAvoidanceRadius); float[] testMap = new float[_contextMapLOD]; RaycastBlockEvaluator(testMap, CombiningMethod.Set, origin: RaycastOrigin, radius: _collisionAvoidanceRadius); // ContextMap.NormalizeMap(testMap); ContextMap.VisualizeMap(testMap, RaycastOrigin + Vector3.up * 2f, Color.red, scale: _collisionAvoidanceRadius); }
private ContextMap TargetPursuingMap() { ContextMap map = new ContextMap(_steer.DirectionsCount); Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, VisionRadius, _target_mask); foreach (Collider2D collider in colliders) { if (TargetIdentification(collider)) { RaycastHit2D[] hits = Physics2D.LinecastAll(transform.position, collider.transform.position); float distance = Vector2.Distance(transform.position, hits[hits.Length - 1].point); float weight = (VisionRadius - distance) / VisionRadius; if (weight < 0) { continue; } map.AddInterestToVector(collider.transform.position - transform.position, weight); } } return(map); }
/// <summary> /// 创建数据库操作 /// </summary> /// <typeparam name="TEntity">实体类</typeparam> /// <param name="tranLevel">开启事务等级</param> public static DbExecutor CreateDbExecutor <TEntity>(IsolationLevel tranLevel = IsolationLevel.Serializable) where TEntity : DbContext { ContextMap map = typeof(TEntity); var dataType = map.ContextProperty.DataType; var connetionString = map.ContextProperty.ConnStr; var commandTimeout = map.ContextProperty.CommandTimeout; return(new DbExecutor(connetionString, dataType, commandTimeout, tranLevel)); }
private ContextMap ForwardGoingMap() { ContextMap map = new ContextMap(_steer.DirectionsCount); float weight = _steer.GetTheBestDirection().magnitude * 0.1f; map.AddInterestToVector(_walker.CurrentDirection, weight); return(map); }
public void ApplyContextMap(ContextMap map) { for (int i = 0; i < _context_map.DirectionsCount; i++) { _context_map.Interests[i] = Mathf.Max(map.Interests[i], _context_map.Interests[i]); } for (int i = 0; i < _context_map.DirectionsCount; i++) { _context_map.Dangers[i] = Mathf.Max(map.Dangers[i], _context_map.Dangers[i]); } }
private Vector3 ChooseDirectionGivenContextMapAndHeading(float[] map, Vector3 heading) { int count = map.Length; Vector3[] directions = ContextMap.GetDiscreteUnitCircleDirections(count); float epsilon = 0.1f; int bestIndex = 0; int i = 0; float maxValue = map [i]; float bestAmountTowardDirection = Vector3.Dot(heading, directions [i]); for (i = 1; i < count; i++) { float currVal = map [i]; // When there is a tie between directional goodness, prefer the one closest to heading. if (Mathf.Abs(currVal - maxValue) <= epsilon) { float currAmountTowardDirection = Vector3.Dot(heading, directions [i]); if (currAmountTowardDirection > bestAmountTowardDirection) { bestAmountTowardDirection = currAmountTowardDirection; bestIndex = i; maxValue = currVal; } continue; } if (currVal > maxValue) { bestAmountTowardDirection = Vector3.Dot(heading, directions [i]); bestIndex = i; maxValue = currVal; continue; } } Vector3 dir = directions[bestIndex] * map[bestIndex]; dir += directions[MathUtils.Modulo(bestIndex + 1, count)] * map[MathUtils.Modulo(bestIndex + 1, count)]; dir += directions[MathUtils.Modulo(bestIndex - 1, count)] * map[MathUtils.Modulo(bestIndex - 1, count)]; dir /= 3f; return(dir); }
public ContextBase() { ContextMap contextMap = null; if (!ContextMaps.ContainsKey(this.GetType())) { contextMap = SetupMaps(this); } else { contextMap = ContextMaps[this.GetType()]; } ContextMap = contextMap; SetupDbSets(); ObjectTracker = new ObjectTracker(this); ObjectMaterializer = new Tracking.ObjectMaterializer(ObjectTracker); contextMap.InitializeContext(this); }
public CompressedHeader( CategoryMap <BlockTypeInfo> blockTypes, DistanceParameters distanceParameters, IList <LiteralContextMode> literalCtxModes, ContextMap literalCtxMap, ContextMap distanceCtxMap, IList <LiteralTree> literalTrees, IList <InsertCopyTree> insertCopyTrees, IList <DistanceTree> distanceTrees ) { this.BlockTypes = blockTypes; this.DistanceParameters = distanceParameters; this.LiteralCtxModes = literalCtxModes.ToArray(); this.LiteralCtxMap = literalCtxMap; this.DistanceCtxMap = distanceCtxMap; this.LiteralTrees = literalTrees.ToArray(); this.InsertCopyTrees = insertCopyTrees.ToArray(); this.DistanceTrees = distanceTrees.ToArray(); }
private void Update() { Vector2 pos = _camera.ScreenToWorldPoint(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { GameObject obj = Instantiate(_intereset_prefab, pos, Quaternion.identity); _interesets.Add(obj.transform); obj.SetActive(true); } else if (Input.GetMouseButtonDown(1)) { GameObject obj = Instantiate(_danger_prefab, pos, Quaternion.identity); _dangers.Add(obj.transform); obj.SetActive(true); } _steer.SetNewMapUp(); ContextMap interest_map = new ContextMap(_direction_number); foreach (Transform danger in _dangers) { float weight = (_vision_radius - danger.position.magnitude) / _vision_radius; interest_map.AddInterestToVectorWithDesirableDot(-danger.position, weight, _desirable_dot); interest_map.AddDangerToVectorWithThreshold(danger.position, weight, _threshold); } _steer.ApplyContextMap(interest_map); ContextMap danger_map = new ContextMap(_direction_number); foreach (Transform interest in _interesets) { float weight = (_vision_radius - interest.position.magnitude) / _vision_radius; danger_map.AddInterestToVector(interest.position, weight); } }
public override void Process(ContextMap <float> map) { throw new System.NotImplementedException(); }
private static ContextMap ReadContextMap(IBitReader reader, Category category, CategoryMap <BlockTypeInfo> blockTypes) { return(ContextMap.Deserialize(reader, blockTypes[category])); }
public ViewQueueManger(DbExecutor database, ContextMap contextMap) : base(database, contextMap) { }
public void TestGenerateWeights() { var target = new ContextMap(); target.NeuronWeights.Should().NotBeNullOrEmpty(); target.NeuronWeights.Length.Should().BeGreaterThan(1); }
/// <summary> /// Creates <see cref="MappingSource{TContext}"/> based on <see cref="ContextMap{TContext}"/>. /// </summary> /// <param name="contextMap">Instance of context mapping</param> /// <typeparam name="TContext">Type of <see cref="ISpContext"/></typeparam> /// <returns>Mapping source for the specified <typeparamref name="TContext"/>.</returns> public MappingSource <TContext> ClassLike <TContext>(ContextMap <TContext> contextMap) where TContext : ISpContext { return(new ClassLikeMappingSource <TContext>(contextMap)); }
/// <summary> /// 构造函数 /// </summary> /// <param name="database">数据库操作</param> /// <param name="contextMap">映射关系</param> public TableQueueManger(DbExecutor database, ContextMap contextMap) : base(database, contextMap) { _groupQueueList = new List <Queue>(); }
protected BaseQueueManger(DbExecutor database, ContextMap contextMap) { DataBase = database; ContextMap = contextMap; DbProvider = DbProvider.CreateInstance(database.DataType); }
public void SetNewMapUp() { _old_context_map = _context_map; ResetSteerData(); }
protected static ContextMap SetupMaps(ContextBase thisItem) { if (ContextMaps == null) { ContextMaps = new ConcurrentDictionary <Type, ContextMap>(); } ContextMap contextMap = new ContextMap(); foreach (var prop in thisItem.GetType().GetProperties()) { if (prop.PropertyType.Name == "KVSDbSet`1" || prop.PropertyType.Name == "ICollection`1") { Type entityType = prop.PropertyType.GetGenericArguments().Last(); var entityProps = entityType.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); var keyProp = entityProps.SingleOrDefault(q => q.Name == "Key" || q.Name == "Id"); var entityMap = new EntityMap(entityType, prop.GetGetMethod(), prop.GetSetMethod(), prop.PropertyType.GetConstructor(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, new Type[] { typeof(EntityMap), typeof(ContextBase) }, new System.Reflection.ParameterModifier[] { }), keyProp.Name, keyProp.GetGetMethod()); contextMap.EntityMaps.Add(entityMap); } } foreach (var entityMap in contextMap.EntityMaps) { foreach (var prop in entityMap.EntityType.GetProperties()) { if (prop.PropertyType.Name == "KVSCollection`1" || prop.PropertyType.Name == "ICollection`1") { Type targetEntityType = prop.PropertyType.GetGenericArguments().Last(); var targetEntityMap = contextMap.EntityMaps.SingleOrDefault(q => q.EntityType == targetEntityType); if (targetEntityMap != null) { var relationshipMap = new RelationshipMap() { LocalObjectMap = entityMap, TargetObjectMap = targetEntityMap, PropertyName = prop.Name, IsManyToTarget = true }; contextMap.RelationshipMaps.Add(relationshipMap); entityMap.RelationshipMaps.Add(relationshipMap); } //many relationship } else if (contextMap.EntityMaps.Any(q => q.EntityType == prop.PropertyType)) { //foreign key ref (single relationship) Type targetEntityType = prop.PropertyType; var targetEntityMap = contextMap.EntityMaps.SingleOrDefault(q => q.EntityType == targetEntityType); if (targetEntityMap != null) { var relationshipMap = new RelationshipMap() { LocalObjectMap = entityMap, TargetObjectMap = targetEntityMap, PropertyName = prop.Name }; contextMap.RelationshipMaps.Add(relationshipMap); entityMap.RelationshipMaps.Add(relationshipMap); } } } //find relationships } ContextMaps.TryAdd(thisItem.GetType(), contextMap); return(contextMap); }
public Steer(int directions_count) { _context_map = new ContextMap(directions_count); _old_context_map = new ContextMap(directions_count); }