Skip to main content

Robust Stochastic Optimization Made Easy

Project description

RSOME: Robust Stochastic Optimization Made Easy

RSOME (Robust Stochastic Optimization Made Easy) is an open-source Python package for generic modeling optimization problems. 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, robust optimization and distributionally robust optimization problems. In the default configuration, linear programming problems 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 RSOME interface Integer variables Second-order cone constraints
scipy.optimize Open source lpg_solver No No
CyLP Open source clp_solver Yes No
Gurobi Commercial grb_solver Yes Yes
MOSEK Commercial msk_solver Yes Yes


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.

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*x + y <= 20)            # Specify the 1st constraint*x + 3*y <= 30)            # Specify the 2nd constraint + 2*y <= 16)              # Specify the 3rd constraint <= 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 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 formulated model 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()
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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rsome-0.1.0.tar.gz (30.4 kB view hashes)

Uploaded Source

Built Distribution

rsome-0.1.0-py3-none-any.whl (33.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page