License | BSD3 |
---|---|
Maintainer | Klara Marntirosian <klara.mar@cs.kuleuven.be> |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
This module defines a parser for the default format of the output of the two solvers
integrated in haskelzinc (G12/FD and choco3). It also provides modular parsers for
entities that constitute a solution, such as MiniZinc variable names and values,
solutions' separator in case of multiple solutions, etc. These modular parsers can be
used in building a parser for a solver's output, the format of which is specified by a
MiniZinc output
item differs from the default one.
- data MValue
- type Solution = [(String, MValue)]
- valueM :: Parser MValue
- intM :: Parser MValue
- boolM :: Parser MValue
- floatM :: Parser MValue
- stringM :: Parser MValue
- setM :: Parser MValue -> Parser MValue
- setRange :: Parser MValue
- arrayM :: Parser MValue -> Parser MValue
- varName :: Parser String
- simpleVarName :: Parser String
- quotedVarName :: Parser String
- comment :: Parser String
- comments :: Parser String
- defaultNameValuePair :: Parser (String, MValue)
- defaultUnsat :: Parser String
- defaultSolution :: Parser Solution
- trySolutionsDefault :: Parser [Solution]
- getAllSolutionsDefault :: String -> Either ParseError [Solution]
- getDefaultSolutionsFromFile :: FilePath -> Int -> IO (Either ParseError [Solution])
- getAllSolutions :: Parser [Solution] -> String -> Either ParseError [Solution]
- trySolutions :: Parser [Solution] -> Parser String -> Parser [Solution]
- nameValuePair :: Parser String -> Parser (String, MValue)
- allSolutions :: Parser Solution -> Parser [Solution]
- takeSolutionsWithParser :: (Int -> Parser [Solution]) -> Int -> String -> Either ParseError [Solution]
Documentation
Representation of returned values.
type Solution = [(String, MValue)] Source #
A Solution consists of a list of pairs. Each pair represents an assignment of a value to a decision variable of the constraint model.
Parsing values
setRange :: Parser MValue Source #
Parses a MiniZinc set value defined with the use of the MiniZinc range operator
(..
).
arrayM :: Parser MValue -> Parser MValue Source #
Parses MiniZinc 1-dimensional or multi-dimensional array values.
Solutions
varName :: Parser String Source #
Parses a MiniZinc variable name by trying simpleVarName
and quotedVarName
.
simpleVarName :: Parser String Source #
Parses a conventional MiniZinc variable identifier. That is, a string of the form
[A-Za-z][A-Za-z0-9_]*
.
quotedVarName :: Parser String Source #
Parses a quoted MiniZinc identifier.
comments :: Parser String Source #
Parses a sequence of commented lines in the solutions and returns their content.
Default parsers
defaultNameValuePair :: Parser (String, MValue) Source #
Parses a MiniZinc variable name-value pair in a solution with the default output format.
defaultUnsat :: Parser String Source #
Parses the default message for a model with no solutions: =====UNSATISFIABLE=====
,
surrounded by commented lines before and after.
defaultSolution :: Parser Solution Source #
Parses a single solution with the default output format from the set of returned solutions.
trySolutionsDefault :: Parser [Solution] Source #
tryDefaultSolutions n
tries to parse the solutions and, if it succeeds, returns
the first n
. Else, tries defaultUnsat
and returns an empty list.
getDefaultSolutionsFromFile :: FilePath -> Int -> IO (Either ParseError [Solution]) Source #
Returns either a parse error or a list of solutions of the constraint model, parsed from the file where they are printed. The length of the list is specified by the second argument of the function.
Custom
getAllSolutions :: Parser [Solution] -> String -> Either ParseError [Solution] Source #
trySolutions :: Parser [Solution] -> Parser String -> Parser [Solution] Source #
trySolutions f p n
applies f n
and returns the solutions. If that fails, tries
to parse an Unsatisfiable message by applying p
and returns an empty list. The
custom parser must be parametrized by an integer, for specifying the number of
solutions to be returned.
The following functions can be used when a MiniZinc output
item, which alters the
default output format of the solver, is present in the model.
takeSolutionsWithParser :: (Int -> Parser [Solution]) -> Int -> String -> Either ParseError [Solution] Source #
A custom version of getDefaultSolutions
. This function accepts a custom parser to
parse the solutions. The custom parser must be parametrized by an integer, for
specifying the number of solutions to be returned.