Skip to main content

A Linear Problem parser

Project description

Aplos

Build Status Coverage Status

Aplos is a simple and elegant linear problem(LP) parser. It allows one to get all the information they need about any linear problem given with the correct syntax. You can read more about Linear Programming here.

Expected LP format

min/max cTx

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

End

Where ⊗ can be any of the following =, <=, >=

Variable(x) constraints/domains are not taken into consideration (not yet).


Examples:

  1. Max 3x1 +2x2

    s.t. x1+2x2<=9

    2x1+5x2<=4

    End

  2. min 3x1 - 5x2 + x4
    st x2 + x3 = 2
    2x1 + 3x2 + 5x4 >= 5
    x1 - 5x2 + 2x3 - 4x4 <= 10
    END

Usage

import Aplos

# Initialization
# From a file
parser = Aplos.AplosParser(filename='lp.txt')

# From a string
text_lp = '''Max 3x1 +2x2

s.t. x1+2x2<=9

2x1+5x2<=4

End'''

parser = Aplos.AplosParser(text=text_lp)

# From a string with a custom delimeter
text = "Max 3x1 +2x3 + x5,s.t. x1+2x2<=9,2x1+5x2<=4,End"

parser = Aplos.AplosParser(text=text, delimeter=',')


# Getting the variables
variables_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 errors
errors = parser.detect_errors() # set print_msg=True to print the full list of errors

if not errors:
    # Get dimensions
    dimensions = 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':-1
    matrix_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 & MinMax
    matrices = parser.get_matrices()
    matrix_A = matrices['A']
    # And so on

    # Save matrices to file
    parser.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 & VarConstr
    dual_matrices = parser.get_dual_matrices()
    dual_A = dual_matrices['A']
    # And so on

    # Save dual matrices to file
    parser.write_matrices_to_file('output_dual.txt', dual=True)


    # After saving matrices (non-dual), you can also read them back
    saved_matrices = parser.read_matrices_from_file('output.txt')

    # If dual
    saved_d_matrices = parser.read_matrices_from_file('output_dual.txt')

As the project continues, the 'usage' section will get updated and eventually (hopefully) be moved in a documentation file/page altogether.

Project details


Release history Release notifications | RSS feed

This version

1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Aplos-1.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Aplos-1.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file Aplos-1.1.tar.gz.

File metadata

  • Download URL: Aplos-1.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for Aplos-1.1.tar.gz
Algorithm Hash digest
SHA256 ee8d4175a9a1ca87e56118d3370f5f44ea10fce79c21274d38b1b369a7bd1bb5
MD5 176bea0da11b9a8e03cc77349b5c09dd
BLAKE2b-256 b14694b3f4f437a2c6067fc72de8fc241fc372707bdd197174bca542d0325a58

See more details on using hashes here.

File details

Details for the file Aplos-1.1-py3-none-any.whl.

File metadata

  • Download URL: Aplos-1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for Aplos-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c299690442172b23f5a9b61f89650fd30d2b1fbdcb5626ee6934e0164fb9fd0
MD5 a19489de13e21c2c254c8f99ec4b853a
BLAKE2b-256 7d9b5adf637319f0ede086b6781fcacc73e01d321b3ddfaa33b759109df97e3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page