10.07.2015 Views

Optimization in Scilab - Projects

Optimization in Scilab - Projects

Optimization in Scilab - Projects

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Optimization</strong> <strong>in</strong> <strong>Scilab</strong>Michaël Baud<strong>in</strong> V<strong>in</strong>cent Couvert Serge SteerJuly 2010


AbstractIn this document, we make an overview of optimization features <strong>in</strong> <strong>Scilab</strong>. The goal of thisdocument is to present all exist<strong>in</strong>g and non-exist<strong>in</strong>g features, such that a user who wants to solvea particular optimization problem can know what to look for. In the <strong>in</strong>troduction, we analysea classification of optimization problems, which serves as a guide for all the document. In thefirst chapter, we analyse the flagship of <strong>Scilab</strong> <strong>in</strong> terms of nonl<strong>in</strong>ear optimization: the optimfunction. We analyse its features, the management of the cost function, the l<strong>in</strong>ear algebra andthe management of the memory. Then we consider the algorithms which are used beh<strong>in</strong>d optim,depend<strong>in</strong>g on the type of algorithm and the constra<strong>in</strong>ts. In the rema<strong>in</strong><strong>in</strong>g chapters, we present thealgorithms available to solve quadratic problems, non-l<strong>in</strong>ear least squares problems, semidef<strong>in</strong>iteprogramm<strong>in</strong>g, genetic algorithms, simulated anneal<strong>in</strong>g and l<strong>in</strong>ear matrix <strong>in</strong>equalities (which makeuse of semidef<strong>in</strong>ite programm<strong>in</strong>g). A chapter focus on optimization data files managed by <strong>Scilab</strong>,especially MPS and SIF files. Some optimization features are available <strong>in</strong> the form of toolboxes,the most important of which are the Quapro and CUTEr toolboxes. The f<strong>in</strong>al chapter is devotedto miss<strong>in</strong>g optimization features <strong>in</strong> <strong>Scilab</strong>.


ContentsIntroduction 51 Non-l<strong>in</strong>ear optimization 101.1 Mathematical po<strong>in</strong>t of view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.2 <strong>Optimization</strong> features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.3 <strong>Optimization</strong> rout<strong>in</strong>es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.4 The cost function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.5 L<strong>in</strong>ear algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.6 Management of memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.7 Quasi-Newton ”qn” without constra<strong>in</strong>ts : n1qn1 . . . . . . . . . . . . . . . . . . . 131.7.1 Management of the approximated Hessian matrix . . . . . . . . . . . . . . 151.7.2 L<strong>in</strong>e search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161.7.3 Initial Hessian matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161.7.4 Term<strong>in</strong>ation criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171.7.5 An example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181.8 Quasi-Newton ”qn” with bounds constra<strong>in</strong>ts : qnbd . . . . . . . . . . . . . . . . . 201.9 L-BFGS ”gc” without constra<strong>in</strong>ts : n1qn3 . . . . . . . . . . . . . . . . . . . . . . . 201.10 L-BFGS ”gc” with bounds constra<strong>in</strong>ts : gcbd . . . . . . . . . . . . . . . . . . . . . 211.11 Non smooth method without constra<strong>in</strong>ts : n1fc1 . . . . . . . . . . . . . . . . . . . 222 Quadratic optimization 232.1 Mathematical po<strong>in</strong>t of view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232.2 qpsolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232.3 qp solve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.4 Memory requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.5 Internal design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Non-l<strong>in</strong>ear least square 263.1 Mathematical po<strong>in</strong>t of view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.2 <strong>Scilab</strong> function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.3 <strong>Optimization</strong> rout<strong>in</strong>es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 Semidef<strong>in</strong>ite programm<strong>in</strong>g 274.1 Mathematical po<strong>in</strong>t of view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.2 <strong>Scilab</strong> function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.3 <strong>Optimization</strong> rout<strong>in</strong>es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271


5 Genetic algorithms 285.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.3 Support functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.3.1 Cod<strong>in</strong>g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.3.2 Cross-over . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.3.3 Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.3.4 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.4 Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.4.1 optim ga . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.4.2 optim moga, pareto filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.4.3 optim nsga . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345.4.4 optim nsga2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 Simulated Anneal<strong>in</strong>g 356.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366.4 Neighbor functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376.5 Acceptance functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386.6 Temperature laws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.7 optim sa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 LMITOOL: a Package for LMI <strong>Optimization</strong> <strong>in</strong> <strong>Scilab</strong> 417.1 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417.2 Function lmisolver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427.2.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427.2.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437.3 Function LMITOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497.3.1 Non-<strong>in</strong>teractive mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497.3.2 Interactive mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507.4 How lmisolver works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527.5 Other versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 <strong>Optimization</strong> data files 568.1 MPS files and the Quapro toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . 568.2 SIF files and the CUTEr toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . 569 <strong>Scilab</strong> <strong>Optimization</strong> Toolboxes 579.1 Quapro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579.1.1 L<strong>in</strong>ear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579.1.2 L<strong>in</strong>ear quadratic optimization . . . . . . . . . . . . . . . . . . . . . . . . . 589.2 CUTEr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599.3 The Unconstra<strong>in</strong>ed <strong>Optimization</strong> Problem Toolbox . . . . . . . . . . . . . . . . . 609.4 Other toolboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609.4.1 Interface to CONMIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609.4.2 Differential Evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622


9.4.3 FSQP Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629.4.4 IPOPT <strong>in</strong>terface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629.4.5 Interface to LIPSOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629.4.6 LPSOLVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639.4.7 NEWUOA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639.4.8 SciCobyla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639.4.9 AMPL Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639.4.10 The Optkelley Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6310 Miss<strong>in</strong>g optimization features <strong>in</strong> <strong>Scilab</strong> 65Conclusion 66Bibliography 673


Copyright c○ 2008-2010 - Consortium <strong>Scilab</strong> - Digiteo - Michael Baud<strong>in</strong>Copyright c○ 2008-2009 - Consortium <strong>Scilab</strong> - Digiteo - V<strong>in</strong>cent CouvertCopyright c○ 2008-2009 - INRIA - Serge SteerThis file must be used under the terms of the Creative Commons Attribution-ShareAlike 3.0Unported License:http://creativecommons.org/licenses/by-sa/3.04


IntroductionThis document aims at giv<strong>in</strong>g <strong>Scilab</strong> users a complete overview of optimization features <strong>in</strong> <strong>Scilab</strong>.It is written for <strong>Scilab</strong> partners needs <strong>in</strong> OMD project (http://omd.lri.fr/tiki-<strong>in</strong>dex.php). Thecore of this document is an analysis of current <strong>Scilab</strong> optimization features. In the f<strong>in</strong>al part,we give a short list of new features which would be <strong>in</strong>terest<strong>in</strong>g to f<strong>in</strong>d <strong>in</strong> <strong>Scilab</strong>. Above all theembedded functionalities of <strong>Scilab</strong> itself, some contributions (toolboxes) have been written toimprove <strong>Scilab</strong> capabilities. Many of these toolboxes are <strong>in</strong>terfaces to optimization libraries, suchas FSQP for example.In this document, we consider optimization problems <strong>in</strong> which we try to m<strong>in</strong>imize a costfunction f(x) with or without constra<strong>in</strong>ts. These problems are partly illustrated <strong>in</strong> figure 1.Several properties of the problem to solve may be taken <strong>in</strong>to account by the numerical algorithms :• The unknown may be a vector of real values or <strong>in</strong>teger values.• The number of unknowns may be small (from 1 to 10 - 100), medium (from 10 to 100 - 1000) or large (from 1 000 - 10 000 and above), lead<strong>in</strong>g to dense or sparse l<strong>in</strong>ear systems.• There may be one or several cost functions (multi-objective optimization).• The cost function may be smooth or non-smooth.• There may be constra<strong>in</strong>ts or no constra<strong>in</strong>ts.• The constra<strong>in</strong>ts may be bounds constra<strong>in</strong>ts, l<strong>in</strong>ear or non-l<strong>in</strong>ear constra<strong>in</strong>ts.• The cost function can be l<strong>in</strong>ear, quadratic or a general non l<strong>in</strong>ear function.An overview of <strong>Scilab</strong> optimization tools is showed <strong>in</strong> figure 2.In this document, we present the follow<strong>in</strong>g optimization features of <strong>Scilab</strong>.• nonl<strong>in</strong>ear optimization with the optim function,• quadratic optimization with the qpsolve function,• nonl<strong>in</strong>ear least-square optimization with the lsqrsolve function,• semidef<strong>in</strong>ite programm<strong>in</strong>g with the semidef function,• genetic algorithms with the optim_ga function,• simulated anneal<strong>in</strong>g with the optim_sa function,• l<strong>in</strong>ear matrix <strong>in</strong>equalities with the lmisolver function,5


<strong>Optimization</strong>DiscreteParametersCont<strong>in</strong>uousParametersSeveralObjectivesOneObjectiveNon SmoothSmoothWithoutConstra<strong>in</strong>tsWithConstra<strong>in</strong>tsBoundsConstra<strong>in</strong>tsL<strong>in</strong>earConstra<strong>in</strong>tsNon-l<strong>in</strong>earConstra<strong>in</strong>tsL<strong>in</strong>earObjectiveQuadraticObjectiveNon-l<strong>in</strong>earObjective1-10Unknowns10-100Unknowns>100UnknownsFigure 1: Classes of optimization problems6


Figure 2: <strong>Scilab</strong> <strong>Optimization</strong> Tools7


• read<strong>in</strong>g of MPS and SIF files with the quapro and CUTEr toolboxes.<strong>Scilab</strong> v5.2 provides the fm<strong>in</strong>search function, which a derivative-free algorithm for smallproblems. The fm<strong>in</strong>search function is based on the simplex algorithm of Nelder and Mead (notto be confused with Dantzig’s simplex for l<strong>in</strong>ear optimization). This unconstra<strong>in</strong>ed algorithmdoes not require the gradient of the cost function. It is efficient for small problems, i.e. up to10 parameters and its memory requirement is only O(n). This algorithm is known to be able tomanage ”noisy” functions, i.e. situations where the cost function is the sum of a general nonl<strong>in</strong>earfunction and a low magnitude function. The neldermead component provides three simplexbasedalgorithms which allow to solve unconstra<strong>in</strong>ed and nonl<strong>in</strong>early constra<strong>in</strong>ed optimizationproblems. It provides an object oriented access to the options. The fm<strong>in</strong>search function is, <strong>in</strong>fact, a specialized use of the neldermead component. This component is presented <strong>in</strong> <strong>in</strong> depth <strong>in</strong>[2].An analysis of optimization <strong>in</strong> <strong>Scilab</strong>, <strong>in</strong>clud<strong>in</strong>g performance tests, is presented <strong>in</strong> ”<strong>Optimization</strong>with <strong>Scilab</strong>, present and future” [3]. The follow<strong>in</strong>g is the abstract of the paper :”We present <strong>in</strong> this paper an overview of optimization algorithms available <strong>in</strong> the<strong>Scilab</strong> software.We focus on the user’s po<strong>in</strong>t of view, that is, we have to m<strong>in</strong>imize or maximize an objectivefunction and must f<strong>in</strong>d a solver suitable for the problem. The aim of this paper is to give a simplebut accurate view of what problems can be solved by <strong>Scilab</strong> and what behavior can be expectedfor those solvers. For each solver, we analyze the type of problems that it can solve as well as itsadvantages and limitations. In order to compare the respective performances of the algorithms,we use the CUTEr library, which is available <strong>in</strong> <strong>Scilab</strong>. Numerical experiments are presented,which <strong>in</strong>dicates that there is no cure-for-all solvers.”Several exist<strong>in</strong>g optimization features are not presented <strong>in</strong> this document. In particular, multiobjectiveoptimization is available <strong>in</strong> <strong>Scilab</strong> with the genetic algorithm component.The organization of this document is as follow<strong>in</strong>g.In the first chapter, we analyse the flagship of <strong>Scilab</strong> <strong>in</strong> terms of nonl<strong>in</strong>ear optimization: theoptim function. This function allows to solve nonl<strong>in</strong>ear optimization problems without constra<strong>in</strong>tsor with bound constra<strong>in</strong>ts. It provides a Quasi-Newton method, a Limited Memory BFGS algorithmand a bundle method for non-smooth functions. We analyse its features, the managementof the cost function, the l<strong>in</strong>ear algebra and the management of the memory. Then we consider thealgorithms which are used beh<strong>in</strong>d optim, depend<strong>in</strong>g on the type of algorithm and the constra<strong>in</strong>ts.In the second chapter we present the qpsolve and qp_solve functions which allows to solvequadratic problems. We describe the solvers which are used, the memory requirements and the<strong>in</strong>ternal design of the tool.The chapter 3 and 4 briefly present non-l<strong>in</strong>ear least squares problems and semidef<strong>in</strong>ite programm<strong>in</strong>g.The chapter 5 focuses on genetic algorithms. We give a tutorial example of the optim_gafunction <strong>in</strong> the case of the Rastrig<strong>in</strong> function. We also analyse the support functions which allowto configure the behavior of the algorithm and describe the algorithm which is used.The simulated anneal<strong>in</strong>g is presented <strong>in</strong> chapter 6, which gives an overview of the algorithmused <strong>in</strong> optim_sa. We present an example of use of this method and shows the convergence ofthe algorithm. Then we analyse the support functions and present the neighbor functions, theacceptance functions and the temperature laws. In the f<strong>in</strong>al section, we analyse the structure ofthe algorithm used <strong>in</strong> optim_sa.The LMITOOL module is presented <strong>in</strong> chapter 7. This tool allows to solve l<strong>in</strong>ear matrix<strong>in</strong>equalities. This chapter was written by Nikoukhah, Delebecque and Ghaoui. The syntax of the8


lmisolver function is analysed and several examples are analysed <strong>in</strong> depth.The chapter 8 focuses on optimization data files managed by <strong>Scilab</strong>, especially MPS and SIFfiles.Some optimization features are available <strong>in</strong> the form of toolboxes, the most important of whichare the Quapro, CUTEr and the Unconstra<strong>in</strong>ed <strong>Optimization</strong> Problems toolboxes. These modulesare presented <strong>in</strong> the chapter 9, along with other modules <strong>in</strong>clud<strong>in</strong>g the <strong>in</strong>terface to CONMIN, toFSQP, to LIPSOL, to LPSOLVE, to NEWUOA.The chapter 10 is devoted to miss<strong>in</strong>g optimization features <strong>in</strong> <strong>Scilab</strong>.9


Chapter 1Non-l<strong>in</strong>ear optimizationThe goal of this chapter is to present the current features of the optim primitive <strong>Scilab</strong>. Theoptim primitive allows to optimize a problem with a nonl<strong>in</strong>ear objective without constra<strong>in</strong>ts orwith bound constra<strong>in</strong>ts.In this chapter, we describe both the <strong>in</strong>ternal design of the optim primitive. We analyse <strong>in</strong>detail the management of the cost function. The cost function and its gradient can be computedus<strong>in</strong>g a <strong>Scilab</strong> function, a C function or a Fortran 77 function. The l<strong>in</strong>ear algebra componentsare analysed, s<strong>in</strong>ce they are used at many places <strong>in</strong> the algorithms. S<strong>in</strong>ce the management ofmemory is a crucial feature of optimization solvers, the current behaviour of <strong>Scilab</strong> with respectto memory is detailed here.Three non-l<strong>in</strong>ear solvers are connected to the optim primitive, namely, a BFGS Quasi-Newtonsolver, a L-BFGS solver, and a Non-Differentiable solver. In this chapter we analyse each solverand present the follow<strong>in</strong>g features :• the reference articles or reports,• the author,• the management of memory,• the l<strong>in</strong>ear algebra system, especially the algorithm name and if dense/sparse cases are taken<strong>in</strong>to account,• the l<strong>in</strong>e search method.The <strong>Scilab</strong> onl<strong>in</strong>e help is a good entry po<strong>in</strong>t for this function.1.1 Mathematical po<strong>in</strong>t of viewThe problem of the non l<strong>in</strong>ear optimization is to f<strong>in</strong>d the solution ofm<strong>in</strong> f(x)xwith bounds constra<strong>in</strong>ts or without constra<strong>in</strong>ts and with f : R n → R the cost function.10


1.2 <strong>Optimization</strong> features<strong>Scilab</strong> offers three non-l<strong>in</strong>ear optimization methods:• Quasi-Newton method with BFGS formula without constra<strong>in</strong>ts or with bound constra<strong>in</strong>ts,• Quasi-Newton with limited memory BFGS (L-BGFS) without constra<strong>in</strong>ts or with boundconstra<strong>in</strong>ts,• Bundle method for non smooth functions (half derivable functions, non-differentiable problem)without constra<strong>in</strong>ts.Problems <strong>in</strong>volv<strong>in</strong>g non l<strong>in</strong>ear constra<strong>in</strong>ts cannot be solved with the current optimizationmethods implemented <strong>in</strong> <strong>Scilab</strong>. Non smooth problems with bounds constra<strong>in</strong>ts cannot be solvedwith the methods currently implemented <strong>in</strong> <strong>Scilab</strong>.1.3 <strong>Optimization</strong> rout<strong>in</strong>esNon-l<strong>in</strong>ear optimization <strong>in</strong> <strong>Scilab</strong> is based on a subset of the Modulopt library, developed atInria. The library which is used by optim was created by the Modulopt project at INRIA anddevelopped by Bonnans, Gilbert and Lemaréchal [5].This section lists the rout<strong>in</strong>es used accord<strong>in</strong>g to the optimization method used.The follow<strong>in</strong>g is the list of solvers currently available <strong>in</strong> <strong>Scilab</strong>, and the correspond<strong>in</strong>g fortranrout<strong>in</strong>e :• ”qn” without constra<strong>in</strong>ts : a Quasi-Newton method without constra<strong>in</strong>ts, n1qn1,• ”qn” with bounds constra<strong>in</strong>ts : Quasi-Newton method with bounds constra<strong>in</strong>ts, qnbd,• ”gc” without constra<strong>in</strong>ts : a Limited memory BGFS methoud without constra<strong>in</strong>ts, n1qn3,• ”gc” with bounds constra<strong>in</strong>ts : a Limited memory BGFS with bounds constra<strong>in</strong>ts, gcbd,• ”nd” without constra<strong>in</strong>ts : a Non smooth method without constra<strong>in</strong>ts, n1fc1.1.4 The cost functionThe communication protocol used by optim is direct, that is, the cost function must be passedas a callback argument to the ”optim” primitive. The cost function must compute the objectiveand/or the gradient of the objective, depend<strong>in</strong>g on the <strong>in</strong>put <strong>in</strong>teger flag ”<strong>in</strong>d”.In the most simple use-case, the cost function is a <strong>Scilab</strong> function, with the follow<strong>in</strong>g header :[ f , g , <strong>in</strong>d ]= c o s t f ( x , <strong>in</strong>d )where ”x” is the current value of the unknown and ”<strong>in</strong>d” is the <strong>in</strong>teger flag which states if ”f”, ”g”or both are to be computed.The cost function is passed to the optimization solver as a callback, which is managed withthe fortran 77 callback system. In that case, the name of the rout<strong>in</strong>e to call back is declared as”external” <strong>in</strong> the source code. The cost function may be provided <strong>in</strong> the follow<strong>in</strong>g ways :11


• the cost function is provided as a <strong>Scilab</strong> script,• the cost function is provided as a C or fortran 77 compiled rout<strong>in</strong>e.If the cost function is a C or fortran 77 source code, the cost function can be statically ordynamically l<strong>in</strong>ked aga<strong>in</strong>st <strong>Scilab</strong>. Indeed, <strong>Scilab</strong> dynamic l<strong>in</strong>k features, such as ilib for l<strong>in</strong>k forexample, can be used to provide a compiled cost function.In the follow<strong>in</strong>g paragraph, we analyse the very <strong>in</strong>ternal aspects of the management of thecost function.This switch is managed at the gateway level, <strong>in</strong> the sci f optim rout<strong>in</strong>e, with a ”if” statement :• if the cost function is compiled, the ”foptim” symbol is passed,• if not, the ”boptim” symbol is passed.In the case where the cost function is a <strong>Scilab</strong> script, the ”boptim” rout<strong>in</strong>e performs the copy ofthe <strong>in</strong>put local arguments <strong>in</strong>to <strong>Scilab</strong> <strong>in</strong>ternal memory, calls the script, and f<strong>in</strong>ally copy back theoutput argument from <strong>Scilab</strong> <strong>in</strong>ternal memory <strong>in</strong>to local output variables. In the case where thecost function is compiled, the computation is based on function po<strong>in</strong>ters, which are managed atthe C level <strong>in</strong> optimtable.c. The optimization function is configured by the ”setfoptim” C service,which takes as argument the name of the rout<strong>in</strong>e to callback. The services implemented <strong>in</strong>AddFunctionInTable.c are used, especially the function ”AddFunctionInTable”, which takes thename of the function as <strong>in</strong>put argument and searches the correspond<strong>in</strong>g function address, be it<strong>in</strong> statically compiled libraries or <strong>in</strong> dynamically compiled libraries. This allows the optimizationsolvers to callback dynamically l<strong>in</strong>ked libraries. These names and addresses are stored <strong>in</strong> thehashmap FTab foptim, which maps function names to function po<strong>in</strong>ter. The static field foptimfoncwith type foptimf is then set to the address of the function to be called back. When theoptimization solver needs to compute the cost function, it calls the ”foptim” C void function which<strong>in</strong> returns calls the compiled cost function associated to the configured address (*foptimfonc).1.5 L<strong>in</strong>ear algebraThe l<strong>in</strong>ear algebra which is used <strong>in</strong> the ”optim” primitive is dense. Generally, the l<strong>in</strong>ear algebrais <strong>in</strong>l<strong>in</strong>ed and there is no use the BLAS API. This applies to all optimization methods, except”gcbd”. This limits the performance of the optimization, because optimized libraries like ATLAScannot not used. There is only one exception : the L-BFGS with bounds constra<strong>in</strong>ts rout<strong>in</strong>e gcbduses the ”dcopy” rout<strong>in</strong>e of the BLAS API.1.6 Management of memoryThe optimization solvers requires memory, especially to store the value of the cost function,the gradient, the descent direction, but most importantly, the approximated Hessian of the costfunction.Most of the memory is required by the approximation of the Hessian matrix. If the fullapproximated Hessian is stored, as <strong>in</strong> the BFGS quasi-Newton method, the amount of memoryis the square of the dimension of the problem O(n 2 ), where n is the size of the unknown. When12


a quasi-Newton method with limited memory is used, only a given number m of vectors of size nare stored.This memory is allocated by <strong>Scilab</strong>, <strong>in</strong>side the stack and the storage area is passed to thesolvers as an <strong>in</strong>put argument. This large storage memory is then split <strong>in</strong>to pieces like a pieceof cake by each solver to store the data. The memory system used by the fortran solvers is thefortran 77 ”assumed-size-dummy-arrays” mechanism, based on ”real arrayname(*)” statements.The management of memory is very important for large-scale problems, where n is from 100to 1000. One ma<strong>in</strong> feature of one of the L-BFGS algorithms is to limit the memory required.More precisely, the follow<strong>in</strong>g is a map from the algorithm to the memory required, as the numberof required double precision values.• Quasi-Newton BFGS ”qn” without constra<strong>in</strong>ts (n1qn1) : n(n + 13)/2,• Quasi-Newton BFGS ”qn” with bounds constra<strong>in</strong>ts (qnbd) : n(n + 1)/2 + 4n + 1,• Limited Memory BFGS ”gc” without constra<strong>in</strong>ts (n1qn3) : 4n + m(2n + 1),• Limited Memory BFGS ”gc” with bounds constra<strong>in</strong>ts (gcbd) : n(5 + 3nt) + 2nt + 1 withnt = max(1, m/3),• Non smooth method without constra<strong>in</strong>ts (n1fc1) : (n + 4)m/2 + (m + 9) ∗ m + 8 + 5n/2.Note that n1fc1 requires an additionnal 2(m + 1) array of <strong>in</strong>tegers. Simplify<strong>in</strong>g these arraysizes leads to the follow<strong>in</strong>g map, which clearly shows why Limited Memory BFGS algorithms <strong>in</strong><strong>Scilab</strong> are more suitable for large problems. This expla<strong>in</strong>s why the name ”cg” was chosen: it refersto the Conjugate Gradient method, which stores only one vector <strong>in</strong> memory. But the name ”cg”is wrongly chosen and this is why we consistently use L-BFGS to identify this algorithm.• Quasi-Newton ”qn” without constra<strong>in</strong>ts (n1qn1) : O(n 2 ),• Quasi-Newton ”qn” with bounds constra<strong>in</strong>ts (qnbd) : O(n 2 ),• Limited Memory BFGS ”gc” without constra<strong>in</strong>ts (n1qn3) : O(n),• Limited Memory BFGS ”gc” with bounds constra<strong>in</strong>ts (gcbd) : O(n),• Non smooth method without constra<strong>in</strong>ts (n1fc1) : O(n).That expla<strong>in</strong>s why L-BFGS methods associated with the ”gc” option of the optim primitiveare recommended for large-scale optimization. It is known that L-BFGS convergence may be slowfor large-scale problems (see [21], chap. 9).1.7 Quasi-Newton ”qn” without constra<strong>in</strong>ts : n1qn1The author is C. Lemarechal, 1987. There is no reference report for this solver.The follow<strong>in</strong>g is the header for the n1qn1 rout<strong>in</strong>e :13


subrout<strong>in</strong>e n1qn1 (simul,n,x,f,g,var,eps,1 mode,niter,nsim,imp,lp,zm,izs,rzs,dzs)c!butc m<strong>in</strong>imisation d une fonction reguliere sans contra<strong>in</strong>tesc!orig<strong>in</strong>ec c. lemarechal, <strong>in</strong>ria, 1987c Copyright INRIAc!methodec direction de descente calculee par une methode de quasi-newtonc recherche l<strong>in</strong>eaire de type wolfeThe follow<strong>in</strong>g is a description of the arguments of this rout<strong>in</strong>e.• simul : po<strong>in</strong>t d’entree au module de simulation (cf normes modulopt i). n1qn1 appelletoujours simul avec <strong>in</strong>dic = 4 ; le module de simulation doit se presenter sous la formesubrout<strong>in</strong>e simul(n,x, f, g, izs, rzs, dzs) et être declare en external dans le programmeappelant n1qn1.• n (e) : nombre de variables dont depend f.• x (e-s) : vecteur de dimension n ; en entree le po<strong>in</strong>t <strong>in</strong>itial ; en sortie : le po<strong>in</strong>t f<strong>in</strong>al calculepar n1qn1.• f (e-s) : scalaire ; en entree valeur de f en x (<strong>in</strong>itial), en sortie valeur de f en x (f<strong>in</strong>al).• g (e-s) : vecteur de dimension n : en entree valeur du gradient en x (<strong>in</strong>itial), en sortie valeurdu gradient en x (f<strong>in</strong>al).• var (e) : vecteur strictement positif de dimension n. amplitude de la modif souhaitee a lapremiere iteration sur x(i).une bonne valeur est 10% de la difference (en valeur absolue)avec la coordonee x(i) optimale• eps (e-s) : en entree scalaire def<strong>in</strong>it la precision du test d’arret. Le programme considereque la convergence est obtenue lorque il lui est impossible de dim<strong>in</strong>uer f en attribuant à aumo<strong>in</strong>s une coordonnée x(i) une variation superieure a eps*var(i). En sortie, eps contient lecarré de la norme du gradient en x (f<strong>in</strong>al).• mode (e) : def<strong>in</strong>it l’approximation <strong>in</strong>itiale du hessien– =1 n1qn1 l’<strong>in</strong>itialise lui-meme– =2 le hessien est fourni dans zm sous forme compressee (zm contient les colonnes dela partie <strong>in</strong>ferieure du hessien)• niter (e-s) : en entree nombre maximal d’iterations : en sortie nombre d’iterations reellementeffectuees.• nsim (e-s) : en entree nombre maximal d’appels a simul (c’est a dire avec <strong>in</strong>dic = 4). ensortie le nombre de tels appels reellement faits.• imp (e) : contrôle les messages d’impression :14


– = 0 rien n’est imprime– = 1 impressions <strong>in</strong>itiales et f<strong>in</strong>ales– = 2 une impression par iteration (nombre d’iterations, nombre d’appels a simul, valeurcourante de f).– >=3 <strong>in</strong>formations supplementaires sur les recherches l<strong>in</strong>eaires ; tres utile pour detecterles erreurs dans le gradient.• lp (e) : le numero du canal de sortie, i.e. les impressions commandees par imp sont faitespar write (lp, format).• zm : memoire de travail pour n1qn1 de dimension n*(n+13)/2.• izs,rzs,dzs memoires reservees au simulateur (cf doc)The n1qn1 solver is an <strong>in</strong>terface to the n1qn1a rout<strong>in</strong>e, which really implements the optimizationmethod. The n1qn1a file counts approximately 300 l<strong>in</strong>es. The n1qn1a rout<strong>in</strong>e is based onthe follow<strong>in</strong>g rout<strong>in</strong>es :• simul : computes the cost function,• majour : probably (there is no comment) an update of the BFGS matrix.Many algorithms are <strong>in</strong>-l<strong>in</strong>ed, especially the l<strong>in</strong>e search and the l<strong>in</strong>ear algebra.1.7.1 Management of the approximated Hessian matrixThe current BFGS implementation is based on a approximation of the Hessian [21], which is basedon Cholesky decomposition, i.e. the approximated Hessian matrix is decomposed as G = LDL T ,where D is a diagonal n × n matrix and L is a lower triangular n × n matrix with unit diagonal.To compute the descent direction, the l<strong>in</strong>ear system Gd = LDL T d = −g is solved.The memory requirements for this method is O(n 2 ) because the approximated Hessian matrixcomputed from the BFGS formula is stored <strong>in</strong> compressed form so that only the lower part ofthe approximated Hessian matrix is stored. This is why this method is not recommended forlarge-scale problems (see [21], chap.9, <strong>in</strong>troduction).The approximated hessian H ∈ R n×n is stored as the vector h ∈ R n h which has size nh =n(n + 1)/2. The matrix is stored <strong>in</strong> factored form as follow<strong>in</strong>gh = (D 11 L 21 . . . L n1 |H 21 D 22 . . . L n2 | . . . |D n−1n−1 L nn−1 |D nn ) . (1.1)Instead of a direct acces to the factors of D and L, <strong>in</strong>tegers algebra is necessary to access to thedata stored <strong>in</strong> the vector h.The algorithm presented <strong>in</strong> figure 1.1 is used to set the diagonal terms the diagonal terms of D,the diagonal matrix of the Cholesky decomposition of the approximated Hessian. The right-handside 0.01cmax of this <strong>in</strong>itialization is analysed <strong>in</strong> the next section of this document.vi215


k ← 1for i = 1 to n doh(k) = 0.01cmaxvi2k ← k + n + 1 − iend forFigure 1.1: Loop over the diagonal terms of the Cholesky decomposition of the approximatedHessianSolv<strong>in</strong>g the l<strong>in</strong>ear system of equationsThe l<strong>in</strong>ear system of equations Gd = LDL T d = −g must be solved to computed the descentdirection d ∈ R n . This direction is computed by the follow<strong>in</strong>g algorithm• compute w so that Lw = −g,• computed d so that DL T d = w.This algorithm requires O(n 2 ) operations.1.7.2 L<strong>in</strong>e searchThe l<strong>in</strong>e search is based on the algorithms developped by Lemaréchal [27]. It uses a cubic <strong>in</strong>terpolation.The Armijo condition for sufficient decrease is used <strong>in</strong> the follow<strong>in</strong>g formf(x k + αp k ) − f(x k ) ≤ c 1 α∇f T k p k (1.2)with c 1 = 0.1. The follow<strong>in</strong>g fortran source code illustrates this conditionif (fb-fa.le.0.10d+0*c*dga) go to 280where fb = f(x k + αp k ), fa = f(x k ), c = α and dga = ∇f T k p k is the local directional derivative.1.7.3 Initial Hessian matrixSeveral modes are available to compute the <strong>in</strong>itial Hessian matrix, depend<strong>in</strong>g on the value of themode variable• if mode = 1, n1qn1 <strong>in</strong>itializes the matrix by itself,• if mode = 2, the hessian is provided <strong>in</strong> compressed form, where only the lower part of thesymetric hessian matrix is stored.An additionnal mode=3 is provided but the feature is not clearly documented. In <strong>Scilab</strong>, then1qn1 rout<strong>in</strong>e is called with mode = 1 by default. In the case where a hot-restart is performed,the mode = 3 is enabled.If mode = 1 is chosen, the <strong>in</strong>itial Hessian matrix H 0 is computed by scal<strong>in</strong>g the identity matrixH 0 = Iδ (1.3)16


where δ ∈ R n is a n-vector and I is the n × n identity matrix. The scal<strong>in</strong>g vector δ ∈ R n is basedon the gradient at the <strong>in</strong>itial guess g 0 = g(x 0 ) = ∇f(x 0 ) ∈ R n and a scal<strong>in</strong>g vector v ∈ R n , givenby the userwhere c max > 0 is computed byδ i = 0.01c maxv 2 i()c max = max 1.0, maxi=1,n (|g0 i )|)(1.4)(1.5)In the <strong>Scilab</strong> <strong>in</strong>terface for optim, the scal<strong>in</strong>g vector is set to 0.1 :1.7.4 Term<strong>in</strong>ation criteriav i = 0.1, i = 1, n. (1.6)The follow<strong>in</strong>g list of parameters are taken <strong>in</strong>to account by the solver• niter, the maximum number of iterations (default value is 100),• nap, the maximum number of function evaluations (default value is 100),• epsg, the m<strong>in</strong>imum length of the search direction (default value is %eps ≈ 2.22e − 16).The other parameters epsf and epsx are not used. The term<strong>in</strong>ation condition is not basedon the gradient, as the name epsg would <strong>in</strong>dicate.The follow<strong>in</strong>g is a list of term<strong>in</strong>ation conditions which are taken <strong>in</strong>to account <strong>in</strong> the sourcecode.• The iteration is greater than the maximum.if (itr.gt.niter) go to 250• The number of function evaluations is greater than the maximum.if (nfun.ge.nsim) go to 250• The directionnal derivative is positive, so that the direction d is not a descent direction forf.if (dga.ge.0.0d+0) go to 240• The cost function set the <strong>in</strong>dic flag (the <strong>in</strong>d parameter) to 0, <strong>in</strong>dicat<strong>in</strong>g that the optimizationmust term<strong>in</strong>ate.call simul (<strong>in</strong>dic,n,xb,fb,gb,izs,rzs,dzs)[...]go to 25017


• The cost function set the <strong>in</strong>dic flag to a negative value <strong>in</strong>dicat<strong>in</strong>g that the function cannotbe evaluated for the given x. The step is reduced by a factor 10, but gets below a limit sothat the algorithm term<strong>in</strong>ates.call simul (<strong>in</strong>dic,n,xb,fb,gb,izs,rzs,dzs)[...]step=step/10.0d+0[...]if (stepbd.gt.steplb) goto 170[...]go to 250• The Armijo condition is not satisfied and step size is below a limit dur<strong>in</strong>g the l<strong>in</strong>e search.if (fb-fa.le.0.10d+0*c*dga) go to 280[...]if (step.gt.steplb) go to 270• Dur<strong>in</strong>g the l<strong>in</strong>e search, a cubic <strong>in</strong>terpolation is computed and the computed m<strong>in</strong>imum isassociated with a zero step length.if(c.eq.0.0d+0) goto 250• Dur<strong>in</strong>g the l<strong>in</strong>e search, the step length is lesser than a computed limit.if (stm<strong>in</strong>+step.le.steplb) go to 240• The rank of the approximated Hessian matrix is lesser than n after the update of theCholesky factors.if (ir.lt.n) go to 2501.7.5 An exampleThe follow<strong>in</strong>g script illustrates that the gradient may be very slow, but the algorithm cont<strong>in</strong>ues.This shows that the term<strong>in</strong>ation criteria is not based on the gradient, but on the length of thestep. The problem has two parameters so that n = 2. The cost function is the follow<strong>in</strong>gf(x) = x p 1 + x p 2 (1.7)where p ≥ 0 is an even <strong>in</strong>teger. Here we choose p = 10. The gradient of the function isg(x) = ∇f(x) = (px p−11 , px p−12 ) T (1.8)and the Hessian matrix isH(x) =( p(p − 1)xp−21 00 p(p − 1)x p−22)(1.9)18


The optimum of this optimization problem is atx ⋆ = (0, 0) T . (1.10)The follow<strong>in</strong>g <strong>Scilab</strong> script def<strong>in</strong>es the cost function, checks that the derivatives are correctlycomputed and performs an optimization. At each iteration, the norm of the gradient of the costfunction is displayed so that one can see if the algorithm term<strong>in</strong>ates when the gradient is small.function [ f , g , <strong>in</strong>d ] = myquadratic ( x , <strong>in</strong>d )p = 10i f <strong>in</strong>d == 1 | <strong>in</strong>d == 2 | <strong>in</strong>d == 4 thenf = x (1)ˆ p + x (2)ˆ p ;endi f <strong>in</strong>d == 1 | <strong>in</strong>d == 2 | <strong>in</strong>d == 4 theng ( 1 ) = p ∗ x ( 1 ) ˆ ( p−1)g ( 2 ) = p ∗ x ( 2 ) ˆ ( p−1)endi f <strong>in</strong>d == 1 thenmpr<strong>in</strong>tf ( ”| x|=%e, f=%e, | g|=%e\n” ,norm( x ) , f ,norm( g ) )endendfunctionfunction f = quadfornumdiff ( x )f = myquadratic ( x , 2 )endfunctionx0 = [ −1.2 1 . 0 ] ;[ f , g ] = myquadratic ( x0 , 4 ) ;mpr<strong>in</strong>tf ( ”Computed f (x0) = %f\n” , f ) ;mpr<strong>in</strong>tf ( ”Computed g(x0) = \n”) ; disp ( g ’ ) ;mpr<strong>in</strong>tf ( ”Expected g(x0) = \n”) ; disp ( derivative ( quadfornumdiff , x0 ’ ) )nap = 100i t e r = 100epsg = %eps[ f o p t , xopt , gradopt ] = optim ( myquadratic , x0 , . . .”ar” , nap , i t e r , epsg , imp = −1)The script produces the follow<strong>in</strong>g output.−−>[ f o p t , xopt , gradopt ] = optim ( myquadratic , x0 , . . .”ar” , nap , i t e r , epsg , imp = −1)| x |=1.562050 e +000 , f =7.191736 e +000 , | g |=5.255790 e+001| x |=1.473640 e +000 , f =3.415994 e +000 , | g |=2.502599 e+001| x |=1.098367 e +000 , f =2.458198 e +000 , | g |=2.246752 e+001| x |=1.013227 e +000 , f =1.092124 e +000 , | g |=1.082542 e+001| x |=9.340864 e −001 , f =4.817592 e −001 , | g |=5.182592 e+000[ . . . ]| x |=1.280564 e −002 , f =7.432396 e −021 , | g |=5.817126 e −018| x |=1.179966 e −002 , f =3.279551 e −021 , | g |=2.785663 e −018| x |=1.087526 e −002 , f =1.450507 e −021 , | g |=1.336802 e −018| x |=1.002237 e −002 , f =6.409611 e −022 , | g |=6.409898 e −019| x |=9.236694 e −003 , f =2.833319 e −022 , | g |=3.074485 e −019Norm o f p r o j e c t e d g r a d i e n t lower than 0.3074485D−18.19


gradopt =1 . 0D−18 ∗0.2332982 0.2002412xopt =0.0065865 0.0064757f o p t =2.833D−22One can see that the algorithm term<strong>in</strong>ates when the gradient is extremely small g(x) ≈ 10 −18 .The cost function is very near zero f(x) ≈ 10 −22 , but the solution is not accurate only up to the3d digit.This is a very difficult test case for optimization solvers. The difficulty is because the functionis extremely flat near the optimum. If the term<strong>in</strong>ation criteria was based on the gradient, thealgorithm would stop <strong>in</strong> the early iterations. Because this is not the case, the algorithm performssignificant iterations which are associated with relatively large steps.1.8 Quasi-Newton ”qn” with bounds constra<strong>in</strong>ts : qnbdThe comments state that the reference report is an INRIA report by F. Bonnans [4]. The solverqnbd is an <strong>in</strong>terface to the zqnbd rout<strong>in</strong>e. The zqnbd rout<strong>in</strong>e is based on the follow<strong>in</strong>g rout<strong>in</strong>es :• calmaj : calls majour, which updates the BFGS matrix,• proj : projects the current iterate <strong>in</strong>to the bounds constra<strong>in</strong>ts,• ajour : probably (there is no comment) an update of the BFGS matrix,• rlbd : l<strong>in</strong>e search method with bound constra<strong>in</strong>ts,• simul : computes the cost functionThe rlbd rout<strong>in</strong>e is documented as us<strong>in</strong>g an extrapolation method to computed a range for theoptimal t parameter. The range is then reduced depend<strong>in</strong>g on the situation by :• a dichotomy method,• a l<strong>in</strong>ear <strong>in</strong>terpolation,• a cubic <strong>in</strong>terpolation.The stopp<strong>in</strong>g criteria is commented as ”an extension of the Wolfe criteria”. The l<strong>in</strong>ear algebra doesnot use the BLAS API. It is <strong>in</strong>-l<strong>in</strong>ed, so that connect<strong>in</strong>g the BLAS may be difficult. The memoryrequirements for this method are O(n 2 ), which shows why this method is not recommended forlarge-scale problems (see [21], chap.9, <strong>in</strong>troduction).1.9 L-BFGS ”gc” without constra<strong>in</strong>ts : n1qn3The comments <strong>in</strong> this solver are clearly written. The authors are Jean Charles Gilbert, ClaudeLemarechal, 1988. The BFGS update is based on the article [35]. The solver n1qn3 is an <strong>in</strong>terfaceto the n1qn3a rout<strong>in</strong>e. The architecture is clear and the source code is well commented. Then1qn3a rout<strong>in</strong>e is based on the follow<strong>in</strong>g rout<strong>in</strong>es :20


1.11 Non smooth method without constra<strong>in</strong>ts : n1fc1This rout<strong>in</strong>e is probably due to Lemaréchal, who is an expert of this topic. References for thisalgorithm <strong>in</strong>clude the ”Part II, Nonsmooth optimization” <strong>in</strong> [5], and the <strong>in</strong>-depth presentation <strong>in</strong>[18, 19].The n1fc1 solver is an <strong>in</strong>terface to the n1fc1a rout<strong>in</strong>e, which really implements the optimizationmethod. The n1fc1a rout<strong>in</strong>e is based on the follow<strong>in</strong>g rout<strong>in</strong>es :• simul : computes the cost function,• fprf2 : computes the direction,• frdf1 : reduction du faisceau• nlis2 : l<strong>in</strong>e search,• prosca : performs a vector x vector scalar product.It is designed for functions which have a non-cont<strong>in</strong>uous derivative (e.g. the objective function isthe maximum of several cont<strong>in</strong>ously differentiable functions).22


Chapter 2Quadratic optimizationQuadratic problems can be solved with the qpsolve <strong>Scilab</strong> macro and the qp_solve <strong>Scilab</strong> primitive.In this chapter, we presents these two primitives, which are meant to be a replacement forthe former Quapro solver (which has be transformed <strong>in</strong>to a <strong>Scilab</strong> toolbox). We especially analysethe management of the l<strong>in</strong>ear algebra as well as the memory requirements of these solvers.2.1 Mathematical po<strong>in</strong>t of viewThis k<strong>in</strong>d of optimization is the m<strong>in</strong>imization of function f(x) withunder the constra<strong>in</strong>ts :2.2 qpsolvef(x) = 1 2 xT Qx + p T xC T 1 x = b 1 (2.1)C T 2 x ≥ b 2 (2.2)The <strong>Scilab</strong> function qpsolve is a solver for quadratic problems when Q is symmetric positivedef<strong>in</strong>ite.The qpsolve function is a <strong>Scilab</strong> macro which aims at provid<strong>in</strong>g the same <strong>in</strong>terface (that is,the same <strong>in</strong>put/output arguments) as the quapro solver.For more details about this solver, please refer to <strong>Scilab</strong> onl<strong>in</strong>e help for qpsolveThe qpsolve <strong>Scilab</strong> macro is based on the work by Berw<strong>in</strong> A Turlach from The University ofWestern Australia, Crawley [39]. The solver is implemented <strong>in</strong> Fortran 77. This rout<strong>in</strong>e uses theGoldfarb/Idnani algorithm [11, 12].The constra<strong>in</strong>ts matrix can be dense or sparse.The qpsolve macro calls the qp_solve compiled primitive. The <strong>in</strong>ternal source code forqpsolve manages the equality and <strong>in</strong>equality constra<strong>in</strong>ts so that it can be processed by theqp_solve primitive.(2.3)23


2.3 qp solveThe qp_solve compiled primitive is an <strong>in</strong>terface for the fortran 77 solver. The <strong>in</strong>terface is implemented<strong>in</strong> the C source code sci qp solve.c. Depend<strong>in</strong>g on the constra<strong>in</strong>ts matrix, a dense orsparse solver is used :• If the constra<strong>in</strong>ts matrix C is dense, the qpgen2 fortran 77 rout<strong>in</strong>e is used. The qpgen2rout<strong>in</strong>e is the orig<strong>in</strong>al, unmodified algorithm which was written by Turlach (the orig<strong>in</strong>alname was solve.QP.f)• If the constra<strong>in</strong>ts matrix C is a <strong>Scilab</strong> sparse matrix, the qpgen1sci rout<strong>in</strong>e is called. Thisrout<strong>in</strong>e is a modification of the orig<strong>in</strong>al rout<strong>in</strong>e qpgen1, <strong>in</strong> order to adapt to the specific<strong>Scilab</strong> sparse matrices storage.2.4 Memory requirementsSuppose that n is the dimension of the quadratic matrix Q and m is the sum of the number ofequality constra<strong>in</strong>ts me and <strong>in</strong>equality constra<strong>in</strong>ts md. Then, the temporary work array which isallocated <strong>in</strong> the primitive has the sizer = m<strong>in</strong>(n, m), (2.4)lw = 2n + r(r + 5)/2 + 2m + 1. (2.5)This temporary array is de-allocated when the qpsolve primitive returns.This formulae may be simplified <strong>in</strong> the follow<strong>in</strong>g cases :• if n ≫ m, that is the number of constra<strong>in</strong>ts m is negligible with respect to the number ofunknowns n, then the memory required is O(n),• if m ≫ n, that is the number of unknowns n is negligible with respect to the number ofconstra<strong>in</strong>ts m, then the memory required is O(m),• if m = n, then the memory required is O(n 2 ).2.5 Internal designThe orig<strong>in</strong>al Goldfarb/Idnani algorithm [11, 12] was designed to solve the follow<strong>in</strong>g m<strong>in</strong>imizationproblem:wherem<strong>in</strong> −d T x + 1x 2 xT DxA T 1 x = b 1 (2.6)A T 2 x >= b 2 (2.7)where the matrix D is assumed to be symmetric positive def<strong>in</strong>ite. It was considered as a build<strong>in</strong>gblock for a Sequential Quadratic Programm<strong>in</strong>g solver. The orig<strong>in</strong>al package provides two rout<strong>in</strong>es :24


• solve.QP.f conta<strong>in</strong><strong>in</strong>g rout<strong>in</strong>e qpgen2 which implements the algorithm for dense matrices,• solve.QP.compact.f conta<strong>in</strong><strong>in</strong>g rout<strong>in</strong>e qpgen1 which implements the algorithm for sparsematrices.25


Chapter 3Non-l<strong>in</strong>ear least square3.1 Mathematical po<strong>in</strong>t of viewThe problem of the non l<strong>in</strong>ear least-quare optimization is to f<strong>in</strong>d the solution of∑m<strong>in</strong> f(x) 2xwith bounds constra<strong>in</strong>ts or without constra<strong>in</strong>ts and with f : R n → R m the cost function.x3.2 <strong>Scilab</strong> function<strong>Scilab</strong> function called lsqrsolve is designed for the m<strong>in</strong>imization of the sum of the squares of nonl<strong>in</strong>earfunctions us<strong>in</strong>g a Levenberg-Marquardt algorithm. For more details about this function,please refer to <strong>Scilab</strong> onl<strong>in</strong>e help3.3 <strong>Optimization</strong> rout<strong>in</strong>es<strong>Scilab</strong> lsqrsolve function is based on the rout<strong>in</strong>es lmdif and lmder of the library M<strong>in</strong>pack (ArgonneNational Laboratory).26


Chapter 4Semidef<strong>in</strong>ite programm<strong>in</strong>g4.1 Mathematical po<strong>in</strong>t of viewThis k<strong>in</strong>d of optimization is the m<strong>in</strong>imization of f(x) = c T x under the constra<strong>in</strong>t:F 0 + x 1 F 1 + ... + x m F m ≥ 0 (4.1)or its dual problem, the maximization or −T race(F 0 , Z) under the constra<strong>in</strong>ts:T race(F i , Z) = c i , i = 1, ..., m (4.2)Z ≥ 0 (4.3)4.2 <strong>Scilab</strong> functionThe <strong>Scilab</strong> function called semidef is designed for this k<strong>in</strong>d of optimization problems. For moredetails about this function, please refer to <strong>Scilab</strong> onl<strong>in</strong>e help4.3 <strong>Optimization</strong> rout<strong>in</strong>es<strong>Scilab</strong> semidef function is based on a rout<strong>in</strong>e from L. Vandenberghe and Stephen Boyd.27


Chapter 5Genetic algorithms5.1 IntroductionGenetic algorithms are search algorithms based on the mechanics on natural selection and naturalgenetics [17, 29]. Genetic algorithms have been <strong>in</strong>troduced <strong>in</strong> <strong>Scilab</strong> v5 thanks to a work by YannCollette [9]. The solver is made of <strong>Scilab</strong> macros, which enables a high-level programm<strong>in</strong>g modelfor this optimization solver.The problems solved by the current genetic algorithms <strong>in</strong> <strong>Scilab</strong> are the follow<strong>in</strong>g :• m<strong>in</strong>imization of a cost function with bound constra<strong>in</strong>ts,• multi-objective non l<strong>in</strong>ear m<strong>in</strong>imization with bound constra<strong>in</strong>ts.Genetic algorithms are different from more normal optimization and search procedures <strong>in</strong> fourways :• GAs work with a cod<strong>in</strong>g of the parameter set, not the parameters themselves,• GAs search from a population of po<strong>in</strong>ts, not a s<strong>in</strong>gle po<strong>in</strong>t,• GAs use payoff (objective function) <strong>in</strong>formation, not derivativess or other auxiliary knowledge,• GAs use probabilistic transition rules, not determ<strong>in</strong>istic rules.A simple genetic algorithm that yields good results <strong>in</strong> many practical problems is composedof three operators [17] :• reproduction,• cross-over,• mutation.Many articles on this subject have been collected by Carlos A. Coello Coello on his website[7]. A brief <strong>in</strong>troduction to GAs is done <strong>in</strong> [44].The GA macros are based on the ”parameters” <strong>Scilab</strong> module for the management of the(many) optional parameters.28


5.2 ExampleIn the current section, we give an example of the user of the GA algorithms.The follow<strong>in</strong>g is the def<strong>in</strong>ition of the Rastrig<strong>in</strong> function.function Res = m<strong>in</strong>_bd_rastrig<strong>in</strong>()Res = [-1 -1]’;endfunctionfunction Res = max_bd_rastrig<strong>in</strong>()Res = [1 1]’;endfunctionfunction Res = opti_rastrig<strong>in</strong>()Res = [0 0]’;endfunctionfunction y = rastrig<strong>in</strong>(x)y = x(1)^2+x(2)^2-cos(12*x(1))-cos(18*x(2));endfunctionThis cost function is then def<strong>in</strong>ed with the generic name ”f”. Other algorithmic parameters,such as the size of the population, are def<strong>in</strong>ed <strong>in</strong> the follow<strong>in</strong>g sample <strong>Scilab</strong> script.func = ’rastrig<strong>in</strong>’;deff(’y=f(x)’,’y = ’+func+’(x)’);PopSize = 100;Proba_cross = 0.7;Proba_mut = 0.1;NbGen = 10;NbCouples = 110;Log = %T;nb_disp = 10;pressure = 0.05;Genetic Algorithms require many sett<strong>in</strong>gs, which are cleanly handled by the ”parameters”module. This module provides the nit_param function, which returns a new, empty, set of parameters.The add_param function allows to set <strong>in</strong>dividual named parameters, which are configurewith key-value pairs.1 ga params = <strong>in</strong>it param ( ) ;2 // Parameters to adapt to the shape of the optimization problem3 ga params = add param ( ga params , ’m<strong>in</strong>bound ’ , eval ( ’m<strong>in</strong> bd ’+func+’ () ’ ) ) ;4 ga params = add param ( ga params , ’maxbound ’ , eval ( ’max bd ’+func+’ () ’ ) ) ;5 ga params = add param ( ga params , ’ dimension ’ , 2 ) ;6 ga params = add param ( ga params , ’ beta ’ , 0 ) ;7 ga params = add param ( ga params , ’ delta ’ , 0 . 1 ) ;8 // Parameters to f<strong>in</strong>e tune the Genetic algorithm .9 ga params = add param ( ga params , ’ <strong>in</strong>it func ’ , i n i t g a d e f a u l t ) ;10 ga params = add param ( ga params , ’ crossover func ’ , c r o s s o v e r g a d e f a u l t ) ;11 ga params = add param ( ga params , ’ mutation func ’ , m u t a t i o n g a d e f a u l t ) ;12 ga params = add param ( ga params , ’ codage func ’ , c o d i n g g a i d e n t i t y ) ;29


13 ga params = add param ( ga params , ’ selection func ’ , s e l e c t i o n g a e l i t i s t ) ;14 ga params = add param ( ga params , ’ nb couples ’ , NbCouples ) ;15 ga params = add param ( ga params , ’ pressure ’ , p r e s s u r e ) ;The optim_ga function search a population solution of a s<strong>in</strong>gle-objective problem with boundconstra<strong>in</strong>ts.1 [ pop opt , fobj pop opt , p o p i n i t , f o b j p o p i n i t ] = . . .2 optim ga ( f , PopSize , NbGen , Proba mut , Proba cross , Log , ga params ) ;The follow<strong>in</strong>g are the messages which are displayed <strong>in</strong> the <strong>Scilab</strong> console :optim_ga: Initialization of the populationoptim_ga: iteration 1 / 10 - m<strong>in</strong> / max value found = -1.682413 / 0.081632optim_ga: iteration 2 / 10 - m<strong>in</strong> / max value found = -1.984184 / -0.853613optim_ga: iteration 3 / 10 - m<strong>in</strong> / max value found = -1.984184 / -1.314217optim_ga: iteration 4 / 10 - m<strong>in</strong> / max value found = -1.984543 / -1.513463optim_ga: iteration 5 / 10 - m<strong>in</strong> / max value found = -1.998183 / -1.691332optim_ga: iteration 6 / 10 - m<strong>in</strong> / max value found = -1.999551 / -1.871632optim_ga: iteration 7 / 10 - m<strong>in</strong> / max value found = -1.999977 / -1.980356optim_ga: iteration 8 / 10 - m<strong>in</strong> / max value found = -1.999979 / -1.994628optim_ga: iteration 9 / 10 - m<strong>in</strong> / max value found = -1.999989 / -1.998123optim_ga: iteration 10 / 10 - m<strong>in</strong> / max value found = -1.999989 / -1.999534The <strong>in</strong>itial and f<strong>in</strong>al populations for this simulation are shown <strong>in</strong> 5.1.The follow<strong>in</strong>g script is a loop over the optimum <strong>in</strong>dividuals of the population.1 pr<strong>in</strong>tf ( ’ Genetic Algorithm : %d po<strong>in</strong>ts from pop opt\n ’ , nb disp ) ;2 for i =1: nb disp3 pr<strong>in</strong>tf ( ’ Individual %d: x(1) = %f x(2) = %f −> f = %f\n ’ , . . .4 i , pop opt ( i ) ( 1 ) , pop opt ( i ) ( 2 ) , f o b j p o p o p t ( i ) ) ;5 endThe previous script make the follow<strong>in</strong>g l<strong>in</strong>es appear <strong>in</strong> the <strong>Scilab</strong> console.Individual 1: x(1) = -0.000101 x(2) = 0.000252 -> f = -1.999989Individual 2: x(1) = -0.000118 x(2) = 0.000268 -> f = -1.999987Individual 3: x(1) = 0.000034 x(2) = -0.000335 -> f = -1.999982Individual 4: x(1) = -0.000497 x(2) = -0.000136 -> f = -1.999979Individual 5: x(1) = 0.000215 x(2) = -0.000351 -> f = -1.999977Individual 6: x(1) = -0.000519 x(2) = -0.000197 -> f = -1.999974Individual 7: x(1) = 0.000188 x(2) = -0.000409 -> f = -1.999970Individual 8: x(1) = -0.000193 x(2) = -0.000427 -> f = -1.999968Individual 9: x(1) = 0.000558 x(2) = 0.000260 -> f = -1.999966Individual 10: x(1) = 0.000235 x(2) = -0.000442 -> f = -1.9999645.3 Support functionsIn this section, we analyze the GA services to configure a GA computation.30


Figure 5.1: Optimum of the Rastrig<strong>in</strong> function – Initial population is <strong>in</strong> red, Optimum populationis accumulated on the blue dot31


5.3.1 Cod<strong>in</strong>gThe follow<strong>in</strong>g is the list of cod<strong>in</strong>g functions available <strong>in</strong> <strong>Scilab</strong>’s GA :• cod<strong>in</strong>g_ga_b<strong>in</strong>ary : A function which performs conversion between b<strong>in</strong>ary and cont<strong>in</strong>uousrepresentation• cod<strong>in</strong>g_ga_identity : A ”no-operation” conversion functionThe user may configure the GA parameters so that the algorithm uses a customized cod<strong>in</strong>gfunction.5.3.2 Cross-overThe crossover function is used when mates have been computed, based on the Wheel algorithm :the crossover algorithm is a loop over the couples, which modifies both elements of each couple.The follow<strong>in</strong>g is the list of crossover functions available <strong>in</strong> <strong>Scilab</strong> :• crossover_ga_default : A crossover function for cont<strong>in</strong>uous variable functions.• crossover_ga_b<strong>in</strong>ary : A crossover function for b<strong>in</strong>ary code5.3.3 SelectionThe selection function is used <strong>in</strong> the loop over the generations, when the new population iscomputed by process<strong>in</strong>g a selection over the <strong>in</strong>dividuals.The follow<strong>in</strong>g is the list of selection functions available <strong>in</strong> <strong>Scilab</strong> :• selection_ga_random : A function which performs a random selection of <strong>in</strong>dividuals. Weselect pop size <strong>in</strong>dividuals <strong>in</strong> the set of parents and childs <strong>in</strong>dividuals at random.• selection_ga_elitist : An ’elitist’ selection function. We select the best <strong>in</strong>dividuals <strong>in</strong>the set of parents and childs <strong>in</strong>dividuals.5.3.4 InitializationThe <strong>in</strong>itialization function returns a population as a list made of ”pop size”<strong>in</strong>dividuals. The <strong>Scilab</strong>macro <strong>in</strong>it_ga_default computes this population by perform<strong>in</strong>g a randomized discretization ofthe doma<strong>in</strong> def<strong>in</strong>ed by the bounds as m<strong>in</strong>imum and maximum arrays. This randomization isbased on the <strong>Scilab</strong> primitive rand.5.4 SolversIn this section, we analyze the 4 GA solvers which are available <strong>in</strong> <strong>Scilab</strong> :• optim_ga : flexible genetic algorithm• optim_moga : multi-objective genetic algorithm• optim_nsga : multi-objective Niched Shar<strong>in</strong>g Genetic Algorithm32


• optim_nsga2 : multi-objective Niched Shar<strong>in</strong>g Genetic Algorithm version 2While optim_ga is designed for one objective, the 3 other solvers are designed for multiobjectiveoptimization.5.4.1 optim gaThe <strong>Scilab</strong> macro optim_ga implements a Genetic Algorithm to f<strong>in</strong>d the solution of an optimizationproblem with one objective function and bound constra<strong>in</strong>ts.The follow<strong>in</strong>g is an overview of the steps <strong>in</strong> the GA algorithm.• process<strong>in</strong>g of <strong>in</strong>put argumentsIn the case where the <strong>in</strong>put cost function is a list, one def<strong>in</strong>es the ”hidden” function _ga_fwhich computes the cost function. If the <strong>in</strong>put cost function is a regular <strong>Scilab</strong> function,the ”hidden” function _ga_f simply encapsulate the <strong>in</strong>put function.• <strong>in</strong>itializationOne computes the <strong>in</strong>itial population with the <strong>in</strong>it_func callback function (the default valuefor <strong>in</strong>it_func is <strong>in</strong>it_ga_default)• cod<strong>in</strong>gOne encodes the <strong>in</strong>itial population with the codage_func callback function (default : cod<strong>in</strong>g_ga_ide• evolutionary algorithm as a loop over the generations• decod<strong>in</strong>gOne decodes the optimum population back to the orig<strong>in</strong>al variable systemThe loop over the generation is made of the follow<strong>in</strong>g steps.• reproduction : two list of children populations are computed, based on a randomized Wheel,• crossover : the two populations are processed through the crossover_func callback function(default : crossover_ga_default)• mutation : the two populations are processed throught the mutation_func callback function(default : mutation_ga_default)• computation of cost functions : the _ga_f function is called to compute the fitness for all<strong>in</strong>dividuals of the two populations• selection : the new generation is computed by process<strong>in</strong>g the two populations through theselection_func callback function (default : selection_ga_elitist)5.4.2 optim moga, pareto filterThe optim_moga function is a multi-objective genetic algorithm. The method is based on [15].The function pareto_filter extracts non dom<strong>in</strong>ated solution from a set.33


5.4.3 optim nsgaThe optim_nsga function is a multi-objective Niched Shar<strong>in</strong>g Genetic Algorithm. The method isbased on [38].5.4.4 optim nsga2The function optim_nsga2 is a multi-objective Niched Shar<strong>in</strong>g Genetic Algorithm. The methodis based on [14].34


Chapter 6Simulated Anneal<strong>in</strong>gIn this document, we describe the Simulated Anneal<strong>in</strong>g optimization methods, a new featureavailable <strong>in</strong> <strong>Scilab</strong> v5 .6.1 IntroductionSimulated anneal<strong>in</strong>g (SA) is a generic probabilistic meta-algorithm for the global optimizationproblem, namely locat<strong>in</strong>g a good approximation to the global optimum of a given function <strong>in</strong> alarge search space. It is often used when the search space is discrete (e.g., all tours that visit agiven set of cities) [43].Genetic algorithms have been <strong>in</strong>troduced <strong>in</strong> <strong>Scilab</strong> v5 thanks to the work by Yann Collette[9].The current Simulated Anneal<strong>in</strong>g solver aims at f<strong>in</strong>d<strong>in</strong>g the solution ofm<strong>in</strong> f(x)xwith bounds constra<strong>in</strong>ts and with f : R n → R the cost function.Reference books on the subject are [25, 26, 13].6.2 OverviewThe solver is made of <strong>Scilab</strong> macros, which enables a high-level programm<strong>in</strong>g model for this optimizationsolver. The GA macros are based on the ”parameters”<strong>Scilab</strong> module for the managementof the (many) optional parameters.To use the SA algorithm, one must perform the follow<strong>in</strong>g steps :• configure the parameters with calls to ”<strong>in</strong>it param” and ”add param” especially,– the neighbor function,– the acceptance function,– the temperature law,• compute an <strong>in</strong>itial temperature with a call to ”compute <strong>in</strong>itial temp”• f<strong>in</strong>d an optimum by us<strong>in</strong>g the ”optim sa” solver35


6.3 ExampleThe follow<strong>in</strong>g example is extracted from the SA examples. The Rastrig<strong>in</strong> funct<strong>in</strong> is used as anexample of a dimension 2 problem because it has many local optima but only one global optimum.1 //2 // Rastrig<strong>in</strong> function3 //4 function Res = m i n b d r a s t r i g i n ( )5 Res = [−1 −1] ’;6 endfunction7 function Res = m a x b d r a s t r i g i n ( )8 Res = [ 1 1 ] ’ ;9 endfunction10 function Res = o p t i r a s t r i g i n ( )11 Res = [ 0 0 ] ’ ;12 endfunction13 function y = r a s t r i g i n ( x )14 y = x(1)ˆ2+x(2)ˆ2 − cos (12∗ x(1)) − cos (18∗ x ( 2 ) ) ;15 endfunction16 //17 // Set parameters18 //19 func = ’ rastrig<strong>in</strong> ’ ;20 P roba s tart = 0 . 8 ;21 I t i n t e r n = 1000;22 I t e x t e r n = 3 0 ;23 I t P r e = 1 00;24 M<strong>in</strong> = eval ( ’m<strong>in</strong> bd ’+func+’ () ’ ) ;25 Max = eval ( ’max bd ’+func+’ () ’ ) ;26 x0 = (Max − M<strong>in</strong> ) . ∗ rand( size (M<strong>in</strong> , 1 ) , size (M<strong>in</strong> , 2 ) ) + M<strong>in</strong> ;27 deff ( ’y=f (x) ’ , ’y=’+func+’ (x) ’ ) ;28 //29 // Simulated Anneal<strong>in</strong>g with default parameters30 //31 pr<strong>in</strong>tf ( ’SA: geometrical decrease temperature law\n ’ ) ;3233 sa params = <strong>in</strong>it param ( ) ;34 sa params = add param ( sa params , ’ m<strong>in</strong> delta ’ , −0.1∗(Max−M<strong>in</strong> ) ) ;35 sa params = add param ( sa params , ’ max delta ’ , 0 . 1 ∗ (Max−M<strong>in</strong> ) ) ;36 sa params = add param ( sa params , ’ neigh func ’ , n e i g h f u n c d e f a u l t ) ;37 sa params = add param ( sa params , ’ accept func ’ , a c c e p t f u n c d e f a u l t ) ;38 sa params = add param ( sa params , ’temp law ’ , temp law default ) ;39 sa params = add param ( sa params , ’m<strong>in</strong> bound ’ ,M<strong>in</strong> ) ;40 sa params = add param ( sa params , ’max bound ’ ,Max ) ;4142 T0 = c o m p u t e i n i t i a l t e m p ( x0 , f , Proba start , It Pre , sa params ) ;43 pr<strong>in</strong>tf ( ’ I n i t i a l temperature T0 = %f\n ’ , T0 ) ;4445 [ x opt , f opt , s a m e a n l i s t , s a v a r l i s t , t e m p l i s t ] = . . .36


46 optim sa ( x0 , f , I t e x t e r n , I t i n t e r n , T0 , Log = %T, sa params ) ;4748 pr<strong>in</strong>tf ( ’ optimal solution :\n ’ ) ; disp ( x opt ) ;49 pr<strong>in</strong>tf ( ’ value of the objective function = %f\n ’ , f o p t ) ;5051 s c f ( ) ;52 drawlater ;53 subplot ( 2 , 1 , 1 ) ;54 x t i t l e ( ’ Geometrical anneal<strong>in</strong>g ’ , ’ Iteration ’ , ’Mean / Variance ’ ) ;55 t = 1 : length ( s a m e a n l i s t ) ;56 plot ( t , s a m e a n l i s t , ’ r ’ , t , s a v a r l i s t , ’g ’ ) ;57 legend ( [ ’Mean’ , ’ Variance ’ ] ) ;58 subplot ( 2 , 1 , 2 ) ;59 x t i t l e ( ’Temperature evolution ’ , ’ Iteration ’ , ’Temperature ’ ) ;60 for i =1: length ( t )−161 plot ( [ t ( i ) t ( i +1)] , [ t e m p l i s t ( i ) t e m p l i s t ( i ) ] , ’k−’ ) ;62 end63 drawnow;After some time, the follow<strong>in</strong>g messages appear <strong>in</strong> the <strong>Scilab</strong> console.optimal solution:- 0.0006975- 0.0000935value of the objective function = -1.999963The figure 6.1 presents the evolution of Mean, Variance and Temperature depend<strong>in</strong>g on theiteration.6.4 Neighbor functionsIn the simulated anneal<strong>in</strong>g algorithm, a neighbour function is used <strong>in</strong> order to explore the doma<strong>in</strong>[44].The prototype of a neighborhood function is the follow<strong>in</strong>g :1 function x neigh = n e i g h f u n c d e f a u l t ( x current , T, param )where:• x current represents the current po<strong>in</strong>t,• T represents the current temperature,• param is a list of parameters.The follow<strong>in</strong>g is a list of the neighbour functions available <strong>in</strong> the SA context :• neigh_func_default : SA function which computes a neighbor of a given po<strong>in</strong>t. Forexample, for a cont<strong>in</strong>uous vector, a neighbor will be produced by add<strong>in</strong>g some noise to eachcomponent of the vector. For a b<strong>in</strong>ary str<strong>in</strong>g, a neighbor will be produced by chang<strong>in</strong>g onebit from 0 to 1 or from 1 to 0.37


Figure 6.1: Convergence of the simulated anneal<strong>in</strong>g algorithm• neigh_func_csa : The classical neighborhood relationship for the simulated anneal<strong>in</strong>g.The neighbors distribution is a gaussian distribution which is more and more peaked as thetemperature decrease.• neigh_func_fsa : The Fast Simulated Anneal<strong>in</strong>g neghborhood relationship. The correspond<strong>in</strong>gdistribution is a Cauchy distribution which is more and more peaked as the temperaturedecreases.• neigh_func_vfsa : The Very Fast Simulated Anneal<strong>in</strong>g neighborhood relationship. Thisdistribution is more and more peaked as the temperature decreases.6.5 Acceptance functionsThere exist several k<strong>in</strong>d of simulated anneal<strong>in</strong>g optimization methods:• the Fast Simulated Anneal<strong>in</strong>g,• the simulated anneal<strong>in</strong>g based on metropolis-hast<strong>in</strong>g acceptance function,• etc...To implement these various simulated anneal<strong>in</strong>g optimization methods, you only need tochange the acceptance function. For common optimization, you need not to change the defaultacceptance function.The follow<strong>in</strong>g is a list of acceptance functions available <strong>in</strong> <strong>Scilab</strong> SAs :38


• accept_func_default : is the default acceptance function, based on the exponential function(level = exp − F )neigh − F currentT• accept_func_vfsa : is the Very Fast Simulated Anneal<strong>in</strong>g function, def<strong>in</strong>ed by :Level =(1 + exp1− Fcurrent−F neighT)6.6 Temperature lawsIn the simulated anneal<strong>in</strong>g algorithm, a temperature law is used <strong>in</strong> a statistical criteria for theupdate of the optimum [44]. If the new (neighbor) po<strong>in</strong>t improves the current optimum, theupdate is done with the new po<strong>in</strong>t replac<strong>in</strong>g the old optimum. If not, the update may still beprocessed, provided that a statistical criteria is satisfied. The statistical law decreases while theiterations are processed.There are 5 temperature laws available <strong>in</strong> the SA context :• temp_law_default : A SA function which computes the temperature of the next temperaturestage• temp_law_csa : The classical temperature decrease law, the one for which the convergenceof the simulated anneal<strong>in</strong>g has been proven• temp_law_fsa : The Szu and Hartley Fast simulated anneal<strong>in</strong>g• temp_law_huang : The Huang temperature decrease law for the simulated anneal<strong>in</strong>g• temp_law_vfsa : This function implements the Very Fast Simulated Anneal<strong>in</strong>g from L.Ingber6.7 optim saThe optim_sa macro implements the simulated anneal<strong>in</strong>g solver. It allows to f<strong>in</strong>d the solution ofan m<strong>in</strong>imization problem with bound constra<strong>in</strong>ts.It is based on an iterative update of two po<strong>in</strong>ts :• the current po<strong>in</strong>t is updated by tak<strong>in</strong>g <strong>in</strong>to account the neighbour function and the acceptancecriterium,• the best po<strong>in</strong>t is the po<strong>in</strong>t which achieved the m<strong>in</strong>imum of the objective function over theiterations.While the current po<strong>in</strong>t is used <strong>in</strong>ternally to explore the doma<strong>in</strong>, only the best po<strong>in</strong>t is returnedas the algorithm output.The algorithm is based on the follow<strong>in</strong>g steps, which <strong>in</strong>clude a ma<strong>in</strong>, external loop over thetemperature decreases, and an <strong>in</strong>ternal loop.39


• process<strong>in</strong>g of <strong>in</strong>put arguments,• <strong>in</strong>itialization,• loop over the number of temperature decreases.For each iteration over the temperature decreases, the follow<strong>in</strong>g steps are processed.• loop over <strong>in</strong>ternal iterations, with constant temperature,• if history is required by user, store the temperature, the x iterates, the values of f,• update the temperature with the temperature law.The <strong>in</strong>ternal loop allows to explore the doma<strong>in</strong> and is based on the neighbour function. It isbased on the follow<strong>in</strong>g steps.• compute a neighbour of the current po<strong>in</strong>t,• compute the objective function for that neighbour• if the objective decreases or if the acceptance criterium is true, then overwrite the currentpo<strong>in</strong>t with the neighbour• if the cost of the best po<strong>in</strong>t is greater than the cost of the current po<strong>in</strong>t, overwrite the bestpo<strong>in</strong>t by the current po<strong>in</strong>t.40


Chapter 7LMITOOL: a Package for LMI<strong>Optimization</strong> <strong>in</strong> <strong>Scilab</strong>R. Nikoukhah Ram<strong>in</strong>e.Nikoukhah@<strong>in</strong>ria.frF. Delebecque Francois.Delebecque@<strong>in</strong>ria.frL. El Ghaoui ENSTA, 32, Bvd. Victor, 75739 Paris, France. Internet: elghaoui@ensta.fr.Research supported <strong>in</strong> part by DRET under contract 92017-BC14This chapter describes a user-friendly <strong>Scilab</strong> package, and <strong>in</strong> particular its two ma<strong>in</strong> functionslmisolver and lmitool for solv<strong>in</strong>g L<strong>in</strong>ear Matrix Inequalities problems. This package uses <strong>Scilab</strong>function semidef, an <strong>in</strong>terface to the program Semidef<strong>in</strong>ite Programm<strong>in</strong>g SP (Copyright c○1994by Lieven Vandenberghe and Stephen Boyd) distributed with <strong>Scilab</strong>.7.1 PurposeMany problems <strong>in</strong> systems and control can be formulated as follows (see [6]):⎧⎨ m<strong>in</strong>imize f(X{ 1 , . . . , X M )Σ :Gi (X⎩ subject to1 , . . . , X M ) = 0, i = 1, 2, ..., p,H j (X 1 , . . . , X M ) ≥ 0, j = 1, 2, .., q.where• X 1 , . . . , X M are unknown real matrices, referred to as the unknown matrices,• f is a real l<strong>in</strong>ear scalar function of the entries of the unknown matrices X 1 , . . . , X M ; it isreferred to as the objective function,• G i ’s are real matrices with entries which are aff<strong>in</strong>e functions of the entries of the unknownmatrices, X 1 , . . . , X M ; they are referred to as “L<strong>in</strong>ear Matrix Equality” (LME) functions,• H j ’s are real symmetric matrices with entries which are aff<strong>in</strong>e functions of the entries of theunknown matrices X 1 , . . . , X M ; they are referred to as “L<strong>in</strong>ear Matrix Inequality” (LMI)functions. (In this report, the V ≥ 0 stands for V positive semi-def<strong>in</strong>ite unless statedotherwise).41


The purpose of LMITOOL is to solve problem Σ <strong>in</strong> a user-friendly manner <strong>in</strong> <strong>Scilab</strong>, us<strong>in</strong>g the codeSP [24]. This code is <strong>in</strong>tended for small and medium-sized problems (say, up to a few hundredvariables).7.2 Function lmisolverLMITOOL is built around the <strong>Scilab</strong> function lmisolver. This function computes the solutionX 1 , . . . , X M of problem Σ, given functions f, G i and H j . To solve Σ, user must provide anevaluation function which “evaluates” f, G i and H j as a function the unknown matrices, as wellas an <strong>in</strong>itial guess on the values of the unknown matrices. User can either <strong>in</strong>voke lmisolverdirectly, by provid<strong>in</strong>g the necessary <strong>in</strong>formation <strong>in</strong> a special format or he can use the <strong>in</strong>teractivefunction lmitool described <strong>in</strong> Section 7.3.7.2.1 Syntax[XLISTF[,OPT]] = lmisolver(XLIST0,EVALFUNC[,options])where• XLIST0: a list structure <strong>in</strong>clud<strong>in</strong>g matrices and/or list of matrices. It conta<strong>in</strong>s <strong>in</strong>itial guesson the values of the unknown matrices. In general, the ith element of XLIST0 is the <strong>in</strong>itialguess on the value of the unknown matrix X i . In some cases however it is more convenientto def<strong>in</strong>e one or more elements of XLIST0 to be lists (of unknown matrices) themselves. Thisis a useful feature when the number of unknown matrices is not fixed a priori (see Exampleof Section 7.2.2).The values of the matrices <strong>in</strong> XLIST0, if compatible with the LME functions, are used as<strong>in</strong>tial condition for the optimization algorithm; they are ignored otherwise. The size andstructure of XLIST0 are used to set up the problem and determ<strong>in</strong>e the size and structure ofthe output XLISTF.• EVALFUNC: a <strong>Scilab</strong> function called evaluation function (supplied by the user) which evaluatesthe LME, LMI and objective functions, given the values of the unknown matrices. Thesyntax is:[LME,LMI,OBJ]=EVALFUNC(XLIST)where– XLIST: a list, identical <strong>in</strong> size and structure to XLIST0.– LME: a list of matrices conta<strong>in</strong><strong>in</strong>g values of the LME functions G i ’s for X values <strong>in</strong>XLIST. LME can be a matrix <strong>in</strong> case there is only one LME function to be evaluated(<strong>in</strong>stead of a list conta<strong>in</strong><strong>in</strong>g this matrix as unique element). It can also be a list of amixture of matrices and lists which <strong>in</strong> turn conta<strong>in</strong> values of LME’s, and so on.– LMI: a list of matrices conta<strong>in</strong><strong>in</strong>g the values of the LMI functions H j ’s for X values<strong>in</strong> XLIST. LMI can also be a matrix (<strong>in</strong> case there is only one LMI function to beevaluated). It can also be a list of a mixture of matrices and lists which <strong>in</strong> turn conta<strong>in</strong>values of of LMI’s, and so on.42


– OBJ: a scalar equal to the value of the objective function f for X values <strong>in</strong> XLIST.If the Σ problem has no equality constra<strong>in</strong>ts then LME should be []. Similarly for LMI andOBJ.• options: a 5×1 vector conta<strong>in</strong><strong>in</strong>g optimization parameters Mbound, abstol, nu, maxiters,and reltol, see manual page for semidef for details (Mbound is a multiplicative coefficientfor M). This argument is optional, if omitted, default parameters are used.• XLISTF: a list, identical <strong>in</strong> size and structure to XLIST0 conta<strong>in</strong><strong>in</strong>g the solution of theproblem (optimal values of the unknown matrices).• OPT: a scalar correspond<strong>in</strong>g to the optimal value of the m<strong>in</strong>imization problem Σ.7.2.2 ExamplesState-feedback with control saturation constra<strong>in</strong>tConsider the l<strong>in</strong>ear systemẋ = Ax + Buwhere A is an n × n and B, an n × n u matrix. There exists a stabiliz<strong>in</strong>g state feedback K suchthat for every <strong>in</strong>itial condition x(0) with ‖x(0)‖ ≤ 1, the result<strong>in</strong>g control satisfies ‖u(t)‖ for allt ≥ 0, if and only if there exist an n × n matrix Q and an n u × n matrix Y satisfy<strong>in</strong>g the equalityconstra<strong>in</strong>tQ − Q T = 0and the <strong>in</strong>equality constra<strong>in</strong>tsQ ≥ 0−AQ − QA T − BY − Y T B T > 0( )u2max I YY T ≥ 0Q<strong>in</strong> which case one such K can be constructed as K = Y Q −1 .To solve this problem us<strong>in</strong>g lmisolver, we first need to construct the evaluation function.function [LME,LMI,OBJ]=sf_sat_eval(XLIST)[Q,Y]=XLIST(:)LME=Q-Q’LMI=list(-A*Q-Q*A’-B*Y-Y’*B’,[umax^2*eye(Y*Y’),Y;Y’,Q],Q-eye())OBJ=[]Note that OBJ=[] <strong>in</strong>dicates that the problem considered is a feasibility problem, i.e., we are only<strong>in</strong>terested <strong>in</strong> f<strong>in</strong>d<strong>in</strong>g a set of X’s that satisfy LME and LMI functions.Assum<strong>in</strong>g A, B and umax already exist <strong>in</strong> the environment, we can call lmisolver, and reconstructthe solution <strong>in</strong> <strong>Scilab</strong>, as follows:43


--> Q_<strong>in</strong>it=zeros(A);--> Y_<strong>in</strong>it=zeros(B’);--> XLIST0=list(Q_<strong>in</strong>it,Y_<strong>in</strong>it);--> XLIST=lmisolver(XLIST0,sf_sat_eval);--> [Q,Y]=XLIST(:)These <strong>Scilab</strong> commands can of course be encapsulated <strong>in</strong> a <strong>Scilab</strong> function, say sf_sat. Then,To solve this problem, all we need to do is type:--> [Q,Y]=sf_sat(A,B,umax)We call sf_sat the solver function for this problem.Control of jump l<strong>in</strong>ear systemsWe are given a l<strong>in</strong>ear systemẋ = A(r(t))x + B(r(t))u,where A is n × n and B is n × n u . The scalar parameter r(t) is a cont<strong>in</strong>uous-time Markov processtak<strong>in</strong>g values <strong>in</strong> a f<strong>in</strong>ite set {1, . . . , N}.The transition probabilities of the process r are def<strong>in</strong>ed by a “transition matrix” Π = (π ij ),where π ij ’s are the transition probability rates from the i-th mode to the j-th. Such systems,referred to as “jump l<strong>in</strong>ear systems”, can be used to model l<strong>in</strong>ear systems subject to failures.We seek a state-feedback control law such that the result<strong>in</strong>g closed-loop system is mean-squarestable. That is, for every <strong>in</strong>itial condition x(0), the result<strong>in</strong>g trajectory of the closed-loop systemsatisfies lim t→∞ E‖x(t)‖ 2 = 0.The control law we look for is a mode-dependent l<strong>in</strong>ear state-feedback, i.e. it has the formu(t) = K(r(t))x(t); K(i)’s are n u × n matrices (the unknowns of our control problem).It can be shown that this problem has a solution if and only if there exist n × n matricesQ(1), . . . , Q(N), and n u × n matrices Y (1), . . . , Y (N), such thatQ(i) − Q(i) T = 0,TrQ(1) + . . . + TrQ(N) − 1 = 0.and[ ]Q(i) Y (i)TY (i) I[]N∑− A(i)Q(i) + Q(i)A(i) T + B(i)Y (i) + Y (i) T B(i) T + π ji Q(j)j=1> 0,> 0, i = 1, . . . , N,If such matrices exist, a stabiliz<strong>in</strong>g state-feedback is given by K(i) = Y (i)Q(i) −1 , i = 1, . . . , N.In the above problem, the data matrices are A(1), . . . , A(N), B(1), . . . , B(N) and the transitionmatrix Π. The unknown matrices are Q(i)’s (which are symmetric n × n matrices) andY (i)’s (which are n u × n matrices). In this case, both the number of the data matrices and thatof the unknown matrices are a-priori unknown.The above problem is obviously a Σ problem. In this case, we can let XLIST be a list of twolists: one represent<strong>in</strong>g the Q’s and the other, the Y ’s.The evaluation function required for <strong>in</strong>vok<strong>in</strong>g lmisolver can be constructed as follows:44


function [LME,LMI,OBJ]=jump_sf_eval(XLIST)[Q,Y]=XLIST(:)N=size(A); [n,nu]=size(B(1))LME=list(); LMI1=list(); LMI2=list()tr=0for i=1:Ntr=tr+trace(Q(i))LME(i)=Q(i)-Q(i)’LMI1(i)=[Q(i),Y(i)’;Y(i),eye(nu,nu)]SUM=zeros(n,n)for j=1:NSUM=SUM+PI(j,i)*Q(j)endLMI2(i)= A(i)*Q(i)+Q(i)*A(i)’+B(i)*Y(i)+Y(i)’*B(i)’+SUMendLMI=list(LMI1,LMI2)LME(N+1)=tr-1OBJ=[]Note that LMI is also a list of lists conta<strong>in</strong><strong>in</strong>g the values of the LMI matrices. This is just a matterof convenience.Now, we can solve the problem <strong>in</strong> <strong>Scilab</strong> as follows (assum<strong>in</strong>g lists A and B, and matrix PIhave already been def<strong>in</strong>ed).First we should <strong>in</strong>itialize Q and Y.--> N=size(A); [n,nu]=size(B(1)); Q_<strong>in</strong>it=list(); Y_<strong>in</strong>it=list();--> for i=1:N, Q_<strong>in</strong>it(i)=zeros(n,n);Y_<strong>in</strong>it(i)=zeros(nu,n);endThen, we can use lmisolver as follows:--> XLIST0=list(Q_<strong>in</strong>it,Y_<strong>in</strong>it)--> XLISTF=lmisolver(XLIST0,jump_sf_eval)--> [Q,Y]=XLISTF(:);The above commands can be encapsulated <strong>in</strong> a solver function, say jump_sf, <strong>in</strong> which casewe simply need to type:--> [Q,Y]=jump_sf(A,B,PI)to obta<strong>in</strong> the solution.Descriptor Lyapunov <strong>in</strong>equalitiesIn the study of descriptor systems, it is sometimes necessary to f<strong>in</strong>d (or f<strong>in</strong>d out that it does notexist) an n × n matrix X satisfy<strong>in</strong>gE T X = X T E ≥ 0A T X + X T A + I ≤ 0where E and A are n × n matrices such that E, A is a regular pencil. In this problem, whichclearly is a Σ problem, the LME functions play important role. The evaluation function can bewritten as follows45


function [LME,LMI,OBJ]=dscr_lyap_eval(XLIST)X=XLIST(:)LME=E’*X-X’*ELMI=list(-A’*X-X’*A-eye(),E’*X)OBJ=[]and the problem can be solved by (assum<strong>in</strong>g E and A are already def<strong>in</strong>ed)--> XLIST0=list(zeros(A))--> XLISTF=lmisolver(XLIST0,dscr_lyap_eval)--> X=XLISTF(:)Mixed H 2 /H ∞ ControlConsider the l<strong>in</strong>ear systemẋ = Ax + B 1 w + B 2 uz 1 = C 1 x + D 11 w + D 12 uz 2 = C 2 x + D 22 uThe mixed H 2 /H ∞ control problem consists <strong>in</strong> f<strong>in</strong>d<strong>in</strong>g a stabiliz<strong>in</strong>g feedback which yields ‖T z1 w‖ ∞ X_<strong>in</strong>it=zeros(A); Y_<strong>in</strong>it=zeros(C2*C2’); L_<strong>in</strong>it=zeros(B2’)--> XLIST0=list(X_<strong>in</strong>it,Y_<strong>in</strong>it,L_<strong>in</strong>it);--> XLISTF=lmisolver(XLIST0,h2h<strong>in</strong>f_eval);--> [X,Y,L]=XLISTF(:)46)> 0> 0


Descriptor Riccati equationsIn Kalman filter<strong>in</strong>g for descriptor systemEx(k + 1) = Ax(k) + u(k)y(k + 1) = Cx(k + 1) + r(k)where u and r are zero-mean, white Gaussian noise sequences with covariance Q and R respectively,one needs to obta<strong>in</strong> the positive solution to the descriptor Riccati equation (see [34])⎛P = − ( 0 0 I ) ⎝AP A T + Q 0 E0 R CE T C T 0It can be shown that this problem can be formulated as a Σ problem as follows: maximizeTrace(P) under constra<strong>in</strong>tsP − P T = 0andThe evaluation function is:⎛⎝AP A T + Q 0 EP0 R CPP T E T P T C T P⎞⎞⎠⎠ ≥ 0.−1 ⎛function [LME,LMI,OBJ]=ric_dscr_eval(XLIST)LME=P-P’LMI=[A*P*A’+Q,zeros(A*C’),E*P;zeros(C*A’),R,C*P;P*E’,P*C’,P]OBJ=-trace(P)which can be used as follows (asum<strong>in</strong>g E, A, C, Q and R are def<strong>in</strong>ed and have compatiblesizes–note that E and A need not be square).--> P_<strong>in</strong>it=zeros(A’*A)--> P=lmisolver(XLIST0,ric_dscr_eval)L<strong>in</strong>ear programm<strong>in</strong>g with equality constra<strong>in</strong>tsConsider the follow<strong>in</strong>g classical optimization problemm<strong>in</strong>imize e T xsubject to Ax + b ≥ 0,Cx + d = 0.where A and C are matrices and e, b and d are vectors with appropriate dimensions. Here thesign ≥ is to be understood elementwise.This problem can be formulated <strong>in</strong> LMITOOL as follows:function [LME,LMI,OBJ]=l<strong>in</strong>prog_eval(XLIST)[x]=XLIST(:)[m,n]=size(A)47⎝00I⎞⎠ .


LME=C*x+dLMI=list()tmp=A*x+bfor i=1:mLMI(i)=tmp(i)endOBJ=e’*xand solved <strong>in</strong> <strong>Scilab</strong> by (assum<strong>in</strong>g A, C, e, b and d and an <strong>in</strong>itial guess x0 exist <strong>in</strong> the environment):--> x=lmisolver(x0,l<strong>in</strong>prog_eval)Sylvester EquationThe problem of f<strong>in</strong>d<strong>in</strong>g matrix X satisfy<strong>in</strong>gorAX + XB = CAXB = Cwhere A and B are square matrices (of possibly different sizes) is a well-known problem. We referto the first equation as the cont<strong>in</strong>uous Sylvester equation and the second, the discrete Sylvesterequation.These two problems can easily be formulated as Σ problems as follows:function [LME,LMI,OBJ]=sylvester_eval(XLIST)[X]=XLIST(:)if flag==’c’ thenLME=A*X+X*B-CelseLME=A*X*B-CendLMI=[]OBJ=[]with a solver function such as:function [X]=sylvester(A,B,C,flag)[na,ma]=size(A);[nb,mb]=size(B);[nc,mc]=size(C);if mana|mbnb|ncna|mcnb then error("<strong>in</strong>valid dimensions");endXLISTF=lmisolver(zeros(nc,mc),sylvester_eval)X=XLISTF(:)Then, to solve the problem, all we need to do is to (assum<strong>in</strong>g A, B and C are def<strong>in</strong>ed)--> X=sylvester(A,B,C,’c’)for the cont<strong>in</strong>uous problem and--> X=sylvester(A,B,C,’d’)for the discrete problem.48


7.3 Function LMITOOLThe purpose of LMITOOL is to automate most of the steps required before <strong>in</strong>vok<strong>in</strong>g lmisolver.In particular, it generates a *.sci file <strong>in</strong>clud<strong>in</strong>g the solver function and the evaluation functionor at least their skeleton. The solver function is used to def<strong>in</strong>e the <strong>in</strong>itial guess and to modifyoptimization parameters (if needed).lmitool can be <strong>in</strong>voked with zero, one or three arguments.7.3.1 Non-<strong>in</strong>teractive modelmitool can be <strong>in</strong>voked with three <strong>in</strong>put arguments as follows:Syntaxtxt=lmitool(probname,varlist,datalist)where• probname: a str<strong>in</strong>g conta<strong>in</strong><strong>in</strong>g the name of the problem,• xlist: a str<strong>in</strong>g conta<strong>in</strong><strong>in</strong>g the names of the unknown matrices (separated by commas ifthere are more than one).• dlist: a str<strong>in</strong>g conta<strong>in</strong><strong>in</strong>g the names of data matrices (separated by commas if there aremore than one).• txt: a str<strong>in</strong>g provid<strong>in</strong>g <strong>in</strong>formation on what the user should do next.In this mode, lmitool generates a file <strong>in</strong> the current directory. The name of this file is obta<strong>in</strong>edby add<strong>in</strong>g “.sci” to the end of probname. This file is the skeleton of a solver function and thecorrespond<strong>in</strong>g evaluation function.ExampleSuppose we want to use lmitool to solve the problem presented <strong>in</strong> Section 7.2.2. Invok<strong>in</strong>g-->txt=lmitool(’sf_sat’,’Q,Y’,’A,B,umax’)yields the output--> txt =! To solve your problem, you need to !! !!1- edit file /usr/home/Dr<strong>Scilab</strong>/sf_sat.sci !! !!2- load (and compile) your functions: !! !! getf(’/usr/home/Dr<strong>Scilab</strong>/sf_sat.sci’,’c’) !49


! !!3- Def<strong>in</strong>e A,B,umax and call sf_sat function: !! !! [Q,Y]=sf_sat(A,B,umax) !! !!To check the result, use [LME,LMI,OBJ]=sf_sat_eval(list(Q,Y)) !and results <strong>in</strong> the creation of the file ’/usr/home/curdir/sf sat.sci’ with the follow<strong>in</strong>g content:function [Q,Y]=sf_sat(A,B,umax)// Generated by lmitool on Tue Feb 07 10:30:35 MET 1995Mbound = 1e3;abstol = 1e-10;nu = 10;maxiters = 100;reltol = 1e-10;options=[Mbound,abstol,nu,maxiters,reltol];///////////DEFINE INITIAL GUESS BELOWQ_<strong>in</strong>it=...Y_<strong>in</strong>it=...///////////XLIST0=list(Q_<strong>in</strong>it,Y_<strong>in</strong>it)XLIST=lmisolver(XLIST0,sf_sat_eval,options)[Q,Y]=XLIST(:)/////////////////EVALUATION FUNCTION////////////////////////////function [LME,LMI,OBJ]=sf_sat_eval(XLIST)[Q,Y]=XLIST(:)/////////////////DEFINE LME, LMI and OBJ BELOWLME=...LMI=...OBJ=...It is easy to see how a small amount of edit<strong>in</strong>g can do the rest!7.3.2 Interactive modelmitool can be <strong>in</strong>voked with zero or one <strong>in</strong>put argument as follows:50


Syntaxtxt=lmitool()txt=lmitool(file)where• file: is a str<strong>in</strong>g giv<strong>in</strong>g the name of an exist<strong>in</strong>g “.sci” file generated by lmitool.In this mode, lmitool is fully <strong>in</strong>teractive. Us<strong>in</strong>g a succession of dialogue boxes, user can completelydef<strong>in</strong>e his problem. This mode is very easy to use and its operation completely selfexplanatory. Invok<strong>in</strong>g lmitool with one argument allows the user to start off with an exist<strong>in</strong>gfile. This mode is useful for modify<strong>in</strong>g exist<strong>in</strong>g files or when the new problem is not too muchdifferent from a problem already treated by lmitool.ExampleConsider the follow<strong>in</strong>g estimation problemy = Hx + V wwhere x is unknown to be estimated, y is known, w is a unit-variance zero-mean Gaussian vector,andH ∈ Co {H(1), ..., H(N)} , V ∈ Co {V (1), ..., V (N)}where Co denotes the convex hull and H(i) and V (i), i = 1, ..., N, are given matrices.The objective is to f<strong>in</strong>d L such that the estimateˆx = Lyis unbiased and the worst case estimation error variance E(‖x − ˆx‖ 2 ) is m<strong>in</strong>imized.It can be shown that this problem can be formulated as a Σ problem as follows: m<strong>in</strong>imize γsubject toI − LH(i) = 0, i = 1, ..., N,X(i) − X(i) T = 0, i = 1, ..., N,and()I (L(i)V (i)) T≥ 0,L(i)V (i) X(i)i = 1, ..., N,γ − Trace(X(i)) ≥ 0, i = 1, ..., N.To use lmitool for this problem, we <strong>in</strong>voke it as follows:--> lmitool()This results is an <strong>in</strong>teractive session which is partly illustrated <strong>in</strong> follow<strong>in</strong>g figures.51


7.4 How lmisolver worksThe function lmisolver works essentially <strong>in</strong> four steps:1. Initial set-up. The sizes and structure of the <strong>in</strong>itial guess are used to set up the problem,and <strong>in</strong> particular the size of the unknown vector.2. Elim<strong>in</strong>ation of equality constra<strong>in</strong>ts. Mak<strong>in</strong>g repeated calls to the evaluation function,lmisolver generates a canonical representation of the formm<strong>in</strong>imize ˜c T zsubject to ˜F0 + z 1 ˜F1 + · · · + z ˜m ˜F ˜m ≥ 0, Az + b = 0,where z conta<strong>in</strong>s the coefficients of all matrix variables. This step uses extensively sparsematrices to speed up the computation and reduce memory requirement.3. Elim<strong>in</strong>ation of variables. Then, lmisolver elim<strong>in</strong>ates the redundant variables. The equalityconstra<strong>in</strong>ts are elim<strong>in</strong>ated by comput<strong>in</strong>g the null space N of A and a solution z 0 (if any) ofAx + b = 0. At this stage, all solutions of the equality constra<strong>in</strong>ts are parametrized byz = Nx + z 0 ,where x is a vector conta<strong>in</strong><strong>in</strong>g the <strong>in</strong>dependent variables. The computation of N, z 0 is doneus<strong>in</strong>g sparse LU functions of <strong>Scilab</strong>.Once the equality constra<strong>in</strong>ts are elim<strong>in</strong>ated, the problem is reformulated asm<strong>in</strong>imize c T xsubject to F 0 + x 1 F 1 + · · · + x m F m ≥ 0,where c is a vector, and F 0 , . . . , F m are symmetric matrices, and x conta<strong>in</strong>s the <strong>in</strong>dependentelements <strong>in</strong> the matrix variables X 1 , . . . , X M . (If the F i ’s are dependent, a columncompression is performed.)Figure 7.1: This w<strong>in</strong>dow must be edited to def<strong>in</strong>e problem name and the name of variables used.52


Figure 7.2: For the example at hand the result of the edit<strong>in</strong>g should look someth<strong>in</strong>g like this.4. <strong>Optimization</strong>. F<strong>in</strong>ally, lmisolver makes a call to the function semidef (an <strong>in</strong>terface to SP[24]). This phase is itself divided <strong>in</strong>to a feasibility phase and a m<strong>in</strong>imization phase (onlyif the l<strong>in</strong>ear objective function is not empty). The feasibility phase is avoided if the <strong>in</strong>itialguess is found to be feasible.The function semidef is called with the optimization parameters abstol, nu, maxiters,reltol. The parameter M is set above the valueMbnd*max(sum(abs([F0 ... Fm])))For details about the optimization phase, and the mean<strong>in</strong>g of the above optimization parameterssee manual page for semidef.7.5 Other versionsLMITOOL is also available on Matlab. The Matlab version can be obta<strong>in</strong>ed by anonymous ftp fromftp.ensta.fr under /pub/elghaoui/lmitool.53


Figure 7.3: This is the skeleton of the solver function and the evaluation function generated byLMITOOL us<strong>in</strong>g the names def<strong>in</strong>ed previously.54


Figure 7.4: After edit<strong>in</strong>g, we obta<strong>in</strong>.Figure 7.5: A file is proposed <strong>in</strong> which the solver and evaluation functions are to be saved. Youcan modify it if you want.55


Chapter 8<strong>Optimization</strong> data filesThis section presents the optimization data files which can be used to configure a specific optimizationproblem <strong>in</strong> <strong>Scilab</strong>. The follow<strong>in</strong>g is a (non-exhaustive) list of ASCII file formats oftenused <strong>in</strong> optimization softwares :• SIF : Standard Input Format [1, 31],• GAMS : General Algebraic Model<strong>in</strong>g System [41, 16]• AMPL : A Mathematical Programm<strong>in</strong>g Language [10, 40]• MPS : Mathematical Programm<strong>in</strong>g System [28, 42]but other file formats appeared <strong>in</strong> recent years, such as the XML-based file format OSiL [36, 8, 37].The follow<strong>in</strong>g sections describe <strong>Scilab</strong> tools to manage optimization data files.8.1 MPS files and the Quapro toolboxThe Quapro toolbox implements the readmps function, which reads a file conta<strong>in</strong><strong>in</strong>g descriptionof an LP problem given <strong>in</strong> MPS format and returns a tlist describ<strong>in</strong>g the optimization problem.It is an <strong>in</strong>terface with the program rdmps1.f of hopdm (J. Gondzio). For a description of thevariables, see the file rdmps1.f. MPS format is a standard ASCII medium for LP codes. MPSformat is described <strong>in</strong> more detail <strong>in</strong> Murtagh’s book [31].8.2 SIF files and the CUTEr toolboxThe SIF file format can be processed with the CUTEr <strong>Scilab</strong> toolbox. Given a SIF [1] file the functionsifdecode generates associated Fortran rout<strong>in</strong>es RANGE.f, EXTER.f, ELFUN.f, GROUP.fand if automatic differentiation is required ELFUND.f, GROUPD.f, EXTERA.f. An associateddata file named OUTSDIF.d and an Output messages file OUTMESS are also generated. Allthese files are created <strong>in</strong> the directory whose path is given <strong>in</strong> Pathout. The sifdecode functionis based on the Sifdec code [20]. More precisely it results of an <strong>in</strong>terface of SDLANC Fortranprocedure.56


Chapter 9<strong>Scilab</strong> <strong>Optimization</strong> ToolboxesSome <strong>Scilab</strong> toolboxes are designed to solve optimization problems. In this chapter, we beg<strong>in</strong> bypresent<strong>in</strong>g the Quapro toolbox, which allows to solve l<strong>in</strong>ear and quadratic problems. Then weoutl<strong>in</strong>e other ma<strong>in</strong> optimization toolboxes.9.1 QuaproThe Quapro toolbox was formely a <strong>Scilab</strong> built-<strong>in</strong> optimization tool. It has been transformed <strong>in</strong>toa toolbox for license reasons.9.1.1 L<strong>in</strong>ear optimizationMathematical po<strong>in</strong>t of viewThis k<strong>in</strong>d of optimization is the m<strong>in</strong>imization of function f(x) withunder:• no constra<strong>in</strong>ts• <strong>in</strong>equality constra<strong>in</strong>ts (9.1)f(x) = p T x• or <strong>in</strong>equality constra<strong>in</strong>ts and bound constra<strong>in</strong>ts ((9.1) & (9.2))• or <strong>in</strong>equality constra<strong>in</strong>ts, bound constra<strong>in</strong>ts and equality constra<strong>in</strong>ts ((9.1) & (9.2) & (9.3)).C ∗ x ≤ b (9.1)ci ≤ x ≤ cs (9.2)C e ∗ x = b e (9.3)57


<strong>Scilab</strong> function<strong>Scilab</strong> function called l<strong>in</strong>pro is designed for l<strong>in</strong>ear optimization programm<strong>in</strong>g. For more detailsabout this function, please refer to <strong>Scilab</strong> onl<strong>in</strong>e help This function and associated rout<strong>in</strong>eshave been written by Cecilia Pola Mendez and Eduardo Casas Renteria from the University ofCantabria. Please note that this function can not solve problems based on sparse matrices. Forthis k<strong>in</strong>d of problem, you can use a <strong>Scilab</strong> toolbox called LIPSOL that gives an equivalent ofl<strong>in</strong>pro for sparse matrices. LIPSOL is available on <strong>Scilab</strong> web site<strong>Optimization</strong> rout<strong>in</strong>es<strong>Scilab</strong> l<strong>in</strong>pro function is based on:• some Fortran rout<strong>in</strong>es written by the authors of l<strong>in</strong>pro• some Fortran Blas rout<strong>in</strong>es• some Fortran <strong>Scilab</strong> rout<strong>in</strong>es• some Fortran Lapack rout<strong>in</strong>es9.1.2 L<strong>in</strong>ear quadratic optimizationMathematical po<strong>in</strong>t of viewThis k<strong>in</strong>d of optimization is the m<strong>in</strong>imization of function f(x) withunder:• no constra<strong>in</strong>ts• <strong>in</strong>equality constra<strong>in</strong>ts (9.1)f(x) = 1 2 xT Qx + p T x• or <strong>in</strong>equality constra<strong>in</strong>ts and bound constra<strong>in</strong>ts ((9.1) & (9.2))• or <strong>in</strong>equality constra<strong>in</strong>ts, bound constra<strong>in</strong>ts and equality constra<strong>in</strong>ts ((9.1) & (9.2) & (9.3)).<strong>Scilab</strong> function<strong>Scilab</strong> functions called quapro (whatever Q is) and qld (when Q is positive def<strong>in</strong>ite) are designedfor l<strong>in</strong>ear optimization programm<strong>in</strong>g. For more details about these functions, please refer to<strong>Scilab</strong> onl<strong>in</strong>e help for quapro and <strong>Scilab</strong> onl<strong>in</strong>e help for qld qld function and associated rout<strong>in</strong>ehave been written by K. Schittkowski from the University of Bayreuth, A.L. Tits and J.L. Zhoufrom the University of Maryland. quapro function and associated rout<strong>in</strong>es have been writtenby Cecilia Pola Mendez and Eduardo Casas Renteria from the University of Cantabria. Bothfunctions can not solve problems based on sparse matrices.58


<strong>Optimization</strong> rout<strong>in</strong>es<strong>Scilab</strong> quapro function is based on:• some Fortran rout<strong>in</strong>es written by the authors of l<strong>in</strong>pro• some Fortran Blas rout<strong>in</strong>es• some Fortran <strong>Scilab</strong> rout<strong>in</strong>es• some Fortran Lapack rout<strong>in</strong>es9.2 CUTErCUTEr is a versatile test<strong>in</strong>g environment for optimization and l<strong>in</strong>ear algebra solvers [32]. Thistoolbox is a scilab port by Serge Steer and Bruno Durand of the orig<strong>in</strong>al Matlab toolbox.A typical use start from problem selection us<strong>in</strong>g the scilab function sifselect. This givesa vector of problem names correspond<strong>in</strong>g to selection criteria [33]. The available problems arelocated <strong>in</strong> the sif directory.The sifbuild function can then be used to generate the fortran codes associated to a givenproblem, to compile them and dynamically l<strong>in</strong>k it to <strong>Scilab</strong>. This will create a set of problemrelative functions, for example, ufn or ugr. This functions can be called to compute the objectivefunction or its gradient at a given po<strong>in</strong>t.The sifoptim function automatically applies the optim function to a selected problem.A Fortran compiler is mandatory to build problems.This toolbox conta<strong>in</strong>s the follow<strong>in</strong>g parts.• Problem databaseA set of test<strong>in</strong>g problems coded <strong>in</strong> ”Standard Input Format” (SIF) is <strong>in</strong>cluded <strong>in</strong> the sif/sub-directory. This set comes from www.numerical.rl.ac.uk/cute/mastsif.html. The <strong>Scilab</strong>function sifselect can be used to select some of this problems accord<strong>in</strong>g to objectivefunction properties, contra<strong>in</strong>ts properties and regularity properties• SIF format decoderThe <strong>Scilab</strong> function sifdecode can be used to generate the Fortran codes associated to agiven problem, while the <strong>Scilab</strong> function buildprob compiles and dynamically l<strong>in</strong>ks thesefortran code with <strong>Scilab</strong>• problem relative functionsThe execution of the function buildprob adds a set of functions to <strong>Scilab</strong>. The first oneis usetup for unconstra<strong>in</strong>ed or bounded problems or csetup for problems with generalcontra<strong>in</strong>ts. These functions are to be called before any of the follow<strong>in</strong>g to <strong>in</strong>itialize theproblem relative data (only one problem can be run at a time). The other functions allowto compute the objective, the gradient, the hessian values, ... of the problem at a givenpo<strong>in</strong>t (see ufn, ugr, udh, ... for unconstra<strong>in</strong>ed or bounded problems or cfn, cgr, cdh, ...for problems with general contra<strong>in</strong>ts)59


• CUTEr and optim The <strong>Scilab</strong> function optim can be used together with CUTEr us<strong>in</strong>g eitherthe external function ucost or the driver function sifoptim.The follow<strong>in</strong>g is a list of references for the CUTEr toolbox :• CUTEr toolbox on <strong>Scilab</strong> Toolbox center• CUTEr website9.3 The Unconstra<strong>in</strong>ed <strong>Optimization</strong> Problem ToolboxThe Unconstra<strong>in</strong>ed <strong>Optimization</strong> Problem Toolbox provides 35 unconstra<strong>in</strong>ed optimization problems.The goal of this toolbox is to provide unconstra<strong>in</strong>ed optimization problems <strong>in</strong> order to testoptimization algorithms.The More, Garbow and Hillstrom collection of test functions [30] is widely used <strong>in</strong> test<strong>in</strong>gunconstra<strong>in</strong>ed optimization software. The problems available <strong>in</strong> this collection are presented <strong>in</strong>the figure 9.1. All the problems are def<strong>in</strong>ed as a sum of squares of functions. The dimension ofthe space is denoted by n, while the number of functions is denoted by m.It provides the function value, the gradient, the function vector, the Jacobian and providesthe Hessian matrix for 18 problems. It provides the start<strong>in</strong>g po<strong>in</strong>t for each problem, the optimumfunction value and the optimum po<strong>in</strong>t x for many problems. Additionnally, it provides f<strong>in</strong>itedifference rout<strong>in</strong>es for the gradient, the Jacobian and the Hessian matrix. The functions arebased on macros based functions : no compiler is required, which is an advantage over the CUTErtoolbox. F<strong>in</strong>ally, all function values, gradients, Jacobians and Hessians are tested.This toolbox is available <strong>in</strong> ATOMS :and is manage under <strong>Scilab</strong>’s Forge :http://atoms.scilab.org/toolboxes/uncprbhttp://forge.scilab.org/<strong>in</strong>dex.php/p/uncprbTo <strong>in</strong>stall it, type the follow<strong>in</strong>g statement <strong>in</strong> <strong>Scilab</strong> v5.2 (or better).1 a t o m s I n s t a l l ( ”uncprb”)9.4 Other toolboxes9.4.1 Interface to CONMINAn <strong>in</strong>terface to the NASTRAN / NASA CONMIN optimization program by Yann Collette. CON-MIN can solve a nonl<strong>in</strong>ear objective problem with nonl<strong>in</strong>ear constra<strong>in</strong>ts. CONMIN uses a two-steplimited memory quasi-Newton-like Conjugate Gradient. The CONMIN optimization method iscurrently used <strong>in</strong> NASTRAN (a professionnal f<strong>in</strong>ite element tool) and the optimization part ofNASTRAN (the CONMIN tool). The CONMIN fortran program has been written by G. Vanderplaats(1973).• CONMIN on <strong>Scilab</strong> Toolbox center60


No. file n m Name1 ROSE 2 2 Rosenbrock2 FROTH 2 2 Freudenste<strong>in</strong> and Roth3 BADSCP 2 2 Powell Badly Scaled4 BADSCB 2 3 Brown Badly Scaled5 BEALE 2 3 Beale6 JENSAM 2 (10) Jennrich and Sampson7 HELIX 3 3 Helical Valley8 BARD 3 15 Bard9 GAUSS 3 15 Gaussian10 MEYER 3 16 Meyer11 GULF 3 (10) Gulf Research and Development12 BOX 3 (10) Box 3-Dimensional13 SING 4 4 Powell S<strong>in</strong>gular14 WOOD 4 6 Wood15 KOWOSB 4 11 Kowalik and Osborne16 BD 4 (20) Brown and Dennis17 OSB1 5 33 Osborne 118 BIGGS 6 (13) Biggs EXP619 OSB2 11 65 Osborne 220 WATSON (10) 31 Watson21 ROSEX (20) (20) Extended Rosenbrock22 SINGX (12) (12) Extended Powell S<strong>in</strong>gular23 PEN1 (8) (9) Penalty I24 PEN2 (8) (16) Penalty II25 VARDIM (10) (12) Variably Dimensioned26 TRIG (10) (10) Trigonometric27 ALMOST (10) (10) Brown Almost L<strong>in</strong>ear28 BV (8) (8) Discrete Boundary Value29 IE (8) (8) Discrete Integral Equation30 TRID (12) (12) Broyden Tridiagonal31 BAND (15) (15) Broyden Banded32 LIN (10) (15) L<strong>in</strong>ear - Full Rank33 LIN1 (10) (15) L<strong>in</strong>ear - Rank 134 LIN0 (10) (15) L<strong>in</strong>ear - Rank 1 with Zero Cols and Rows35 CHEB (10) (10) ChebyquadFigure 9.1: Problems available <strong>in</strong> the Unconstra<strong>in</strong>ed <strong>Optimization</strong> Problems toolbox61


9.4.2 Differential EvolutionA random search of a global m<strong>in</strong>imum by Helmut Jarausch. This toolbox is based on a Ra<strong>in</strong>er-Storn algorithm.• Differential Evolution on <strong>Scilab</strong> Toolbox center9.4.3 FSQP InterfaceAn <strong>in</strong>terface for the Feasible Sequential Quadratic Programm<strong>in</strong>g library. This toolbox is designedfor non-l<strong>in</strong>ear optimization with equality and <strong>in</strong>equality constra<strong>in</strong>ts. FSQP is a commercial productbut is provided by the authors, free of charge, for an academic use.• This module is available on the former <strong>Scilab</strong> Toolbox Center• FSQP on <strong>Scilab</strong> Toolbox center• FSQP websiteThere are older versions of this module, namely FSQP 2007-09-24, and FSQP 2000-02-01.9.4.4 IPOPT <strong>in</strong>terfaceAn <strong>in</strong>terface for Ipopt, which is based on an <strong>in</strong>terior po<strong>in</strong>t method which can handle equality and<strong>in</strong>equality nonl<strong>in</strong>ear constra<strong>in</strong>ts. This solver can handle large scale optimization problems. Asopen source software, the source code for Ipopt is provided without charge. You are free to use it,also for commercial purposes. This <strong>Scilab</strong>-Ipopt <strong>in</strong>terface was based on the Matlab Mex Interfacedeveloped by Claas Michalik and Ste<strong>in</strong>ar Hauan. This version only works on l<strong>in</strong>ux, scons and<strong>Scilab</strong> >=4.0. Tested with gcc 4.0.3. Modifications to <strong>Scilab</strong> Interface made by Edson Cordeirodo Valle.• Ipopt on <strong>Scilab</strong> Toolbox center• Ipopt website9.4.5 Interface to LIPSOLA sparse l<strong>in</strong>ear problems solver with <strong>in</strong>terior po<strong>in</strong>ts method by H. Rubio Scola. LIPSOL can m<strong>in</strong>imizea l<strong>in</strong>ear objective with l<strong>in</strong>ear constra<strong>in</strong>ts and bound constra<strong>in</strong>ts. It is based on a primal-dual<strong>in</strong>terior po<strong>in</strong>t method, which uses sparse-matrix data-structure to solve large, sparse, symmetricpositive def<strong>in</strong>ite l<strong>in</strong>ear systems. LIPSOL is written by Y<strong>in</strong> Zhang . The orig<strong>in</strong>al Matlab-basedcode has been adapted to <strong>Scilab</strong> by H. Rubio Scola (University of Rosario, Argent<strong>in</strong>a). It is distributedfreely under the terms of the GPL. LIPSOL also uses the ORNL sparse Cholesky solverversion 0.3 written by Esmond Ng and Barry Peyton by H. Rubio Scola.• LIPSOL on <strong>Scilab</strong> Toolbox center• LIPSOL website• LIPSOL User’s Guide62


9.4.6 LPSOLVEAn <strong>in</strong>terface to lp solve. The lp solve library is a free mixed <strong>in</strong>teger/b<strong>in</strong>ary l<strong>in</strong>ear programm<strong>in</strong>gsolver with full source, examples and manuals. lp solve is under LGPL, the GNU lesser generalpublic license. lp solve uses the ’Simplex’ algorithm and sparse matrix methods for pure LPproblems.• LPSOLVE toolbox on <strong>Scilab</strong> Toolbox center• lp solve solver on Sourceforge• lp solve on Geocities• lp solve Yahoo Group9.4.7 NEWUOANEWUOA is a software developped by M.J.D. Powell for unconstra<strong>in</strong>ed optimization withoutderivatives. The NEWUOA seeks the least value of a function F(x) (x is a vector of dimension n )when F(x) can be calculated for any vector of variables x . The algorithm is iterative, a quadraticmodel be<strong>in</strong>g required at the beg<strong>in</strong>n<strong>in</strong>g of each iteration, which is used <strong>in</strong> a trust region procedurefor adjust<strong>in</strong>g the variables. When the quadratic model is revised, the new model <strong>in</strong>terpolates Fat m po<strong>in</strong>ts, the value m=2n+1 be<strong>in</strong>g recommended.• NEWUOA toolbox on <strong>Scilab</strong> Toolbox center• NEWUOA at INRIA Alpes9.4.8 SciCobylaThe SciCobyla optimization method is a derivative free non l<strong>in</strong>ear constra<strong>in</strong>ed optimizationmethod. It is available on ATOMS : http://atoms.scilab.org/toolboxes/scicobyla.9.4.9 AMPL ToolboxThe AMPL toolbox allows you to load <strong>in</strong>to <strong>Scilab</strong> .nl files created us<strong>in</strong>g AMPL. Once loaded<strong>in</strong>to <strong>Scilab</strong>, you can use them like any other objective functions, get derivatives, constra<strong>in</strong>ts, etc.You can use <strong>Scilab</strong> optimization tools to f<strong>in</strong>d some solutions. You must compile ampl .mod files<strong>in</strong>to .nl files before us<strong>in</strong>g this toolbox to load the file <strong>in</strong>to <strong>Scilab</strong>. It is available on ATOMS :http://atoms.scilab.org/toolboxes/ampl_toolbox.9.4.10 The Optkelley ToolboxThese <strong>Scilab</strong> files are implementations of the algorithms from the book ”Iterative Methods for<strong>Optimization</strong>”, by C.T. Kelley [22].The follow<strong>in</strong>g is an overview of the functions available :• optkelley_bfgswopt : Steepest descent/bfgs with polynomial l<strong>in</strong>e search.• optkelley_cgtrust : Steihaug Newton-CG-Trust region algorithm.63


• optkelley_diffhess : Compute a forward difference Hessian.• optkelley_dirdero : F<strong>in</strong>ite difference directional derivative.• optkelley_gaussn : Damped Gauss-Newton with Armijo rule.• optkelley_gradproj : Gradient projection with Armijo rule, simple l<strong>in</strong>esearch• optkelley_hooke : Hooke-Jeeves optimization.• optkelley_imfil : Unconstra<strong>in</strong>ed implicit filter<strong>in</strong>g.• optkelley_levmar : Levenberg-Marquardt.• optkelley_mds : Multidirectional search.• optkelley_nelder : Nelder-Mead optimizer, No tie-break<strong>in</strong>g rule other than <strong>Scilab</strong>’s gsort.• optkelley_ntrust : Dogleg trust region.• optkelley_polyl<strong>in</strong>e : Polynomial l<strong>in</strong>e search.• optkelley_polymod : Cubic/quadratic polynomial l<strong>in</strong>esearch.• optkelley_projbfgs : Projected BFGS with Armijo rule, simple l<strong>in</strong>esearch• optkelley_simpgrad : Simplex gradient.• optkelley_steep : Steepest descent with Armijo rule.The optimization codes have the call<strong>in</strong>g convention1 [ f , g ] = o b j e c t i v e ( x )returns both the objective function value f and the gradient vector g. I expect g to be a columnvector. The Nelder-Mead, Hooke-Jeeves, Implicit Filter<strong>in</strong>g, and MDS codes do not ask for agradient.The authors of this toolbox are C. T. Kelley, Yann Collette, Michael Baud<strong>in</strong>.To <strong>in</strong>stall it, type the follow<strong>in</strong>g statement <strong>in</strong> <strong>Scilab</strong> v5.2 (or better).1 a t o m s I n s t a l l ( ”optkelley ”)64


Chapter 10Miss<strong>in</strong>g optimization features <strong>in</strong> <strong>Scilab</strong>Several optimization features are miss<strong>in</strong>g <strong>in</strong> <strong>Scilab</strong>. Two classes of miss<strong>in</strong>g features are to analyse :• features which are not available <strong>in</strong> <strong>Scilab</strong>, but which are available as toolboxes (see previoussection),• features which are not available neither <strong>in</strong> <strong>Scilab</strong>, nor <strong>in</strong> toolboxes.Here is a list of features which are not available <strong>in</strong> <strong>Scilab</strong>, but are available <strong>in</strong> toolboxes. Thesefeatures would be to <strong>in</strong>clude <strong>in</strong> <strong>Scilab</strong>.• <strong>in</strong>teger parameter with l<strong>in</strong>ear objective solver and sparse matrices : currently available <strong>in</strong>LPSOLVE toolbox, based on the simplex method,• l<strong>in</strong>ear objective with sparse matrices : currently available <strong>in</strong> LIPSOL, based on <strong>in</strong>teriorpo<strong>in</strong>ts method,• nonl<strong>in</strong>ear objective and non l<strong>in</strong>ear constra<strong>in</strong>ts : currently available <strong>in</strong> <strong>in</strong>terface to IPOPTtoolbox, based on <strong>in</strong>terior po<strong>in</strong>t methods,• nonl<strong>in</strong>ear objective and non l<strong>in</strong>ear constra<strong>in</strong>ts : currently available <strong>in</strong> <strong>in</strong>terface to CONMINtoolbox, based on method of feasible directions,Notice that IPOPT is a commercial product and CONMIN is a doma<strong>in</strong>-public library. Thereforethe only open-source, free, nonl<strong>in</strong>ear solver with non l<strong>in</strong>ear constra<strong>in</strong>ts tool available with <strong>Scilab</strong>is the <strong>in</strong>terface to CONMIN.Here is a list of features which are not available neither <strong>in</strong> <strong>Scilab</strong>, nor <strong>in</strong> toolboxes.• quadratic objective solver with sparse objective matrix,• simplex programm<strong>in</strong>g method (*),• non-l<strong>in</strong>ear objective with nonl<strong>in</strong>ear constra<strong>in</strong>ts (*),• non-l<strong>in</strong>ear objective with nonl<strong>in</strong>ear constra<strong>in</strong>ts problems based on sparse l<strong>in</strong>ear algebra,• enabl<strong>in</strong>g/disabl<strong>in</strong>g of unknowns or constra<strong>in</strong>ts,• customization of errors for constra<strong>in</strong>ts.Functionalities marked with a (*) would be available <strong>in</strong> <strong>Scilab</strong> if the MODULOPT libraryembedded <strong>in</strong> <strong>Scilab</strong> was updated.65


ConclusionEven if <strong>Scilab</strong> itself has lacks <strong>in</strong> optimization functionalities, all embedded functions are veryuseful to beg<strong>in</strong> with. After that, by download<strong>in</strong>g and <strong>in</strong>stall<strong>in</strong>g some toolboxes, you can easilyimprove your <strong>Scilab</strong> capabilities.One of the questions we can ask is: “Why are these toolboxes not <strong>in</strong>tegrated <strong>in</strong> <strong>Scilab</strong> distribution?”.The answer is often a problem of license. All GPL libraries can not be <strong>in</strong>cluded <strong>in</strong><strong>Scilab</strong> s<strong>in</strong>ce <strong>Scilab</strong> is not designed to become GPL.66


Bibliography[1] Nicholas I. M. Gould Andrew R. Conn and Philippe L. To<strong>in</strong>t. The sif reference document.http://www.numerical.rl.ac.uk/lancelot/sif/sifhtml.html.[2] Michael Baud<strong>in</strong>. Nelder mead user’s manual. http://wiki.scilab.org/The_Nelder-Mead_Component, 2009.[3] Michael Baud<strong>in</strong> and Serge Steer. <strong>Optimization</strong> with scilab, present and future. To appear<strong>in</strong> Proceed<strong>in</strong>gs Of 2009 International Workshop On Open-Source Software For ScientificComputation (Ossc-2009).[4] Frédéric Bonnans. A variant of a projected variable metric method for bound constra<strong>in</strong>edoptimization problems. Technical Report RR-0242, INRIA - Rocquencourt, Octobre 1983.[5] Joseph Frédéric Bonnans, Jean-Charles Gilbert, Claude Lemaréchal, and Claudia A. Sagastizábal.Numerical <strong>Optimization</strong>. Theoretical and Practical Aspects. Universitext. Spr<strong>in</strong>gerVerlag, November 2006. Nouvelle édition, revue et augmentéee. 490 pages.[6] S. Boyd, L. El Ghaoui, E. Feron, and V. Balakrishnan. L<strong>in</strong>ear Matrix Inequalities <strong>in</strong> Systemand Control Theory, volume 15 of Studies <strong>in</strong> Applied Mathematics. SIAM, Philadelphia, PA,June 1994.[7] Carlos A. Coello Coello. List of references on evolutionary multiobjective optimization.http://www.lania.mx/~ccoello/EMOObib.html.[8] co<strong>in</strong> or.org. <strong>Optimization</strong> services <strong>in</strong>stance language (osil). https://www.co<strong>in</strong>-or.org/OS/OSiL.html.[9] Yann Collette. Personnal website. http://ycollette.free.fr.[10] AMPL company. A model<strong>in</strong>g language for mathematical programm<strong>in</strong>g. http://en.wikipedia.org/wiki/AMPL_programm<strong>in</strong>g_language.[11] Goldfarb D. and Idnani A. Dual and primal-dual methods for solv<strong>in</strong>g strictly convexquadratic programs. Lecture Notes <strong>in</strong> Mathematics, Spr<strong>in</strong>ger-Verlag, 909:226–239, 1982.[12] Goldfarb D. and Idnani A. A numerically stable dual method for solv<strong>in</strong>g strictly convexquadratic programs. Mathematical Programm<strong>in</strong>g, 27:1–33, 1982.[13] Lawrence Davis. Genetic Algorithms and Simulated Anneal<strong>in</strong>g. Morgan Kaufmann PublishersInc., San Francisco, CA, USA, 1987.67


[14] Kalyanmoy Deb, Samir Agrawal, Amrit Pratap, and T Meyarivan. A fast elitist nondom<strong>in</strong>atedsort<strong>in</strong>g genetic algorithm for multi-objective optimization: Nsga-ii. pages 849–858.Spr<strong>in</strong>ger, 2000. http://www.lania.mx/%7Eccoello/deb00.ps.gz.[15] Carlos M. Fonseca and Peter J. Flem<strong>in</strong>g. Genetic algorithms for multiobjective optimization:Formulationdiscussion and generalization. In Proceed<strong>in</strong>gs of the 5th International Conferenceon Genetic Algorithms, pages 416–423, San Francisco, CA, USA, 1993. Morgan KaufmannPublishers Inc. http://www.lania.mx/%7Eccoello/fonseca93.ps.gz.[16] gams.com. The general algebraic model<strong>in</strong>g system. http://www.gams.com/.[17] David E. Goldberg. Genetic Algorithms <strong>in</strong> Search, <strong>Optimization</strong> & Mach<strong>in</strong>e Learn<strong>in</strong>g.Addison-Wesley, 1989.[18] Jean-Baptiste Hiriart-Urruty and Claude Lemaréchal. Convex Analysis and M<strong>in</strong>imizationAlgorithms I: Fundamentals. Spr<strong>in</strong>ger, October 1993.[19] Jean-Baptiste Hiriart-Urruty and Claude Lemaréchal. Convex Analysis and M<strong>in</strong>imizationAlgorithms II: Advanced Theory and Bundle Methods. Spr<strong>in</strong>ger, October 1993.[20] hsl.rl.ac.uk. A lonesome sif decoder. http://hsl.rl.ac.uk/cuter-www/sifdec/doc.html.[21] Stephen J. Wright Jorge Nocedal. Numerical <strong>Optimization</strong>. Spr<strong>in</strong>ger, 1999.[22] C.T. Kelley. Iterative Methods For <strong>Optimization</strong>. Spr<strong>in</strong>ger, 1999.[23] P.P. Khargonekar and M.A. Rotea. Mixed h2/h? control: a convex optimization approach.Automatic Control, IEEE Transactions on, 36(7):824–837, Jul 1991.[24] Vandenberghe L. and S. Boyd. Semidef<strong>in</strong>ite programm<strong>in</strong>g. Internal Report, Stanford University,1994 (submitted to SIAM Review).[25] P. J. M. Laarhoven and E. H. L. Aarts, editors. Simulated anneal<strong>in</strong>g: theory and applications.Kluwer Academic Publishers, Norwell, MA, USA, 1987.[26] P. J. M. van Laarhoven. Theoretical and Computational Aspects of Simulated Anneal<strong>in</strong>g.Amsterdam, Netherlands : Centrum voor Wiskunde en Informatica, 1988.[27] Claude Lemaréchal. A view of l<strong>in</strong>e-searches. Lectures Notes <strong>in</strong> Control and InformationSciences, 30:59–78, 1981.[28] lpsolve. Mps file format. http://lpsolve.sourceforge.net/5.5/mps-format.htm.[29] Zbigniew Michalewicz. Genetic Algorithms + Data Structures = Evolution Programs.Spr<strong>in</strong>ger, 1996.[30] J. J. Moré, Burton S. Garbow, and Kenneth E. Hillstrom. Algorithm 566: Fortran subrout<strong>in</strong>esfor test<strong>in</strong>g unconstra<strong>in</strong>ed optimization software [c5], [e4]. ACM Trans. Math. Softw.,7(1):136–140, 1981.[31] B. Murtagh. Advanced L<strong>in</strong>ear Programm<strong>in</strong>g: Computation and Practice. McGraw-Hill, 1981.68


[32] Philippe L. To<strong>in</strong>t Nicholas I.M. Gould, Dom<strong>in</strong>ique Orban. A constra<strong>in</strong>ed and unconstra<strong>in</strong>edtest<strong>in</strong>g environment, revisited. http://hsl.rl.ac.uk/cuter-www/.[33] Philippe L. To<strong>in</strong>t Nicholas I.M. Gould, Dom<strong>in</strong>ique Orban. The cuter test problem set.http://www.numerical.rl.ac.uk/cute/mastsif.html.[34] R. Nikoukhah, A.S. Willsky, and B.C. Levy. Kalman filter<strong>in</strong>g and riccati equations fordescriptor systems. Automatic Control, IEEE Transactions on, 37(9):1325–1342, Sep 1992.[35] Jorge Nocedal. Updat<strong>in</strong>g quasi-newton matrices with limited storage. Mathematics of Computation,35(151):773–782, 1980.[36] optimizationservices.org. <strong>Optimization</strong> services. http://www.optimizationservices.org/.[37] Jun Ma Robert Fourer and Kipp Mart<strong>in</strong>. Osil: An <strong>in</strong>stance language for optimization.Computational <strong>Optimization</strong> and Applications, 2008.[38] N. Sr<strong>in</strong>ivas and Kalyanmoy Deb. Multiobjective optimization us<strong>in</strong>g nondom<strong>in</strong>ated sort<strong>in</strong>g<strong>in</strong> genetic algorithms. Evolutionary Computation, 2:221–248, 1994. http://www.lania.mx/%7Eccoello/deb95.ps.gz.[39] Berw<strong>in</strong> A Turlach. Quadprog, (quadratic programm<strong>in</strong>g rout<strong>in</strong>es). http://www.maths.uwa.edu.au/~berw<strong>in</strong>/software/quadprog.html.[40] Wikipedia. Ampl (programm<strong>in</strong>g language). http://en.wikipedia.org/wiki/AMPL_programm<strong>in</strong>g_language.[41] Wikipedia. General algebraic model<strong>in</strong>g system. http://en.wikipedia.org/wiki/General_Algebraic_Model<strong>in</strong>g_System.[42] Wikipedia. Mps (format). http://en.wikipedia.org/wiki/MPS_(format).[43] Wikipedia. Simulated anneal<strong>in</strong>g. http://en.wikipedia.org/wiki/Simulated_anneal<strong>in</strong>g.[44] Patrick Siarry Yann Collette. Optimisation Multiobjectif. Eyrolles, Collection Algorithmes,1999.69

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!