-- | Bindings to the file I/O functions from GLPK, on the CPLEX LP file format.
module Data.LinearProgram.GLPK.IO where

import Data.LinearProgram.Common

import Data.LinearProgram.GLPK.Common
import Data.LinearProgram.GLPK.IO.Internal

{-# SPECIALIZE readLP :: (Ord v, Read v) => FilePath -> IO (LP v Double) #-}
-- | Read a linear program from a file in CPLEX LP format.  Warning: this will not necessarily succeed
-- on all files generated by 'writeLP', as variable names may be changed.
readLP :: (Ord v, Read v, Fractional c) => FilePath -> IO (LP v c)
readLP = fmap (mapVals realToFrac . mapVars read) . readLP'

-- | Read a linear program from a file in CPLEX LP format.
readLP' :: FilePath -> IO (LP String Double)
readLP' = runGLPK . readGLPLP

-- | Write a linear program to a file in CPLEX LP format.
writeLP :: (Ord v, Show v, Real c) => FilePath -> LP v c -> IO ()
writeLP file = runGLPK . writeGLPLP file