Debian Codegraph @

src/mas/kernel.h

raw symbols SCIP
1 /***************************************************************************
2 kernel.h - description
3 -------------------
4 begin : nov 29th 2005
5 copyright : (C) 2005 by Duong Khang NGUYEN
6 email : neoneurone @ gmail com
7 author : Victor STINNER
8
9 $Id: kernel.h 375 2008-10-28 14:47:15Z neoneurone $
10 ***************************************************************************/
11
12 /***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * any later version. *
18 * *
19 ***************************************************************************/
20
21
22 #ifndef _OPENCITY_KERNEL_H_
23 #define _OPENCITY_KERNEL_H_ 1
24
25 #include "agent.h"
26
27 #include <map>
28 #include <list>
29
30 // Forward declaration
31 class Message;
32
33
34 /*=====================================================================*/
35 /** This is the kernel of the Multi-Agent System.
36 @author Victor STINNER
37 */
38 class Kernel
39 {
40 public:
41 Kernel();
42 ~Kernel();
43
44 unsigned long getStep() const;
45
46 //========================================================================
47 /** The main method of the kernel. It must be called in order to execute
48 the agents and other things
49 */
50 void live();
51
52 AgentID_t getAgentUniqId();
53
54 //========================================================================
55 /** Return the pointer to the singleton of the kernel.
56 @return The pointer to the only one kernel of the application,
57 otherwise null
58 */
59 static Kernel* getSingleton();
60
61 void registerAgent(Agent* agent);
62 void registerRole(Agent *agent, MAS_ROLE role);
63 void unregisterAgent(Agent* agent);
64 void unregisterRole(Agent *agent, MAS_ROLE role);
65
66 //========================================================================
67 /** First, remove the agent either from the yellow or the white pages.
68 Then, physically destroy it.
69 @param agent The pointer to the agent to destroy
70 */
71 void killAgent(Agent* agent);
72
73 void sendMessage(MAS_ROLE role, const Message& msg);
74 void sendMessageToAgent(AgentID_t agent, const Message& msg);
75
76
77 private:
78 static Kernel* m_singleton; ///< Singleton
79
80 unsigned long m_step;
81 std::map<AgentID_t, Agent*> m_white_pages;
82 typedef std::map<AgentID_t, Agent*>::iterator m_white_pages_it;
83 std::map<MAS_ROLE, std::list<Agent*> > m_yellow_pages;
84 typedef std::map<MAS_ROLE, std::list<Agent*> >::iterator m_yellow_pages_it;
85 typedef std::list<Agent*>::iterator m_agent_set_it;
86 std::list<Agent*> m_agent_dying;
87 typedef std::list<Agent*>::iterator m_agent_dying_it;
88 AgentID_t m_agent_uniq_id;
89
90
91 /*=====================================================================*/
92 /* PRIVATE METHODS */
93 /*=====================================================================*/
94 Agent& getAgentById(AgentID_t agent);
95 };
96
97
98 #endif
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131