Пример #1
0
    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);
        }
    }
Пример #2
0
    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);
    }
Пример #3
0
    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);
    }
Пример #4
0
    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);
    }
Пример #5
0
        /// <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));
        }
Пример #6
0
    private ContextMap ForwardGoingMap()
    {
        ContextMap map = new ContextMap(_steer.DirectionsCount);

        float weight = _steer.GetTheBestDirection().magnitude * 0.1f;

        map.AddInterestToVector(_walker.CurrentDirection, weight);

        return(map);
    }
Пример #7
0
 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]);
     }
 }
Пример #8
0
    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);
    }
Пример #9
0
        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);
        }
Пример #10
0
        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();
        }
Пример #11
0
    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);
        }
    }
Пример #12
0
 public override void Process(ContextMap <float> map)
 {
     throw new System.NotImplementedException();
 }
Пример #13
0
 private static ContextMap ReadContextMap(IBitReader reader, Category category, CategoryMap <BlockTypeInfo> blockTypes)
 {
     return(ContextMap.Deserialize(reader, blockTypes[category]));
 }
Пример #14
0
 public ViewQueueManger(DbExecutor database, ContextMap contextMap)
     : base(database, contextMap)
 {
 }
Пример #15
0
 public void TestGenerateWeights()
 {
     var target = new ContextMap();
     target.NeuronWeights.Should().NotBeNullOrEmpty();
     target.NeuronWeights.Length.Should().BeGreaterThan(1);
 }
Пример #16
0
 /// <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));
 }
Пример #17
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="database">数据库操作</param>
 /// <param name="contextMap">映射关系</param>
 public TableQueueManger(DbExecutor database, ContextMap contextMap)
     : base(database, contextMap)
 {
     _groupQueueList = new List <Queue>();
 }
Пример #18
0
 protected BaseQueueManger(DbExecutor database, ContextMap contextMap)
 {
     DataBase   = database;
     ContextMap = contextMap;
     DbProvider = DbProvider.CreateInstance(database.DataType);
 }
Пример #19
0
 public void SetNewMapUp()
 {
     _old_context_map = _context_map;
     ResetSteerData();
 }
Пример #20
0
        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);
        }
Пример #21
0
 public Steer(int directions_count)
 {
     _context_map     = new ContextMap(directions_count);
     _old_context_map = new ContextMap(directions_count);
 }