Search code examples
constraintsconstraint-programmingeclipse-clp

Active vs Passive constraints in ECLiPSe CLP


What is the difference between active and passive constraints in the ECLiPSe CLP language? And how/when can I use one or the other?


Solution

  • The distinction refers to the way the constraints are used during execution. Active constraints (may) directly affect the variables present in them, whereas passive constraints will not. Consider a small, trivial example of both structures:

    % Active
    f(a,X) = f(Y,b)
    
    % Passive
    2*X < 3*Y+2
    

    In the first example, when either X or Y becomes instantiated, the 'constraint' can trigger and immediately evaluate (and if valid, unify) both sides = active behaviour.

    In the second example on the other hand, both sides are dependent on each other and thus it doesn't matter whether X or Y becomes instantiated first, the evaluation will have to be delayed until both sides' variables are instantiated = passive behaviour.

    (Note that I tried to answer without using any constraint/language-specific syntax, since the concept of active/passive constraints can generically be applied to all constraint logic based systems. Also note that some languages like ECLiPSe provide global constraints reasoning over finite integer domains and may actually make some behaviour active/passive to our needs. However, being outside the scope of this question, no further behaviour is considered to keep things simple.)

    Hope this helps!