�
��g�� � �2 � d Z ddlmZ ddlmZ ddlmZmZmZ ddl m
Z
ddlmZ ddl
mZ ddlmZ dd lmZmZ dd
lmZ ddlmZ ddlmZ G d
� de� � Z G d� de� � Zd� Zd� Zd"d�Zd#d�Z d$d�Z!d%d�Z"d� Z#d� Z$d� Z%d� Z&d� Z'd� Z(d&d �Z)d&d!�Z*dS )'a Tools for optimizing a linear function for a given simplex.
For the linear objective function ``f`` with linear constraints
expressed using `Le`, `Ge` or `Eq` can be found with ``lpmin`` or
``lpmax``. The symbols are **unbounded** unless specifically
constrained.
As an alternative, the matrices describing the objective and the
constraints, and an optional list of bounds can be passed to
``linprog`` which will solve for the minimization of ``C*x``
under constraints ``A*x <= b`` and/or ``Aeq*x = beq``, and
individual bounds for variables given as ``(lo, hi)``. The values
returned are **nonnegative** unless bounds are provided that
indicate otherwise.
Errors that might be raised are UnboundedLPError when there is no
finite solution for the system or InfeasibleLPError when the
constraints represent impossible conditions (i.e. a non-existant
simplex).
Here is a simple 1-D system: minimize `x` given that ``x >= 1``.
>>> from sympy.solvers.simplex import lpmin, linprog
>>> from sympy.abc import x
The function and a list with the constraint is passed directly
to `lpmin`:
>>> lpmin(x, [x >= 1])
(1, {x: 1})
For `linprog` the matrix for the objective is `[1]` and the
uivariate constraint can be passed as a bound with None acting
as infinity:
>>> linprog([1], bounds=(1, None))
(1, [1])
Or the matrices, corresponding to ``x >= 1`` expressed as
``-x <= -1`` as required by the routine, can be passed:
>>> linprog([1], [-1], [-1])
(1, [1])
If there is no limit for the objective, an error is raised.
In this case there is a valid region of interest (simplex)
but no limit to how small ``x`` can be:
>>> lpmin(x, [])
Traceback (most recent call last):
...
sympy.solvers.simplex.UnboundedLPError:
Objective function can assume arbitrarily large values!
An error is raised if there is no possible solution:
>>> lpmin(x,[x<=1,x>=2])
Traceback (most recent call last):
...
sympy.solvers.simplex.InfeasibleLPError:
Inconsistent/False constraint
� ��sympify)�factor_terms)�Le�Ge�Eq)�S)�Dummy)�ordered)�sign)�Matrix�zeros)�linear_eq_to_matrix��numbered_symbols)�
filldedentc � � e Zd ZdZdS )�UnboundedLPErrora
A linear programing problem is said to be unbounded if its objective
function can assume arbitrarily large values.
Example
=======
Suppose you want to maximize
2x
subject to
x >= 0
There's no upper limit that 2x can take.
N��__name__�
__module__�__qualname__�__doc__� � �e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/solvers/simplex.pyr r M s � � � � � �
�
� �Dr r c � � e Zd ZdZdS )�InfeasibleLPErrorai
A linear programing problem is considered infeasible if its
constraint set is empty. That is, if the set of all vectors
satisfying the contraints is empty, then the problem is infeasible.
Example
=======
Suppose you want to maximize
x
subject to
x >= 10
x <= 9
No x can satisfy those constraints.
Nr r r r r r ` s � � � � � �� �"