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


#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include"simplex.h"
#include"params.h"

// This routine checks all non-basic variables
// If a non-basic variable is near its bound it is set to the bound
// If not it is unchanged

void reset(LP_state* s)
{
   long j;
// Check non-basic variables
   for(j=1; j<=s->n; j++)
   {
      switch(s->ntype[j])
      {
         case LBOUNDED:
            if(fabs(s->x[j]- s->nl[j])< delf)
            {
               s->x[j]=s->nl[j];
            }
            break;
         case UBOUNDED:
            if(fabs(s->x[j]- s->nu[j])< delf)
            {
               s->x[j]=s->nu[j];
            }
            break;
         case BOTHBOUNDS:
            if(fabs(s->x[j]- s->nl[j])< delf)
            {
               s->x[j]=s->nl[j];
            }
            else if(fabs(s->x[j]- s->nu[j])< delf)
            {
               s->x[j]=s->nu[j];
            }
            break;
         case FIXED:
            if(fabs(s->x[j]- s->nl[j])< delf)
            {
               s->x[j]=s->nl[j];
            }
            break;
         case FREE: // Leave at curretn value
            break;
         default:
            printf("\nImproper type code");
            exit (506);
      } // end switch

   } // end for j loop
   return;
}

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