Project 2024-25:
Simulation of a "predator-prey" model
Prey detection by vibration


Disclaimer: the automatically generated English translation is provided only for convenience and it may contain wording flaws. The original French document must be taken as reference!


Through this project, you will learn to create a complete program that is larger in scope than those you have worked with until now. Your program will also include a graphical component. From a computer science perspective, this project aims to strengthen your programming knowledge and help you practice the essential concepts of object-oriented programming: abstraction and encapsulation, inheritance, virtual methods, and polymorphism.

It is not recommended to print the entire project statement: additional information may be added along the way.

Introduction | Steps | References

Introduction

Every program must be designed before being implemented. This design phase aims to establish a computer modeling of the program's components and involves asking a number of questions:To answer these questions, it is obviously important to have a fairly precise idea of what you want to achieve. If you haven't already done so, please read the project description which will shed light on the matter.

The explanation below aims to outline in very broad terms the design we will propose for you to adhere to for this project.

First steps towards program design

When the program is launched, a window should open and display the macroscopic view of the simulation (the population-scale simulation). It will be possible using keyboard keys to view this environment at various scales or different locations:

The simulated environment is populated with scorpions and lizards. It contains cactus clusters that serve as a food source for the latter.

item ← Population-scale simulation




Here zoomed in on a part of the world
item

We can suspect that each of these elements on the screen will need to have a C++ equivalent in your code.

By using control keys, you will be able to switch to "individual scale simulation" mode. At this scale, you can more closely observe the mechanisms of predation in the scorpion. The window will then display only one scorpion, and you can create a lizard to observe how the scorpion approaches it.

Before reaching this stage, we will use a relatively abstract visualization of the scorpion, where it will be possible to observe its sensors, neurons and the waves it perceives.

item

When designing the program, you must not only identify the elements to be modeled, but also ask yourself a number of questions such as:

We outline for you below the fundamental elements that will be involved in the program to be implemented.

Basic Objects

Given the preceding description, the following classes seem to immediately impose their presence:

More specifically, it will quickly become apparent that there are elements common to all animals, such as the fact that they have a position in the world, a movement speed, a gender, etc. There will also be (more or less) obvious differences such as how they feed.

We can therefore imagine a base class Animal to specify the characteristics and methods common to all inhabitants of the world. We will then need to specialize this base class (inheritance concept), to characterize attributes and methods specific to lizards and scorpions etc.

To summarize, we can thus anticipate the different elements involved in the simulation and gradually propose a possible design for the program. As you progress through the project, you will find detailed diagrams explaining the program architecture that we suggest you adhere to. It is essential to understand it in order to implement it correctly. It is obvious that other solutions, whether simpler, more complex, or simply different, exist. Each (simple or complex) generally has its advantages and disadvantages. However, the modeling we propose is reasonable, and following it will save you time.

You can certainly deviate from the proposed design if you feel more comfortable with a different approach. However, you must ensure that the proposed tests remain operational and document/justify your personal design choices in an additional file that you will call CONCEPTION.
Simulation Core and Graphical Displays
To perform the simulation, we will evolve the components of the program over time (the fauna, flora etc.).

Time is sampled (we will talk about discrete time steps). At each time step, each animal, for example, may undergo or initiate a certain number of events depending on the context (feeding, avoiding an obstacle, etc.). These actions determine the evolution of the system over time. Of course, the components will need to be re-displayed after each event to effectively visualize the evolution of the system.

The system elements will therefore generally have:

A good design will ensure that these different facets of the program are independent: for example, the behavioral aspects should be able to be simulated independently of the graphical display (so that, for instance, the graphical interface can be changed without having to change the rest of the program).

The project statement guidelines will help you achieve a design that moves in this direction.

The simulation core, which will evolve the world over time and take into account potential user interventions, will be provided. This core will allow:

This is a provided Application class that will be responsible for this mission (it will come in many variants through inheritance, allowing you to test different aspects of your program). The operating principle of the simulation core will be explained to you in due time. It uses the functionalities of the SFML library that you have already had the opportunity to practice a bit during lab sessions.

Graphic library

There is no standard library in C++ for defining graphical interfaces. Each of the existing libraries therefore has its own specificities (features, prototypes, etc).

Among the possibilities:

It is this last option that we have chosen for its ease of use. It will provide you with the necessary features for graphics and event management in your program.

The support from the teaching team is only guaranteed for the suggested environment. If you work in your own environments, it is imperative that your programs also run on the EPFL VMs.

Registration

If you haven't registered yet, please before Monday March 17 at 9 a.m!


Steps

Create a project subdirectory in the ~/myfiles/cpp. All files relating to this project must be in the directory ~/myfiles/cpp/project.

A schedule of the various stages is given in the description description. In addition, below you'll find tips on which classes to implement and how. We recommend recommended to follow these guidelines, but you can of course add or modify any elements you wish to customize your program.

The project is designed to be made by two. So share the work the work as soon as you start to feel comfortable with the subject.
Parallel and complementary is certainly an instructive instructive experience, but obviously requires good communication communication between you to be effective.

Throughout the development process, you can check your program using small test programs. There are two ways of debugging your program possibilities (which are often used in conjunction with each other):

  1. use cost (or, much better, cerr) to identify where the program "crashes", as well as the the value of attributes at that point
  2. use "debuggeris indispensable for certain types of error.

Important: The statement provided is quite but will not necessarily not necessarily all indications. You should therefore supplement what you are given with a little personal investigation. The assistants - in particular your coach - are there to help are there to help you. It is also possible that additional may be provided along the way if necessary.

The necessary archives are supplied as and when required as they become necessary.

Don't forget comment your code and code cleanly. A part of the final score. What's more, it will make it easier when you have to re-read your code after several weeks.


Step 1: Utility class (warm-up)

Purpose: Implement a base class for modeling abstract entities that can be positioned and moved in a toric world.

Concepts concepts: classes, encapsulation, constructors, destructors and operator overloading

These concepts are explained in course 16, 17 & 18.

Expected duration of coding : 1 week of supervised practical work (from Tuesday of week 5 included, to Tuesday of week 6 not included, according to the numbering of the course outline)

Click here to to access the statement for this part.


Step 2: Random walk

Aim: Implement abstract animals able to move randomly in their environment and move towards targets.

Concepts necessary: classes classes, constructors/destructors, operator overloading and inheritance

These concepts are explained in courses 16, 17, 18 & 19.

Expected duration of coding2 weeks of practical work (from Tuesday of week 6 inclusive to Tuesday of week 8 exclusive, according to the numbering of the course outline) course outline)

Click here to to access the statement for this part.


Stage 3: Life cycles

Purpose: Simulate the complete life cycle of lizards and scorpions (food consumption, reproduction, predation, escape and death).

At the end of this stage, all the functionalities required to simulate population dynamics will be implemented.

Concepts necessary: classes classes, constructors/destructors, inheritance and polymorphism.

These concepts are explained in courses 16, 17, 18, 19 & 20.

Expected duration of coding2 weeks of supervised practical work (from Tuesday of week 8 inclusive, to Tuesday of week 10 exclusive, according to the numbering of the course outline)

Click here to to access the statement for this part.


Step 4: Neural model of the scorpion

Goals: Simulate predation mechanisms at the scorpion level (neural model).

Concepts concepts: classes, constructors/destructors, inheritance and polymorphism

These concepts are explained in courses 16, 17, 18, 19, 20 & 21.

Expected duration of coding2 weeks of supervised practical work (from Tuesday of week 10 inclusive to Tuesday of week 12 exclusive, according to the numbering of the course outline) course outline.

Click here to to access the statement for this part.


Step 5: Statistics

Goals: Complete the system to display simulation statistics.

Concepts necessary: classes, constructors/destructors, inheritance and polymorphism

These concepts are explained in courses 16, 17, 18, 19, 20 & 21.

Expected coding time1 week of supervised practical work (from Tuesday of week 12 inclusive to Tuesday of week 13 exclusive, according to the numbering of the course outline) course outline.

Click here to to access the statement for this part.


Step 6: Free extensions

Goals: Code freely chosen extensions.

Concepts concepts: classes, constructors/destructors, inheritance and polymorphism

These concepts are explained in courses 16, 17, 18, 19, 20 & 21.

Expected coding time1 week of supervised practical work (from Tuesday of week 11 inclusive to Tuesday of week 13 exclusive, according to the numbering of the course outline) course outline.

Click here to to access the statement for this part.


A few references

You you'll also find references on the C++ language here.