[Java/SARL] Virtual Life Simulation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
8.6KB

  1. \documentclass[a4paper,12pt]{report}
  2. \usepackage[top=2.0cm, bottom=1.5cm, left=2.0cm, right=2.0cm]{geometry}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[francais]{babel}
  5. \usepackage[final]{pdfpages}
  6. \usepackage{array,multirow,makecell}
  7. \usepackage{eurosym}
  8. \usepackage{float}
  9. \usepackage[pdfborder={0 0 0}]{hyperref}
  10. \setcellgapes{1pt}
  11. \makegapedcells
  12. \newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
  13. \newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
  14. \newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}
  15. \hypersetup{ % parametrage des hyperliens
  16. colorlinks=true, % colorise les liens
  17. breaklinks=true, % permet les retours à la ligne pour
  18. urlcolor= blue, % couleur des hyperliens
  19. linkcolor= black, % couleur des liens internes
  20. citecolor= green % couleur des liens vers
  21. }
  22. \title{\textbf{VI51 Project Report}\\
  23. Eurockéennes}
  24. \author{Florent Jacquet (GI04 - Libre)\\
  25. Simon Magnin-Feysot (GI05 - LEIM)}
  26. \date{}
  27. \begin{document}
  28. \maketitle
  29. \tableofcontents
  30. \chapter{Introduction}
  31. The goal of this project was to simulate the famous rock music festival of
  32. Belfort : "Les eurockéennes". In order to achieve this we have used the agent
  33. concept seen during the semester.
  34. We have used the SARL language, because this is the language used during
  35. the whole semester, and it aims to create multi-agents programs.
  36. \begin{figure}[h]
  37. \centering\includegraphics[scale=0.6]{pic/beginning.png}
  38. \caption{The festival when every agents arrive in the festival}
  39. \label{begin}\
  40. \end{figure}
  41. \chapter{Agent}
  42. We have only one kind of agent named "Guy". Guy agents mainly want to listen
  43. music. The willing of the agent is coded with a state machine, which can have
  44. four states :
  45. \begin{itemize}
  46. \item{NEED\_MUSIC}
  47. \item{NEED\_PEE}
  48. \item{NEED\_DRINK}
  49. \item{NOTHING}
  50. \end{itemize}
  51. This is the four main states for a normal human being during a music festival :
  52. listen music in front of the scene, get a drink, pee, or just wander anywhere.
  53. \section{State Machine}
  54. In reality there is two machines states:
  55. \begin{itemize}
  56. \item{One for the need of the agent}
  57. \item{One for the state move of the agent}
  58. \end{itemize}
  59. \subsection{Move state}
  60. The machine state is located in the \verb-on PerceptionEvent- of the agent.
  61. First it looks if the agent is wandering (doing nothing special) or is already
  62. moving to a special position or waiting in a queue. \\
  63. If the agent is wandering, it will decide to do something, otherwise its
  64. state will be affected by its current action.\\
  65. Finally the move will be applied.
  66. \subsection{Need state}
  67. The need state is set if the agent is wandering. Each action has its own
  68. probability, of course the need of music is the bigger, and its own duration
  69. (with an additional random time).
  70. \section{Drunkness}
  71. If the agent drinks too much, it will get drunk. And this state will influence
  72. its move.\\
  73. During the computation of the forces (attraction and repulsion) another random
  74. vector will be added depending on the drunkness level of the agent. This
  75. vector will influence the kinematic behavior.\\
  76. The drunkness is decreasing slowly at each PerceptionEvent and increasing
  77. each time the agent is going at the bar. Drunkness increases the "need to pee"
  78. probability of the agent.
  79. \section{Queue}
  80. On the toilets objects, agents are making queue and don't go there
  81. wildly (theoretically).
  82. \paragraph{}If the toilets are not free, the first agent will wait just behind.
  83. The next who will arrive, will try to go just in front of the toilet but the
  84. agent who already began a queue will tell him to go just behind him. Once the
  85. second agent is in queue, he will say to the first of the queue that he's
  86. actually the last. If anyone else arrive, the first will be able to say to the
  87. new one to go at the end of the queue and specify the last agent in queue.
  88. \chapter{Environnement}
  89. We have used the environment given during labs sessions but we had improve it in order to
  90. be usable for our project, for example: objects were crossable and not printed on
  91. the GUI.
  92. \section{Print object on GUI}
  93. \paragraph{}In the file WorldModel.java we have :
  94. \begin{verbatim}
  95. public Iterable<? extends SituatedObject> getAllObjects() {
  96. Iterable<? extends SituatedObject> l = CollectionUtil.newIterable(
  97. getAgentBodies(),
  98. this.northWall,
  99. this.southWall,
  100. this.eastWall,
  101. this.westWall,
  102. this.toilets,
  103. this.mainStage,
  104. this.secondStage,
  105. this.bar1,
  106. this.bar2);
  107. if (this.mouseTarget != null) {
  108. return CollectionUtil.newIterable(l, this.mouseTarget);
  109. }
  110. return l;
  111. }
  112. \end{verbatim}
  113. We added all the objects on the screen and not just agent bodies, and we also added all this static objects to the view
  114. frustum of the agent, to simulate a "map" of the festival: everybody knows where the interesting points are.
  115. \section{Two frustums}
  116. \par
  117. To improve the behaviours, we added a second perception frustum. We had so a "view frustum", and a "move frustum", which
  118. allowed to loop quickly on a smaller list to handle the moving behaviours.
  119. \par
  120. It had to be defined at many levels of the simulator stack: in the agent body, then in the perception computation
  121. function, the finally build an updated Percept object that could contains both list. At the end, the agents could
  122. iterate on one or the other, considering what had to be done (moving or taking decisions).
  123. \section{Musical tastes of the agents}
  124. There are two kinds of agent body :
  125. \begin{itemize}
  126. \item{One black, who listen metal music}
  127. \item{One pink, who listen rock music}
  128. \end{itemize}
  129. Following this they will be attract by the scene of the same style (or the green
  130. scene, which is neutral and attract all agents).\\
  131. At the beginning of the program all agents appears randomly in one of the four
  132. corners of the map, and then decides to do something.
  133. \section{Avoid collisions}
  134. To avoid collisions, we had to implement a function to get the nearest point
  135. between a circle (agent) and a rectangle (bars, scenes, toilets)
  136. \begin{verbatim}
  137. public Point2f getNearestPointFrom(Point2f p) {
  138. Vector2f u = new Vector2f(this.upper.x-this.lower.x, 0, true);
  139. Vector2f v = new Vector2f(0, this.upper.y-this.lower.y, true);
  140. Point2f c = this.getCenter();
  141. float a = u.dot(new Vector2f(p.getX()-c.getX(), p.getY()-c.getY()));
  142. float b = v.dot(new Vector2f(p.getX()-c.getX(), p.getY()-c.getY()));
  143. if (a < -this.getWidth()) a = -this.getWidth();
  144. else if (a > this.getWidth()) a = this.getWidth();
  145. if (b < -this.getHeight()) b = -this.getHeight();
  146. else if (b > this.getHeight()) b = this.getHeight();
  147. return new Point2f(a + c.getX(), b + c.getY());
  148. }
  149. \end{verbatim}
  150. In the influence computation of the agent we add the perception of the objects
  151. using the nearestPoint function.
  152. \begin{verbatim}
  153. if (influence != null) {
  154. if (influence instanceof MotionInfluence) {
  155. MotionInfluence mi = (MotionInfluence) influence;
  156. Vector2f avoid_collision = new Vector2f();
  157. for (Percept o : this.movePerceptions) {
  158. if (o.getType() != "GUY" && this.getShape().intersects(o.getShape())) {
  159. Vector2f collision;
  160. if (o.getShape() instanceof Rectangle2f) {
  161. Rectangle2f s = (Rectangle2f) o.getShape();
  162. collision = new Vector2f(
  163. s.getNearestPointFrom(this.getPosition()).getX() - this.getPosition().getX(),
  164. s.getNearestPointFrom(this.getPosition()).getY() - this.getPosition().getY());
  165. } else {
  166. collision = new Vector2f(
  167. o.getPosition().getX() - this.getPosition().getX(),
  168. o.getPosition().getY() - this.getPosition().getY());
  169. }
  170. influenceKinematic(collision, mi.getAngularInfluence());
  171. return;
  172. }
  173. }
  174. avoid_collision.add(mi.getLinearInfluence());
  175. \end{verbatim}
  176. \paragraph{}
  177. \chapter{Conclusion}
  178. \section{Possibles improvements}
  179. Agents are attracted by scenes, but a possible improvement is that agent are
  180. just attracted by just one side of the rectangle (the front of the scene) and not on
  181. the four sides.
  182. \paragraph{}The queue implementation doesn't really work, they moove differently
  183. but they are not making a real queue.
  184. \paragraph{}The number of agents is quite low for a festival (400), maybe there are
  185. some improvements to do on alogrithms to allow more agents on the simulation
  186. \section{Others}
  187. The project was very interssant, this was the occasion to see many things :
  188. \begin{itemize}
  189. \item{Agent concept}
  190. \item{A new language, even if SARL is too close of JAVA to properly speak of
  191. a new language}
  192. \item{Use Janus platform}
  193. \item{Program agents and make them interacts between them}
  194. \item{Try to have general behavior}
  195. \end{itemize}
  196. \end{document}