private void LogArbitrationOpportunity(ArbitrationOpportunity opportunity) { if (opportunity != null) { StringBuilder logStringBuilder = new StringBuilder(); logStringBuilder.Append("\"" + DateTime.Now.ToString() + "\",\"" + opportunity.BuyExchange.Name + "\",\"" + opportunity.SellExchange.Name + "\",\"" + opportunity.BuyPrice + "\",\"" + opportunity.SellPrice + "\",\"" + opportunity.BuyAmount + "\",\"" + opportunity.Profit + "\",\"" + opportunity.BuyExchangeOrderBook.AsksToString() + "\",\"" + opportunity.SellExchangeOrderBook.BidsToString() + "\""); try { FileWriting.WriteToFile(_currentRun.LogFileName, logStringBuilder.ToString(), FileMode.Append); } catch (IOException) { //Do nothing; just need to catch the exception. If the file is not available its no worries, //just don't log. } } }
//This is required because content size fitter doesn't work with beta unity if inside panel groupings. public static void SetInputFieldTextHackyResize(InputField inputText, string newText, bool displayVisually) { //inputText.text = newText; if (displayVisually) { inputText.text = newText; } else { string fileNameBeforePrefix = "resultsData"; string extension = ".txt"; fileNameBeforePrefix = FileWriting.WriteString(fileNameBeforePrefix, extension, newText); SetInputFieldTextHackyResize(inputText, "The text was too long for Unity to display. Open filename " + Application.dataPath + "/" + fileNameBeforePrefix + extension, true); return; } //inputText.text = newText; Canvas.ForceUpdateCanvases(); Text[] texts = inputText.GetComponentsInChildren <Text>(); if (texts != null) { foreach (Text text in texts) { if (text != null) { //Not sure why this all of a sudden gives wrong line counts when addition of new panel. +10 for buffer. int lineCount = text.cachedTextGenerator.lineCount + 10; RectTransform t = text.rectTransform; Vector2 dimension = t.sizeDelta; dimension.y = (16 * lineCount) + 15; t.sizeDelta = dimension; } } } }
static void Main(string[] args) { FileWriting fw = new FileWriting(); fw.WriteDataIntoFile(); }
public static void Main(string[] args) { FileWriting.CreateTestFile("../../Data/Test.csv", "ID, Type, Minimum Time, Average Delay, Average Cost"); rnd = new Random(); read_configuration_files(); int testID = 1; while (true) { if (_currentAirport.Radar.Count == 0) { _radar = new Thread(() => read_radar_thread("../../Data/Airport" + Airport + "/Radar.csv")); _radar.Start(); } while (!_currentAirport.Ready) { } var selection = new Selection(); var crossover = new Crossover(2, 2); var mutation = new Mutation(); var fitness = new Fitness(); var chromosome = new Chromosome(_currentAirport); var population = new Population(250, 500, chromosome); // FIFO var fifoChr = new Chromosome(_currentAirport, true); fitness.Evaluate(fifoChr, true); var ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation) { CrossoverProbability = 0.5f, MutationProbability = 0.2f, Termination = new TimeEvolvingTermination(TimeSpan.FromMinutes(1)), Reinsertion = new CustomReinsertion(), }; var initialTimeSpan = DateTime.Now; Console.WriteLine("[{0}] Scheduling started", initialTimeSpan); Chromosome lastBest = null; ga.GenerationRan += (sender, e) => { var bestChromosome = ga.BestChromosome as Chromosome; if (lastBest == null) { lastBest = bestChromosome; } }; ga.Start(); Console.WriteLine("[{0}] New Round !", DateTime.Now); FileWriting.WriteToFile("../../Data/Test.csv", testID + ", FIFO, " + fifoChr.ToString()); FileWriting.WriteToFile("../../Data/Test.csv", testID + ", --GA, " + ga.BestChromosome.ToString()); ga.Stop(); _radar.Interrupt(); _currentAirport.Ready = false; _currentAirport.Radar.Clear(); testID++; } }