module AI.Examples where
import AI.VersionSpaces
import AI.LogicHelpers (choices, fairInts, observeAll)
import GHC.Real (infinity)
sizeVS :: VersionSpace Int Int
sizeVS = (VS intHs) `union` (intFromRatTr $ VS ratHs)
intFromRatTr :: VersionSpace Rational Rational -> VersionSpace Int Int
intFromRatTr = Tr fromIntegral fromIntegral round
data Rectangle = Rect {x_coord :: Int,
y_coord :: Int,
width :: Int,
height :: Int
} deriving (Show, Eq)
type Region1D = (Int, Int)
rectangleVS :: VersionSpace Rectangle Rectangle
rectangleVS = rectTr $ region1d `join` region1d
where
rectTr = Tr decompose decompose compose
compose ((x, w), (y, h)) = Rect x y w h
decompose (Rect x y w h) = ((x, w), (y, h))
region1d :: VersionSpace Region1D Region1D
region1d = sizeVS `join` sizeVS
intHs :: BSR (Int, Int) i Int
intHs = BSR { storage = (minBound :: Int, maxBound :: Int)
, narrow = narrowIntHs
, hypos = hyposIntHs
}
narrowIntHs :: BSR (Int, Int) i Int -> i -> Int -> BSR (Int, Int) i Int
narrowIntHs EmptyBSR _ _ = EmptyBSR
narrowIntHs (BSR (l, u) f g) _ exOut
| exOut < l || u < exOut = EmptyBSR
| otherwise = BSR (exOut, exOut) f g
hyposIntHs :: BSR (Int, Int) i Int -> [(i -> Int)]
hyposIntHs EmptyBSR = []
hyposIntHs (BSR (l,u) _ _) = [\_-> y | y <- observeAll $ fairInts l u]
ratHs :: BSR (Rational, Rational) Rational Rational
ratHs = BSR { storage = (infinity, infinity)
, narrow = narrowRatHs
, hypos = hyposRatHs
}
narrowRatHs :: BSR (Rational, Rational) Rational Rational
-> Rational
-> Rational
-> BSR (Rational, Rational) Rational Rational
narrowRatHs EmptyBSR _ _ = EmptyBSR
narrowRatHs bsr@(BSR (n, d) f g) exIn exOut
| d == infinity = bsr { storage = (exOut, exIn) }
| exOut / exIn == n / d = bsr
| otherwise = EmptyBSR
hyposRatHs :: BSR (Rational, Rational) Rational Rational -> [Rational -> Rational]
hyposRatHs EmptyBSR = []
hyposRatHs (BSR (n, d) _ _) | d == infinity = [\_-> y | y <- [n .. d]]
| n == 0 = [\_ -> 0]
| otherwise = [\x -> x * (n / d)]