sasoptpy is a Python package providing a modeling interface for SAS Viya Optimization solvers.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc More typo fixes Jul 31, 2018
examples Doc changes before release Jul 30, 2018
img Initial upload Dec 22, 2017
sasoptpy Fixed typo Jul 30, 2018
tests Pandas function update, get_objective_value fix Jul 25, 2018
.gitignore Gitignore changes saspy ex doc fix Apr 19, 2018
LICENSE Create license file Dec 21, 2017
README.md Typo fixes Nov 9, 2018
setup.py Version number changes Jul 30, 2018

README.md

SAS Optimization Interface for Python

sasoptpy is a Python package providing a modeling interface to SAS Viya and SAS/OR Optimization solvers. It provides a quick way for users to deploy optimization models and solve them using CAS Actions.

sasoptpy can handle linear, mixed integer linear and nonlinear optimization problems. Users can benefit from native Python structures like dictionaries, tuples, and list to define an optimization problem. sasoptpy uses Pandas structures extensively.

Under the hood, sasoptpy uses the swat package to communicate SAS Viya, and uses the saspy package to communicate SAS 9.4 installations.

sasoptpy is an interface to SAS Optimization solvers. Check SAS/OR and PROC OPTMODEL for more details about optimization tools provided by SAS and an interface to model optimization problems inside SAS.

Requirements

To use sasoptpy, you need to have:

Installation

sasoptpy can be installed from project releases page. Download the release and install it using pip:

pip install vX.X.X.tar.gz

where vX.X.X is the release you want to install.

Alternatively, use:

   pip install https://github.com/sassoftware/sasoptpy/archive/vX.X.X.tar.gz

Getting Started

Examples

sasoptpy demo gif

from swat import CAS
import sasoptpy as so

# Create a CAS Session
s = CAS(hostname='host', port=12345)
# Create an empty optimization model
m = so.Model('demo', session=s)
# Add variables
x = m.add_variable(vartype=so.CONT, name='x')
y = m.add_variable(vartype=so.INT, name='y')
# Set objective function
m.set_objective(2*x+y, sense=so.MAX, name='obj')
# Add constraints
m.add_constraint(x+2*y <= 4.5, name='c1')
m.add_constraint(3*x+y <= 5.5, name='c2')
# Solve the optimization problem
result = m.solve()
# Print and list variable values
print(so.get_solution_table(x, y))
print('Optimal objective value:', m.get_objective_value())

Output

NOTE: Initialized model demo.
NOTE: Added action set 'optimization'.
NOTE: Converting model demo to OPTMODEL.
NOTE: Submitting OPTMODEL codes to CAS server.
NOTE: Problem generation will use 32 threads.
NOTE: The problem has 2 variables (2 free, 0 fixed).
NOTE: The problem has 0 binary and 1 integer variables.
NOTE: The problem has 2 linear constraints (2 LE, 0 EQ, 0 GE, 0 range).
NOTE: The problem has 4 linear constraint coefficients.
NOTE: The problem has 0 nonlinear constraints (0 LE, 0 EQ, 0 GE, 0 range).
NOTE: The OPTMODEL presolver is disabled for linear problems.
NOTE: The initial MILP heuristics are applied.
NOTE: The MILP presolver value AUTOMATIC is applied.
NOTE: The MILP presolver removed 0 variables and 1 constraints.
NOTE: The MILP presolver removed 2 constraint coefficients.
NOTE: The MILP presolver modified 0 constraint coefficients.
NOTE: The presolved problem has 2 variables, 1 constraints, and 2 constraint coefficients.
NOTE: The MILP solver is called.
NOTE: The parallel Branch and Cut algorithm is used.
NOTE: The Branch and Cut algorithm is using up to 32 threads.
             Node   Active   Sols    BestInteger      BestBound      Gap    Time
                0        1      2      3.3333333      4.2000000   20.63%       0
                0        1      3      4.0000000      4.0000000    0.00%       0
                0        0      3      4.0000000      4.0000000    0.00%       0
NOTE: Optimal.
NOTE: Objective = 4.
NOTE: The CAS table 'solutionSummary' in caslib 'CASUSERHDFS(casuser)' has 18 rows and 4 columns.
NOTE: The CAS table 'problemSummary' in caslib 'CASUSERHDFS(casuser)' has 20 rows and 4 columns.
NOTE: The CAS table 'primal' in caslib 'CASUSERHDFS(casuser)' has 2 rows and 6 columns.
NOTE: The CAS table 'dual' in caslib 'CASUSERHDFS(casuser)' has 2 rows and 4 columns.
     x    y
1          
   1.5  1.0
Optimal objective value: 4.0

Resources

Copyright SAS Institute