sasoptpy: SAS Optimization Interface for Python
Project description
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 using pip
:
pip install sasoptpy
or using conda
:
conda install -c sas-institute sasoptpy
Old releases can be found on the GitHub repository: https://github.com/sassoftware/sasoptpy/releases
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
- The source code is currently hosted on GitHub at https://github.com/sassoftware/sasoptpy
- Online documentation is at https://sassoftware.github.io/sasoptpy/
- For the latest release go to https://github.com/sassoftware/sasoptpy/releases/latest
Examples
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sasoptpy-1.0.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a96d6dbd914166bde5838c2bc51f6f2d0ccfad40c07e95197ab2cb375949886 |
|
MD5 | ef3bd4c829ff1e3bbadb805628994ac4 |
|
BLAKE2b-256 | 633108b458b999964d3cc20d26fd94a5fc21f9255e3b4745edf19d524b7686e8 |