Changeset 7548
- Timestamp:
- 03/05/12 16:30:27 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 13 added
- 11 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.csproj
r7483 r7548 89 89 </ItemGroup> 90 90 <ItemGroup> 91 <Compile Include="ToolTipComboBox.cs">92 <SubType>Component</SubType>93 </Compile>94 <Compile Include="ToolTipComboBox.Designer.cs">95 <DependentUpon>ToolTipComboBox.cs</DependentUpon>96 </Compile>97 <Compile Include="ToolTipRequiredEventArgs.cs" />98 91 <Compile Include="ProblemInstanceProviderView.cs"> 99 92 <SubType>UserControl</SubType> … … 139 132 </ItemGroup> 140 133 <ItemGroup> 141 <EmbeddedResource Include="ToolTipComboBox.resx">142 <DependentUpon>ToolTipComboBox.cs</DependentUpon>143 </EmbeddedResource>144 134 <EmbeddedResource Include="ProblemInstanceProviderView.resx"> 145 135 <DependentUpon>ProblemInstanceProviderView.cs</DependentUpon> -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.Designer.cs
r7538 r7548 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.components = new System.ComponentModel.Container(); 47 48 this.loadButton = new System.Windows.Forms.Button(); 48 49 this.label2 = new System.Windows.Forms.Label(); … … 50 51 this.importButton = new System.Windows.Forms.Button(); 51 52 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 53 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 52 54 this.SuspendLayout(); 53 55 // … … 55 57 // 56 58 this.loadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 57 this.loadButton.Location = new System.Drawing.Point( 451, -1);59 this.loadButton.Location = new System.Drawing.Point(549, -1); 58 60 this.loadButton.Name = "loadButton"; 59 this.loadButton.Size = new System.Drawing.Size( 75, 23);61 this.loadButton.Size = new System.Drawing.Size(26, 23); 60 62 this.loadButton.TabIndex = 6; 61 63 this.loadButton.Text = "Load"; … … 80 82 this.instancesComboBox.Location = new System.Drawing.Point(54, 0); 81 83 this.instancesComboBox.Name = "instancesComboBox"; 82 this.instancesComboBox.Size = new System.Drawing.Size( 391, 21);84 this.instancesComboBox.Size = new System.Drawing.Size(489, 21); 83 85 this.instancesComboBox.TabIndex = 7; 84 86 this.instancesComboBox.DataSourceChanged += new System.EventHandler(this.comboBox_DataSourceChanged); … … 87 89 // 88 90 this.importButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 89 this.importButton.Location = new System.Drawing.Point(5 32, -1);91 this.importButton.Location = new System.Drawing.Point(581, -1); 90 92 this.importButton.Name = "importButton"; 91 this.importButton.Size = new System.Drawing.Size( 75, 23);93 this.importButton.Size = new System.Drawing.Size(26, 23); 92 94 this.importButton.TabIndex = 6; 93 95 this.importButton.Text = "Import"; … … 122 124 private System.Windows.Forms.Button importButton; 123 125 private System.Windows.Forms.OpenFileDialog openFileDialog; 126 private System.Windows.Forms.ToolTip toolTip; 124 127 125 128 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs
r7538 r7548 21 21 22 22 using System; 23 using System.IO; 23 24 using System.Linq; 24 25 using System.Windows.Forms; … … 40 41 public ProblemInstanceProviderView() { 41 42 InitializeComponent(); 43 importButton.Text = String.Empty; 42 44 importButton.Image = VSImageLibrary.Open; 45 toolTip.SetToolTip(importButton, "Import a " + GetProblemType() + " instance from file."); 46 loadButton.Text = String.Empty; 47 loadButton.Image = VSImageLibrary.Checkout; 48 toolTip.SetToolTip(loadButton, "Load the selected instance."); 43 49 } 44 50 … … 49 55 } else { 50 56 instancesComboBox.DisplayMember = "Name"; 51 instancesComboBox.DataSource = Content.Get InstanceDescriptors().ToList();57 instancesComboBox.DataSource = Content.GetDataDescriptors().ToList(); 52 58 } 53 59 } … … 60 66 61 67 private void loadButton_Click(object sender, EventArgs e) { 62 var descriptor = (IInstanceDescriptor)instancesComboBox.SelectedItem; 63 var instance = Content.LoadInstance(descriptor); 64 if (!Content.Consumer.LoadFrom(instance)) { 65 MessageBox.Show("This problem does not support loading the instance " + descriptor.Name + ".", "Cannot load instance"); 68 var descriptor = (IDataDescriptor)instancesComboBox.SelectedItem; 69 var instance = Content.LoadData(descriptor); 70 try { 71 Content.Consumer.Load(instance); 72 } catch (Exception ex) { 73 MessageBox.Show(String.Format("This problem does not support loading the instance {0}: {1}", descriptor.Name, Environment.NewLine + ex.Message), "Cannot load instance"); 66 74 } 67 75 } 68 76 69 77 private void importButton_Click(object sender, EventArgs e) { 78 openFileDialog.FileName = GetProblemType() + " instance"; 70 79 if (openFileDialog.ShowDialog() == DialogResult.OK) { 71 80 T instance = default(T); 72 81 try { 73 instance = Content.Load Instance(openFileDialog.FileName);74 } catch {75 MessageBox.Show( "There was an error parsing the file.", "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);82 instance = Content.LoadData(openFileDialog.FileName); 83 } catch (Exception ex) { 84 MessageBox.Show(String.Format("There was an error parsing the file: {0}", Environment.NewLine + ex.Message), "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error); 76 85 return; 77 86 } 78 87 try { 79 if (!Content.Consumer.LoadFrom(instance)) { 80 MessageBox.Show("This problem does not support loading the instance in the file.", "Cannot load instance", MessageBoxButtons.OK, MessageBoxIcon.Error); 81 } 82 } catch { 83 MessageBox.Show("There was an error while importing the file."); 88 Content.Consumer.Load(instance); 89 } catch (Exception ex) { 90 MessageBox.Show(String.Format("This problem does not support loading the instance {0}: {1}", Path.GetFileName(openFileDialog.FileName), Environment.NewLine + ex.Message), "Cannot load instance"); 84 91 } 85 92 } … … 91 98 comboBox.Items.Clear(); 92 99 } 100 101 private string GetProblemType() { 102 string dataTypeName = typeof(T).Name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Last(); 103 if (dataTypeName.EndsWith("Data")) 104 return dataTypeName.Substring(0, dataTypeName.Length - "Data".Length); 105 else return dataTypeName; 106 } 93 107 } 94 108 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.resx
r7538 r7548 121 121 <value>17, 17</value> 122 122 </metadata> 123 <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 124 <value>150, 17</value> 125 </metadata> 123 126 </root> -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.Designer.cs
r7538 r7548 47 47 this.label1 = new System.Windows.Forms.Label(); 48 48 this.problemInstanceProviderViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 49 this.problemInstanceProviderComboBox = new HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views.ToolTipComboBox(); 49 this.problemInstanceProviderComboBox = new System.Windows.Forms.ComboBox(); 50 this.libraryInfoButton = new System.Windows.Forms.Button(); 50 51 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 51 52 this.SuspendLayout(); … … 93 94 this.problemInstanceProviderViewHost.Content = null; 94 95 this.problemInstanceProviderViewHost.Enabled = false; 95 this.problemInstanceProviderViewHost.Location = new System.Drawing.Point(2 29, 5);96 this.problemInstanceProviderViewHost.Location = new System.Drawing.Point(259, 5); 96 97 this.problemInstanceProviderViewHost.Name = "problemInstanceProviderViewHost"; 97 98 this.problemInstanceProviderViewHost.ReadOnly = false; 98 this.problemInstanceProviderViewHost.Size = new System.Drawing.Size( 421, 21);99 this.problemInstanceProviderViewHost.Size = new System.Drawing.Size(391, 21); 99 100 this.problemInstanceProviderViewHost.TabIndex = 6; 100 101 this.problemInstanceProviderViewHost.ViewsLabelVisible = false; … … 103 104 // problemInstanceProviderComboBox 104 105 // 105 this.problemInstanceProviderComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;106 106 this.problemInstanceProviderComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 107 this.problemInstanceProviderComboBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));108 107 this.problemInstanceProviderComboBox.FormattingEnabled = true; 109 108 this.problemInstanceProviderComboBox.Location = new System.Drawing.Point(50, 5); 110 this.problemInstanceProviderComboBox.MaxDropDownItems = 16;111 109 this.problemInstanceProviderComboBox.Name = "problemInstanceProviderComboBox"; 112 this.problemInstanceProviderComboBox.Size = new System.Drawing.Size(17 3, 21);110 this.problemInstanceProviderComboBox.Size = new System.Drawing.Size(171, 21); 113 111 this.problemInstanceProviderComboBox.TabIndex = 7; 114 this.problemInstanceProviderComboBox.ToolTipRequired += new System.EventHandler<HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views.ToolTipRequiredEventArgs>(this.problemInstanceProviderComboBox_ToolTipRequired);115 112 this.problemInstanceProviderComboBox.SelectedIndexChanged += new System.EventHandler(this.problemInstanceProviderComboBox_SelectedIndexChanged); 116 113 this.problemInstanceProviderComboBox.DataSourceChanged += new System.EventHandler(this.comboBox_DataSourceChanged); 114 // 115 // libraryInfoButton 116 // 117 this.libraryInfoButton.Location = new System.Drawing.Point(227, 4); 118 this.libraryInfoButton.Name = "libraryInfoButton"; 119 this.libraryInfoButton.Size = new System.Drawing.Size(26, 23); 120 this.libraryInfoButton.TabIndex = 8; 121 this.libraryInfoButton.Text = "Info"; 122 this.libraryInfoButton.UseVisualStyleBackColor = true; 123 this.libraryInfoButton.Click += new System.EventHandler(this.libraryInfoButton_Click); 117 124 // 118 125 // ProblemView … … 123 130 this.Controls.Add(this.problemInstanceProviderComboBox); 124 131 this.Controls.Add(this.label1); 132 this.Controls.Add(this.libraryInfoButton); 125 133 this.Name = "ProblemView"; 126 134 this.Size = new System.Drawing.Size(653, 455); 135 this.Controls.SetChildIndex(this.libraryInfoButton, 0); 136 this.Controls.SetChildIndex(this.label1, 0); 137 this.Controls.SetChildIndex(this.problemInstanceProviderComboBox, 0); 138 this.Controls.SetChildIndex(this.problemInstanceProviderViewHost, 0); 127 139 this.Controls.SetChildIndex(this.infoLabel, 0); 128 this.Controls.SetChildIndex(this.label1, 0);129 140 this.Controls.SetChildIndex(this.nameTextBox, 0); 130 141 this.Controls.SetChildIndex(this.nameLabel, 0); 131 this.Controls.SetChildIndex(this.problemInstanceProviderComboBox, 0);132 this.Controls.SetChildIndex(this.problemInstanceProviderViewHost, 0);133 142 this.Controls.SetChildIndex(this.parameterCollectionView, 0); 134 143 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); … … 142 151 private System.Windows.Forms.Label label1; 143 152 private MainForm.WindowsForms.ViewHost problemInstanceProviderViewHost; 144 private ToolTipComboBox problemInstanceProviderComboBox; 153 private System.Windows.Forms.ComboBox problemInstanceProviderComboBox; 154 private System.Windows.Forms.Button libraryInfoButton; 145 155 146 156 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.cs
r7539 r7548 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics; 24 25 using System.Linq; 25 26 using System.Reflection; 26 27 using System.Windows.Forms; 28 using HeuristicLab.Common.Resources; 27 29 using HeuristicLab.Core.Views; 28 30 using HeuristicLab.MainForm; … … 42 44 } 43 45 46 private IProblemInstanceProvider SelectedProvider { 47 get { return (problemInstanceProviderComboBox.SelectedIndex >= 0 ? (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem : null); } 48 } 49 44 50 public ProblemView() { 45 51 InitializeComponent(); 52 libraryInfoButton.Text = String.Empty; 53 libraryInfoButton.Image = VSImageLibrary.Information; 46 54 } 47 55 … … 54 62 problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList(); 55 63 } 64 SetEnabledStateOfControls(); 56 65 } 57 66 58 67 protected override void SetEnabledStateOfControls() { 59 68 base.SetEnabledStateOfControls(); 60 problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null; 69 problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null && problemInstanceProviderComboBox.Items.Count > 0; 70 libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null; 61 71 } 62 72 63 73 private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) { 64 74 if (problemInstanceProviderComboBox.SelectedIndex >= 0) { 65 var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem; 66 var genericType = provider.GetType().GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IProblemInstanceProvider<>)).GetGenericArguments().First(); 75 var genericType = SelectedProvider.GetType().GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IProblemInstanceProvider<>)).GetGenericArguments().First(); 67 76 this.GetType().GetMethod("SetConsumable", BindingFlags.NonPublic | BindingFlags.Instance) 68 .MakeGenericMethod(genericType).Invoke(this, new object[] { provider, Content }); 69 problemInstanceProviderViewHost.Content = provider; 77 .MakeGenericMethod(genericType).Invoke(this, new object[] { SelectedProvider, Content }); 78 problemInstanceProviderViewHost.Content = SelectedProvider; 79 SetTooltip(); 70 80 } 81 SetEnabledStateOfControls(); 71 82 } 72 83 73 /// <summary> 74 /// Do not change method name without changing the string reference above 75 /// </summary> 76 private void SetConsumable<T>(IProblemInstanceProvider<T> producer, IConsumable<T> consumer) { 84 // Do not change method without changing the reflection call above 85 [Obsolete] 86 private void SetConsumable<T>(IProblemInstanceProvider<T> producer, IProblemInstanceConsumer<T> consumer) { 77 87 producer.Consumer = consumer; 78 88 } … … 84 94 } 85 95 96 private void libraryInfoButton_Click(object sender, EventArgs e) { 97 if (problemInstanceProviderComboBox.SelectedIndex >= 0) { 98 if (SelectedProvider != null && SelectedProvider.WebLink != null) 99 Process.Start(SelectedProvider.WebLink.ToString()); 100 } 101 } 102 86 103 protected virtual IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() { 87 104 var consumerTypes = Content.GetType().GetInterfaces() 88 105 .Where(x => x.IsGenericType 89 && x.GetGenericTypeDefinition() == typeof(I Consumable<>));106 && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>)); 90 107 91 108 if (consumerTypes.Any()) { … … 101 118 } 102 119 103 protected virtual string GetProviderToolTip(IProblemInstanceProvider provider) { 104 if (provider.WebLink != null) { 105 return provider.Name 106 + Environment.NewLine 107 + provider.WebLink.ToString() 108 + Environment.NewLine + Environment.NewLine 109 + provider.ReferencePublication; 110 } else { 111 return provider.Name 120 private void SetTooltip() { 121 toolTip.SetToolTip(problemInstanceProviderComboBox, GetProviderToolTip()); 122 if (SelectedProvider.WebLink != null) 123 toolTip.SetToolTip(libraryInfoButton, "Browse to " + SelectedProvider.WebLink.ToString()); 124 else toolTip.SetToolTip(libraryInfoButton, "Library does not have a web reference."); 125 } 126 127 protected virtual string GetProviderToolTip() { 128 var provider = SelectedProvider; 129 string toolTip = provider.Name; 130 131 if (!String.IsNullOrEmpty(provider.ReferencePublication)) { 132 toolTip = toolTip 112 133 + Environment.NewLine + Environment.NewLine 113 134 + provider.ReferencePublication; 114 135 } 115 } 136 if (provider.WebLink != null) { 137 toolTip = toolTip 138 + Environment.NewLine 139 + provider.WebLink.ToString(); 140 } 116 141 117 private void problemInstanceProviderComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) { 118 e.ToolTip = GetProviderToolTip((IProblemInstanceProvider)e.Item); 142 return toolTip; 119 143 } 120 144 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.resx
r7482 r7548 121 121 <value>107, 17</value> 122 122 </metadata> 123 <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 124 <value>107, 17</value> 125 </metadata> 123 126 <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 124 127 <value>17, 17</value> -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs
r7538 r7548 39 39 [StorableClass] 40 40 public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent, 41 I Consumable<QAPInstance>,42 I Consumable<CTAPInstance>,43 I Consumable<TSPInstance>,44 I Consumable<ATSPInstance>,45 I Consumable<GQAPInstance> {41 IProblemInstanceConsumer<QAPData>, 42 IProblemInstanceConsumer<CTAPData>, 43 IProblemInstanceConsumer<TSPData>, 44 IProblemInstanceConsumer<ATSPData>, 45 IProblemInstanceConsumer<GQAPData> { 46 46 47 47 public override Image ItemImage { … … 169 169 Parameters.Add(new ValueParameter<DoubleMatrix>("InstallationCosts", InstallationCostsDescription, new DoubleMatrix(), false)); 170 170 Parameters.Add(new FixedValueParameter<DoubleValue>("TransportationCosts", TransportationCostsDescription, new DoubleValue(1))); 171 Parameters.Add(new FixedValueParameter<DoubleValue>("OverbookedCapacityPenalty", OverbookedCapacityPenaltyDescription, new DoubleValue(1000 )));171 Parameters.Add(new FixedValueParameter<DoubleValue>("OverbookedCapacityPenalty", OverbookedCapacityPenaltyDescription, new DoubleValue(100000))); 172 172 Parameters.Add(new ValueParameter<DoubleArray>("Demands", DemandsDescription, new DoubleArray(), false)); 173 173 Parameters.Add(new ValueParameter<DoubleArray>("Capacities", CapacitiesDescription, new DoubleArray(), false)); … … 213 213 } 214 214 215 #region Problem Instance Consumptions 216 public bool LoadFrom(QAPInstance instance) { 217 try { 218 Name = instance.Name; 219 Description = instance.Description; 220 221 Weights = new DoubleMatrix(instance.Weights); 222 Distances = new DoubleMatrix(instance.Distances); 223 InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); // all zero 224 Capacities = new DoubleArray(Enumerable.Range(0, Distances.Rows).Select(x => 1.0).ToArray()); 225 Demands = new DoubleArray(Enumerable.Range(0, Weights.Rows).Select(x => 1.0).ToArray()); 226 227 TransportationCosts.Value = 1; 228 229 if (instance.BestKnownAssignment != null) { 230 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 231 } else { 232 BestKnownQuality = null; 233 BestKnownSolution = null; 234 BestKnownSolutions = null; 215 #region Problem Instance Loading 216 public void Load(QAPData data) { 217 Name = data.Name; 218 Description = data.Description; 219 220 var weights = new DoubleMatrix(data.Weights); 221 var distances = new DoubleMatrix(data.Distances); 222 var installationCosts = new DoubleMatrix(weights.Rows, distances.Columns); // all zero 223 var capacities = new DoubleArray(Enumerable.Range(0, distances.Rows).Select(x => 1.0).ToArray()); 224 var demands = new DoubleArray(Enumerable.Range(0, weights.Rows).Select(x => 1.0).ToArray()); 225 226 Load(demands, capacities, weights, distances, installationCosts, new DoubleValue(1)); 227 EvaluateAndLoadAssignment(data.BestKnownAssignment); 228 } 229 230 public void Load(CTAPData data) { 231 Name = data.Name; 232 Description = data.Description; 233 234 var capacities = new DoubleArray(data.MemoryCapacities); 235 var demands = new DoubleArray(data.MemoryRequirements); 236 var weights = new DoubleMatrix(data.CommunicationCosts); 237 var installationCosts = new DoubleMatrix(data.ExecutionCosts.Transpose()); 238 var distances = new DoubleMatrix(capacities.Length, capacities.Length); 239 for (int i = 0; i < capacities.Length - 1; i++) 240 for (int j = i + 1; j < capacities.Length; j++) { 241 distances[i, j] = 1; 235 242 } 236 } catch { 237 return false; 238 } 239 return true; 240 } 241 242 public bool LoadFrom(CTAPInstance instance) { 243 try { 244 Name = instance.Name; 245 Description = instance.Description; 246 247 Capacities = new DoubleArray(instance.MemoryCapacities); 248 Demands = new DoubleArray(instance.MemoryRequirements); 249 Weights = new DoubleMatrix(instance.CommunicationCosts); 250 InstallationCosts = new DoubleMatrix(instance.ExecutionCosts.Transpose()); 251 Distances = new DoubleMatrix(Capacities.Length, Capacities.Length); 252 for (int i = 0; i < Capacities.Length - 1; i++) 253 for (int j = i + 1; j < Capacities.Length; j++) { 254 Distances[i, j] = 1; 255 } 256 257 TransportationCosts.Value = 1; 258 259 if (instance.BestKnownAssignment != null) { 260 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 261 } else { 262 BestKnownQuality = null; 263 BestKnownSolution = null; 264 BestKnownSolutions = null; 265 } 266 } catch { 267 return false; 268 } 269 return true; 270 } 271 272 public bool LoadFrom(TSPInstance instance) { 273 try { 274 if (instance.Dimension > 1000) return false; 275 276 Name = instance.Name; 277 Description = instance.Description; 278 279 Capacities = new DoubleArray(instance.Dimension); 280 Demands = new DoubleArray(instance.Dimension); 281 for (int i = 0; i < instance.Dimension; i++) { 282 Capacities[i] = 1; 283 Demands[i] = 1; 284 } 285 InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension); 286 Weights = new DoubleMatrix(instance.Dimension, instance.Dimension); 287 for (int i = 0; i < instance.Dimension; i++) 288 Weights[i, (i + 1) % instance.Dimension] = 1; 289 Distances = new DoubleMatrix(instance.GetDistanceMatrix()); 290 291 TransportationCosts.Value = 1; 292 293 if (instance.BestKnownTour != null) { 294 EvaluateAndLoadAssignment(instance.BestKnownTour); 295 } else { 296 BestKnownQuality = null; 297 BestKnownSolution = null; 298 BestKnownSolutions = null; 299 } 300 } catch { 301 return false; 302 } 303 return true; 304 } 305 306 public bool LoadFrom(ATSPInstance instance) { 307 try { 308 Name = instance.Name; 309 Description = instance.Description; 310 311 Capacities = new DoubleArray(instance.Dimension); 312 Demands = new DoubleArray(instance.Dimension); 313 for (int i = 0; i < instance.Dimension; i++) { 314 Capacities[i] = 1; 315 Demands[i] = 1; 316 } 317 InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension); 318 Weights = new DoubleMatrix(instance.Dimension, instance.Dimension); 319 for (int i = 0; i < instance.Dimension; i++) 320 Weights[i, (i + 1) % instance.Dimension] = 1; 321 Distances = new DoubleMatrix(instance.Distances); 322 323 TransportationCosts.Value = 1; 324 325 if (instance.BestKnownTour != null) { 326 EvaluateAndLoadAssignment(instance.BestKnownTour); 327 } else { 328 BestKnownQuality = null; 329 BestKnownSolution = null; 330 BestKnownSolutions = null; 331 } 332 } catch { 333 return false; 334 } 335 return true; 336 } 337 338 public bool LoadFrom(GQAPInstance instance) { 339 try { 340 Name = instance.Name; 341 Description = instance.Description; 342 343 Capacities = new DoubleArray(instance.Capacities); 344 Demands = new DoubleArray(instance.Demands); 345 InstallationCosts = new DoubleMatrix(instance.InstallationCosts); 346 Weights = new DoubleMatrix(instance.Weights); 347 Distances = new DoubleMatrix(instance.Distances); 348 TransportationCosts.Value = instance.TransportationCosts; 349 350 if (instance.BestKnownAssignment != null) { 351 EvaluateAndLoadAssignment(instance.BestKnownAssignment); 352 } else if (instance.BestKnownQuality.HasValue) { 353 BestKnownQuality = new DoubleValue(instance.BestKnownQuality.Value); 354 BestKnownSolution = null; 355 BestKnownSolutions = null; 356 } else { 357 BestKnownQuality = null; 358 BestKnownSolution = null; 359 BestKnownSolutions = null; 360 } 361 } catch { 362 return false; 363 } 364 return true; 365 } 366 #endregion 243 244 Load(demands, capacities, weights, distances, installationCosts, new DoubleValue(1)); 245 EvaluateAndLoadAssignment(data.BestKnownAssignment); 246 } 247 248 public void Load(TSPData data) { 249 if (data.Dimension > 1000) 250 throw new System.IO.InvalidDataException("Instances with more than 1000 cities are not supported."); 251 252 Name = data.Name; 253 Description = data.Description; 254 255 var capacities = new DoubleArray(data.Dimension); 256 var demands = new DoubleArray(data.Dimension); 257 for (int i = 0; i < data.Dimension; i++) { 258 capacities[i] = 1; 259 demands[i] = 1; 260 } 261 var installationCosts = new DoubleMatrix(data.Dimension, data.Dimension); 262 var weights = new DoubleMatrix(data.Dimension, data.Dimension); 263 for (int i = 0; i < data.Dimension; i++) 264 weights[i, (i + 1) % data.Dimension] = 1; 265 var distances = new DoubleMatrix(data.GetDistanceMatrix()); 266 267 Load(demands, capacities, weights, distances, installationCosts, new DoubleValue(1)); 268 EvaluateAndLoadAssignment(data.BestKnownTour); 269 } 270 271 public void Load(ATSPData data) { 272 Name = data.Name; 273 Description = data.Description; 274 275 var capacities = new DoubleArray(data.Dimension); 276 var demands = new DoubleArray(data.Dimension); 277 for (int i = 0; i < data.Dimension; i++) { 278 capacities[i] = 1; 279 demands[i] = 1; 280 } 281 var installationCosts = new DoubleMatrix(data.Dimension, data.Dimension); 282 var weights = new DoubleMatrix(data.Dimension, data.Dimension); 283 for (int i = 0; i < data.Dimension; i++) 284 weights[i, (i + 1) % data.Dimension] = 1; 285 var distances = new DoubleMatrix(data.Distances); 286 287 Load(demands, capacities, weights, distances, installationCosts, new DoubleValue(1)); 288 EvaluateAndLoadAssignment(data.BestKnownTour); 289 } 290 291 public void Load(GQAPData data) { 292 Name = data.Name; 293 Description = data.Description; 294 295 var capacities = new DoubleArray(data.Capacities); 296 var demands = new DoubleArray(data.Demands); 297 var installationCosts = new DoubleMatrix(data.InstallationCosts); 298 var weights = new DoubleMatrix(data.Weights); 299 var distances = new DoubleMatrix(data.Distances); 300 var transportationCosts = new DoubleValue(data.TransportationCosts); 301 302 Load(demands, capacities, weights, distances, installationCosts, transportationCosts); 303 EvaluateAndLoadAssignment(data.BestKnownAssignment); 304 305 if (data.BestKnownAssignment == null && data.BestKnownQuality.HasValue) { 306 BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value); 307 } 308 } 309 310 public void Load(DoubleArray demands, DoubleArray capacities, 311 DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 312 DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty = null) { 313 if (weights == null || weights.Rows == 0) 314 throw new System.IO.InvalidDataException( 315 @"The given instance does not contain weights!"); 316 if (weights.Rows != weights.Columns) 317 throw new System.IO.InvalidDataException( 318 @"The weights matrix of the given instance contains an unequal number of rows 319 and columns."); 320 Weights = weights; 321 322 if (distances == null || distances.Rows == 0) 323 throw new System.IO.InvalidDataException( 324 @"The given instance does not contain distances!"); 325 if (distances.Rows != distances.Columns) 326 throw new System.IO.InvalidDataException( 327 @"The distances matrix of the given instance contains an unequal number of rows 328 and columns."); 329 Distances = distances; 330 331 if (installationCosts == null || installationCosts.Rows == 0) 332 throw new System.IO.InvalidDataException( 333 @"The given instance does not contain installation costs!"); 334 if (installationCosts.Rows != weights.Rows 335 || installationCosts.Columns != distances.Columns) 336 throw new System.IO.InvalidDataException( 337 @"The installation costs matrix of the given instance contains different number 338 of rows than given in the weights matrix and a different number of columns than 339 given in the distances matrix."); 340 InstallationCosts = installationCosts; 341 342 if (capacities == null || capacities.Length == 0) 343 throw new System.IO.InvalidDataException( 344 @"The given instance does not contain capacities!"); 345 if (capacities.Length != distances.Rows) 346 throw new System.IO.InvalidDataException( 347 @"The given instance contains a different number of capacities than rows given in 348 the distances matrix."); 349 Capacities = capacities; 350 351 if (demands == null || demands.Length == 0) 352 throw new System.IO.InvalidDataException( 353 @"The given instance does not contain demands!"); 354 if (demands.Length != weights.Rows) 355 throw new System.IO.InvalidDataException( 356 @"The given instance contains a different number of demands than rows given in 357 the weights matrix."); 358 Demands = demands; 359 360 if (transportationCosts == null) 361 throw new System.IO.InvalidDataException( 362 @"The given instance does not contain transportation costs."); 363 TransportationCosts.Value = transportationCosts.Value; 364 365 if (overbookedCapacityPenalty != null) 366 OverbookedCapacityPenalty.Value = overbookedCapacityPenalty.Value; 367 368 BestKnownQuality = null; 369 BestKnownSolution = null; 370 BestKnownSolutions = null; 371 } 367 372 368 373 private void EvaluateAndLoadAssignment(int[] vector) { 374 if (vector == null || vector.Length == 0) return; 369 375 EvaluateAndLoadAssignment(new IntegerVector(vector)); 370 376 } 371 p rivatevoid EvaluateAndLoadAssignment(IntegerVector assignment) {377 public void EvaluateAndLoadAssignment(IntegerVector assignment) { 372 378 if (!IsConfigurationValid()) { 373 379 BestKnownQuality = null; … … 387 393 BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity))); 388 394 } 395 #endregion 389 396 390 397 #region Events … … 525 532 #endregion 526 533 527 p rivatebool IsConfigurationValid() {534 public bool IsConfigurationValid() { 528 535 return Weights != null && Distances != null && Demands != null && Capacities != null && InstallationCosts != null 529 536 && Weights.Rows == Weights.Columns && Weights.Rows == InstallationCosts.Rows -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPInstanceProvider.cs
r7538 r7548 28 28 29 29 namespace HeuristicLab.Problems.Instances.CordeauGQAP { 30 public class CordeauGQAPInstanceProvider : ProblemInstanceProvider<GQAP Instance> {30 public class CordeauGQAPInstanceProvider : ProblemInstanceProvider<GQAPData> { 31 31 public override string Name { 32 32 get { return "Cordeau et al. GQAP instances"; } … … 49 49 } 50 50 51 public override IEnumerable<I InstanceDescriptor> GetInstanceDescriptors() {51 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 52 52 return Assembly.GetExecutingAssembly() 53 53 .GetManifestResourceNames() 54 54 .Where(x => x.EndsWith(".txt")) 55 55 .OrderBy(x => x) 56 .Select(x => new CordeauGQAP InstanceDescriptor(GetPrettyName(x), GetDescription(), x));56 .Select(x => new CordeauGQAPDataDescriptor(GetPrettyName(x), GetDescription(), x)); 57 57 } 58 58 59 public override GQAP Instance LoadInstance(IInstanceDescriptor id) {60 var descriptor = (CordeauGQAP InstanceDescriptor)id;59 public override GQAPData LoadData(IDataDescriptor id) { 60 var descriptor = (CordeauGQAPDataDescriptor)id; 61 61 using (var stream = Assembly.GetExecutingAssembly() 62 62 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { … … 72 72 } 73 73 74 public override GQAP Instance LoadInstance(string path) {74 public override GQAPData LoadData(string path) { 75 75 var parser = new CordeauGQAPParser(); 76 76 parser.Parse(path); … … 83 83 } 84 84 85 public override void Save Instance(GQAPInstanceinstance, string path) {85 public override void SaveData(GQAPData instance, string path) { 86 86 throw new NotSupportedException(); 87 87 } 88 88 89 private GQAP InstanceLoad(CordeauGQAPParser parser) {90 var instance = new GQAP Instance();89 private GQAPData Load(CordeauGQAPParser parser) { 90 var instance = new GQAPData(); 91 91 instance.Equipments = parser.Equipments; 92 92 instance.Locations = parser.Locations; -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/HeuristicLab.Problems.Instances.CordeauGQAP-3.3.csproj
r7538 r7548 112 112 <Compile Include="CordeauGQAPParser.cs" /> 113 113 <Compile Include="CordeauGQAPInstanceProvider.cs" /> 114 <Compile Include="CordeauGQAP InstanceDescriptor.cs" />114 <Compile Include="CordeauGQAPDataDescriptor.cs" /> 115 115 <Compile Include="Plugin.cs" /> 116 116 <Compile Include="Properties\AssemblyInfo.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPInstanceProvider.cs
r7538 r7548 28 28 29 29 namespace HeuristicLab.Problems.Instances.ElloumiCTAP { 30 public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider<CTAP Instance> {30 public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider<CTAPData> { 31 31 public override string Name { 32 32 get { return "Elloumi's CTAP instances"; } … … 49 49 } 50 50 51 public override IEnumerable<I InstanceDescriptor> GetInstanceDescriptors() {51 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 52 52 var solutions = Assembly.GetExecutingAssembly() 53 53 .GetManifestResourceNames() … … 59 59 .Where(x => x.EndsWith(".dat")) 60 60 .OrderBy(x => x) 61 .Select(x => new ElloumiCTAP InstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));61 .Select(x => new ElloumiCTAPDataDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty)); 62 62 } 63 63 64 public override CTAP Instance LoadInstance(IInstanceDescriptor id) {65 var descriptor = (ElloumiCTAP InstanceDescriptor)id;64 public override CTAPData LoadData(IDataDescriptor id) { 65 var descriptor = (ElloumiCTAPDataDescriptor)id; 66 66 using (var stream = Assembly.GetExecutingAssembly() 67 67 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { … … 88 88 } 89 89 90 public override CTAP Instance LoadInstance(string path) {90 public override CTAPData LoadData(string path) { 91 91 var parser = new ElloumiCTAPParser(); 92 92 parser.Parse(path); … … 97 97 } 98 98 99 public override void Save Instance(CTAPInstanceinstance, string path) {99 public override void SaveData(CTAPData instance, string path) { 100 100 throw new NotSupportedException(); 101 101 } 102 102 103 private CTAP InstanceLoad(ElloumiCTAPParser parser) {104 var instance = new CTAP Instance();103 private CTAPData Load(ElloumiCTAPParser parser) { 104 var instance = new CTAPData(); 105 105 instance.Processors = parser.Processors; 106 106 instance.Tasks = parser.Tasks; -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/HeuristicLab.Problems.Instances.ElloumiCTAP-3.3.csproj
r7538 r7548 133 133 <EmbeddedResource Include="Data\tassc2005De.dat" /> 134 134 <None Include="Plugin.cs.frame" /> 135 <Compile Include="ElloumiCTAP InstanceDescriptor.cs" />135 <Compile Include="ElloumiCTAPDataDescriptor.cs" /> 136 136 <Compile Include="ElloumiCTAPInstanceProvider.cs" /> 137 137 <Compile Include="ElloumiCTAPParser.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/HeuristicLab.Problems.Instances.QAPLIB-3.3.csproj
r7538 r7548 51 51 <ItemGroup> 52 52 <Compile Include="QAPLIBParser.cs" /> 53 <Compile Include="QAPLIB InstanceDescriptor.cs" />53 <Compile Include="QAPLIBDataDescriptor.cs" /> 54 54 <Compile Include="QAPLIBSolutionParser.cs" /> 55 55 <Compile Include="QAPLIBInstanceProvider.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBInstanceProvider.cs
r7538 r7548 28 28 29 29 namespace HeuristicLab.Problems.Instances.QAPLIB { 30 public class QAPLIBInstanceProvider : ProblemInstanceProvider<QAP Instance> {30 public class QAPLIBInstanceProvider : ProblemInstanceProvider<QAPData> { 31 31 public override string Name { 32 32 get { return "QAPLIB"; } … … 49 49 } 50 50 51 public override IEnumerable<I InstanceDescriptor> GetInstanceDescriptors() {51 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 52 52 var solutions = Assembly.GetExecutingAssembly() 53 53 .GetManifestResourceNames() … … 59 59 .Where(x => x.EndsWith(".dat")) 60 60 .OrderBy(x => x) 61 .Select(x => new QAPLIB InstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));61 .Select(x => new QAPLIBDataDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty)); 62 62 } 63 63 64 public override QAP Instance LoadInstance(IInstanceDescriptor id) {65 var descriptor = (QAPLIB InstanceDescriptor)id;64 public override QAPData LoadData(IDataDescriptor id) { 65 var descriptor = (QAPLIBDataDescriptor)id; 66 66 using (var stream = Assembly.GetExecutingAssembly() 67 67 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { … … 87 87 } 88 88 89 public override QAP Instance LoadInstance(string path) {89 public override QAPData LoadData(string path) { 90 90 var parser = new QAPLIBParser(); 91 91 parser.Parse(path); … … 96 96 } 97 97 98 public override void Save Instance(QAPInstanceinstance, string path) {98 public override void SaveData(QAPData instance, string path) { 99 99 throw new NotSupportedException(); 100 100 } 101 101 102 private QAP InstanceLoad(QAPLIBParser parser) {103 var instance = new QAP Instance();102 private QAPData Load(QAPLIBParser parser) { 103 var instance = new QAPData(); 104 104 instance.Dimension = parser.Size; 105 105 instance.Distances = parser.Distances; -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/HeuristicLab.Problems.Instances.TSPLIB-3.3.csproj
r7538 r7548 47 47 <Compile Include="TSPLIBATSPInstanceProvider.cs" /> 48 48 <Compile Include="TSPLIBCVRPInstanceProvider.cs" /> 49 <Compile Include="TSPLIB InstanceDescriptor.cs" />49 <Compile Include="TSPLIBDataDescriptor.cs" /> 50 50 <Compile Include="TSPLIBTSPInstanceProvider.cs" /> 51 51 <Compile Include="TSPLIBParser.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBATSPInstanceProvider.cs
r7538 r7548 28 28 29 29 namespace HeuristicLab.Problems.Instances.TSPLIB { 30 public class TSPLIBATSPInstanceProvider : ProblemInstanceProvider<ATSP Instance> {30 public class TSPLIBATSPInstanceProvider : ProblemInstanceProvider<ATSPData> { 31 31 32 32 public override string Name { … … 50 50 } 51 51 52 public override IEnumerable<I InstanceDescriptor> GetInstanceDescriptors() {52 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 53 53 var solutions = Assembly.GetExecutingAssembly() 54 54 .GetManifestResourceNames() … … 62 62 .Where(x => x.EndsWith(".atsp")) 63 63 .OrderBy(x => x) 64 .Select(x => new TSPLIB InstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));64 .Select(x => new TSPLIBDataDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty)); 65 65 } 66 66 67 public override ATSP Instance LoadInstance(IInstanceDescriptor id) {68 var descriptor = (TSPLIB InstanceDescriptor)id;67 public override ATSPData LoadData(IDataDescriptor id) { 68 var descriptor = (TSPLIBDataDescriptor)id; 69 69 using (var stream = Assembly.GetExecutingAssembly() 70 70 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { … … 83 83 } 84 84 85 public override ATSP Instance LoadInstance(string path) {85 public override ATSPData LoadData(string path) { 86 86 return Load(new TSPLIBParser(path)); 87 87 } 88 88 89 public override void Save Instance(ATSPInstanceinstance, string path) {89 public override void SaveData(ATSPData instance, string path) { 90 90 throw new NotSupportedException(); 91 91 } 92 92 93 private ATSP InstanceLoad(TSPLIBParser parser) {94 var instance = new ATSP Instance();93 private ATSPData Load(TSPLIBParser parser) { 94 var instance = new ATSPData(); 95 95 96 96 parser.Parse(); -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs
r7538 r7548 28 28 29 29 namespace HeuristicLab.Problems.Instances.TSPLIB { 30 public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider<CVRP Instance> {30 public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider<CVRPData> { 31 31 32 32 public override string Name { … … 50 50 } 51 51 52 public override IEnumerable<I InstanceDescriptor> GetInstanceDescriptors() {52 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 53 53 var solutions = Assembly.GetExecutingAssembly() 54 54 .GetManifestResourceNames() … … 61 61 .Where(x => Regex.Match(x, @".*\.Data\.CVRP\..*").Success) 62 62 .OrderBy(x => x) 63 .Select(x => new TSPLIB InstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));63 .Select(x => new TSPLIBDataDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty)); 64 64 } 65 65 66 public override CVRP Instance LoadInstance(IInstanceDescriptor id) {67 var descriptor = (TSPLIB InstanceDescriptor)id;66 public override CVRPData LoadData(IDataDescriptor id) { 67 var descriptor = (TSPLIBDataDescriptor)id; 68 68 using (var stream = Assembly.GetExecutingAssembly() 69 69 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { … … 82 82 } 83 83 84 public override CVRP Instance LoadInstance(string path) {84 public override CVRPData LoadData(string path) { 85 85 return Load(new TSPLIBParser(path)); 86 86 } 87 87 88 public override void Save Instance(CVRPInstanceinstance, string path) {88 public override void SaveData(CVRPData instance, string path) { 89 89 throw new NotSupportedException(); 90 90 } 91 91 92 private CVRP InstanceLoad(TSPLIBParser parser) {92 private CVRPData Load(TSPLIBParser parser) { 93 93 parser.Parse(); 94 var instance = new CVRP Instance();94 var instance = new CVRPData(); 95 95 instance.Dimension = parser.Dimension; 96 96 instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices; -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBTSPInstanceProvider.cs
r7538 r7548 28 28 29 29 namespace HeuristicLab.Problems.Instances.TSPLIB { 30 public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider<TSP Instance> {30 public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider<TSPData> { 31 31 32 32 public override string Name { … … 50 50 } 51 51 52 public override IEnumerable<I InstanceDescriptor> GetInstanceDescriptors() {52 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 53 53 var solutions = Assembly.GetExecutingAssembly() 54 54 .GetManifestResourceNames() … … 62 62 .Where(x => x.EndsWith(".tsp")) 63 63 .OrderBy(x => x) 64 .Select(x => new TSPLIB InstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));64 .Select(x => new TSPLIBDataDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty)); 65 65 } 66 66 67 public override TSP Instance LoadInstance(IInstanceDescriptor id) {68 var descriptor = (TSPLIB InstanceDescriptor)id;67 public override TSPData LoadData(IDataDescriptor id) { 68 var descriptor = (TSPLIBDataDescriptor)id; 69 69 using (var stream = Assembly.GetExecutingAssembly() 70 70 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { … … 84 84 } 85 85 86 public override TSP Instance LoadInstance(string path) {86 public override TSPData LoadData(string path) { 87 87 return Load(new TSPLIBParser(path)); 88 88 } 89 89 90 public override void Save Instance(TSPInstanceinstance, string path) {90 public override void SaveData(TSPData instance, string path) { 91 91 throw new NotSupportedException(); 92 92 } 93 93 94 private TSP InstanceLoad(TSPLIBParser parser) {94 private TSPData Load(TSPLIBParser parser) { 95 95 parser.Parse(); 96 96 if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab."); 97 var instance = new TSP Instance();97 var instance = new TSPData(); 98 98 instance.Dimension = parser.Dimension; 99 99 instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices; -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/HeuristicLab.Problems.Instances-3.3.csproj
r7538 r7548 54 54 <None Include="Plugin.cs.frame" /> 55 55 <Compile Include="IExportable.cs" /> 56 <Compile Include=" Instances\ATSPInstance.cs" />57 <Compile Include=" Instances\CTAPInstance.cs" />58 <Compile Include="I InstanceDescriptor.cs" />59 <Compile Include=" Instances\CVRPInstance.cs" />60 <Compile Include=" Instances\GQAPInstance.cs" />61 <Compile Include=" Instances\QAPInstance.cs" />62 <Compile Include=" Instances\TSPInstance.cs" />63 <Compile Include="I Consumable.cs" />56 <Compile Include="Types\ATSPData.cs" /> 57 <Compile Include="Types\CTAPData.cs" /> 58 <Compile Include="IDataDescriptor.cs" /> 59 <Compile Include="Types\CVRPData.cs" /> 60 <Compile Include="Types\GQAPData.cs" /> 61 <Compile Include="Types\QAPData.cs" /> 62 <Compile Include="Types\TSPData.cs" /> 63 <Compile Include="IProblemInstanceConsumer.cs" /> 64 64 <Compile Include="IProblemInstanceProvider.cs" /> 65 65 <Compile Include="Plugin.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/IProblemInstanceProvider.cs
r7538 r7548 32 32 } 33 33 34 public interface IProblemInstanceProvider<T Instance> : IProblemInstanceProvider {35 I Consumable<TInstance> Consumer { get; set; }34 public interface IProblemInstanceProvider<TData> : IProblemInstanceProvider { 35 IProblemInstanceConsumer<TData> Consumer { get; set; } 36 36 37 IEnumerable<I InstanceDescriptor> GetInstanceDescriptors();38 T Instance LoadInstance(IInstanceDescriptor descriptor);39 T Instance LoadInstance(string path);40 41 void Save Instance(TInstanceinstance, string path);37 IEnumerable<IDataDescriptor> GetDataDescriptors(); 38 TData LoadData(IDataDescriptor descriptor); 39 TData LoadData(string path); 40 41 void SaveData(TData instance, string path); 42 42 } 43 43 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/ProblemInstanceProvider.cs
r7538 r7548 24 24 25 25 namespace HeuristicLab.Problems.Instances { 26 public abstract class ProblemInstanceProvider<T Instance> : IProblemInstanceProvider<TInstance> {27 public virtual I Consumable<TInstance> Consumer { get; set; }26 public abstract class ProblemInstanceProvider<TData> : IProblemInstanceProvider<TData> { 27 public virtual IProblemInstanceConsumer<TData> Consumer { get; set; } 28 28 29 29 public abstract string Name { get; } … … 32 32 public abstract string ReferencePublication { get; } 33 33 34 public abstract IEnumerable<I InstanceDescriptor> GetInstanceDescriptors();34 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 35 35 36 public abstract T Instance LoadInstance(IInstanceDescriptor descriptor);37 public abstract T Instance LoadInstance(string path);36 public abstract TData LoadData(IDataDescriptor descriptor); 37 public abstract TData LoadData(string path); 38 38 39 public abstract void Save Instance(TInstanceinstance, string path);39 public abstract void SaveData(TData instance, string path); 40 40 } 41 41 } -
branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs
r7538 r7548 34 34 public void CordeauCrossoverFunctionalityTest() { 35 35 var provider = new CordeauGQAPInstanceProvider(); 36 var instance = provider.Load Instance(provider.GetInstanceDescriptors().First());36 var instance = provider.LoadData(provider.GetDataDescriptors().First()); 37 37 var gqap = new GeneralizedQuadraticAssignmentProblem(); 38 gqap.Load From(instance);38 gqap.Load(instance); 39 39 40 40 var random = new MersenneTwister(); -
branches/GeneralizedQAP/UnitTests/CordeauGQAPInstanceProviderTest.cs
r7538 r7548 34 34 StringBuilder erroneousInstances = new StringBuilder(); 35 35 int count = 0; 36 foreach (var id in target.Get InstanceDescriptors()) {36 foreach (var id in target.GetDataDescriptors()) { 37 37 try { 38 target.Load Instance(id);38 target.LoadData(id); 39 39 } catch (Exception ex) { 40 40 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); -
branches/GeneralizedQAP/UnitTests/ElloumiCTAPInstanceProviderTest.cs
r7538 r7548 34 34 StringBuilder erroneousInstances = new StringBuilder(); 35 35 int count = 0; 36 foreach (var id in target.Get InstanceDescriptors()) {36 foreach (var id in target.GetDataDescriptors()) { 37 37 try { 38 target.Load Instance(id);38 target.LoadData(id); 39 39 } catch (Exception ex) { 40 40 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); -
branches/GeneralizedQAP/UnitTests/QAPLIBInstanceProviderTest.cs
r7538 r7548 35 35 StringBuilder erroneousInstances = new StringBuilder(); 36 36 int count = 0; 37 foreach (var id in target.Get InstanceDescriptors()) {37 foreach (var id in target.GetDataDescriptors()) { 38 38 try { 39 target.Load Instance(id);39 target.LoadData(id); 40 40 } catch (Exception ex) { 41 41 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); … … 54 54 List<string> nonZeroDiagonalInstances = new List<string>(); 55 55 var target = new QAPLIBInstanceProvider(); 56 foreach (var id in target.Get InstanceDescriptors()) {57 var instance = target.Load Instance(id);56 foreach (var id in target.GetDataDescriptors()) { 57 var instance = target.LoadData(id); 58 58 for (int i = 0; i < instance.Dimension; i++) 59 59 if (instance.Distances[i, i] != 0 || instance.Weights[i, i] != 0) { -
branches/GeneralizedQAP/UnitTests/TSPLIBInstanceProviderTest.cs
r7538 r7548 34 34 StringBuilder erroneousInstances = new StringBuilder(); 35 35 int count = 0; 36 foreach (var id in target.Get InstanceDescriptors()) {36 foreach (var id in target.GetDataDescriptors()) { 37 37 try { 38 target.Load Instance(id);38 target.LoadData(id); 39 39 } catch (Exception ex) { 40 40 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); … … 51 51 StringBuilder erroneousInstances = new StringBuilder(); 52 52 int count = 0; 53 foreach (var id in target.Get InstanceDescriptors()) {53 foreach (var id in target.GetDataDescriptors()) { 54 54 try { 55 target.Load Instance(id);55 target.LoadData(id); 56 56 } catch (Exception ex) { 57 57 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); … … 68 68 StringBuilder erroneousInstances = new StringBuilder(); 69 69 int count = 0; 70 foreach (var id in target.Get InstanceDescriptors()) {70 foreach (var id in target.GetDataDescriptors()) { 71 71 try { 72 target.Load Instance(id);72 target.LoadData(id); 73 73 } catch (Exception ex) { 74 74 erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
Note: See TracChangeset
for help on using the changeset viewer.