This project simulates the spread of an epidemic using the SIR (Susceptible-Infected-Recovered) model. It is implemented in Java and provides:
- Real-time simulation based on user input.
- CSV output for analysis.
- Graphical visualization using JFreeChart.
- Real-time simulation: Dynamically calculates S, I, R values using Euler's method.
- CSV output: Saves simulation data to
output/SIR_Simulation.csv. - Graphical visualization: Displays results in a line chart.
- Image export: Option to save the chart as
output/SIR_Simulation.png. - User-friendly: Terminal-based input and output with input validation.
- Download and install JDK 11 or later from Oracle.
- JFreeChart:
- Download
jfreechart-1.5.3.jarandjcommon-1.0.23.jarfrom JFreeChart Official Site.
- Download
- Apache Commons CSV:
- Download
commons-csv-1.9.0.jarfrom Apache Commons CSV.
- Download
- Create a
libfolder in your project directory. - Place the downloaded JAR files in the
libfolder. - Add the JAR files to your project's library dependencies in your IDE.
- Clone the repository or download the project files.
- Open the project in IntelliJ IDEA, Eclipse, or VS Code.
-
Compile the Java file:
javac -cp "lib/*" -d bin src/SIRModel.java -
Run the Code:
java -cp "lib/*;bin" SIRModel
- Enter the following parameters when prompted:
- Initial susceptible population (S).
- Initial infected population (I).
- Initial recovered population (R).
- Infection rate (( \beta )).
- Recovery rate (( \gamma )).
- Time step (( \Delta t )).
- Simulation duration (days).
- A graph will display the simulation results.
- The simulation data will be saved to
output/SIR_Simulation.csv. - You will be prompted to save the chart as a PNG image (
output/SIR_Simulation.png).
- A line chart showing the changes in Susceptible, Infected, and Recovered populations over time.
- Colors:
- Blue: Susceptible population.
- Red: Infected population.
- Green: Recovered population.
- The simulation data is saved in
output/SIR_simulation.csvwith the following columns:Day: The day of the simulation.Susceptible: The number of susceptible individuals.Infected: The number of infected individuals.Recovered: The number of recovered individuals.
SIR_Simulation/
├── src/
│ └── SIRModel.java
├── lib/
│ ├── jfreechart-1.5.3.jar
│ ├── jcommon-1.0.23.jar
│ └── commons-csv-1.9.0.jar
├── output/
│ ├── SIR_Simulation.csv
│ └── SIR_Simulation.png
└── README.md
- Fork the repository.
- Create a new branch (git checkout -b feature/YourFeatureName).
- Commit your changes (git commit -m 'Add some feature').
- Push to the branch (git push origin feature/YourFeatureName).
- Open a pull request.
- Educational Purpose: Learn how mathematical models like SIR can simulate real-world phenomena.
- Practical Application: Understand the impact of infection and recovery rates on disease spread.
- Hands-on Experience: Gain experience in Java programming, numerical methods, and data visualization.
- Add a GUI for better user interaction.
- Extend the model to include vaccination and quarantine effects.
- Implement advanced numerical methods (e.g., Runge-Kutta) for better accuracy.
- Inspired by the work of Kermack and McKendrick (1927) on the SIR model.
- Thanks to the developers of JFreeChart and Apache Commons CSV for their libraries.
For questions or feedback, feel free to reach out:
-
Email: subashdhamee@gmail.com
-
GitHub: mesubash