Lab 1 Mathematical Programming OPER 631 Virginia Commonwealth University Fall 2006 Due: Wednesday, September 27, 2006 There are two main objectives for this lab: (1) learn how to submit math programming problems to the NEOS Server using AMPL-formatted files and retrieve the output, and (2) begin learning how to take advantage of Matlab functions and scripting capabilities to develop routines for solving math programs. The first two sections describe the assignments for this lab concerning the NEOS Server and Matlab, respectively. The last two sections provide references for support for AMPL/NEOS Server and Matlab, respectively. 1 NEOS Server and AMPL The NEOS Server can be accessed at http://www-neos.mcs.anl.gov/. Users are able to submit virtually all types of math programs in a variety of formats for solution by industry-standard solvers on machines donated by a handful of sources. Aside from a few user-specified options, the user has little control over the behavior of the solvers; therefore, the server is most useful in simply obtaining an answer to a math program and in comparing the quality of solutions. The server is generally not a viable means for developing solution techniques. Most of the solvers available on the NEOS Server take AMPL files as input. AMPL, A Mathematical Programming Language, is a modeling language that facilitates the translation of a math program on paper into a form acceptable to solver software. Our goals for this lab are to refresh our memories about AMPL file format and to become comfortable with the submission process for the NEOS Server. • Re-familiarize yourself with the AMPL language by looking at the model and data files for the diet problem on the AMPL website (http://www.ampl.com/EXAMPLES/index.html). A math program consists of decision variables, an objective function, and constraints. When translating a math program into AMPL modeling language, a general rule of thumb is to create one set for each type of variable and one set for each type of constraint. Parameters are defined as vectors or matrices and usually represent coefficients on the variables or functions of the variables. The .mod file consists of the models in general form, while the .dat file defines the sets and parameter values that specify a particular instance. Download the diet problem files to your computer, and submit them to at least two solvers on NEOS that accept AMPL files. From the NEOS Server home page, click on “NEOS Solvers”. Does the output differ among the solvers? • Consider the paper: FJ Vasko and KJ Stott, “Optimizing Continuous Caster Product Dimensions: An Example of a Nonlinear Design Problem in the Steel Industry” SIAM Review 37:82-84, 1995. Compare the models in the paper with the models csfi1.mod and csfi2.mod on Robert Vanderbei’s page of nonlinear AMPL examples arising from applications http://www.sor.princeton.edu/ rvdb/ampl/nlmodels/index.html. The problems are in the directory labeled “Cute Set” because they are part of the CUTE test problem set (see Section 4). Download the models to your machine. What do the CUTEr classifications say about the nature of the math programs? Submit them to at least two solvers on NEOS that accept AMPL files. Do the solvers return the same solution? What are the options on the solvers that can be adjusted? What is the best solution that you can find? • Formulate linear regression as a math programming problem (refer to your homework). After writing the model on paper, write a model file that can accommodate any appropriate data set. (Hint: you should have one ‘set’ to index the observations, two vectors of ‘parameters’ to record the x and y measurements for the observations, and two ‘variables’ - one for slope and one for the y-intercept.) Select two real-world data sets to analyze. The Math Forum at Drexel University has data sets available at http://mathforum.org/workshops/sum96/data.collections/datalibrary/data.set6.html Follow the remainder of the directions on your homework assignment. 2 Matlab MATLAB stands for “matrix laboratory” and began as a tool for matrix computations. The software has since evolved to accommodate many branches of mathematics. Matlab now has sophisticated graphical capabilities and is able to interface with a variety of other programs and programming languages. Our goal for this lab is to be able to code a gradient method algorithm for single-variable unconstrained math programs. • Browse through the “Getting Started” portion of the Matlab manual and familiarize yourself with the handling of matrices. Find the function for calculating the eigenvalues of a matrix. Calculate the eigenvalues for the following matrix. 3 2 1 3 3 0 0 1 3 Is the matrix positive definite, positive semidefinite, negative definite, negative semidefinite, or none of the above? • Read the section on M-files under “Working with Matrices”. Write an M-file (use any text editor) that defines the matrix above and calculates its eigenvalues. Note that if you end a command with a semicolon (;), the output of the command is printed out. If you leave the semicolon off, the output is printed to the screen. • Read the section called “Functions” under “Programming”. A function is an M-file that accepts input and can produce output. The first line in an M-file for a function has the following general form. function [<output1>, <output2>, . . . ] = <function name> (<input1>, <input2>, . . . ); where <output1>, etc. are the outputs of the function, <function name> is the name of the function, and <input1>, etc. are the inputs to the function. The inputs and outputs of a function can be scalars, vectors, or matrices. A definition of a function that finds the global minimum point and the function value at the global minimum point for a polynomial function defined in a file might have the following definition function [optimal x, optimal f] = minimize (function filename, solution method, maximum iterations, tolerance); Write a function that accepts a matrix as input and returns a message that the matrix is positive definite, positive semidefinite, negative definite, negative semidefinite, or none of the above. • Now write a function that implements the gradient method for single-variable unconstrained math programs. Use your function to find all of the local minima of the following function f (x) = x4 /4 − 2x3 − x2 /2 + 2x + 2 3 More help on NEOS Server and AMPL • The NEOS Server for Optimization can be accessed at http://www-neos.mcs.anl.gov. A list of the solvers available is at http://neos.mcs.anl.gov/neos/solvers/index.html. The NEOS guide to optimization software (including and beyond what is available on the server) is at http://www-fp.mcs.anl.gov/otc/Guide/SoftwareGuide/index.html. • CUTEr is a Constrained and Unconstrained Testing Environment, revisited. It includes routines for developing nonlinear programming solvers and a large set of test problems. The tools are only available on Unix/Linux, but we will take advantage of the test problems. A list of the problems is at http://www.numerical.rl.ac.uk/cute/mastsif.html, and the classification scheme is described at http://cuter.rl.ac.uk/cuter-www/Problems/classification.shtml. A selection tool for the CUTE problems whereby the user can search for problems meeting certain criteria is available from Rolf Felkel at http://numawww.mathematik.tu-darmstadt.de:8081/opti/select.html. • Several application problems including many of the CUTE problems are available in AMPL format on Robert Vanderbei’s website at http://www.sor.princeton.edu/ rvdb/ampl/nlmodels/index.html. • The Netlib test problem set is available in AMPL format at http://www.netlib.org/ampl/models/. • Linear, integer, and network programming examples in AMPL are available on the AMPL website at http://www.ampl.com/EXAMPLES/index.html. 4 More help on Matlab • The Matlab helpdesk is online at http://www.mathworks.com/access/helpdesk/help/techdoc/. • A Matlab function reference by category can be found at http://www.mathworks.com/access/helpdesk/help/techdoc/ref/index.html. • Octave, an open source software “mostly compatible” with Matlab, is available at http://www.gnu.org/software/octave/. • Many tutorials are available on the web; however, I think the Matlab help manual should be sufficient for our purposes.