The SAS/OR s OPTMODEL Procedure :

Similar documents
Chapter 1 Introduction to Optimization

Chapter 1 Introduction to Optimization

Chapter 1 Introduction to Optimization

Using the OPTMODEL Procedure in SAS/OR to Solve Complex Problems. Rob Pratt, Senior R&D Manager, SAS/OR

The Decomposition Algorithm

Simulation. Lecture O1 Optimization: Linear Programming. Saeed Bastani April 2016

NOTATION AND TERMINOLOGY

LP SCIP NEOS URL. example1.lp 2.1 LP 1. minimize. subject to, bounds, free, general, binary, end. .lp 1 2.2

Linear Programming. Linear programming provides methods for allocating limited resources among competing activities in an optimal way.

SAS/OR 12.3 User s Guide. Mathematical Programming Examples

The MIP-Solving-Framework SCIP

Contents. Introduction

Linear Programming with Bounds

SAS/OR 14.2 User s Guide: Mathematical Programming. The OPTMILP Procedure

3 INTEGER LINEAR PROGRAMMING

Outline. Modeling. Outline DMP204 SCHEDULING, TIMETABLING AND ROUTING. 1. Models Lecture 5 Mixed Integer Programming Models and Exercises

Agenda. Understanding advanced modeling techniques takes some time and experience No exercises today Ask questions!

Optimieren mit MATLAB jetzt auch gemischt-ganzzahlig Dr. Maka Karalashvili Application Engineer MathWorks

Introduction to CPLEX. Some very convenient solvers for most students include those with Excel and Matlab.

Using SAS/OR to Optimize Scheduling and Routing of Service Vehicles

Using the OPTMODEL Procedure in SAS/OR to Solve Complex Problems

Department of Mathematics Oleg Burdakov of 30 October Consider the following linear programming problem (LP):

SAS/OR 14.2 User s Guide: Mathematical Programming. The Quadratic Programming Solver

New Features in SAS/OR 13.1

SAS/OR 9.2 User s Guide. Local Search Optimization

SAS/OR 13.2 User s Guide: Mathematical Programming. The OPTLP Procedure

APPLICATION OF FUZZY REGRESSION METHODOLOGY IN AGRICULTURE USING SAS

Introduction. Chapter 15. Optimization Modeling: Applications. Integer Programming. Manufacturing Example. Three Types of ILP Models

Read: H&L chapters 1-6

Linear and Integer Programming :Algorithms in the Real World. Related Optimization Problems. How important is optimization?

Tools for Modeling Optimization Problems A Short Course. Algebraic Modeling Systems. Dr. Ted Ralphs

Introduction to Mathematical Programming IE406. Lecture 9. Dr. Ted Ralphs

SAS/OR 14.3 User s Guide. Mathematical Programming. The OPTQP Procedure

Prepared By. Handaru Jati, Ph.D. Universitas Negeri Yogyakarta.

COMP9334: Capacity Planning of Computer Systems and Networks

Section Notes 4. Duality, Sensitivity, and the Dual Simplex Algorithm. Applied Math / Engineering Sciences 121. Week of October 8, 2018

Advanced Operations Research Techniques IE316. Lecture 10. Dr. Ted Ralphs

Fundamentals of Integer Programming

Linear Programming. Slides by Carl Kingsford. Apr. 14, 2014

OPTIMIZATION. joint course with. Ottimizzazione Discreta and Complementi di R.O. Edoardo Amaldi. DEIB Politecnico di Milano

Algorithms for Decision Support. Integer linear programming models

A Nonlinear Presolve Algorithm in AIMMS

Unit.9 Integer Programming

MILP. LP: max cx ' MILP: some integer. ILP: x integer BLP: x 0,1. x 1. x 2 2 2, c ,

Introduction to Linear Programming. Algorithmic and Geometric Foundations of Optimization

Benders in a nutshell Matteo Fischetti, University of Padova

CMSC 451: Linear Programming

Package Rglpk. May 18, 2017

Linear Programming Problems

Solving Large-Scale Energy System Models

LocalSolver 4.0: novelties and benchmarks

Notes on the IFPRI Spatial Production Allocation NLP Model

Best practices for using the multistart algorithm in AIMMS. Marcel Hunting AIMMS Optimization Specialist

Exact solutions to mixed-integer linear programming problems

MPL Modeling System. Release 4.2

MATHEMATICS II: COLLECTION OF EXERCISES AND PROBLEMS

Section Notes 5. Review of Linear Programming. Applied Math / Engineering Sciences 121. Week of October 15, 2017

Notes on AMPL for and (Adapted from notes by Sommer Gentry)

Introduction to AMPL (Math 464, Spring 2018)

AMPL Integer Linear Programming And Sensitivity Analysis for LP. ORLAB Operations Research Laboratory. Borzou Rostami. Politecnico di Milano, Italy

Welcome to the Webinar. What s New in Gurobi 7.5

SAS/OR 15.1 User s Guide. Local Search Optimization. The OPTLSO Procedure

GAMS. How can I make this work... arrgghh? GAMS Development Corporation

Computer Laboratories: Mathematical Formulation and Implementation in GAMS. S. Vitali Charles University. 3/15/2017 Copyright 2017 S.

Mixed Integer Programming Class Library (MIPCL)

Strategies for Using Algebraic Modeling Languages to Formulate Second-Order Cone Programs

Math Models of OR: The Simplex Algorithm: Practical Considerations

INEN 420 Final Review

Crash-Starting the Simplex Method

Math 464 (Spring 2007) Introduction to AMPL

Column Generation Method for an Agent Scheduling Problem

AM 121: Intro to Optimization Models and Methods Fall 2017

Outline. CS38 Introduction to Algorithms. Linear programming 5/21/2014. Linear programming. Lecture 15 May 20, 2014

Process Optimization

Heuristics in MILP. Group 1 D. Assouline, N. Molyneaux, B. Morén. Supervisors: Michel Bierlaire, Andrea Lodi. Zinal 2017 Winter School

SAS/OR 9.2 User s Guide. Bill of Material Processing

optlang Documentation

AIMMS Function Reference - GMPInstance Procedures and Functions

lpsymphony - Integer Linear Programming in R

Gurobi Guidelines for Numerical Issues February 2017

LPL: Product Description

56:272 Integer Programming & Network Flows Final Examination -- December 14, 1998

Civil Engineering Systems Analysis Lecture XV. Instructor: Prof. Naveen Eluru Department of Civil Engineering and Applied Mechanics

Pivot and Gomory Cut. A MIP Feasibility Heuristic NSERC

Free modelling languages for linear and integer programming

Introduction to Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Advanced Use of GAMS Solver Links

Linking GAMS to Solvers Using COIN-OSI. Michael Bussieck Steve Dirkse GAMS Development Corporation

Integer Programming! Using linear programming to solve discrete problems

AMPL Integer Linear Programming. ORLAB Operations Research Laboratory. Borzou Rostami. Politecnico di Milano, Italy.

Solving Scenarios in the Cloud

Tutorial on CPLEX Linear Programming

Parallelizing the dual revised simplex method

INTERIOR-POINT LINEAR PROGRAMMING SOLVERS

Using COIN-OR to Solve the Uncapacitated Facility Location Problem

SOLVING BUSINESS PROBLEMS WITH SAS ANALYTICS AND OPTMODEL

Building a Custom Solver with the COIN-OR Branch, Cut, and Price Frameworks

Working Under Feasible Region Contraction Algorithm (FRCA) Solver Environment

SAS/OR 14.1 User s Guide: Mathematical Programming. The Mixed Integer Linear Programming Solver

SUBSTITUTING GOMORY CUTTING PLANE METHOD TOWARDS BALAS ALGORITHM FOR SOLVING BINARY LINEAR PROGRAMMING

Transcription:

The SAS/OR s OPTMODEL Procedure : A Powerful Modeling Environment for Building, Solving, and Maintaining Mathematical Optimization Models Maurice Djona OASUS - Wednesday, November 19 th, 2008

Agenda Context: Why Proc OPTMODEL? Defining Mathematical Optimization Problems Classification of Optimization Problems Examples of the use of Mathematical Optimization SAS Procedures for solving optimization problems Proc OPTMODEL Introduction Proc OPTMODEL Syntax Proc OPTMODEL Examples Proc OPTMODEL vs. Proc OPTLP Conclusion How to Get Started? 2

Context: Why Proc OPTMODEL? Redevelopment of some survey processing systems that use mathematical optimization, at Statistics Canada Too costly to reinvent the wheel by developing our own optimization module Searched for an optimization software package taking into account: - Performance, -Cost, - Ease of use, - Support - Integration with existing systems SAS/OR s Proc OPTMODEL was selected among several possibilities This presentation focuses on mathematical optimization and Proc OPTMODEL 3

Defining Mathematical Optimization Problems General form of optimization problems: Min OR Max f(x) Subject to c i (x) {, =, } b i (i = 1, 2,, m) l j x j u j (j = 1, 2,, n) Where: x is the set of decision variables x 1, x 2,, x N f(x) is an objective function (ex. f = x 1 + 2x 2 ) c i (x) are the constraints on the variables x (ex. x 1 + 3x 2 5) l j and u j are lower and upper bounds on variables x (ex. 2 x 1 6) 4

Classification of Mathematical Optimization Problems LP (Linear Programming): f(x) and c i (x) are linear functions, all x are real numbers ILP (Integer Linear Programming): f(x) and c i (x) are linear functions, all x are integers MILP (Mixed-Integer Linear Programming): f(x) and c i (x) are linear functions, at least some x must be integers, while other x may be real NLP (Non Linear Programming): f(x) and c i (x) are continuous, but at least some of them must be non linear functions (ex. f = x 1 + x 2 * x 3 ) 5

Examples of Use of Mathematical Optimization Examples of typical use include: Facility Location Production Planning Workforce Planning Product Distribution Delivery Network Configuration Investment Planning Inventory Replenishment Planning Retail Pricing SAS solutions using optimization: SAS Marketing Optimization SAS Revenue Optimization Suite SAS Size Optimization SAS Inventory Optimization, SAS Service Parts Optimization SAS Credit Risk Management Two examples of particular use at Statistics Canada: Banff system: Edit and Imputation of survey data CONFID system: Minimization of information lost while suppressing sensitive survey data before publication 6

Examples of Optimization Problems A LP (Linear Programming) problem: max x 1 + x 2 + x 3 subject to 3x 1 + 2x 2 - x 3 1-2x 1-3x 2 + 2x 3 1 x 1 0, x 2 0, x 3 0 A NLP (Non Linear Programming) problem: max x 1 * x 2 * x 3 subject to 3x 1 + 2x 2 - x 3 1-2x 1-3x 2 + 2x 3 1 x 1 0, x 2 0, x 3 0 LPs solved in CONFID at Statistics Canada: Number of variables: dozens to 200 000 Number of constraints: dozens to 50 000 Non-zero constraint coefficients: hundreds to 300 000 7

Software Packages for Solving Optimization Problems Commercial packages include: - CPLEX (ILOG) - XPRESS (Dash Optimization) - Many procedures of SAS/OR (SAS Institute) -etc. Free packages include: - GLPK (GNU Linear Programming Kit) - lp_solve -etc. 8

SAS Procedures for Solving Optimization Problems Proc OPTMODEL (SAS/OR 9.1.3 User s Guide: Mathematical Programming 3.2) 9

OPTMODEL Procedure - Introduction Introduced with SAS/OR version 9.1.3 Provides a modeling environment tailored to building, solving, and maintaining optimization models Powerful modeling language mimics symbolic algebra Building optimization models is virtually transparent Simplifies population of models by reading data from SAS data sets, and creates SAS data sets from the models Bottom line: with Proc OPTMODEL, models are - more easily built, - more easily inspected for completeness and correctness, - more easily corrected, - more easily modified, and - manipulated mainly in memory less I/O higher efficiency 10

OPTMODEL Procedure - Introduction (cont.) OPTMODEL can be used to : Build and solve models Build models that are then solved using other SAS/OR procedures (or non SAS solvers as CPLEX, XPRESS, GLPK, ) Seven solvers are available in OPTMODEL to solve models: Problem Linear Programming Mixed Integer Programming Quadratic Programming Nonlinear Programming, Unconstrained General Nonlinear Programming General Nonlinear Programming General Nonlinear Programming Solver LP MILP QP (experimental) NLPU NLPC SQP IPNLP (experimental) OPTMODEL more friendly interface to various optimization solvers 11

OPTMODEL Procedure Some Elements of Syntax PROC OPTMODEL options ; Declaration Statements: CONSTRAINT constraints ; MAX objective ; MIN objective ; NUMBER parameter declarations ; STRING parameter declarations ; SET [ < types > ] parameter declarations ; VAR variable declarations ; Programming Statements parameter = expression ; (Assignment) CALL name [ ( expressions ) ] ; CLOSEFILE files ; CONTINUE ; CREATE DATA SAS-data-set FROM columns ; DO ; statements ; END ; DO variable = specifications; statements ; END; DO UNTIL ( logic ) ; statements ; END ; DO WHILE ( logic ) ; statements ; END ; DROP constraint ; EXPAND name [ / options ] ; FILE file ; FIX variable [ = expression ] ; Quit; FOR { index set } statement; IF logic THEN statement ; [ ELSE statement ; ] LEAVE ; PRINT print items ; PUT put items ; READ DATA SAS-data-set INTO columns ; RESET OPTIONS options ; RESTORE constraint ; SAVE MPS SAS-data-set ; SAVE QPS SAS-data-set ; SOLVE [ WITH solver ] [ OBJECTIVE name ] [ / options ; STOP ; UNFIX variable [ = expression ] ; Plus: Powerful expressions for sets manipulation OPTMODEL A complete programming environment, may be preferred to data step in some cases 12

OPTMODEL Procedure: Example A simple LP problem: max x 1 + x 2 + x 3 subject to 3x 1 + 2x 2 - x 3 1-2x 1-3x 2 + 2x 3 1 x 1 0, x 2 0, x 3 0 /* Linear Problem using named parameters and variables*/ PROC OPTMODEL; VAR x1 >= 0, x2 >= 0, x3 >= 0; /*Declare variables, & set bounds*/ MAX f = x1 + x2 + x3 ; /* Objective function*/ CONSTRAINT c1: 3*x1 + 2*x2 - x3 <= 1; /* Constraint*/ CONSTRAINT c2: -2*x1-3*x2 + 2*x3 <= 1; /* Constraint*/ SOLVE WITH LP OBJECTIVE f; /* Solve; */ /* Solve model using LP solver */ PRINT x1 x2 x3; /* Print the solution */ QUIT; 13

OPTMODEL Procedure: Example (cont.) SAS output windows The OPTMODEL Procedure Problem Summary Objective Sense Maximization Objective Function f Objective Type Linear Number of Variables 3 Bounded Above 0 Bounded Below 3 Bounded Below and Above 0 Free 0 Fixed 0 Number of Constraints 2 Linear LE (<=) 2 Linear EQ (=) 0 Linear GE (>=) 0 Linear Range 0 Solution Summary Solver Dual Simplex Objective Function f Solution Status Optimal Objective Value 8 Iterations 3 Primal Infeasibility 0 Dual Infeasibility 0 Bound Infeasibility 0 x1 x2 x3 0 3 5 14

OPTMODEL Procedure: Example (cont.) /* Non Linear Problem using named parameters and variables */ PROC OPTMODEL; VAR x1 >= 0, x2 >= 0, x3 >= 0; /*Declare variables, & set bounds*/ MAX f = x1 * x2 * x3 ; /* Objective function: Non Linear*/ CONSTRAINT c1: 3*x1 + 2*x2 - x3 <= 1; /* Constraint*/ CONSTRAINT c2: -2*x1-3*x2 + 2*x3 <= 1; /* Constraint*/ SOLVE WITH NLPC OBJECTIVE f; /*Solve;*/ /* Solve model using NLPC solver */ PRINT x1 x2 x3; /* Print the solution */ QUIT; The OPTMODEL Procedure Solution Summary Solver NLPC/Trust Region Objective Function f Solution Status Optimal Objective Value 1.8951890412 Iterations 6 Absolute Optimality Error 1.2305578E-8 Relative Optimality Error 1.8366968E-9 Absolute Infeasibility 8.326673E-16 Relative Infeasibility 4.163336E-16 x1 x2 x3 0.28287 1.8685 3.5856 15

16 OPTMODEL Procedure: Example (cont.) /* Linear problem using indexes for parameters and variables (Indexing like arrays in the DATA STEP, but much more flexible) */ PROC OPTMODEL; NUMBER NbVar INIT 3; VAR x{j IN 1.. NbVar} >= 0; MAX f = SUM{j IN 1..NbVar} x[j]; CONSTRAINT c1: 3*x[1] + 2*x[2] - /*Number of variables*/ /*Declare variables, & set bounds*/ /* Objective function*/ x[3] <= 1; /* Constraint*/ CONSTRAINT c2: -2*x[1] - 3*x[2] + 2*x[3] <= 1; /* Constraint*/ SOLVE WITH LP OBJECTIVE f; /* Solve model using LP solver */ PRINT x; /* Print the solution */ QUIT; The OPTMODEL Procedure Solution Summary Solver Dual Simplex Objective Function f Solution Status Optimal Objective Value 8 Iterations 3 Primal Infeasibility 0 Dual Infeasibility 0 Bound Infeasibility 0 [1] x 1 0 2 3 3 5

OPTMODEL Procedure: Example (cont.) Read model data from data sets max x 1 + x 2 + x 3 subject to 3x 1 + 2x 2 - x 3 1-2x 1-3x 2 + 2x 3 1 x 1 0, x 2 0, x 3 0 /* Objective coefficients data set */ DATA objcoefds; INPUT varid objcoef; DATALINES; 1 1 2 1 3 1 ; RUN; /* Constraints comparison operator (L, E or H) & right hand side data set */ DATA rhsds; INPUT constrid rhs comp $1.; DATALINES; 1 1 L 2 1 L ; RUN; /* Constraint coefficients data set */ DATA constrds; INPUT constrid varid ConstrCoef; DATALINES; 1 1 3 1 2 2 1 3-1 2 1-2 2 2-3 2 3 2 ; RUN; 17

OPTMODEL Procedure: Example (cont.) /* Read model data from data sets: more indexing*/ PROC OPTMODEL; SET<NUMBER> varindex; /*Set of indexes of variables*/ NUMBER mobjcoef{varindex}; /*Array of objective function coefficients values*/ SET<NUMBER, NUMBER> constrcoefloc; /*Set of indexes (tuples) of constraint coefficients*/ NUMBER mconstrcoef{constrcoefloc}; /*Array of constraint coefficients values*/ SET<NUMBER> constrindex; /*Set of indexes of constraints*/ NUMBER mrhs{constrindex}; /*Array of right hand side values*/ STRING mcomp{constrindex}; /*Array for comparison operators: L (lower), E(equal) or H (higher) */ /* Read variables indexes and objective function coefficients from data set*/ READ DATA objcoefds INTO varindex = [varid] mobjcoef = objcoef; Data set s variable OPTMODEL s array /* Read constraint coefficients from data set*/ READ DATA constrds INTO constrcoefloc = [constrid varid] mconstrcoef = ConstrCoef; /* Read rhs from data set*/ READ DATA rhsds INTO constrindex = [constrid] mcomp = comp mrhs = rhs; /*Declare variables, objective function and constraints*/ VAR x{j IN varindex} >= 0; MAX f = SUM{j IN varindex} mobjcoef[j]*x[j]; CONSTRAINT cl{i IN constrindex: mcomp[i]= L }: (SUM{<(i), j> IN constrcoefloc} mconstrcoef[i, j]*x[j]) <= mrhs[i]; CONSTRAINT ce{i IN constrindex: mcomp[i]= E }: (SUM{<(i), j> IN constrcoefloc} mconstrcoef[i, j]*x[j]) = mrhs[i]; CONSTRAINT ch{i IN constrindex: mcomp[i]= H }: (SUM{<(i), j> IN constrcoefloc} mconstrcoef[i, j]*x[j]) >= mrhs[i]; EXPAND/SOLVE; /*Print model in algebraic form*/ SOLVE WITH LP OBJECTIVE f; /*Solve model using LP solver*/ PRINT x; /*Print solution*/ CREATE DATA results FROM [var]=varindex value=x; /* Write solution to data set*/ QUIT; NB: Possibility to modify and re-solve the problem in memory without leaving OPTMODEL (loops). 18

OPTMODEL Procedure: Example (cont.) The OPTMODEL Procedure Var x[1] >= 0 Var x[2] >= 0 Var x[3] >= 0 Maximize f=x[1] + x[2] + x[3] Constraint c[1]: 3*x[1] + 2*x[2] - x[3] <= 1 Constraint c[2]: - 2*x[1] - 3*x[2] + 2*x[3] <= 1 Solution Summary Solver Dual Simplex Objective Function f Solution Status Optimal Objective Value 8 Iterations 3 Primal Infeasibility 0 Dual Infeasibility 0 Bound Infeasibility 0 [1] x 1 0 2 3 3 5 19

OPTMODEL Procedure: Example (cont.) Creating data sets from the model Arrays in OPTMODEL /* Write solution to data set*/ CREATE DATA results FROM [var]=varindex value=x; Data Set Variables PROC PRINT DATA=results; TITLE "Results data set created in Proc OPTMODEL"; RUN; Results data set created in Proc OPTMODEL Obs var value 1 1 0 2 2 3 3 3 5 20

OPTMODEL vs. OPTLP: MPS Format Proc OPTLP requires models in SAS data set, in MPS format MPS format: an industry standard, but not user friendly Use Proc OPTMODEL to create MPS format data set required by OPTLP: PROC OPTMODEL; VAR x1 >= 0, x2 >= 0, x3 >= 0; /*Declare variables, and set bounds*/ MAX f = x1 + x2 + x3 ; /* Objective function*/ CON c1: 3*x1 + 2*x2 - x3 <= 1; /* Constraint*/ CON c2: -2*x1-3*x2 + 2*x3 <= 1; /* Constraint*/ QUIT; /*Save model in MPS format to be solved outside OPTMODEL */ SAVE MPS model_mps; PROC PRINT DATA=model_mps; TITLE "Model in MPS format"; RUN; 21

OPTMODEL vs. OPTLP: MPS Format Model in MPS format data set required by Proc OPTLP Model in MPS format Obs FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 1 NAME model_mp.. 2 ROWS.. 3 MAX f.. 4 L c1.. 5 L c2.. 6 COLUMNS.. 7 x1 f 1 c1 3 8 x1 c2-2. 9 x2 f 1 c1 2 10 x2 c2-3. 11 x3 f 1 c1-1 12 x3 c2 2. 13 RHS.. 14.RHS. c1 1. 15.RHS. c2 1. 16 ENDATA.. 22 NB: Models in MPS format (text file) can also be solved by non-sas solvers such as CPLEX, XPRESS, GLPK, etc.

OPTMODEL vs. OPTLP: MPS Format Solve the model using Proc OPTLP: PROC OPTLP DATA=model_mps PRIMALOUT = optlp_sol; /*Solution data set*/ RUN; PROC PRINT DATA=optlp_sol; TITLE "Solution from OPTLP"; RUN; Solution data set created by Proc OPTLP (selected fields): Solution from OPTLP Obs _OBJ_ID VAR TYPE OBJCOEF VALUE_ 1 f x1 N 1 0 2 f x2 N 1 3 3 f x3 N 1 5 23

Conclusion Proc OPTMODEL: Thanks to its powerful programming language, facilitates building and maintaining optimization models Models data reside in memory and can be more easily manipulated less I/O higher efficiency Has access to many SAS/OR optimization solvers Facilitates building models to be solved outside OPTMODEL, including by non-sas solvers. 24

How to Get Started? By yourself: SAS/OR 9.1.3 User s Guide: Mathematical Programming 3.2 Chapter 6: The OPTMODEL Procedure SAS Course: Building and Solving Optimization Models with SAS/OR (Mainly focused on Proc OPTMODEL) I found this course very useful! 25

Questions / Comments Statistics Canada Statistique Canada Maurice Djona Programmer/Analyst, SAS Technology Centre System Development Division R.H. Coats Building, 14th Floor, Section Q Ottawa, Ontario, Canada K1A 0T6 (613) 951-5331 Fax (613) 951-0607 Maurice.Djona@statcan.gc.ca Canada 26