//------------------------------------------------------------------------------------------------ /// <summary> /// Builds a discrete element from a reference list and an array of objects 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 static DiscreteElement ConstructDiscreteElement <T>(ReferenceList <T> refList, params T[] 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 (T world in worlds) { if (!refList.Contains(world)) { throw new IncompatibleReferenceListException(String.Format("The given ReferenceList does not contain the world \"{0}\"!", world.ToString())); } } //Constructing: int size = refList.Count; int card = worlds.Length; uint[] numbers = new uint[size / NB_BITS_UINT + 1]; foreach (T w in worlds) { int index = refList.IndexOf(w); numbers[index / NB_BITS_UINT] += 1U << (index % NB_BITS_UINT); } DiscreteElement newlyBuilt = new DiscreteElement(size, numbers); newlyBuilt._card = card; return(newlyBuilt); }
//------------------------------------------------------------------------------------------------ /// <summary> /// Tests equality between the current reference list and the given one. /// </summary> /// <param name="list">The list to compare to.</param> /// <returns>Returns true if both reference lists are equals, false otherwise.</returns> public bool Equals(ReferenceList <T> list) { foreach (T element in list) { if (!this.Contains(element)) { return(false); } } foreach (T element in this) { if (!list.Contains(element)) { return(false); } } return(true); }