/************************************************************************
* 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.*
************************************************************************/


// IMPORTANT! IT IS IMPORTANT TO MAINTAIN CONSISTANCY AMONG
// PIVOT (used in refresh), PIVOT_PLUS (used in regular iteration,
// AND CHOOSE_COLUMN (used if no available column from PIVOT_PLUS)

// To improve locality, we scan matrix alternately left to right
// and right to left, controlled by pdir
extern short pdir; // Used in pivot, and pivot+


#include "simplex.h"
void pivot(LP_state *s, long ip, long jp )
/* New pivot (reversed) in aji format*/
{
    long i, j;
    double t;
    double piv;

    piv=1.0/s->a[jp][ip];
// See which direction to go through the matrix
    long jj;
    pdir = -pdir;
    for (jj=0;jj<=s->n; jj++)
    {
         if(pdir > 0)j = jj; else j = s->n - jj;
         if(j==jp)continue;
         t = (s->a[j][ip] *= -piv);
         for (i=0;i<ip;i++)
        {
            s->a[j][i] += s->a[jp][i]*t;
        }

        for (i=ip+1;i<=s->m+1;i++)
        {
            s->a[j][i] += s->a[jp][i]*t;
        }
    }

    for (i=0;i<=s->m+1;i++)
        s->a[jp][i] *= piv;

    s->a[jp][ip]=piv;

}

/************************************************************************
* 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,           *
*                                                                      *
************************************************************************/
