Git Product home page Git Product logo

gilp's Introduction

GILP

PyPI pyversions CircleCI Documentation Status codecov

GILP (Geometric Interpretation of Linear Programs) is a Python package for visualizing the geometry of:

LPs can be constructed from NumPy arrays and many examples (such as the Klee-Minty cube) are included. The revised simplex method is implemented along with phase I for finding an initial feasible solution. The package relies on Plotly to generate standalone HTML files which can be viewed in a Jupyter Notebook inline or in a web browser.

Examples

2d simplex example 3d simplex example 2d branch and bound example 3d branch and bound example

Installation

The quickest way to get started is with a pip install.

pip install gilp

Development

To develop and run tests on gilp, first download the source code in the desired directory.

git clone https://github.com/engri-1101/gilp.git

Next, cd into the gilp directory and create a Python virtual enviroment.

cd gilp
python -m venv env_name

Activate the virtual enviroment.

source env_name/bin/activate

Run the following in the virtual enviroment. The -e flag lets you make adjustments to the source code and see changes without re-installing. The [dev] installs necessary dependencies for developing and testing.

pip install -e .[dev]

To run tests and see coverage, run the following in the virtual enviroment.

coverage run -m pytest
coverage report --include=gilp/*

Usage

The LP class creates linear programs from (3) NumPy arrays: A, b, and c which define the LP in standard inequality form.

For example, consider the following LP:

The LP instance is created as follows.

import gilp
import numpy as np
from gilp.simplex import LP
A = np.array([[2, 1],
              [1, 1],
              [1, 0]])
b = np.array([[20],
              [16],
              [7]])
c = np.array([[5],
              [3]])
lp = LP(A,b,c)

After creating an LP, one can run simplex and generate a visualization with

from gilp.visualize import simplex_visual
simplex_visual(lp)

where simplex_visual() returns a plotly figure. The figure can then be viewed on a Jupyter Notebook inline using

simplex_visual(lp).show()

If .show() is run outside a Jupyter Notebook enviroment, the visualization will open up in the browser. Alternatively, the HTML file can be written and then opened.

simplex_visual(lp).write_html('name.html')

Below is the visualization for the example LP. The plot on the left shows the feasible region and constraints of the LP. Hovering over an extreme point shows the basic feasible solution, basis, and objective value. The iteration slider allows one to toggle through the iterations of simplex and see the updating tableaus. The objective slider lets one see the objective line or plane for some range of objective values.

2d simplex example

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.