Index: trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs	(revision 4068)
+++ trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs	(revision 4098)
@@ -120,5 +120,4 @@
       set { BestKnownSolutionParameter.Value = value; }
     }
-    private List<IOperator> operators;
     public IEnumerable<IOperator> Operators {
       get { return operators; }
@@ -129,4 +128,9 @@
     #endregion
 
+    [Storable]
+    private List<IOperator> operators;
+
+    [StorableConstructor]
+    private TravelingSalesmanProblem(bool deserializing) : base() { }
     public TravelingSalesmanProblem()
       : base() {
@@ -155,15 +159,187 @@
       ParameterizeEvaluator();
 
-      Initialize();
-    }
-    [StorableConstructor]
-    private TravelingSalesmanProblem(bool deserializing) : base() { }
+      InitializeOperators();
+      AttachEventHandlers();
+    }
 
     public override IDeepCloneable Clone(Cloner cloner) {
       TravelingSalesmanProblem clone = (TravelingSalesmanProblem)base.Clone(cloner);
+      clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
       clone.DistanceMatrixParameter.Value = DistanceMatrixParameter.Value;
-      clone.Initialize();
+      clone.AttachEventHandlers();
       return clone;
     }
+
+    #region Events
+    public event EventHandler SolutionCreatorChanged;
+    private void OnSolutionCreatorChanged() {
+      EventHandler handler = SolutionCreatorChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+    public event EventHandler EvaluatorChanged;
+    private void OnEvaluatorChanged() {
+      EventHandler handler = EvaluatorChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+    public event EventHandler OperatorsChanged;
+    private void OnOperatorsChanged() {
+      EventHandler handler = OperatorsChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+    public event EventHandler Reset;
+    private void OnReset() {
+      EventHandler handler = Reset;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+
+    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
+      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
+      Coordinates.Reset += new EventHandler(Coordinates_Reset);
+      ParameterizeSolutionCreator();
+      ClearDistanceMatrix();
+    }
+    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
+      ClearDistanceMatrix();
+    }
+    private void Coordinates_Reset(object sender, EventArgs e) {
+      ParameterizeSolutionCreator();
+      ClearDistanceMatrix();
+    }
+    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
+      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
+      ParameterizeSolutionCreator();
+      ParameterizeEvaluator();
+      ParameterizeAnalyzer();
+      ParameterizeOperators();
+      OnSolutionCreatorChanged();
+    }
+    private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
+      ParameterizeEvaluator();
+      ParameterizeAnalyzer();
+      ParameterizeOperators();
+    }
+    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
+      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
+      ParameterizeEvaluator();
+      UpdateMoveEvaluators();
+      ParameterizeAnalyzer();
+      ClearDistanceMatrix();
+      OnEvaluatorChanged();
+    }
+    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
+      ParameterizeAnalyzer();
+    }
+    private void MoveGenerator_InversionMoveParameter_ActualNameChanged(object sender, EventArgs e) {
+      string name = ((ILookupParameter<InversionMove>)sender).ActualName;
+      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
+        op.InversionMoveParameter.ActualName = name;
+      }
+    }
+    private void MoveGenerator_TranslocationMoveParameter_ActualNameChanged(object sender, EventArgs e) {
+      string name = ((ILookupParameter<TranslocationMove>)sender).ActualName;
+      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
+        op.TranslocationMoveParameter.ActualName = name;
+      }
+    }
+    #endregion
+
+    #region Helpers
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AttachEventHandlers() {
+      // Start BackwardsCompatibility3.3 (remove with 3.4)
+      if (operators == null) InitializeOperators();
+      // End BackwardsCompatibility3.3
+      CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
+      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
+      Coordinates.Reset += new EventHandler(Coordinates_Reset);
+      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
+      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
+      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
+      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
+    }
+
+    private void InitializeOperators() {
+      operators = new List<IOperator>();
+      operators.Add(new BestTSPSolutionAnalyzer());
+      ParameterizeAnalyzer();
+      operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>().Cast<IOperator>());
+      ParameterizeOperators();
+      UpdateMoveEvaluators();
+      InitializeMoveGenerators();
+    }
+    private void InitializeMoveGenerators() {
+      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
+        if (op is IMoveGenerator) {
+          op.InversionMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_InversionMoveParameter_ActualNameChanged);
+        }
+      }
+      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
+        if (op is IMoveGenerator) {
+          op.TranslocationMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_TranslocationMoveParameter_ActualNameChanged);
+        }
+      }
+    }
+    private void UpdateMoveEvaluators() {
+      operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
+      foreach (ITSPPathMoveEvaluator op in ApplicationManager.Manager.GetInstances<ITSPPathMoveEvaluator>())
+        if (op.EvaluatorType == Evaluator.GetType()) {
+          operators.Add(op);
+        }
+      ParameterizeOperators();
+      OnOperatorsChanged();
+    }
+    private void ParameterizeSolutionCreator() {
+      SolutionCreator.LengthParameter.Value = new IntValue(Coordinates.Rows);
+      SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected);
+    }
+    private void ParameterizeEvaluator() {
+      if (Evaluator is ITSPPathEvaluator)
+        ((ITSPPathEvaluator)Evaluator).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
+      if (Evaluator is ITSPCoordinatesPathEvaluator) {
+        ITSPCoordinatesPathEvaluator evaluator = (ITSPCoordinatesPathEvaluator)Evaluator;
+        evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
+        evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
+        evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
+      }
+    }
+    private void ParameterizeAnalyzer() {
+      BestTSPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
+      BestTSPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
+      BestTSPSolutionAnalyzer.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
+      BestTSPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
+      BestTSPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
+      BestTSPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
+      BestTSPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
+    }
+    private void ParameterizeOperators() {
+      foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) {
+        op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
+        op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
+      }
+      foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>()) {
+        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
+      }
+      foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) {
+        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
+      }
+      foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>()) {
+        op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
+        op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
+        op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
+        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
+        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
+      }
+      string inversionMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>().First().InversionMoveParameter.ActualName;
+      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>())
+        op.InversionMoveParameter.ActualName = inversionMove;
+      string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName;
+      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>())
+        op.TranslocationMoveParameter.ActualName = translocationMove;
+    }
+
+    private void ClearDistanceMatrix() {
+      DistanceMatrixParameter.Value = null;
+    }
+    #endregion
 
     public void ImportFromTSPLIB(string tspFileName, string optimalTourFileName) {
@@ -197,174 +373,4 @@
       BestKnownQuality = new DoubleValue(bestKnownQuality);
     }
-
-    #region Events
-    public event EventHandler SolutionCreatorChanged;
-    private void OnSolutionCreatorChanged() {
-      EventHandler handler = SolutionCreatorChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler EvaluatorChanged;
-    private void OnEvaluatorChanged() {
-      EventHandler handler = EvaluatorChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler OperatorsChanged;
-    private void OnOperatorsChanged() {
-      EventHandler handler = OperatorsChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler Reset;
-    private void OnReset() {
-      EventHandler handler = Reset;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-
-    private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
-      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
-      Coordinates.Reset += new EventHandler(Coordinates_Reset);
-      ParameterizeSolutionCreator();
-      ClearDistanceMatrix();
-    }
-    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
-      ClearDistanceMatrix();
-    }
-    private void Coordinates_Reset(object sender, EventArgs e) {
-      ParameterizeSolutionCreator();
-      ClearDistanceMatrix();
-    }
-    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
-      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
-      ParameterizeSolutionCreator();
-      ParameterizeEvaluator();
-      ParameterizeAnalyzer();
-      ParameterizeOperators();
-      OnSolutionCreatorChanged();
-    }
-    private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
-      ParameterizeEvaluator();
-      ParameterizeAnalyzer();
-      ParameterizeOperators();
-    }
-    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
-      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
-      ParameterizeEvaluator();
-      UpdateMoveEvaluators();
-      ParameterizeAnalyzer();
-      ClearDistanceMatrix();
-      OnEvaluatorChanged();
-    }
-    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
-      ParameterizeAnalyzer();
-    }
-    private void MoveGenerator_InversionMoveParameter_ActualNameChanged(object sender, EventArgs e) {
-      string name = ((ILookupParameter<InversionMove>)sender).ActualName;
-      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
-        op.InversionMoveParameter.ActualName = name;
-      }
-    }
-    private void MoveGenerator_TranslocationMoveParameter_ActualNameChanged(object sender, EventArgs e) {
-      string name = ((ILookupParameter<TranslocationMove>)sender).ActualName;
-      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
-        op.TranslocationMoveParameter.ActualName = name;
-      }
-    }
-    #endregion
-
-    #region Helpers
-    [StorableHook(HookType.AfterDeserialization)]
-    private void Initialize() {
-      InitializeOperators();
-      CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
-      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
-      Coordinates.Reset += new EventHandler(Coordinates_Reset);
-      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
-      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
-      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
-      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
-    }
-
-    private void InitializeOperators() {
-      operators = new List<IOperator>();
-      operators.Add(new BestTSPSolutionAnalyzer());
-      ParameterizeAnalyzer();
-      operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>().Cast<IOperator>());
-      ParameterizeOperators();
-      UpdateMoveEvaluators();
-      InitializeMoveGenerators();
-    }
-    private void InitializeMoveGenerators() {
-      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
-        if (op is IMoveGenerator) {
-          op.InversionMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_InversionMoveParameter_ActualNameChanged);
-        }
-      }
-      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
-        if (op is IMoveGenerator) {
-          op.TranslocationMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_TranslocationMoveParameter_ActualNameChanged);
-        }
-      }
-    }
-    private void UpdateMoveEvaluators() {
-      operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
-      foreach (ITSPPathMoveEvaluator op in ApplicationManager.Manager.GetInstances<ITSPPathMoveEvaluator>())
-        if (op.EvaluatorType == Evaluator.GetType()) {
-          operators.Add(op);
-        }
-      ParameterizeOperators();
-      OnOperatorsChanged();
-    }
-    private void ParameterizeSolutionCreator() {
-      SolutionCreator.LengthParameter.Value = new IntValue(Coordinates.Rows);
-      SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected);
-    }
-    private void ParameterizeEvaluator() {
-      if (Evaluator is ITSPPathEvaluator)
-        ((ITSPPathEvaluator)Evaluator).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
-      if (Evaluator is ITSPCoordinatesPathEvaluator) {
-        ITSPCoordinatesPathEvaluator evaluator = (ITSPCoordinatesPathEvaluator)Evaluator;
-        evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
-        evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
-        evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
-      }
-    }
-    private void ParameterizeAnalyzer() {
-      BestTSPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
-      BestTSPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
-      BestTSPSolutionAnalyzer.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
-      BestTSPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
-      BestTSPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
-      BestTSPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
-      BestTSPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
-    }
-    private void ParameterizeOperators() {
-      foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) {
-        op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
-        op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
-      }
-      foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>()) {
-        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
-      }
-      foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) {
-        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
-      }
-      foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>()) {
-        op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
-        op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
-        op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
-        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
-        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
-      }
-      string inversionMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>().First().InversionMoveParameter.ActualName;
-      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>())
-        op.InversionMoveParameter.ActualName = inversionMove;
-      string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName;
-      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>())
-        op.TranslocationMoveParameter.ActualName = translocationMove;
-    }
-
-    private void ClearDistanceMatrix() {
-      DistanceMatrixParameter.Value = null;
-    }
-    #endregion
   }
 }
