Esempio n. 1
0
        /// <summary>
        ///     Given a random model and a BeliefLevel
        ///     return the beliefBits for the agent: an array fill of random binaries
        ///     representing the detailed belief of an agent
        /// </summary>
        /// <param name="model"></param>
        /// <param name="beliefLevel"></param>
        /// <returns></returns>
        public float[] InitializeBits(RandomGenerator model, BeliefLevel beliefLevel)
        {
            float[] beliefBits;
            switch (model)
            {
            case RandomGenerator.RandomUniform:
            {
                float min;
                float max;

                if (beliefLevel == BeliefLevel.Random)
                {
                    min = RangeMin;
                    max = RangeMax;
                }
                else
                {
                    min = GetMinFromBeliefLevel(beliefLevel);
                    max = GetMaxFromBeliefLevel(beliefLevel);
                }

                beliefBits = ContinuousUniform.Samples(Length, min, max);
                break;
            }

            case RandomGenerator.RandomBinary:
            {
                if (beliefLevel == BeliefLevel.Random)
                {
                    beliefBits = ContinuousUniform.FilteredSamples(Length, RangeMin, RangeMax);
                }
                else
                {
                    var mean = 1 - GetValueFromBeliefLevel(beliefLevel);
                    beliefBits = ContinuousUniform.FilteredSamples(Length, mean);
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(model), model, null);
            }

            return(beliefBits);
        }
Esempio n. 2
0
        /// <summary>
        ///     Given a KnowledgeModel and a KnowledgeLevel
        ///     return the knowledgeBits for the agent: an array fill of random binaries
        ///     representing the detailed knowledge of an agent
        /// </summary>
        /// <param name="length"></param>
        /// <param name="model"></param>
        /// <param name="knowledgeLevel"></param>
        /// <param name="step"></param>
        /// <returns></returns>
        public void InitializeKnowledge(byte length, RandomGenerator model, KnowledgeLevel knowledgeLevel, ushort step)
        {
            float[] knowledgeBits;
            switch (model)
            {
            case RandomGenerator.RandomUniform:
            {
                float min;
                float max;

                switch (knowledgeLevel)
                {
                case KnowledgeLevel.Random:
                    min = 0;
                    max = 1;
                    break;

                default:
                    min = Knowledge.GetMinFromKnowledgeLevel(knowledgeLevel);
                    max = Knowledge.GetMaxFromKnowledgeLevel(knowledgeLevel);
                    break;
                }

                knowledgeBits = ContinuousUniform.Samples(length, min, max);
                if (Math.Abs(min - max) < Constants.Tolerance)
                {
                    SetKnowledgeBits(knowledgeBits, step);
                    return;
                }

                for (byte i = 0; i < knowledgeBits.Length; i++)
                {
                    if (knowledgeBits[i] < min * (1 + 0.05))
                    {
                        // In randomUniform, there is quasi no bit == 0. But in reality, there are knowledgeBit we ignore.
                        // We force the lowest (Min +5%) knowledgeBit to 0
                        knowledgeBits[i] = 0;
                    }
                }

                break;
            }

            case RandomGenerator.RandomBinary:
            {
                switch (knowledgeLevel)
                {
                case KnowledgeLevel.Random:
                    knowledgeBits = ContinuousUniform.FilteredSamples(length, 0, 1);
                    break;

                default:
                    var mean = 1 - Knowledge.GetValueFromKnowledgeLevel(knowledgeLevel);
                    knowledgeBits = ContinuousUniform.FilteredSamples(length, mean);
                    break;
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(model), model, null);
            }

            SetKnowledgeBits(knowledgeBits, step);
        }