This commit is contained in:
shinya 2025-03-02 10:13:15 +01:00
parent 96f33bc328
commit 301378d46e

View File

@ -9,8 +9,15 @@ namespace MonteCarlo_Bank
{
static void Main()
{
BankSim bankSim = new BankSim(250, 15, 15, 5, MaxNumOfCounters: 5);
BankSim bankSim2 = new BankSim(250, 15, 15, 5);
/*
* uint CustomersPerDay - 300 customers per day,
* uint MaxWaitTime - 15 min. maximal waiting time,
* uint MaxServiceTime - 15 min. maximal service time,
* uint MinServiceTime - 5 min. minimal service time
* uint MaxNumOfCounters is optional - Maximal number of opened counters
* uint float[11] TimeCoef is optional - Coefficients for number of customers for each hour
*/
_ = new BankSim(250, 15, 15, 5);
}
}
@ -20,36 +27,38 @@ namespace MonteCarlo_Bank
public uint MaxWaitTime;
public uint MaxServiceTime;
public uint MinServiceTime;
public uint MaxNumOfCounters;
private float[] NumOfCustomersCoef = new float[] { 0.04f, 0.1f, 0.15f, 0.08f, 0.1f, 0.6f, 0.09f, 0.14f, 0.1f, 0.12f, 0.02f };
private uint NumOfCustomers;
private static Random random = new Random();
private Dictionary<uint, KeyValuePair<uint, double>> result = new Dictionary<uint, KeyValuePair<uint, double>>();
private List<KeyValuePair<uint, uint>> Customers = new List<KeyValuePair<uint, uint>>();
public BankSim(uint CustomersPerDay, uint MaxWaitTime, uint MaxServiceTime, uint MinServiceTime, uint? MaxNumOfCounters = null, float[]? TimeCoef = null) // Time is in minutes
public BankSim(uint CustomersPerDay, uint MaxWaitTime, uint MaxServiceTime, uint MinServiceTime, uint? MaxNumOfCounters = 250, float[]? TimeCoef = null) // Time is in minutes
{
// Set the parameters for the simulation
this.CustomersPerDay = CustomersPerDay;
this.MaxWaitTime = MaxWaitTime;
this.MaxServiceTime = MaxServiceTime;
this.MinServiceTime = MinServiceTime;
this.MaxNumOfCounters = MaxNumOfCounters ?? 250;
if (MaxNumOfCounters == null)
{
this.MaxNumOfCounters = CustomersPerDay;
}
if (TimeCoef != null && TimeCoef.Length == 11) //! Remove check for 11 elements in array
{
NumOfCustomersCoef = TimeCoef;
}
Console.WriteLine("Running simulation with this parameters:");
Console.WriteLine($"Total Number Of Customers: {this.CustomersPerDay}");
Console.WriteLine($"Maximal Customer Waiting Time To Tolerate: {this.MaxWaitTime} min.");
Console.WriteLine($"Maximal Service Time Of One Customer: {this.MaxServiceTime} min.");
Console.WriteLine($"Minimal Service Time Of One Customer: {this.MinServiceTime} min.");
Console.WriteLine($"Maximal Number Of Opened Counters: {this.MaxNumOfCounters} min.");
Console.WriteLine();
// Generate the number of customers for each hour and run simulation for each hour
uint day_hour = 1;
foreach (var DayTimeCoef in NumOfCustomersCoef)
@ -70,22 +79,26 @@ namespace MonteCarlo_Bank
// Select number of counter with the satisfied coefficient
int best_counter = satisfied_coefficient.IndexOf(satisfied_coefficient.Max()) + 1;
Console.WriteLine($"Best number of counters: {best_counter}");
Console.WriteLine($"Best number of counters: {best_counter}, satisfied customers {satisfied_coefficient.Max() * 100}%");
result[day_hour] = new KeyValuePair<uint, double>((uint)best_counter, satisfied_coefficient.Max());
Customers.Clear();
Console.WriteLine();
day_hour++;
}
Console.WriteLine("Simulation finished.");
Console.WriteLine();
}
public uint CalcNumOfCustomersPerHour(float DayTime)
private uint CalcNumOfCustomersPerHour(float DayTime)
{
// Calculate the number of customers for each hour of the day
NumOfCustomers = (uint)(CustomersPerDay * DayTime);
return NumOfCustomers;
}
public List<KeyValuePair<uint, uint>> GenCustTimesOfArrivalAndService()
private List<KeyValuePair<uint, uint>> GenCustTimesOfArrivalAndService()
{
// Generate random times of arrival for each customer (from one to 60 minutes)
for (uint i = 0; i < NumOfCustomers; ++i)
@ -98,7 +111,7 @@ namespace MonteCarlo_Bank
return Customers;
}
public List<uint> RunSimulationHour(int counters)
private List<uint> RunSimulationHour(int counters)
{
Customers.Sort((x, y) => x.Key.CompareTo(y.Key));
@ -161,7 +174,5 @@ namespace MonteCarlo_Bank
// Return the percentage of satisfied customers as a value between 0 and 1
return (double)satisfied / waiting_times.Count();
}
}
}