Index: /reasoner/consRescheduling.tex
===================================================================
--- /reasoner/consRescheduling.tex	(revision 162)
+++ /reasoner/consRescheduling.tex	(revision 163)
@@ -66,23 +66,42 @@
 For this purpose, Algorithm \ref{algRescheduleContainerValue} receives the changed variable $v$, its optional parent variable $v_p$ (if $v$ is nested into $p$), the old value $val_o$ and a flag that indicates whether existing constraints shall be cleared within this call. If $val_n$ is a constraint, the algorithm calls Algorithm \ref{algRescheduleConstraintValue} (lines \ref{algRescheduleContainerValueConsStart}-\ref{algRescheduleContainerValueConsEnd}). If $val_n$ is a compound, the algorithm calls itself recursively for all slots that have a value assigned (lines \ref{algRescheduleContainerValueCompStart}-\ref{algRescheduleContainerValueCompEnd}). Finally, if $val_n$ is a container, the algorithm iterates over the elements in the new and the old value (assuming that at least all elements in $val_n$ are considered, eventually $val_o$ is $\undef$ then) and calls itself recursively for each pair (lines \ref{algRescheduleContainerValueContStart}-\ref{algRescheduleContainerValueContEnd}). Existing constraints are cleared only for the first element pair ($first$).
 
+Algorithm \ref{algRescheduleConstraintValue} targets re-scheduling a constraint value. This involves replacing existing constraints for a given variable $v$ by a new constraint instantiated using variable substitution. In more details, Algorithm \ref{algRescheduleConstraintValue} receives the changed variable $v$, its optional parent variable $v_p$ and a flag whether existing constraints shall be cleared (if this function is called repeatedly on the same $v_p$, e.g., for all slots of a compound).
+
 \begin{algorithm}[H]
   \SetAlgoLined
   \KwIn{parent variable $v_p$, decision variable $v$, clear flag $clear$}
-  \KwData{scope assignments $\scopeAssignments$, relevant constraints $\relevantConstraintsPerDeclaration$ and $\relevantConstraintVariables$}
+  \KwData{constraint base $base$, other constraints $\otherConstraints$ and relevant constraints per declaration $\relevantConstraintsPerDeclaration$}
 
-      $obtainConstraints(v_p, clear, \undef)$ \MISSING{!}\;
-      $ex \assng getConstraintValueConstraintExpression(value(v))$ \MISSING{!}\;
-      \If{$ex \neq \undef$}{
-          $ex_p \assng createParentExpression(v)$\;
-          $c \assng createConstraintVariableConstraint(ex, ex_p, v_p)$\;
-          $setValue(v, c)$\;
-          $base \assng base \addSeq \otherConstraints$\;
-          \ForAll{$p\iterAssng allParents(v)$}{ % variablesMap.addAll(variable, otherConstraints);
+      $obtainConstraints(v_p, clear, \undef)$ \MISSING{!}\; \label{algRescheduleConstraintValueClear}
+      $e \assng getConstraintValueExpression(value(v))$\;
+      \If{$e \neq \undef$}{
+          $e_p \assng createParentExpression(v)$\;\label{algRescheduleConstraintValueCreateParent}
+          $c \assng createConstraintVariableConstraint(e, e_p, v_p)$\;\label{algRescheduleConstraintValueCreateConstraint}
+          $setValue(v, c)$\; \label{algRescheduleConstraintValueChangeValue}
+          $base \assng base \addSeq \otherConstraints$\; \label{algRescheduleConstraintValueAdd}
+          \ForAll{$p\iterAssng allParents(v)$}{ \label{algRescheduleConstraintValueCorrectStart}
+             % variablesMap.addAll(variable, otherConstraints);
               $\relevantConstraintsPerDeclaration \assng \relevantConstraintsPerDeclaration \addMap \mapEntry{p}{\relevantConstraintsPerDeclaration [v] \cup \otherConstraints}$\;
-          }
-          $\otherConstraints \assng \emptySet$\;
+          }\label{algRescheduleConstraintValueCorrectEnd}
+          $\otherConstraints \assng \emptySet$\;\label{algRescheduleConstraintValueClearCo}
        }
  \caption{Reschedule a constraint value (\IVML{rescheduleConstraintValue}).}\label{algRescheduleConstraintValue}
 \end{algorithm}
+
+Algorithm \ref{algRescheduleConstraintValue} accesses the existing constraints of the parent variable and clears them in line \ref{algRescheduleConstraintValueClear} from the constraint base and $\relevantConstraintsPerDeclaration$ if requested  using Algorithm \ref{algObtainConstraints}. Then it determines a constraint expression for the given value, i.e., it extracts a constraint or a constant boolean expression from the given value as shown below\footnote{For the implementation, constraint value and Boolean value are two differently typed instances that require different code to obtain a constraint expression.}:
+%
+\begin{align*}
+get&ConstraintValueExpression(val) =\\ &\begin{cases} value(val) & \text{if } isConstraint(type(value)) \vee isBoolean(type(value)) \\ \undef & \text{else}\end{cases}
+\end{align*}
+%
+If a constraint expression $e$ was extracted, the algorithm constructs a parent access expression $e_p$ from $v$, in particular to enable variable substitutions for \IVMLself{} in line \ref{algRescheduleConstraintValueCreateParent}. Such an access expression can be created through a recursive traversal of the parent model elements, e.g., compounds, incrementally leading to an access expression starting at a top-level variable:
+%
+\begin{align*}
+cre&ateParentExpression(v) =\\ &\createExpression{\closedCases{\IVMLMeta{acc}(createParentExpression(v), decl(v)) & \text{if } parent(v) \neq \undef \\ decl(v) & \text{else}}}
+\end{align*}
+%
+ From the constraint expression $e$, the parent access expression $e_p$ and the parent variable $v_p$, Algorithm \ref{algRescheduleConstraintValue} creates in line \ref{algRescheduleConstraintValueCreateConstraint} a constraint by calling Algorithm \ref{algCreateConstraintVariableConstraint}. Algorithm \ref{algCreateConstraintVariableConstraint} performs the variable substitution, registers the constraint appropriately and adds the constraint to $\otherConstraints$ (as for the initial translations, to be cleared later). To correct constraints with unbound iterator variables, Algorithm \ref{algRescheduleConstraintValue} changes in line \ref{algRescheduleConstraintValueChangeValue} the value of $v$ in a way that avoids re-triggering the constraint re-scheduling Algorithm \ref{algVarChange}, i.e., prevents an accidental recursion. Finally, Algorithm \ref{algRescheduleConstraintValue} takes over the new constraint into the constraint base in line \ref{algRescheduleConstraintValueAdd}, corrects the constraint registration in $\relevantConstraintsPerDeclaration$ for $v$ and all its parents (lines \ref{algRescheduleConstraintValueCorrectStart}-\ref{algRescheduleConstraintValueCorrectEnd}) so so that future re-scheduling of dependent constraints can take the new constraint into account and clears $\otherConstraints$ in line \ref{algRescheduleConstraintValueClearCo} for future calls.
+
+
 
 %\begin{algorithm}[H]
@@ -120,4 +139,12 @@
 \begin{algorithm}[H]
   \SetAlgoLined
+  \caption{Obtaining and clearing constraints (\IVML{obtainConstraints}).}\label{algObtainConstraints}
+  \MISSING{Algorithm}\\
+
+\end{algorithm}
+
+
+\begin{algorithm}[H]
+  \SetAlgoLined
   \caption{Reschedule a value type change (\IVML{rescheduleValueTypeChange}).}\label{algRescheduleValueTypeChange}
   \MISSING{Algorithm}\\
