Ejemplo n.º 1
0
 /**
  * Sends a message to the given agents notifying them that the environment has changed
  * (called by the user environment). If no agent is informed, the notification is sent
  * to all agents.
  */
 public void InformAgsEnvironmentChanged(params string[] agents)
 {
     if (agents.Length == 0)
     {
         foreach (CentralisedAgArch ag in masRunner.GetAgs().Values)
         {
             ag.GetReasoner().GetUserAgArch().WakeUpSense();
         }
     }
     else
     {
         foreach (string agName in agents)
         {
             CentralisedAgArch ag = masRunner.GetAg(agName);
             if (ag != null)
             {
                 ag.WakeUpSense();
             }
             else
             {
                 Debug.Log("Error sending message notification: agent " + agName + " does not exist!");
             }
         }
     }
 }
Ejemplo n.º 2
0
    public string CreateAgent(string agName, string agSource, string agClass, List <string> archClasses, Settings stts, Agent father)
    {
        Debug.Log("Creating centralised agent " + agName + " from source " + agSource + " (agClass=" + agClass + ", archClass=" + archClasses + ", settings=" + stts);

        if (stts == null)
        {
            stts = new Settings();
        }

        string prefix = null;

        if (father != null && father.GetASLSrc().StartsWith(SourcePath.CRPrefix))
        {
            prefix = SourcePath.CRPrefix + "/";
        }
        //agSource = masRunner.GetProject().GetSourcePaths().FixPath(agSource, prefix); //el proyect creo que es algo con unity. Sep, esto es unity

        string nb = "";
        int    n  = 1;

        while (masRunner.GetAg(agName + nb) != null)
        {
            nb = "_" + (n++);
        }
        agName = agName + nb;

        CentralisedAgArch agArch = NewAgInstance();

        agArch.SetAgName(agName);
        //agArch.CreateArchs(ap.GetAgArchClasses(), ap.agClass.GetClassName(), ap.getBBClass(), agSource, stts, masRunner); //esto creo que no hace falta porque no tenemos cosas personalizadas
        agArch.SetEnvInfraTier(masRunner.GetEnvironmentInfraTier());
        agArch.SetControlInfraTier(masRunner.GetControllerInfraTier());     //Esto esta comentado en masrunner

        // if debug mode is active, set up new agent to be synchronous and visible for ExecutionControlGUI
        if (masRunner.IsDebug())
        {
            stts.SetVerbose(2);
            stts.SetSync(true);
            //agArch.GetLogger().SetLevel(Level.FINE);
            //agArch.GetTS().GetLogger().SetLevel(Level.FINE);
            //agArch.GetTS().GetAg().GetLogger().SetLevel(Level.FINE);
        }

        masRunner.AddAg(agArch);

        Debug.Log("Agent " + agName + " created!");
        return(agName);
    }
Ejemplo n.º 3
0
        // this is used by the .send internal action in stdlib
        public void SendMsg(Message m)
        {
            if (m.GetSender() == null)
            {
                m.SetSender(GetAgName());
            }
            CentralisedAgArch rec = masRunner.GetAg(m.GetReceiver());

            if (rec == null)
            {
                if (IsRunning())
                {
                    throw new ReceiverNotFoundException("Receiver '" + m.GetReceiver() + "' does not exist! Could not send " + m);
                }
                else
                {
                    return;
                }
            }
            rec.ReceiveMsg(m.Clone()); // send a cloned message

            // notify listeners
            if (msgListeners != null)
            {
                foreach (IMsgListener l in msgListeners)
                {
                    l.MsgSent(m);
                }
            }
        }