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


// 3/26/05 Changed so that readmps could be integrated 
//         into retroLP
// 8/8/01 Added allocations for lpb_version,names(lpbV1)

// These routines allocate memory for LP_structure for use
// with MPS files

//  Allocates arrays for the input.

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

LP_state *allocate_LP_state();
double **allocate_a(long , long);
short *allocate_svector(long);
void *allocate_evector(long,size_t);
int *allocate_ivector(long);
long *allocate_lvector(long);
double *allocate_dvector(long);
char *allocate_cvector(long );
char *allocate_strvector(int ,long );
void free_a(double ** , long , long );

LP_state *make_arrays(long m, long n)
{
   LP_state *l;
   l = allocate_LP_state();
   l->lpb_version = allocate_cvector(10);
   l->name = allocate_cvector(101);
   l->ntype = (var_type *)allocate_evector(n, sizeof(var_type));
   l->a = allocate_a(m, n);
   l->btype = (var_type *)allocate_evector(m, sizeof(var_type));
   l->bl = allocate_dvector(m);
   l->bu = allocate_dvector(m);
   l->nl = allocate_dvector(n);
   l->nu = allocate_dvector(n);
   l->x = allocate_dvector(n);
   l->nrange = (var_range *)allocate_evector(n, sizeof(var_range));
   l->ibasic = allocate_lvector(m +1);
   l->b = allocate_dvector(m + 1);
   l->brange = (var_range *)allocate_evector(m, sizeof(var_range));
   l->jnonbasic = allocate_lvector(n);
// Used for lpbV1 and after
   l->names = allocate_strvector(8,m+n);
   return l;  // 'ell'
}
//============================ RETURN_ARRAYS =====================
void free_arrays(LP_state *lp)
{
   free(lp->names);
   lp->names = NULL;
   free(lp->jnonbasic);
   lp->jnonbasic = NULL;
   free(lp->x);
   lp->x = NULL;
   free(lp->nl);
   lp->nl = NULL;
   free(lp->nu);
   lp->nu = NULL;
   free(lp->ntype);
   lp->ntype = NULL;
   free(lp->nrange);
   lp->nrange = NULL;
   free(lp->b);
   lp->b = NULL;
   free(lp->bl);
   lp->bl = NULL;
   free(lp->bu);
   lp->bu = NULL;
   free(lp->ibasic);
   lp->ibasic = NULL;
   free(lp->btype);
   lp->btype = NULL;
   free(lp->brange);
   lp->brange = NULL;
   free(lp->name);
   lp->name = NULL;
   free(lp->lpb_version);
   lp->lpb_version = NULL;
   free_a(lp->a,lp->m, lp->n);
   lp->a = NULL;
   free(lp);
   lp = NULL;
}

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