Index: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/GenerateTask.java
===================================================================
--- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/GenerateTask.java	(revision 1621)
+++ branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/GenerateTask.java	(revision 1630)
@@ -1,13 +1,15 @@
 package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms;
 
+/*
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
-
+*/
 public class GenerateTask {
 	
 	
-	private ITaskFactory taskFactory;
+	//private ITaskFactory taskFactory;
 	/**
 	 * <p>
@@ -16,4 +18,5 @@
 	 * </p>
 	 */
+	/*
 	private ITaskBuilder taskBuilder;
 	
@@ -30,5 +33,11 @@
 	}
 	
+	void optional() {
+		IOptional optional = taskFactory.createNewOptional();
+		//taskBuilder.setChild(optional, child);
+		
+	}
 	
+	*/
 	
 }
Index: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/Match.java
===================================================================
--- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/Match.java	(revision 1621)
+++ branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/Match.java	(revision 1630)
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.LinkedList;
+
+
 
 public class Match {
@@ -64,4 +65,6 @@
 		occurences.addAll(occ);
 	}
+	
+   
 
 }
Index: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java
===================================================================
--- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java	(revision 1621)
+++ branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java	(revision 1630)
@@ -2,5 +2,4 @@
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.logging.Level;
 
Index: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java
===================================================================
--- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java	(revision 1621)
+++ branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/pal/tree/UPGMAAligningTree.java	(revision 1630)
@@ -56,5 +56,4 @@
 	
 		this.numberseqs = numberseqs;
-		this.alignments = alignments;
 		this.submat = submat;
 		init(alignments.getDistanceMatrix());
@@ -82,5 +81,4 @@
 	//
 	private ArrayList<NumberSequence> numberseqs;
-	private PairwiseAlignmentStorage alignments;
 	private ObjectDistanceSubstitionMatrix submat;
 	private int numClusters;
Index: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
===================================================================
--- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java	(revision 1621)
+++ branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java	(revision 1630)
@@ -27,5 +27,4 @@
 import java.util.logging.Level;
 
-import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory;
 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match;
 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence;
@@ -34,8 +33,8 @@
 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage;
 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix;
-import de.ugoe.cs.autoquest.tasktrees.alignment.pal.tree.UPGMAAligningTree;
 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance;
@@ -49,5 +48,4 @@
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
 import de.ugoe.cs.autoquest.usageprofiles.SymbolMap;
-import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor;
 import de.ugoe.cs.util.StopWatch;
 import de.ugoe.cs.util.console.Console;
@@ -97,11 +95,11 @@
 	 * <p>
 	 * the task handling strategy to be used for comparing tasks during
-	 * iteration detection an trie generation, i.e., after the tasks are
+	 * iteration detection i.e., after the tasks are
 	 * harmonized
 	 * </p>
 	 */
-	private TaskHandlingStrategy identityTaskHandlingStrategy;;
-
-	private ArrayList<NumberSequence> numberseqs;
+	private TaskHandlingStrategy identityTaskHandlingStrategy;
+
+
 
 	/**
@@ -129,5 +127,4 @@
 		this.identityTaskHandlingStrategy = new TaskHandlingStrategy(
 				TaskEquality.IDENTICAL);
-		numberseqs = new ArrayList<NumberSequence>();
 
 	}
@@ -157,5 +154,5 @@
 		SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData);
 
-		// Generate a substitution matrix between all occuring events.
+		// Generate a substitution matrix between all occurring events.
 		Console.traceln(Level.INFO, "generating substitution matrix");
 		ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix(
@@ -167,15 +164,15 @@
 		LinkedList<Match> matchseqs = new LinkedList<Match>();
 		PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator
-				.generate(numberseqs, submat, 9);
+				.generate(appData.getNumberSequences(), submat, 9);
 
 		// Retrieve all matches reached a specific threshold
 		Console.traceln(Level.INFO, "retrieving significant sequence pieces");
-		for (int i = 0; i < numberseqs.size(); i++) {
+		for (int i = 0; i < appData.getNumberSequences().size(); i++) {
 			Console.traceln(
 					Level.FINEST,
 					"retrieving significant sequence pieces:  "
-							+ Math.round((float) i / (float) numberseqs.size()
+							+ Math.round((float) i / (float) appData.getNumberSequences().size()
 									* 100) + "%");
-			for (int j = 0; j < numberseqs.size(); j++) {
+			for (int j = 0; j < appData.getNumberSequences().size(); j++) {
 				if (i != j) {
 					matchseqs.addAll(alignments.get(i, j).getMatches());
@@ -189,6 +186,4 @@
 		// search each match in every other sequence
 		for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) {
-			int sequencecount = 0;
-			int totalcount = 0;
 			Match pattern = it.next();
 
@@ -202,10 +197,9 @@
 				continue;
 	
-			for (int j = 0; j < numberseqs.size(); j++) {
-				LinkedList<Integer> startpositions = numberseqs.get(j)
+			for (int j = 0; j < appData.getNumberSequences().size(); j++) {
+				LinkedList<Integer> startpositions = appData.getNumberSequences().get(j)
 						.containsPattern(pattern);
 				if (startpositions.size() > 0) {
-					sequencecount++;
-					totalcount += startpositions.size();
+					
 					for (Iterator<Integer> jt = startpositions.iterator(); jt
 							.hasNext();) {
@@ -219,5 +213,5 @@
 
 		Console.traceln(Level.INFO, "sorting results");
-		// Sort results to get the most occuring results
+		// Sort results to get the most occurring results
 		Comparator<Match> comparator = new Comparator<Match>() {
 			public int compare(Match m1, Match m2) {
@@ -229,7 +223,5 @@
 		
 
-		
-		
-		// Harmonize matches: finding double matches and merge them
+		// TODO: Harmonize matches: finding double matches and merge them
 		/*
 		Console.traceln(Level.INFO, "harmonizing matches");
@@ -241,5 +233,5 @@
 				if(i!=j) {
 					if(matchseqs.get(i).equals(matchseqs.get(j))) {
-						matchseqs.get(i).addOccurencesOf(matchseqs.get(j));
+						//matchseqs.get(i).addOccurencesOf(matchseqs.get(j));
 						matchseqs.remove(j);
 					
@@ -258,10 +250,5 @@
 		}
 		Collections.sort(matchseqs, comparator);
-		*/ 
-	
-					
-			
-		
-		
+		*/
 		
 		
@@ -269,12 +256,15 @@
 		for (int i = 0; i < matchseqs.size(); i++) {
 			// Every pattern consists of 2 sequences, therefore the minimum
-			// occurences here is 2.
-			// We just need the sequences also occuring in other sequences as
+			// occurrences here is 2.
+			// We just need the sequences also occurring in other sequences as
 			// well
 			if (matchseqs.get(i).occurenceCount() > 2) {
-				matchseqs.get(i).getFirstSequence().printSequence();
-				matchseqs.get(i).getSecondSequence().printSequence();
-				System.out.println("Found pattern "
-						+ matchseqs.get(i).occurenceCount() + " times");
+				
+				ITask task = matchAsTask(appData,matchseqs.get(i));
+				System.out.println(task);
+				//matchseqs.get(i).getFirstSequence().printSequence();
+				//matchseqs.get(i).getSecondSequence().printSequence();
+				//System.out.println("Found pattern "
+				//		+ matchseqs.get(i).occurenceCount() + " times");
 				System.out.println();
 			}
@@ -284,20 +274,19 @@
 		alignments = null;
 
-		/*
-		 * do {
-		 * 
-		 * // appData.getStopWatch().start("whole loop"); //
-		 * detectAndReplaceIterations(appData);
-		 * 
-		 * // appData.getStopWatch().start("task replacement"); //
-		 * detectAndReplaceTasks(appData); //
-		 * appData.getStopWatch().stop("task replacement"); //
-		 * appData.getStopWatch().stop("whole loop");
-		 * 
-		 * // appData.getStopWatch().dumpStatistics(System.out); //
-		 * appData.getStopWatch().reset();
-		 * 
-		 * } while (appData.detectedAndReplacedTasks());
-		 */
+		do {
+		  
+		  appData.getStopWatch().start("whole loop"); //
+		  detectAndReplaceIterations(appData);
+		 
+		  appData.getStopWatch().start("task replacement"); //
+		  //detectAndReplaceTasks(appData); //
+		  appData.getStopWatch().stop("task replacement"); //
+		  appData.getStopWatch().stop("whole loop");
+		  
+		  appData.getStopWatch().dumpStatistics(System.out); //
+		  appData.getStopWatch().reset();
+		  
+		  } while (appData.detectedAndReplacedTasks());
+		 
 
 		Console.println("created "
@@ -316,4 +305,6 @@
 	}
 
+	
+	
 	/**
 	 * <p>
@@ -344,5 +335,4 @@
 		List<IUserSession> sessions = appData.getSessions();
 		int sessionNo = 0;
-		numberseqs = new ArrayList<NumberSequence>();
 		for (IUserSession session : sessions) {
 			Console.traceln(Level.FINE, "handling " + (++sessionNo) + ". "
@@ -357,4 +347,5 @@
 					uniqueTasks.addSymbol(taskInstance, taskInstance.getTask());
 					templist.getSequence()[i] = taskInstance.getTask().getId();
+		
 				} else {
 					taskBuilder.setTask(taskInstance, task);
@@ -362,7 +353,8 @@
 					unifiedTasks++;
 				}
-			}
-			templist.setId(numberseqs.size());
-			numberseqs.add(templist);
+				appData.getNumber2Task().put(templist.getSequence()[i], taskInstance.getTask());
+			}
+			templist.setId(appData.getNumberSequences().size());
+			appData.getNumberSequences().add(templist);
 			comparator.clearBuffers();
 		}
@@ -505,4 +497,50 @@
 	}
 
+	
+	 ITask matchAsTask(RuleApplicationData appData,Match m) {
+	    	
+	    	ISequence sequence = taskFactory.createNewSequence();
+	    	
+	    	int[] first = m.getFirstSequence().getSequence();
+	    	int[] second = m.getSecondSequence().getSequence();
+	    	System.out.println("Number2Task size: " +appData.getNumber2Task().size());
+	    	
+	    	//Both sequences of a match are equally long
+	    	for(int i=0;i<m.getFirstSequence().size();i++) {
+	    		System.out.println("First:" + first[i]);
+	    		System.out.println("Second:" + second[i]);
+	    		System.out.println();
+	    		//Two gaps aligned to each other: Have not seen it happening so far, just to handle it
+	    		if(first[i]==-1 && second[i]==-1) {
+	    			//TODO: Do nothing?
+	    		}
+	    		//Both events are equal, we can simply add the task referring to the number
+	    		else if(first[i]==second[i]) {
+	    			taskBuilder.addChild(sequence, appData.getNumber2Task().get(first[i]));
+	    		}
+	    		//We have a gap in the first sequence, we need to add the task of the second sequence as optional
+	    		else if(first[i]==-1 && second[i]!=-1) {
+	    			IOptional optional = taskFactory.createNewOptional();
+	    			taskBuilder.setMarkedTask(optional, appData.getNumber2Task().get(second[i]));
+	    			taskBuilder.addChild(sequence,optional);
+	    		}
+	    		//We have a gap in the second sequence, we need to add the task of the first sequence as optional
+	    		else if(first[i]!=-1 && second[i]==-1) {
+	    			IOptional optional = taskFactory.createNewOptional();
+	    			taskBuilder.setMarkedTask(optional, appData.getNumber2Task().get(first[i]));
+	    			taskBuilder.addChild(sequence,optional);
+	    		}
+	    		//Both tasks are unequal, we need to insert a selection here
+	    		else {
+	    			ISelection selection = taskFactory.createNewSelection();
+	    			taskBuilder.addChild(selection, appData.getNumber2Task().get(first[i]));
+	    			taskBuilder.addChild(selection, appData.getNumber2Task().get(second[i]));
+	    			taskBuilder.addChild(sequence,selection);
+	    		}
+	    	}
+			return sequence;
+		}
+	
+	
 	/**
 	 * <p>
@@ -579,5 +617,5 @@
 		appData.getStopWatch().start("detecting tasks");
 
-		getSequencesOccuringMostOften(appData);
+		//getSequencesOccuringMostOften(appData);
 
 		appData.getStopWatch().stop("detecting tasks");
@@ -587,8 +625,12 @@
 
 		appData.getStopWatch().stop("replacing tasks");
-		Console.traceln(Level.INFO, "detected and replaced "
-				+ appData.getLastFoundTasks().size() + " tasks occuring "
-				+ appData.getLastFoundTasks().getOccurrenceCount() + " times");
-	}
+		
+		//Console.traceln(Level.INFO, "detected and replaced "
+		//		+ appData.getLastFoundTasks().size() + " tasks occuring "
+		//		+ appData.getLastFoundTasks().getOccurrenceCount() + " times");
+	}
+
+	
+
 
 	/**
@@ -597,127 +639,10 @@
 	 *            this rule
 	 */
-	private void getSequencesOccuringMostOften(RuleApplicationData appData) {
-		Console.traceln(Level.FINE, "determining most prominent tasks");
-
-		Tasks tasks;
-		boolean createNewTrie = (appData.getLastTrie() == null)
-				|| appData.detectedAndReplacedTasks(); // tree has changed
-
-		do {
-			if (createNewTrie) {
-				createNewTrie(appData);
-			}
-
-			MaxCountAndLongestTasksFinder finder = new MaxCountAndLongestTasksFinder();
-			appData.getLastTrie().process(finder);
-
-			tasks = finder.getFoundTasks();
-
-			createNewTrie = false;
-
-			for (List<ITaskInstance> task : tasks) {
-				if (task.size() >= appData.getTrainedSequenceLength()) {
-					// Trie must be recreated with a longer sequence length to
-					// be sure that
-					// the found sequences occurring most often are found in
-					// their whole length
-					appData.setTrainedSequenceLength(appData
-							.getTrainedSequenceLength() + 1);
-					createNewTrie = true;
-					break;
-				}
-			}
-		} while (createNewTrie);
-
-		// create a normal trie for comparison
-		/*
-		 * System.out.println("creating test trie for comparison");
-		 * 
-		 * appData.getStopWatch().start("testtrie"); Trie<ITaskInstance> trie =
-		 * new Trie<ITaskInstance>(identityTaskComparator);
-		 * 
-		 * for (IUserSession session : appData.getSessions()) {
-		 * trie.train(session.getExecutedTasks(),
-		 * appData.getTrainedSequenceLength()); }
-		 * 
-		 * appData.getStopWatch().stop("testtrie");
-		 * 
-		 * MaxCountAndLongestTasksFinder finder = new
-		 * MaxCountAndLongestTasksFinder(); trie.process(finder);
-		 * 
-		 * boolean allTasksEqual = finder.getFoundTasks().size() ==
-		 * tasks.size();
-		 * 
-		 * allTasksEqual &= finder.getFoundTasks().occurrenceCount ==
-		 * tasks.occurrenceCount;
-		 * 
-		 * for (List<ITaskInstance> task1 : finder.getFoundTasks()) { boolean
-		 * foundTask = false; for (List<ITaskInstance> task2 : tasks) { boolean
-		 * tasksEqual = false; if (task1.size() == task2.size()) { tasksEqual =
-		 * true; for (int i = 0; i < task1.size(); i++) { if
-		 * (!identityTaskComparator.equals(task1.get(i).getTask(),
-		 * task2.get(i).getTask())) { tasksEqual = false; } } }
-		 * 
-		 * if (tasksEqual) { foundTask = true; break; } }
-		 * 
-		 * if (!foundTask) { System.out.println("different is " + task1);
-		 * allTasksEqual = false; break; } }
-		 * 
-		 * if (!allTasksEqual) { System.out.println(finder.getFoundTasks());
-		 * System.out.println(tasks);
-		 * 
-		 * throw new
-		 * IllegalArgumentException("both tries calculated different subsequences"
-		 * ); }
-		 * 
-		 * /*TrieStatisticsDumper dumper = new TrieStatisticsDumper();
-		 * appData.getLastTrie().process(dumper); dumper.dumpCounters();
-		 */
-
-		appData.setLastFoundTasks(tasks);
-
-		Console.traceln(Level.FINE, "found "
-				+ appData.getLastFoundTasks().size() + " tasks " + "occurring "
-				+ appData.getLastFoundTasks().getOccurrenceCount() + " times");
-	}
-
-	/**
-	 * @param appData
-	 *            the rule application data combining all data used for applying
-	 *            this rule
-	 */
-	private void createNewTrie(RuleApplicationData appData) {
-		Console.traceln(
-				Level.FINER,
-				"training trie with a maximum sequence length of "
-						+ appData.getTrainedSequenceLength());
-
-		appData.getStopWatch().start("training trie");
-
-		// we prepared the task instances to refer to unique tasks, if they are
-		// treated
-		// as equal. Therefore, we just compare the identity of the tasks of the
-		// task
-		// instances
-		appData.setLastTrie(new TaskInstanceTrie(identityTaskHandlingStrategy));
-
-		appData.getLastTrie().trainSessions(appData.getSessions(),
-				appData.getTrainedSequenceLength());
-
-		appData.getStopWatch().stop("training trie");
-	}
-
-	/**
-	 * @param appData
-	 *            the rule application data combining all data used for applying
-	 *            this rule
-	 */
 	private void replaceSequencesOccurringMostOften(RuleApplicationData appData) {
 		appData.detectedAndReplacedTasks(false);
 
-		if ((appData.getLastFoundTasks().size() > 0)
-				&& (appData.getLastFoundTasks().getOccurrenceCount() > 1)) {
+	
 			Console.traceln(Level.FINER, "replacing tasks occurrences");
-
+			/*
 			for (List<ITaskInstance> task : appData.getLastFoundTasks()) {
 				ISequence sequence = taskFactory.createNewSequence();
@@ -746,7 +671,7 @@
 				}
 			}
-		}
-
-	}
+			*/
+	}
+
 
 	/**
@@ -880,214 +805,4 @@
 	}
 
-	/**
-	 * @param trie
-	 * @param object
-	 * @return
-	 */
-	private int getSubListIndex(List<ITaskInstance> list,
-			List<ITaskInstance> subList, int startIndex) {
-		boolean matchFound;
-		int result = -1;
-
-		for (int i = startIndex; i <= list.size() - subList.size(); i++) {
-			matchFound = true;
-
-			for (int j = 0; j < subList.size(); j++) {
-				// we prepared the task instances to refer to unique tasks, if
-				// they are treated
-				// as equal. Therefore, we just compare the identity of the
-				// tasks of the task
-				// instances
-				if (list.get(i + j) != subList.get(j)) {
-					matchFound = false;
-					break;
-				}
-			}
-
-			if (matchFound) {
-				result = i;
-				break;
-			}
-		}
-
-		return result;
-	}
-
-	/**
-	 * @author Patrick Harms
-	 */
-	private class MaxCountAndLongestTasksFinder implements
-			TrieProcessor<ITaskInstance> {
-
-		/**
-         * 
-         */
-		private int currentCount;
-
-		/**
-         * 
-         */
-		private List<List<ITaskInstance>> foundTasks = new LinkedList<List<ITaskInstance>>();
-
-		/**
-         *
-         */
-		public MaxCountAndLongestTasksFinder() {
-			super();
-			this.currentCount = 0;
-		}
-
-		/*
-		 * (non-Javadoc)
-		 * 
-		 * @see
-		 * de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util
-		 * .List, int)
-		 */
-		@Override
-		public TrieProcessor.Result process(List<ITaskInstance> foundTask,
-				int count) {
-			if (foundTask.size() < 2) {
-				// ignore single tasks
-				return TrieProcessor.Result.CONTINUE;
-			}
-
-			if (count < 2) {
-				// ignore singular occurrences
-				return TrieProcessor.Result.SKIP_NODE;
-			}
-
-			if (this.currentCount > count) {
-				// ignore this children of this task, as they may have only
-				// smaller counts than
-				// the already found tasks
-				return TrieProcessor.Result.SKIP_NODE;
-			}
-
-			if (this.currentCount < count) {
-				// the provided task occurs more often that all tasks found so
-				// far.
-				// clear all found tasks and use the new count as the one
-				// searched for
-				foundTasks.clear();
-				this.currentCount = count;
-			}
-
-			if (this.currentCount == count) {
-				// the task is of interest. Sort it into the other found tasks
-				// so that
-				// the longest come first
-				boolean added = false;
-				for (int i = 0; i < foundTasks.size(); i++) {
-					if (foundTasks.get(i).size() < foundTask.size()) {
-						// defensive copy
-						foundTasks.add(i, new LinkedList<ITaskInstance>(
-								foundTask)); // defensive copy
-						added = true;
-						break;
-					}
-				}
-
-				if (!added) {
-					foundTasks.add(new LinkedList<ITaskInstance>(foundTask)); // defensive
-																				// copy
-				}
-			}
-
-			return TrieProcessor.Result.CONTINUE;
-		}
-
-		/**
-		 * @return
-		 */
-		public Tasks getFoundTasks() {
-			removePermutationsOfShorterTasks();
-			return new Tasks(currentCount, foundTasks);
-		}
-
-		/**
-         *
-         */
-		private void removePermutationsOfShorterTasks() {
-			// now iterate the sorted list and for each task remove all other
-			// tasks that are shorter
-			// (i.e. come later in the sorted list) and that represent a subpart
-			// of the task
-			for (int i = 0; i < foundTasks.size(); i++) {
-				for (int j = i + 1; j < foundTasks.size();) {
-					if (foundTasks.get(j).size() < foundTasks.get(i).size()) {
-						// found a task that is a potential subtask. Check for
-						// this and remove the
-						// subtask if needed
-						List<ITaskInstance> longTask = foundTasks.get(i);
-						List<ITaskInstance> shortTask = foundTasks.get(j);
-
-						if (getSubListIndex(longTask, shortTask, 0) > -1) {
-							foundTasks.remove(j);
-						} else {
-							j++;
-						}
-					} else {
-						j++;
-					}
-				}
-			}
-		}
-
-	}
-
-	// /**
-	// * @author Patrick Harms
-	// */
-	// private class TrieStatisticsDumper implements
-	// TrieProcessor<ITaskInstance> {
-	//
-	// /**
-	// *
-	// */
-	// private Map<Integer, Integer> counters = new HashMap<Integer, Integer>();
-	//
-	// /* (non-Javadoc)
-	// * @see
-	// de.ugoe.cs.autoquest.usageprofiles.TrieProcessor#process(java.util.List,
-	// int)
-	// */
-	// @Override
-	// public TrieProcessor.Result process(List<ITaskInstance> subsequence, int
-	// count) {
-	// if (subsequence.size() == 1) {
-	// Integer value = counters.get(count);
-	//
-	// if (value == null) {
-	// value = 0;
-	// }
-	//
-	// counters.put(count, value + 1);
-	//
-	// return TrieProcessor.Result.CONTINUE;
-	// }
-	// else {
-	// // ignore singular occurrences
-	// return TrieProcessor.Result.SKIP_NODE;
-	// }
-	// }
-	//
-	// /**
-	// * @return
-	// */
-	// public void dumpCounters() {
-	// int dumpedCounters = 0;
-	//
-	// int count = 1;
-	// while (dumpedCounters < counters.size()) {
-	// Integer value = counters.get(count++);
-	// if (value != null) {
-	// System.out.println(value + " symbols occurred " + count + " times");
-	// dumpedCounters++;
-	// }
-	// }
-	// }
-	//
-	// }
 
 	/**
@@ -1096,4 +811,10 @@
 	private static class RuleApplicationData {
 
+		
+		private HashMap<Integer,ITask> number2task;
+		
+		
+		private ArrayList<NumberSequence> numberseqs;
+		
 		/**
          * 
@@ -1101,18 +822,5 @@
 		private List<IUserSession> sessions;
 
-		/**
-         * 
-         */
-		private TaskInstanceTrie lastTrie;
-
-		/**
-		 * default and minimum trained sequence length is 3
-		 */
-		private int trainedSequenceLength = 3;
-
-		/**
-         * 
-         */
-		private Tasks lastFoundTasks = new Tasks(Integer.MAX_VALUE, null);
+
 
 		/**
@@ -1124,10 +832,10 @@
          * 
          */
-		private RuleApplicationResult result = new RuleApplicationResult();
+		private RuleApplicationResult result;
 
 		/**
          * 
          */
-		private StopWatch stopWatch = new StopWatch();
+		private StopWatch stopWatch;
 
 		/**
@@ -1136,4 +844,8 @@
 		private RuleApplicationData(List<IUserSession> sessions) {
 			this.sessions = sessions;
+			numberseqs = new ArrayList<NumberSequence>();
+			number2task = new HashMap<Integer,ITask>();
+			stopWatch= new StopWatch();
+			result =  new RuleApplicationResult();
 		}
 
@@ -1145,48 +857,10 @@
 		}
 
-		/**
-		 * @param lastTrie
-		 *            the lastTrie to set
-		 */
-		private void setLastTrie(TaskInstanceTrie lastTrie) {
-			this.lastTrie = lastTrie;
-		}
-
-		/**
-		 * @return the lastTrie
-		 */
-		private TaskInstanceTrie getLastTrie() {
-			return lastTrie;
-		}
-
-		/**
-		 * @param trainedSequenceLength
-		 *            the trainedSequenceLength to set
-		 */
-		private void setTrainedSequenceLength(int trainedSequenceLength) {
-			this.trainedSequenceLength = trainedSequenceLength;
-		}
-
-		/**
-		 * @return the trainedSequenceLength
-		 */
-		private int getTrainedSequenceLength() {
-			return trainedSequenceLength;
-		}
-
-		/**
-		 * @param lastFoundSequences
-		 *            the lastFoundSequences to set
-		 */
-		private void setLastFoundTasks(Tasks lastFoundSequences) {
-			this.lastFoundTasks = lastFoundSequences;
-		}
-
-		/**
-		 * @return the lastFoundSequences
-		 */
-		private Tasks getLastFoundTasks() {
-			return lastFoundTasks;
-		}
+		
+		private ArrayList<NumberSequence> getNumberSequences() {
+			return numberseqs;
+		}
+
+	
 
 		/**
@@ -1218,147 +892,12 @@
 		}
 
-	}
-
-	/**
-	 * @author Patrick Harms
-	 */
-	private static class Tasks implements Iterable<List<ITaskInstance>> {
-
-		/**
-         * 
-         */
-		private int occurrenceCount;
-
-		/**
-         * 
-         */
-		private List<List<ITaskInstance>> sequences;
-
-		/**
-		 * @param occurrenceCount
-		 * @param sequences
-		 */
-		private Tasks(int occurrenceCount, List<List<ITaskInstance>> sequences) {
-			super();
-			this.occurrenceCount = occurrenceCount;
-			this.sequences = sequences;
-		}
-
-		/**
-		 * @return
-		 */
-		private int getOccurrenceCount() {
-			return occurrenceCount;
-		}
-
-		/**
-		 * @return
-		 */
-		private int size() {
-			return this.sequences.size();
-		}
-
-		/**
-         * 
-         */
-
-		/*
-		 * (non-Javadoc)
-		 * 
-		 * @see java.lang.Iterable#iterator()
-		 */
-		@Override
-		public Iterator<List<ITaskInstance>> iterator() {
-			return this.sequences.iterator();
-		}
-
-		/*
-		 * (non-Javadoc)
-		 * 
-		 * @see java.lang.Object#toString()
-		 */
-		@Override
-		public String toString() {
-			StringBuffer result = new StringBuffer();
-			result.append(this.occurrenceCount);
-			result.append(" occurrences:\n");
-
-			for (List<ITaskInstance> task : sequences) {
-				result.append(task);
-				result.append("\n");
-			}
-
-			return result.toString();
-		}
-
-	}
-
-	// methods for internal testing
-	// private void checkMatchingOfSessions(List<List<Event>> flattenedSessions,
-	// List<IUserSession> sessions,
-	// String when)
-	// {
-	// List<List<Event>> currentFlattenedSessions = flattenSessions(sessions);
-	// if (flattenedSessions.size() != currentFlattenedSessions.size()) {
-	// System.out.println("################## number of sessions changed after "
-	// + when);
-	// }
-	// else {
-	// for (int i = 0; i < flattenedSessions.size(); i++) {
-	// List<Event> expected = flattenedSessions.get(i);
-	// List<Event> current = currentFlattenedSessions.get(i);
-	//
-	// if (expected.size() != current.size()) {
-	// System.out.println
-	// ("################## length of session " + i + " changed after " + when);
-	// }
-	// else {
-	// for (int j = 0; j < expected.size(); j++) {
-	// if (!expected.get(j).equals(current.get(j))) {
-	// System.out.println("################## event " + j + " of session " +
-	// i + " changed after " + when);
-	// }
-	// }
-	// }
-	// }
-	// }
-	// }
-	//
-	// private List<List<Event>> flattenSessions(List<IUserSession> sessions) {
-	// List<List<Event>> flattenedSessions = new ArrayList<List<Event>>();
-	// for (IUserSession session : sessions) {
-	// List<Event> flattenedUserSession = new ArrayList<Event>();
-	// flatten(session, flattenedUserSession);
-	// flattenedSessions.add(flattenedUserSession);
-	// }
-	//
-	// return flattenedSessions;
-	// }
-	//
-	// private void flatten(IUserSession iUserSession, List<Event>
-	// flattenedUserSession) {
-	// for (ITaskInstance instance : iUserSession) {
-	// flatten(instance, flattenedUserSession);
-	// }
-	// }
-	//
-	// private void flatten(ITaskInstance instance, List<Event>
-	// flattenedUserSession) {
-	// if (instance instanceof ITaskInstanceList) {
-	// for (ITaskInstance child : (ITaskInstanceList) instance) {
-	// flatten(child, flattenedUserSession);
-	// }
-	// }
-	// else if (instance instanceof ISelectionInstance) {
-	// flatten(((ISelectionInstance) instance).getChild(),
-	// flattenedUserSession);
-	// }
-	// else if (instance instanceof IOptionalInstance) {
-	// flatten(((IOptionalInstance) instance).getChild(), flattenedUserSession);
-	// }
-	// else if (instance instanceof IEventTaskInstance) {
-	// flattenedUserSession.add(((IEventTaskInstance) instance).getEvent());
-	// }
-	// }
+		private HashMap<Integer,ITask> getNumber2Task() {
+			return number2task;
+		}
+
+	}
+
+	
+
 
 }
