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

        /// <summary>
        /// Adds a mapping vector to the matrix.
        /// </summary>
        /// <param name="vector">The vector to add to the basic matrix.</param>
        /// <exception cref="InvalidBeliefModelException">Thrown if the given vector defines the propagation
        /// for an element already in the matrix.</exception>
        public void AddVector(DiscreteMappingVector vector)
        {
            if (this.Contains(vector))
            {
                throw new InvalidBeliefModelException("An Element to get the belief from appears twice in the model!");
            }
            _vectors.Add(vector);
        }
        //------------------------------------------------------------------------------------------------

        private void ParseDiscreteEvidentialMapping(XmlNode node)
        {
            //Create the ReferenceList:
            XmlNode frame = node.SelectSingleNode("subframe");

            if (frame == null)
            {
                throw new InvalidBeliefModelException("The xml model element \"evidential-mapping\" should contain an element called \"subframe\" to define the frame of discernment!");
            }
            string frameName = frame.Attributes["name"].InnerText;
            StringReferenceList references = new StringReferenceList();

            try
            {
                foreach (XmlNode n in frame.ChildNodes)
                {
                    references.Add(n.InnerText);
                }
            }
            catch (IncompatibleReferenceListException)
            {
                throw new InvalidBeliefModelException("The xml model element file \"evidential-mapping\" has a state defined multiple times in the frame node!");
            }
            DiscreteEvidentialMapping mapping = new DiscreteEvidentialMapping(frameName, references);
            //Load evidential vectors:
            XmlNodeList vectors = node.SelectNodes("mapping-vector");

            if (vectors == null)
            {
                throw new InvalidBeliefModelException("An evidential mapping should contain mapping vectors!");
            }
            foreach (XmlNode n in vectors)
            {
                XmlNode fr = n.SelectSingleNode("from");
                DiscreteMappingVector mp = new DiscreteMappingVector(new DiscreteElement(references, fr.Attributes["element"].InnerText.Split(' ')));
                XmlNodeList           to = n.SelectNodes("to");
                foreach (XmlNode t in to)
                {
                    mp.AddPoint(new DiscreteMappingPoint(new DiscreteElement(_refList, t.Attributes["element"].InnerText.Split(' ')), Convert.ToDouble(t.InnerText)));
                }
                mapping.AddVector(mp);
            }
            _mappings.Add(mapping);
        }
        //------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------

        #region Private load methods

        /*
         * Private methods
         */
        private void LoadDiscreteEvidentialMapping(string path)
        {
            //Load the reference list:
            string refListFileName = path + "/values";

            if (!File.Exists(refListFileName))
            {
                throw new InvalidBeliefModelException(String.Format("The path \"{0}\" should contain a file named \"values\" with the names of the possible worlds (one per line)!", path));
            }
            DiscreteEvidentialMapping mapping = new DiscreteEvidentialMapping(new DirectoryInfo(path).Name, refListFileName);

            //Load files one by one:
            foreach (string filename in Directory.GetFiles(path))
            {
                //Avoid temp files and the "values" file:
                if (filename[filename.Length - 1] == '~' ||
                    new FileInfo(filename).Name == "values")
                {
                    continue;
                }
                using (StreamReader file = new StreamReader(filename))
                {
                    string[] lines = file.ReadToEnd().Split('\n');
                    try
                    {
                        int lineCounter = 0;
                        int nbAtoms     = Convert.ToInt32(lines[0].Split(' ')[0]);
                        if (nbAtoms <= 0)
                        {
                            throw new InvalidBeliefModelException("There must be at least one atom to build an Element!");
                        }
                        lineCounter++;
                        string[] atoms = new string[nbAtoms];
                        for (int i = 0; i < nbAtoms; i++)
                        {
                            atoms[i] = lines[i + lineCounter];
                        }
                        lineCounter += nbAtoms;
                        DiscreteMappingVector vector = new DiscreteMappingVector(new DiscreteElement(mapping.References, atoms));
                        //Add the points:
                        int nbConversions = Convert.ToInt32(lines[lineCounter].Split(' ')[0]);
                        if (nbConversions < 1)
                        {
                            throw new InvalidBeliefModelException("There must be at least one element to convert mass to!");
                        }
                        lineCounter++;
                        for (int i = 0; i < nbConversions; i++)
                        {
                            int nbAtomsTo = Convert.ToInt32(lines[lineCounter].Split(' ')[0]);
                            if (nbAtomsTo <= 0)
                            {
                                throw new InvalidBeliefModelException("There must be at least one atom to build an Element!");
                            }
                            lineCounter++;
                            string[] atomsTo = new string[nbAtomsTo];
                            for (int j = 0; j < nbAtomsTo; j++)
                            {
                                atomsTo[j] = lines[j + lineCounter];
                            }
                            lineCounter += nbAtomsTo;
                            double factor = Convert.ToDouble(lines[lineCounter].Split(' ')[0]);
                            lineCounter++;
                            vector.AddPoint(new DiscreteElement(this.References, atomsTo), factor);
                        }
                        mapping.AddVector(vector);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new InvalidBeliefModelException(String.Format("The model contained in file \"{0}\" is not formatted properly!", filename));
                    }
                    catch (FormatException)
                    {
                        throw new InvalidBeliefModelException(String.Format("The numbers in the file \"{0}\" are not in the proper format or at the wrong place!", filename));
                    }
                }
            }
            _mappings.Add(mapping);
        }
        //------------------------------------------------------------------------------------------------

        /// <summary>
        /// Checks if the given vector is already contained in the basic matrix.
        /// </summary>
        /// <param name="vector">The vector to test.</param>
        /// <returns>Returns true if the given vector is already contained, false otherwise.</returns>
        public bool Contains(DiscreteMappingVector vector)
        {
            return(_vectors.Contains(vector));
        }