A Gentle Introduction to COIN-OR s Optimization Solver Interface (OSI) Resources and Examples CORS/INFORMS Banff 2004

Similar documents
CPLEX Tutorial Handout

Mixed Integer Linear Programming in R

Cloud Branching. Timo Berthold. joint work with Domenico Salvagnin (Università degli Studi di Padova)

How to speed-up hard problem resolution using GLPK?

Using GMPL/GLPK for IE 1079/2079

IBM ILOG CPLEX Optimization Studio Getting Started with CPLEX. Version12Release4

IBM ILOG CPLEX for Microsoft Excel User's Manual

Using CPLEX. =5 has objective value 150.

An Incomplete C++ Primer. University of Wyoming MA 5310

Noncommercial Software for Mixed-Integer Linear Programming

Adaptive Stable Additive Methods for Linear Algebraic Calculations

AIMMS 4.0. Portable component Linux Intel version. Release Notes for Build 4.9. Visit our web site for regular updates AIMMS

Using EXCEL Solver October, 2000

Visual C Tutorial

Chapter 6: Sensitivity Analysis

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

TECH TUTORIAL: EMBEDDING ANALYTICS INTO A DATABASE USING SOURCEPRO AND JMSL

Image Acquisition Toolbox Adaptor Kit User's Guide

Introduction to Scientific Computing Part II: C and C++ C. David Sherrill School of Chemistry and Biochemistry Georgia Institute of Technology

A numerically adaptive implementation of the simplex method

The Gurobi Optimizer

Virtuozzo Virtualization SDK

An Overview Of Software For Convex Optimization. Brian Borchers Department of Mathematics New Mexico Tech Socorro, NM

Chapter 6. Linear Programming: The Simplex Method. Introduction to the Big M Method. Section 4 Maximization and Minimization with Problem Constraints

Help File. Version February, MetaDigger for PC

Learning Module 4 - Thermal Fluid Analysis Note: LM4 is still in progress. This version contains only 3 tutorials.

Routing in Line Planning for Public Transport

Using diversification, communication and parallelism to solve mixed-integer linear programs

ADF Code Corner. 92. Caching ADF Web Service results for in-memory filtering. Abstract: twitter.com/adfcodecorner

IEOR 4404 Homework #2 Intro OR: Deterministic Models February 14, 2011 Prof. Jay Sethuraman Page 1 of 5. Homework #2

Branch, Cut, and Price: Sequential and Parallel

AIMMS User s Guide - Math Program Inspector

BlueJ Teamwork Tutorial

Computational aspects of simplex and MBU-simplex algorithms using different anti-cycling pivot rules

OPENRULES. Getting Started. Open Source Business Decision Management System. Release OpenRules, Inc.

Integer Set Library: Manual

Building an Embedded Processor System on a Xilinx Zync FPGA (Profiling): A Tutorial

Re-optimization of Rolling Stock Rotations

Microsoft Access 2007

Table of Contents. The RCS MINI HOWTO

MySQL Connector/C++ Developer Guide

Journal of Statistical Software

Creating a Database in Access

sqlite driver manual

Tutorial Overview Quick Tips on Using the ONRR Statistical Information Website

Linear Program Solver

Coding conventions and C++-style

Running your first Linux Program

Copyright Bizagi. Change Management Construction Document Bizagi Process Modeler

Create a New Database in Access 2010

CP Lab 2: Writing programs for simple arithmetic problems

DE4 NetFPGA Packet Generator Design User Guide

Basics of I/O Streams and File I/O

C++ Overloading, Constructors, Assignment operator

4.6 Linear Programming duality

gbuild: State of the LibreOffice build system

Rational Team Concert. Quick Start Tutorial

INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3

Introduction to HP ArcSight ESM Web Services APIs

Welcome to GAMS 1. Jesper Jensen TECA TRAINING ApS This version: September 2006

Analysis of Micro-Macro Transformations of Railway Networks

Storage and linkage specifiers

Solving convex MINLP problems with AIMMS

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

Chapter 10: Network Flow Programming

Simplex method summary

Basic SQL Server operations

Using Visual C++ and Pelles C

OpenSolver: Open Source Optimisation for Excel

A Constraint Programming based Column Generation Approach to Nurse Rostering Problems

Code::Blocks Student Manual

Netscape Internet Service Broker for C++ Programmer's Guide. Contents

7. LU factorization. factor-solve method. LU factorization. solving Ax = b with A nonsingular. the inverse of a nonsingular matrix

SQLITE C/C++ TUTORIAL

An API for Reading the MySQL Binary Log

How To Use Optimum Control EDI Import. EDI Invoice Import. EDI Supplier Setup General Set up

Xcode Project Management Guide. (Legacy)

URI and UUID. Identifying things on the Web.

MPLAB X + CCS C Compiler Tutorial

GIVE WINGS TO YOUR IDEAS TUTORIAL

Creating a Java application using Perfect Developer and the Java Develo...

SAS Marketing Optimization. Windows Installation Instructions for Hot Fix 51mo14

Creating OpenGL applications that use GLUT

Guidelines and Procedures for Project Management

LECTURE 5: DUALITY AND SENSITIVITY ANALYSIS. 1. Dual linear program 2. Duality theory 3. Sensitivity analysis 4. Dual simplex method

Application Note: AN00141 xcore-xa - Application Development

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

Facebook Twitter YouTube Google Plus Website

Improve Fortran Code Quality with Static Analysis

GAMS, Condor and the Grid: Solving Hard Optimization Models in Parallel. Michael C. Ferris University of Wisconsin

Microsoft Excel Introduction to Microsoft Excel 2007

EXCEL SOLVER TUTORIAL

Pendragon Forms Industrial

E x c e l : Data Analysis Tools Student Manual

Outside In Image Export Technology SDK Quick Start Guide

How To Deploy Office 2016 With Office 2016 Deployment Tool

Using Git for Project Management with µvision

Expedite for Windows Software Development Kit Programming Guide

Chapter 13: Binary and Mixed-Integer Programming

Reduced echelon form: Add the following conditions to conditions 1, 2, and 3 above:

Transcription:

A Gentle Introduction to COIN-OR s Optimization Solver Interface (OSI) Resources and Examples CORS/INFORMS Banff 2004 June 2, 2004 Note: This document is intended as a reference aid. The material is not presented in the same order as the presentation. 1 Web resources COIN-OR website: www.coin-or.org COIN-OR tutorials site: http://sagan.ie.lehigh.edu/coin/ C++ Annotations by Frank B. Brokken; intended for people who know C and want to learn C++. http://www.icce.rug.nl/documents/cplusplus/cplusplus.html C/C++ Reference, http://www.cppreference.com/ 2 Getting help with OSI We want to help make your use of OSI successful! First review the appropriate documentation the answer may be there. Send email to coin-discuss@www-124.ibm.com. This address is likely to change soon check www.coin-or.org before sending. In your email, give as much detail as you can: Operating system COIN-OR modules (OSI, CLP, etc.) Solvers Error messages 1

3 Optimization Solver Interface (OSI) Uniform interface to LP/IP solvers: CLP (COIN-OR) CPLEX (ILOG) DyLP (BonsaiG LP Solver) GLPK (GNU LP Kit) OSL (IBM) SoPlex (Konrad-Zuse-Zentrum für Informationstechnik Berlin) Volume (COIN-OR) XPRESS (Dash Optimization) Mosek interface is written and will enter the repository soon 4 Procedures 4.1 Steps to prepare OSI 1. Download source code 2. Configure based on available solvers 3. Compile 4. Create a makefile for your project (optional) 5. Use OSI in your code 4.2 Downloading, configuring, and compiling OSI Download tarball from www.coin-or.org: Osi 2003Oct17.tgz. You may also want Osi-doc 2003Oct17.tgz. (Replace Oct17 with a current date when you acquire the code.) Repository can also be accessed with CVS. Configuration in the Makefiles directory Edit Makefile.location to tell OSI which solvers are available and where they are Edit Makefile.<platform> (e.g. Makefile.Linux, Makefile.SunOS) if you want to control the compiler, linker, etc. The default settings are probably OK. 2

Compile with the command make in the directory Coin and then Osi. May need to do make in subdirectories of Osi as well, such as OsiGlpk and OsiDylp, depending on the solvers available. Create a Makefile for your project that indicates the location of OSI headers and libraries. An example is given later. 4.3 Using OSI in your code Solver dependent parts: Include the header files for solver(s) you want to use. Create an OsiXxxSolverInterface object. Solver independent: Call functions to load/create a problem. Call functions to solve the problem. Call functions to report on the solution, modify the problem and re-solve, or do something else 3

5 Examples 5.1 basic.cpp // Bare bones example of using COIN-OR OSI #include <iostream> #include "OsiClpSolverInterface.hpp" int main(void) // Create a problem pointer. We use the base class here. OsiSolverInterface *si; // When we instantiate the object, we need a specific derived class. si = new OsiClpSolverInterface; // Read in an mps file. This one s from the MIPLIB library. si->readmps("p0033"); // Solve the (relaxation of the) problem si->initialsolve(); // Check the solution if ( si->isprovenoptimal() ) std::cout << "Found optimal solution!" << std::endl; std::cout << "Objective value is " << si->getobjvalue() << std::endl; int n = si->getnumcols(); const double *solution; solution = si->getcolsolution(); // We could then print the solution or examine it. else stdd::cout << "Didn t find optimal solution." << std::endl; // Could then check other status functions. return 0; 4

5.2 basic2.cpp // Bare bones example of using COIN-OR OSI #include <iostream> //#include "OsiClpSolverInterface.hpp" #include "OsiGlpkSolverInterface.hpp" int main(void) // Create a problem pointer. We use the base class here. OsiSolverInterface *si; // When we instantiate the object, we need a specific derived class. //si = new OsiClpSolverInterface; si = new OsiGlpkSolverInterface; // Read in an mps file. This one s from the MIPLIB library. si->readmps("p0033"); // Solve the (relaxation of the) problem si->initialsolve(); // Check the solution if ( si->isprovenoptimal() ) std::cout << "Found optimal solution!" << std::endl; std::cout << "Objective value is " << si->getobjvalue() << std::endl; int n = si->getnumcols(); const double *solution; solution = si->getcolsolution(); // We could then print the solution or examine it. else std::cout << "Didn t find optimal solution." << std::endl; // Could then check other status functions. return 0; 5

5.3 query.cpp // Example of using COIN-OR OSI // Demonstrates some problem and solution query methods #include <iostream> #include "OsiClpSolverInterface.hpp" int main(void) // Create a problem pointer. We use the base class here. OsiSolverInterface *si; // When we instantiate the object, we need a specific derived class. si = new OsiClpSolverInterface; // Read in an mps file. This one s from the MIPLIB library. si->readmps("p0033"); // Display some information about the instance int nrows = si->getnumrows(); int ncols = si->getnumcols(); int nelem = si->getnumelements(); std::cout << "This problem has " << nrows << " rows, " << ncols << " columns, and " << nelem << " nonzeros." << std::endl; double const * upper_bounds = si->getcolupper(); std::cout << "The upper bound on the first column is " << upper_bounds[0] << std::endl; // All the information about the instance is available with similar methods // Solve the (relaxation of the) problem si->initialsolve(); // Check the solution if ( si->isprovenoptimal() ) std::cout << "Found optimal solution!" << std::endl; std::cout << "Objective value is " << si->getobjvalue() << std::endl; // Examine solution int n = si->getnumcols(); const double *solution; solution = si->getcolsolution(); std::cout << "Solution: "; for (int i = 0; i < n; i++) std::cout << solution[i] << " "; std::cout << std::endl; std::cout << "It took " << si->getiterationcount() << " iterations" << " to solve." << std::endl; else std::cout << "Didn t find optimal solution." << std::endl; // Check other status functions. What happened? if (si->isprovenprimalinfeasible()) std::cout << "Problem is proven to be infeasible." << std::endl; if (si->isprovendualinfeasible()) std::cout << "Problem is proven dual infeasible." << std::endl; if (si->isiterationlimitreached()) std::cout << "Reached iteration limit." << std::endl; return 0; 6

5.4 parameters.cpp // Example of using COIN-OR OSI // Demonstrates some problem and solution query methods // Also demonstrates some parameter setting #include <iostream> #include "OsiClpSolverInterface.hpp" int main(void) // Create a problem pointer. We use the base class here. OsiSolverInterface *si; // When we instantiate the object, we need a specific derived class. si = new OsiClpSolverInterface; // Read in an mps file. This one s from the MIPLIB library. si->readmps("p0033"); // Display some information about the instance int nrows = si->getnumrows(); int ncols = si->getnumcols(); int nelem = si->getnumelements(); std::cout << "This problem has " << nrows << " rows, " << ncols << " columns, and " << nelem << " nonzeros." << std::endl; double const * upper_bounds = si->getcolupper(); std::cout << "The upper bound on the first column is " << upper_bounds[0] << std::endl; // All the information about the instance is available with similar methods // Before solving, indicate some parameters si->setintparam( OsiMaxNumIteration, 10); si->setdblparam( OsiPrimalTolerance, 0.001 ); // Can also read parameters string solver; si->getstrparam( OsiSolverName, solver ); std::cout << "About to solve with: " << solver << std::endl; // Solve the (relaxation of the) problem si->initialsolve(); // Check the solution if ( si->isprovenoptimal() ) std::cout << "Found optimal solution!" << std::endl; std::cout << "Objective value is " << si->getobjvalue() << std::endl; // Examine solution int n = si->getnumcols(); const double *solution; solution = si->getcolsolution(); std::cout << "Solution: "; for (int i = 0; i < n; i++) std::cout << solution[i] << " "; std::cout << std::endl; std::cout << "It took " << si->getiterationcount() << " iterations" << " to solve." << std::endl; else 7

std::cout << "Didn t find optimal solution." << std::endl; // Check other status functions. What happened? if (si->isprovenprimalinfeasible()) std::cout << "Problem is proven to be infeasible." << std::endl; if (si->isprovendualinfeasible()) std::cout << "Problem is proven dual infeasible." << std::endl; if (si->isiterationlimitreached()) std::cout << "Reached iteration limit." << std::endl; return 0; 8

5.5 build.cpp // Example of using COIN-OR OSI, building the instance internally // with sparse matrix object #include <iostream> #include "OsiClpSolverInterface.hpp" #include "CoinPackedMatrix.hpp" #include "CoinPackedVector.hpp" int main(void) // Create a problem pointer. We use the base class here. OsiSolverInterface *si; // When we instantiate the object, we need a specific derived class. si = new OsiClpSolverInterface; // Build our own instance from scratch /* * This section adapted from Matt Galati s example * on the COIN-OR Tutorial website. * * Problem from Bertsimas, Tsitsiklis page 21 * * optimal solution: x* = (1,1) * * minimize -1 x0-1 x1 * s.t 1 x0 + 2 x1 <= 3 * 2 x0 + 1 x1 <= 3 * x0 >= 0 * x1 >= 0 */ int n_cols = 2; double * objective double * col_lb double * col_ub = new double[n_cols];//the objective coefficients = new double[n_cols];//the column lower bounds = new double[n_cols];//the column upper bounds //Define the objective coefficients. //minimize -1 x0-1 x1 objective[0] = -1.0; objective[1] = -1.0; //Define the variable lower/upper bounds. // x0 >= 0 => 0 <= x0 <= infinity // x1 >= 0 => 0 <= x1 <= infinity col_lb[0] = 0.0; col_lb[1] = 0.0; col_ub[0] = si->getinfinity(); col_ub[1] = si->getinfinity(); int n_rows = 2; double * row_lb = new double[n_rows]; //the row lower bounds double * row_ub = new double[n_rows]; //the row upper bounds //Define the constraint matrix. CoinPackedMatrix * matrix = new CoinPackedMatrix(false,0,0); matrix->setdimensions(0, n_cols); //1 x0 + 2 x1 <= 3 => -infinity <= 1 x0 + 2 x2 <= 3 CoinPackedVector row1; row1.insert(0, 1.0); row1.insert(1, 2.0); row_lb[0] = -1.0 * si->getinfinity(); row_ub[0] = 3.0; 9

matrix->appendrow(row1); //2 x0 + 1 x1 <= 3 => -infinity <= 2 x0 + 1 x1 <= 3 CoinPackedVector row2; row2.insert(0, 2.0); row2.insert(1, 1.0); row_lb[1] = -1.0 * si->getinfinity(); row_ub[1] = 3.0; matrix->appendrow(row2); //load the problem to OSI si->loadproblem(*matrix, col_lb, col_ub, objective, row_lb, row_ub); //write the MPS file to a file called example.mps si->writemps("example"); // Solve the (relaxation of the) problem si->initialsolve(); // Check the solution if ( si->isprovenoptimal() ) std::cout << "Found optimal solution!" << std::endl; std::cout << "Objective value is " << si->getobjvalue() << std::endl; int n = si->getnumcols(); const double *solution; solution = si->getcolsolution(); // We could then print the solution or examine it. else std::cout << "Didn t find optimal solution." << std::endl; // Could then check other status functions. return 0; 10

5.6 specific.cpp // Example of using COIN-OR OSI // including accessing solver-specific functions #include <iostream> #include "OsiClpSolverInterface.hpp" int main(void) // Create a problem pointer. We use the base class here. OsiSolverInterface *si; // When we instantiate the object, we need a specific derived class. si = new OsiClpSolverInterface; // The next few lines are solver-dependent! ClpSimplex * clppointer; clppointer = (dynamic_cast<osiclpsolverinterface *>(si))->getmodelptr(); clppointer->setloglevel(0); //clppointer->setmaximumiterations(10); // Could tell Clp many other things // Read in an mps file. This one s from the MIPLIB library. si->readmps("p0033"); // Solve the (relaxation of the) problem si->initialsolve(); // Check the solution if ( si->isprovenoptimal() ) std::cout << "Found optimal solution!" << std::endl; std::cout << "Objective value is " << si->getobjvalue() << std::endl; int n = si->getnumcols(); const double *solution; solution = si->getcolsolution(); // We could then print the solution or examine it. else std::cout << "Didn t find optimal solution." << std::endl; // Could then check other status functions. return 0; 5.7 Features of OSI not demonstrated by the examples Several methods for loading problems Re-solve after modifying problem Integer programs Hints for presolving, scaling, using dual simplex Warm starts and hot starts Simplex-level controls for basis, pivots, etc. (currently only implemented for CLP, I think) 11

6 Example Makefile CXX := g++ COIN_DIR := $(HOME)/research/computation/COIN GLPK_DIR := $(HOME)/research/computation/glpk-4.1 COIN_INC_DIR := $(COIN_DIR)/include GLPK_INC_DIR := $(GLPK_DIR)/include CXX_FLAGS := -I$(COIN_INC_DIR) -I$(GLPK_INC_DIR) COIN_LIB_DIR := $(COIN_DIR)/lib GLPK_LIB_DIR := $(GLPK_DIR) LD_FLAGS := -L$(COIN_LIB_DIR) -L$(GLPK_LIB_DIR) LD_FLAGS += -Wl,-R,$(COIN_LIB_DIR):$(GLPK_LIB_DIR) LIB_FLAGS := -lcoin -losi -losiglpk -losiclp -lclp -lglpk -lm default: basic %.o: %.cpp $(CXX) $(CXX_FLAGS) -c $< basic: basic.o $(CXX) -o $@ $(CXX_FLAGS) $(LD_FLAGS) $< $(LIB_FLAGS) 12