//------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------

        /*
         * Methods:
         */

        #region Belief model methods

        /// <summary>
        /// Gets the raw mass function from the given sensor measure. No option is applied here as
        /// it requires data associated to a specific sensor. (Temporisations and variation are thus
        /// applied in <see cref="DiscreteSensorData"/>.
        /// </summary>
        /// <param name="measure">The sensor measure which the belief is inferred from.</param>
        /// <returns>Returns a new mass function given the received sensor measure.</returns>
        public DiscreteMassFunction GetEvidence(double?measure)
        {
            // ----
            //Build the new mass function:
            // ---
            DiscreteMassFunction evidence = new DiscreteMassFunction();

            if (measure != null)
            {
                foreach (DiscreteSensorFocalBelief fb in FocalBeliefs)
                {
                    evidence.AddMass(fb.Element, fb.GetEvidence((double)measure));
                }
            }
            else
            {
                evidence = DiscreteMassFunction.GetVacuousMassFunction(ElementSize);
            }
            // ---- /Building ---
            return(evidence);
        }
        //------------------------------------------------------------------------------------------------

        /// <summary>
        /// Builds a new discrete mass function based on the received measure and the current model. If
        /// measure == null, it means that no measure has been received. The effect of options (temporisation,
        /// variation) are applied here.
        /// </summary>
        /// <param name="measure">The sensor measure received.</param>
        /// <returns>Returns a new discrete mass function based on the current model and the received
        /// measurement (and if options are applied also previous measurements).</returns>
        public DiscreteMassFunction GetEvidence(double?measure)
        {
            // ----
            //If variation applies:
            // ----
            double?newMeasure     = 0;
            int    variationIndex = -1;

            for (int i = 0; i < Options.Count; i++)
            {
                if (Options[i].Flag == DiscreteSensorOption.Option_Flags.OP_VARIATION)
                {
                    variationIndex = i;
                }
            }
            if (variationIndex != -1)
            {
                double sum        = 0;
                int    nbMeasures = 0;
                for (int i = 0; i < Options[i].Param; i++)
                {
                    if (Options[i].Data[i].Measure != null)
                    {
                        sum += measure.Value - Options[i].Data[i].Measure.Value;
                        nbMeasures++;
                    }
                }
                if (nbMeasures != 0)
                {
                    newMeasure = sum / nbMeasures;
                }
                else
                {
                    newMeasure = null;
                }
                Options[variationIndex].AddMeasure(measure);
            }
            else
            {
                newMeasure = measure;
            }
            // ---- /Variations ----

            //Get evidence from the model:
            DiscreteMassFunction evidence = _model.GetEvidence(newMeasure);

            // ----
            //Apply temporization if needed:
            // ----
            int tempo = -1;

            for (int i = 0; i < Options.Count; i++)
            {
                if (Options[i].Flag == DiscreteSensorOption.Option_Flags.OP_TEMPO_FUSION)
                {
                    tempo = i;
                }
            }
            // ----
            //Apply tempo fusion:
            // ----
            if (tempo != -1)
            {
                long newTime = _watch.ElapsedMilliseconds;
                //First measure:
                if (Options[tempo].PreviousTime == -1)
                {
                    Options[tempo].UpdatePreviousTime(newTime);
                    Options[tempo].PreviousMassFunction.Clear();
                    foreach (FocalElement <DiscreteElement> e in evidence)
                    {
                        Options[tempo].PreviousMassFunction.AddMass(e);
                    }
                }
                else
                {
                    //Not first measure:
                    long elapsedTime = newTime - Options[tempo].PreviousTime;
                    if (newMeasure != null)
                    {
                        if (!(elapsedTime >= Options[tempo].Param))
                        {
                            DiscreteMassFunction discounted = Options[tempo].PreviousMassFunction.Discounting((double)elapsedTime / Options[tempo].Param);
                            evidence = discounted.CombinationDuboisPrade(evidence);
                        }
                        Options[tempo].UpdatePreviousTime(newTime);
                        Options[tempo].PreviousMassFunction.Clear();
                        foreach (FocalElement <DiscreteElement> e in evidence)
                        {
                            Options[tempo].PreviousMassFunction.AddMass(e);
                        }
                    }
                    else
                    {
                        if (elapsedTime >= Options[tempo].Param)
                        {
                            evidence = DiscreteMassFunction.GetVacuousMassFunction(_model.ElementSize);
                        }
                        else
                        {
                            evidence = Options[tempo].PreviousMassFunction.Discounting((double)elapsedTime / Options[tempo].Param);
                        }
                    }
                }
                // --- /TempoFusion ----
            }
            else
            {
                for (int i = 0; i < Options.Count; i++)
                {
                    if (Options[i].Flag == DiscreteSensorOption.Option_Flags.OP_TEMPO_SPECIFICITY)
                    {
                        tempo = i;
                    }
                }
                // ----
                //Apply tempo specificity:
                // ----
                if (tempo != -1)
                {
                    long newTime = _watch.ElapsedMilliseconds;
                    //First measure:
                    if (Options[tempo].PreviousTime == -1)
                    {
                        Options[tempo].UpdatePreviousTime(newTime);
                        Options[tempo].PreviousMassFunction.Clear();
                        foreach (FocalElement <DiscreteElement> e in evidence)
                        {
                            Options[tempo].PreviousMassFunction.AddMass(e);
                        }
                    }
                    else
                    {
                        //Not first measure:
                        long elapsedTime = newTime - Options[tempo].PreviousTime;
                        if (newMeasure == null)
                        {
                            if (elapsedTime >= Options[tempo].Param)
                            {
                                evidence = DiscreteMassFunction.GetVacuousMassFunction(_model.ElementSize);
                            }
                            else
                            {
                                evidence = Options[tempo].PreviousMassFunction.Discounting((double)elapsedTime / Options[tempo].Param);
                            }
                        }
                        else
                        {
                            if (elapsedTime >= Options[tempo].Param)
                            {
                                Options[tempo].UpdatePreviousTime(newTime);
                                // ----
                                Options[tempo].PreviousMassFunction.Clear();
                                foreach (FocalElement <DiscreteElement> e in evidence)
                                {
                                    Options[tempo].PreviousMassFunction.AddMass(e);
                                }
                            }
                            else
                            {
                                DiscreteMassFunction discounted = Options[tempo].PreviousMassFunction.Discounting((double)elapsedTime / Options[tempo].Param);
                                if (discounted.Specificity > evidence.Specificity)
                                {
                                    evidence = discounted;
                                }
                                else
                                {
                                    Options[tempo].UpdatePreviousTime(newTime);
                                    // ----
                                    Options[tempo].PreviousMassFunction.Clear();
                                    foreach (FocalElement <DiscreteElement> e in evidence)
                                    {
                                        Options[tempo].PreviousMassFunction.AddMass(e);
                                    }
                                }
                            }
                        }
                    }
                }
                // ---- /TempoSpec ----
            }
            return(evidence);
        }