Giter Site home page Giter Site logo

rsome's Introduction

RSOME: Robust Stochastic Optimization Made Easy

RSOME (Robust Stochastic Optimization Made Easy) is an open-source Python package for generic modeling of optimization problems (subject to uncertainty). Models in RSOME are constructed by variables, constraints, and expressions that are formatted as N-dimensional arrays. These arrays are consistent with the NumPy library in terms of syntax and operations, including broadcasting, indexing, slicing, element-wise operations, and matrix calculation rules, among others. In short, RSOME provides a convenient platform to facilitate developments of optimization models and their applications.

The current version of RSOME supports deterministic as well as robust and distributionally robust optimization problems. In the default configuration, linear programs are solved by the open-source solver linprog() imported from the scipy.optimize package. Details of this solver interface, together with interfaces of other open-source and commercial solvers are presented in the following table.

Solver License type RSOME interface Integer variables Second-order cone constraints
scipy.optimize Open-source lpg_solver No No
CyLP Open-source clp_solver Yes No
OR-Tools Open-source ort_solver Yes No
Gurobi Commercial grb_solver Yes Yes
MOSEK Commercial msk_solver Yes Yes
CPLEX Commercial cpx_solver Yes Yes

Introduction

Installing RSOME and solvers

The RSOME package can be installed by using the pip command:


pip install rsome


Getting started

In RSOME, models can be specified by using highly readable algebraic expressions that are consistent with NumPy-syntax. Below we provide a simple linear program as an example to illustrate the steps of modeling and solving an optimization problem in RSOME.

from rsome import ro                 # Import the ro modeling tool
from rsome import grb_solver as grb  # Import Gurobi solver interface

model = ro.Model('LP model')         # Create a Model object
x = model.dvar()                     # Define a decision variable x
y = model.dvar()                     # Define a decision variable y

model.max(3*x + 4*y)                 # Maximize the objective function
model.st(2.5*x + y <= 20)            # Specify the 1st constraint
model.st(5*x + 3*y <= 30)            # Specify the 2nd constraint
model.st(x + 2*y <= 16)              # Specify the 3rd constraint
model.st(abs(y) <= 2)                # Specify the 4th constraint

model.solve(grb)                     # Solve the model with Gurobi
Being solved by Gurobi...
Solution status: 2
Running time: 0.0005s

In this sample code, a model object is created by calling the constructor Model() imported from the rsome.ro toolbox. Based on the model object, decision variables x and y are created with the method dvar(). Variables are then used in specifying the objective function and constraints. The last step is to call the solve() method to solve the problem via the imported solver interface grb. Once the solution procedure completes, a message showing the solution status and running time will be printed.

According to the Gurobi solution status, the status code 2 suggests that the problem was solved to optimality (subject to tolerances) and an optimal solution is available. The optimal solution and the corresponding objective value can be obtained by the get() method.

print('x:', x.get())
print('y:', y.get())
print('Objective:', model.get())
x: [4.8]
y: [2.]
Objective: 22.4

The example above shows that RSOME models can be formulated via straightforward and highly readable algebraic expressions, and the reformulation can be transformed into a standard form, which is then solved by the Gurobi (or MOSEK) solver. The basic information of the standard form can be retrieved by calling the do_math() method of the RSOME model object.

formula = model.do_math()
print(formula)
Second order cone program object:
=============================================
Number of variables:          3
Continuous/binaries/integers: 3/0/0
---------------------------------------------
Number of linear constraints: 6
Inequalities/equalities:      6/0
Number of coefficients:       11
---------------------------------------------
Number of SOC constraints:    0

rsome's People

Contributors

xiongpengnus avatar chenzjames avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.