Robust Stochastic Optimization Made Easy
RSOME: Robust Stochastic Optimization Made Easy
- Website: RSOME for Python
- PyPI: RSOME 0.0.9
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. Interfaces with Gurobi and MOSEK solvers are also provided for solving problems with second-order cone constraints and integer variables.
Installing RSOME and solvers
The RSOME package can be installed by using the
pip install rsome
The current version of RSOME requires the Gurobi or MOSEK solver for solving the formatted models. You may follow these steps to complete Gurobi installation. The MOSEK solver can be installed via steps in this link.
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 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
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
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() 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
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.