opl的python接口。
doopl的Python项目详细描述
欢迎使用ibm®opl connector for python。 在apache许可证v2.0下授权。
有了这个库,您可以快速轻松地将优化的能力添加到 您的python应用程序。您可以使用opl语言和ide对问题建模,并通过python/pandas/sql炼金术输入/输出将其集成到python中。
使用cplex解决问题需要在您的计算机上安装ibm®ilog cplex optimization studio v12.8.0。
安装库
pip install doopl
获取示例
获取IBM®ILOG CPLEX Optimization Studio版本
- 你可以得到免费的Community Edition 在CPLEX优化工作室,有限的解决能力方面的问题规模。
- 认证机构的教员、研究人员可以通过 IBM® Academic Initiative。
许可证
此库在2004年1月的ApacheLicense2.0版本下提供(请参阅license.txt)。
起点
这个api非常简洁。 必须在路径/ld_library_path中包含opl二进制文件,或者 dyld_library_path,取决于您的平台。它们位于 <cplex_studio_dir>/opl/bin/<platform>其中:
- ^{tt2}$ is the installation directory of CPLEX 12.8
- ^{tt3}$ is your plaform (OPL nomenclature, that is ^{tt4}$, ^{tt5}$ or ^{tt6}$)
以下是这些功能的小结:
- Inputs can be tuple lists, panda’s dataframe, sql alchemy fetch statements.
- Generate, solve and get output tuplesets as panda’s dataframe
- Get the CPLEX problem statistics and quality metrics for the solution
- Convert all integer variables to floating point variables and vice-versa.
- Run the conflict/relaxation mechanism.
- Call the ‘RunSeed’ diagnosis for CPLEX/CPO based problems.
这些特性中的每一个都用简单的例子来演示。
下面是一个开始使用api的小示例:
from doopl.factory import * # Create an OPL model from a .mod file with create_opl_model(model="file.mod") as opl: # tuple can be a list of tuples, a pandas dataframe... opl.set_input("TupleSet1", tuples) # Generate the problem and solve it. opl.run() # Get the names of post processing tables print("Table names are: "+ str(opl.output_table_names)) # Get all the post processing tables as dataframes. for name, table in iteritems(opl.report): print("Table : " + name) for t in table.itertuples(index=False): print(t)