I'm still missing something on how this works. Here's the code I'm trying to use (with error "Use of unassigned local variable 'ndrep' "). The code I added is bold.
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace MinASA_Test_csharp_31_1 { class Program { public static void function1_grad(double[] x, ref double func, double[] grad, object obj) { // this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4 // and its derivatives df/d0 and df/dx1 func = 100 * System.Math.Pow(x[0] + 3, 4) + System.Math.Pow(x[1] - 3, 4); grad[0] = 400 * System.Math.Pow(x[0] + 3, 3); grad[1] = 4 * System.Math.Pow(x[1] - 3, 3); } public static int Main(string[] args) { // // This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4 // subject to bound constraints -1<=x0<=+1, -1<=x1<=+1, using ASA. // double[] x = new double[] { 0, 0 }; double[] bndl = new double[] { -1, -1 }; double[] bndu = new double[] { +1, +1 }; double epsg = 0.0000000001; double epsf = 0; double epsx = 0; int maxits = 0; alglib.minasastate state; alglib.minasareport rep; alglib.ndimensional_rep ndrep; alglib.minasacreate(x, bndl, bndu, out state); alglib.minasasetcond(state, epsg, epsf, epsx, maxits); alglib.minasasetxrep(state, true); alglib.minasaoptimize(state, function1_grad, ndrep, null); alglib.minasaresults(state, out x, out rep);
System.Console.WriteLine("{0}", rep.terminationtype); // EXPECTED: 4 System.Console.WriteLine("{0}", alglib.ap.format(x, 2)); // EXPECTED: [-1,1] System.Console.ReadLine(); return 0; } } }
Any thoughts would be greatly appreciated.
Thanks, DAK
|