Introduction
RSOME (Robust Stochastic Optimization Made Easy) is an open-source Python package for modeling generic 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.
Installing RSOME and Solvers
The RSOME package can be installed with the pip
command:
pip install rsome
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 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 |
A Linear Programming Example
The RSOME package supports specifying models using highly readable algebraic expressions that are consistent with NumPy syntax. A very simple linear program example is provided below,
max 3 x + 4 y s.t. 2.5 x + y ≤ 20 5 x + 3 y ≤ 30 x + 2 y ≤ 16 ∣ y ∣ ≤ 2 \begin{aligned} \max ~&3x + 4y \\ \text{s.t.}~&2.5x + y \leq 20 \\ &5x + 3y \leq 30 \\ &x+2y \leq 16 \\ &|y| \leq 2 \end{aligned} max s.t. 3x+4y2.5x+y≤205x+3y≤30x+2y≤16∣y∣≤2
and it is used to illustrate the steps of solving optimization models.
from rsome import ro # import the ro modeling tool
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 constraints
model.st(5*x + 3*y <= 30) # specify the 2nd constraints
model.st(x + 2*y <= 16) # specify the 3rd constraints
model.st(abs(y) <= 2) # specify the 4th constraints
model.solve() # solve the model by the default solver
Being solved by the default LP solver...
Solution status: 0
Running time: 0.0426s
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 by the method dvar()
. These variables are then used in specifying the objective function and model constraints. The last step is calling the solve()
method to solve the problem. Once the solution completes, a message showing the solution status and running time will be printed.
You may find the interpretation of the solution status code of linprog()
from the website scipy.optimize.linprog
. The status code 0
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 attained by the get()
method.
print('x:', x.get())
print('y:', y.get())
print('Objective:', round(model.get(), 2))
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 integrated 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