Skip to main content

Implementation of a simplex dictionary in python

Project description

Simplex dictionary

Python Versions License Build Status

simplex is a small python module that implements a simplex_dictionary structure representing a dictionary for the Simplex algorithm. The package is intended for educational purpose, e.g., to have students implement the Simplex algorithm based on the structure.

Basic usage

The following code creates a simplex dictionary with 5 variables:

from simplex import simplex_dictionary

# The list of variables (can be anything):
x1, x2, x3, x4, x5 = ('x_{}'.format(i + 1) for i in range(5))
variables = [x1, x2, x3, x4, x5]

# The simplex dictionary with B = (x3, x4, x5):
sdict = simplex_dictionary(B=[x3, x4, x5], N=[x1, x2])

# Set the values of the basic variables:
sdict.b = {x3: 18, x4: 42, x5: 24}

# Coefficients of the non-basic variables in the dictionary (we represent
# the positive coefficients):
sdict.a = {
    x3: {x1: 2, x2: 1},
    x4: {x1: 2, x2: 3},
    x5: {x1: 3, x2: 1}
}

# Current value of the objective:
sdict.z = 0

# Coefficients of the non-basic variables in the objective function:
sdict.c[x1] = 3
sdict.c[x2] = 2

# Trying to set the coefficients for a basic variables that should be 0 raise an
# exception:
sdict.c[x3] = 4  # raises "x_3 is not a non-basic variable."
sdict.b[x1] = 1  # raises "x_1 is not a basic variable."

When using the simplex module within a jupyter notebook, the display() method outputs a latex version of the dictionary:

sdict.display(name='S_0')

Project details


Download files

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

Source Distribution

simplex-dictionary-0.0.1.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

simplex_dictionary-0.0.1-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

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