net.sf.cpsolver.ifs.extension
Class MacPropagation<V extends Variable<V,T>,T extends Value<V,T>>

java.lang.Object
  extended by net.sf.cpsolver.ifs.extension.Extension<V,T>
      extended by net.sf.cpsolver.ifs.extension.MacPropagation<V,T>
All Implemented Interfaces:
ModelListener<V,T>
Direct Known Subclasses:
DbtPropagation

public class MacPropagation<V extends Variable<V,T>,T extends Value<V,T>>
extends Extension<V,T>

MAC propagation.

During the arc consistency maintenance, when a value is deleted from a variable�s domain, the reason (forming an explanation) can be computed and attached to the deleted value. Once a variable (say Vx with the assigned value vx) is unassigned during the search, all deleted values which contain a pair Vx = vx in their explanations need to be recomputed. Such value can be either still inconsistent with the current (partial) solution (a different explanation is attached to it in this case) or it can be returned back to its variable's domain. Arc consistency is maintained after each iteration step, i.e., the selected assignment is propagated into the not yet assigned variables. When a value vx is assigned to a variable Vx, an explanation Vx != vx' ← Vx = vx is attached to all values vx' of the variable Vx, different from vx.

In the case of forward checking (only constraints going from assigned variables to unassigned variables are revised), computing explanations is rather easy. A value vx is deleted from the domain of the variable Vx only if there is a constraint which prohibits the assignment Vx=vx because of the existing assignments (e.g., Vy = vy, � Vz = vz). An explanation for the deletion of this value vx is then Vx != vx ← (Vy = vy & ... Vz = vz), where Vy = vy & ... Vz = vz are assignments contained in the prohibiting constraint. In case of arc consistency, a value vx is deleted from the domain of the variable Vx if there is a constraint which does not permit the assignment Vx = vx with other possible assignments of the other variables in the constraint. This means that there is no support value (or combination of values) for the value vx of the variable Vx in the constraint. An explanation is then a union of explanations of all possible support values for the assignment Vx = vx of this constraint which were deleted. The reason is that if one of these support values is returned to its variable's domain, this value vx may be returned as well (i.e., the reason for its deletion has vanished, a new reason needs to be computed).

As for the implementation, we only need to enforce arc consistency of the initial solution and to extend unassign and assign methods. Procedure afterAssigned(long, Value) enforces arc consistency of the solution with the selected assignment variable = value and the procedure afterUnassigned(long, Value) "undoes" the assignment variable = value. It means that explanations of all values which were deleted and which contain assignment variable = value in their explanations need to be recomputed. This can be done via returning all these values into their variables� domains followed by arc consistency maintenance over their variables.

Parameters:

Parameter Type Comment
MacPropagation.JustForwardCheck Boolean If true, only forward checking instead of full arc consistency is maintained during the search.

Version:
IFS 1.2 (Iterative Forward Search)
Copyright (C) 2006 - 2010 Tomáš Müller
muller@unitime.org
http://muller.unitime.org

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses/.

Field Summary
protected  List<Constraint<V,T>> iConstraints
          List of constraints on which arc-consistency is to be maintained
protected  long iIteration
          Current iteration
 
Constructor Summary
MacPropagation(Solver<V,T> solver, DataProperties properties)
          Constructor
 
Method Summary
 void addConstraint(Constraint<V,T> constraint)
          Adds a constraint on which arc-consistency is to be maintained
 void afterAssigned(long iteration, T value)
          After a value is assigned: explanations of other values of the value's variable are reset (to contain only the assigned value), propagation over the assigned variable takes place.
 void afterUnassigned(long iteration, T value)
          After a value is unassigned: explanations of all values of unassigned variable are recomputed (Value.conflicts()), propagation undo over the unassigned variable takes place.
 void beforeAssigned(long iteration, T value)
          Before a value is unassigned: until the value is inconsistent with the current solution, an assignment from its explanation is picked and unassigned.
 boolean contains(Constraint<V,T> constraint)
          Returns true, if arc-consistency is to be maintained on the given constraint
 Set<T> goodValues(V variable)
          good values of a variable (values not removed from variables domain)
 boolean init(Solver<V,T> solver)
          Initialization.
 boolean isGood(T value)
          is variable good
 Set<T> noGood(T value)
          variables explanation
protected  void propagate(Queue<V> queue)
          Propagation over the queue of variables.
protected  void propagate(V variable)
          Propagation over the given variable.
protected  boolean propagate(V aVariable, V anotherVariable)
           
protected  boolean propagate(V aVariable, V anotherVariable, List<T> adepts)
           
protected  void setGood(T value)
          sets value to be good
 void setNoGood(T value, Set<T> reason)
          sets value's explanation
 void undoPropagate(V variable)
          Propagation undo over the given variable.
 
Methods inherited from class net.sf.cpsolver.ifs.extension.Extension
beforeUnassigned, constraintAdded, constraintRemoved, getModel, getProperties, getSolver, isRegistered, register, unregister, useValueExtra, useVariableExtra, variableAdded, variableRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iConstraints

protected List<Constraint<V extends Variable<V,T>,T extends Value<V,T>>> iConstraints
List of constraints on which arc-consistency is to be maintained


iIteration

protected long iIteration
Current iteration

Constructor Detail

MacPropagation

public MacPropagation(Solver<V,T> solver,
                      DataProperties properties)
Constructor

Method Detail

addConstraint

public void addConstraint(Constraint<V,T> constraint)
Adds a constraint on which arc-consistency is to be maintained


contains

public boolean contains(Constraint<V,T> constraint)
Returns true, if arc-consistency is to be maintained on the given constraint


beforeAssigned

public void beforeAssigned(long iteration,
                           T value)
Before a value is unassigned: until the value is inconsistent with the current solution, an assignment from its explanation is picked and unassigned.

Specified by:
beforeAssigned in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>
Overrides:
beforeAssigned in class Extension<V extends Variable<V,T>,T extends Value<V,T>>
Parameters:
iteration - current iteration
value - value to be assigned

afterAssigned

public void afterAssigned(long iteration,
                          T value)
After a value is assigned: explanations of other values of the value's variable are reset (to contain only the assigned value), propagation over the assigned variable takes place.

Specified by:
afterAssigned in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>
Overrides:
afterAssigned in class Extension<V extends Variable<V,T>,T extends Value<V,T>>
Parameters:
iteration - current iteration
value - value to be assigned

afterUnassigned

public void afterUnassigned(long iteration,
                            T value)
After a value is unassigned: explanations of all values of unassigned variable are recomputed (Value.conflicts()), propagation undo over the unassigned variable takes place.

Specified by:
afterUnassigned in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>
Overrides:
afterUnassigned in class Extension<V extends Variable<V,T>,T extends Value<V,T>>
Parameters:
iteration - current iteration
value - value to be unassigned

init

public boolean init(Solver<V,T> solver)
Initialization. Enforce arc-consistency over the current (initial) solution. AC3 algorithm is used.

Specified by:
init in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>
Overrides:
init in class Extension<V extends Variable<V,T>,T extends Value<V,T>>
Parameters:
solver - IFS solver

propagate

protected void propagate(V variable)
Propagation over the given variable.


propagate

protected void propagate(Queue<V> queue)
Propagation over the queue of variables.


undoPropagate

public void undoPropagate(V variable)
Propagation undo over the given variable. All values having given variable in thair explanations needs to be recomputed. This is done in two phases: 1) values that contain this variable in explanation are returned back to domains (marked as good) 2) propagation over variables which contains a value that was marked as good takes place


propagate

protected boolean propagate(V aVariable,
                            V anotherVariable,
                            List<T> adepts)

propagate

protected boolean propagate(V aVariable,
                            V anotherVariable)

goodValues

public Set<T> goodValues(V variable)
good values of a variable (values not removed from variables domain)


noGood

public Set<T> noGood(T value)
variables explanation


isGood

public boolean isGood(T value)
is variable good


setGood

protected void setGood(T value)
sets value to be good


setNoGood

public void setNoGood(T value,
                      Set<T> reason)
sets value's explanation