• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

msakai / haskell-MIP / 351

04 Jan 2026 10:32PM UTC coverage: 77.291% (+0.005%) from 77.286%
351

push

github

msakai
update ChangeLog for v0.2.0.1

1518 of 1964 relevant lines covered (77.29%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.79
/MIP/src/Numeric/Optimization/MIP/Solver/HiGHS.hs
1
{-# OPTIONS_GHC -Wall #-}
2
{-# OPTIONS_HADDOCK show-extensions #-}
3
{-# LANGUAGE MultiParamTypeClasses #-}
4
-----------------------------------------------------------------------------
5
-- |
6
-- Module      :  Numeric.Optimization.MIP.Solver.HiGHS
7
-- Copyright   :  (c) Masahiro Sakai 2025
8
-- License     :  BSD-style
9
--
10
-- Maintainer  :  masahiro.sakai@gmail.com
11
-- Stability   :  provisional
12
-- Portability :  non-portable
13
--
14
-----------------------------------------------------------------------------
15
module Numeric.Optimization.MIP.Solver.HiGHS
16
  ( HiGHS (..)
17
  , highs
18
  ) where
19

20
import Data.Default.Class
21
import qualified Data.Text.Lazy.IO as TLIO
22
import System.IO
23
import System.IO.Temp
24
import qualified Numeric.Optimization.MIP.LPFile as LPFile
25
import qualified Numeric.Optimization.MIP.Base as MIP
26
import Numeric.Optimization.MIP.Solver.Base
27
import qualified Numeric.Optimization.MIP.Solution.HiGHS as HiGHSSol
28
import Numeric.Optimization.MIP.Internal.ProcessUtil (runProcessWithOutputCallback)
29

30
-- | A solver instance for calling @highs@ command from [HiGHS](https://github.com/ERGO-Code/HiGHS).
31
--
32
-- Use 'highs' and record update syntax to modify its field.
33
data HiGHS
34
  = HiGHS
35
  { highsPath :: String
1✔
36
  , highsArgs :: [String]
1✔
37
  }
38

39
instance Default HiGHS where
40
  def = highs
×
41

42
-- | Default value of t'HiGHS'
43
highs :: HiGHS
44
highs = HiGHS "highs" []
1✔
45

46
instance IsSolver HiGHS IO where
1✔
47
  solve' solver opt prob = do
1✔
48
    case LPFile.render def prob of
×
49
      Left err -> ioError $ userError err
×
50
      Right lp -> do
1✔
51
        withSystemTempFile "highs.lp" $ \fname1 h1 -> do
1✔
52
          TLIO.hPutStr h1 lp
1✔
53
          hClose h1
1✔
54

55
          withSystemTempFile "highs.sol" $ \fname2 h2 -> do
1✔
56
            hClose h2
1✔
57

58
            withSystemTempFile "highs_options.txt" $ \fname3 h3 -> do
1✔
59
              -- XXX: HiGHS does not support multiple options files
60
              options_args <-
61
                case solveTol opt of
1✔
62
                  Nothing -> return []
1✔
63
                  Just tol -> do
1✔
64
                    hPutStrLn h3 $ "mip_feasibility_tolerance = " ++ show (MIP.integralityTol tol)
1✔
65
                    hPutStrLn h3 $ "primal_feasibility_tolerance = " ++ show (MIP.feasibilityTol tol)
1✔
66
                    hPutStrLn h3 $ "dual_feasibility_tolerance = " ++ show (MIP.optimalityTol tol)
1✔
67
                    return ["--options_file", fname3]
1✔
68
              hClose h3
1✔
69

70
              let args = highsArgs solver ++
1✔
71
                         ["--model_file", fname1, "--solution_file", fname2] ++
1✔
72
                         options_args ++
1✔
73
                         (case solveTimeLimit opt of
1✔
74
                            Nothing -> []
1✔
75
                            Just sec -> ["--time_limit", show sec])
×
76
                  onGetLine s = solveLogger opt s
×
77
                  onGetErrorLine = solveErrorLogger opt
×
78
              _exitcode <- runProcessWithOutputCallback (highsPath solver) args Nothing "" onGetLine onGetErrorLine
×
79
              HiGHSSol.readFile fname2
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc