public QpProgressReport Solve(QpProblem data) { QpProgressReport report = this.preSolver.PreSolve(); if (report.SolveStatus != QpTerminationCode.InProgress) { return(report); } // Set up the problem from the warm start strategy Variables currentIterate = this.warmStartStrategy.GenerateInitialPoint(data, report.X); NewtonSystem newtonEquations = this.warmStartStrategy.InitialNewtonEquations; Residuals residuals = this.warmStartStrategy.InitialResiduals; double mu = currentIterate.Mu(); int count = 0; do { // Analyse and report on the algorithm progress report = this.statusReporter.DetermineProgress(currentIterate, residuals, mu, count); this.publisher.Publish(report); if (report.SolveStatus != QpTerminationCode.InProgress) { break; } // ~~~~~ Predictor Step ~~~~~ // Factorise the system of equations using a Newton method ISolver <double> choleskyFactor = newtonEquations.Factorize(currentIterate, count); Variables step = newtonEquations.ComputeStep(currentIterate, residuals, choleskyFactor); // Calculate the largest permissable step length (alpha affine) double alpha = currentIterate.GetLargestAlphaForStep(step); // Calculate the complementarity measure and associated centering parameter. double muAffine = currentIterate.MuGivenStep(step, alpha); double sigma = Math.Pow(muAffine / mu, 3); // ~~~~~ Corrector Step ~~~~~ // Apply second order step corrections and a re-centering adjustment. residuals.ApplyCorrection(step, sigma, mu); // Compute the corrected step and largest permitted step length. step = newtonEquations.ComputeStep(currentIterate, residuals, choleskyFactor); alpha = currentIterate.GetLargestAlphaForStep(step); // Finally take the step and calculate the new complementarity measure. currentIterate.ApplyStep(step, alpha); residuals.Update(currentIterate); mu = currentIterate.Mu(); count++; } while (report.SolveStatus == QpTerminationCode.InProgress && count < 10000); return(report); }
private void PrintTitle(QpProgressReport report) { this.PrintSeparator(); string[] headers = new[] { "Iteration", "Merit Function", "Solve Status" }; var stringHeaders = string.Format("{0,-17}{1,-17}{2,-17}", headers[0], headers[1], headers[2]); this.PrintMessage(stringHeaders); this.PrintSeparator(); }
public void PrintResults(QpProgressReport results, SpreadSheetExample example, Int64 elapsedMs, StringBuilder stringBuilder) { this.Display(new String('*', 50), stringBuilder); this.Display(example.Name, stringBuilder); this.Display(string.Format("Iterations: {0}", results.Iterations), stringBuilder); this.Display(string.Format("Elapsed time: {0}ms", elapsedMs), stringBuilder); this.Display("Solution: " + results.SolveStatus.ToString(), stringBuilder); this.Display(results.X, stringBuilder); this.Display(string.Empty, stringBuilder); }
private void PrintQpReport(object sender, QpReportPublishedEventArgs e) { QpProgressReport report = e.ProgressReport; if (report.Iterations == 0) { this.PrintTitle(report); } this.PrintTableData(report); if (report.SolveStatus != QpTerminationCode.InProgress) { this.PrintSeparator(); this.PrintMessage(string.Empty); } }
private void PrintTableData(QpProgressReport report) { string phi; if (Math.Abs(report.MeritFunction) > 10000 || Math.Abs(report.MeritFunction) < 0.01) { phi = report.MeritFunction.ToString("0.00000E+0"); } else { phi = report.MeritFunction.ToString("0.###"); } var stringHeaders = string.Format( "{0,-17}{1,-17}{2,-17}", report.Iterations, phi, report.SolveStatus); this.PrintMessage(stringHeaders); }