Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/06/11 20:47:56 (12 years ago)
Author:
abeham
Message:

#1619

  • reverted changes to trunk
  • readded instances as embedded resources
Location:
trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/HeuristicLab.Problems.QuadraticAssignment.Views-3.3.csproj

    r6891 r6952  
    212212    </ProjectReference>
    213213  </ItemGroup>
    214   <ItemGroup>
    215     <WCFMetadata Include="Service References\" />
    216   </ItemGroup>
    217214  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    218215  <PropertyGroup>
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.Designer.cs

    r6891 r6952  
    5454      this.visualizationTabPage = new System.Windows.Forms.TabPage();
    5555      this.qapView = new HeuristicLab.Problems.QuadraticAssignment.Views.QAPVisualizationControl();
    56       this.reloadInstancesButton = new System.Windows.Forms.Button();
    57       this.loadInstanceWorker = new System.ComponentModel.BackgroundWorker();
    58       this.progressBar = new System.Windows.Forms.ProgressBar();
    59       this.getInstancesWorker = new System.ComponentModel.BackgroundWorker();
    6056      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    6157      this.tabControl.SuspendLayout();
     
    9490      this.toolTip.SetToolTip(this.importInstanceButton, "Import files in QAPLIB format.");
    9591      this.importInstanceButton.UseVisualStyleBackColor = true;
    96       this.importInstanceButton.Click += new System.EventHandler(this.importFileInstanceButton_Click);
     92      this.importInstanceButton.Click += new System.EventHandler(this.importInstanceButton_Click);
    9793      //
    9894      // openFileDialog
     
    124120      this.instancesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    125121      this.instancesComboBox.FormattingEnabled = true;
    126       this.instancesComboBox.Location = new System.Drawing.Point(137, 1);
     122      this.instancesComboBox.Location = new System.Drawing.Point(105, 2);
    127123      this.instancesComboBox.Name = "instancesComboBox";
    128       this.instancesComboBox.Size = new System.Drawing.Size(326, 21);
     124      this.instancesComboBox.Size = new System.Drawing.Size(358, 21);
    129125      this.instancesComboBox.TabIndex = 7;
    130126      this.instancesComboBox.SelectedValueChanged += new System.EventHandler(this.instancesComboBox_SelectedValueChanged);
     
    188184      this.qapView.Weights = null;
    189185      //
    190       // reloadInstancesButton
    191       //
    192       this.reloadInstancesButton.Location = new System.Drawing.Point(105, 0);
    193       this.reloadInstancesButton.Name = "reloadInstancesButton";
    194       this.reloadInstancesButton.Size = new System.Drawing.Size(26, 23);
    195       this.reloadInstancesButton.TabIndex = 9;
    196       this.reloadInstancesButton.Text = "Reload";
    197       this.reloadInstancesButton.UseVisualStyleBackColor = true;
    198       this.reloadInstancesButton.Click += new System.EventHandler(this.reloadInstancesButton_Click);
    199       //
    200       // loadInstanceWorker
    201       //
    202       this.loadInstanceWorker.WorkerReportsProgress = true;
    203       this.loadInstanceWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.loadInstanceWorker_DoWork);
    204       this.loadInstanceWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.worker_ProgressChanged);
    205       this.loadInstanceWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.worker_RunWorkerCompleted);
    206       //
    207       // progressBar
    208       //
    209       this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    210                   | System.Windows.Forms.AnchorStyles.Right)));
    211       this.progressBar.Location = new System.Drawing.Point(137, 0);
    212       this.progressBar.Name = "progressBar";
    213       this.progressBar.Size = new System.Drawing.Size(326, 23);
    214       this.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
    215       this.progressBar.TabIndex = 10;
    216       this.progressBar.Visible = false;
    217       //
    218       // getInstancesWorker
    219       //
    220       this.getInstancesWorker.WorkerReportsProgress = true;
    221       this.getInstancesWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.getInstancesWorker_DoWork);
    222       this.getInstancesWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.worker_ProgressChanged);
    223       this.getInstancesWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.worker_RunWorkerCompleted);
    224       //
    225186      // QuadraticAssignmentProblemView
    226187      //
    227188      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    228189      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    229       this.Controls.Add(this.progressBar);
    230190      this.Controls.Add(this.instancesComboBox);
    231191      this.Controls.Add(this.tabControl);
    232192      this.Controls.Add(this.importInstanceButton);
    233193      this.Controls.Add(this.loadInstanceButton);
    234       this.Controls.Add(this.reloadInstancesButton);
    235194      this.Controls.Add(this.QAPLIBInstancesLabel);
    236195      this.Name = "QuadraticAssignmentProblemView";
    237196      this.Size = new System.Drawing.Size(647, 492);
    238197      this.Controls.SetChildIndex(this.QAPLIBInstancesLabel, 0);
    239       this.Controls.SetChildIndex(this.reloadInstancesButton, 0);
    240198      this.Controls.SetChildIndex(this.loadInstanceButton, 0);
    241199      this.Controls.SetChildIndex(this.importInstanceButton, 0);
     
    246204      this.Controls.SetChildIndex(this.nameLabel, 0);
    247205      this.Controls.SetChildIndex(this.nameTextBox, 0);
    248       this.Controls.SetChildIndex(this.progressBar, 0);
    249206      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    250207      this.tabControl.ResumeLayout(false);
     
    266223    private System.Windows.Forms.TabPage visualizationTabPage;
    267224    private QAPVisualizationControl qapView;
    268     private System.Windows.Forms.Button reloadInstancesButton;
    269     private System.ComponentModel.BackgroundWorker loadInstanceWorker;
    270     private System.Windows.Forms.ProgressBar progressBar;
    271     private System.ComponentModel.BackgroundWorker getInstancesWorker;
    272225  }
    273226}
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.cs

    r6891 r6952  
    2121
    2222using System;
    23 using System.ComponentModel;
    2423using System.Drawing;
    25 using System.Linq;
     24using System.IO;
    2625using System.Windows.Forms;
    2726using HeuristicLab.Common.Resources;
    28 using HeuristicLab.Core;
    2927using HeuristicLab.Core.Views;
    30 using HeuristicLab.Data;
    31 using HeuristicLab.Encodings.PermutationEncoding;
    3228using HeuristicLab.MainForm;
    3329using HeuristicLab.MainForm.WindowsForms;
    34 using HeuristicLab.Problems.QuadraticAssignment.QAPInstanceService;
    3530
    3631namespace HeuristicLab.Problems.QuadraticAssignment.Views {
     
    4641      InitializeComponent();
    4742      importInstanceButton.Image = VSImageLibrary.Open;
    48       reloadInstancesButton.Text = String.Empty;
    49       reloadInstancesButton.Image = VSImageLibrary.Refresh;
    50       loadInstanceButton.Image = VSImageLibrary.Internet;
    5143      Controls.Remove(parameterCollectionView);
    5244      parameterCollectionView.Dock = DockStyle.Fill;
     
    5951      Content.WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged);
    6052      Content.BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
    61       Content.Instances.ItemsAdded += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    62       Content.Instances.ItemsMoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    63       Content.Instances.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    64       Content.Instances.ItemsReplaced += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    65       Content.Instances.CollectionReset += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    6653    }
    6754
     
    7057      Content.WeightsParameter.ValueChanged -= new EventHandler(WeightsParameter_ValueChanged);
    7158      Content.BestKnownSolutionParameter.ValueChanged -= new EventHandler(BestKnownSolutionParameter_ValueChanged);
    72       Content.Instances.ItemsAdded -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    73       Content.Instances.ItemsMoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    74       Content.Instances.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    75       Content.Instances.ItemsReplaced -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    76       Content.Instances.CollectionReset -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<string>>(Content_Instances_Changed);
    7759      base.DeregisterContentEvents();
    78     }
    79 
    80     private void Content_Instances_Changed(object sender, EventArgs e) {
    81       instancesComboBox.Items.Clear();
    82       foreach (string name in Content.Instances)
    83         instancesComboBox.Items.Add(name);
    84       if (instancesComboBox.Items.Count > 0)
    85         instancesComboBox.SelectedIndex = 0;
    8660    }
    8761
     
    10074    protected override void OnContentChanged() {
    10175      base.OnContentChanged();
     76      instancesComboBox.Items.Clear();
    10277      if (Content != null) {
     78        foreach (string instance in Content.Instances) {
     79          instancesComboBox.Items.Add(instance);
     80        }
    10381        qapView.Distances = Content.Distances;
    10482        qapView.Weights = Content.Weights;
     
    11391    protected override void SetEnabledStateOfControls() {
    11492      base.SetEnabledStateOfControls();
    115       reloadInstancesButton.Enabled = !ReadOnly && !Locked && Content != null;
    11693      instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null;
    117       loadInstanceButton.Enabled = !ReadOnly && !Locked && Content != null && !String.IsNullOrEmpty((string)instancesComboBox.SelectedItem);
     94      loadInstanceButton.Enabled = !ReadOnly && !Locked && Content != null && instancesComboBox.SelectedItem != null;
    11895      importInstanceButton.Enabled = !ReadOnly && !Locked && Content != null;
    11996    }
    12097
    12198    private void instancesComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
    122       SetEnabledStateOfControls();
     99      loadInstanceButton.Enabled = instancesComboBox.SelectedItem != null;
    123100    }
    124101
    125102    private void loadInstanceButton_Click(object sender, System.EventArgs e) {
    126       ReadOnly = true;
    127       string instanceStr = instancesComboBox.SelectedItem as string;
    128       progressBar.Visible = true;
    129       loadInstanceWorker.RunWorkerAsync(instanceStr);
     103      string instance = instancesComboBox.SelectedItem as string;
     104      try {
     105        Content.LoadInstanceFromEmbeddedResource(instance);
     106      } catch (Exception ex) {
     107        PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
     108      }
    130109    }
    131110
    132     private void importFileInstanceButton_Click(object sender, System.EventArgs e) {
     111    private void importInstanceButton_Click(object sender, System.EventArgs e) {
    133112      if (openFileDialog.ShowDialog() == DialogResult.OK) {
    134113        try {
    135           Content.LoadInstanceFromFile(openFileDialog.FileName);
     114          string datFile = openFileDialog.FileName;
     115          string directory = Path.GetDirectoryName(datFile);
     116          string solFile = Path.Combine(directory, Path.GetFileNameWithoutExtension(datFile) + ".sln");
     117          if (File.Exists(solFile)) {
     118            Content.LoadInstanceFromFile(datFile, solFile);
     119          } else {
     120            Content.LoadInstanceFromFile(datFile);
     121          }
    136122        } catch (Exception ex) {
    137123          PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex);
    138124        }
    139125      }
    140     }
    141 
    142     private void reloadInstancesButton_Click(object sender, EventArgs e) {
    143       ReadOnly = true;
    144       progressBar.Visible = true;
    145       getInstancesWorker.RunWorkerAsync();
    146     }
    147 
    148     private void loadInstanceWorker_DoWork(object sender, DoWorkEventArgs e) {
    149       string instance = (string)e.Argument;
    150       if (String.IsNullOrEmpty(instance)) return;
    151       using (var client = new QAPClient()) {
    152         loadInstanceWorker.ReportProgress(10);
    153         var data = client.GetProblemInstanceData(instance);
    154         loadInstanceWorker.ReportProgress(60);
    155         DoubleMatrix weights = new DoubleMatrix(data.Weights.Length, data.Weights.Length);
    156         DoubleMatrix distances = new DoubleMatrix(data.Weights.Length, data.Weights.Length);
    157         try {
    158           for (int i = 0; i < data.Weights.Length; i++)
    159             for (int j = 0; j < data.Weights.Length; j++) {
    160               weights[i, j] = data.Weights[i][j];
    161               distances[i, j] = data.Distances[i][j];
    162             }
    163         } catch (IndexOutOfRangeException) {
    164           MessageBox.Show("The problem data is malformed, the problem could not be loaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    165         }
    166         loadInstanceWorker.ReportProgress(65);
    167         Content.Name = data.Name;
    168         Content.Description = data.Description;
    169         Content.Maximization.Value = data.Maximization;
    170         Content.Weights = weights;
    171         Content.Distances = distances;
    172 
    173         Content.BestKnownQualityParameter.Value = null;
    174         Content.BestKnownSolution = null;
    175         Content.BestKnownSolutions = new ItemSet<Permutation>();
    176         var solutions = client.GetBestSolutionsData(instance);
    177         loadInstanceWorker.ReportProgress(90);
    178         if (solutions.Any()) {
    179           Content.BestKnownQualityParameter.Value = new DoubleValue(solutions.First().Quality);
    180           Content.BestKnownSolution = new Permutation(PermutationTypes.Absolute, solutions.First().Assignment);
    181           foreach (var solution in solutions) {
    182             Content.BestKnownSolutions.Add(new Permutation(PermutationTypes.Absolute, solution.Assignment));
    183           }
    184         }
    185         loadInstanceWorker.ReportProgress(100);
    186       }
    187     }
    188 
    189     private void getInstancesWorker_DoWork(object sender, DoWorkEventArgs e) {
    190       using (var client = new QAPClient()) {
    191         getInstancesWorker.ReportProgress(10);
    192         var instances = client.GetProblemInstances();
    193         getInstancesWorker.ReportProgress(85);
    194         Content.Instances.Replace(instances);
    195         getInstancesWorker.ReportProgress(100);
    196       }
    197     }
    198 
    199     private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) {
    200       progressBar.Value = e.ProgressPercentage;
    201     }
    202 
    203     private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    204       progressBar.Visible = false;
    205       ReadOnly = false;
    206       if (e.Error != null)
    207         PluginInfrastructure.ErrorHandling.ShowErrorDialog(e.Error);
    208126    }
    209127
Note: See TracChangeset for help on using the changeset viewer.