Class: MatchingChallenge

MatchingChallenge(…constraints)

Represents a matching challenge. A matching challenge is defined by two sets of constraints. The first set is the challenge to be solved, the second set contains the solutions found when solving the challenge. Both sets may be empty upon construction of a matching challenge, and the solution set may remain empty if the challenge has no solutions.

Constructor

new MatchingChallenge(…constraints)

Creates a new instance of MatchingChallenge by taking an arbitrary number of arrays (including zero), creating constraints from them, and then creating a constraints list out of them called challenge.
Parameters:
Name Type Attributes Description
constraints Array <repeatable>
an arbitrary number of arguments each of which is a length-2 array containing a pattern and an expression, i.e. containing two expressions.
Source:

Classes

MatchingChallenge

Methods

addConstraint(pattern, expr)

Takes two expressions, creates a Constraint object from them, and adds it to `this.challengeList`. If any solutions have been found already, they are applied to the constraint before it is added.
Parameters:
Name Type Description
pattern OM An expression
expr OM An expression
Source:

addConstraints(…constraints)

Adds an arbitrary number of constraints to the challenge, each supplies by a length-2 array containing a pattern and an expression.
Parameters:
Name Type Attributes Description
constraints Array <repeatable>
Source:

addSolutionAndCheckBindingConstraints(constraint)

Adds a solution, and checks that it passes `satisfiesBindingConstraints`. If it does not, empties the solutions list and sets variables in order to end the search.
Parameters:
Name Type Description
constraint Constraint either a Constraint, or a (meta)variable
Source:

clone()

Source:
Returns:
a deep copy of the matching challenge, including solutions

getOneSolution()

Computes just one solution to this matching problem and returns it, or returns undefined if there are none. Uses the cache if possible.
Source:
Returns:
The first solution or `undefined`. State when this is done: `this.solvable` will be true or false but `this.solutions` will be undefined, to indicate we have not computed all of them.

getSolutions()

If the matching challenge is unsolved, this finds all solutions, then returns them. It will guarantee that `this.solvable` is true/false and that `this.solutions` is fully populated with all solutions.
Source:
Returns:
`this.solutions`

isSolvable()

Source:
Returns:
`this.solvable` if it is defined. If it is undefined, then `getSolutions` has not been called. This function will call `getSolutions` in that case.

numSolutions()

Source:
Returns:
`this.solutions.length` by calling `getSolutions`, hence it solves if `getSolutions` has not been called.

satisfiesBindingConstraints()

Tests whether the first currently-in-progress solution satisfies all the challenge's already-computed binding constraints.
Source:

solutionSatisfiesBindingConstraints()

Tests whether a solution satisfies all the challenge's already-computed binding constraints.
Source: