Index: trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.Designer.cs
===================================================================
--- trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.Designer.cs	(revision 7880)
+++ trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.Designer.cs	(revision 7885)
@@ -61,4 +61,5 @@
       this.selectAllCheckBox = new System.Windows.Forms.CheckBox();
       this.selectNoneCheckBox = new System.Windows.Forms.CheckBox();
+      this.instanceDiscoveryBackgroundWorker = new System.ComponentModel.BackgroundWorker();
       ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).BeginInit();
       this.SuspendLayout();
@@ -181,14 +182,13 @@
       this.experimentCreationBackgroundWorker.WorkerSupportsCancellation = true;
       this.experimentCreationBackgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.experimentCreationBackgroundWorker_DoWork);
-      this.experimentCreationBackgroundWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.experimentCreationBackgroundWorker_ProgressChanged);
+      this.experimentCreationBackgroundWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker_ProgressChanged);
       this.experimentCreationBackgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.experimentCreationBackgroundWorker_RunWorkerCompleted);
       // 
       // experimentCreationProgressBar
       // 
-      this.experimentCreationProgressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
-            | System.Windows.Forms.AnchorStyles.Right)));
-      this.experimentCreationProgressBar.Location = new System.Drawing.Point(15, 259);
+      this.experimentCreationProgressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
+      this.experimentCreationProgressBar.Location = new System.Drawing.Point(128, 142);
       this.experimentCreationProgressBar.Name = "experimentCreationProgressBar";
-      this.experimentCreationProgressBar.Size = new System.Drawing.Size(92, 23);
+      this.experimentCreationProgressBar.Size = new System.Drawing.Size(128, 23);
       this.experimentCreationProgressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
       this.experimentCreationProgressBar.TabIndex = 7;
@@ -197,12 +197,12 @@
       // progressLabel
       // 
-      this.progressLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+      this.progressLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
       this.progressLabel.BackColor = System.Drawing.SystemColors.Control;
-      this.progressLabel.Location = new System.Drawing.Point(113, 259);
+      this.progressLabel.Location = new System.Drawing.Point(128, 168);
       this.progressLabel.Name = "progressLabel";
-      this.progressLabel.Size = new System.Drawing.Size(75, 23);
+      this.progressLabel.Size = new System.Drawing.Size(128, 23);
       this.progressLabel.TabIndex = 8;
       this.progressLabel.Text = "label1";
-      this.progressLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+      this.progressLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
       this.progressLabel.Visible = false;
       // 
@@ -229,4 +229,12 @@
       this.selectNoneCheckBox.CheckedChanged += new System.EventHandler(this.selectNoneCheckBox_CheckedChanged);
       // 
+      // instanceDiscoveryBackgroundWorker
+      // 
+      this.instanceDiscoveryBackgroundWorker.WorkerReportsProgress = true;
+      this.instanceDiscoveryBackgroundWorker.WorkerSupportsCancellation = true;
+      this.instanceDiscoveryBackgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.instanceDiscoveryBackgroundWorker_DoWork);
+      this.instanceDiscoveryBackgroundWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker_ProgressChanged);
+      this.instanceDiscoveryBackgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.instanceDiscoveryBackgroundWorker_RunWorkerCompleted);
+      // 
       // CreateExperimentDialog
       // 
@@ -236,4 +244,6 @@
       this.CancelButton = this.cancelButton;
       this.ClientSize = new System.Drawing.Size(281, 294);
+      this.Controls.Add(this.progressLabel);
+      this.Controls.Add(this.experimentCreationProgressBar);
       this.Controls.Add(this.selectNoneCheckBox);
       this.Controls.Add(this.selectAllCheckBox);
@@ -246,6 +256,4 @@
       this.Controls.Add(this.cancelButton);
       this.Controls.Add(this.okButton);
-      this.Controls.Add(this.progressLabel);
-      this.Controls.Add(this.experimentCreationProgressBar);
       this.MaximizeBox = false;
       this.MinimizeBox = false;
@@ -257,4 +265,5 @@
       this.TopMost = true;
       this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CreateExperimentDialog_FormClosing);
+      this.Load += new System.EventHandler(this.CreateExperimentDialog_Load);
       ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).EndInit();
       this.ResumeLayout(false);
@@ -280,4 +289,5 @@
     private System.Windows.Forms.CheckBox selectAllCheckBox;
     private System.Windows.Forms.CheckBox selectNoneCheckBox;
+    private System.ComponentModel.BackgroundWorker instanceDiscoveryBackgroundWorker;
 
   }
Index: trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
===================================================================
--- trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs	(revision 7880)
+++ trunk/sources/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs	(revision 7885)
@@ -24,4 +24,5 @@
 using System.ComponentModel;
 using System.Linq;
+using System.Text;
 using System.Threading;
 using System.Windows.Forms;
@@ -38,5 +39,5 @@
         experiment = null;
         okButton.Enabled = optimizer != null;
-        FillOrHideInstanceListView();
+        SetInstanceListViewVisibility();
       }
     }
@@ -57,56 +58,38 @@
       createBatchRun = createBatchRunCheckBox.Checked;
       repetitions = (int)repetitionsNumericUpDown.Value;
-      Optimizer = optimizer;
-    }
-
-    private void FillOrHideInstanceListView() {
-      if (optimizer != null && optimizer is IAlgorithm) {
-        var algorithm = (IAlgorithm)Optimizer;
-        if (algorithm.Problem != null) {
-          var instanceProviders = ProblemInstanceManager.GetProviders(algorithm.Problem);
-          if (instanceProviders.Any()) {
-            FillInstanceListView(instanceProviders);
-            if (instancesListView.Items.Count > 0) {
-              selectAllCheckBox.Visible = true;
-              selectNoneCheckBox.Visible = true;
-              instancesLabel.Visible = true;
-              instancesListView.Visible = true;
-              Height = 330;
-              return;
-            }
-          }
-        }
-      }
-      selectAllCheckBox.Visible = false;
-      selectNoneCheckBox.Visible = false;
-      instancesLabel.Visible = false;
-      instancesListView.Visible = false;
-      Height = 130;
-    }
-
-    private void FillInstanceListView(IEnumerable<IProblemInstanceProvider> instanceProviders) {
-      foreach (var provider in instanceProviders) {
-        var group = new ListViewGroup(provider.Name, provider.Name);
-        group.Tag = provider;
-        instancesListView.Groups.Add(group);
-        foreach (var d in ProblemInstanceManager.GetDataDescriptors(provider)) {
-          var item = new ListViewItem(d.Name, group);
-          item.Tag = d;
-          instancesListView.Items.Add(item);
-        }
-      }
-      instancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
-      selectAllCheckBox.Checked = true;
-    }
-
-    private void createBatchRunCheckBox_CheckedChanged(object sender, EventArgs e) {
-      repetitionsNumericUpDown.Enabled = createBatchRunCheckBox.Checked;
-      createBatchRun = createBatchRunCheckBox.Checked;
-    }
-    private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
-      if (repetitionsNumericUpDown.Text == string.Empty)
-        repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
-      repetitions = (int)repetitionsNumericUpDown.Value;
-    }
+      // do not set the Optimizer property here, because we want to delay instance discovery to the time when the form loads
+      this.optimizer = optimizer;
+      this.experiment = null;
+      okButton.Enabled = optimizer != null;
+    }
+
+    #region Event handlers
+    private void CreateExperimentDialog_Load(object sender, EventArgs e) {
+      SetInstanceListViewVisibility();
+    }
+
+    private void CreateExperimentDialog_FormClosing(object sender, FormClosingEventArgs e) {
+      if (experimentCreationBackgroundWorker.IsBusy) {
+        if (DialogResult != System.Windows.Forms.DialogResult.OK) {
+          if (experimentCreationBackgroundWorker.IsBusy) experimentCreationBackgroundWorker.CancelAsync();
+          if (instanceDiscoveryBackgroundWorker.IsBusy) instanceDiscoveryBackgroundWorker.CancelAsync();
+        }
+        e.Cancel = true;
+      }
+    }
+
+    private void okButton_Click(object sender, EventArgs e) {
+      SetMode(locked: true);
+      experimentCreationBackgroundWorker.RunWorkerAsync(GetSelectedInstances());
+      backgroundWorkerWaitHandle.WaitOne(); // make sure the background worker has started before exiting
+    }
+
+    private void instancesListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
+      if (!suppressListViewEventHandling) {
+        selectAllCheckBox.Checked = instancesListView.Items.Count == instancesListView.CheckedItems.Count;
+        selectNoneCheckBox.Checked = instancesListView.CheckedItems.Count == 0;
+      }
+    }
+
     private void selectAllCheckBox_CheckedChanged(object sender, EventArgs e) {
       if (selectAllCheckBox.Checked) {
@@ -121,4 +104,5 @@
       }
     }
+
     private void selectNoneCheckBox_CheckedChanged(object sender, EventArgs e) {
       if (selectNoneCheckBox.Checked) {
@@ -133,18 +117,133 @@
       }
     }
-    private void instancesListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
-      if (!suppressListViewEventHandling) {
-        selectAllCheckBox.Checked = instancesListView.Items.Count == instancesListView.CheckedItems.Count;
-        selectNoneCheckBox.Checked = instancesListView.CheckedItems.Count == 0;
-      }
-    }
-    private void okButton_Click(object sender, EventArgs e) {
-      SetMode(createExperiment: true);
-      experimentCreationBackgroundWorker.RunWorkerAsync(GetSelectedInstances());
-      backgroundWorkerWaitHandle.WaitOne();
-    }
+
+    private void createBatchRunCheckBox_CheckedChanged(object sender, EventArgs e) {
+      repetitionsNumericUpDown.Enabled = createBatchRunCheckBox.Checked;
+      createBatchRun = createBatchRunCheckBox.Checked;
+    }
+
+    private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
+      if (repetitionsNumericUpDown.Text == string.Empty)
+        repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
+      repetitions = (int)repetitionsNumericUpDown.Value;
+    }
+    #endregion
+
+    #region Helpers
+    private void SetInstanceListViewVisibility() {
+      bool instancesAvailable = optimizer != null
+        && optimizer is IAlgorithm
+        && ((IAlgorithm)optimizer).Problem != null
+        && ProblemInstanceManager.GetProviders(((IAlgorithm)optimizer).Problem).Any();
+      selectAllCheckBox.Visible = instancesAvailable;
+      selectNoneCheckBox.Visible = instancesAvailable;
+      instancesLabel.Visible = instancesAvailable;
+      instancesListView.Visible = instancesAvailable;
+      if (instancesAvailable) {
+        Height = 330;
+        FillInstanceListViewAsync();
+      } else Height = 130;
+    }
+
+    private void FillInstanceListViewAsync() {
+      SetMode(locked: true);
+      var instanceProviders = ProblemInstanceManager.GetProviders(((IAlgorithm)Optimizer).Problem);
+      instanceDiscoveryBackgroundWorker.RunWorkerAsync(instanceProviders);
+    }
+
+    private void AddOptimizer(IOptimizer optimizer, Experiment experiment) {
+      if (createBatchRun) {
+        var batchRun = new BatchRun();
+        batchRun.Repetitions = repetitions;
+        batchRun.Optimizer = optimizer;
+        experiment.Optimizers.Add(batchRun);
+      } else {
+        experiment.Optimizers.Add(optimizer);
+      }
+    }
+
+    private void SetMode(bool locked) {
+      createBatchRunCheckBox.Enabled = !locked;
+      repetitionsNumericUpDown.Enabled = !locked;
+      selectAllCheckBox.Enabled = !locked;
+      selectNoneCheckBox.Enabled = !locked;
+      instancesListView.Enabled = !locked;
+      instancesListView.Visible = !locked;
+      okButton.Enabled = !locked;
+      okButton.Visible = !locked;
+      progressLabel.Visible = locked;
+      experimentCreationProgressBar.Visible = locked;
+    }
+
+    private Dictionary<IProblemInstanceProvider, List<IDataDescriptor>> GetSelectedInstances() {
+      var selectedInstances = new Dictionary<IProblemInstanceProvider, List<IDataDescriptor>>();
+      foreach (var checkedItem in instancesListView.CheckedItems.OfType<ListViewItem>()) {
+        if (!selectedInstances.ContainsKey((IProblemInstanceProvider)checkedItem.Group.Tag))
+          selectedInstances.Add((IProblemInstanceProvider)checkedItem.Group.Tag, new List<IDataDescriptor>());
+        selectedInstances[(IProblemInstanceProvider)checkedItem.Group.Tag].Add((IDataDescriptor)checkedItem.Tag);
+      }
+      return selectedInstances;
+    }
+    #endregion
+
+    #region Background workers
+    private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
+      experimentCreationProgressBar.Value = e.ProgressPercentage;
+      progressLabel.Text = (string)e.UserState;
+    }
+
+    private void instanceDiscoveryBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
+      double progress = 0;
+      instanceDiscoveryBackgroundWorker.ReportProgress((int)progress, string.Empty);
+      var instanceProviders = ((IEnumerable<IProblemInstanceProvider>)e.Argument).ToArray();
+      ListViewGroup[] groups = new ListViewGroup[instanceProviders.Length];
+      for (int i = 0; i < instanceProviders.Length; i++) {
+        var provider = instanceProviders[i];
+        groups[i] = new ListViewGroup(provider.Name, provider.Name) { Tag = provider };
+      }
+      e.Result = groups;
+      for (int i = 0; i < groups.Length; i++) {
+        var group = groups[i];
+        var provider = group.Tag as IProblemInstanceProvider;
+        progress = (100.0 * i) / groups.Length;
+        instanceDiscoveryBackgroundWorker.ReportProgress((int)progress, provider.Name);
+        var descriptors = ProblemInstanceManager.GetDataDescriptors(provider).ToArray();
+        for (int j = 0; j < descriptors.Length; j++) {
+          #region Check cancellation request
+          if (instanceDiscoveryBackgroundWorker.CancellationPending) {
+            e.Cancel = true;
+            return;
+          }
+          #endregion
+          var d = descriptors[j];
+          progress += 1.0 / (descriptors.Length * groups.Length);
+          instanceDiscoveryBackgroundWorker.ReportProgress((int)progress, d.Name);
+          var item = new ListViewItem(d.Name, group) { Tag = d };
+        }
+      }
+      instanceDiscoveryBackgroundWorker.ReportProgress(100, string.Empty);
+    }
+
+    private void instanceDiscoveryBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
+      try {
+        // unfortunately it's not enough to just add the groups, the items need to be added separately
+        foreach (var group in (ListViewGroup[])e.Result) {
+          instancesListView.Groups.Add(group);
+          instancesListView.Items.AddRange(group.Items);
+        }
+        instancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
+        selectAllCheckBox.Checked = true;
+      } catch { }
+      try {
+        SetMode(locked: false);
+        if (e.Error != null) MessageBox.Show(e.Error.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
+      } catch { }
+    }
+
+    private StringBuilder failedInstances;
     private void experimentCreationBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
       backgroundWorkerWaitHandle.Set();
       experimentCreationBackgroundWorker.ReportProgress(0, string.Empty);
+      failedInstances = new StringBuilder();
       var items = (Dictionary<IProblemInstanceProvider, List<IDataDescriptor>>)e.Argument;
       var localExperiment = new Experiment();
@@ -156,14 +255,24 @@
         foreach (var provider in items.Keys) {
           foreach (var descriptor in items[provider]) {
-            var algorithm = (IAlgorithm)Optimizer.Clone();
-            ProblemInstanceManager.LoadData(provider, descriptor, (IProblemInstanceConsumer)algorithm.Problem);
-            AddOptimizer(algorithm, localExperiment);
-            counter++;
-            experimentCreationBackgroundWorker.ReportProgress((int)Math.Round(100.0 * counter / total), descriptor.Name);
+            #region Check cancellation request
             if (experimentCreationBackgroundWorker.CancellationPending) {
               e.Cancel = true;
               localExperiment = null;
-              break;
+              return;
             }
+            #endregion
+            var algorithm = (IAlgorithm)Optimizer.Clone();
+            bool failed = false;
+            try {
+              ProblemInstanceManager.LoadData(provider, descriptor, (IProblemInstanceConsumer)algorithm.Problem);
+            } catch (Exception ex) {
+              failedInstances.AppendLine(descriptor.Name + ": " + ex.Message);
+              failed = true;
+            }
+            if (!failed) {
+              AddOptimizer(algorithm, localExperiment);
+              counter++;
+              experimentCreationBackgroundWorker.ReportProgress((int)Math.Round(100.0 * counter / total), descriptor.Name);
+            } else experimentCreationBackgroundWorker.ReportProgress((int)Math.Round(100.0 * counter / total), "Loading failed (" + descriptor.Name + ")");
           }
         }
@@ -172,57 +281,18 @@
       e.Result = localExperiment;
     }
-    private void experimentCreationBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
-      experimentCreationProgressBar.Value = e.ProgressPercentage;
-      progressLabel.Text = (string)e.UserState;
-    }
+
     private void experimentCreationBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
-      SetMode(createExperiment: false);
-      if (e.Error != null) MessageBox.Show(e.Error.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
-      if (!e.Cancelled && e.Error == null) {
-        experiment = (Experiment)e.Result;
-        DialogResult = System.Windows.Forms.DialogResult.OK;
-        Close();
-      }
-    }
-    private void CreateExperimentDialog_FormClosing(object sender, FormClosingEventArgs e) {
-      if (experimentCreationBackgroundWorker.IsBusy) {
-        if (DialogResult != System.Windows.Forms.DialogResult.OK)
-          experimentCreationBackgroundWorker.CancelAsync();
-        e.Cancel = true;
-      }
-    }
-
-    private void AddOptimizer(IOptimizer optimizer, Experiment experiment) {
-      if (createBatchRun) {
-        var batchRun = new BatchRun();
-        batchRun.Repetitions = repetitions;
-        batchRun.Optimizer = optimizer;
-        experiment.Optimizers.Add(batchRun);
-      } else {
-        experiment.Optimizers.Add(optimizer);
-      }
-    }
-
-    private void SetMode(bool createExperiment) {
-      createBatchRunCheckBox.Enabled = !createExperiment;
-      repetitionsNumericUpDown.Enabled = !createExperiment;
-      selectAllCheckBox.Enabled = !createExperiment;
-      selectNoneCheckBox.Enabled = !createExperiment;
-      instancesListView.Enabled = !createExperiment;
-      okButton.Enabled = !createExperiment;
-      okButton.Visible = !createExperiment;
-      progressLabel.Visible = createExperiment;
-      experimentCreationProgressBar.Visible = createExperiment;
-    }
-
-    private Dictionary<IProblemInstanceProvider, List<IDataDescriptor>> GetSelectedInstances() {
-      var selectedInstances = new Dictionary<IProblemInstanceProvider, List<IDataDescriptor>>();
-      foreach (var checkedItem in instancesListView.CheckedItems.OfType<ListViewItem>()) {
-        if (!selectedInstances.ContainsKey((IProblemInstanceProvider)checkedItem.Group.Tag))
-          selectedInstances.Add((IProblemInstanceProvider)checkedItem.Group.Tag, new List<IDataDescriptor>());
-        selectedInstances[(IProblemInstanceProvider)checkedItem.Group.Tag].Add((IDataDescriptor)checkedItem.Tag);
-      }
-      return selectedInstances;
-    }
+      try {
+        SetMode(locked: false);
+        if (e.Error != null) MessageBox.Show(e.Error.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
+        if (failedInstances.Length > 0) MessageBox.Show("Some instances could not be loaded: " + Environment.NewLine + failedInstances.ToString(), "Some instances failed to load", MessageBoxButtons.OK, MessageBoxIcon.Error);
+        if (!e.Cancelled && e.Error == null) {
+          experiment = (Experiment)e.Result;
+          DialogResult = System.Windows.Forms.DialogResult.OK;
+          Close();
+        }
+      } catch { }
+    }
+    #endregion
   }
 }
