packages feed

highs-lp-0.0: src/Numeric/HiGHS/LP/Example.hs

module Numeric.HiGHS.LP.Example
  {-# WARNING "Only for documentation. Do not import." #-}
  where

import qualified Numeric.HiGHS.LP as LP
import Numeric.HiGHS.LP ((.*), (==.))

import qualified Data.Array.Comfort.Storable as Array
import qualified Data.Array.Comfort.Shape as Shape
import Data.Array.Comfort.Storable (Array)
import Data.Tuple.HT (mapSnd)

import Text.Printf (printf)


type X = Shape.Element
type PairShape = Shape.NestedTuple Shape.TupleIndex (X,X)

main :: IO ()
main =
  case Shape.indexTupleFromShape (Shape.static :: PairShape) of
    (posIx,negIx) ->
      case fmap (mapSnd Array.toTuple) $ snd $
           LP.solve LP.choose [] [[1.*posIx, (-1).*negIx] ==. 314]
             (LP.Minimize,
              Array.fromTuple (23,42) :: Array PairShape Double)
        of
          Just (absol, (pos, neg)) ->
            printf "absol %f,  pos %f, neg %f\n" absol pos neg
          _ -> fail "HiGHS solver failed"