GithubHelp home page GithubHelp logo

jyuv / revisedsimplex Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 46 KB

A high performence numpy based implementation of revised simplex

Python 100.00%
algorithm optimization solvers revised-simplex simplex

revisedsimplex's Introduction

RevisedSimplex

Code style: black

Overview

A numpy based implementation of revised simplex with numerical stability checks. The implementation was found 16% faster than scipy's revised-simplex method running a series of random configurations.

The Problem - Linear Programming Maximization Problem

This repositry offers an implementation for an algorithm that solves Linear Programming configurations. A Linear Programming Maximization Problem is defined as:

Where the A matrix and b & c vectors are given and we need to find a valid x vector that maximizes the score function.

The Algorithm - Revised Simplex

The Revised Simplex method is a variant of the classic simplex algorithm for solving Linear Programming configurations. This method allows for a greater computational efficiency. For more details you can watch the slides here.

The Implementation & How To Use

The implementation is based on numpy. It includes a number of numerical stability checks utilizing eta matrices and lu factorization to keep it efficient.

How To Use

The implementation allows the use of both Bland & Dantzig rules. The module provides two main external API functions:

  1. get_optimal_solution - searches for an optimal solution. This function returns a SimplexResult object:
class ResultCode(Enum):
    INFEASIBLE = 1
    FINITE_OPTIMAL = 2
    UNBOUNDED_OPTIMAL = 3
    CYCLE_DETECTED = 4


@dataclass
class SimplexResult(object):
    res_code: ResultCode
    assignment: Union[None, np.ndarray]
    optimal_score: Union[None, float]
  1. has_feasible_solution - checks if there is a feasible solution for the configuration. Returns True\False.

Here is an example of how to use the module:

import numpy as np
from Simplex import Simplex, PickingRule

solver = Simplex()
A = np.array([[-1, 1], [-2, -2], [-1, 4]])
b = np.array([-1, -6, 2])
c = np.array([1, 3])
rule = PickingRule.DANTZIG_RULE  # Or PickingRule.BLAND_RULE

# optimal using the default rule - bland's
solver.get_optimal_solution(A, b, c)

# optimal using a specified rule - dantzig's
solver.get_optimal_solution(A, b, c)

# check for existance of feasible solution
solver.has_feasible_solution(A, b, c)

Performance Analysis

The performance of this repository was compared to scipy's revised-simplex method by running 10,000 random generated configurations. The results show an improvement of 16% compared to scipy's performance when running the full revised simplex (searching for optimal solution). The more humble method (has_feasible_solution) was 41% faster than scipy's full revised simplex.

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.