- Timestamp:
- 11/06/11 20:47:56 (12 years ago)
- 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 212 212 </ProjectReference> 213 213 </ItemGroup> 214 <ItemGroup>215 <WCFMetadata Include="Service References\" />216 </ItemGroup>217 214 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 218 215 <PropertyGroup> -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.Designer.cs
r6891 r6952 54 54 this.visualizationTabPage = new System.Windows.Forms.TabPage(); 55 55 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();60 56 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 61 57 this.tabControl.SuspendLayout(); … … 94 90 this.toolTip.SetToolTip(this.importInstanceButton, "Import files in QAPLIB format."); 95 91 this.importInstanceButton.UseVisualStyleBackColor = true; 96 this.importInstanceButton.Click += new System.EventHandler(this.import FileInstanceButton_Click);92 this.importInstanceButton.Click += new System.EventHandler(this.importInstanceButton_Click); 97 93 // 98 94 // openFileDialog … … 124 120 this.instancesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 125 121 this.instancesComboBox.FormattingEnabled = true; 126 this.instancesComboBox.Location = new System.Drawing.Point(1 37, 1);122 this.instancesComboBox.Location = new System.Drawing.Point(105, 2); 127 123 this.instancesComboBox.Name = "instancesComboBox"; 128 this.instancesComboBox.Size = new System.Drawing.Size(3 26, 21);124 this.instancesComboBox.Size = new System.Drawing.Size(358, 21); 129 125 this.instancesComboBox.TabIndex = 7; 130 126 this.instancesComboBox.SelectedValueChanged += new System.EventHandler(this.instancesComboBox_SelectedValueChanged); … … 188 184 this.qapView.Weights = null; 189 185 // 190 // reloadInstancesButton191 //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 // loadInstanceWorker201 //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 // progressBar208 //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 // getInstancesWorker219 //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 //225 186 // QuadraticAssignmentProblemView 226 187 // 227 188 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 228 189 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 229 this.Controls.Add(this.progressBar);230 190 this.Controls.Add(this.instancesComboBox); 231 191 this.Controls.Add(this.tabControl); 232 192 this.Controls.Add(this.importInstanceButton); 233 193 this.Controls.Add(this.loadInstanceButton); 234 this.Controls.Add(this.reloadInstancesButton);235 194 this.Controls.Add(this.QAPLIBInstancesLabel); 236 195 this.Name = "QuadraticAssignmentProblemView"; 237 196 this.Size = new System.Drawing.Size(647, 492); 238 197 this.Controls.SetChildIndex(this.QAPLIBInstancesLabel, 0); 239 this.Controls.SetChildIndex(this.reloadInstancesButton, 0);240 198 this.Controls.SetChildIndex(this.loadInstanceButton, 0); 241 199 this.Controls.SetChildIndex(this.importInstanceButton, 0); … … 246 204 this.Controls.SetChildIndex(this.nameLabel, 0); 247 205 this.Controls.SetChildIndex(this.nameTextBox, 0); 248 this.Controls.SetChildIndex(this.progressBar, 0);249 206 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 250 207 this.tabControl.ResumeLayout(false); … … 266 223 private System.Windows.Forms.TabPage visualizationTabPage; 267 224 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;272 225 } 273 226 } -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.cs
r6891 r6952 21 21 22 22 using System; 23 using System.ComponentModel;24 23 using System.Drawing; 25 using System. Linq;24 using System.IO; 26 25 using System.Windows.Forms; 27 26 using HeuristicLab.Common.Resources; 28 using HeuristicLab.Core;29 27 using HeuristicLab.Core.Views; 30 using HeuristicLab.Data;31 using HeuristicLab.Encodings.PermutationEncoding;32 28 using HeuristicLab.MainForm; 33 29 using HeuristicLab.MainForm.WindowsForms; 34 using HeuristicLab.Problems.QuadraticAssignment.QAPInstanceService;35 30 36 31 namespace HeuristicLab.Problems.QuadraticAssignment.Views { … … 46 41 InitializeComponent(); 47 42 importInstanceButton.Image = VSImageLibrary.Open; 48 reloadInstancesButton.Text = String.Empty;49 reloadInstancesButton.Image = VSImageLibrary.Refresh;50 loadInstanceButton.Image = VSImageLibrary.Internet;51 43 Controls.Remove(parameterCollectionView); 52 44 parameterCollectionView.Dock = DockStyle.Fill; … … 59 51 Content.WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged); 60 52 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);66 53 } 67 54 … … 70 57 Content.WeightsParameter.ValueChanged -= new EventHandler(WeightsParameter_ValueChanged); 71 58 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);77 59 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;86 60 } 87 61 … … 100 74 protected override void OnContentChanged() { 101 75 base.OnContentChanged(); 76 instancesComboBox.Items.Clear(); 102 77 if (Content != null) { 78 foreach (string instance in Content.Instances) { 79 instancesComboBox.Items.Add(instance); 80 } 103 81 qapView.Distances = Content.Distances; 104 82 qapView.Weights = Content.Weights; … … 113 91 protected override void SetEnabledStateOfControls() { 114 92 base.SetEnabledStateOfControls(); 115 reloadInstancesButton.Enabled = !ReadOnly && !Locked && Content != null;116 93 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; 118 95 importInstanceButton.Enabled = !ReadOnly && !Locked && Content != null; 119 96 } 120 97 121 98 private void instancesComboBox_SelectedValueChanged(object sender, System.EventArgs e) { 122 SetEnabledStateOfControls();99 loadInstanceButton.Enabled = instancesComboBox.SelectedItem != null; 123 100 } 124 101 125 102 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 } 130 109 } 131 110 132 private void import FileInstanceButton_Click(object sender, System.EventArgs e) {111 private void importInstanceButton_Click(object sender, System.EventArgs e) { 133 112 if (openFileDialog.ShowDialog() == DialogResult.OK) { 134 113 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 } 136 122 } catch (Exception ex) { 137 123 PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex); 138 124 } 139 125 } 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);208 126 } 209 127
Note: See TracChangeset
for help on using the changeset viewer.