interval-algebra-0.7.0: An implementation of Allen's interval algebra for temporal logic
Copyright(c) NoviSci Inc 2020
LicenseBSD3
Maintainerbsaul@novisci.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

IntervalAlgebra

Description

The IntervalAlgebra module provides data types and related classes for the interval-based temporal logic described in Allen (1983) and axiomatized in Allen and Hayes (1987).

A good primer on Allen's algebra can be found here.

Design

The module is built around four typeclasses designed to separate concerns of constructing, relating, and combining types that contain Intervals:

  1. Intervallic provides an interface to the data structures which contain an Interval.
  2. IntervalAlgebraic provides an interface to the IntervalRelations, the workhorse of Allen's temporal logic.
  3. IntervalCombinable provides an interface to methods of combining two Intervals.
  4. IntervalSizeable provides methods for measuring and modifying the size of an interval.

An advantage of nested typeclass design is that developers can define an Interval of type a with just the amount of structure that they need.

Total Ordering of Intervals

The modules makes the (opinionated) choice of a total ordering for Intervallic Intervals. Namely, the ordering is based on first ordering the begins then the ends.

Development

This module is under development and the API may change in the future.

Synopsis

Classes

class (Ord a, Show a) => Intervallic i a where Source #

The Intervallic typeclass defines how to get and set the Interval content of a data structure. It also includes functions for getting the begin and end this data.

Minimal complete definition

getInterval, setInterval

Methods

getInterval :: i a -> Interval a Source #

Get the interval from an i a

setInterval :: i a -> Interval a -> i a Source #

Set the interval in an i a

begin :: i a -> a Source #

Access the ends of an i a .

end :: i a -> a Source #

Access the ends of an i a .

Instances

Instances details
(Ord a, Show a) => Intervallic Interval a Source # 
Instance details

Defined in IntervalAlgebra

(Ord a, Show a) => Intervallic (PairedInterval b) a Source # 
Instance details

Defined in IntervalAlgebra.PairedInterval

class (Eq (i a), Intervallic i a) => IntervalAlgebraic i a where Source #

The IntervalAlgebraic typeclass specifies the functions and relational operators for interval-based temporal logic. The typeclass defines the relational operators for types that contain an 'Interval a', plus other useful utilities such as disjoint, within, and unionPredicates.

Minimal complete definition

Nothing

Methods

relate :: i a -> i a -> IntervalRelation (i a) Source #

Compare two i a to determine their IntervalRelation.

predicate' :: IntervalRelation (i a) -> ComparativePredicateOf (i a) Source #

Maps an IntervalRelation to its corresponding predicate function.

predicates :: Set (IntervalRelation (i a)) -> [ComparativePredicateOf (i a)] Source #

Given a set of IntervalRelations return a list of predicate functions corresponding to each relation.

predicate :: Set (IntervalRelation (i a)) -> ComparativePredicateOf (i a) Source #

Forms a predicate function from the union of a set of IntervalRelations.

toSet :: [IntervalRelation (i a)] -> Set (IntervalRelation (i a)) Source #

Shortcut to creating a 'Set IntervalRelation' from a list.

compose :: IntervalRelation (i a) -> IntervalRelation (i a) -> Set (IntervalRelation (i a)) Source #

Compose two interval relations according to the rules of the algebra. The rules are enumerated according to this table.

complement :: Set (IntervalRelation (i a)) -> Set (IntervalRelation (i a)) Source #

Finds the complement of a 'Set IntervalRelation'.

intersection :: Set (IntervalRelation (i a)) -> Set (IntervalRelation (i a)) -> Set (IntervalRelation (i a)) Source #

Find the intersection of two Sets of IntervalRelations.

union :: Set (IntervalRelation (i a)) -> Set (IntervalRelation (i a)) -> Set (IntervalRelation (i a)) Source #

Find the union of two Sets of IntervalRelations.

converse :: Set (IntervalRelation (i a)) -> Set (IntervalRelation (i a)) Source #

Find the converse of a 'Set IntervalRelation'.

equals :: ComparativePredicateOf (i a) Source #

Does x equal y?

meets :: ComparativePredicateOf (i a) Source #

Does x meet y? Is y metBy x?

metBy :: ComparativePredicateOf (i a) Source #

Does x meet y? Is y metBy x?

before :: ComparativePredicateOf (i a) Source #

Is x before y? Is x after y?

after :: ComparativePredicateOf (i a) Source #

Is x before y? Is x after y?

overlaps :: ComparativePredicateOf (i a) Source #

Does x overlap y? Is x overlapped by y?

overlappedBy :: ComparativePredicateOf (i a) Source #

Does x overlap y? Is x overlapped by y?

starts :: ComparativePredicateOf (i a) Source #

Does x start y? Is x started by y?

startedBy :: ComparativePredicateOf (i a) Source #

Does x start y? Is x started by y?

precedes :: ComparativePredicateOf (i a) Source #

Synonyms for starts and startedBy

precededBy :: ComparativePredicateOf (i a) Source #

Synonyms for starts and startedBy

finishes :: ComparativePredicateOf (i a) Source #

Does x finish y? Is x finished by y?

finishedBy :: ComparativePredicateOf (i a) Source #

Does x finish y? Is x finished by y?

during :: ComparativePredicateOf (i a) Source #

Is x during y? Does x contain y?

contains :: ComparativePredicateOf (i a) Source #

Is x during y? Does x contain y?

unionPredicates :: [ComparativePredicateOf (i a)] -> ComparativePredicateOf (i a) Source #

Compose a list of interval relations with _or_ to create a new ComparativePredicateOf i a. For example, unionPredicates [before, meets] creates a predicate function determining if one interval is either before or meets another interval.

(<|>) :: ComparativePredicateOf (i a) -> ComparativePredicateOf (i a) -> ComparativePredicateOf (i a) Source #

Operator for composing the union of two predicates

disjointRelations :: Set (IntervalRelation (i a)) Source #

withinRelations :: Set (IntervalRelation (i a)) Source #

disjoint :: ComparativePredicateOf (i a) Source #

Are x and y disjoint (before, after, meets, or metBy)?

notDisjoint :: ComparativePredicateOf (i a) Source #

Are x and y not disjoint; i.e. do they share any support?

concur :: ComparativePredicateOf (i a) Source #

A synonym for notDisjoint.

within :: ComparativePredicateOf (i a) Source #

Is x entirely *within* the endpoints of y? That is, during, starts, finishes, or equals?

enclose :: ComparativePredicateOf (i a) Source #

Does x enclose y? That is, is y within x?

enclosedBy :: ComparativePredicateOf (i a) Source #

Synonym for within.

Instances

Instances details
(Eq a, Ord a, Show a) => IntervalAlgebraic Interval a Source # 
Instance details

Defined in IntervalAlgebra

Methods

relate :: Interval a -> Interval a -> IntervalRelation (Interval a) Source #

predicate' :: IntervalRelation (Interval a) -> ComparativePredicateOf (Interval a) Source #

predicates :: Set (IntervalRelation (Interval a)) -> [ComparativePredicateOf (Interval a)] Source #

predicate :: Set (IntervalRelation (Interval a)) -> ComparativePredicateOf (Interval a) Source #

toSet :: [IntervalRelation (Interval a)] -> Set (IntervalRelation (Interval a)) Source #

compose :: IntervalRelation (Interval a) -> IntervalRelation (Interval a) -> Set (IntervalRelation (Interval a)) Source #

complement :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

intersection :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

union :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

converse :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

equals :: ComparativePredicateOf (Interval a) Source #

meets :: ComparativePredicateOf (Interval a) Source #

metBy :: ComparativePredicateOf (Interval a) Source #

before :: ComparativePredicateOf (Interval a) Source #

after :: ComparativePredicateOf (Interval a) Source #

overlaps :: ComparativePredicateOf (Interval a) Source #

overlappedBy :: ComparativePredicateOf (Interval a) Source #

starts :: ComparativePredicateOf (Interval a) Source #

startedBy :: ComparativePredicateOf (Interval a) Source #

precedes :: ComparativePredicateOf (Interval a) Source #

precededBy :: ComparativePredicateOf (Interval a) Source #

finishes :: ComparativePredicateOf (Interval a) Source #

finishedBy :: ComparativePredicateOf (Interval a) Source #

during :: ComparativePredicateOf (Interval a) Source #

contains :: ComparativePredicateOf (Interval a) Source #

unionPredicates :: [ComparativePredicateOf (Interval a)] -> ComparativePredicateOf (Interval a) Source #

(<|>) :: ComparativePredicateOf (Interval a) -> ComparativePredicateOf (Interval a) -> ComparativePredicateOf (Interval a) Source #

disjointRelations :: Set (IntervalRelation (Interval a)) Source #

withinRelations :: Set (IntervalRelation (Interval a)) Source #

disjoint :: ComparativePredicateOf (Interval a) Source #

notDisjoint :: ComparativePredicateOf (Interval a) Source #

concur :: ComparativePredicateOf (Interval a) Source #

within :: ComparativePredicateOf (Interval a) Source #

enclose :: ComparativePredicateOf (Interval a) Source #

enclosedBy :: ComparativePredicateOf (Interval a) Source #

(Eq b, Show a, Ord a) => IntervalAlgebraic (PairedInterval b) a Source # 
Instance details

Defined in IntervalAlgebra.PairedInterval

Methods

relate :: PairedInterval b a -> PairedInterval b a -> IntervalRelation (PairedInterval b a) Source #

predicate' :: IntervalRelation (PairedInterval b a) -> ComparativePredicateOf (PairedInterval b a) Source #

predicates :: Set (IntervalRelation (PairedInterval b a)) -> [ComparativePredicateOf (PairedInterval b a)] Source #

predicate :: Set (IntervalRelation (PairedInterval b a)) -> ComparativePredicateOf (PairedInterval b a) Source #

toSet :: [IntervalRelation (PairedInterval b a)] -> Set (IntervalRelation (PairedInterval b a)) Source #

compose :: IntervalRelation (PairedInterval b a) -> IntervalRelation (PairedInterval b a) -> Set (IntervalRelation (PairedInterval b a)) Source #

complement :: Set (IntervalRelation (PairedInterval b a)) -> Set (IntervalRelation (PairedInterval b a)) Source #

intersection :: Set (IntervalRelation (PairedInterval b a)) -> Set (IntervalRelation (PairedInterval b a)) -> Set (IntervalRelation (PairedInterval b a)) Source #

union :: Set (IntervalRelation (PairedInterval b a)) -> Set (IntervalRelation (PairedInterval b a)) -> Set (IntervalRelation (PairedInterval b a)) Source #

converse :: Set (IntervalRelation (PairedInterval b a)) -> Set (IntervalRelation (PairedInterval b a)) Source #

equals :: ComparativePredicateOf (PairedInterval b a) Source #

meets :: ComparativePredicateOf (PairedInterval b a) Source #

metBy :: ComparativePredicateOf (PairedInterval b a) Source #

before :: ComparativePredicateOf (PairedInterval b a) Source #

after :: ComparativePredicateOf (PairedInterval b a) Source #

overlaps :: ComparativePredicateOf (PairedInterval b a) Source #

overlappedBy :: ComparativePredicateOf (PairedInterval b a) Source #

starts :: ComparativePredicateOf (PairedInterval b a) Source #

startedBy :: ComparativePredicateOf (PairedInterval b a) Source #

precedes :: ComparativePredicateOf (PairedInterval b a) Source #

precededBy :: ComparativePredicateOf (PairedInterval b a) Source #

finishes :: ComparativePredicateOf (PairedInterval b a) Source #

finishedBy :: ComparativePredicateOf (PairedInterval b a) Source #

during :: ComparativePredicateOf (PairedInterval b a) Source #

contains :: ComparativePredicateOf (PairedInterval b a) Source #

unionPredicates :: [ComparativePredicateOf (PairedInterval b a)] -> ComparativePredicateOf (PairedInterval b a) Source #

(<|>) :: ComparativePredicateOf (PairedInterval b a) -> ComparativePredicateOf (PairedInterval b a) -> ComparativePredicateOf (PairedInterval b a) Source #

disjointRelations :: Set (IntervalRelation (PairedInterval b a)) Source #

withinRelations :: Set (IntervalRelation (PairedInterval b a)) Source #

disjoint :: ComparativePredicateOf (PairedInterval b a) Source #

notDisjoint :: ComparativePredicateOf (PairedInterval b a) Source #

concur :: ComparativePredicateOf (PairedInterval b a) Source #

within :: ComparativePredicateOf (PairedInterval b a) Source #

enclose :: ComparativePredicateOf (PairedInterval b a) Source #

enclosedBy :: ComparativePredicateOf (PairedInterval b a) Source #

class IntervalAlgebraic i a => IntervalCombinable i a where Source #

The IntervalCombinable typeclass provides methods for (possibly) combining two i as to form an Interval.

Minimal complete definition

(><), (<+>)

Methods

(.+.) :: i a -> i a -> Maybe (i a) Source #

Maybe form a new i a by the union of two i as that meets.

(><) :: i a -> i a -> Maybe (i a) Source #

If x is before y, then form a new Just Interval a from the interval in the "gap" between x and y from the end of x to the begin of y. Otherwise, Nothing.

(<+>) :: (Semigroup (f (i a)), Applicative f) => i a -> i a -> f (i a) Source #

If x is before y, return f x appended to f y. Otherwise, return extenterval of x and y (wrapped in f). This is useful for (left) folding over an *ordered* container of Intervals and combining intervals when x is *not* before y.

Instances

Instances details
(Ord a, Show a) => IntervalCombinable Interval a Source # 
Instance details

Defined in IntervalAlgebra

(Ord a, Show a, Eq b, Monoid b) => IntervalCombinable (PairedInterval b) a Source # 
Instance details

Defined in IntervalAlgebra.PairedInterval

class (Show a, Ord a, Num b, Ord b) => IntervalSizeable a b | a -> b where Source #

The IntervalSizeable typeclass provides functions to determine the size of an Intervallic type and to resize an 'Interval a'.

Minimal complete definition

add, diff

Methods

moment :: b Source #

The smallest duration for an 'Interval a'.

moment' :: Intervallic i a => i a -> b Source #

Gives back a moment based on the input's type.

duration :: Intervallic i a => i a -> b Source #

Determine the duration of an 'i a'.

add :: b -> a -> a Source #

Shifts an a. Most often, the b will be the same type as a. But for example, if a is Day then b could be Int.

diff :: a -> a -> b Source #

Takes the difference between two a to return a b.

Types

data Interval a Source #

An Interval a is a pair of as \( (x, y) \text{ where } x < y\). The parseInterval function that returns Left error if \(y < x\) and Right Interval otherwise.

Instances

Instances details
Functor Interval Source # 
Instance details

Defined in IntervalAlgebra

Methods

fmap :: (a -> b) -> Interval a -> Interval b #

(<$) :: a -> Interval b -> Interval a #

(Ord a, Show a) => IntervalCombinable Interval a Source # 
Instance details

Defined in IntervalAlgebra

(Eq a, Ord a, Show a) => IntervalAlgebraic Interval a Source # 
Instance details

Defined in IntervalAlgebra

Methods

relate :: Interval a -> Interval a -> IntervalRelation (Interval a) Source #

predicate' :: IntervalRelation (Interval a) -> ComparativePredicateOf (Interval a) Source #

predicates :: Set (IntervalRelation (Interval a)) -> [ComparativePredicateOf (Interval a)] Source #

predicate :: Set (IntervalRelation (Interval a)) -> ComparativePredicateOf (Interval a) Source #

toSet :: [IntervalRelation (Interval a)] -> Set (IntervalRelation (Interval a)) Source #

compose :: IntervalRelation (Interval a) -> IntervalRelation (Interval a) -> Set (IntervalRelation (Interval a)) Source #

complement :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

intersection :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

union :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

converse :: Set (IntervalRelation (Interval a)) -> Set (IntervalRelation (Interval a)) Source #

equals :: ComparativePredicateOf (Interval a) Source #

meets :: ComparativePredicateOf (Interval a) Source #

metBy :: ComparativePredicateOf (Interval a) Source #

before :: ComparativePredicateOf (Interval a) Source #

after :: ComparativePredicateOf (Interval a) Source #

overlaps :: ComparativePredicateOf (Interval a) Source #

overlappedBy :: ComparativePredicateOf (Interval a) Source #

starts :: ComparativePredicateOf (Interval a) Source #

startedBy :: ComparativePredicateOf (Interval a) Source #

precedes :: ComparativePredicateOf (Interval a) Source #

precededBy :: ComparativePredicateOf (Interval a) Source #

finishes :: ComparativePredicateOf (Interval a) Source #

finishedBy :: ComparativePredicateOf (Interval a) Source #

during :: ComparativePredicateOf (Interval a) Source #

contains :: ComparativePredicateOf (Interval a) Source #

unionPredicates :: [ComparativePredicateOf (Interval a)] -> ComparativePredicateOf (Interval a) Source #

(<|>) :: ComparativePredicateOf (Interval a) -> ComparativePredicateOf (Interval a) -> ComparativePredicateOf (Interval a) Source #

disjointRelations :: Set (IntervalRelation (Interval a)) Source #

withinRelations :: Set (IntervalRelation (Interval a)) Source #

disjoint :: ComparativePredicateOf (Interval a) Source #

notDisjoint :: ComparativePredicateOf (Interval a) Source #

concur :: ComparativePredicateOf (Interval a) Source #

within :: ComparativePredicateOf (Interval a) Source #

enclose :: ComparativePredicateOf (Interval a) Source #

enclosedBy :: ComparativePredicateOf (Interval a) Source #

(Ord a, Show a) => Intervallic Interval a Source # 
Instance details

Defined in IntervalAlgebra

Eq a => Eq (Interval a) Source # 
Instance details

Defined in IntervalAlgebra

Methods

(==) :: Interval a -> Interval a -> Bool #

(/=) :: Interval a -> Interval a -> Bool #

(Eq (Interval a), Intervallic Interval a) => Ord (Interval a) Source #

Imposes a total ordering on Interval a based on first ordering the begins then the ends.

Instance details

Defined in IntervalAlgebra

Methods

compare :: Interval a -> Interval a -> Ordering #

(<) :: Interval a -> Interval a -> Bool #

(<=) :: Interval a -> Interval a -> Bool #

(>) :: Interval a -> Interval a -> Bool #

(>=) :: Interval a -> Interval a -> Bool #

max :: Interval a -> Interval a -> Interval a #

min :: Interval a -> Interval a -> Interval a #

Intervallic Interval a => Show (Interval a) Source # 
Instance details

Defined in IntervalAlgebra

Methods

showsPrec :: Int -> Interval a -> ShowS #

show :: Interval a -> String #

showList :: [Interval a] -> ShowS #

Arbitrary (Interval Int) Source # 
Instance details

Defined in IntervalAlgebra.Arbitrary

Arbitrary (Interval Day) Source # 
Instance details

Defined in IntervalAlgebra.Arbitrary

parseInterval :: (Show a, Ord a) => a -> a -> Either String (Interval a) Source #

Safely parse a pair of as to create an Interval a.

data IntervalRelation a Source #

The IntervalRelation type enumerates the thirteen possible ways that two Interval a objects can relate according to the interval algebra.

Meets, Metby

x `meets` y
y `metBy` x
x: |-----|
y:       |-----| 

Before, After

x `before` y
y `after` x
x: |-----|  
y:          |-----|

Overlaps, OverlappedBy

x `overlaps` y
y `overlappedBy` x
x: |-----|
y:     |-----|

Starts, StartedBy

x `starts` y
y `startedBy` x
x: |---| 
y: |-----|

Finishes, FinishedBy

x `finishes` y
y `finishedBy` x
x:   |---| 
y: |-----|

During, Contains

x `during` y
y `contains` x
x:   |-| 
y: |-----|

Equal

x `equal` y
y `equal` x
x: |-----| 
y: |-----|

Instances

Instances details
Bounded (IntervalRelation a) Source # 
Instance details

Defined in IntervalAlgebra

Enum (IntervalRelation a) Source # 
Instance details

Defined in IntervalAlgebra

Eq (IntervalRelation a) Source # 
Instance details

Defined in IntervalAlgebra

Ord (IntervalRelation a) Source # 
Instance details

Defined in IntervalAlgebra

Read (IntervalRelation a) Source # 
Instance details

Defined in IntervalAlgebra

Show (IntervalRelation a) Source # 
Instance details

Defined in IntervalAlgebra

type ComparativePredicateOf a = a -> a -> Bool Source #

Defines a predicate of two objects of type a.

Functions for creating new intervals from existing

expand :: (IntervalSizeable a b, Intervallic i a) => b -> b -> i a -> i a Source #

Resize an 'i a' to by expanding to "left" by l and to the "right" by r. In the case that l or r are less than a moment the respective endpoints are unchanged.

expandl :: (IntervalSizeable a b, Intervallic i a) => b -> i a -> i a Source #

Expands an 'i a' to left by i.

expandr :: (IntervalSizeable a b, Intervallic i a) => b -> i a -> i a Source #

Expands an 'i a' to right by i.

beginerval :: IntervalSizeable a b => b -> a -> Interval a Source #

Safely creates an 'Interval a' using x as the begin and adding max moment dur to x as the end.

enderval :: IntervalSizeable a b => b -> a -> Interval a Source #

Safely creates an 'Interval a' using x as the end and adding negate max moment dur to x as the begin.

extenterval :: IntervalAlgebraic i a => i a -> i a -> Interval a Source #

Creates a new Interval spanning the extent x and y.