1
#include "constraint.h"
8
* \class ConstraintHelper
10
* \brief ConstraintHelper is the base for all constraint helpers.
12
* Constraint-helpers do the actual validation against the rules of a constraint
13
* and optionaly helps to resolve the constraint
17
* \fn void apply(IHelperTarget* target) const
18
* Applies the helper to the \a target (which is a solver in most cases).
20
* This includes validation and changing the targets problem in a way the limits
21
* the possible configurations towards the solution(s) of the problem.
22
* Needs to be implemented by derived classes.
26
* \fn Constraint* constraint() const
27
* Returns the constraint the helper belongs to.
29
* Needs to be implemented by derived classes.
33
* Constructs a new constraint-helper.
35
ConstraintHelper::ConstraintHelper()
41
* Registers the helper at \a ruleset.
43
void ConstraintHelper::setup(Ruleset* ruleset) {
44
ruleset->addHelper(this);
45
m_entry.setup(ruleset);
49
* Called when an \a item associated with the helper changed.
51
* Reactivates the helper in \a problem if it is really affected
52
* by the change in item.
54
void ConstraintHelper::itemChanged(Problem* problem, const Item* item) const {
55
if(!constraint()->reallyAffectsItem(item, problem)) return;
57
m_entry.activate(problem);
61
* Helps to resolve the constraint.
63
* This method calls apply() and afterwards set this helper to idle
65
bool ConstraintHelper::resolve(Problem *problem) const {
66
bool noerror = apply(problem);
67
m_entry.resolve(problem);
72
* Returns whether the constraint waits for solving.
74
bool ConstraintHelper::isPending(Problem* problem) const {
75
return m_entry.isPending(problem);
81
* \brief Constraint is the base for all constraints in a graph.
83
* A constraint is the specific application of a rule. For example
84
* in sudoku a constraint may limit all cells in a specific row
85
* to contain each value only once.
89
* \fn QVector<int> Constraint::affectedNodes() const
90
* Returns a list of all nodes that may be affected by the constraint.
94
* Constructs a new constraint.
96
Constraint::Constraint() {
100
* Returns true if the constraint really affects \a item.
101
* Reimplement this if the nodes affected by constraint might change
102
* depending on the state of \a puzzle.
104
bool Constraint::reallyAffectsItem(const Item *item, Problem *puzzle) const {
111
* Reimplement this to initilazies the constraint and registrater it
114
void Constraint::init(Ruleset *rules) {
118
#include "constraint.moc"