Safe Haskell | None |
---|---|
Language | Haskell98 |
Data.DCFL
- data Distribution
- data Values
- data Variable
- data ConstraintEl
- data Solved
- initDistribution :: Int -> Distribution
- cummDistribution :: Distribution -> Distribution
- checkSolved :: [Variable] -> Bool
- randomizeSingle :: Int -> [Variable] -> [IO Variable]
- randomize :: [Variable] -> [IO Variable]
- printVariables :: [Variable] -> [IO ()]
- getConstraintsFor :: Int -> [ConstraintEl] -> [[Int] -> Bool]
- justConstraints :: [ConstraintEl] -> [[Int] -> Bool]
- solve :: [Variable] -> [ConstraintEl] -> IO Solved
- update :: Int -> [Variable] -> [ConstraintEl] -> IO [Variable]
- updateEach :: [Variable] -> [ConstraintEl] -> IO [Variable]
- updateEachTimes :: [Variable] -> [ConstraintEl] -> Int -> IO [Variable]
- solveParallel :: [Variable] -> [ConstraintEl] -> IO Solved
- updateEachTimesParallel :: [Variable] -> [ConstraintEl] -> Int -> IO [Variable]
- updateEachParallel :: [Variable] -> [ConstraintEl] -> IO [Variable]
Documentation
Each Variable
has a finite set of possible values, a value it holds
and a probability distribution over the set of possible values.
data ConstraintEl Source
Each constraint function ([Int] -> Bool) is associated with a certain set of
variables. ConstraintEl
represents this relationship for a given constraint
function.
Instances
Distributions
initDistribution :: Int -> Distribution Source
Initialize a distribution with each possible value having the same probability.
For example, initDistribution 5 gives
Distribution
[0.2, 0.2, 0.2, 0.2, 0.2].
cummDistribution :: Distribution -> Distribution Source
Creates a cummulative Distribution
out of a given Distribution
.
checkSolved :: [Variable] -> Bool Source
Check if the constraints have been solved by looking at the distributions
of each Variable
.
Variables
printVariables :: [Variable] -> [IO ()] Source
Print variables.
Constraints
getConstraintsFor :: Int -> [ConstraintEl] -> [[Int] -> Bool] Source
justConstraints :: [ConstraintEl] -> [[Int] -> Bool] Source
Get the constraint functions out of a list of ConstraintEl
s.
Solving
Serial/Single Threaded
solve :: [Variable] -> [ConstraintEl] -> IO Solved Source
This is the moost important function within this library. Given a list of
Variable
and a list of ConstraintEl
, the library uses the Communcation Free Learning
Algorithm to return a Solved
value. See solveThreaded
for a parallelized implementation.
update :: Int -> [Variable] -> [ConstraintEl] -> IO [Variable] Source
Either randomize or let a variable stay, depending on what the constraint check tells us.
updateEach :: [Variable] -> [ConstraintEl] -> IO [Variable] Source
Update each variable in the variable set based on the constraint set value.
updateEachTimes :: [Variable] -> [ConstraintEl] -> Int -> IO [Variable] Source
Update the variable set n
number of times.
Parallelized
solveParallel :: [Variable] -> [ConstraintEl] -> IO Solved Source
Solve the constraint set in parallel using Haskell threads. In order for the solution to be parallelized, the program using DCFL must be compiled with GHC's '-threaded' option.
updateEachTimesParallel :: [Variable] -> [ConstraintEl] -> Int -> IO [Variable] Source
updateEachParallel :: [Variable] -> [ConstraintEl] -> IO [Variable] Source
Updates each variable in the variable set a number of times and does each variable's update in a separate thread.