Main Page | Class Hierarchy | Class List | File List | Class Members

Constraint Class Reference

The constraint used by the compact representation. More...

#include <Queens.h>

Inheritance diagram for Constraint:

AllDiff List of all members.

Public Types

typedef FastVector< Variable
* >::const_iterator 
variable_iterator

Public Member Functions

 Constraint (int queens=0)
virtual bool check () const
 Constraint (Problem &problem)
 Constraint (Problem &problem, const Constraint &constraint)
double weight () const
double weight (const Variable &variable, const Value &value) const
double minWeight () const
double maxWeight () const
void buildWrapper (const wstring &model, size_t nPairs, double probability, bool flawed)
void buildEmpty ()
 Prepare an empty constraint (i.e. no allowed values).
void addPair (int value0, int value1)
 Add a pair of allowed values to a constraint.
virtual bool check () const
bool isFlawless () const
ulonglong allowedTuples () const
 Return the number of tuples allowed by the constraint.
virtual wostream & print (wostream &wos) const
 Constraint ()
virtual ~Constraint ()
 Destructor.
variable_iterator add (Variable &variable)
 Add `variable' to the list of variables in this constraint.
void remove (Variable &variable, bool recursive=false)
 Remove `variable' from the list of variables in this constraint.
void setId (id_t id)
 Set the constraint's id.
id_t id () const
 Return the constraint's id.
virtual wstring name () const
virtual wstring color () const
virtual wstring textColor () const
bool isActive () const
void activate ()
 Activate the constraint.
void deactivate ()
 Deactivate the constraint.
bool isComplete () const
bool involves (const Variable &variable) const
Variablepair (const Variable &variable) const
size_t variables () const
size_t order () const
 Same as `variables()'. Return the order of the constraint.
const variable_iterator beginVariables () const
 Return an iterator to the first variable in this constraint.
const variable_iterator endVariables () const
 Return an interator past the last variable in this constraint.
const variable_iterator secondVariable () const
VariablefindVariable (bool instantiated=false) const
bool isSatisfied () const
virtual bool check () const =0
virtual bool propagate (Variable &)
bool tryOut (Variable &variable0, Value &value0, Variable &variable1, Value &value1) const
virtual ulonglong validTuples () const
ulonglong maxTuples () const
long double tightness () const
bool isLoose () const
virtual ulonglong invalidTuples () const
ulonglong checks () const
 Return the number of constraint checks for this constraint.
ulonglong failures () const
 Return the number of constraint check failures for this constraint.
virtual void init ()
virtual void done ()
 Cleanup. Make sure you call this from derived classes.
size_t instantiatedVariables () const
size_t uninstantiatedVariables () const
void inc ()
 Increment the number of instantiated variables.
void dec ()
 Decrement the number of instantiated variables.
void incrementWeight ()
 Increment the constraint's weight.
ulonglong weight () const
 Return the constraint's weight.
virtual wostream & print (wostream &wos) const

Friends

CSP_API wostream & operator<< (wostream &wos, const Constraint &constraint)
 The constraint's output operator.

Detailed Description

The constraint used by the compact representation.

Abstract super class for defining CSP constraints.


Constructor & Destructor Documentation

Constraint::Constraint  ) 
 

Create a new constraint object.


Member Function Documentation

virtual bool Constraint::check  )  const [virtual]
 

Return `true' if the constraint is satisfied by the current assignment.

virtual wstring Constraint::color  )  const [inline, virtual]
 

Return the constraint's drawing color, if the derived class decided to assign it one. The default color is "black".

Returns:
the constraint's color.

Variable & Constraint::findVariable bool  instantiated = false  )  const
 

Return the first instantiated/uninstantiated variable in the constraint. At least one such variable should exist at the time of the call.

Parameters:
instantiated `false' if looking for uninstantiated variables, `true' if looking for instantiated variables.
Returns:
the first matching variable.

virtual void Constraint::init  )  [inline, virtual]
 

This performs a few initializations that are required before starting a new search. Make sure you call this from derived classes.

size_t Constraint::instantiatedVariables  )  const [inline]
 

Return the number of instantiated variables involved in this constraint.

virtual ulonglong Constraint::invalidTuples  )  const [inline, virtual]
 

Return the number of tuples disallowed by the constraint.

bool Constraint::involves const Variable variable  )  const [inline]
 

Return `true' if this constraint involves the given variable, `false' otherwise.

Parameters:
variable the variable to be found in the list of variables involved in this constraint.
Returns:
return `true' if the given variable is found, `false' otherwise.

bool Constraint::isActive  )  const [inline]
 

Return the constraint's active status.

Returns:
`true' if the constraint is active, `false' otherwise.

bool Constraint::isComplete  )  const [inline]
 

A constraint is considered `complete' if all the variables involved have been instantiated.

Returns:
`true' if the constraint is `complete'.

bool Constraint::isFlawless  )  const
 

Return `true' if every value in the variables involved in this constraint has a support in the other variable.

bool Constraint::isLoose  )  const
 

Return `true' if the constraint's tightness is 0 (i.e. all tuples are valid), `false' otherwise.

bool Constraint::isSatisfied  )  const [inline]
 

Check whether or not the constraint is satisfied by the current assignments of its variables and update the constraint check counters. The implementation should work if the variables involved have had their domain reduced to a single value, regardless of wether they have been instantiated or not. Calling this method is the proper way of verifying that a constraint is satisfied.

Returns:
`true' if the constraint is satisfied, `false' otherwise.

ulonglong Constraint::maxTuples  )  const
 

Return the maximum number of tuples allowed by the constraint, which is the product of the domain sizes of all the variables involved in the constraint.

wstring Constraint::name  )  const [virtual]
 

Return the constraint's name, if the derived class decided to assign it one. The default is to return the constraint's id as a string.

Returns:
the constraint's name.

Variable& Constraint::pair const Variable variable  )  const [inline]
 

Given one variable involved in this (assumed binary) constraint, this method will return the other variable (the pair).

Parameters:
variable one of the variables involved in the constraint.
Returns:
the other variable involved in the constraint.

virtual wostream& Constraint::print wostream &  wos  )  const [virtual]
 

Print the constraint at the given stream.

Parameters:
wos the output stream to print to.
Returns:
the given stream.

virtual bool Constraint::propagate Variable  )  [inline, virtual]
 

Propagate this constraint. If you decide to overwrite this function, you can prune domains of other variables, provided that you make correct use of [save|restore|postpone|add]Diffs. This should work regardles of the arity of the constraint.

Parameters:
modifiedVariable the variable that has been modified; obviously this should be involved in the current constraint.
Returns:
`true' if the propagation was successful, `false' otherwise.

Reimplemented in AllDiff.

const variable_iterator Constraint::secondVariable  )  const [inline]
 

This is for convenience only, since binary constraints are so common. Use this for binary constraints only!

Returns:
an iterator pointing to the second variable in this constraint.

virtual wstring Constraint::textColor  )  const [inline, virtual]
 

Return the constraint's text color, if the derived class decided to assign it one. The default color is "black".

Returns:
the constraint's text color.

long double Constraint::tightness  )  const [inline]
 

Return the constraint's tightness, i.e. 1-validTuples()/maxTuples().

bool Constraint::tryOut Variable variable0,
Value value0,
Variable variable1,
Value value1
const
 

Check if the constraint is satisfied by the assignment of `value0' to `variable0' and `value1' to `variable1'.

size_t Constraint::uninstantiatedVariables  )  const [inline]
 

Return the number of uninstantiated variables involved in this constraint.

ulonglong Constraint::validTuples  )  const [virtual]
 

Return the number of tuples allowed by the constraint.

size_t Constraint::variables  )  const [inline]
 

Return the number of variables involved in the constraint.

Returns:
the number of variables involved in the constraint.


The documentation for this class was generated from the following files:
Generated on Wed May 25 12:21:16 2005 for csp.kdevelop by  doxygen 1.3.9.1