/* $Id: zlpglue.c,v 1.2 2012/07/29 15:09:31 bzfkocht Exp $ */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*                                                                           */
/*   File....: zlpglue.c                                                     */
/*   Name....: LP Storage Interface Zimpl commandline part                   */
/*   Author..: Thorsten Koch                                                 */
/*   Copyright by Author, All rights reserved                                */
/*                                                                           */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
 * Copyright (C) 2001-2012 by Thorsten Koch <koch@zib.de>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3
 * 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <gmp.h>

#include "bool.h"
#include "mshell.h"
#include "ratlptypes.h"
#include "numb.h"
#include "elem.h"
#include "tuple.h"
#include "mme.h"
#include "bound.h"
#include "mono.h"
#include "term.h"
#include "ratlp.h"
#include "zlpglue.h"

/*lint -esym(818, lp) 'lp' could be declared as pointing to const */

static const char* const title = "This file was automatically generated by Zimpl";

/** Print some statistics about the mathematical program stored.
 */
void zlp_stat(
   Lps* lp)         /**< Pointer to storage */
{
   assert(lp != NULL);

   lps_stat(lp);
}

/** Set the maximal length for generated variable and constraint names.
 */ 
void zlp_setnamelen(
   Lps* lp,          /**< Pointer to storage */
   int  name_len)    /**< Maximal length for generated variable and constraint names */
{
   assert(lp != NULL);

   lps_setnamelen(lp, name_len);
}

#if 0 /* Not used anymore */
Bool zlp_presolve(Lps* lp)
{
   PSResult res;
   
   res = lps_presolve(lp, verbose);

   switch(res)
   {
   case PRESOLVE_INFEASIBLE :
      printf("Model is infeasible\n");
      return FALSE;
   case PRESOLVE_UNBOUNDED :
      printf("Model is unbounded\n");
      return FALSE;
   case PRESOLVE_VANISHED :
      printf("Presolve solved the problem -- see .tbl file for values\n");
      break;
   case PRESOLVE_OKAY :
      break;
   default :
      abort();
   }
   return TRUE;
}

#endif
     

/** Write mathematical program to file.
 */
void zlp_write(
   Lps*        lp,         /**< Pointer to storage */
   FILE*       fp,         /**< File pointer to write to */
   LpFormat    format,     /**< File format */
   const char* text)       /**< Comment to be written into the file */
{  
   assert(lp != NULL);
   assert(fp != NULL);

   lps_scale(lp);
   lps_write(lp, fp, format, text);
}

/** Write variable and constraint translation table to file.
 *  Depending on the maximal allowed name length, variable and constraint
 *  names will be mangled to keep them unique. This table provied the
 *  necessary translation between the mangled and the original name.
 */
void zlp_transtable(
   Lps*     lp,         /**< Pointer to storage */
   FILE*    fp,         /**< File pointer to write to */
   LpFormat format)     /**< File format */
{
   assert(lp != NULL);
   assert(fp != NULL);
   
   lps_transtable(lp, fp, format, "zimpl");
}

/** Write branching ordering information to file.
 */
void zlp_orderfile(
   Lps*     lp,         /**< Pointer to storage */
   FILE*    fp,         /**< File pointer to write to */
   LpFormat format)     /**< File format */
{
   assert(lp != NULL);
   assert(fp != NULL);

   lps_orderfile(lp, fp, format, title);
}

/** Write Mip STart file.
 */
void zlp_mstfile(
   Lps*     lp,         /**< Pointer to storage */
   FILE*    fp,         /**< File pointer to write to */
   LpFormat format)     /**< File format */
{
   assert(lp != NULL);
   assert(fp != NULL);

   lps_mstfile(lp, fp, format, title);
}

