/// <summary> /// evenly spaced /// </summary> /// <param name="rows"></param> /// <param name="columns"></param> /// <param name="max"></param> /// <param name="min"></param> /// <returns></returns> //public List<double[]> GetMeshPointsInX(int rows, int columns, double[] max, double[] min) //{ // List<double[]> vals = new List<double[]>(); // double deltax = max[0] - min[0]; // double deltay = max[1] - min[1]; // int i, j; // double x, y; // for (i = 0; i < rows; i++) // { // y = (double)i / (double)(rows - 1) * deltay + min[1]; // for (j = 0; j < columns; j++) // { // x = (double)j / (double)(columns - 1) * deltax + min[0]; // double[] p = new double[3] { x, y, 0 }; // Value(ref p); // vals.Add(p); // } // } // return vals; //} /// <summary> /// unevenly spaced /// </summary> /// <param name="rows"></param> /// <param name="columns"></param> /// <param name="max"></param> /// <param name="min"></param> /// <returns></returns> public List<double[]> GetMeshPointsInXUneven(int rows, int columns, double[] max, double[] min) { List<double[]> vals = new List<double[]>(); double deltax = max[0] - min[0]; double deltay = max[1] - min[1]; int i, j; double y, sx; List<double[]> points = new List<double[]>(); points.Add(new double[] { 0, 0 }); points.Add(new double[] { 1.0, 0.5 }); points.Add(new double[] { 8.0, 5.0 }); points.Add(new double[] { 10.0, 10.0 }); RBFCurve rbf = new RBFCurve(null, "shaper", points, new RBFBasis.ThinPlateSpline(null), new RBFPolynomials.Linear(null), 0.0); shaper Shape = ((double value) => { double[] pnt = new double[] { 10.0*value, 0 }; rbf.Value(ref pnt); return pnt[1]/10.0; }); if (m_threaded) { try { int start, end; meshArray.Clear(); for (i = 0; i < meshThreadcount; i++) { meshDoneEvents[i] = new ManualResetEvent(false); start = (rows * i) / meshThreadcount; end = ((i + 1) * rows) / meshThreadcount; MeshThread mt = new MeshThread(this, rows, start, end, columns, deltax, deltay, min, null, meshDoneEvents[i], Shape, null); meshArray.Add(mt); ThreadPool.QueueUserWorkItem(mt.ThreadPoolCallback, i); } // Wait for all threads in pool to calculate. foreach (var e in meshDoneEvents) e.WaitOne(); meshArray.ForEach(delegate(MeshThread m) { vals.AddRange(m.Result); }); } catch (Exception e) { string message = e.Message; } } else { for (i = 0; i < rows; i++) { y = (double)i / (double)(rows - 1) * deltay + min[1]; for (j = 0; j < columns; j++) { //x = (double)j / (double)(columns - 1) * deltax + min[0]; sx = Shape((double)j / (double)(columns - 1)) * deltax + min[0]; double[] p = new double[3] { sx, y, 0 }; Value(ref p); vals.Add(p); } } } return vals; }
void p1BRW_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (p1BRW.CancellationPending == true) Algo.Stop(); m_progBar.Value = e.ProgressPercentage; if (e.UserState == null) return; List<int> bestChromo = (List<int>)e.UserState; if (bestChromo.Count > 0) { List<double[]> GAPnts = new List<double[]>(); double[] result = EvalChromosome(ref bestChromo, ref GAPnts); object curve = new object(); object plot = new object(); for (int j = 0; j < 1; j++) { switch (j + 1) { case 1: curve = p1Curve; plot = plotSurface2D1; break; case 2: curve = p2Curve; plot = plotSurface2D2; break; case 3: curve = p3Curve; plot = plotSurface2D3; break; case 4: curve = p4Curve; plot = plotSurface2D4; break; case 5: curve = p5Curve; plot = plotSurface2D5; break; case 6: curve = p6Curve; plot = plotSurface2D6; break; } RBFCurve oldRBF = curve as RBFCurve; CustomBasis GeneticBasis = new CustomBasis(16.383 / 2.0 - result[0], 16.383 / 2.0 - result[1], 16.383 / 2.0 - result[2], 16.383 / 2.0 - result[3]); //List<double[]> fitpoints = new List<double[]>(oldRBF.OriginalFitPoints); List<double[]> fitpoints = new List<double[]>(GAPnts); if (RemoveExtraFitPoints) { fitpoints.RemoveAt(1); fitpoints.RemoveAt(2); } RBFCurve GaRBF = new RBFCurve(null, "GA RBF", fitpoints, GeneticBasis, new Linear(null), 0.0); NPlot.Windows.PlotSurface2D plotter = (NPlot.Windows.PlotSurface2D)plot; plotter.Clear(); plotter.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; //Add a background grid for better chart readability. NPlot.Grid grid = new NPlot.Grid(); grid.VerticalGridType = NPlot.Grid.GridType.Coarse; grid.HorizontalGridType = NPlot.Grid.GridType.Coarse; grid.MinorGridPen = new Pen(Color.Blue, 1.0f); grid.MajorGridPen = new Pen(Color.LightGray, 1.0f); plotter.Add(grid); int length = oldRBF.FitPoints.Count * 5; //Create a step plot instance for the balance chart. LinePlot speed = new LinePlot(); LinePlot speed2 = new LinePlot(); PointPlot pplot = new PointPlot(); PointPlot pplot2 = new PointPlot(); pplot2.Marker = new Marker(Marker.MarkerType.Cross1, 10, System.Drawing.Color.Red); speed.Pen = new Pen(Color.Blue, 1); //Create the lists from which to pull data. List<Int32> countaxis = new List<Int32>(); List<Int32> Pplotcountaxis = new List<Int32>(); List<Int32> Pplotcountaxis2 = new List<Int32>(); List<decimal> speedlist = new List<decimal>(); List<decimal> speedlist2 = new List<decimal>(); for (int i = 0; i < length; i++) countaxis.Add(i); for (int i = 0; i < oldRBF.FitPoints.Count; i++) Pplotcountaxis.Add((int)oldRBF.OriginalFitPoints[i][0]); for (int i = 0; i < GaRBF.FitPoints.Count; i++) Pplotcountaxis2.Add((int)GaRBF.OriginalFitPoints[i][0]); //Populate the balanceAmount list double[] pnt; List<decimal> pointsList = oldRBF.OriginalFitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); })); List<decimal> pointsList2 = GaRBF.OriginalFitPoints.ConvertAll(new Converter<double[], decimal>((double[] dd) => { return Convert.ToDecimal(dd[1]); })); for (int i = 0; i < length; i++) { pnt = new double[] { (double)i, 0 }; oldRBF.Value(ref pnt); speedlist.Add(Convert.ToDecimal(pnt[1])); pnt = new double[] { (double)i, 0 }; GaRBF.Value(ref pnt); speedlist2.Add(Convert.ToDecimal(pnt[1])); } pplot.AbscissaData = Pplotcountaxis; pplot.DataSource = pointsList; pplot2.AbscissaData = Pplotcountaxis2; pplot2.DataSource = pointsList2; speed.AbscissaData = countaxis; speed.DataSource = speedlist; speed2.AbscissaData = countaxis; speed2.DataSource = speedlist2; //Add stepBalance to plotSurfaceBalance. plotter.Add(speed); plotter.Add(speed2); plotter.Add(pplot); plotter.Add(pplot2); //Balance plot general settings. plotter.ShowCoordinates = true; plotter.AutoScaleAutoGeneratedAxes = true; plotter.AddAxesConstraint(new AxesConstraint.AxisPosition(NPlot.PlotSurface2D.YAxisPosition.Left, 60)); plotter.YAxis1.Label = "Y"; plotter.YAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); plotter.YAxis1.LabelOffsetAbsolute = true; plotter.XAxis1.Label = "X"; plotter.XAxis1.LabelFont = new Font(this.Font, FontStyle.Bold); plotter.YAxis1.LabelOffset = 40; plotter.XAxis1.HideTickText = false; plotter.Padding = 5; plotter.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu; plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false)); plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); plotter.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); plotter.Title = GeneticBasis.ToString(); plotter.TitleFont = new Font(this.Font, FontStyle.Bold); //} //Refresh surfaces. plotter.Refresh(); } Application.DoEvents(); } }