线性问题分析器

Aplos的Python项目详细描述


Aplos

Build StatusCoverage Status

aplos是一个简单而优雅的线性问题(lp)解析器。它允许一个人获得所有的信息,他们所需要的任何线性问题给出正确的语法。您可以阅读有关线性规划的更多信息here.

预期的LP格式

min/max cTx

s.t /st /s.t. /subject to Ax ⊗ b

End

其中可以是以下任一项=,<;=,>;=

变量(x)约束/域未考虑(尚未)


示例:

  1. 最大3x1+2x2

    S.T.x1+2x2<;=9

    2x1+5x2<;=4

    结束

  2. 最小3x1-5x2+x4
    st x2+x3=2
    2x1+3x2+5x4>;=5
    x1-5x2+2x3-4x4<;=10
    结束

用法

importAplos# Initialization# From a fileparser=Aplos.AplosParser(filename='lp.txt')# From a stringtext_lp='''Max 3x1 +2x2s.t. x1+2x2<=92x1+5x2<=4End'''parser=Aplos.AplosParser(text=text_lp)# From a string with a custom delimetertext="Max 3x1 +2x3 + x5,s.t. x1+2x2<=9,2x1+5x2<=4,End"parser=Aplos.AplosParser(text=text,delimeter=',')# Getting the variablesvariables_of_line=parser.get_vars(line_idx=0)# variables_of_line = {"existing":['x1','x3'], "extended":['x1','x2','x3','x4','x5']}variables_all=parser.get_vars()# variables_all = ['x1','x2','x3','x4','x5']# Detect errorserrors=parser.detect_errors()# set print_msg=True to print the full list of errorsifnoterrors:# Get dimensionsdimensions=parser.get_dimensions()m=dimensions['m']n=dimensions['n']# Get any matrix (A,b,c,Eqin or MinMax)# Eqin and MinMax have values corresponding to symbols# Eqin -- '<=': -1 | '>=' : 1 | '=' : 0# MinMax -- 'max':1 | 'min':-1matrix_A=parser.get_matrix('a')matrix_b=parser.get_matrix('B')# And so on# Otherwise, get all matrices at once.# Keys are : A,b,c,Eqin & MinMaxmatrices=parser.get_matrices()matrix_A=matrices['A']# And so on# Save matrices to fileparser.write_matrices_to_file('output.txt')# Get dual matrices# Variable constraints -- 'free' : 0 | '>= 0' : 1 | '<= 0' : -1}dual_A=parser.get_dual_matrix('a')# Variable constraints are calculated assuming that x(i) >= 0# for every i. This is subject to change.dual_var_constr=parser.get_dual_matrix('var_constr')# And so on# You can also get all the dual matrices together# Similarly keys are : A,b,c,Eqin,MinMax & VarConstrdual_matrices=parser.get_dual_matrices()dual_A=dual_matrices['A']# And so on# Save dual matrices to fileparser.write_matrices_to_file('output_dual.txt',dual=True)# After saving matrices (non-dual), you can also read them backsaved_matrices=parser.read_matrices_from_file('output.txt')# If dualsaved_d_matrices=parser.read_matrices_from_file('output_dual.txt')

随着项目的继续,“usage”部分将得到更新,并最终(希望)在文档文件/页面中一起移动。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java获取骆驼路由交换正文()中的无效字符   java如何在Android中创建多语言枚举?   java如何将多个ArrayList<Hashmap>值组合到一个ListView中   后缀运算符Java后增量和预增量行为   SQlite在java中更新列号   Mac OS Yosemite上的java No JRE 1.8虚拟机   java swing在Jlabel中遇到问题   JAVAutil。scanner小java程序打印不可见的换行符?   java从原点到点的路径数   java重写Excel列而不是创建新列   将一行从SQL数据映射到Java对象   spring Application Insights Java SDK+代理不能很好地协同工作   java排序字符串列表?不使用长度函数查找列表的长度   java使用stream collect返回相同的列表,对重复项进行剪切和求和,抛出一个非静态引用   将字母字符与前面没有百分号的Java正则表达式匹配