[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 Raw Permalink Blame History

 \documentclass[a4paper,12pt]{report} \usepackage[top=2.0cm, bottom=1.5cm, left=2.0cm, right=2.0cm]{geometry} \usepackage[utf8]{inputenc} \usepackage[francais]{babel} \usepackage[final]{pdfpages} \usepackage{array,multirow,makecell} \usepackage{eurosym} \usepackage{float} \usepackage[pdfborder={0 0 0}]{hyperref} \setcellgapes{1pt} \makegapedcells \newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}} \newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}} \newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}} \hypersetup{ % parametrage des hyperliens colorlinks=true, % colorise les liens breaklinks=true, % permet les retours à la ligne pour urlcolor= blue, % couleur des hyperliens linkcolor= black, % couleur des liens internes citecolor= green % couleur des liens vers } \title{\textbf{VI51 Project Report}\\ Eurockéennes} \author{Florent Jacquet (GI04 - Libre)\\ Simon Magnin-Feysot (GI05 - LEIM)} \date{} \begin{document} \maketitle \tableofcontents \chapter{Introduction} The goal of this project was to simulate the famous rock music festival of Belfort : "Les eurockéennes". In order to achieve this we have used the agent concept seen during the semester. We have used the SARL language, because this is the language used during the whole semester, and it aims to create multi-agents programs. \begin{figure}[h] \centering\includegraphics[scale=0.6]{pic/beginning.png} \caption{The festival when every agents arrive in the festival} \label{begin}\ \end{figure} \chapter{Agent} We have only one kind of agent named "Guy". Guy agents mainly want to listen music. The willing of the agent is coded with a state machine, which can have four states : \begin{itemize} \item{NEED\_MUSIC} \item{NEED\_PEE} \item{NEED\_DRINK} \item{NOTHING} \end{itemize} This is the four main states for a normal human being during a music festival : listen music in front of the scene, get a drink, pee, or just wander anywhere. \section{State Machine} In reality there is two machines states: \begin{itemize} \item{One for the need of the agent} \item{One for the state move of the agent} \end{itemize} \subsection{Move state} The machine state is located in the \verb-on PerceptionEvent- of the agent. First it looks if the agent is wandering (doing nothing special) or is already moving to a special position or waiting in a queue. \\ If the agent is wandering, it will decide to do something, otherwise its state will be affected by its current action.\\ Finally the move will be applied. \subsection{Need state} The need state is set if the agent is wandering. Each action has its own probability, of course the need of music is the bigger, and its own duration (with an additional random time). \section{Drunkness} If the agent drinks too much, it will get drunk. And this state will influence its move.\\ During the computation of the forces (attraction and repulsion) another random vector will be added depending on the drunkness level of the agent. This vector will influence the kinematic behavior.\\ The drunkness is decreasing slowly at each PerceptionEvent and increasing each time the agent is going at the bar. Drunkness increases the "need to pee" probability of the agent. \section{Queue} On the toilets objects, agents are making queue and don't go there wildly (theoretically). \paragraph{}If the toilets are not free, the first agent will wait just behind. The next who will arrive, will try to go just in front of the toilet but the agent who already began a queue will tell him to go just behind him. Once the second agent is in queue, he will say to the first of the queue that he's actually the last. If anyone else arrive, the first will be able to say to the new one to go at the end of the queue and specify the last agent in queue. \chapter{Environnement} We have used the environment given during labs sessions but we had improve it in order to be usable for our project, for example: objects were crossable and not printed on the GUI. \section{Print object on GUI} \paragraph{}In the file WorldModel.java we have : \begin{verbatim} public Iterable getAllObjects() { Iterable l = CollectionUtil.newIterable( getAgentBodies(), this.northWall, this.southWall, this.eastWall, this.westWall, this.toilets, this.mainStage, this.secondStage, this.bar1, this.bar2); if (this.mouseTarget != null) { return CollectionUtil.newIterable(l, this.mouseTarget); } return l; } \end{verbatim} We added all the objects on the screen and not just agent bodies, and we also added all this static objects to the view frustum of the agent, to simulate a "map" of the festival: everybody knows where the interesting points are. \section{Two frustums} \par To improve the behaviours, we added a second perception frustum. We had so a "view frustum", and a "move frustum", which allowed to loop quickly on a smaller list to handle the moving behaviours. \par It had to be defined at many levels of the simulator stack: in the agent body, then in the perception computation function, the finally build an updated Percept object that could contains both list. At the end, the agents could iterate on one or the other, considering what had to be done (moving or taking decisions). \section{Musical tastes of the agents} There are two kinds of agent body : \begin{itemize} \item{One black, who listen metal music} \item{One pink, who listen rock music} \end{itemize} Following this they will be attract by the scene of the same style (or the green scene, which is neutral and attract all agents).\\ At the beginning of the program all agents appears randomly in one of the four corners of the map, and then decides to do something. \section{Avoid collisions} To avoid collisions, we had to implement a function to get the nearest point between a circle (agent) and a rectangle (bars, scenes, toilets) \begin{verbatim} public Point2f getNearestPointFrom(Point2f p) { Vector2f u = new Vector2f(this.upper.x-this.lower.x, 0, true); Vector2f v = new Vector2f(0, this.upper.y-this.lower.y, true); Point2f c = this.getCenter(); float a = u.dot(new Vector2f(p.getX()-c.getX(), p.getY()-c.getY())); float b = v.dot(new Vector2f(p.getX()-c.getX(), p.getY()-c.getY())); if (a < -this.getWidth()) a = -this.getWidth(); else if (a > this.getWidth()) a = this.getWidth(); if (b < -this.getHeight()) b = -this.getHeight(); else if (b > this.getHeight()) b = this.getHeight(); return new Point2f(a + c.getX(), b + c.getY()); } \end{verbatim} In the influence computation of the agent we add the perception of the objects using the nearestPoint function. \begin{verbatim} if (influence != null) { if (influence instanceof MotionInfluence) { MotionInfluence mi = (MotionInfluence) influence; Vector2f avoid_collision = new Vector2f(); for (Percept o : this.movePerceptions) { if (o.getType() != "GUY" && this.getShape().intersects(o.getShape())) { Vector2f collision; if (o.getShape() instanceof Rectangle2f) { Rectangle2f s = (Rectangle2f) o.getShape(); collision = new Vector2f( s.getNearestPointFrom(this.getPosition()).getX() - this.getPosition().getX(), s.getNearestPointFrom(this.getPosition()).getY() - this.getPosition().getY()); } else { collision = new Vector2f( o.getPosition().getX() - this.getPosition().getX(), o.getPosition().getY() - this.getPosition().getY()); } influenceKinematic(collision, mi.getAngularInfluence()); return; } } avoid_collision.add(mi.getLinearInfluence()); \end{verbatim} \paragraph{} \chapter{Conclusion} \section{Possibles improvements} Agents are attracted by scenes, but a possible improvement is that agent are just attracted by just one side of the rectangle (the front of the scene) and not on the four sides. \paragraph{}The queue implementation doesn't really work, they moove differently but they are not making a real queue. \paragraph{}The number of agents is quite low for a festival (400), maybe there are some improvements to do on alogrithms to allow more agents on the simulation \section{Others} The project was very interssant, this was the occasion to see many things : \begin{itemize} \item{Agent concept} \item{A new language, even if SARL is too close of JAVA to properly speak of a new language} \item{Use Janus platform} \item{Program agents and make them interacts between them} \item{Try to have general behavior} \end{itemize} \end{document}