/// <summary>
        /// Method for updating secondary motivation Aspect ( != attention/satisfaction/confidence)
        /// </summary>
        ///
        /// <param name="ms"> Motivation state for storing the new values. </param>
        internal void updateSecondaryMotivationAspects(MotivationState ms)
        {
            MotivationModel mm = ms.getMotivationModel();

            foreach (MotivationAspect ma in mm.motivationAspects.motivationAspectList)
            {
                if (!primaryMotivationAspects.Contains(ma.name))
                {
                    if (ms.getMotivation().ContainsKey(ma.name))
                    {
                        try
                        {
                            double sol = FormulaInterpreter.eval(ma.rule);
                            ms.updateMotivationAspect(ma.name, sol);
                        }
                        catch (Exception e)
                        {
                            loggingMAs("Warning: Update for secondary motivation aspects not done.", Severity.Warning);
                            loggingMAs("Exception caught: " + e.Message);
                        }
                    }
                    else
                    {
                        loggingMAs("Warning: Motivation aspect not found!", Severity.Warning);
                    }
                }
            }
        }
        /// <summary>
        /// This method validates the motivation model - the variables in the formulas are checked (Are they all motivation aspects?).
        /// </summary>
        ///
        /// <param name="MotivationModel"> The motivation model to validate. </param>
        ///
        /// <returns> True if no error was found in the formulas, false otherwise. </returns>
        internal Boolean validateMotivationModel(MotivationModel mm)
        {
            List <String> motivationAspects = new List <String>();

            foreach (MotivationAspect ma in mm.motivationAspects.motivationAspectList)
            {
                motivationAspects.Add(ma.name);
            }

            Boolean valid;

            foreach (MotivationAspect ma in mm.motivationAspects.motivationAspectList)
            {
                if (primaryMotivationAspects.Contains(ma.name))
                {
                    valid = ruleValid(ma.down + "+" + ma.up, motivationAspects);
                }
                else
                {
                    valid = ruleValid(ma.rule, motivationAspects);
                }

                if (!valid)
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Method for deserialization of a XML-String to the coressponding MotivationModel.
        /// </summary>
        ///
        /// <param name="str"> String containing the XML-MotivationModel for deserialization. </param>
        ///
        /// <returns>
        /// MotivationModel-type coressponding to the parameter "str" after deserialization.
        /// </returns>
        internal MotivationModel getMMFromXmlString(String str)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MotivationModel));

            using (TextReader reader = new StringReader(str))
            {
                MotivationModel result = (MotivationModel)serializer.Deserialize(reader);
                return(result);
            }
        }
        /// <summary>
        /// Method for loading the motivation model for a certain player.
        /// </summary>
        ///
        /// <param name="playerId"> Identification of player for which the MM is loaded. </param>
        ///
        /// <returns> The motivation model for the specified player. </returns>
        public MotivationModel getMotivationModel()
        {
            if (motivationModel != null)
            {
                return(motivationModel);
            }
            MotivationModel mm = loadDefaultMotivationModel();

            motivationModel = mm;
            return(mm);
        }
        /// <summary>
        /// Method for replacing motivation component variables with the current values.
        /// </summary>
        ///
        /// <param name="expression"> String for which replacement should happen. </param>
        ///
        /// <returns> String without any motivation component variables. </returns>
        private static String replaceVariables(String expression)
        {
            MotivationState ms = MotivationAssessmentAsset.Handler.getMotivationState();
            MotivationModel mm = ms.getMotivationModel();

            foreach (MotivationAspect ma in mm.motivationAspects.motivationAspectList)
            {
                expression = expression.Replace(ma.name, ms.getMotivationAspectValue(ma.name).ToString());
            }
            MotivationAssessmentAsset.Handler.loggingMAs("FormulaInterpreter: expression to evaluate without variables=" + expression);
            return(expression);
        }
        /// <summary>
        /// Method for updating primary motivation Aspect (attention/satisfaction/confidence)
        /// </summary>
        ///
        ///<param name="ms"> Motivation state for storing the new values. </param>
        ///<param name="aspect"> String containing "attention","satisfaction" or "confidence". Describes which component gets updated. </param>
        ///<param name="direction"> Boolean - if true upgrade, else downgrade is done. </param>
        ///<param name="playerId"> Identification of the player. </param>
        internal void updatePrimaryMotivationAspect(MotivationState ms, String aspect, Boolean direction)
        {
            MotivationModel  mm         = ms.getMotivationModel();
            MotivationAspect ma         = mm.motivationAspects.getMotivationAspectByName(aspect);
            String           expression = direction ? ma.up : ma.down;

            try
            {
                double sol = FormulaInterpreter.eval(expression);
                ms.updateMotivationAspect(aspect, sol);
            }
            catch (Exception e)
            {
                loggingMAs("Warning: Update for primary motivation aspects not done.", Severity.Warning);
                loggingMAs("Exception caught: " + e.Message);
            }
        }
        /// <summary>
        /// Motivation state c-tor
        /// </summary>
        ///
        /// <param name="mm"> MotivationModel for which this motivation state is created. </param>
        public MotivationState(MotivationModel mm)
        {
            motivationModel = mm;

            int counter = 0;

            foreach (MotivationAspect ma in mm.motivationAspects.motivationAspectList)
            {
                motivation[ma.name] = 0.5;
                if (MotivationAssessmentAsset.Handler.getPrimaryMotivationAspects().Contains(ma.name))
                {
                    counter++;
                }
            }

            if (counter != MotivationAssessmentAsset.Handler.getPrimaryMotivationAspects().Count)
            {
                MotivationAssessmentAsset.Handler.loggingMAs("Warning: MotivationalModel corrupted - at least one primary motivation aspect is missing!", Severity.Warning);
            }
        }