Changeset 7538 for branches/GeneralizedQAP
- Timestamp:
- 03/01/12 15:15:22 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 9 added
- 13 deleted
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Plugin.cs.frame
r7363 r7538 36 36 [PluginDependency("HeuristicLab.Persistence", "3.3")] 37 37 [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")] 38 [PluginDependency("HeuristicLab.Random", "3.3")] 39 [PluginDependency("HeuristicLab.Selection", "3.3")] 38 40 public class HeuristicLabProblemsGeneralizedQuadraticAssignmentAlgorithmsPlugin : PluginBase { 39 41 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common/3.3/Plugin.cs.frame
r7363 r7538 25 25 [Plugin("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3.0.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Collections", "3.3")] 28 [PluginDependency("HeuristicLab.Common", "3.3")] 29 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] 30 [PluginDependency("HeuristicLab.Core", "3.3")] 31 [PluginDependency("HeuristicLab.Data", "3.3")] 32 [PluginDependency("HeuristicLab.Encodings.IntegerVectorEncoding", "3.3")] 33 [PluginDependency("HeuristicLab.Operators", "3.3")] 34 [PluginDependency("HeuristicLab.Optimization", "3.3")] 35 [PluginDependency("HeuristicLab.Parameters", "3.3")] 36 [PluginDependency("HeuristicLab.Persistence", "3.3")] 27 37 public class HeuristicLabProblemsGeneralizedQuadraticAssignmentCommonPlugin : PluginBase { 28 38 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/Plugin.cs.frame
r7363 r7538 25 25 [Plugin("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views", "3.3.6.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Collections", "3.3")] 27 28 [PluginDependency("HeuristicLab.Common", "3.3")] 28 29 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] … … 30 31 [PluginDependency("HeuristicLab.Core.Views", "3.3")] 31 32 [PluginDependency("HeuristicLab.Data", "3.3")] 33 [PluginDependency("HeuristicLab.Data.Views", "3.3")] 32 34 [PluginDependency("HeuristicLab.Encodings.IntegerVectorEncoding", "3.3")] 33 35 [PluginDependency("HeuristicLab.MainForm", "3.3")] … … 37 39 [PluginDependency("HeuristicLab.Parameters", "3.3")] 38 40 [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment", "3.3")] 41 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 42 [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")] 39 43 public class HeuristicLabProblemsGeneralizedQuadraticAssignmentViewsPlugin : PluginBase { 40 44 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.Designer.cs
r7523 r7538 21 21 22 22 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views { 23 partial class ProblemInstanceProviderView {23 partial class ProblemInstanceProviderView<T> { 24 24 /// <summary> 25 25 /// Required designer variable. … … 48 48 this.label2 = new System.Windows.Forms.Label(); 49 49 this.instancesComboBox = new System.Windows.Forms.ComboBox(); 50 this.importButton = new System.Windows.Forms.Button(); 51 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 50 52 this.SuspendLayout(); 51 53 // … … 53 55 // 54 56 this.loadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 55 this.loadButton.Location = new System.Drawing.Point( 535, -1);57 this.loadButton.Location = new System.Drawing.Point(451, -1); 56 58 this.loadButton.Name = "loadButton"; 57 59 this.loadButton.Size = new System.Drawing.Size(75, 23); … … 78 80 this.instancesComboBox.Location = new System.Drawing.Point(54, 0); 79 81 this.instancesComboBox.Name = "instancesComboBox"; 80 this.instancesComboBox.Size = new System.Drawing.Size( 475, 21);82 this.instancesComboBox.Size = new System.Drawing.Size(391, 21); 81 83 this.instancesComboBox.TabIndex = 7; 82 84 this.instancesComboBox.DataSourceChanged += new System.EventHandler(this.comboBox_DataSourceChanged); 85 // 86 // importButton 87 // 88 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(532, -1); 90 this.importButton.Name = "importButton"; 91 this.importButton.Size = new System.Drawing.Size(75, 23); 92 this.importButton.TabIndex = 6; 93 this.importButton.Text = "Import"; 94 this.importButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; 95 this.importButton.UseVisualStyleBackColor = true; 96 this.importButton.Click += new System.EventHandler(this.importButton_Click); 97 // 98 // openFileDialog 99 // 100 this.openFileDialog.Filter = "All files|*.*"; 83 101 // 84 102 // ProblemInstanceProviderView … … 87 105 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 88 106 this.Controls.Add(this.instancesComboBox); 107 this.Controls.Add(this.importButton); 89 108 this.Controls.Add(this.loadButton); 90 109 this.Controls.Add(this.label2); … … 101 120 private System.Windows.Forms.Label label2; 102 121 private System.Windows.Forms.ComboBox instancesComboBox; 122 private System.Windows.Forms.Button importButton; 123 private System.Windows.Forms.OpenFileDialog openFileDialog; 103 124 104 125 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs
r7505 r7538 23 23 using System.Linq; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Common.Resources; 25 26 using HeuristicLab.MainForm; 26 27 using HeuristicLab.MainForm.WindowsForms; … … 29 30 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views { 30 31 [View("ProblemInstanceProviderView")] 31 [Content(typeof(IProblemInstanceProvider ), IsDefaultView = true)]32 public partial class ProblemInstanceProviderView : AsynchronousContentView {32 [Content(typeof(IProblemInstanceProvider<>), IsDefaultView = true)] 33 public partial class ProblemInstanceProviderView<T> : AsynchronousContentView { 33 34 34 public new IProblemInstanceProvider Content {35 get { return (IProblemInstanceProvider )base.Content; }35 public new IProblemInstanceProvider<T> Content { 36 get { return (IProblemInstanceProvider<T>)base.Content; } 36 37 set { base.Content = value; } 37 38 } … … 39 40 public ProblemInstanceProviderView() { 40 41 InitializeComponent(); 42 importButton.Image = VSImageLibrary.Open; 41 43 } 42 44 … … 53 55 protected override void SetEnabledStateOfControls() { 54 56 base.SetEnabledStateOfControls(); 55 instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer CanBeFed;56 loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer CanBeFed;57 instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null; 58 loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null; 57 59 } 58 60 59 61 private void loadButton_Click(object sender, EventArgs e) { 60 var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem; 61 if (!Content.FeedConsumer(instance)) { 62 MessageBox.Show("This problem does not support loading the instance " + instance.Name + ".", "Cannot load instance"); 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"); 66 } 67 } 68 69 private void importButton_Click(object sender, EventArgs e) { 70 if (openFileDialog.ShowDialog() == DialogResult.OK) { 71 T instance = default(T); 72 try { 73 instance = Content.LoadInstance(openFileDialog.FileName); 74 } catch { 75 MessageBox.Show("There was an error parsing the file.", "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error); 76 return; 77 } 78 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."); 84 } 63 85 } 64 86 } … … 69 91 comboBox.Items.Clear(); 70 92 } 71 72 private void instancesComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {73 var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;74 e.ToolTip = instance.Description;75 }76 93 } 77 94 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.resx
r7448 r7538 118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 119 119 </resheader> 120 <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 121 <value>17, 17</value> 122 </metadata> 120 123 </root> -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.Designer.cs
r7482 r7538 103 103 // problemInstanceProviderComboBox 104 104 // 105 this.problemInstanceProviderComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDraw Fixed;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))); 107 108 this.problemInstanceProviderComboBox.FormattingEnabled = true; 108 109 this.problemInstanceProviderComboBox.Location = new System.Drawing.Point(50, 5); 110 this.problemInstanceProviderComboBox.MaxDropDownItems = 16; 109 111 this.problemInstanceProviderComboBox.Name = "problemInstanceProviderComboBox"; 110 112 this.problemInstanceProviderComboBox.Size = new System.Drawing.Size(173, 21); -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.cs
r7523 r7538 63 63 if (problemInstanceProviderComboBox.SelectedIndex >= 0) { 64 64 var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem; 65 provider.SetConsumer((IProblemInstanceConsumer)Content); 65 var genericType = provider.GetType().GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IProblemInstanceProvider<>)).GetGenericArguments().First(); 66 this.GetType().GetMethod("SetConsumable").MakeGenericMethod(genericType).Invoke(this, new object[] { provider, Content }); 66 67 problemInstanceProviderViewHost.Content = provider; 67 68 } 69 } 70 71 /// <summary> 72 /// Do not change method name without changing the string reference above 73 /// </summary> 74 private void SetConsumable<T>(IProblemInstanceProvider<T> producer, IConsumable<T> consumer) { 75 producer.Consumer = consumer; 68 76 } 69 77 … … 77 85 var consumerTypes = Content.GetType().GetInterfaces() 78 86 .Where(x => x.IsGenericType 79 && typeof(IProblemInstanceConsumer).IsAssignableFrom(x));87 && x.GetGenericTypeDefinition() == typeof(IConsumable<>)); 80 88 81 89 if (consumerTypes.Any()) { -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.Designer.cs
r7482 r7538 48 48 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 49 49 this.SuspendLayout(); 50 // 51 // ToolTipComboBox 52 // 53 this.MaxDropDownItems = 16; 50 54 this.ResumeLayout(false); 51 55 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs
r7523 r7538 29 29 30 30 private ComboBoxState comboBoxState = ComboBoxState.Normal; 31 private bool mouseOver = false;32 31 33 32 public ToolTipComboBox() … … 36 35 SetStyle(ControlStyles.UserPaint, true); 37 36 InitializeComponent(); 38 DrawMode = System.Windows.Forms.DrawMode.OwnerDraw Variable;37 DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; 39 38 DropDownStyle = ComboBoxStyle.DropDownList; 40 }41 42 protected override void OnMeasureItem(MeasureItemEventArgs e) {43 base.OnMeasureItem(e);44 string text = GetItemText(Items[e.Index]);45 if (string.IsNullOrEmpty(text)) text = "test";46 var rect = TextRenderer.MeasureText(text, Font);47 e.ItemHeight = rect.Height - 2;48 e.ItemWidth = rect.Width;49 39 } 50 40 … … 72 62 } else { 73 63 using (var b = new SolidBrush(ForeColor)) { 74 Rectangle r = e.Bounds; 75 r.Offset(0, 1); 76 e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, r); 64 var rect = new Rectangle(2, 4, Size.Width - 2, Size.Height - 4); 65 e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, rect); 77 66 } 78 67 } … … 84 73 base.OnPaint(e); 85 74 if (Enabled == false) comboBoxState = ComboBoxState.Disabled; 86 Rectangle clip = Bounds; // using e.ClipRectangle leads to strange behavior when maximizing/unmaximizing, just redraw the entire region all the time87 clip. Offset(-clip.X, -clip.Y); // x and y need to be 075 Rectangle clip = new Rectangle(new Point(0, 0), Size); 76 clip.Inflate(0, 1); 88 77 if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser) { 89 78 PushButtonState pb_State = PushButtonState.Normal; … … 109 98 ComboBoxRenderer.DrawDropDownButton(e.Graphics, r, comboBoxState); 110 99 } 111 Rectangle rect = clip; 112 rect.Inflate(-2, -4); 113 rect.Offset(1, 0); 100 var rect = new Rectangle(2, 4, Size.Width - 2, Size.Height - 4); 114 101 if (SelectedIndex > -1 && Items.Count > 0) { 115 102 using (var b = new SolidBrush(ForeColor)) { … … 141 128 protected override void OnMouseEnter(EventArgs e) { 142 129 base.OnMouseEnter(e); 143 mouseOver = true;144 130 if (comboBoxState == ComboBoxState.Normal) { 145 131 comboBoxState = ComboBoxState.Hot; … … 158 144 protected override void OnMouseLeave(EventArgs e) { 159 145 base.OnMouseLeave(e); 160 mouseOver = false;161 146 if (comboBoxState == ComboBoxState.Hot) { 162 147 comboBoxState = ComboBoxState.Normal; … … 167 152 protected override void OnMouseDown(MouseEventArgs e) { 168 153 base.OnMouseDown(e); 169 comboBoxState = ComboBoxState.Pressed; 170 Invalidate(); 154 if (e.Button == MouseButtons.Left) { 155 comboBoxState = ComboBoxState.Pressed; 156 Invalidate(); 157 } 171 158 } 172 159 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs
r7523 r7538 39 39 [StorableClass] 40 40 public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent, 41 I ProblemInstanceConsumer<IQAPInstance>,42 I ProblemInstanceConsumer<ICTAPInstance>,43 I ProblemInstanceConsumer<ITSPInstance>,44 I ProblemInstanceConsumer<IATSPInstance>,45 I ProblemInstanceConsumer<IGQAPInstance> {41 IConsumable<QAPInstance>, 42 IConsumable<CTAPInstance>, 43 IConsumable<TSPInstance>, 44 IConsumable<ATSPInstance>, 45 IConsumable<GQAPInstance> { 46 46 47 47 public override Image ItemImage { … … 214 214 215 215 #region Problem Instance Consumptions 216 public bool LoadFrom( IQAPInstance instance) {216 public bool LoadFrom(QAPInstance instance) { 217 217 try { 218 218 Name = instance.Name; … … 240 240 } 241 241 242 public bool LoadFrom( ICTAPInstance instance) {242 public bool LoadFrom(CTAPInstance instance) { 243 243 try { 244 244 Name = instance.Name; … … 270 270 } 271 271 272 public bool LoadFrom( ITSPInstance instance) {272 public bool LoadFrom(TSPInstance instance) { 273 273 try { 274 274 if (instance.Dimension > 1000) return false; … … 304 304 } 305 305 306 public bool LoadFrom( IATSPInstance instance) {306 public bool LoadFrom(ATSPInstance instance) { 307 307 try { 308 308 Name = instance.Name; … … 336 336 } 337 337 338 public bool LoadFrom( IGQAPInstance instance) {338 public bool LoadFrom(GQAPInstance instance) { 339 339 try { 340 340 Name = instance.Name; -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Plugin.cs.frame
r7363 r7538 25 25 [Plugin("HeuristicLab.Problems.GeneralizedQuadraticAssignment", "3.3.6.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Analysis", "3.3")] 27 28 [PluginDependency("HeuristicLab.Collections", "3.3")] 28 29 [PluginDependency("HeuristicLab.Common", "3.3")] … … 33 34 [PluginDependency("HeuristicLab.Operators", "3.3")] 34 35 [PluginDependency("HeuristicLab.Optimization", "3.3")] 36 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 35 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 36 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] 37 39 [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")] 40 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 38 41 public class HeuristicLabProblemsGeneralizedQuadraticAssignmentPlugin : PluginBase { 39 42 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPInstanceProvider.cs
r7523 r7538 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.IO; 24 25 using System.Linq; 25 26 using System.Reflection; … … 27 28 28 29 namespace HeuristicLab.Problems.Instances.CordeauGQAP { 29 public class CordeauGQAPInstanceProvider : ProblemInstanceProvider< IGQAPInstance> {30 public class CordeauGQAPInstanceProvider : ProblemInstanceProvider<GQAPInstance> { 30 31 public override string Name { 31 32 get { return "Cordeau et al. GQAP instances"; } … … 56 57 } 57 58 58 public override IGQAPInstance GetInstance(IInstanceDescriptor id) {59 public override GQAPInstance LoadInstance(IInstanceDescriptor id) { 59 60 var descriptor = (CordeauGQAPInstanceDescriptor)id; 60 var instance = new CordeauGQAPInstance();61 61 using (var stream = Assembly.GetExecutingAssembly() 62 62 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { 63 63 var parser = new CordeauGQAPParser(); 64 64 parser.Parse(stream); 65 if (parser.Error != null) throw parser.Error; 66 instance.Equipments = parser.Equipments; 67 instance.Locations = parser.Locations; 68 instance.Demands = parser.Demands; 69 instance.Capacities = parser.Capacities; 70 instance.Weights = parser.Weights; 71 instance.Distances = parser.Distances; 72 instance.InstallationCosts = parser.InstallationCosts; 73 instance.TransportationCosts = parser.TransportationCosts; 65 var instance = Load(parser); 74 66 75 67 instance.Name = id.Name; 76 68 instance.Description = id.Description; 69 70 return instance; 77 71 } 72 } 73 74 public override GQAPInstance LoadInstance(string path) { 75 var parser = new CordeauGQAPParser(); 76 parser.Parse(path); 77 var instance = Load(parser); 78 79 instance.Name = Path.GetFileName(path); 80 instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString(); 81 82 return instance; 83 } 84 85 public override void SaveInstance(GQAPInstance instance, string path) { 86 throw new NotSupportedException(); 87 } 88 89 private GQAPInstance Load(CordeauGQAPParser parser) { 90 var instance = new GQAPInstance(); 91 instance.Equipments = parser.Equipments; 92 instance.Locations = parser.Locations; 93 instance.Demands = parser.Demands; 94 instance.Capacities = parser.Capacities; 95 instance.Weights = parser.Weights; 96 instance.Distances = parser.Distances; 97 instance.InstallationCosts = parser.InstallationCosts; 98 instance.TransportationCosts = parser.TransportationCosts; 78 99 return instance; 79 100 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPParser.cs
r7505 r7538 34 34 public double[] Demands { get; private set; } 35 35 public double[] Capacities { get; private set; } 36 public Exception Error { get; private set; }37 36 38 37 public CordeauGQAPParser() { … … 48 47 Demands = null; 49 48 Capacities = null; 50 Error = null;51 49 } 52 50 53 public boolParse(string file) {51 public void Parse(string file) { 54 52 using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) { 55 returnParse(stream);53 Parse(stream); 56 54 } 57 55 } … … 64 62 /// </remarks> 65 63 /// <param name="stream">The stream to read data from.</param> 66 /// <returns>True if the file was successfully read or false otherwise.</returns> 67 public bool Parse(Stream stream) { 68 Error = null; 64 public void Parse(Stream stream) { 69 65 var separator = new char[] { ' ', '\t' }; 70 try { 71 StreamReader reader = new StreamReader(stream); 72 string line = Continue(reader); 66 var reader = new StreamReader(stream); 67 string line = Continue(reader); 73 68 74 75 76 77 69 var info = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 70 Equipments = int.Parse(info[0]); 71 Locations = int.Parse(info[1]); 72 TransportationCosts = double.Parse(info[2]); 78 73 74 line = Continue(reader); 75 76 Weights = new double[Equipments, Equipments]; 77 for (int i = 0; i < Equipments; i++) { 78 var weightsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 79 for (int j = 0; j < Equipments; j++) { 80 Weights[i, j] = double.Parse(weightsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 81 } 79 82 line = Continue(reader); 83 } 80 84 81 Weights = new double[Equipments, Equipments]; 82 for (int i = 0; i < Equipments; i++) { 83 var weightsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 84 for (int j = 0; j < Equipments; j++) { 85 Weights[i, j] = double.Parse(weightsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 86 } 87 line = Continue(reader); 85 Distances = new double[Locations, Locations]; 86 for (int i = 0; i < Locations; i++) { 87 var distancePerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 88 for (int j = 0; j < Locations; j++) { 89 Distances[i, j] = double.Parse(distancePerLocation[j], CultureInfo.InvariantCulture.NumberFormat); 88 90 } 91 line = Continue(reader); 92 } 89 93 90 Distances = new double[Locations, Locations]; 91 for (int i = 0; i < Locations; i++) { 92 var distancePerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 93 for (int j = 0; j < Locations; j++) { 94 Distances[i, j] = double.Parse(distancePerLocation[j], CultureInfo.InvariantCulture.NumberFormat); 95 } 96 line = Continue(reader); 97 } 94 InstallationCosts = new double[Equipments, Locations]; 95 for (int i = 0; i < Equipments; i++) { 96 var costsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 97 for (int j = 0; j < Locations; j++) 98 InstallationCosts[i, j] = double.Parse(costsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 99 line = Continue(reader); 100 } 98 101 99 InstallationCosts = new double[Equipments, Locations]; 100 for (int i = 0; i < Equipments; i++) { 101 var costsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 102 for (int j = 0; j < Locations; j++) 103 InstallationCosts[i, j] = double.Parse(costsPerEquipment[j], CultureInfo.InvariantCulture.NumberFormat); 104 line = Continue(reader); 105 } 102 Demands = new double[Equipments]; 103 var demandsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 104 for (int i = 0; i < Equipments; i++) 105 Demands[i] = double.Parse(demandsPerEquipment[i], CultureInfo.InvariantCulture.NumberFormat); 106 106 107 Demands = new double[Equipments]; 108 var demandsPerEquipment = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 109 for (int i = 0; i < Equipments; i++) 110 Demands[i] = double.Parse(demandsPerEquipment[i], CultureInfo.InvariantCulture.NumberFormat); 107 line = Continue(reader); 111 108 112 line = Continue(reader); 113 114 Capacities = new double[Locations]; 115 string[] capacityPerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 116 for (int i = 0; i < Locations; i++) 117 Capacities[i] = double.Parse(capacityPerLocation[i], CultureInfo.InvariantCulture.NumberFormat); 118 119 return true; 120 } catch (Exception e) { 121 Error = e; 122 return false; 123 } 109 Capacities = new double[Locations]; 110 string[] capacityPerLocation = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 111 for (int i = 0; i < Locations; i++) 112 Capacities[i] = double.Parse(capacityPerLocation[i], CultureInfo.InvariantCulture.NumberFormat); 124 113 } 125 114 -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/HeuristicLab.Problems.Instances.CordeauGQAP-3.3.csproj
r7505 r7538 111 111 <None Include="Plugin.cs.frame" /> 112 112 <Compile Include="CordeauGQAPParser.cs" /> 113 <Compile Include="CordeauGQAPInstance.cs" />114 113 <Compile Include="CordeauGQAPInstanceProvider.cs" /> 115 114 <Compile Include="CordeauGQAPInstanceDescriptor.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/Plugin.cs.frame
r7505 r7538 25 25 [Plugin("HeuristicLab.Problems.Instances.CordeauGQAP", "3.3.6.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.Instances.CordeauGQAP-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Common", "3.3")] 28 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 27 29 public class HeuristicLabProblemsInstancesCordeauGQAPPlugin : PluginBase { 28 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPInstanceProvider.cs
r7482 r7538 28 28 29 29 namespace HeuristicLab.Problems.Instances.ElloumiCTAP { 30 public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider< ICTAPInstance> {30 public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider<CTAPInstance> { 31 31 public override string Name { 32 32 get { return "Elloumi's CTAP instances"; } … … 62 62 } 63 63 64 public override ICTAPInstance GetInstance(IInstanceDescriptor id) {64 public override CTAPInstance LoadInstance(IInstanceDescriptor id) { 65 65 var descriptor = (ElloumiCTAPInstanceDescriptor)id; 66 var instance = new ElloumiCTAPInstance();67 66 using (var stream = Assembly.GetExecutingAssembly() 68 67 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { 69 ElloumiCTAPParser datParser = new ElloumiCTAPParser(); 70 datParser.Parse(stream); 71 if (datParser.Error != null) throw datParser.Error; 72 instance.Processors = datParser.Processors; 73 instance.Tasks = datParser.Tasks; 74 instance.ExecutionCosts = datParser.ExecutionCosts; 75 instance.CommunicationCosts = datParser.CommunicationCosts; 76 instance.MemoryRequirements = datParser.MemoryRequirements; 77 instance.MemoryCapacities = datParser.MemoryCapacities; 68 var parser = new ElloumiCTAPParser(); 69 parser.Parse(stream); 70 var instance = Load(parser); 78 71 79 72 instance.Name = id.Name; … … 91 84 } 92 85 } 86 return instance; 93 87 } 88 } 89 90 public override CTAPInstance LoadInstance(string path) { 91 var parser = new ElloumiCTAPParser(); 92 parser.Parse(path); 93 var instance = Load(parser); 94 instance.Name = Path.GetFileName(path); 95 instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString(); 96 return instance; 97 } 98 99 public override void SaveInstance(CTAPInstance instance, string path) { 100 throw new NotSupportedException(); 101 } 102 103 private CTAPInstance Load(ElloumiCTAPParser parser) { 104 var instance = new CTAPInstance(); 105 instance.Processors = parser.Processors; 106 instance.Tasks = parser.Tasks; 107 instance.ExecutionCosts = parser.ExecutionCosts; 108 instance.CommunicationCosts = parser.CommunicationCosts; 109 instance.MemoryRequirements = parser.MemoryRequirements; 110 instance.MemoryCapacities = parser.MemoryCapacities; 94 111 return instance; 95 112 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPParser.cs
r7448 r7538 32 32 public double[] MemoryRequirements { get; private set; } 33 33 public double[] MemoryCapacities { get; private set; } 34 public Exception Error { get; private set; }35 34 36 35 public ElloumiCTAPParser() { … … 45 44 MemoryRequirements = null; 46 45 MemoryCapacities = null; 47 Error = null;48 46 } 49 47 50 public boolParse(string file) {48 public void Parse(string file) { 51 49 using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) { 52 returnParse(stream);50 Parse(stream); 53 51 } 54 52 } … … 62 60 /// <param name="stream">The stream to read data from.</param> 63 61 /// <returns>True if the file was successfully read or false otherwise.</returns> 64 public bool Parse(Stream stream) { 65 Error = null; 62 public void Parse(Stream stream) { 66 63 var separator = new char[] { ' ', '\t' }; 67 try { 68 StreamReader reader = new StreamReader(stream); 69 string line = Continue(reader); 64 var reader = new StreamReader(stream); 65 string line = Continue(reader); 70 66 71 67 Tasks = int.Parse(line); 72 68 69 line = Continue(reader); 70 71 Processors = int.Parse(line); 72 73 line = Continue(reader); 74 75 ExecutionCosts = new double[Processors, Tasks]; 76 for (int i = 0; i < Processors; i++) { 77 string[] costsPerTask = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 78 for (int j = 0; j < Tasks; j++) 79 ExecutionCosts[i, j] = double.Parse(costsPerTask[j], CultureInfo.InvariantCulture.NumberFormat); 73 80 line = Continue(reader); 81 } 74 82 75 Processors = int.Parse(line); 83 CommunicationCosts = new double[Tasks, Tasks]; 84 for (int i = 0; i < Tasks - 1; i++) { 85 string[] costsTaskToTasks = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 86 for (int j = i + 1; j < Tasks; j++) { 87 CommunicationCosts[i, j] = double.Parse(costsTaskToTasks[j - i - 1], CultureInfo.InvariantCulture.NumberFormat); 88 CommunicationCosts[j, i] = CommunicationCosts[i, j]; 89 } 90 line = Continue(reader); 91 } 76 92 77 line = Continue(reader); 93 MemoryRequirements = new double[Tasks]; 94 string[] requirementsPerTask = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 95 for (int i = 0; i < Tasks; i++) 96 MemoryRequirements[i] = double.Parse(requirementsPerTask[i], CultureInfo.InvariantCulture.NumberFormat); 78 97 79 ExecutionCosts = new double[Processors, Tasks]; 80 for (int i = 0; i < Processors; i++) { 81 string[] costsPerTask = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 82 for (int j = 0; j < Tasks; j++) 83 ExecutionCosts[i, j] = double.Parse(costsPerTask[j], CultureInfo.InvariantCulture.NumberFormat); 84 line = Continue(reader); 85 } 98 line = Continue(reader); 86 99 87 CommunicationCosts = new double[Tasks, Tasks]; 88 for (int i = 0; i < Tasks - 1; i++) { 89 string[] costsTaskToTasks = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 90 for (int j = i + 1; j < Tasks; j++) { 91 CommunicationCosts[i, j] = double.Parse(costsTaskToTasks[j - i - 1], CultureInfo.InvariantCulture.NumberFormat); 92 CommunicationCosts[j, i] = CommunicationCosts[i, j]; 93 } 94 line = Continue(reader); 95 } 100 MemoryCapacities = new double[Processors]; 101 string[] capacitiesPerProcessor = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); 102 for (int i = 0; i < Processors; i++) 103 MemoryCapacities[i] = double.Parse(capacitiesPerProcessor[i], CultureInfo.InvariantCulture.NumberFormat); 96 104 97 MemoryRequirements = new double[Tasks];98 string[] requirementsPerTask = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);99 for (int i = 0; i < Tasks; i++)100 MemoryRequirements[i] = double.Parse(requirementsPerTask[i], CultureInfo.InvariantCulture.NumberFormat);101 102 line = Continue(reader);103 104 MemoryCapacities = new double[Processors];105 string[] capacitiesPerProcessor = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);106 for (int i = 0; i < Processors; i++)107 MemoryCapacities[i] = double.Parse(capacitiesPerProcessor[i], CultureInfo.InvariantCulture.NumberFormat);108 109 return true;110 } catch (Exception e) {111 Error = e;112 return false;113 }114 105 } 115 106 -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/HeuristicLab.Problems.Instances.ElloumiCTAP-3.3.csproj
r7448 r7538 133 133 <EmbeddedResource Include="Data\tassc2005De.dat" /> 134 134 <None Include="Plugin.cs.frame" /> 135 <Compile Include="ElloumiCTAPInstance.cs" />136 135 <Compile Include="ElloumiCTAPInstanceDescriptor.cs" /> 137 136 <Compile Include="ElloumiCTAPInstanceProvider.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/Plugin.cs.frame
r7443 r7538 25 25 [Plugin("HeuristicLab.Problems.Instances.ElloumiCTAP", "3.3.6.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.Instances.ElloumiCTAP-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Common", "3.3")] 28 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 27 29 public class HeuristicLabProblemsInstancesElloumiCTAPPlugin : PluginBase { 28 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/HeuristicLab.Problems.Instances.QAPLIB-3.3.csproj
r7448 r7538 51 51 <ItemGroup> 52 52 <Compile Include="QAPLIBParser.cs" /> 53 <Compile Include="QAPLIBInstance.cs" />54 53 <Compile Include="QAPLIBInstanceDescriptor.cs" /> 55 54 <Compile Include="QAPLIBSolutionParser.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/Plugin.cs.frame
r7443 r7538 25 25 [Plugin("HeuristicLab.Problems.Instances.QAPLIB", "3.3.6.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.Instances.QAPLIB-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Common", "3.3")] 28 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 27 29 public class HeuristicLabProblemsInstancesQAPLIBPlugin : PluginBase { 28 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBInstanceProvider.cs
r7482 r7538 28 28 29 29 namespace HeuristicLab.Problems.Instances.QAPLIB { 30 public class QAPLIBInstanceProvider : ProblemInstanceProvider< IQAPInstance> {30 public class QAPLIBInstanceProvider : ProblemInstanceProvider<QAPInstance> { 31 31 public override string Name { 32 32 get { return "QAPLIB"; } … … 62 62 } 63 63 64 public override IQAPInstance GetInstance(IInstanceDescriptor id) {64 public override QAPInstance LoadInstance(IInstanceDescriptor id) { 65 65 var descriptor = (QAPLIBInstanceDescriptor)id; 66 var instance = new QAPLIBInstance();67 66 using (var stream = Assembly.GetExecutingAssembly() 68 67 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { 69 QAPLIBParser datParser = new QAPLIBParser(); 70 datParser.Parse(stream); 71 if (datParser.Error != null) throw datParser.Error; 72 instance.Dimension = datParser.Size; 73 instance.Distances = datParser.Distances; 74 instance.Weights = datParser.Weights; 75 68 var parser = new QAPLIBParser(); 69 parser.Parse(stream); 70 var instance = Load(parser); 76 71 instance.Name = id.Name; 77 72 instance.Description = id.Description; … … 80 75 using (Stream solStream = Assembly.GetExecutingAssembly() 81 76 .GetManifestResourceStream(descriptor.SolutionIdentifier)) { 82 QAPLIBSolutionParser slnParser = new QAPLIBSolutionParser();77 var slnParser = new QAPLIBSolutionParser(); 83 78 slnParser.Parse(solStream, true); 84 79 if (slnParser.Error != null) throw slnParser.Error; … … 88 83 } 89 84 } 85 return instance; 90 86 } 87 } 88 89 public override QAPInstance LoadInstance(string path) { 90 var parser = new QAPLIBParser(); 91 parser.Parse(path); 92 var instance = Load(parser); 93 instance.Name = Path.GetFileName(path); 94 instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString(); 95 return instance; 96 } 97 98 public override void SaveInstance(QAPInstance instance, string path) { 99 throw new NotSupportedException(); 100 } 101 102 private QAPInstance Load(QAPLIBParser parser) { 103 var instance = new QAPInstance(); 104 instance.Dimension = parser.Size; 105 instance.Distances = parser.Distances; 106 instance.Weights = parser.Weights; 91 107 return instance; 92 108 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBParser.cs
r7445 r7538 28 28 public double[,] Distances { get; private set; } 29 29 public double[,] Weights { get; private set; } 30 public Exception Error { get; private set; }31 30 32 31 public QAPLIBParser() { … … 38 37 Distances = null; 39 38 Weights = null; 40 Error = null;41 39 } 42 40 43 public boolParse(string file) {41 public void Parse(string file) { 44 42 using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) { 45 returnParse(stream);43 Parse(stream); 46 44 } 47 45 } … … 55 53 /// <param name="stream">The stream to read data from.</param> 56 54 /// <returns>True if the file was successfully read or false otherwise.</returns> 57 public bool Parse(Stream stream) { 58 Error = null; 59 try { 60 StreamReader reader = new StreamReader(stream); 61 Size = int.Parse(reader.ReadLine()); 62 Distances = new double[Size, Size]; 63 Weights = new double[Size, Size]; 64 string valLine = null; 65 char[] delim = new char[] { ' ' }; 66 int read = 0; 67 int k = 0; 68 while (k < Size) { 69 if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading first matrix."); 70 valLine = reader.ReadLine(); 71 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 72 string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 73 foreach (string val in vals) { 74 Weights[k, read++] = double.Parse(val); 75 if (read == Size) { 76 read = 0; 77 k++; 78 } 55 public void Parse(Stream stream) { 56 var reader = new StreamReader(stream); 57 Size = int.Parse(reader.ReadLine()); 58 Distances = new double[Size, Size]; 59 Weights = new double[Size, Size]; 60 char[] delim = new char[] { ' ' }; 61 62 Distances = ParseMatrix(reader, delim); 63 Weights = ParseMatrix(reader, delim); 64 } 65 66 private double[,] ParseMatrix(StreamReader reader, char[] delim) { 67 int read = 0, k = 0; 68 double[,] result = new double[Size, Size]; 69 while (k < Size) { 70 if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading second matrix."); 71 string valLine = reader.ReadLine(); 72 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 73 string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 74 foreach (string val in vals) { 75 Distances[k, read++] = double.Parse(val); 76 if (read == Size) { 77 read = 0; 78 k++; 79 79 } 80 80 } 81 82 read = 0;83 k = 0;84 85 while (k < Size) {86 if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading second matrix.");87 valLine = reader.ReadLine();88 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();89 string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);90 foreach (string val in vals) {91 Distances[k, read++] = double.Parse(val);92 if (read == Size) {93 read = 0;94 k++;95 }96 }97 }98 return true;99 } catch (Exception e) {100 Error = e;101 return false;102 81 } 82 return result; 103 83 } 104 84 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/HeuristicLab.Problems.Instances.TSPLIB-3.3.csproj
r7470 r7538 45 45 </ItemGroup> 46 46 <ItemGroup> 47 <Compile Include="TSPLIBATSPInstance.cs" />48 47 <Compile Include="TSPLIBATSPInstanceProvider.cs" /> 49 <Compile Include="TSPLIBCVRPInstance.cs" />50 48 <Compile Include="TSPLIBCVRPInstanceProvider.cs" /> 51 <Compile Include="TSPLIBTSPInstance.cs" />52 49 <Compile Include="TSPLIBInstanceDescriptor.cs" /> 53 50 <Compile Include="TSPLIBTSPInstanceProvider.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/Plugin.cs.frame
r7465 r7538 25 25 [Plugin("HeuristicLab.Problems.Instances.TSPLIB", "3.3.6.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.Instances.TSPLIB-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Common", "3.3")] 28 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 27 29 public class HeuristicLabProblemsInstancesTSPLIBPlugin : PluginBase { 28 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBATSPInstanceProvider.cs
r7482 r7538 28 28 29 29 namespace HeuristicLab.Problems.Instances.TSPLIB { 30 public class TSPLIBATSPInstanceProvider : ProblemInstanceProvider< IATSPInstance> {30 public class TSPLIBATSPInstanceProvider : ProblemInstanceProvider<ATSPInstance> { 31 31 32 32 public override string Name { … … 65 65 } 66 66 67 public override IATSPInstance GetInstance(IInstanceDescriptor id) {67 public override ATSPInstance LoadInstance(IInstanceDescriptor id) { 68 68 var descriptor = (TSPLIBInstanceDescriptor)id; 69 var instance = new TSPLIBATSPInstance();70 69 using (var stream = Assembly.GetExecutingAssembly() 71 70 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { 72 var parser = new TSPLIBParser(stream); 73 parser.Parse(); 74 instance.Dimension = parser.Dimension; 75 instance.Coordinates = parser.DisplayVertices != null ? parser.DisplayVertices : parser.Vertices; 76 instance.Distances = parser.Distances; 77 78 instance.Name = parser.Name; 79 instance.Description = parser.Comment 80 + Environment.NewLine + Environment.NewLine 81 + GetDescription(); 71 var instance = Load(new TSPLIBParser(stream)); 82 72 83 73 if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) { … … 89 79 } 90 80 } 81 return instance; 91 82 } 83 } 84 85 public override ATSPInstance LoadInstance(string path) { 86 return Load(new TSPLIBParser(path)); 87 } 88 89 public override void SaveInstance(ATSPInstance instance, string path) { 90 throw new NotSupportedException(); 91 } 92 93 private ATSPInstance Load(TSPLIBParser parser) { 94 var instance = new ATSPInstance(); 95 96 parser.Parse(); 97 instance.Dimension = parser.Dimension; 98 instance.Coordinates = parser.DisplayVertices != null ? parser.DisplayVertices : parser.Vertices; 99 instance.Distances = parser.Distances; 100 101 instance.Name = parser.Name; 102 instance.Description = parser.Comment 103 + Environment.NewLine + Environment.NewLine 104 + GetDescription(); 105 92 106 return instance; 93 107 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs
r7482 r7538 28 28 29 29 namespace HeuristicLab.Problems.Instances.TSPLIB { 30 public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider< ICVRPInstance> {30 public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider<CVRPInstance> { 31 31 32 32 public override string Name { … … 64 64 } 65 65 66 public override ICVRPInstance GetInstance(IInstanceDescriptor id) {66 public override CVRPInstance LoadInstance(IInstanceDescriptor id) { 67 67 var descriptor = (TSPLIBInstanceDescriptor)id; 68 var instance = new TSPLIBCVRPInstance();69 68 using (var stream = Assembly.GetExecutingAssembly() 70 69 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { 71 var parser = new TSPLIBParser(stream); 72 parser.Parse(); 73 instance.Dimension = parser.Dimension; 74 instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices; 75 instance.Distances = parser.Distances; 76 instance.Capacity = parser.Capacity.Value; 77 instance.Demands = parser.Demands; 78 switch (parser.EdgeWeightType) { 79 case TSPLIBEdgeWeightTypes.ATT: 80 instance.DistanceMeasure = CVRPDistanceMeasure.Att; break; 81 case TSPLIBEdgeWeightTypes.CEIL_2D: 82 instance.DistanceMeasure = CVRPDistanceMeasure.UpperEuclidean; break; 83 case TSPLIBEdgeWeightTypes.EUC_2D: 84 case TSPLIBEdgeWeightTypes.EUC_3D: 85 instance.DistanceMeasure = CVRPDistanceMeasure.RoundedEuclidean; break; 86 case TSPLIBEdgeWeightTypes.EXPLICIT: 87 instance.DistanceMeasure = CVRPDistanceMeasure.Direct; break; 88 case TSPLIBEdgeWeightTypes.GEO: 89 instance.DistanceMeasure = CVRPDistanceMeasure.Geo; break; 90 case TSPLIBEdgeWeightTypes.MAN_2D: 91 case TSPLIBEdgeWeightTypes.MAN_3D: 92 instance.DistanceMeasure = CVRPDistanceMeasure.Manhattan; break; 93 case TSPLIBEdgeWeightTypes.MAX_2D: 94 case TSPLIBEdgeWeightTypes.MAX_3D: 95 instance.DistanceMeasure = CVRPDistanceMeasure.Maximum; break; 96 default: 97 throw new InvalidDataException("The given edge weight is not supported by HeuristicLab."); 98 } 99 100 instance.Name = parser.Name; 101 instance.Description = parser.Comment 102 + Environment.NewLine + Environment.NewLine 103 + GetDescription(); 70 var instance = Load(new TSPLIBParser(stream)); 104 71 105 72 if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) { … … 111 78 } 112 79 } 80 return instance; 113 81 } 82 } 83 84 public override CVRPInstance LoadInstance(string path) { 85 return Load(new TSPLIBParser(path)); 86 } 87 88 public override void SaveInstance(CVRPInstance instance, string path) { 89 throw new NotSupportedException(); 90 } 91 92 private CVRPInstance Load(TSPLIBParser parser) { 93 parser.Parse(); 94 var instance = new CVRPInstance(); 95 instance.Dimension = parser.Dimension; 96 instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices; 97 instance.Distances = parser.Distances; 98 instance.Capacity = parser.Capacity.Value; 99 instance.Demands = parser.Demands; 100 switch (parser.EdgeWeightType) { 101 case TSPLIBEdgeWeightTypes.ATT: 102 instance.DistanceMeasure = CVRPDistanceMeasure.Att; break; 103 case TSPLIBEdgeWeightTypes.CEIL_2D: 104 instance.DistanceMeasure = CVRPDistanceMeasure.UpperEuclidean; break; 105 case TSPLIBEdgeWeightTypes.EUC_2D: 106 case TSPLIBEdgeWeightTypes.EUC_3D: 107 instance.DistanceMeasure = CVRPDistanceMeasure.RoundedEuclidean; break; 108 case TSPLIBEdgeWeightTypes.EXPLICIT: 109 instance.DistanceMeasure = CVRPDistanceMeasure.Direct; break; 110 case TSPLIBEdgeWeightTypes.GEO: 111 instance.DistanceMeasure = CVRPDistanceMeasure.Geo; break; 112 case TSPLIBEdgeWeightTypes.MAN_2D: 113 case TSPLIBEdgeWeightTypes.MAN_3D: 114 instance.DistanceMeasure = CVRPDistanceMeasure.Manhattan; break; 115 case TSPLIBEdgeWeightTypes.MAX_2D: 116 case TSPLIBEdgeWeightTypes.MAX_3D: 117 instance.DistanceMeasure = CVRPDistanceMeasure.Maximum; break; 118 default: 119 throw new InvalidDataException("The given edge weight is not supported by HeuristicLab."); 120 } 121 122 instance.Name = parser.Name; 123 instance.Description = parser.Comment 124 + Environment.NewLine + Environment.NewLine 125 + GetDescription(); 126 114 127 return instance; 115 128 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBTSPInstanceProvider.cs
r7482 r7538 28 28 29 29 namespace HeuristicLab.Problems.Instances.TSPLIB { 30 public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider< ITSPInstance> {30 public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider<TSPInstance> { 31 31 32 32 public override string Name { … … 65 65 } 66 66 67 public override ITSPInstance GetInstance(IInstanceDescriptor id) {67 public override TSPInstance LoadInstance(IInstanceDescriptor id) { 68 68 var descriptor = (TSPLIBInstanceDescriptor)id; 69 var instance = new TSPLIBTSPInstance();70 69 using (var stream = Assembly.GetExecutingAssembly() 71 70 .GetManifestResourceStream(descriptor.InstanceIdentifier)) { 72 71 var parser = new TSPLIBParser(stream); 73 parser.Parse(); 74 if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab."); 75 76 instance.Dimension = parser.Dimension; 77 instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices; 78 instance.Distances = parser.Distances; 79 switch (parser.EdgeWeightType) { 80 case TSPLIBEdgeWeightTypes.ATT: 81 instance.DistanceMeasure = TSPDistanceMeasure.Att; break; 82 case TSPLIBEdgeWeightTypes.CEIL_2D: 83 instance.DistanceMeasure = TSPDistanceMeasure.UpperEuclidean; break; 84 case TSPLIBEdgeWeightTypes.EUC_2D: 85 instance.DistanceMeasure = TSPDistanceMeasure.RoundedEuclidean; break; 86 case TSPLIBEdgeWeightTypes.EUC_3D: 87 throw new InvalidDataException("3D coordinates are not supported."); 88 case TSPLIBEdgeWeightTypes.EXPLICIT: 89 instance.DistanceMeasure = TSPDistanceMeasure.Direct; break; 90 case TSPLIBEdgeWeightTypes.GEO: 91 instance.DistanceMeasure = TSPDistanceMeasure.Geo; break; 92 case TSPLIBEdgeWeightTypes.MAN_2D: 93 instance.DistanceMeasure = TSPDistanceMeasure.Manhattan; break; 94 case TSPLIBEdgeWeightTypes.MAN_3D: 95 throw new InvalidDataException("3D coordinates are not supported."); 96 case TSPLIBEdgeWeightTypes.MAX_2D: 97 instance.DistanceMeasure = TSPDistanceMeasure.Maximum; break; 98 case TSPLIBEdgeWeightTypes.MAX_3D: 99 throw new InvalidDataException("3D coordinates are not supported."); 100 default: 101 throw new InvalidDataException("The given edge weight is not supported by HeuristicLab."); 102 } 103 104 instance.Name = parser.Name; 105 instance.Description = parser.Comment 106 + Environment.NewLine + Environment.NewLine 107 + GetDescription(); 72 var instance = Load(parser); 108 73 109 74 if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) { … … 115 80 } 116 81 } 82 return instance; 117 83 } 84 } 85 86 public override TSPInstance LoadInstance(string path) { 87 return Load(new TSPLIBParser(path)); 88 } 89 90 public override void SaveInstance(TSPInstance instance, string path) { 91 throw new NotSupportedException(); 92 } 93 94 private TSPInstance Load(TSPLIBParser parser) { 95 parser.Parse(); 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 TSPInstance(); 98 instance.Dimension = parser.Dimension; 99 instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices; 100 instance.Distances = parser.Distances; 101 switch (parser.EdgeWeightType) { 102 case TSPLIBEdgeWeightTypes.ATT: 103 instance.DistanceMeasure = TSPDistanceMeasure.Att; break; 104 case TSPLIBEdgeWeightTypes.CEIL_2D: 105 instance.DistanceMeasure = TSPDistanceMeasure.UpperEuclidean; break; 106 case TSPLIBEdgeWeightTypes.EUC_2D: 107 instance.DistanceMeasure = TSPDistanceMeasure.RoundedEuclidean; break; 108 case TSPLIBEdgeWeightTypes.EUC_3D: 109 throw new InvalidDataException("3D coordinates are not supported."); 110 case TSPLIBEdgeWeightTypes.EXPLICIT: 111 instance.DistanceMeasure = TSPDistanceMeasure.Direct; break; 112 case TSPLIBEdgeWeightTypes.GEO: 113 instance.DistanceMeasure = TSPDistanceMeasure.Geo; break; 114 case TSPLIBEdgeWeightTypes.MAN_2D: 115 instance.DistanceMeasure = TSPDistanceMeasure.Manhattan; break; 116 case TSPLIBEdgeWeightTypes.MAN_3D: 117 throw new InvalidDataException("3D coordinates are not supported."); 118 case TSPLIBEdgeWeightTypes.MAX_2D: 119 instance.DistanceMeasure = TSPDistanceMeasure.Maximum; break; 120 case TSPLIBEdgeWeightTypes.MAX_3D: 121 throw new InvalidDataException("3D coordinates are not supported."); 122 default: 123 throw new InvalidDataException("The given edge weight is not supported by HeuristicLab."); 124 } 125 126 instance.Name = parser.Name; 127 instance.Description = parser.Comment 128 + Environment.NewLine + Environment.NewLine 129 + GetDescription(); 118 130 return instance; 119 131 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/HeuristicLab.Problems.Instances-3.3.csproj
r7505 r7538 51 51 </ItemGroup> 52 52 <ItemGroup> 53 <None Include="ClassDiagram1.cd" /> 53 54 <None Include="Plugin.cs.frame" /> 54 <Compile Include="Instances\IATSPInstance.cs" /> 55 <Compile Include="Instances\ICTAPInstance.cs" /> 55 <Compile Include="IExportable.cs" /> 56 <Compile Include="Instances\ATSPInstance.cs" /> 57 <Compile Include="Instances\CTAPInstance.cs" /> 56 58 <Compile Include="IInstanceDescriptor.cs" /> 57 <Compile Include="Instances\ ICVRPInstance.cs" />58 <Compile Include="Instances\ IGQAPInstance.cs" />59 <Compile Include="Instances\ IQAPInstance.cs" />60 <Compile Include="Instances\ ITSPInstance.cs" />61 <Compile Include="I ProblemInstanceConsumer.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="IConsumable.cs" /> 62 64 <Compile Include="IProblemInstanceProvider.cs" /> 63 65 <Compile Include="Plugin.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/IProblemInstanceProvider.cs
r7482 r7538 30 30 Uri WebLink { get; } 31 31 string ReferencePublication { get; } 32 33 bool ConsumerCanBeFed { get; }34 35 void SetConsumer(IProblemInstanceConsumer consumer);36 bool FeedConsumer(IInstanceDescriptor descriptor);37 38 IEnumerable<IInstanceDescriptor> GetInstanceDescriptors();39 32 } 40 33 41 34 public interface IProblemInstanceProvider<TInstance> : IProblemInstanceProvider { 42 TInstance GetInstance(IInstanceDescriptor descriptor); 35 IConsumable<TInstance> Consumer { get; set; } 36 37 IEnumerable<IInstanceDescriptor> GetInstanceDescriptors(); 38 TInstance LoadInstance(IInstanceDescriptor descriptor); 39 TInstance LoadInstance(string path); 40 41 void SaveInstance(TInstance instance, string path); 43 42 } 44 43 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/Plugin.cs.frame
r7443 r7538 25 25 [Plugin("HeuristicLab.Problems.Instances", "3.3.6.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.Instances-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Common", "3.3")] 27 28 public class HeuristicLabProblemsInstancesPlugin : PluginBase { 28 29 } -
branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/ProblemInstanceProvider.cs
r7482 r7538 24 24 25 25 namespace HeuristicLab.Problems.Instances { 26 public abstract class ProblemInstanceProvider<T > : IProblemInstanceProvider<T> {27 p rivate IProblemInstanceConsumer<T> Consumer { get; set; }26 public abstract class ProblemInstanceProvider<TInstance> : IProblemInstanceProvider<TInstance> { 27 public virtual IConsumable<TInstance> Consumer { get; set; } 28 28 29 29 public abstract string Name { get; } … … 32 32 public abstract string ReferencePublication { get; } 33 33 34 public bool ConsumerCanBeFed {35 get { return Consumer != null; }36 }37 38 public void SetConsumer(IProblemInstanceConsumer consumer) {39 if (consumer is IProblemInstanceConsumer<T>)40 Consumer = (IProblemInstanceConsumer<T>)consumer;41 else Consumer = null;42 }43 44 public bool FeedConsumer(IInstanceDescriptor descriptor) {45 return Consumer.LoadFrom(GetInstance(descriptor));46 }47 48 34 public abstract IEnumerable<IInstanceDescriptor> GetInstanceDescriptors(); 49 35 50 public abstract T GetInstance(IInstanceDescriptor descriptor); 36 public abstract TInstance LoadInstance(IInstanceDescriptor descriptor); 37 public abstract TInstance LoadInstance(string path); 51 38 39 public abstract void SaveInstance(TInstance instance, string path); 52 40 } 53 41 } -
branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs
r7523 r7538 34 34 public void CordeauCrossoverFunctionalityTest() { 35 35 var provider = new CordeauGQAPInstanceProvider(); 36 var instance = provider. GetInstance(provider.GetInstanceDescriptors().First());36 var instance = provider.LoadInstance(provider.GetInstanceDescriptors().First()); 37 37 var gqap = new GeneralizedQuadraticAssignmentProblem(); 38 38 gqap.LoadFrom(instance); -
branches/GeneralizedQAP/UnitTests/CordeauGQAPInstanceProviderTest.cs
r7505 r7538 36 36 foreach (var id in target.GetInstanceDescriptors()) { 37 37 try { 38 target. GetInstance(id);38 target.LoadInstance(id); 39 39 } catch (Exception ex) { 40 40 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); -
branches/GeneralizedQAP/UnitTests/ElloumiCTAPInstanceProviderTest.cs
r7505 r7538 36 36 foreach (var id in target.GetInstanceDescriptors()) { 37 37 try { 38 target. GetInstance(id);38 target.LoadInstance(id); 39 39 } catch (Exception ex) { 40 40 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); -
branches/GeneralizedQAP/UnitTests/QAPLIBInstanceProviderTest.cs
r7523 r7538 37 37 foreach (var id in target.GetInstanceDescriptors()) { 38 38 try { 39 target. GetInstance(id);39 target.LoadInstance(id); 40 40 } catch (Exception ex) { 41 41 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); … … 55 55 var target = new QAPLIBInstanceProvider(); 56 56 foreach (var id in target.GetInstanceDescriptors()) { 57 var instance = target. GetInstance(id);57 var instance = target.LoadInstance(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
r7505 r7538 36 36 foreach (var id in target.GetInstanceDescriptors()) { 37 37 try { 38 target. GetInstance(id);38 target.LoadInstance(id); 39 39 } catch (Exception ex) { 40 40 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); … … 53 53 foreach (var id in target.GetInstanceDescriptors()) { 54 54 try { 55 target. GetInstance(id);55 target.LoadInstance(id); 56 56 } catch (Exception ex) { 57 57 erroneousInstances.AppendLine(id.Name + ": " + ex.Message); … … 70 70 foreach (var id in target.GetInstanceDescriptors()) { 71 71 try { 72 target. GetInstance(id);72 target.LoadInstance(id); 73 73 } catch (Exception ex) { 74 74 erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
Note: See TracChangeset
for help on using the changeset viewer.