Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Distribution = Distribution {}
- data Values = Values [Integer]
- data Variable = Variable {
- possible :: [Int]
- valueIndex :: Int
- distr :: Distribution
- data ConstraintEl = ConstraintEl {
- variableIndices :: [Int]
- constraint :: [Int] -> Bool
- data Solved = Solved {
- variables :: [Variable]
- iterationCount :: Int
- width :: Num b => Distribution -> b
- b :: Double
- oneIfEqual :: (Num a1, Eq a) => a -> a -> a1
- replicateDouble :: Int -> Double -> [Double]
- initDistribution :: Int -> Distribution
- failureCurrProb :: t -> Double -> Double
- failureOtherProb :: Double -> Double -> Double
- failureProb :: Eq a => Double -> a -> Double -> a -> Double
- updateProb :: (Num a, Eq a, Enum a) => Distribution -> a -> Bool -> Distribution
- updateVariableProb :: Variable -> Bool -> Variable
- cummDistributionIter :: Distribution -> Int -> Double -> [Double]
- cummDistribution :: Distribution -> Distribution
- getValueIndex :: Distribution -> Double -> Int
- randomNum :: IO Double
- randomizeVariable :: Variable -> IO Variable
- evalConstraint :: ([Int] -> Bool) -> [Int] -> Bool
- evalConstraints :: [[Int] -> Bool] -> [Int] -> Bool
- applyAt :: (Num b1, Eq b1, Enum b1) => (b -> b) -> b1 -> [b] -> [b]
- getConstraintsFor :: Int -> [ConstraintEl] -> [[Int] -> Bool]
- justConstraints :: [ConstraintEl] -> [[Int] -> Bool]
- getValues :: [Variable] -> [Int]
- randomizeSingle :: Int -> [Variable] -> [IO Variable]
- randomize :: [Variable] -> [IO Variable]
- printVariables :: Show a => [a] -> [IO ()]
- update :: Int -> [Variable] -> [ConstraintEl] -> IO [Variable]
- updateEach' :: [Variable] -> [ConstraintEl] -> [Int] -> IO [Variable]
- updateEach :: [Variable] -> [ConstraintEl] -> IO [Variable]
- updateEachTimes :: [Variable] -> [ConstraintEl] -> Int -> IO [Variable]
- checkDistrSolved :: Distribution -> Bool
- checkSolved :: [Variable] -> Bool
- solve :: [Variable] -> [ConstraintEl] -> IO Solved
- updateMapF :: [Variable] -> [ConstraintEl] -> Int -> IO Variable
- updateEachThreaded :: Int -> [Variable] -> [ConstraintEl] -> IO [Variable]
- updateEachTimesThreaded :: Int -> [Variable] -> [ConstraintEl] -> Int -> IO [Variable]
- solveThreaded :: Int -> [Variable] -> [ConstraintEl] -> IO Solved
Documentation
Each variable has a finite set of possible values, a value it holds at a given point and a probability distribution over the set of possible values.
Variable | |
|
data ConstraintEl Source
Each constraint function ([Int] -> Bool) is associated with a certain set of
variables. ConstraintEl
represents this relationship for a constraint
function.
ConstraintEl | |
|
width :: Num b => Distribution -> b Source
Returns the number of finite values that a Distribution
is over.
Constant, as defined in the research paper "Decentralized Constraint Satisfaction" Duffy, et al.
oneIfEqual :: (Num a1, Eq a) => a -> a -> a1 Source
Internally called function.
replicateDouble :: Int -> Double -> [Double] Source
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].
failureCurrProb :: t -> Double -> Double Source
Adjust probability for the value which has just failed a constraint.
failureOtherProb :: Double -> Double -> Double Source
Adjust probability for values other than the one that just failed a constraint.
failureProb :: Eq a => Double -> a -> Double -> a -> Double Source
Adjust probability of taking on a value for a certain Variable
given that
a constraint was just failed.
updateProb :: (Num a, Eq a, Enum a) => Distribution -> a -> Bool -> Distribution Source
Given a distribution, update it based on the value of success. If successful, then set the probability of the current value to 1.0 and the probability for every other value to 0.0. Otherwise, update it with failureProb.
updateVariableProb :: Variable -> Bool -> Variable Source
Same as updateProb
, but rather than returning a Distribution
, this function
returns a Variable
.
cummDistributionIter :: Distribution -> Int -> Double -> [Double] Source
Internal iteration function used by cummDistribution
.
cummDistribution :: Distribution -> Distribution Source
Creates a cummulative Distribution
out of a given Distribution
.
getValueIndex :: Distribution -> Double -> Int Source
Given a cummulative Distribution
, this function returns the where a random
value should be "placed" within the Distribution
.
evalConstraint :: ([Int] -> Bool) -> [Int] -> Bool Source
Evaluate one constraint
with a list of values
.
evalConstraints :: [[Int] -> Bool] -> [Int] -> Bool Source
Evaluate the set constraint functions constraints
with a list of values
.
applyAt :: (Num b1, Eq b1, Enum b1) => (b -> b) -> b1 -> [b] -> [b] Source
Apply a function at only one index of a list. Internal function.
getConstraintsFor :: Int -> [ConstraintEl] -> [[Int] -> Bool] Source
justConstraints :: [ConstraintEl] -> [[Int] -> Bool] Source
Get the constraint functions out of a list of ConstraintEl
s.
printVariables :: Show a => [a] -> [IO ()] Source
Print variables.
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] -> [Int] -> IO [Variable] Source
Update each variable in the indices list once. Internal function used by updateEach.
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.
checkDistrSolved :: Distribution -> Bool Source
Checks if every probability in the distribution is either 0 or 1. If it is, then, all constraints have been satisfied.
checkSolved :: [Variable] -> Bool Source
Check if the constraints have been solved by looking at the distributions
of each Variable
.
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. Note that the implementation is not parallelized./
updateMapF :: [Variable] -> [ConstraintEl] -> Int -> IO Variable Source
updateEachThreaded :: Int -> [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.
updateEachTimesThreaded :: Int -> [Variable] -> [ConstraintEl] -> Int -> IO [Variable] Source
solveThreaded :: Int -> [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.