static void InitialiseFoodTrucks()
 {
     for (int i = 0; i < numberOfFoodtrucks; i++)
     {
         FoodTruck truck = new FoodTruck(i, 0.3);
         layout.Add(i, truck);
     }
     InitialiseLayout();
 }
 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 void WriteArrays(FoodTruck truck)
        {
            int simulationOffset = Program.currentsimulation * 485;

            oSheet.Cells[1 + simulationOffset, 1 + trucksWritten * outputWidth] = String.Format("Truck At Position {0}", truck.location);
            oSheet.Cells[2 + simulationOffset, 1 + trucksWritten * outputWidth] = "Current Time Frame";
            oSheet.Cells[2 + simulationOffset, 2 + trucksWritten * outputWidth] = "Queue Size";
            //oSheet.Cells[2 + simulationOffset, 3 + trucksWritten * outputWidth] = "Current Appeal";
            //  oSheet.Cells[2 + simulationOffset, 4 + trucksWritten * outputWidth] = "Visitors that got in line";
            // oSheet.Cells[2 + simulationOffset, 5 + trucksWritten * outputWidth] = "Visitors that didn't get in line";
            //The timeframes
            for (int i = 0; i < Program.maxTimeFrame; i++)
            {
                oSheet.Cells[3 + i + simulationOffset, 1 + trucksWritten * outputWidth] = i;
            }
            WriteArray(truck.queueArray, null, 2, simulationOffset);
            //WriteArray(null, truck.actualAppeal, 3, simulationOffset);
            //WriteArray (truck.gotInLine, null, 4, simulationOffset);
            // WriteArray(truck.didntGetInLine, null, 5, simulationOffset);
            trucksWritten++;
            if (trucksWritten == Program.numberOfFoodtrucks && Program.currentsimulation == Program.amountOfSimulations - 1)
            {
                trucksWritten = 0;
                for (int i = 0; i < Program.numberOfFoodtrucks; i++)
                {
                    int simOffSet = simulationOffset + 485;
                    oSheet.Cells[1 + simOffSet, 1 + trucksWritten * outputWidth] = String.Format("Average for Truck At Position {0}", trucksWritten);
                    oSheet.Cells[2 + simOffSet, 1 + trucksWritten * outputWidth] = "Current Time Frame";
                    oSheet.Cells[2 + simOffSet, 2 + trucksWritten * outputWidth] = "Queue Size";
                    oSheet.Cells[2 + simOffSet, 3 + trucksWritten * outputWidth] = "Current Appeal";
                    //The timeframes
                    for (int j = 0; j < Program.maxTimeFrame; j++)
                    {
                        oSheet.Cells[3 + j + simOffSet, 1 + trucksWritten * outputWidth] = j;
                    }
                    double[] averageQueues = getAverages(2);
                    //double[] averageAppeal = getAverages(3);
                    WriteArray(null, averageQueues, 2, simOffSet);
                    // WriteArray(null, averageAppeal, 3, simOffSet);
                    trucksWritten++;
                }
            }
        }
 public void GetInLine(FoodTruck truck)
 {
     truck.queue.Enqueue(this);
     waiting = true;
     locationsVisited[location] = true;
 }
        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)
            {
            }
        }