haskelzinc-0.3.1.1: CP in Haskell through MiniZinc

LicenseBSD3
MaintainerKlara Marntirosian <klara.mar@cs.kuleuven.be>
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Interfaces.FZSolutionParser

Contents

Description

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.

Synopsis

Documentation

data MValue Source #

Representation of returned values.

Instances

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

valueM :: Parser MValue Source #

Parses a MiniZinc value. Tries floatM, intM, boolM, setM, arrayM and stringM in this order.

intM :: Parser MValue Source #

Parses a MiniZinc integer value.

boolM :: Parser MValue Source #

Parses a MiniZinc boolean value.

floatM :: Parser MValue Source #

Parses a MiniZinc float value.

stringM :: Parser MValue Source #

Parses a MiniZinc string value.

setM :: Parser MValue -> Parser MValue Source #

Parses a MiniZinc set value.

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.

comment :: Parser String Source #

Parses a comment in the solutions and returns the content.

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

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.

nameValuePair Source #

Arguments

:: Parser String

Value-name separator

-> Parser (String, MValue) 

Used to parse a MiniZinc variable name-value pair in a solution. nameValuePair s parses succesfully if sequential parsing of varName, s and valueM is succesfull. Returns the MiniZinc name-value pair in a Haskell pair and forgets the result of parser s.

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.