← Back
Editing: _linprog_util.cpython-311.pyc
� d�c@� � �� � d Z ddlZddlmZ ddlmZ ddlm Z ddl mZmZm Z mZ ddlmZ edd � � Zd ej _ de_ d� Zdd�Zd� Zd� Zdd�Zd� Zd� Zd� Zd� Zd� Zd� Zdd�Zd� Z dS )z9 Method agnostic utility functions for linear progamming � N)�warn� )�OptimizeWarning)�_remove_redundancy_svd�_remove_redundancy_pivot_sparse�_remove_redundancy_pivot_dense�_remove_redundancy_id)� namedtuple� _LPProblemz+c A_ub b_ub A_eq b_eq bounds x0 integrality)NNNNNNNa� Represents a linear-programming problem. Attributes ---------- c : 1D array The coefficients of the linear objective function to be minimized. A_ub : 2D array, optional The inequality constraint matrix. Each row of ``A_ub`` specifies the coefficients of a linear inequality constraint on ``x``. b_ub : 1D array, optional The inequality constraint vector. Each element represents an upper bound on the corresponding value of ``A_ub @ x``. A_eq : 2D array, optional The equality constraint matrix. Each row of ``A_eq`` specifies the coefficients of a linear equality constraint on ``x``. b_eq : 1D array, optional The equality constraint vector. Each element of ``A_eq @ x`` must equal the corresponding element of ``b_eq``. bounds : various valid formats, optional The bounds of ``x``, as ``min`` and ``max`` pairs. If bounds are specified for all N variables separately, valid formats are: * a 2D array (N x 2); * a sequence of N sequences, each with 2 values. If all variables have the same bounds, the bounds can be specified as a 1-D or 2-D array or sequence with 2 scalar values. If all variables have a lower bound of 0 and no upper bound, the bounds parameter can be omitted (or given as None). Absent lower and/or upper bounds can be specified as -numpy.inf (no lower bound), numpy.inf (no upper bound) or None (both). x0 : 1D array, optional Guess values of the decision variables, which will be refined by the optimization algorithm. This argument is currently used only by the 'revised simplex' method, and can only be used if `x0` represents a basic feasible solution. integrality : 1-D array or int, optional Indicates the type of integrality constraint on each decision variable. ``0`` : Continuous variable; no integrality constraint. ``1`` : Integer variable; decision variable must be an integer within `bounds`. ``2`` : Semi-continuous variable; decision variable must be within `bounds` or take value ``0``. ``3`` : Semi-integer variable; decision variable must be an integer within `bounds` or take value ``0``. By default, all variables are continuous. For mixed integrality constraints, supply an array of shape `c.shape`. To infer a constraint on each decision variable from shorter inputs, the argument will be broadcasted to `c.shape` using `np.broadcast_to`. This argument is currently used only by the ``'highs'`` method and ignored otherwise. Notes ----- This namedtuple supports 2 ways of initialization: >>> lp1 = _LPProblem(c=[-1, 4], A_ub=[[-3, 1], [1, 2]], b_ub=[6, 4]) >>> lp2 = _LPProblem([-1, 4], [[-3, 1], [1, 2]], [6, 4]) Note that only ``c`` is a required argument here, whereas all other arguments ``A_ub``, ``b_ub``, ``A_eq``, ``b_eq``, ``bounds``, ``x0`` are optional with default values of None. For example, ``A_eq`` and ``b_eq`` can be set without ``A_ub`` or ``b_ub``: >>> lp3 = _LPProblem(c=[-1, 4], A_eq=[[2, 1]], b_eq=[10]) c � � | � dd� � }|r|�t j |� � }|r|�t j |� � }t j |� � pt j |� � }h d�}ddh}||v r|rt d|� d|� d �� � �| � d d� � }|s$|r"|dk rd| d <