private static List <System.Windows.Point> Spline(List <System.Windows.Point> point_vector, int splits) { List <System.Windows.Point> temp1 = new List <System.Windows.Point>(); General.Vector Y = new General.Vector(point_vector.Count); General.Vector a = new General.Vector(point_vector.Count); General.Matrix A = new General.Matrix(point_vector.Count); double[] x = new double[splits]; double[] y = new double[splits]; for (int i = 0; i < point_vector.Count; i++) { double temp = point_vector[i].X; y[i] = point_vector[i].Y; for (int j = 0; j < point_vector.Count; j++) { A[i, j] = System.Math.Pow(temp, j); } } a = A.InverceMatrix() * Y; for (int k = 0; k < splits; k++) { var max = (search_max(point_vector, XorY.X) - search_min(point_vector, XorY.X)); x[k] = max * k / splits; } for (int k = 0; k < splits; k++) { for (int i = 0; i < point_vector.Count; i++) { y[k] += a[i] * System.Math.Pow(x[k], i); } } for (int k = 0; k < splits; ++k) { System.Windows.Point temp = new System.Windows.Point(x[k], y[k]); temp1.Add(temp); } return(temp1); }
/// <summary> /// Execute the crossover with UNDX /// </summary> /// <param name="parents">Individuals of previous generation</param> /// <returns>If all crossovers are succesful, offsprings are returned, otherwise null is returned.</returns> public double[][] ExecuteCrossover(IndividualsGroup parents) { Airfoil.CombinedAirfoilsGroupManager offsptingAirfoils = new Airfoil.CombinedAirfoilsGroupManager(nCrossover); Airfoil.AirfoilManager[] selectedParents = new Airfoil.AirfoilManager[2]; General.RandomNumber.RandomNumberGenerator randomNumberGenerator = new General.RandomNumber.RandomNumberGenerator(); General.Statistics.SamplingWithoutReplacement sampling = new General.Statistics.SamplingWithoutReplacement(); // Random Airfoil Selection uint[] pIndex = sampling.GetIndex(3, (uint)parents.NumberOfIndividuals); ParentsIndex[0] = (int)pIndex[0]; ParentsIndex[1] = (int)pIndex[1]; // Create Optimization Parameter Vector General.Vector p1 = new General.Vector(nParams); General.Vector p2 = new General.Vector(nParams); General.Vector p3 = new General.Vector(nParams); for (int i = 0; i < nParams; i++) { p1[i] = parents.IndivisualsGroup[(int)pIndex[0]].OptParameters[i]; p2[i] = parents.IndivisualsGroup[(int)pIndex[1]].OptParameters[i]; p3[i] = parents.IndivisualsGroup[(int)pIndex[2]].OptParameters[i]; } // If same parameter vector are selected, return null to retry selection. if (p1.Equals(p2) && p1.Equals(p3)) { return(null); } int n = parents.NumberOfIndividuals; double d1 = (p2 - p1).Norm(); double d2 = (General.Vector.InnerProduct(p3 - p1, p2 - p1) / Math.Pow((p2 - p1).Norm(), 2) * (p2 - p1) - p3).Norm(); double sigma1 = alpha * d1; double sigma2 = beta * d2 / Math.Sqrt(n); General.Vector m = (1.0 / 2.0) * (p1 + p2); // Create new parameter vector for offsprings General.Vector[] offspringParameter = new General.Vector[nCrossover]; double[][] offspringParameterArray = new double[nCrossover][]; // Create Offspring's parameter vector for (int i = 0; i < nCrossover; i++) { var StdOffspringPts = randomNumberGenerator.NormDistRandNumSeq(nParams); offspringParameter[i] = new General.Vector(StdOffspringPts); var e1 = 1 / (p2 - p1).Norm() * (p2 - p1); var pAxisComp = General.Vector.InnerProduct(offspringParameter[i], e1); offspringParameter[i] -= pAxisComp * e1; offspringParameter[i] = sigma2 * offspringParameter[i]; offspringParameter[i] += sigma1 * pAxisComp * e1; offspringParameter[i] = offspringParameter[i] + m; offspringParameterArray[i] = offspringParameter[i].ToDoubleArray(); } return(offspringParameterArray); }
public static List <System.Windows.Point> SplineInterpolation(List <System.Windows.Point> point_vector, int _splits) { int n = point_vector.Count - 1; var splits = _splits / n; double[] ax = new double[n + 1]; double[] bx = new double[n + 1]; double[] cx = new double[n + 1]; double[] dx = new double[n + 1]; double[] ay = new double[n + 1]; double[] by = new double[n + 1]; double[] cy = new double[n + 1]; double[] dy = new double[n + 1]; double[] u = new double[splits]; General.Matrix A = new General.Matrix(n + 1); General.Vector vec_bx = new General.Vector(n + 1); General.Vector vec_cx = new General.Vector(n + 1); General.Vector vec_by = new General.Vector(n + 1); General.Vector vec_cy = new General.Vector(n + 1); List <System.Windows.Point> new_list = new List <System.Windows.Point>(); for (int i = 0; i < n + 1; i++) { ax[i] = point_vector[i].X; ay[i] = point_vector[i].Y; } A[0, 0] = 1; A[n, n] = 1; for (int i = 1; i < n; i++) { A[i, i - 1] = 1; A[i, i] = 4; A[i, i + 1] = 1; } vec_bx[0] = 0; vec_bx[n] = 0; vec_by[0] = 0; vec_by[n] = 0; for (int i = 1; i < n; i++) { vec_bx[i] = 3 * (ax[i + 1] - 2 * ax[i] + ax[i - 1]); vec_by[i] = 3 * (ay[i + 1] - 2 * ay[i] + ay[i - 1]); } //cx = (A.InverceMatrix() * vec_bx).ToDoubleArray(); //cy = (A.InverceMatrix() * vec_by).ToDoubleArray(); General.Solvers.JacobiMethod jSolver1 = new Solvers.JacobiMethod(A.GetArray(), vec_bx.ToDoubleArray()); General.Solvers.JacobiMethod jSolver2 = new Solvers.JacobiMethod(A.GetArray(), vec_by.ToDoubleArray()); jSolver1.Error = 1E-15; jSolver2.Error = 1E-15; jSolver1.CheckInterval = 10; jSolver2.CheckInterval = 10; jSolver1.Solve(); jSolver2.Solve(); cx = jSolver1.Solution; cy = jSolver2.Solution; for (int i = 0; i < n; i++) { bx[i] = (ax[i + 1] - ax[i]) - (cx[i + 1] + 2 * cx[i]) / 3; dx[i] = (cx[i + 1] - cx[i]) / 3; by[i] = (ay[i + 1] - ay[i]) - (cy[i + 1] + 2 * cy[i]) / 3; dy[i] = (cy[i + 1] - cy[i]) / 3; } //Generate x point for (int k = 0; k < splits; k++) { u[k] = (double)k / (double)splits; } for (int i = 0; i < n; i++) { for (int k = 0; k < splits; k++) { var x = ax[i] + bx[i] * u[k] + cx[i] * System.Math.Pow(u[k], 2) + dx[i] * System.Math.Pow(u[k], 3); var y = ay[i] + by[i] * u[k] + cy[i] * System.Math.Pow(u[k], 2) + dy[i] * System.Math.Pow(u[k], 3); new_list.Add(new System.Windows.Point(x, y)); } } new_list.Add(point_vector[n]); return(new_list); }