Index: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskModel.java
===================================================================
--- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskModel.java	(revision 1646)
+++ branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskModel.java	(revision 1733)
@@ -43,6 +43,7 @@
  * <p>
  * this is the default implementation of the interface {@link ITaskModel}. It
- * does not do anything fancy except implementing the interface. It also calculates on
- * initialisations the measures for diverse metrics of the task belonging to the model
+ * does not do anything fancy except implementing the interface. It also
+ * calculates on initialisations the measures for diverse metrics of the task
+ * belonging to the model
  * </p>
  * 
@@ -50,344 +51,360 @@
  */
 class TaskModel implements ITaskModel {
-    
-    /**
-     * <p>
-     * default serial version UID
-     * </p>
-     */
-    private static final long serialVersionUID = 1L;
-    
-    /**
-     * <p>
-     * all metrics calculated by this type of task model
-     * </p>
-     */
-    private static final TaskMetric[] taskMetrics = new TaskMetric[]
-        { TaskMetric.COUNT,
-          TaskMetric.DEPTH,
-          TaskMetric.EVENT_COVERAGE,
-          TaskMetric.EVENT_COVERAGE_RATIO,
-          TaskMetric.EVENT_COVERAGE_QUANTILE };
-
-    /**
-     * <p>
-     * the user sessions belonging to the model
-     * </p>
-     */
-    private List<IUserSession> userSessions;
-
-    /**
-     * <p>
-     * index for effectively accessing the model and calculating statistics about it
-     * </p>
-     */
-    private transient TaskModelIndex index = null;
-    
-    /**
-     * <p>
-     * initializes the task model with the user sessions out of which the tasks are extracted
-     * </p>
-     * 
-     * @param userSessions as described
-     */
-    TaskModel(List<IUserSession> userSessions) {
-        if ((userSessions == null) || (userSessions.size() == 0)) {
-            throw new IllegalArgumentException("user sessions must not be null");
-        }
-        
-        this.userSessions = userSessions;
-    }
-
-    
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions()
-     */
-    @Override
-    public List<IUserSession> getUserSessions() {
-        ensureInitialized();
-        return Collections.unmodifiableList(userSessions);
-    }
-
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks()
-     */
-    @Override
-    public Collection<ITask> getTasks() {
-        ensureInitialized();
-        return Collections.unmodifiableCollection(index.taskMap.keySet());
-    }
-
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(ITask)
-     */
-    @Override
-    public ITaskInfo getTaskInfo(ITask task) {
-        ensureInitialized();
-        return index.taskMap.get(task);
-    }
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getAllMetrics()
-     */
-    @Override
-    public TaskMetric[] getAllMetrics() {
-        return taskMetrics;
-    }
-
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#clone()
-     */
-    @Override
-    public TaskModel clone() {
-        return new TaskModel(userSessions);
-    }
-
-    /**
-     * <p>
-     * internal convenience method that initializes the internal index and calculates all measures
-     * for metrics available for the tasks
-     * </p>
-     */
-    private synchronized void ensureInitialized() {
-        if (index == null) {
-            index = new TaskModelIndex();
-            
-            for (IUserSession session : this.userSessions) {
-                for (ITaskInstance taskInstance : session) {
-                    index.handleTaskInstance(taskInstance, null);
-                }
-            }
-            
-            // count all events covered
-            int allEventsCovered = 0;
-            Collection<ITask> tasks = getTasks();
-            for (ITask task : tasks) {
-                if (task instanceof IEventTask) {
-                    allEventsCovered += task.getInstances().size();
-                }
-            }
-            
-            int[] eventCoverageRatios = new int[tasks.size()];
-            int i = 0;
-
-            // add some further measures
-            for (ITask task : tasks) {
-                TaskInfo info = index.taskMap.get(task);
-                info.addMeasure(TaskMetric.EVENT_COVERAGE_RATIO);
-                
-                int coveredEvents = info.getMeasureValue(TaskMetric.EVENT_COVERAGE);
-                int coverageRatio = 0;
-                
-                if (allEventsCovered > 0) {
-                    coverageRatio = (coveredEvents * 1000) / allEventsCovered;
-                }
-                
-                eventCoverageRatios[i++] = coverageRatio;
-                info.setCount(TaskMetric.EVENT_COVERAGE_RATIO, null, coverageRatio);
-            }
-            
-            Arrays.sort(eventCoverageRatios);
-            
-            // add some further measures
-            for (ITask task : tasks) {
-                TaskInfo info = index.taskMap.get(task);
-                info.addMeasure(TaskMetric.EVENT_COVERAGE_QUANTILE);
-                int quantile = Arrays.binarySearch
-                    (eventCoverageRatios, info.getMeasureValue(TaskMetric.EVENT_COVERAGE_RATIO));
-                
-                quantile = 1000 * quantile / eventCoverageRatios.length;
-                
-                info.setCount(TaskMetric.EVENT_COVERAGE_QUANTILE, null, quantile);
-            }
-            
-            //index.dumpToCSV(System.out);
-            /*try {
-                OutputStream stream = new FileOutputStream(new File("tasks.csv"));
-                index.dumpToCSV(new PrintStream(stream));
-                stream.close();
-            }
-            catch (FileNotFoundException e) {
-                e.printStackTrace();
-            }*/
-        }
-        
-    }
-
-    /**
-     * <p>
-     * the index of task infos used internally. The index is created once and while that filled
-     * with task infos for each observed task containing all measures for metrics belonging
-     * to the tasks. 
-     * </p>
-     * 
-     * @author Patrick Harms
-     */
-    private static class TaskModelIndex {
-
-        /**
-         * <p>
-         * the tasks contained in the user session belonging to the model as well as statistical
-         * infos about them
-         * </p>
-         */
-        private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>();
-
-        /**
-         * <p>
-         * called on initialization to fill the index with infos about the given task instance
-         * as well as to calculate the appropriate metrics
-         * </p>
-         */
-        private int[] handleTaskInstance(ITaskInstance taskInstance, ITask context) {
-            int eventTaskInstancesCovered = 0;
-            int depth = 0;
-            
-            if (taskInstance instanceof ITaskInstanceList) {
-                for (ITaskInstance child : (ITaskInstanceList) taskInstance) {
-                    int[] measures = handleTaskInstance(child, taskInstance.getTask());
-                    eventTaskInstancesCovered += measures[0];
-                    depth = Math.max(depth, measures[1]);
-                }
-                
-                if ((((ITaskInstanceList) taskInstance).size() == 0) &&
-                    (taskInstance instanceof IIterationInstance))
-                {
-                    // ensure also empty task infos for unselected variants
-                    ensureTaskInfo(((IIteration) taskInstance.getTask()).getMarkedTask(), context);
-                }
-            }
-            else if (taskInstance instanceof ISelectionInstance) {
-                ITaskInstance child = ((ISelectionInstance) taskInstance).getChild();
-                int[] measures = handleTaskInstance(child, taskInstance.getTask());
-                eventTaskInstancesCovered += measures[0];
-                depth = Math.max(depth, measures[1]);
-                
-                // ensure also empty task infos for unselected variants
-                for (ITask otherChildTask : ((ISelection) taskInstance.getTask()).getChildren()) {
-                    ensureTaskInfo(otherChildTask, context);
-                }
-            }
-            else if (taskInstance instanceof IOptionalInstance) {
-                ITaskInstance child = ((IOptionalInstance) taskInstance).getChild();
-                if (child != null) {
-                    int[] measures = handleTaskInstance(child, taskInstance.getTask());
-                    eventTaskInstancesCovered += measures[0];
-                    depth = Math.max(depth, measures[1]);
-                }
-                else {
-                    // ensure also empty task infos for unselected variants
-                    ensureTaskInfo(((IOptional) taskInstance.getTask()).getMarkedTask(), context);
-                }
-            }
-            else if (taskInstance instanceof IEventTaskInstance) {
-                eventTaskInstancesCovered = 1;
-            }
-            
-            depth++;
-            
-            ensureTaskInfo(taskInstance.getTask(), context, eventTaskInstancesCovered, depth);
-            
-            return new int[] { eventTaskInstancesCovered, depth };
-        }
-        
-        /**
-         * <p>
-         * internal convenience method to build the task model during initialization
-         * </p>
-         */
-        private void ensureTaskInfo(ITask task, ITask context) {
-            ensureTaskInfo(task, context, 0, 0);
-            
-            if (task instanceof IStructuringTemporalRelationship) {
-                for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) {
-                    ensureTaskInfo(child, task);
-                }
-            }
-            else if (task instanceof IMarkingTemporalRelationship) {
-                ensureTaskInfo(((IMarkingTemporalRelationship) task).getMarkedTask(), task);
-            }
-        
-        }
-        
-        /**
-         * <p>
-         * internal convenience method to build the task model during initialization. Adds a new
-         * task info object to the map for the provided task and fills it with measures. If there
-         * are already some task infos for the task, the contained measures are updated according
-         * to the parameters.
-         * </p>
-         */
-        private void ensureTaskInfo(ITask task,
-                                    ITask context,
-                                    int   eventTaskInstancesCovered,
-                                    int   depth)
-        {
-            TaskInfo taskInfo = taskMap.get(task);
-
-            if (taskInfo == null) {
-                taskInfo = new TaskInfo(task);
-                taskInfo.addMeasure(TaskMetric.COUNT);
-                taskInfo.addMeasure(TaskMetric.EVENT_COVERAGE);
-                taskInfo.addMeasure(TaskMetric.DEPTH);
-                taskMap.put(task, taskInfo);
-                
-                taskInfo.setCount(TaskMetric.DEPTH, null, getDepth(task));
-            }
-
-            taskInfo.increaseCount(TaskMetric.COUNT, context, 1);
-            taskInfo.increaseCount(TaskMetric.EVENT_COVERAGE, context, eventTaskInstancesCovered);
-
-            taskInfo.setCount(TaskMetric.DEPTH, context, depth);
-        }
-
-        /**
-         * <p>
-         * internal convenience method to calculate the maximum depth of a task
-         * </p>
-         */
-        private int getDepth(ITask task) {
-            if (task instanceof IMarkingTemporalRelationship) {
-                return getDepth(((IMarkingTemporalRelationship) task).getMarkedTask()) + 1;
-            }
-            else if (task instanceof IStructuringTemporalRelationship) {
-                int maxDepth = 0;
-                
-                for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) {
-                    maxDepth = Math.max(maxDepth, getDepth(child));
-                }
-                
-                return maxDepth + 1;
-            }
-            else {
-                // event tasks
-                return 1;
-            }
-        }
-
-        /**
-         *
-         */
-        /*private void dumpToCSV(PrintStream out) {
-            out.println("taskid;depth;count;eventcoverage;eventcoverageratio");
-            
-            for (Map.Entry<ITask, TaskInfo> entry : taskMap.entrySet()) {
-                out.print(entry.getKey().getId());
-                out.print(';');
-                out.print(entry.getValue().getMeasureValue(TaskMetric.DEPTH));
-                out.print(';');
-                out.print(entry.getValue().getMeasureValue(TaskMetric.COUNT));
-                out.print(';');
-                out.print(entry.getValue().getMeasureValue(TaskMetric.EVENT_COVERAGE));
-                out.print(';');
-                out.print(entry.getValue().getMeasureValue(TaskMetric.EVENT_COVERAGE_RATIO));
-                out.println();
-            }
-        }*/
-
-    }
-
+
+	/**
+	 * <p>
+	 * the index of task infos used internally. The index is created once and
+	 * while that filled with task infos for each observed task containing all
+	 * measures for metrics belonging to the tasks.
+	 * </p>
+	 * 
+	 * @author Patrick Harms
+	 */
+	private static class TaskModelIndex {
+
+		/**
+		 * <p>
+		 * the tasks contained in the user session belonging to the model as
+		 * well as statistical infos about them
+		 * </p>
+		 */
+		private final Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>();
+
+		/**
+		 * <p>
+		 * internal convenience method to build the task model during
+		 * initialization
+		 * </p>
+		 */
+		private void ensureTaskInfo(ITask task, ITask context) {
+			ensureTaskInfo(task, context, 0, 0);
+
+			if (task instanceof IStructuringTemporalRelationship) {
+				for (final ITask child : ((IStructuringTemporalRelationship) task)
+						.getChildren()) {
+					ensureTaskInfo(child, task);
+				}
+			} else if (task instanceof IMarkingTemporalRelationship) {
+				ensureTaskInfo(
+						((IMarkingTemporalRelationship) task).getMarkedTask(),
+						task);
+			}
+
+		}
+
+		/**
+		 * <p>
+		 * internal convenience method to build the task model during
+		 * initialization. Adds a new task info object to the map for the
+		 * provided task and fills it with measures. If there are already some
+		 * task infos for the task, the contained measures are updated according
+		 * to the parameters.
+		 * </p>
+		 */
+		private void ensureTaskInfo(ITask task, ITask context,
+				int eventTaskInstancesCovered, int depth) {
+			TaskInfo taskInfo = taskMap.get(task);
+
+			if (taskInfo == null) {
+				taskInfo = new TaskInfo(task);
+				taskInfo.addMeasure(TaskMetric.COUNT);
+				taskInfo.addMeasure(TaskMetric.EVENT_COVERAGE);
+				taskInfo.addMeasure(TaskMetric.DEPTH);
+				taskMap.put(task, taskInfo);
+
+				taskInfo.setCount(TaskMetric.DEPTH, null, getDepth(task));
+			}
+
+			taskInfo.increaseCount(TaskMetric.COUNT, context, 1);
+			taskInfo.increaseCount(TaskMetric.EVENT_COVERAGE, context,
+					eventTaskInstancesCovered);
+
+			taskInfo.setCount(TaskMetric.DEPTH, context, depth);
+		}
+
+		/**
+		 * <p>
+		 * internal convenience method to calculate the maximum depth of a task
+		 * </p>
+		 */
+		private int getDepth(ITask task) {
+			if (task instanceof IMarkingTemporalRelationship) {
+				return getDepth(((IMarkingTemporalRelationship) task)
+						.getMarkedTask()) + 1;
+			} else if (task instanceof IStructuringTemporalRelationship) {
+				int maxDepth = 0;
+
+				for (final ITask child : ((IStructuringTemporalRelationship) task)
+						.getChildren()) {
+					maxDepth = Math.max(maxDepth, getDepth(child));
+				}
+
+				return maxDepth + 1;
+			} else {
+				// event tasks
+				return 1;
+			}
+		}
+
+		/**
+		 * <p>
+		 * called on initialization to fill the index with infos about the given
+		 * task instance as well as to calculate the appropriate metrics
+		 * </p>
+		 */
+		private int[] handleTaskInstance(ITaskInstance taskInstance,
+				ITask context) {
+			int eventTaskInstancesCovered = 0;
+			int depth = 0;
+
+			if (taskInstance instanceof ITaskInstanceList) {
+				for (final ITaskInstance child : (ITaskInstanceList) taskInstance) {
+					final int[] measures = handleTaskInstance(child,
+							taskInstance.getTask());
+					eventTaskInstancesCovered += measures[0];
+					depth = Math.max(depth, measures[1]);
+				}
+
+				if ((((ITaskInstanceList) taskInstance).size() == 0)
+						&& (taskInstance instanceof IIterationInstance)) {
+					// ensure also empty task infos for unselected variants
+					ensureTaskInfo(
+							((IIteration) taskInstance.getTask())
+									.getMarkedTask(),
+							context);
+				}
+			} else if (taskInstance instanceof ISelectionInstance) {
+				final ITaskInstance child = ((ISelectionInstance) taskInstance)
+						.getChild();
+				final int[] measures = handleTaskInstance(child,
+						taskInstance.getTask());
+				eventTaskInstancesCovered += measures[0];
+				depth = Math.max(depth, measures[1]);
+
+				// ensure also empty task infos for unselected variants
+				for (final ITask otherChildTask : ((ISelection) taskInstance
+						.getTask()).getChildren()) {
+					ensureTaskInfo(otherChildTask, context);
+				}
+			} else if (taskInstance instanceof IOptionalInstance) {
+				final ITaskInstance child = ((IOptionalInstance) taskInstance)
+						.getChild();
+				if (child != null) {
+					final int[] measures = handleTaskInstance(child,
+							taskInstance.getTask());
+					eventTaskInstancesCovered += measures[0];
+					depth = Math.max(depth, measures[1]);
+				} else {
+					// ensure also empty task infos for unselected variants
+					ensureTaskInfo(
+							((IOptional) taskInstance.getTask())
+									.getMarkedTask(),
+							context);
+				}
+			} else if (taskInstance instanceof IEventTaskInstance) {
+				eventTaskInstancesCovered = 1;
+			}
+
+			depth++;
+
+			ensureTaskInfo(taskInstance.getTask(), context,
+					eventTaskInstancesCovered, depth);
+
+			return new int[] { eventTaskInstancesCovered, depth };
+		}
+
+		/**
+		 *
+		 */
+		/*
+		 * private void dumpToCSV(PrintStream out) {
+		 * out.println("taskid;depth;count;eventcoverage;eventcoverageratio");
+		 * 
+		 * for (Map.Entry<ITask, TaskInfo> entry : taskMap.entrySet()) {
+		 * out.print(entry.getKey().getId()); out.print(';');
+		 * out.print(entry.getValue().getMeasureValue(TaskMetric.DEPTH));
+		 * out.print(';');
+		 * out.print(entry.getValue().getMeasureValue(TaskMetric.COUNT));
+		 * out.print(';');
+		 * out.print(entry.getValue().getMeasureValue(TaskMetric.
+		 * EVENT_COVERAGE)); out.print(';');
+		 * out.print(entry.getValue().getMeasureValue
+		 * (TaskMetric.EVENT_COVERAGE_RATIO)); out.println(); } }
+		 */
+
+	}
+
+	/**
+	 * <p>
+	 * default serial version UID
+	 * </p>
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * <p>
+	 * all metrics calculated by this type of task model
+	 * </p>
+	 */
+	private static final TaskMetric[] taskMetrics = new TaskMetric[] {
+			TaskMetric.COUNT, TaskMetric.DEPTH, TaskMetric.EVENT_COVERAGE,
+			TaskMetric.EVENT_COVERAGE_RATIO, TaskMetric.EVENT_COVERAGE_QUANTILE };
+
+	/**
+	 * <p>
+	 * the user sessions belonging to the model
+	 * </p>
+	 */
+	private final List<IUserSession> userSessions;
+
+	/**
+	 * <p>
+	 * index for effectively accessing the model and calculating statistics
+	 * about it
+	 * </p>
+	 */
+	private transient TaskModelIndex index = null;
+
+	/**
+	 * <p>
+	 * initializes the task model with the user sessions out of which the tasks
+	 * are extracted
+	 * </p>
+	 * 
+	 * @param userSessions
+	 *            as described
+	 */
+	TaskModel(List<IUserSession> userSessions) {
+		if ((userSessions == null) || (userSessions.size() == 0)) {
+			throw new IllegalArgumentException("user sessions must not be null");
+		}
+
+		this.userSessions = userSessions;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Object#clone()
+	 */
+	@Override
+	public TaskModel clone() {
+		return new TaskModel(userSessions);
+	}
+
+	/**
+	 * <p>
+	 * internal convenience method that initializes the internal index and
+	 * calculates all measures for metrics available for the tasks
+	 * </p>
+	 */
+	private synchronized void ensureInitialized() {
+		if (index == null) {
+			index = new TaskModelIndex();
+
+			for (final IUserSession session : this.userSessions) {
+				for (final ITaskInstance taskInstance : session) {
+					index.handleTaskInstance(taskInstance, null);
+				}
+			}
+
+			// count all events covered
+			int allEventsCovered = 0;
+			final Collection<ITask> tasks = getTasks();
+			for (final ITask task : tasks) {
+				if (task instanceof IEventTask) {
+					allEventsCovered += task.getInstances().size();
+				}
+			}
+
+			final int[] eventCoverageRatios = new int[tasks.size()];
+			int i = 0;
+
+			// add some further measures
+			for (final ITask task : tasks) {
+				final TaskInfo info = index.taskMap.get(task);
+				info.addMeasure(TaskMetric.EVENT_COVERAGE_RATIO);
+
+				final int coveredEvents = info
+						.getMeasureValue(TaskMetric.EVENT_COVERAGE);
+				int coverageRatio = 0;
+
+				if (allEventsCovered > 0) {
+					coverageRatio = (coveredEvents * 1000) / allEventsCovered;
+				}
+
+				eventCoverageRatios[i++] = coverageRatio;
+				info.setCount(TaskMetric.EVENT_COVERAGE_RATIO, null,
+						coverageRatio);
+			}
+
+			Arrays.sort(eventCoverageRatios);
+
+			// add some further measures
+			for (final ITask task : tasks) {
+				final TaskInfo info = index.taskMap.get(task);
+				info.addMeasure(TaskMetric.EVENT_COVERAGE_QUANTILE);
+				int quantile = Arrays.binarySearch(eventCoverageRatios,
+						info.getMeasureValue(TaskMetric.EVENT_COVERAGE_RATIO));
+
+				quantile = (1000 * quantile) / eventCoverageRatios.length;
+
+				info.setCount(TaskMetric.EVENT_COVERAGE_QUANTILE, null,
+						quantile);
+			}
+
+			// index.dumpToCSV(System.out);
+			/*
+			 * try { OutputStream stream = new FileOutputStream(new
+			 * File("tasks.csv")); index.dumpToCSV(new PrintStream(stream));
+			 * stream.close(); } catch (FileNotFoundException e) {
+			 * e.printStackTrace(); }
+			 */
+		}
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getAllMetrics()
+	 */
+	@Override
+	public TaskMetric[] getAllMetrics() {
+		return taskMetrics;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(ITask)
+	 */
+	@Override
+	public ITaskInfo getTaskInfo(ITask task) {
+		ensureInitialized();
+		return index.taskMap.get(task);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks()
+	 */
+	@Override
+	public Collection<ITask> getTasks() {
+		ensureInitialized();
+		return Collections.unmodifiableCollection(index.taskMap.keySet());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions()
+	 */
+	@Override
+	public List<IUserSession> getUserSessions() {
+		ensureInitialized();
+		return Collections.unmodifiableList(userSessions);
+	}
 
 }
