public IActionResult Hookes() { int nNumVars = 2; double[] fX = new double[] { 0, 0 }; double[] fParam = new double[] { 0, 0 }; double[] fStepSize = new double[] { 0.1, 0.1 }; double[] fMinStepSize = new double[] { 0.0000001, 0.0000001 }; int nIter = 0; double fEpsFx = 0.01; int i; object fBestF; Hookes oOpt; SolvedModel model = new SolvedModel(); MyFxDelegate MyFx = new MyFxDelegate(Fx3); SayFxDelegate SayFx = new SayFxDelegate(SayFx3); oOpt = new Hookes(); model.Tolerace = fEpsFx; Console.WriteLine("******** FINAL RESULTS *************"); fBestF = oOpt.CalcOptim(nNumVars, ref fX, ref fParam, ref fStepSize, ref fMinStepSize, fEpsFx, ref nIter, MyFx); Console.WriteLine("Optimum at"); for (i = 0; i < nNumVars; i++) { model.X.Add(fX[i]); } model.Function = (double)fBestF; model.Iterations = nIter; return(View(model)); }
public IActionResult Hookes() { int nNumVars = 2; double[] fX = new double[] { 0, 0 }; double[] fParam = new double[] { 0, 0 }; double[] fStepSize = new double[] { 0.1, 0.1 }; double[] fMinStepSize = new double[] { 0.0000001, 0.0000001 }; int nIter = 0; double fEpsFx = 0.0000001; int i; object fBestF; string sAnswer; Hookes oOpt; MyFxDelegate MyFx = new MyFxDelegate(Fx3); SayFxDelegate SayFx = new SayFxDelegate(SayFx3); oOpt = new Hookes(); Console.WriteLine("Hooke-Jeeves Search Optimization"); Console.WriteLine("Finding the minimum of function:"); Console.WriteLine(SayFx()); Console.Write("Use default input values? (Y/N) "); sAnswer = Console.ReadLine(); if (sAnswer.ToUpper() == "Y") { for (i = 0; i < nNumVars; i++) { Console.WriteLine("X({0}) = {1}", i + 1, fX[i]); Console.WriteLine("Step size({0}) = {1}", i + 1, fStepSize[i]); Console.WriteLine("Min step Size ({0}) = {1}", i + 1, fMinStepSize[i]); } Console.WriteLine("Function tolerance = {0}", fEpsFx); } else { for (i = 0; i < nNumVars; i++) { fX[i] = GetIndexedDblInput("X", i + 1, fX[i]); fStepSize[i] = GetIndexedDblInput("Step size", i + 1, fStepSize[i]); fMinStepSize[i] = GetIndexedDblInput("Min step size", i + 1, fMinStepSize[i]); } fEpsFx = GetDblInput("Function tolerance", fEpsFx); } Console.WriteLine("******** FINAL RESULTS *************"); fBestF = oOpt.CalcOptim(nNumVars, ref fX, ref fParam, ref fStepSize, ref fMinStepSize, fEpsFx, ref nIter, MyFx); Console.WriteLine("Optimum at"); for (i = 0; i < nNumVars; i++) { Console.WriteLine("X({0}) = {1}", i + 1, fX[i]); } Console.WriteLine("Function value = {0}", fBestF); Console.WriteLine("Number of iterations = {0}", nIter); Console.WriteLine(); Console.Write("Press Enter to end the program ..."); Console.ReadLine(); return(View()); }
public IActionResult Fletcher() { int nNumVars = 2; double[] fX = new double[] { 0, 0 }; double[] fParam = new double[] { 0, 0 }; int nIter = 0; int nMaxIter = 100; double fEpsFx = 0.001; int i; double fBestF; string sErrorMsg = ""; Fletcher oOpt; SolvedModel model = new SolvedModel(); MyFxDelegate MyFx = new MyFxDelegate(Fx3); SayFxDelegate SayFx = new SayFxDelegate(SayFx3); oOpt = new Fletcher(); model.Tolerace = fEpsFx; model.MaxCycles = nMaxIter; fBestF = oOpt.CalcOptim(nNumVars, ref fX, ref fParam, fEpsFx, nMaxIter, ref nIter, ref sErrorMsg, MyFx); if (sErrorMsg.Length > 0) { model.ErrorMsg = sErrorMsg; } for (i = 0; i < nNumVars; i++) { model.X.Add(fX[i]); } model.Function = fBestF; model.Iterations = nIter; return(View(model)); }