Skip to content

Instantly share code, notes, and snippets.

@timjb
Created October 31, 2015 12:23
Show Gist options
  • Select an option

  • Save timjb/c216571451551fbd400d to your computer and use it in GitHub Desktop.

Select an option

Save timjb/c216571451551fbd400d to your computer and use it in GitHub Desktop.
#!/usr/bin/env stack
-- stack --resolver lts-3.11 --install-ghc runghc --package hmatrix-glpk-0.4.1.0
module Main where
import Numeric.LinearProgramming
constraints :: [Bound [Double]]
constraints =
-- first vector is valid
[ [ 1, 1, 1, 0, 0, 0, 0, 0, 0 ] :>=: 0
, [ 1, 0, 0, 0, 0, 0, 0, 0, 0 ] :>=: 1
, [ 0, 1, 0, 0, 0, 0, 0, 0, 0 ] :<=: 0
, [ 0, 0, 1, 0, 0, 0, 0, 0, 0 ] :<=: 0
-- second vector is valid
, [ 0, 0, 0, 1, 1, 1, 0, 0, 0 ] :>=: 0
, [ 0, 0, 0, 0, 1, 0, 0, 0, 0 ] :>=: 1
, [ 0, 0, 0, 1, 0, 0, 0, 0, 0 ] :<=: 0
, [ 0, 0, 0, 0, 0, 1, 0, 0, 0 ] :<=: 0
-- third vector is valid
, [ 0, 0, 0, 0, 0, 0, 1, 1, 1 ] :>=: 0
, [ 0, 0, 0, 0, 0, 0, 0, 0, 1 ] :>=: 1
, [ 0, 0, 0, 0, 0, 0, 1, 0, 0 ] :<=: 0
, [ 0, 0, 0, 0, 0, 0, 0, 1, 0 ] :<=: 0
-- at least one vector is strictly positive
--, [ 1, 1, 1, 1, 1, 1, 1, 1, 1 ] :>=: 1
-- the third vector is a combination of the first two
, [ 1, 0, 0, -1, 0, 0, 1, 0, 0 ] :==: 0
, [ 0, 1, 0, 0, -1, 0, 0, 1, 0 ] :==: 0
, [ 0, 0, 1, 0, 0, -1, 0, 0, 1 ] :==: 0
]
main :: IO ()
main = print $ simplex opt (Dense constraints) []
where opt = Minimize [1,1,1,1,1,1,1,1,1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment