A Windows Forms application built in C# to simulate a single-channel, single-server queueing system using the Inverse Transform Technique for random variable generation.
This project is a practical implementation of "Manual Simulation" concepts. It applies mathematical models and builds stochastic simulation frameworks without relying on built-in search or replace functions. This demonstrates a deep understanding of how random engines operate within simulation software.
The project strictly follows the step-by-step simulation methodology outlined in standard academic curricula (such as the single-server queue examples found in simulation textbooks).
-
Advanced Setup Interface (Form2):
- Create probability distribution tables for Interarrival Time and Service Time.
- Input field for the maximum number of time intervals with strict input validation (
int.TryParse). - Automated Random Probability Generation: Generates random numbers and applies a custom Normalization algorithm to ensure the total sum of all probabilities equals exactly 1.0.
- Automatic calculation of Cumulative Probability and the Random Number Assignment (RNA) range using a custom
StringBuilderlogic. - Dynamic, editable DataGridView with smart warnings (if the sum exceeds 1.0, or locks further input if the sum reaches 1.0 early).
-
Simulation and Statistics Interface (Form1):
- Generates separate random numbers for each customer's arrival and service.
- A custom logic function (
LookupValueByRandomNumber) that maps the generated random number to the correct time interval based on the cumulative probability, without using any built-in search functions (likeIndexOf,Find, orReplace). - A detailed results table displaying (Arrival Time, Start of Service, End of Service, Time in Queue, Time in System, and Server Idle Time).
- Performance Metrics: Statistical results (e.g., Average Wait Time, Server Utilization) are displayed dynamically in a dedicated
Label. - Smart Summary Rows: Automatically appends
TotalandAveragerows at the end of the results table with customized background coloring and bold fonts for improved readability.
- Language: C# (.NET 6+)
- UI Framework: Windows Forms (WinForms)
- Data Management:
System.Data.DataTableandSystem.Data.DataRow(Enforcing a clear separation between data logic and UI). - Data Visualization:
DataGridViewwith dynamic data binding. - Data Structures:
System.Collections.Generic.List<T>for storing random numbers before normalization. - Mathematical Logic: LINQ (
Sum,AsEnumerable) andMath.Absfor robust floating-point precision checks.
- Run the Application: The main window (
Form1) will appear. - Open Settings: Click the
Set Up Formbutton to open the configuration window (Form2). - Configure Probabilities (Form2):
- Under the
Time Between Arrivaltab, enter the maximum number of time intervals (e.g., 8) and clickInput. - Fill in the
Probabilitycolumn manually, or clickGenerate Probabilityto get a valid normalized set of random numbers. - Repeat the exact same steps for the
Service Timetab. - Note: You cannot input further values in remaining probability rows if the cumulative sum has already reached 1.0.
- Under the
- Run Simulation (Form1):
- Enter the desired number of customers in the
Number Of Customerstextbox. - Click the
Simulatebutton.
- Enter the desired number of customers in the
- Read the Results:
- A detailed simulation table will appear in the
DataGridView. - Scroll down to see the colored
TotalandAveragesummary rows. - The performance metrics (e.g.,
Server UtilizationandAverage Time in Queue) will be displayed in theLabellocated above the table.
- A detailed simulation table will appear in the
The simulation relies on a custom probability distribution. The following algorithms are implemented entirely from scratch:
- Normalization of Random Numbers:
Sum = Σ RandomNumbers[i]NormalizationFactor = 1.0 / SumFinalProbability = RandomNumbers[i] * NormalizationFactor(Ensures the sum of all probabilities exactly equals 1.0).
- Cumulative Probability Calculation:
Cumulative[i] = Cumulative[i-1] + Probability[i]
- Inverse Transform Technique (Value Mapping):
- Check if the generated random number
RNfalls within the range:Cumulative[i-1] < RN <= Cumulative[i]. - Return the corresponding
Time[i].
- Check if the generated random number
- Clone the repository to your local machine.
git clone https://github.com/ProMoath/Single-Channel-Queue-Simulation.git
- Open the solution file
Simulation.slnusing Microsoft Visual Studio 2022 (or newer). - Ensure
Simulationis set as the Startup Project. - Press
F5or click theRunbutton to launch the application.
Form1.cs/Form1.Designer.cs: Main window, simulation logic, and results table.Form2.cs/Form2.Designer.cs: Setup window for configuring probabilities, cumulative sums, and random generation.Program.cs: The application's main entry point.
This project is licensed under the MIT License. You are free to use, modify, and distribute it for academic or personal purposes.
Contributions are welcome! To get started:
# 1. Fork the repository on GitHub
# 2. Create a feature branch
git checkout -b feature/your-feature-name
# 3. Make your changes and commit
git commit -m "feat: describe your change"
# 4. Push your branch
git push origin feature/your-feature-name
# 5. Open a Pull Request on GitHub| Channel | Details |
|---|---|
| 👨💻 Developer | Moath Alshahari |
| moathalshah2023@gmail.com | |
| 🐙 GitHub | @ProMoath |