public List <double> DecodeSpeedProfile(OptimizableStructure individual) { //this.speedProfileIndividual = individual; int numberOfLineSegments = individual.ParameterList.Count - 1; List <double> speedSequence = new List <double>(); for (int i = 0; i < numberOfLineSegments + 1; i++) { int speedIndex = ((IntParameter)individual.ParameterList[i]).ParameterValue; speedSequence.Add(possibleSpeedList[speedIndex]); } speedProfile = new PiecewiseLinearSpeedProfile(metricPath, numberOfLineSegments); speedProfile.Generate(metricPath, speedSequence); return(speedSequence); }
private void ShowBatchResult(int numberOfEvaluatedIndividuals, double bestScore, double averageScore, int iRun, OptimizableStructure optimizedProfile) { batchRunProgressListBox.Items.Insert(0, "Run ID: " + iRun.ToString("0") + " Number of evaluated individuals: " + numberOfEvaluatedIndividuals.ToString().PadLeft(7) + " Best fitness: " + bestScore.ToString("0.000000")); List <double> speedSequence = new List <double>(); for (int i = 0; i < optimizationSettings.NumberOfSpeedPoints + 1; i++) { int speedIndex = ((IntParameter)optimizedProfile.ParameterList[i]).ParameterValue; speedSequence.Add(speedProfileOptimizer.PossibleSpeedList[speedIndex]); } PiecewiseLinearSpeedProfile tempProfile = new PiecewiseLinearSpeedProfile(metricPath, optimizationSettings.NumberOfSpeedPoints); tempProfile.Generate(metricPath, speedSequence); PlotSpeedProfile(speedProfilePlot2DPanel, tempProfile, "Batch run"); }
private void PlotSpeedProfile(Plot2DPanel speedProfilePlot2DPanel, PiecewiseLinearSpeedProfile speedProfile, string selectedItem) { if (selectedItem == "Batch run") { } else if (speedProfilePlot2DPanel.HorizontalAxisLabel != "") { speedProfilePlot2DPanel.RemoveSeries(selectedItem); } Color lineColor = Color.Navy; Color pointColor = Color.Blue; if (selectedItem == "Best individual") { lineColor = Color.DarkRed; pointColor = Color.DarkRed; } else if (selectedItem == "Selected individual") { lineColor = Color.DarkGreen; pointColor = Color.DarkGreen; } List <double> horizentalAxisData = new List <double>(); List <double> verticalAxisData = new List <double>(); double xMin = 0; double xMax = speedProfile.ConnectionPointsList.Last()[1]; double entryDistance = 0; double exitDistance = 0; // It is assumed that there are only one SegmentSpeedProfile for (int i = 0; i < speedProfile.ConnectionPointsList.Count; i++) { exitDistance = speedProfile.ConnectionPointsList[i][1]; for (double u = 0; u <= 1; u += 0.1) { double x = entryDistance + u * (exitDistance - entryDistance); double speed = speedProfile.SegmentLinearSpeedProfileList[0].LinearBezierSplineList[i].GetPoint(u).CoordinateList[0]; horizentalAxisData.Add(x); verticalAxisData.Add(speed); } entryDistance = exitDistance; } DataSeries speedProfileDataSeries = new DataSeries(); speedProfileDataSeries.Generate(selectedItem, horizentalAxisData, verticalAxisData); speedProfileDataSeries.SetLineColor(lineColor); speedProfileDataSeries.SetPointColor(pointColor); speedProfileDataSeries.ConnectRange(xMin, xMax); speedProfileDataSeries.SetPointVisibilityState(false); speedProfileDataSeries.SetLineWidth(0.0035); double horizentalDataRange = horizentalAxisData.Max() - horizentalAxisData.Min(); double verticalDataRange = optimizationSettings.MaximumSpeedValue - optimizationSettings.MinimumSpeedValue; speedProfilePlot2DPanel.MajorHorizontalTickMarkSpacing = horizentalDataRange / 10; speedProfilePlot2DPanel.MajorVerticalTickMarkSpacing = verticalDataRange / 4; speedProfilePlot2DPanel.AxisColor = Color.Black; speedProfilePlot2DPanel.VerticalAxisVisible = true; speedProfilePlot2DPanel.HorizontalAxisVisible = true; speedProfilePlot2DPanel.HorizontalAxisMarkingsVisible = true; speedProfilePlot2DPanel.GridVisible = true; speedProfilePlot2DPanel.SetHorizontalPlotRange(horizentalAxisData.Min(), horizentalAxisData.Max()); speedProfilePlot2DPanel.SetVerticalPlotRange(optimizationSettings.MinimumSpeedValue, optimizationSettings.MaximumSpeedValue); // Hardcoded range for the speed profile, need to be fixed. speedProfilePlot2DPanel.HorizontalAxisLabel = "X"; speedProfilePlot2DPanel.HorizontalAxisLabelFontSize = 14; speedProfilePlot2DPanel.VerticalAxisLabel = "Speed"; speedProfilePlot2DPanel.VerticalAxisLabelFontSize = 14; speedProfilePlot2DPanel.HorizontalAxisMarkingsFormatString = "0"; speedProfilePlot2DPanel.VerticalAxisMarkingsFormatString = "0.0"; speedProfilePlot2DPanel.AddDataSeries(speedProfileDataSeries); //speedProfilePlot2DPanel.AddDataSeries(vehicleSpeedDataSeries); }
// Used when (re-)evaluating a given speed profile set, rather than obtaining // it via decoding (as in a GA). public void AssignSpeedProfile(PiecewiseLinearSpeedProfile speedProfile) { this.speedProfile = speedProfile; }