/// <summary> /// Runs a simulation and prints results on the console. /// </summary> /// <param name="nbrPoints">The number of points for each path to be generated.</param> /// <param name="nbrPaths">The number of paths to be generated.</param> /// <param name="simulationName">The name of the simulation</param> /// <param name="creator">The function used to create the <seealso cref="StockPath"/> from a given index.</param> /// <param name="mode">The <see cref="Program.ExecutionMode"/></param> public static void RunSimulation(int nbrPoints, int nbrPaths, string simulationName, Func<int,StockPath> creator, ExecutionMode mode) { Stopwatch stopWatch = new Stopwatch(); StockPath[] paths = new StockPath[nbrPaths]; IEnumerable<int> indices = Enumerable.Range(0, nbrPaths - 1); Console.WriteLine("Starting " + simulationName + " simulation."); stopWatch.Start(); switch (mode) { case ExecutionMode.CLASSIC: paths = indices.Select(creator).ToArray(); break; case ExecutionMode.PARALLEL: paths = indices.AsParallel().Select(creator).ToArray(); break; default: throw new ArgumentException("Unknown execution mode", "mode"); } stopWatch.Stop(); Console.WriteLine("End of " + simulationName + " simulation."); var lastPrices = paths.Select(x => x.LastPrice); Console.WriteLine("Min price: " + lastPrices.Min().ToString("N2")); Console.WriteLine("Max price: " + lastPrices.Max().ToString("N2")); Console.WriteLine("Computation time: " + stopWatch.Elapsed.TotalSeconds.ToString("N2") + " sec"); }
private void Awake() { sugarline = FindObjectOfType <SugarLineController>(); createRequireBox = FindObjectOfType <HandleMachine_Create>(); destoryRequireBox = FindObjectOfType <HandleMachine_Destory>(); stockpath = FindObjectOfType <StockPath>(); handleOrder = FindObjectOfType <HandleOrder>(); storyScene = FindObjectOfType <StoryScene>(); controller = FindObjectOfType <GameController>(); candyFloss = FindObjectOfType <SpricalCandyFloss>(); numOfBox = LevelManager.amountBox; }
private void Awake() { stockPath = FindObjectOfType <StockPath>(); }