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

        /// <summary>
        /// Builds a discrete element from a string reference list and an array of strings corresponding to
        /// the states/worlds to include.
        /// </summary>
        /// <param name="refList">The reference list.</param>
        /// <param name="worlds">The states/worlds of the frame of discernment to include.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown is the reference list is too short to
        /// create a valid element</exception>
        /// <exception cref="IncompatibleReferenceListException">Thrown if one of the given states/worlds
        /// could not be found in the reference list.</exception>
        public DiscreteElement(StringReferenceList refList, params string[] worlds)
        {
            //Checking arguments:
            if (refList.Count <= 1)
            {
                throw new ArgumentOutOfRangeException("refList.Length. The size of an DiscreteElement cannot be null, negative or too small!");
            }
            foreach (string world in worlds)
            {
                if (!refList.Contains(world))
                {
                    throw new IncompatibleReferenceListException(String.Format("The given ReferenceList does not contain the world \"{0}\"!", world));
                }
            }

            //Constructing:
            _size    = refList.Count;
            _card    = worlds.Length;
            _numbers = new uint[_size / NB_BITS_UINT + 1];
            foreach (string w in worlds)
            {
                int index = refList.IndexOf(w);
                _numbers[index / NB_BITS_UINT] += 1U << (index % NB_BITS_UINT);
            }
        }
예제 #2
0
        //------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------

        #region Methods

        /*
         * Methods
         */

        /// <summary>
        /// Tests the equality of the given list with the current one.
        /// </summary>
        /// <param name="list">The list to compare to.</param>
        /// <returns>Returns true if both list are equal, false otherwise.</returns>
        public bool Equals(StringReferenceList list)
        {
            return(base.Equals(list));
        }
예제 #3
0
        //------------------------------------------------------------------------------------------------

        /// <summary>
        /// Gives a string representation of the mass function using the given reference list.
        /// </summary>
        /// <param name="refList">The reference list to gives sense to the elements.</param>
        /// <returns>Returns a string representation of the mass function.</returns>
        /// <exception cref="IncompatibleReferenceListException">Thrown if the given reference
        /// list surely does not correspond to this discrete mass function.</exception>
        public string ToString(StringReferenceList refList)
        {
            return(ToString <string>(refList));
        }
        //------------------------------------------------------------------------------------------------

        /// <summary>
        /// Gets a string representation of the current discrete element given a reference list in an easy to parse
        /// form where elements are simply separated by a space.
        /// </summary>
        /// <param name="refList">The reference list to give sense to the states/worlds.</param>
        /// <returns>Returns a string representation of the current discrete element.</returns>
        /// <exception cref="IncompatibleReferenceListException">Thrown if the given reference list
        /// could not correspond to frame of discernment on which the discrete element has been defined.</exception>
        public string ToConvenientString(StringReferenceList refList)
        {
            return(ToConvenientString <string>(refList));
        }