/************************************************************************
* retroLP solves linear programs using the simplex method.             *
* Copyright (C) 2001, 2003, 2005 Gavriel Yarmish & Richard Van Slyke.  *
* For further information, and gpl licensing, see the end of this file.*
************************************************************************/


// Split in two; simplex.h defines lp structure, params.h defines
// and declares global parameters
// 4/3/05 Add header guard
// 8/8/01 Added lpb_version, rname, and lname to LP_state to support
// variable names in output

#ifndef SIMPLEX_H
#define SIMPLEX_H

// DEFINITIONS:

#define TRUE (1)
#define FALSE (0)

// DESCRIBES TYPE OF VARIABLE
enum var_type
{
   TERROR,         // Shouldn't happen
   FREE,          // No bounds
   LBOUNDED,      // Lower bounds only
   UBOUNDED,      // Upper bounds only
   BOTHBOUNDS,    // Upper and lower bounds
   FIXED          // Fixed: upper =  lower
};

// DESCRIBES RANGE OF CURRENT VALUE
enum var_range
{
   RERROR,         // Shouldn't happen
   BELOW,         // Below lower bound (infeasible)
   ATLOWER,       // At lower bound (within epsilon)
   BETWEEN,       // Strictly between bounds
   ATUPPER,       // At upper bound (within epsilon)
   ABOVE,         // Above upper bound (infeasible)
   ATBOTH         // At both bounds (feasible fixed
                  // variable)
};

// DESCRIBES THE RESULT OF ROW_CHOICE
enum iter_result
{
   IERROR,                  // Shouldn't happen
   UNBOUNDED,              // No row binding; unbounded
                              // solution possible.
   PIVOTLBOUND,        // Pivot, basic goes
                              // non-basic at lower bound.
   PIVOTUBOUND,        // Pivot, basic goes
                              // non-basic at upper bound.
   NOPIVOTLBOUND,      // No pivot, non-basic goe to
                              // lower bound.
   NOPIVOTUBOUND,      // No pivot, non-basic goe to
                              // upper bound.
   BASICTOFEASIBLEL,       // Infeasible basic becomes
                              // feasible at lower bound,
                              // Phase 1 objective must be
                              // modified.
   BASICTOFEASIBLEU,       // Infeasible basic becomes
                              // feasible at upper bound,
                              // Phase 1 objective must be
                              // modified.
   NONBASICTOFEASIBLEL,    // Infeasible non-basic becomes
                              // feasible at lower bound,
                              // Phase 1 objective must be
                              // modified.
   NONBASICTOFEASIBLEU,    // Infeasible non-basic becomes
                              // feasible at upper bound,
                              // Phase 1 objective must be
                              // modified.
   NONDEGENERATEPIVOT  // Ordinary pivot with incoming
                              // basic variable not at a bound
};


// LP_state is a structure that is supposed to aggregate all the
// data structures needed for the simplex algorithm

typedef struct
{
    char *lpb_version;   // Version of lpb file. Currently "lpbV1"
                        // (10 char)
    char *name;         // name of problem (usually file name (100))
    long m;             // number of rows
    long n;             // number of columns
                           // (actually, the matrix is (m+2)x(n+1))
    long mm;            // index of the current objective row; m+1
                           // for Phase I; 0 for Phase 2.
    double ** a;        // points to the constraint matrix ((m+2)x(n+1))
                           // (n+1)
    var_type *ntype;    // types of non-basic variables: fixed.
                           // lower bounded, upper bounded, both, free. (n+1)
    double *nl;         // lower bounds of non-basics n
    double *nu;         // upper bounds of non-basics n
    long *jnonbasic;    // indices of current non-basic variables
    var_range *nrange;  // non-basic values within, at, below,
                           // or above bounds.
    double *x;          // current value of non-basic variables (to
                           // implement EXPAND) (n+1)
    var_type *btype;       // types of basic variables: fixed. lower
                           // bounded, upper bounded, both, free. (n+1)
    double *bl;         // lower bounds for basic variables
    double *bu;         // upper bounds for basic variables
    long *ibasic;       // indices of current basic variables (m+1)
    var_range *brange;      // basic values within, at, below,
                           // or above bounds.
    double *b;          // current value of basic variables
//  Following not in intitial version; only version "lpbV1" or later
    char * names;       // String of characters containing row and col NAMES 9(m+n+1)bytes

} LP_state;

#endif // SIMPLEX_H

/************************************************************************
* retroLP solves linear programs using the simplex method.             *
* Copyright (C) 2001, 2003, 2005 Gavriel Yarmish & Richard Van Slyke.  *
*                                                                      *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or    *
* (at your option) any later version.                                  *
*                                                                      *
* This program is distributed in the hope that it will be useful,      *
* but WITHOUT ANY WARRANTY; without even the implied warranty of       *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
* GNU General Public License for more details.                         *
*                                                                      *
* You should have received a copy of the GNU General Public License    *  
* along with this program; if not, write to the Free Software          *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,           *
*                                                                      *
************************************************************************/
