private void Initialize() { defaultPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "..\\..\\..\\Data"); batchPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "..\\..\\..\\Results"); optimizationSettings = new PiecewiseLinearSpeedProfileOptimizationSettings(); optimizationSettings.SetDefault(); }
private void BatchRunLoop(int numberOfBatchRuns, PiecewiseLinearSpeedProfileOptimizationSettings optimizationSettings, OptimizationMethod optimizationMethod) { for (int iRun = 0; iRun < numberOfBatchRuns; iRun++) { speedProfileOptimizer = new PiecewiseLinearSpeedProfileOptimization(); speedProfileOptimizer.OptimizationMethod = optimizationMethod; speedProfileOptimizer.IndividualEvaluated += new EventHandler <EvaluatedIndividualEventArgs>(ThreadSafeHandleBatchRunIndividualEvaluated); speedProfileOptimizer.RunSynchronous(optimizationSettings, new Random(), optimizationSettings.OptimizationTime, metricMap, metricPath); double bestScore = speedProfileOptimizer.BestScore; int numberOfEvaluatedIndividuals = speedProfileOptimizer.NumberOfEvaluatedIndividuals; OptimizableStructure optimizedProfile = speedProfileOptimizer.OptimizedSpeedProfile.Copy(); bestIndividualsList.Add(optimizedProfile); double averageScore = speedProfileOptimizer.AverageFitness; List <double> speedSequence = new List <double>(); List <int> speedSequenceIndexList = new List <int>(); for (int i = 0; i < optimizationSettings.NumberOfSpeedPoints + 1; i++) { int speedIndex = ((IntParameter)optimizedProfile.ParameterList[i]).ParameterValue; speedSequenceIndexList.Add(speedIndex); speedSequence.Add(speedProfileOptimizer.PossibleSpeedList[speedIndex]); } long speedProfileIndex = GetIndexFromValues(speedSequenceIndexList, speedProfileOptimizer.PossibleSpeedList.Count); batchRunInfo += iRun.ToString("0").PadLeft(3) + " " + bestScore.ToString("0.000000").PadLeft(11) + " " + averageScore.ToString("0.000000").PadLeft(11) + " ["; for (int ii = 0; ii < speedSequenceIndexList.Count - 1; ii++) { batchRunInfo += speedSequenceIndexList[ii].ToString("0") + " "; } batchRunInfo += speedSequenceIndexList[speedSequenceIndexList.Count - 1].ToString("0") + "] " + speedProfileIndex.ToString("0").PadLeft(13) + " " + numberOfEvaluatedIndividuals.ToString("0").PadLeft(6) + "\r\n"; ThreadSafeShowResult(numberOfEvaluatedIndividuals, bestScore, averageScore, iRun, optimizedProfile); } if (InvokeRequired) { this.BeginInvoke(new MethodInvoker(() => startBatchRunButton.Enabled = true)); } else { startBatchRunButton.Enabled = true; } if (InvokeRequired) { this.BeginInvoke(new MethodInvoker(() => batchRunProgressListBox.Enabled = true)); } else { batchRunProgressListBox.Enabled = true; } string path = batchPath + "\\BatchRunResult" + "_" + roadFileName + ".txt"; System.IO.File.WriteAllText(path, batchRunInfo); }
public void SetOptimizationSettings(PiecewiseLinearSpeedProfileOptimizationSettings optimizationSettings) { this.optimizationSettings = optimizationSettings; optimizationSettingsPropertyPanel.SetObject(this.optimizationSettings); }