Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

jyuv/RevisedSimplex

Repository files navigation

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.

About

A high performence numpy based implementation of revised simplex

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /