@hackage MIP0.2.0.0

Library for using Mixed Integer Programming (MIP)

  • Installation

  • Dependencies (20)

  • Dependents (2)

    @hackage/toysolver, @hackage/MIP-glpk
  • Package Flags

      testcbc
       (off by default)

      run test cases that depend on cbc command

      testcplex
       (off by default)

      run test cases that depend on cplex command

      testglpsol
       (off by default)

      run test cases that depend on glpsol command

      testgurobicl
       (off by default)

      run test cases that depend on gurobi_cl command

      testhighs
       (off by default)

      run test cases that depend on highs command

      testlpsolve
       (off by default)

      run test cases that depend on lp_solve command

      testprintemps
       (off by default)

      run test cases that depend on mps_solver.exe command of printemps

      testscip
       (off by default)

      run test cases that depend on scip command

      withzlib
       (on by default)

      Use zlib package to support gzipped files

MIP

Hackage Hackage Deps License: BSD 3-Clause

Library for using Mixed Integer Programming (MIP) in Haskell. This library contains functions like:

  • Reading / Writing MIP problem files (e.g. LP file or MPS file),
  • Invokling MIP solvers like Gurobi, CPLEX, CBC, GLPK, lp_solve,
  • Reading solution files of those solvers.

Examples

Convert LP file into MPS file

import qualified Numeric.Optimization.MIP as MIP

main :: IO ()
main = do
  prob <- MIP.readFile MIP.def "samples/lp/test.lp"
  MIP.writeFile MIP.def "test.mps" prob

Solve LP file using the CbC solver

import Control.Monad
import qualified Data.Map.Lazy as Map
import qualified Data.Text as T

import qualified Numeric.Optimization.MIP as MIP
import Numeric.Optimization.MIP.Solver

main :: IO ()
main = do
  prob <- MIP.readFile MIP.def "samples/lp/test.lp"
  sol <- solve cbc MIP.def{ solveTimeLimit = Just 10.0 } prob
  print $ MIP.solStatus sol
  putStrLn $ "Objective Value: " ++ show (MIP.solObjectiveValue sol)
  forM_ (MIP.variables prob) $ \v -> do
    putStrLn $ T.unpack (MIP.varName v) ++ " = " ++ show (MIP.solVariables sol Map.! v)

Construcing a problem instance and solving it using the CbC solver

{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import qualified Data.Map.Lazy as Map
import qualified Data.Text as T

import qualified Numeric.Optimization.MIP as MIP
import Numeric.Optimization.MIP ((.<=.))
import Numeric.Optimization.MIP.Solver

-- Example from https://en.wikipedia.org/wiki/Integer_programming
main :: IO ()
main = do
  let [x, y] = map MIP.varExpr ["x", "y"]
      prob =
        MIP.def
        { MIP.objectiveFunction =
            MIP.def
            { MIP.objDir = MIP.OptMax
            , MIP.objExpr = y
            }
        , MIP.constraints =
            [ - x +   y .<=. 1
            , 3*x + 2*y .<=. 12
            , 2*x + 3*y .<=. 12
            ]
        , MIP.varDomains =
            Map.fromList
            [ ("x", (MIP.IntegerVariable, (0, MIP.PosInf)))
            , ("y", (MIP.IntegerVariable, (0, MIP.PosInf)))
            ]
        }

  sol <- solve cbc MIP.def{ solveTimeLimit = Just 10.0 } prob
  print $ MIP.solStatus sol
  putStrLn $ "Objective Value: " ++ show (MIP.solObjectiveValue sol)
  forM_ (MIP.variables prob) $ \v -> do
    putStrLn $ T.unpack (MIP.varName v) ++ " = " ++ show (MIP.solVariables sol Map.! v)