public double ChanceQueueing(FoodTruck truck) { if (truck.QueueTime() >= Program.maxQueueTime) { return(0); } if (truck.QueueTime() >= 10) { return(Math.Max(0, (truck.appeal - (0.5 * truck.appeal * (truck.QueueTime() / Program.maxQueueTime))))); } return(truck.appeal); }
public static Random r; //random number generator static void Main(string[] args) { foreach (string s in args) { chanceOfEntering = double.Parse(s); } Initialise(); //TODO: Initialise foodtrucks while (currentsimulation < amountOfSimulations) { ResetSimulation(); while (currentTimeFrame < maxTimeFrame) { for (int i = 0; i < incomingVisitors(); i++) { double rnd = r.NextDouble(); if (rnd <= chanceOfEntering) { visitors.Add(new Visitor(currentTimeFrame)); } } foreach (Visitor v in visitors.ToList()) { //if not waiting if (!v.waiting) { //Chance of leaving (early/without having passed all foodtrucks) if (r.NextDouble() <= v.ChanceOfLeaving()) { visitors.Remove(v); //Leave } if (!v.isEating) { FoodTruck truck = layout[v.location]; //Food truck at th current location if (r.NextDouble() <= v.ChanceQueueing(truck) && !v.locationsVisited[v.location] && truck.QueueTime() < maxTimeFrame - currentTimeFrame) //chance to get in line if u haven't passed this food truck yet { v.GetInLine(truck); //get in line at the food truck truck.gotInLine[currentTimeFrame]++; //got in line because of combination appeal + queuetime } else { if (!v.locationsVisited[v.location]) { truck.didntGetInLine[currentTimeFrame]++; //didnt get in line because of combination appeal + queuetime } v.locationsVisited[v.location] = true; List <int> directDestinations = new List <int>(); // all not visited neighbours List <int> indirectDestinations = new List <int>(); // all neighbours with not visited neighbours foreach (int l in truck.neighbours) //for every neighbour { if (!v.locationsVisited[l]) //if not visited add them to directdestinations { directDestinations.Add(l); } else { foreach (int j in layout[l].neighbours) //if neighbour has neighbours that arent visited, add neighbour to indirect destinations { if (!v.locationsVisited[j]) { indirectDestinations.Add(l); } } } } if (directDestinations.Count == 0) //if all direct neighbours visited, go to a neighbour who has not visited neighbours { if (indirectDestinations.Count == 0) //if no neighbours have not visited neighbours then leave the festival(seen it all(at least for this layout)) { visitors.Remove(v); } else { int rnd = r.Next(0, indirectDestinations.Count); v.location = indirectDestinations[rnd]; //move towards indirectly not visited neighbour } } else { int rnd = r.Next(0, directDestinations.Count); v.location = directDestinations[rnd]; //move to directly not visited neighbour } } } else { v.ProgressEating(); } //eat } } foreach (KeyValuePair <int, FoodTruck> k in layout) { k.Value.ProgressServing(); } currentTimeFrame++; } if (currentsimulation == 0) { writer.OpenWorksheet(); } foreach (KeyValuePair <int, FoodTruck> k in layout) { writer.WriteArrays(k.Value); } currentsimulation++; } writer.SaveSheet(); //while (true) { } }