Ejemplo n.º 1
0
        public async Task TestConfirmed()
        {
            var queue = new SimpleQueue <SimpleDocument>(GetType().FullName);
            await queue.Clear();

            await queue.Enqueue(new SimpleDocument()
            {
                Value = "test"
            });

            var value = await queue.Dequeue(new DequeueOptions()
            {
                ConfirmTime = TimeSpan.FromMilliseconds(500)
            });

            Assert.AreEqual("test", value.Payload.Value);

            await queue.Confirm(value);


            value = await queue.Dequeue();

            Assert.IsNull(value);

            await Task.Delay(1000);

            value = await queue.Dequeue();

            Assert.IsNull(value);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            // Create simple queue.
            var simpleQueue = new SimpleQueue();

            // Create queue configurator.
            var queueConfiguration = new MagicQueueConfiguration();

            // Create magic queue mased on configurator and simple queue.
            var queue = new MagicQueue(simpleQueue, queueConfiguration);

            // Create new magic man.
            var magicMan = new MagicMan(queue);

            // Configure queue.
            // Q+F traslated into T
            queueConfiguration.AddCombine('Q', 'F', 'T');

            // Q&F will clear the queue.
            queueConfiguration.AddOpposed('Q', 'F');

            // Do magic.
            magicMan.InvokeElements("FAQFDFQ");

            // Take result.
            var res = simpleQueue.Result;

            Console.WriteLine(res);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CrossGridVectorField"/> class.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="path">The path.</param>
        /// <param name="options">The options.</param>
        public CrossGridVectorField(TransientGroup <IUnitFacade> group, Path path, VectorFieldOptions options)
        {
            Ensure.ArgumentNotNull(group, "group");
            this.group = group;

            _currentPath = path;

            var modelUnit = group.modelUnit;

            _unitProperties = modelUnit;
            var pathOptions = modelUnit.pathFinderOptions;

            // cache options locally
            _allowCornerCutting = pathOptions.allowCornerCutting;
            _allowDiagonals     = !pathOptions.preventDiagonalMoves;
            _announceAllNodes   = modelUnit.pathNavigationOptions.announceAllNodes;

            _obstacleStrengthFactor     = options.obstacleStrengthFactor;
            _builtInContainment         = options.builtInContainment;
            _updateInterval             = options.updateInterval;
            _paddingIncrease            = options.paddingIncrease;
            _maxExtraPadding            = options.maxExtraPadding;
            _boundsPadding              = options.boundsPadding;
            _boundsRecalculateThreshold = options.boundsRecalculateThreshold;
            _expectedGroupGrowthFactor  = 1f + options.expectedGroupGrowthFactor;

            // pre-allocate lists
            _openSet = new SimpleQueue <Cell>(31);
            _tempWalkableNeighbours      = new DynamicArray <Cell>(8);
            _extraTempWalkableNeighbours = new DynamicArray <Cell>(8);
            _groupBounds = new RectangleXZ(group.centerOfGravity, _boundsPadding, _boundsPadding);

            _grids = new List <IGrid>(4);
        }
Ejemplo n.º 4
0
        public async Task Test()
        {
            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);
            await queue.Clear();

            var producers = new List <Task>();

            for (int i = 0; i < 4; i++)
            {
                producers.Add(Task.Run(() => Produce(10)));
            }


            var consumers = new List <Task>();

            for (int i = 0; i < 8; i++)
            {
                consumers.Add(Task.Run(Consume));
            }


            await Task.WhenAll(producers.Concat(consumers));


            Assert.AreEqual(40, _totalConsumed);
        }
Ejemplo n.º 5
0
        public void TestQueueBehavior()
        {
            List <char> chars = new List <char> {
                'a', 'b', 'c'
            };

            SimpleQueue <char> charQueue = new SimpleQueue <char>(chars);

            chars.Add('d');
            chars.Add('e');
            chars.Add('f');

            charQueue.Enqueue('d');
            charQueue.Enqueue('e');
            charQueue.Enqueue('f');

            int index = 0;

            while (!charQueue.IsEmpty())
            {
                Assert.AreEqual(chars[index++], charQueue.Dequeue());
            }

            Assert.AreEqual(0, charQueue.Count);
        }
Ejemplo n.º 6
0
        private static bool TestCase_Dequeue()  //Hebein Fabian
        {
            bool        status = true;
            int         size   = 5;
            int         idx;
            SimpleQueue q1 = new SimpleQueue(size);

            for (idx = 0; idx < size; idx++)
            {
                q1.Enqueue(idx);
            }
            idx = 0;
            while (idx < size && status == true)
            {
                if (q1.Dequeue() != idx)
                {
                    status = false;
                }
                idx++;
            }
            if (status == true)
            {
                try
                {
                    status = false;
                    q1.Dequeue();
                }
                catch
                {
                    status = true;
                }
            }

            return(status);
        }
Ejemplo n.º 7
0
 /// <summary>Removes all waiters from the queue, completing each.</summary>
 /// <param name="waiters">The queue of waiters to complete.</param>
 /// <param name="result">The value with which to complete each waiter.</param>
 private static void WakeUpWaiters(SimpleQueue <Reader <bool> > waiters, bool result)
 {
     if (waiters.Count > 0)
     {
         WakeUpWaitersCore(waiters, result); // separated out to streamline inlining
     }
 }
Ejemplo n.º 8
0
 /// <summary>Core of WakeUpWaiters, separated out for performance due to inlining.</summary>
 private static void WakeUpWaitersCore(SimpleQueue <Reader <bool> > waiters, bool result)
 {
     while (waiters.Count > 0)
     {
         waiters.Dequeue().Success(result);
     }
 }
Ejemplo n.º 9
0
        static bool TestCase_Copy()         //Fahrgruber Samuel
        {
            int         capacity         = 100;
            int         numberOfElements = 50;
            bool        result           = false;
            SimpleQueue q1 = new SimpleQueue(capacity);
            SimpleQueue q2;
            int         idx;

            for (idx = 0; idx < numberOfElements; idx++)
            {
                q1.Enqueue(idx);
            }
            q2 = q1.Copy();
            if (q1 != q2)
            {
                result = true;
            }
            while (result == true && idx > 0)
            {
                try
                {
                    if (q1.Dequeue() != q2.Dequeue())
                    {
                        result = false;
                    }
                }
                catch
                {
                    result = false;
                }
                idx--;
            }
            return(result);
        }
Ejemplo n.º 10
0
        // Driver code
        public static void Main()
        {
            // Calling Arraylist
            ArraylistSample arr = new ArraylistSample();

            arr.arrayListTest();

            // Calling Queue
            SimpleQueue nq = new SimpleQueue();

            nq.QueueD();

            // Calling Stack
            SimpleStack sta = new SimpleStack();

            sta.StackD();

            SimpleHashTable HT = new SimpleHashTable();

            HT.HashT();

            Array coll = new Array();

            coll.CollectionsS();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FullGridVectorField"/> class.
        /// </summary>
        /// <param name="group">The transient unit group.</param>
        /// <param name="path">The path.</param>
        /// <param name="options">The vector field options.</param>
        public FullGridVectorField(TransientGroup<IUnitFacade> group, Path path, VectorFieldOptions options)
        {
            Ensure.ArgumentNotNull(group, "group");
            this.group = group;

            _currentPath = path;

            var modelUnit = group.modelUnit;
            _unitProperties = modelUnit;
            var pathOptions = modelUnit.pathFinderOptions;

            // cache options locally
            _obstacleStrengthFactor = options.obstacleStrengthFactor;
            _allowCornerCutting = pathOptions.allowCornerCutting;
            _allowDiagonals = !pathOptions.preventDiagonalMoves;
            _announceAllNodes = modelUnit.pathNavigationOptions.announceAllNodes;

            _builtInContainment = options.builtInContainment;
            _updateInterval = options.updateInterval;

            // pre-allocate lists
            _openSet = new SimpleQueue<Cell>(31);
            _tempWalkableNeighbours = new DynamicArray<Cell>(8);
            _extraTempWalkableNeighbours = new DynamicArray<Cell>(8);

            _grid = GridManager.instance.GetGrid(group.modelUnit.position);
            if (_grid != null)
            {
                _fastMarchedCells = new PlaneVector[_grid.sizeX, _grid.sizeZ];
                _cellDirs = new VectorFieldCell[_grid.sizeX, _grid.sizeZ];
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Setups signal delaying
 /// </summary>
 /// <param name="distancesStat">Distance statistics to be used when synaptic delay method is Distance</param>
 /// <param name="rand">Random object to be used when synaptic delay method is Random</param>
 public void SetupDelay(BasicStat distancesStat, Random rand)
 {
     if (_maxDelay > 0)
     {
         //Set synapse signal delay
         if (DelayMethod == SynapticDelayMethod.Distance)
         {
             double relDistance = (Distance - distancesStat.Min) / distancesStat.Span;
             Delay = (int)Math.Round(_maxDelay * relDistance);
         }
         else
         {
             Delay = rand.Next(_maxDelay + 1);
         }
         if (Delay == 0)
         {
             //No queue will be used
             _signalQueue = null;
         }
         else
         {
             //Delay queue
             _signalQueue = new SimpleQueue <Signal>(Delay + 1);
         }
     }
     return;
 }
Ejemplo n.º 13
0
 //Constructor
 /// <summary>
 /// Creates an initialized instance of hidden neuron having analog activation
 /// </summary>
 /// <param name="location">Information about a neuron location within the neural preprocessor</param>
 /// <param name="analogActivation">Instantiated activation function.</param>
 /// <param name="bias">Constant bias to be applied.</param>
 /// <param name="firingThreshold">A number between 0 and 1 (LT1). Every time the new activation value is higher than the previous activation value by at least the threshold, it is evaluated as a firing event.</param>
 /// <param name="thresholdMaxRefDeepness">Maximum deepness of historical normalized activation value to be compared with current normalized activation value when evaluating firing event.</param>
 /// <param name="retainmentStrength">Strength of the analog neuron's retainment property.</param>
 /// <param name="predictorsCfg">Configuration of neuron's predictors</param>
 public HiddenNeuron(NeuronLocation location,
                     IActivationFunction analogActivation,
                     double bias,
                     double firingThreshold,
                     int thresholdMaxRefDeepness,
                     double retainmentStrength,
                     PredictorsSettings predictorsCfg
                     )
 {
     Location   = location;
     Statistics = new NeuronStatistics();
     Bias       = bias;
     //Activation check
     if (analogActivation.TypeOfActivation == ActivationType.Spiking)
     {
         throw new InvalidOperationException($"Called wrong type of hidden neuron constructor for analog activation.");
     }
     _activation               = analogActivation;
     _analogFiringThreshold    = firingThreshold;
     _histActivationsQueue     = thresholdMaxRefDeepness < 2 ? null : new SimpleQueue <double>(thresholdMaxRefDeepness);
     _analogRetainmentStrength = retainmentStrength;
     _predictors               = predictorsCfg != null ? new PredictorsProvider(predictorsCfg) : null;
     OutputData = new NeuronOutputData();
     Reset(false);
     return;
 }
Ejemplo n.º 14
0
        public async Task TestEnqueueDeque()
        {
            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);

            await queue.Clear();

            var simpleStrings = new List <string>();

            for (int i = 0; i < 100; i++)
            {
                simpleStrings.Add(Guid.NewGuid().ToString().Replace("-", ""));
            }

            var documents = simpleStrings.Select(q => new SimpleDocument()
            {
                Value = q
            });


            await Task.WhenAll(documents.Select(simpleDocument => queue.Enqueue(simpleDocument, new EnqueOptions())));

            for (int i = 0; i < 100; i++)
            {
                Assert.IsNotNull(await queue.Dequeue(new DequeueOptions()));
            }
            var document = await queue.Dequeue(new DequeueOptions());

            Assert.IsNull(document);
        }
Ejemplo n.º 15
0
        public async Task TestPriority()
        {
            var rand = new Random();

            var priorities = Enumerable.Range(1, 200).OrderBy(q => rand.Next()).ToList();

            var queue = new SimpleQueue <SimpleDocument>(this.GetType().FullName);

            await queue.Clear();

            foreach (var priority in priorities)
            {
                await queue.Enqueue(
                    new SimpleDocument()
                {
                    Value = priority.ToString()
                },
                    new EnqueOptions()
                {
                    Priority = (byte)priority
                });
            }

            for (byte i = 200; i >= 1; i--)
            {
                Assert.AreEqual(i.ToString(), (await queue.Dequeue()).Payload.Value);
            }
        }
        /// <inheritdoc/>
        public double Compute(BasicStat continuousActivationStat,
                              BasicStat continuousActivationDiffStat,
                              MovingDataWindow activationMDW,
                              SimpleQueue <byte> firingMDW,
                              double activation,
                              double normalizedActivation,
                              bool spike
                              )
        {
            PredictorActivationDiffStatFigureSettings cfg = (PredictorActivationDiffStatFigureSettings)Cfg;

            if (cfg.Window == PredictorActivationDiffStatFigureSettings.NAWindowNum)
            {
                return(continuousActivationDiffStat.Get(cfg.Figure));
            }
            else
            {
                if (activationMDW.UsedCapacity >= cfg.Window)
                {
                    return(activationMDW.GetDataDiffStat(cfg.Window).Get(cfg.Figure));
                }
                else
                {
                    return(0d);
                }
            }
        }
Ejemplo n.º 17
0
        static bool TestCase_Find() //Moritz Breschan
        {                           //rgw gibt an wie viele Elemente gefunden wurde
            bool        rgw     = true;
            SimpleQueue s1      = new SimpleQueue(20);
            int         counter = 0;

            for (counter = 0; counter < 10; counter++)
            {
                s1.Enqueue(counter);
            }
            for (counter = 9; counter >= 0; counter--)
            {
                s1.Enqueue(counter);
            }
            counter = 0;
            while (counter < 10 && rgw)
            {
                if (s1.Find(counter) != 2)
                {
                    rgw = false;
                }
                counter++;
            }
            return(rgw);
        }
Ejemplo n.º 18
0
        private static bool TestCase_Resize()     //Melanie Bugelnig
        {
            int         newCapacity = 5;
            SimpleQueue s1          = new SimpleQueue(newCapacity);
            bool        result      = true;
            int         counter;

            for (counter = 0; counter < newCapacity; counter++)
            {
                s1.Enqueue(counter);
            }
            newCapacity = 10;

            s1.Resize(newCapacity);

            for (; counter < newCapacity; counter++)
            {
                s1.Enqueue(counter);
            }
            counter--;

            if (s1.GetElement() != counter)
            {
                result = false;
            }
            counter--;

            return(result);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CrossGridVectorField"/> class.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="path">The path.</param>
        /// <param name="options">The options.</param>
        public CrossGridVectorField(TransientGroup<IUnitFacade> group, Path path, VectorFieldOptions options)
        {
            Ensure.ArgumentNotNull(group, "group");
            this.group = group;

            _currentPath = path;

            var modelUnit = group.modelUnit;
            _unitProperties = modelUnit;
            var pathOptions = modelUnit.pathFinderOptions;

            // cache options locally
            _allowCornerCutting = pathOptions.allowCornerCutting;
            _allowDiagonals = !pathOptions.preventDiagonalMoves;
            _announceAllNodes = modelUnit.pathNavigationOptions.announceAllNodes;

            _obstacleStrengthFactor = options.obstacleStrengthFactor;
            _builtInContainment = options.builtInContainment;
            _updateInterval = options.updateInterval;
            _paddingIncrease = options.paddingIncrease;
            _maxExtraPadding = options.maxExtraPadding;
            _boundsPadding = options.boundsPadding;
            _boundsRecalculateThreshold = options.boundsRecalculateThreshold;
            _expectedGroupGrowthFactor = 1f + options.expectedGroupGrowthFactor;

            // pre-allocate lists
            _openSet = new SimpleQueue<Cell>(31);
            _tempWalkableNeighbours = new DynamicArray<Cell>(8);
            _extraTempWalkableNeighbours = new DynamicArray<Cell>(8);
            _groupBounds = new RectangleXZ(group.centerOfGravity, _boundsPadding, _boundsPadding);

            _grids = new List<IGrid>(4);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FullGridVectorField"/> class.
        /// </summary>
        /// <param name="group">The transient unit group.</param>
        /// <param name="path">The path.</param>
        /// <param name="options">The vector field options.</param>
        public FullGridVectorField(TransientGroup <IUnitFacade> group, Path path, VectorFieldOptions options)
        {
            Ensure.ArgumentNotNull(group, "group");
            this.group = group;

            _currentPath = path;

            var modelUnit = group.modelUnit;

            _unitProperties = modelUnit;
            var pathOptions = modelUnit.pathFinderOptions;

            // cache options locally
            _obstacleStrengthFactor = options.obstacleStrengthFactor;
            _allowCornerCutting     = pathOptions.allowCornerCutting;
            _allowDiagonals         = !pathOptions.preventDiagonalMoves;
            _announceAllNodes       = modelUnit.pathNavigationOptions.announceAllNodes;

            _builtInContainment = options.builtInContainment;
            _updateInterval     = options.updateInterval;

            // pre-allocate lists
            _openSet = new SimpleQueue <Cell>(31);
            _tempWalkableNeighbours      = new DynamicArray <Cell>(8);
            _extraTempWalkableNeighbours = new DynamicArray <Cell>(8);

            _grid = GridManager.instance.GetGrid(group.modelUnit.position);
            if (_grid != null)
            {
                _fastMarchedCells = new PlaneVector[_grid.sizeX, _grid.sizeZ];
                _cellDirs         = new VectorFieldCell[_grid.sizeX, _grid.sizeZ];
            }
        }
Ejemplo n.º 21
0
        /// <inheritdoc/>
        public double Compute(BasicStat continuousActivationStat,
                              BasicStat continuousActivationDiffStat,
                              MovingDataWindow activationMDW,
                              SimpleQueue <byte> firingMDW,
                              double activation,
                              double normalizedActivation,
                              bool spike
                              )
        {
            PredictorFiringTraceSettings cfg = (PredictorFiringTraceSettings)Cfg;

            if (cfg.Window == PredictorFiringTraceSettings.NAWindowNum)
            {
                return(_continuousTrace);
            }
            else
            {
                if (firingMDW.Count >= cfg.Window)
                {
                    double trace = 0d;
                    for (int i = cfg.Window - 1; i >= 0; i--)
                    {
                        trace *= (1d - cfg.Fading);
                        trace += firingMDW.GetElementAt(i, true);
                    }
                    return(trace);
                }
                else
                {
                    return(0d);
                }
            }
        }
Ejemplo n.º 22
0
 //Constructor
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="location">The neuron's location.</param>
 /// <param name="analogActivation">The instance of an analog activation function.</param>
 /// <param name="bias">The constant bias.</param>
 /// <param name="firingThreshold">The firing threshold value. It must be GE0 and LT1. Every time the current normalized activation is higher than the normalized past reference activation by at least this threshold, it is evaluated as a firing event.</param>
 /// <param name="firingThresholdMaxRefDeepness">Maximum age of the past activation for the evaluation of the firing event.</param>
 /// <param name="retainmentStrength">The strength of the analog neuron's retainment property. It enables the leaky integrator feature of the neuron.</param>
 /// <param name="predictorsProviderCfg">The configuration of the predictors provider.</param>
 public HiddenNeuron(NeuronLocation location,
                     AFAnalogBase analogActivation,
                     double bias,
                     double firingThreshold,
                     int firingThresholdMaxRefDeepness,
                     double retainmentStrength,
                     PredictorsProviderSettings predictorsProviderCfg
                     )
 {
     Location   = location;
     Statistics = new NeuronStatistics();
     Bias       = bias;
     //Activation check
     if (analogActivation.TypeOfActivation == ActivationType.Spiking)
     {
         throw new ArgumentException($"Wrong type of the activation function.", "analogActivation");
     }
     _activationFn             = analogActivation;
     _analogFiringThreshold    = firingThreshold;
     _histActivationsQueue     = firingThresholdMaxRefDeepness < 2 ? null : new SimpleQueue <double>(firingThresholdMaxRefDeepness);
     _analogRetainmentStrength = retainmentStrength;
     _predictorsProvider       = predictorsProviderCfg != null ? new PredictorsProvider(predictorsProviderCfg) : null;
     OutputData = new NeuronOutputData();
     Reset(false);
     return;
 }
Ejemplo n.º 23
0
        private IEnumerable <TreeNode> TraverseBreadthFirst()
        {
            if (Count == 0)
            {
                yield break;
            }

            var queue = new SimpleQueue <TreeNode>();

            queue.Enqueue(_root);
            while (queue.Count > 0)
            {
                var current = queue.Dequeue();
                yield return(current);

                if (current.Left != null)
                {
                    queue.Enqueue(current.Left);
                }
                if (current.Right != null)
                {
                    queue.Enqueue(current.Right);
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Called on Awake
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            this.WarnIfMultipleInstances();

            _transform = this.transform;

            _wayPoints          = new SimpleQueue <Vector3>();
            _pathboundWayPoints = new SimpleQueue <Vector3>();
            _navMessage         = new UnitNavigationEventMessage(this.gameObject);

            _resultProcessors = this.GetComponents <SteerForPathResultProcessorComponent>();
            Array.Sort(_resultProcessors, (a, b) => a.processingOrder.CompareTo(b.processingOrder));

            _unit         = this.GetUnitFacade();
            _pathSettings = _unit.pathNavigationOptions;

            if (this.arrivalDistance > _pathSettings.nextNodeDistance)
            {
                Debug.LogError("The Arrival Distance must be equal to or less that the Next Node Distance.");
            }

            _stopped = true;
            _unit.hasArrivedAtDestination = true;
        }
Ejemplo n.º 25
0
 //Constructor
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="coderCfg">The coder configuration.</param>
 public A2SCoderDownDirArrows(A2SCoderDownDirArrowsSettings coderCfg)
     : base(coderCfg.NumOfTimePoints, coderCfg.NumOfReceptors)
 {
     _coderCfg   = (A2SCoderDownDirArrowsSettings)coderCfg.DeepClone();
     _histValues = new SimpleQueue <double>(_coderCfg.NumOfReceptors);
     ResetHistValues();
     return;
 }
Ejemplo n.º 26
0
        static bool TestCase_Enqueue()      //Judth Marcel
        {
            SimpleQueue Queue1        = new SimpleQueue(1);
            int         NumbertoQueue = 1;

            Queue1.Enqueue(NumbertoQueue);

            return(Queue1.GetElement() == NumbertoQueue);
        }
Ejemplo n.º 27
0
        public void TestCheckFrontItem()
        {
            List <char> chars = new List <char> {
                'a', 'b', 'c'
            };

            SimpleQueue <char> charQueue = new SimpleQueue <char>(chars);

            Assert.AreEqual(chars[0], charQueue.Front());
        }
Ejemplo n.º 28
0
        static bool TestCase_IsEmpty()  //Drabosenig Andreas
        {
            bool        result = false;
            SimpleQueue q1     = new SimpleQueue(3);

            if (q1.IsEmpty() == true)
            {
                result = true;
            }
            return(result);
        }
Ejemplo n.º 29
0
 //Constructor
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="availableFieldNames">The collection of names of all available input fields.</param>
 /// <param name="cfg">The configuration.</param>
 public MWStatTransformer(List <string> availableFieldNames, MWStatTransformerSettings cfg)
 {
     _cfg      = (MWStatTransformerSettings)cfg.DeepClone();
     _fieldIdx = availableFieldNames.IndexOf(_cfg.InputFieldName);
     if (_fieldIdx == -1)
     {
         throw new InvalidOperationException($"Input field name {_cfg.InputFieldName} not found among given available fields.");
     }
     _lastValues = new SimpleQueue <double>(_cfg.WindowSize);
     return;
 }
Ejemplo n.º 30
0
 /// <inheritdoc/>
 public double Compute(BasicStat continuousActivationStat,
                       BasicStat continuousActivationDiffStat,
                       MovingDataWindow activationMDW,
                       SimpleQueue <byte> firingMDW,
                       double activation,
                       double normalizedActivation,
                       bool spike
                       )
 {
     return(activation);
 }
Ejemplo n.º 31
0
 //Constructor
 /// <summary>
 /// Creates initialized instance
 /// </summary>
 /// <param name="sourceNeuron">Source neuron</param>
 /// <param name="targetNeuron">Target neuron</param>
 /// <param name="weight">Synapse weight</param>
 public StaticSynapse(INeuron sourceNeuron,
                      INeuron targetNeuron,
                      double weight
                      )
     : base(sourceNeuron, targetNeuron, weight)
 {
     _signalQueue = null;
     //Initialize efficacy stat to constant 1 (static synapse has always efficacy 1)
     EfficacyStat.AddSampleValue(1d);
     return;
 }
Ejemplo n.º 32
0
        public void ConstructorWithItems()
        {
            IEnumerable <string> strings = new List <string> {
                "Hello", "World", "With", "Data", "Structures"
            };

            SimpleQueue <string> stringQueue = new SimpleQueue <string>(strings);

            Assert.IsInstanceOfType(stringQueue, typeof(SimpleQueue <string>));
            Assert.AreEqual(strings.Count(), stringQueue.Count);
        }
        public ResolvedEventDispatcher(
            IEventStoreConnection eventStore,
            ISerializer serializer,
            ICheckpointRepository checkpoints,
            Func<ISerializer, ResolvedEvent, bool, CancellationToken, Task> dispatchResolvedEvent,
            Action onCaughtUp = null,
            string streamId = null,
            UserCredentials userCredentials = null)
        {
            _isStarted = new InterlockedBoolean();
            _isDisposed = new InterlockedBoolean();

            _eventStore = eventStore;
            _serializer = serializer;
            _checkpoints = checkpoints;
            _dispatchResolvedEvent = dispatchResolvedEvent;
            _onCaughtUp = onCaughtUp ?? (() => { });
            _streamId = streamId;
            _userCredentials = userCredentials;
            _projectedEvents = new Subject<ResolvedEvent>();

            _queue = new SimpleQueue(async (resolvedEvent, token) =>
            {
                try
                {
                    await _dispatchResolvedEvent(_serializer, resolvedEvent, _subscription.IsSubscribedToAll, _disposed.Token);
                }
                catch(Exception ex)
                {
                    _projectedEvents.OnError(ex);
                    throw;
                }

                if(_isDisposed.Value)
                {
                    return;
                }

                _projectedEvents.OnNext(resolvedEvent);

            }, _disposed.Token);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FunnelVectorField"/> class.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="path">The path.</param>
        /// <param name="options">The options.</param>
        public FunnelVectorField(TransientGroup<IUnitFacade> group, Path path, VectorFieldOptions options)
        {
            Ensure.ArgumentNotNull(group, "group");
            this.group = group;

            _currentPath = path;

            var modelUnit = group.modelUnit;
            _unitProperties = modelUnit;
            var pathOptions = modelUnit.pathFinderOptions;

            // cache options locally
            _funnelWidth = options.funnelWidth;
            _obstacleStrengthFactor = options.obstacleStrengthFactor;
            _allowCornerCutting = pathOptions.allowCornerCutting;
            _allowDiagonals = !pathOptions.preventDiagonalMoves;
            _announceAllNodes = modelUnit.pathNavigationOptions.announceAllNodes;

            _builtInContainment = options.builtInContainment;
            _updateInterval = options.updateInterval;

            // pre-allocate lists memory
            _openSet = new SimpleQueue<Cell>(31);
            _tempWalkableNeighbours = new DynamicArray<Cell>(8);
            _extraTempWalkableNeighbours = new DynamicArray<Cell>(8);

            _grid = GridManager.instance.GetGrid(group.modelUnit.position);
            if (_grid != null)
            {
                // we allocate half of the grid's size in order to have a bit more allocated memory than we expect to actually use
                int size = Mathf.CeilToInt((_grid.sizeX * _grid.sizeZ) / 2f);

                float minF = 9.99999944E-11f;
                _cellDirsSet = new Dictionary<Vector3, VectorFieldCell>(size, new Vector3EqualityComparer(minF));
                _fastMarchedCellsSet = new Dictionary<Vector3, PlaneVector>(size, new Vector3EqualityComparer(minF));
            }

            _funnelWidthSqr = _funnelWidth * _funnelWidth;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Called on Awake
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            this.WarnIfMultipleInstances();

            _transform = this.transform;

            _wayPoints = new SimpleQueue<Vector3>();
            _pathboundWayPoints = new SimpleQueue<Vector3>();
            _navMessage = new UnitNavigationEventMessage(this.gameObject);

            _resultProcessors = this.GetComponents<SteerForPathResultProcessorComponent>();
            Array.Sort(_resultProcessors, (a, b) => a.processingOrder.CompareTo(b.processingOrder));

            _unit = this.GetUnitFacade();
            _pathSettings = _unit.pathNavigationOptions;

            if (this.arrivalDistance > _pathSettings.nextNodeDistance)
            {
                Debug.LogError("The Arrival Distance must be equal to or less that the Next Node Distance.");
            }

            _stopped = true;
            _unit.hasArrivedAtDestination = true;
        }
        private void Initialize()
        {
            _wayPoints = new SimpleQueue<Vector3>();
            _groupCog = GetGroupCenterOfGravity();

            _unitSortComparer = new DistanceComparer<IUnitFacade>(false);

            _stopped = true;
            var updateInterval = GameServices.navigationSettings.groupUpdateInterval;

            NavLoadBalancer.steering.Add(this, updateInterval, true);
        }
Ejemplo n.º 37
0
 internal Marshaller(int maxMillisecondsPerFrame)
 {
     _maxMillisecondsPerFrame = maxMillisecondsPerFrame;
     _queue = new SimpleQueue<Action>(10);
     _watch = new Stopwatch();
 }