logicUSLIB / logicus-pl / LogicUS.PL.CSP

This module is designed for working with Constraint Satisfaction Problems, defining it by Big Formulas using Big Operators. For this purpose this module provides a parser, for reading a big formula directly from a String, a transformer from BigFormulas to standard FormulaPL, a SAT Solver (inspired in Chronological Backtracking + MRV) and the functions for representing the big formulas in string (raw) and in Latex format.

Defining BigFPL


type BigFPL
    = Atom String (List LogicUS.PL.A_Expressions.A_Expr)
    | Neg BigFPL
    | Conj BigFPL BigFPL
    | Disj BigFPL BigFPL
    | Impl BigFPL BigFPL
    | Equi BigFPL BigFPL
    | BAnd (List Param) LogicUS.PL.B_Expressions.B_Expr BigFPL
    | BOr (List Param) LogicUS.PL.B_Expressions.B_Expr BigFPL
    | Insat
    | Taut

It defines the structure of a BigFPL Formula

bfplReadFromString : String -> ( Maybe BigFPL, String )

It allows defining BFPL from text strings, through a parser. To do this, a series of rules are established:

As a final example, the restriction of the absence of two queens on the same secondary diagonal, in the 8 Queens problem, could be expressed as:

!& [i (0:7), j (0:7)] {T} (P_{i, j} ->!& [k (-7:7)] {[k!= 0] AND [i + k> = 0] AND [j-k> = 0] AND [i + k <= 7] AND [j-k <= 7]} (¬P_{i + k, j-k}))

bfplReadExtraction : ( Maybe BigFPL, String ) -> BigFPL

It allows to extract the formula readed. If there is a parsing error, then it returns Insat formula

BigFPL to FormulaPL

bfplToFPL : BigFPL -> LogicUS.PL.SyntaxSemantics.FormulaPL

It converts a BigFPL to a FPL

sbfplToSPL : List BigFPL -> LogicUS.PL.SyntaxSemantics.SetPL

It converts a BigFPL to a FPL

CSP Solver

sbfplsolver : List BigFPL -> ( Basics.Bool, List LogicUS.PL.SyntaxSemantics.PSymb )

It allows resolve the satisfiability of a set of BigFormulas using Backtracking + MRV

solver : List LogicUS.PL.Clauses.ClausePL -> ( Basics.Bool, List LogicUS.PL.SyntaxSemantics.PSymb )

It allows resolve the satisfiability of a set of clauses using Backtracking + MRV

Representation

bfplToString : BigFPL -> String

It generates the String representation of a BigFPL formula.

bfplToMathString : BigFPL -> String

It generates the String representation of a BigFPL formula in Latex Format

bfplToMathString2 : BigFPL -> ( String, String )

It generates the String representation of a BigFPL formula in Latex Format, separating the representation of the formula and the representations of the conditions.

solutionModelToString : LogicUS.PL.SyntaxSemantics.Interpretation -> String

It gives the true variables of the model in a string

solutionModelToMathString : LogicUS.PL.SyntaxSemantics.Interpretation -> String

It gives the true variables of the model in a string in Latex format