CGO solver usage

From TomWiki
Jump to navigationJump to search

Notice.png

This page is part of the CGO Manual. See CGO Manual.

Defining the problem

Let the name of the problem be "CGOF Test" The function CGOF is best written as

function f = CGOF(x, Prob)

Then any information, say u and W is easily sent to CGOF (and the constraint function CGOC, if present) using the Prob structure. See the example below.

Assume bounds x_L and x_U are initialized, as well as the linear constraint matrix A, lower and upper bounds, b_L and b_U on the linear constraints, and lower and upper bounds c_L and c_U on the nonlinear constraints (Put [] if all bounds are inf or -inf). Use the TOMLAB Quick format:

   Prob   = glcAssign('CGOF',x_L,x_U,'CGOF Test',A,b_L,b_U,'CGOC',c_L,c_U);
   Prob.user.u = u; Prob.user.W=W;    % example of extra user data

Default values are now set for PriLevOpt, and structure optParam
To change a value, examples are shown on the two next lines

   Prob.optParam.MaxFunc = 400;   % Change max number of costly function evaluations
   Prob.optParam.MaxIter = 2000;  % Change local iteration maximum to 2000
   Prob.GO.MaxFunc       = 20000; % 20000 global function values in subproblem

Driver calls

Printing with level 2:

     Result = tomRun('rbfSolve',Prob,2);

or

     Result = tomRun('arbfmip',Prob,2);

or

     Result = tomRun('ego',Prob,2);

Direct solver call

   Result = rbfSolve(Prob);

or

   Result = arbfmip(Prob);

or

   Result = ego(Prob);

then

   PrintResult(Result);

User functions

The user function CGOF is written as

   function f = CGOF(x, Prob)
   u = Prob.user.u; W = Prob.user.W;
   f = "some function of x, u and W"

It is also possible (not recommmended) to use the function format

   function f = CGOF(x)

but then any additional parameters must be sent as global variables.

The user function CGOC, computing the nonlinear constraints, is written as

   function c = CGOC(x, Prob)
   u = Prob.user.u; W = Prob.user.W;
   c = "some vector function of x, V and W"

Note! If CGOF has the 2nd input argument Prob, also CGOC must have that.

Restart a problem

To make a restart (warm start), just set the restart flag, and call any CGO solver once again:

   Prob.WarmStart = 1;

then

   Result         = tomRun('rbfSolve',Prob,2);

or

   Result         = tomRun('arbfmip',Prob,2);

or

   Result         = tomRun('ego',Prob,2);

Another option for warm start is to put the restart information from the Result structure to the Prob structure and then call a CGO solver again:

   Prob   = WarmDefGLOBAL('rbfSolve',Prob,Result)

or

   Prob   = WarmDefGLOBAL('arbfmip',Prob,Result)

or

   Prob   = WarmDefGLOBAL('ego',Prob,Result)

then (now Prob.WarmStart is 1)

   Result = tomRun('rbfSolve',Prob,2);

or

   Result = tomRun('arbfmip',Prob,2);

or

   Result = tomRun('ego',Prob,2);

It is always possible to switch CGO solver when doing the warm start

To continue last run, similar to a warm start, but also add a new experimental design

   % Read and set as input the computed (x,f(x)) from last run
   % The latest run is always saved in mat file cgoSave.mat
   LastRun        = load('glcSave.mat')
   LastRun.Name                     % Check that the Name of the problem is correct
   ws             = LastRun.WSInfo; % The WSInfo structure has all relevant information
   Prob.CGO.F     = ws.F00;         % The actual f(x) value computed without any penalties
   Prob.CGO.X     = ws.O;           % All x points in original space, not scaled to [0,1]
   Prob.CGO.Cc    = ws.Cc;          % Costly nonlinear constraint, used in forthcoming release
   Prob.Percent   = 6;              % New design with e.g. latin hypercube
   Prob.nSample   = 20;             % 20 points with latin hypercube
   Prob.WarmStart = 0;              % No warm start, computed data is in CGO.F and CGO.X instead

then

   Result         = tomRun('rbfSolve',Prob,2);

or

   Result         = tomRun('arbfmip',Prob,2);

or

   Result         = tomRun('ego',Prob,2);

Considerations

Observe that when cancelling with CTRL+C during a run, some memory allocated by the CGO solver will not be deallocated. To deallocate, do:

 >> clear cgolib