Esempio n. 1
0
        /// <summary>
        /// Returns the action / competence / actionpattern with the given name.
        ///
        /// This method looks for the element with the given name and
        /// returns it.  If the element is an action, then it creates a
        /// new L{POSH.strict.Action} object from the agent's behaviour
        /// dictionary. Otherwise it just returns the competence or action
        /// pattern object.
        ///
        /// The method also checks if the the given name is both an action and a
        /// competence / action pattern. In that case a NameError is raised.
        /// </summary>
        /// <param name="agent">The agent that the element belongs to.</param>
        /// <param name="name">The name of the element.</param>
        /// <param name="competences">A competence object dictionary.</param>
        /// <param name="actionPatterns">An action pattern object dictionary.</param>
        /// <returns>The element with the given name either POSH.strict.Action, POSH.strict.Competence
        ///     or POSH.strict.ActionPattern.</returns>
        /// <exception cref="NameException">
        ///     If actions and competences / action pattern have
        ///     the same name.</exception>
        internal CopiableElement getTriggerable(Agent agent, string name, Dictionary <string, Competence> competences,
                                                Dictionary <string, ActionPattern> actionPatterns)
        {
            // creating an action would raise a NameError when looking up the
            // according behaviour in the behaviour dictionary. Hence, if no
            // behaviour provides that action, we need to check competences and
            // action pattern
            POSH.sys.strict.POSHAction element;

            try
            {
                element = new POSH.sys.strict.POSHAction(agent, name);
            }
            catch (NameException)
            {
                if (competences is Dictionary <string, Competence> &&
                    competences.ContainsKey(name))
                {
                    return(competences[name]);
                }
                else if (actionPatterns is Dictionary <string, ActionPattern> &&
                         actionPatterns.ContainsKey(name))
                {
                    return(actionPatterns[name]);
                }
                else
                {
                    throw new NameException(string.Format("No action / competence / action pattern " +
                                                          "with name '{0}' found", name));
                }
            }
            // we get here only if the action was created successfully,
            // check now for clashes with competences / action pattern

            if ((competences is Dictionary <string, Competence> && competences.ContainsKey(name)) ||
                (actionPatterns is Dictionary <string, ActionPattern> && actionPatterns.ContainsKey(name)))
            {
                throw new NameException(string.Format("Name of action '{0}' also held by other " +
                                                      "competence / action pattern", name));
            }

            return(element);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the action / competence / actionpattern with the given name.
        /// 
        /// This method looks for the element with the given name and
        /// returns it.  If the element is an action, then it creates a
        /// new L{POSH.strict.Action} object from the agent's behaviour
        /// dictionary. Otherwise it just returns the competence or action
        /// pattern object.
        /// 
        /// The method also checks if the the given name is both an action and a
        /// competence / action pattern. In that case a NameError is raised.
        /// </summary>
        /// <param name="agent">The agent that the element belongs to.</param>
        /// <param name="name">The name of the element.</param>
        /// <param name="competences">A competence object dictionary.</param>
        /// <param name="actionPatterns">An action pattern object dictionary.</param>
        /// <returns>The element with the given name either POSH.strict.Action, POSH.strict.Competence 
        ///     or POSH.strict.ActionPattern.</returns>
        /// <exception cref="NameException">
        ///     If actions and competences / action pattern have
        ///     the same name.</exception>
        internal CopiableElement getTriggerable(Agent agent, string name, Dictionary<string,Competence> competences, 
            Dictionary<string,ActionPattern> actionPatterns)
        {
            // creating an action would raise a NameError when looking up the
            // according behaviour in the behaviour dictionary. Hence, if no
            // behaviour provides that action, we need to check competences and
            // action pattern
            POSH.sys.strict.POSHAction element;

            try
            {
                element = new POSH.sys.strict.POSHAction(agent,name);
            }
            catch (NameException)
            {
                if (competences is Dictionary<string,Competence> &&
                    competences.ContainsKey(name))
                    return competences[name];
                else if (actionPatterns is Dictionary<string,ActionPattern> &&
                    actionPatterns.ContainsKey(name))
                    return actionPatterns[name];
                else
                    throw new NameException(string.Format("No action / competence / action pattern " +
                      "with name '{0}' found", name));
            }
            // we get here only if the action was created successfully,
            // check now for clashes with competences / action pattern

            if ( (competences is Dictionary<string,Competence> && competences.ContainsKey(name) ) ||
                ( actionPatterns is Dictionary<string,ActionPattern> && actionPatterns.ContainsKey(name)))
                throw new NameException(string.Format("Name of action '{0}' also held by other " +
                "competence / action pattern", name));

            return element;
        }