/// <summary> /// This method combines the passed base airfoil with the passed coefficients as aparallel processing. /// If finish the processing, it fires the event combinatedAirfoilUpdated. /// </summary> /// <param name="basisAirfoils"></param> /// <param name="coefficients"></param> public void CombineAirfoils(General.BasisAirfoils basisAirfoils, Double[,] coefficients) { List <Task> tasks = new List <Task>(); for (int i = 0; i < _numberOfAirfoils; i++) { // Null Check if (_combinedAirfoils[i] == null) { _combinedAirfoils[i] = new Representation.AirfoilCombiner(); } var x = i; var basis = basisAirfoils.AirfoilGroup.ToArray(); var coef = GetRowArray(coefficients, i); // Update Source and Re-Combinate Airfoil. tasks.Add(Task.Run(() => _combinedAirfoils[x].UpdateBaseSource(coef, basis))); } Task.WaitAll(tasks.ToArray()); // Fire the event combinedAirfoilsUpdated CombinedAirfoilsUpdated?.Invoke(this, new CombinedAirfoilsUpdatedEventArgs() { combinedAirfoils = this._combinedAirfoils }); }
private void SourceChanged(object sender, EventArgs e) { // Null Check if (AirfoilOptimizationResource.Instance.BasisAirfoils == null) { return; } if (AirfoilOptimizationResource.Instance.CurrentCoefficients == null) { return; } // Update baseAirfoil this.basisAirfoils = General.BasisAirfoils.Convert(AirfoilOptimizationResource.Instance.BasisAirfoils); // Update coefficients this.coefficients = AirfoilOptimizationResource.Instance.CurrentCoefficients.GetCoefficientArray() as Double[, ]; // Re-combinate Airfoil this.currentPopulations = AirfoilOptimizationResource.Instance.CurrentPopulations; // Re-set current offsprings this.offspringAirfoilCandidates = AirfoilOptimizationResource.Instance.OffspringCandidates; // Re-generate the coordinates for airfoil previewing. ReDrawPreviewWindow(); }
public void StartCrossover(Airfoil.CombinedAirfoilsGroup parents) { parentAirfoils = parents; var parentsAirfoilsArray = parentAirfoils.CombinedAirfoils; // Initialize Basis airfoils basisAirfoils = new General.BasisAirfoils(parentAirfoils.BasisAirfoils.AirfoilGroup); // Execute Crossover crossoverExecutor.ExecuteCrossover(parentAirfoils.CoefficientOfCombination); // Read Offsprings' optimization parameters var optParams = crossoverExecutor.OptimizationParamters; optParams = SwapJuggedArray(optParams); var optCoef = new Airfoil.CoefficientOfCombination(General.ArrayManager.ConvertJuggedArrayToArray(optParams)); // Assign Selected Parents Index parentsIndex = crossoverExecutor.ParentsIndex; // Initialize each fields offspringAirfoilsCombiner = new Airfoil.CombinedAirfoilsGroup(basisAirfoils); Airfoil.AirfoilsMixer airfoilsMixer = new Airfoil.AirfoilsMixer(basisAirfoils, optCoef); // Create Offspring Airfoils // Combine airfoils airfoilsMixer.CombineAirfoils(); // Store combined airfoils into CombinedAirfoilsGroup class offspringAirfoilsCombiner.AddRange(airfoilsMixer.CombinedAirfoils); }
/// <summary> /// /// </summary> /// <param name="optParams"></param> /// <param name="basisAirfoils"></param> /// <returns></returns> private CombinedAirfoilsGroup AssignParameters(double[][] optParams, General.BasisAirfoils basisAirfoils) { // Format Check if (optParams.Length == basisAirfoils.NumberOfAirfoils) { var length = basisAirfoils.NumberOfAirfoils; combinedAirfoilsGroup = new CombinedAirfoilsGroup(basisAirfoils); // Create optimized Coefficients var optCoefficients = new CoefficientOfCombination(General.ArrayManager.ConvertJuggedArrayToArray(optParams)); // Combine airfoil AirfoilsMixer airfoilsMixer = new AirfoilsMixer(basisAirfoils, optCoefficients); airfoilsMixer.CombineAirfoils(); // Assign combined airfoils into the CombinedAirfoilsGroup combinedAirfoilsGroup.AddRange(airfoilsMixer.CombinedAirfoils); } return(combinedAirfoilsGroup); }
private static void InitializeTestVariables(out Airfoil.CoefficientOfCombination coefficients, out General.BasisAirfoils basisAirfoils) { StreamReader sr1 = new StreamReader(@"DAE-11.csv"); StreamReader sr2 = new StreamReader(@"NACA4412.csv"); var dae = General.CsvManager.ConvertCsvToArray(sr1.ReadToEnd()); var naca = General.CsvManager.ConvertCsvToArray(sr2.ReadToEnd()); var daeCoordinate = new Airfoil.AirfoilCoordinate(); var nacaCoordinate = new Airfoil.AirfoilCoordinate(); daeCoordinate.Import(dae); nacaCoordinate.Import(naca); var DAE11 = new Airfoil.AirfoilManager(daeCoordinate); var NACA4412 = new Airfoil.AirfoilManager(daeCoordinate); var coef = new double[][] { new[] { 0.7, 0.3, 0.6 }, new[] { 0.3, 0.7, 0.4 } }; coefficients = new Airfoil.CoefficientOfCombination(General.ArrayManager.ConvertJuggedArrayToArray(coef)); basisAirfoils = new General.BasisAirfoils(new[] { DAE11, NACA4412 }); }
private void WorkingFileImported(object sender, FWorkingFileIO.WorkingFileIO.OpeningFileFinishedEventArgs e) { General.BasisAirfoils baseAirfoilsGroup = new General.BasisAirfoils(); foreach (var item in e.BaseAirfoils) { baseAirfoilsGroup.Add(item); } // Set Current Population AirfoilOptimizationResource.Instance.SetSource ( baseAirfoilsGroup, e.CoefficientOfCombination, e.CurrentNames, e.CurrentLifts, e.CurrentDrags ); // Set Optimization Halfway if (e.ParentsIndex != null) { AirfoilOptimizationResource.Instance.ParentsIndex = e.ParentsIndex; } // Set Current Offspring candidates if (e.OffspringCoefficients != null) { AirfoilOptimizationResource.Instance.SetOffspringCandidates ( e.OffspringCoefficients, e.OffspringNames, e.OffspringLifts, e.OffspringDrags ); } }
public ExternalEvaluation(General.BasisAirfoils basisAirfoils) { this.basisAirfoils = basisAirfoils; }
public CombinedAirfoilsGroup(General.BasisAirfoils basisAirfoils) { this._basisAirfoils = basisAirfoils; _numberOfBasisAirfoils = basisAirfoils.NumberOfAirfoils; }
public void StartSelection(Airfoil.CombinedAirfoilsGroup offsprings) { // Initialize Basis airfoils if (basisAirfoils == null) { basisAirfoils = new General.BasisAirfoils(parentAirfoils.BasisAirfoils.AirfoilGroup); } // Executes selection to extract airfoil from offsprings var selectedParents = new Airfoil.CombinedAirfoilsGroup(parentAirfoils.BasisAirfoils); foreach (var item in parentsIndex) { selectedParents.Add( parentAirfoils.CombinedAirfoils[item], parentAirfoils.CoefficientOfCombination.GetCoefficients(item)); } selectionExecutor.ExecuteSelection(offsprings + selectedParents); // Extract selected offsprings SelectedOffspringsNo = selectionExecutor.SelectedAirfoilsNo; var selectedAirfoils = selectionExecutor.SelectedAirfoils; offspringAirfoils = new Airfoil.CombinedAirfoilsGroup(basisAirfoils); for (int i = 0; i < selectedAirfoils.CombinedAirfoils.Length; i++) { var airfoil = selectedAirfoils.CombinedAirfoils[i]; var coefficients = selectedAirfoils.CoefficientOfCombination.GetCoefficients(i); offspringAirfoils.Add(airfoil, coefficients); } // Create next Generation int k = 0; var previousGen = parentAirfoils.CombinedAirfoils; Airfoil.CombinedAirfoilsGroup nextGenerations = new Airfoil.CombinedAirfoilsGroup(basisAirfoils); for (int i = 0; i < previousGen.Length; i++) { if (IsEqual(i, parentsIndex)) { var airfoil = selectedAirfoils.CombinedAirfoils[k]; var coefficients = selectedAirfoils.CoefficientOfCombination.GetCoefficients(k); nextGenerations.Add(airfoil, coefficients); ++k; } else { var airfoil = parentAirfoils.CombinedAirfoils[i]; var coefficients = parentAirfoils.CoefficientOfCombination.GetCoefficients(i); nextGenerations.Add(airfoil, coefficients); } } nextAirfoilGenerations = nextGenerations; // newest virsion /* * var nextGenerations = new Airfoil.CombinedAirfoilGroup(); * for (int i = 0; i < previousGen.Length; i++) * { * if (IsEqual(i, parentsIndex)) * { * nextGenerations.Add(selectedAirfoils[k].CombinedAirfoil); ++k; * } * else * { * nextGenerations.Add(previousGen[i].CombinedAirfoil); * } * } */ }