sasoptpy:python的sas优化接口
sasoptp的Python项目详细描述
Python的SAS优化接口
sasoptpy是一个python包,为SAS Viya和sas/或优化求解器提供建模接口。 它为用户提供了一种快速部署优化模型并使用cas操作解决它们的方法。
sasoptpy可以处理线性、混合整数线性和非线性优化问题。 用户可以从本机python结构(如字典、元组和列表)中获益,以定义优化问题。 sasoptpy广泛使用Pandas结构。
在引擎盖下,sasoptpy使用 swat package通信 sas viya和uses saspy package与SAS 9.4通信 装置。
sasoptpy是SAS优化求解器的接口。支票 SAS/OR 和 PROC OPTMODEL 有关SAS提供的优化工具和 SAS中的模型优化问题。
要求
要使用sasoptpy,您需要有:
安装
sasoptpy可以从project releases页安装。
下载发行版并使用pip
:
pip install vX.X.X.tar.gz
其中vX.X.X
是要安装的版本。
或者,使用:
pip install https://github.com/sassoftware/sasoptpy/archive/vX.X.X.tar.gz
开始
- 源代码当前托管在github上的https://github.com/sassoftware/sasoptpy
- 在线文档位于https://sassoftware.github.io/sasoptpy/
- 有关最新版本,请转到https://github.com/sassoftware/sasoptpy/releases/latest
示例
fromswatimportCASimportsasoptpyasso# Create a CAS Sessions=CAS(hostname='host',port=12345)# Create an empty optimization modelm=so.Model('demo',session=s)# Add variablesx=m.add_variable(vartype=so.CONT,name='x')y=m.add_variable(vartype=so.INT,name='y')# Set objective functionm.set_objective(2*x+y,sense=so.MAX,name='obj')# Add constraintsm.add_constraint(x+2*y<=4.5,name='c1')m.add_constraint(3*x+y<=5.5,name='c2')# Solve the optimization problemresult=m.solve()# Print and list variable valuesprint(so.get_solution_table(x,y))print('Optimal objective value:',m.get_objective_value())
输出
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 0123.3333333 4.2000000 20.63% 00134.0000000 4.0000000 0.00% 00034.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 11.5 1.0 Optimal objective value: 4.0
资源
SAS协会版权所有