Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/01/12 15:15:22 (13 years ago)
Author:
abeham
Message:

#1614

  • Fixed plugin dependencies
  • Updated GQAP view
  • Changed instances infrastructure
    • Changed interface types into classes
    • Removed the library specific instance classes
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  
    3636  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    3737  [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")]
     38  [PluginDependency("HeuristicLab.Random", "3.3")]
     39  [PluginDependency("HeuristicLab.Selection", "3.3")]
    3840  public class HeuristicLabProblemsGeneralizedQuadraticAssignmentAlgorithmsPlugin : PluginBase {
    3941  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common/3.3/Plugin.cs.frame

    r7363 r7538  
    2525  [Plugin("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3.0.$WCREV$")]
    2626  [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")]
    2737  public class HeuristicLabProblemsGeneralizedQuadraticAssignmentCommonPlugin : PluginBase {
    2838  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/Plugin.cs.frame

    r7363 r7538  
    2525  [Plugin("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Collections", "3.3")]
    2728  [PluginDependency("HeuristicLab.Common", "3.3")]
    2829  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
     
    3031  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
    3132  [PluginDependency("HeuristicLab.Data", "3.3")]
     33  [PluginDependency("HeuristicLab.Data.Views", "3.3")]
    3234  [PluginDependency("HeuristicLab.Encodings.IntegerVectorEncoding", "3.3")]
    3335  [PluginDependency("HeuristicLab.MainForm", "3.3")]
     
    3739  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3840  [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment", "3.3")]
     41  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
     42  [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")]
    3943  public class HeuristicLabProblemsGeneralizedQuadraticAssignmentViewsPlugin : PluginBase {
    4044  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.Designer.cs

    r7523 r7538  
    2121
    2222namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
    23   partial class ProblemInstanceProviderView {
     23  partial class ProblemInstanceProviderView<T> {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    4848      this.label2 = new System.Windows.Forms.Label();
    4949      this.instancesComboBox = new System.Windows.Forms.ComboBox();
     50      this.importButton = new System.Windows.Forms.Button();
     51      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    5052      this.SuspendLayout();
    5153      //
     
    5355      //
    5456      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);
    5658      this.loadButton.Name = "loadButton";
    5759      this.loadButton.Size = new System.Drawing.Size(75, 23);
     
    7880      this.instancesComboBox.Location = new System.Drawing.Point(54, 0);
    7981      this.instancesComboBox.Name = "instancesComboBox";
    80       this.instancesComboBox.Size = new System.Drawing.Size(475, 21);
     82      this.instancesComboBox.Size = new System.Drawing.Size(391, 21);
    8183      this.instancesComboBox.TabIndex = 7;
    8284      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|*.*";
    83101      //
    84102      // ProblemInstanceProviderView
     
    87105      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    88106      this.Controls.Add(this.instancesComboBox);
     107      this.Controls.Add(this.importButton);
    89108      this.Controls.Add(this.loadButton);
    90109      this.Controls.Add(this.label2);
     
    101120    private System.Windows.Forms.Label label2;
    102121    private System.Windows.Forms.ComboBox instancesComboBox;
     122    private System.Windows.Forms.Button importButton;
     123    private System.Windows.Forms.OpenFileDialog openFileDialog;
    103124
    104125  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs

    r7505 r7538  
    2323using System.Linq;
    2424using System.Windows.Forms;
     25using HeuristicLab.Common.Resources;
    2526using HeuristicLab.MainForm;
    2627using HeuristicLab.MainForm.WindowsForms;
     
    2930namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
    3031  [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 {
    3334
    34     public new IProblemInstanceProvider Content {
    35       get { return (IProblemInstanceProvider)base.Content; }
     35    public new IProblemInstanceProvider<T> Content {
     36      get { return (IProblemInstanceProvider<T>)base.Content; }
    3637      set { base.Content = value; }
    3738    }
     
    3940    public ProblemInstanceProviderView() {
    4041      InitializeComponent();
     42      importButton.Image = VSImageLibrary.Open;
    4143    }
    4244
     
    5355    protected override void SetEnabledStateOfControls() {
    5456      base.SetEnabledStateOfControls();
    55       instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
    56       loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
     57      instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
     58      loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
    5759    }
    5860
    5961    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        }
    6385      }
    6486    }
     
    6991        comboBox.Items.Clear();
    7092    }
    71 
    72     private void instancesComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {
    73       var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;
    74       e.ToolTip = instance.Description;
    75     }
    7693  }
    7794}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.resx

    r7448 r7538  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </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>
    120123</root>
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.Designer.cs

    r7482 r7538  
    103103      // problemInstanceProviderComboBox
    104104      //
    105       this.problemInstanceProviderComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
     105      this.problemInstanceProviderComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
    106106      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)));
    107108      this.problemInstanceProviderComboBox.FormattingEnabled = true;
    108109      this.problemInstanceProviderComboBox.Location = new System.Drawing.Point(50, 5);
     110      this.problemInstanceProviderComboBox.MaxDropDownItems = 16;
    109111      this.problemInstanceProviderComboBox.Name = "problemInstanceProviderComboBox";
    110112      this.problemInstanceProviderComboBox.Size = new System.Drawing.Size(173, 21);
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemView.cs

    r7523 r7538  
    6363      if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
    6464        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 });
    6667        problemInstanceProviderViewHost.Content = provider;
    6768      }
     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;
    6876    }
    6977
     
    7785      var consumerTypes = Content.GetType().GetInterfaces()
    7886        .Where(x => x.IsGenericType
    79           && typeof(IProblemInstanceConsumer).IsAssignableFrom(x));
     87          && x.GetGenericTypeDefinition() == typeof(IConsumable<>));
    8088
    8189      if (consumerTypes.Any()) {
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.Designer.cs

    r7482 r7538  
    4848      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    4949      this.SuspendLayout();
     50      //
     51      // ToolTipComboBox
     52      //
     53      this.MaxDropDownItems = 16;
    5054      this.ResumeLayout(false);
    5155
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs

    r7523 r7538  
    2929
    3030    private ComboBoxState comboBoxState = ComboBoxState.Normal;
    31     private bool mouseOver = false;
    3231
    3332    public ToolTipComboBox()
     
    3635      SetStyle(ControlStyles.UserPaint, true);
    3736      InitializeComponent();
    38       DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
     37      DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
    3938      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;
    4939    }
    5040
     
    7262        } else {
    7363          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);
    7766          }
    7867        }
     
    8473      base.OnPaint(e);
    8574      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 time
    87       clip.Offset(-clip.X, -clip.Y); // x and y need to be 0
     75      Rectangle clip = new Rectangle(new Point(0, 0), Size);
     76      clip.Inflate(0, 1);
    8877      if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser) {
    8978        PushButtonState pb_State = PushButtonState.Normal;
     
    10998        ComboBoxRenderer.DrawDropDownButton(e.Graphics, r, comboBoxState);
    11099      }
    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);
    114101      if (SelectedIndex > -1 && Items.Count > 0) {
    115102        using (var b = new SolidBrush(ForeColor)) {
     
    141128    protected override void OnMouseEnter(EventArgs e) {
    142129      base.OnMouseEnter(e);
    143       mouseOver = true;
    144130      if (comboBoxState == ComboBoxState.Normal) {
    145131        comboBoxState = ComboBoxState.Hot;
     
    158144    protected override void OnMouseLeave(EventArgs e) {
    159145      base.OnMouseLeave(e);
    160       mouseOver = false;
    161146      if (comboBoxState == ComboBoxState.Hot) {
    162147        comboBoxState = ComboBoxState.Normal;
     
    167152    protected override void OnMouseDown(MouseEventArgs e) {
    168153      base.OnMouseDown(e);
    169       comboBoxState = ComboBoxState.Pressed;
    170       Invalidate();
     154      if (e.Button == MouseButtons.Left) {
     155        comboBoxState = ComboBoxState.Pressed;
     156        Invalidate();
     157      }
    171158    }
    172159
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs

    r7523 r7538  
    3939  [StorableClass]
    4040  public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent,
    41     IProblemInstanceConsumer<IQAPInstance>,
    42     IProblemInstanceConsumer<ICTAPInstance>,
    43     IProblemInstanceConsumer<ITSPInstance>,
    44     IProblemInstanceConsumer<IATSPInstance>,
    45     IProblemInstanceConsumer<IGQAPInstance> {
     41    IConsumable<QAPInstance>,
     42    IConsumable<CTAPInstance>,
     43    IConsumable<TSPInstance>,
     44    IConsumable<ATSPInstance>,
     45    IConsumable<GQAPInstance> {
    4646
    4747    public override Image ItemImage {
     
    214214
    215215    #region Problem Instance Consumptions
    216     public bool LoadFrom(IQAPInstance instance) {
     216    public bool LoadFrom(QAPInstance instance) {
    217217      try {
    218218        Name = instance.Name;
     
    240240    }
    241241
    242     public bool LoadFrom(ICTAPInstance instance) {
     242    public bool LoadFrom(CTAPInstance instance) {
    243243      try {
    244244        Name = instance.Name;
     
    270270    }
    271271
    272     public bool LoadFrom(ITSPInstance instance) {
     272    public bool LoadFrom(TSPInstance instance) {
    273273      try {
    274274        if (instance.Dimension > 1000) return false;
     
    304304    }
    305305
    306     public bool LoadFrom(IATSPInstance instance) {
     306    public bool LoadFrom(ATSPInstance instance) {
    307307      try {
    308308        Name = instance.Name;
     
    336336    }
    337337
    338     public bool LoadFrom(IGQAPInstance instance) {
     338    public bool LoadFrom(GQAPInstance instance) {
    339339      try {
    340340        Name = instance.Name;
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Plugin.cs.frame

    r7363 r7538  
    2525  [Plugin("HeuristicLab.Problems.GeneralizedQuadraticAssignment", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    2728  [PluginDependency("HeuristicLab.Collections", "3.3")]
    2829  [PluginDependency("HeuristicLab.Common", "3.3")]
     
    3334  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3435  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     36  [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]
    3537  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3638  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    3739  [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")]
     40  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    3841  public class HeuristicLabProblemsGeneralizedQuadraticAssignmentPlugin : PluginBase {
    3942  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPInstanceProvider.cs

    r7523 r7538  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using System.Linq;
    2526using System.Reflection;
     
    2728
    2829namespace HeuristicLab.Problems.Instances.CordeauGQAP {
    29   public class CordeauGQAPInstanceProvider : ProblemInstanceProvider<IGQAPInstance> {
     30  public class CordeauGQAPInstanceProvider : ProblemInstanceProvider<GQAPInstance> {
    3031    public override string Name {
    3132      get { return "Cordeau et al. GQAP instances"; }
     
    5657    }
    5758
    58     public override IGQAPInstance GetInstance(IInstanceDescriptor id) {
     59    public override GQAPInstance LoadInstance(IInstanceDescriptor id) {
    5960      var descriptor = (CordeauGQAPInstanceDescriptor)id;
    60       var instance = new CordeauGQAPInstance();
    6161      using (var stream = Assembly.GetExecutingAssembly()
    6262        .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
    6363        var parser = new CordeauGQAPParser();
    6464        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);
    7466
    7567        instance.Name = id.Name;
    7668        instance.Description = id.Description;
     69
     70        return instance;
    7771      }
     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;
    7899      return instance;
    79100    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPParser.cs

    r7505 r7538  
    3434    public double[] Demands { get; private set; }
    3535    public double[] Capacities { get; private set; }
    36     public Exception Error { get; private set; }
    3736
    3837    public CordeauGQAPParser() {
     
    4847      Demands = null;
    4948      Capacities = null;
    50       Error = null;
    5149    }
    5250
    53     public bool Parse(string file) {
     51    public void Parse(string file) {
    5452      using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
    55         return Parse(stream);
     53        Parse(stream);
    5654      }
    5755    }
     
    6462    /// </remarks>
    6563    /// <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) {
    6965      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);
    7368
    74         var info = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    75         Equipments = int.Parse(info[0]);
    76         Locations = int.Parse(info[1]);
    77         TransportationCosts = double.Parse(info[2]);
     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]);
    7873
     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        }
    7982        line = Continue(reader);
     83      }
    8084
    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);
    8890        }
     91        line = Continue(reader);
     92      }
    8993
    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      }
    98101
    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);
    106106
    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);
    111108
    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);
    124113    }
    125114
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/HeuristicLab.Problems.Instances.CordeauGQAP-3.3.csproj

    r7505 r7538  
    111111    <None Include="Plugin.cs.frame" />
    112112    <Compile Include="CordeauGQAPParser.cs" />
    113     <Compile Include="CordeauGQAPInstance.cs" />
    114113    <Compile Include="CordeauGQAPInstanceProvider.cs" />
    115114    <Compile Include="CordeauGQAPInstanceDescriptor.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/Plugin.cs.frame

    r7505 r7538  
    2525  [Plugin("HeuristicLab.Problems.Instances.CordeauGQAP", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.Instances.CordeauGQAP-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Common", "3.3")]
     28  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    2729  public class HeuristicLabProblemsInstancesCordeauGQAPPlugin : PluginBase {
    2830  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPInstanceProvider.cs

    r7482 r7538  
    2828
    2929namespace HeuristicLab.Problems.Instances.ElloumiCTAP {
    30   public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider<ICTAPInstance> {
     30  public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider<CTAPInstance> {
    3131    public override string Name {
    3232      get { return "Elloumi's CTAP instances"; }
     
    6262    }
    6363
    64     public override ICTAPInstance GetInstance(IInstanceDescriptor id) {
     64    public override CTAPInstance LoadInstance(IInstanceDescriptor id) {
    6565      var descriptor = (ElloumiCTAPInstanceDescriptor)id;
    66       var instance = new ElloumiCTAPInstance();
    6766      using (var stream = Assembly.GetExecutingAssembly()
    6867        .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);
    7871
    7972        instance.Name = id.Name;
     
    9184          }
    9285        }
     86        return instance;
    9387      }
     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;
    94111      return instance;
    95112    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPParser.cs

    r7448 r7538  
    3232    public double[] MemoryRequirements { get; private set; }
    3333    public double[] MemoryCapacities { get; private set; }
    34     public Exception Error { get; private set; }
    3534
    3635    public ElloumiCTAPParser() {
     
    4544      MemoryRequirements = null;
    4645      MemoryCapacities = null;
    47       Error = null;
    4846    }
    4947
    50     public bool Parse(string file) {
     48    public void Parse(string file) {
    5149      using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
    52         return Parse(stream);
     50        Parse(stream);
    5351      }
    5452    }
     
    6260    /// <param name="stream">The stream to read data from.</param>
    6361    /// <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) {
    6663      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);
    7066
    71         Tasks = int.Parse(line);
     67      Tasks = int.Parse(line);
    7268
     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);
    7380        line = Continue(reader);
     81      }
    7482
    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      }
    7692
    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);
    7897
    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);
    8699
    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);
    96104
    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       }
    114105    }
    115106
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/HeuristicLab.Problems.Instances.ElloumiCTAP-3.3.csproj

    r7448 r7538  
    133133    <EmbeddedResource Include="Data\tassc2005De.dat" />
    134134    <None Include="Plugin.cs.frame" />
    135     <Compile Include="ElloumiCTAPInstance.cs" />
    136135    <Compile Include="ElloumiCTAPInstanceDescriptor.cs" />
    137136    <Compile Include="ElloumiCTAPInstanceProvider.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/Plugin.cs.frame

    r7443 r7538  
    2525  [Plugin("HeuristicLab.Problems.Instances.ElloumiCTAP", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.Instances.ElloumiCTAP-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Common", "3.3")]
     28  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    2729  public class HeuristicLabProblemsInstancesElloumiCTAPPlugin : PluginBase {
    2830  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/HeuristicLab.Problems.Instances.QAPLIB-3.3.csproj

    r7448 r7538  
    5151  <ItemGroup>
    5252    <Compile Include="QAPLIBParser.cs" />
    53     <Compile Include="QAPLIBInstance.cs" />
    5453    <Compile Include="QAPLIBInstanceDescriptor.cs" />
    5554    <Compile Include="QAPLIBSolutionParser.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/Plugin.cs.frame

    r7443 r7538  
    2525  [Plugin("HeuristicLab.Problems.Instances.QAPLIB", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.Instances.QAPLIB-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Common", "3.3")]
     28  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    2729  public class HeuristicLabProblemsInstancesQAPLIBPlugin : PluginBase {
    2830  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBInstanceProvider.cs

    r7482 r7538  
    2828
    2929namespace HeuristicLab.Problems.Instances.QAPLIB {
    30   public class QAPLIBInstanceProvider : ProblemInstanceProvider<IQAPInstance> {
     30  public class QAPLIBInstanceProvider : ProblemInstanceProvider<QAPInstance> {
    3131    public override string Name {
    3232      get { return "QAPLIB"; }
     
    6262    }
    6363
    64     public override IQAPInstance GetInstance(IInstanceDescriptor id) {
     64    public override QAPInstance LoadInstance(IInstanceDescriptor id) {
    6565      var descriptor = (QAPLIBInstanceDescriptor)id;
    66       var instance = new QAPLIBInstance();
    6766      using (var stream = Assembly.GetExecutingAssembly()
    6867        .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);
    7671        instance.Name = id.Name;
    7772        instance.Description = id.Description;
     
    8075          using (Stream solStream = Assembly.GetExecutingAssembly()
    8176            .GetManifestResourceStream(descriptor.SolutionIdentifier)) {
    82             QAPLIBSolutionParser slnParser = new QAPLIBSolutionParser();
     77            var slnParser = new QAPLIBSolutionParser();
    8378            slnParser.Parse(solStream, true);
    8479            if (slnParser.Error != null) throw slnParser.Error;
     
    8883          }
    8984        }
     85        return instance;
    9086      }
     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;
    91107      return instance;
    92108    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBParser.cs

    r7445 r7538  
    2828    public double[,] Distances { get; private set; }
    2929    public double[,] Weights { get; private set; }
    30     public Exception Error { get; private set; }
    3130
    3231    public QAPLIBParser() {
     
    3837      Distances = null;
    3938      Weights = null;
    40       Error = null;
    4139    }
    4240
    43     public bool Parse(string file) {
     41    public void Parse(string file) {
    4442      using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
    45         return Parse(stream);
     43        Parse(stream);
    4644      }
    4745    }
     
    5553    /// <param name="stream">The stream to read data from.</param>
    5654    /// <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++;
    7979          }
    8080        }
    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;
    10281      }
     82      return result;
    10383    }
    10484  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/HeuristicLab.Problems.Instances.TSPLIB-3.3.csproj

    r7470 r7538  
    4545  </ItemGroup>
    4646  <ItemGroup>
    47     <Compile Include="TSPLIBATSPInstance.cs" />
    4847    <Compile Include="TSPLIBATSPInstanceProvider.cs" />
    49     <Compile Include="TSPLIBCVRPInstance.cs" />
    5048    <Compile Include="TSPLIBCVRPInstanceProvider.cs" />
    51     <Compile Include="TSPLIBTSPInstance.cs" />
    5249    <Compile Include="TSPLIBInstanceDescriptor.cs" />
    5350    <Compile Include="TSPLIBTSPInstanceProvider.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/Plugin.cs.frame

    r7465 r7538  
    2525  [Plugin("HeuristicLab.Problems.Instances.TSPLIB", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.Instances.TSPLIB-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Common", "3.3")]
     28  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    2729  public class HeuristicLabProblemsInstancesTSPLIBPlugin : PluginBase {
    2830  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBATSPInstanceProvider.cs

    r7482 r7538  
    2828
    2929namespace HeuristicLab.Problems.Instances.TSPLIB {
    30   public class TSPLIBATSPInstanceProvider : ProblemInstanceProvider<IATSPInstance> {
     30  public class TSPLIBATSPInstanceProvider : ProblemInstanceProvider<ATSPInstance> {
    3131
    3232    public override string Name {
     
    6565    }
    6666
    67     public override IATSPInstance GetInstance(IInstanceDescriptor id) {
     67    public override ATSPInstance LoadInstance(IInstanceDescriptor id) {
    6868      var descriptor = (TSPLIBInstanceDescriptor)id;
    69       var instance = new TSPLIBATSPInstance();
    7069      using (var stream = Assembly.GetExecutingAssembly()
    7170        .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));
    8272
    8373        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
     
    8979          }
    9080        }
     81        return instance;
    9182      }
     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
    92106      return instance;
    93107    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs

    r7482 r7538  
    2828
    2929namespace HeuristicLab.Problems.Instances.TSPLIB {
    30   public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider<ICVRPInstance> {
     30  public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider<CVRPInstance> {
    3131
    3232    public override string Name {
     
    6464    }
    6565
    66     public override ICVRPInstance GetInstance(IInstanceDescriptor id) {
     66    public override CVRPInstance LoadInstance(IInstanceDescriptor id) {
    6767      var descriptor = (TSPLIBInstanceDescriptor)id;
    68       var instance = new TSPLIBCVRPInstance();
    6968      using (var stream = Assembly.GetExecutingAssembly()
    7069        .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));
    10471
    10572        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
     
    11178          }
    11279        }
     80        return instance;
    11381      }
     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
    114127      return instance;
    115128    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBTSPInstanceProvider.cs

    r7482 r7538  
    2828
    2929namespace HeuristicLab.Problems.Instances.TSPLIB {
    30   public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider<ITSPInstance> {
     30  public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider<TSPInstance> {
    3131
    3232    public override string Name {
     
    6565    }
    6666
    67     public override ITSPInstance GetInstance(IInstanceDescriptor id) {
     67    public override TSPInstance LoadInstance(IInstanceDescriptor id) {
    6868      var descriptor = (TSPLIBInstanceDescriptor)id;
    69       var instance = new TSPLIBTSPInstance();
    7069      using (var stream = Assembly.GetExecutingAssembly()
    7170        .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
    7271        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);
    10873
    10974        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
     
    11580          }
    11681        }
     82        return instance;
    11783      }
     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();
    118130      return instance;
    119131    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/HeuristicLab.Problems.Instances-3.3.csproj

    r7505 r7538  
    5151  </ItemGroup>
    5252  <ItemGroup>
     53    <None Include="ClassDiagram1.cd" />
    5354    <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" />
    5658    <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="IProblemInstanceConsumer.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" />
    6264    <Compile Include="IProblemInstanceProvider.cs" />
    6365    <Compile Include="Plugin.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/IProblemInstanceProvider.cs

    r7482 r7538  
    3030    Uri WebLink { get; }
    3131    string ReferencePublication { get; }
    32 
    33     bool ConsumerCanBeFed { get; }
    34 
    35     void SetConsumer(IProblemInstanceConsumer consumer);
    36     bool FeedConsumer(IInstanceDescriptor descriptor);
    37 
    38     IEnumerable<IInstanceDescriptor> GetInstanceDescriptors();
    3932  }
    4033
    4134  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);
    4342  }
    4443}
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/Plugin.cs.frame

    r7443 r7538  
    2525  [Plugin("HeuristicLab.Problems.Instances", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.Instances-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Common", "3.3")]
    2728  public class HeuristicLabProblemsInstancesPlugin : PluginBase {
    2829  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/ProblemInstanceProvider.cs

    r7482 r7538  
    2424
    2525namespace HeuristicLab.Problems.Instances {
    26   public abstract class ProblemInstanceProvider<T> : IProblemInstanceProvider<T> {
    27     private IProblemInstanceConsumer<T> Consumer { get; set; }
     26  public abstract class ProblemInstanceProvider<TInstance> : IProblemInstanceProvider<TInstance> {
     27    public virtual IConsumable<TInstance> Consumer { get; set; }
    2828
    2929    public abstract string Name { get; }
     
    3232    public abstract string ReferencePublication { get; }
    3333
    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 
    4834    public abstract IEnumerable<IInstanceDescriptor> GetInstanceDescriptors();
    4935
    50     public abstract T GetInstance(IInstanceDescriptor descriptor);
     36    public abstract TInstance LoadInstance(IInstanceDescriptor descriptor);
     37    public abstract TInstance LoadInstance(string path);
    5138
     39    public abstract void SaveInstance(TInstance instance, string path);
    5240  }
    5341}
  • branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs

    r7523 r7538  
    3434    public void CordeauCrossoverFunctionalityTest() {
    3535      var provider = new CordeauGQAPInstanceProvider();
    36       var instance = provider.GetInstance(provider.GetInstanceDescriptors().First());
     36      var instance = provider.LoadInstance(provider.GetInstanceDescriptors().First());
    3737      var gqap = new GeneralizedQuadraticAssignmentProblem();
    3838      gqap.LoadFrom(instance);
  • branches/GeneralizedQAP/UnitTests/CordeauGQAPInstanceProviderTest.cs

    r7505 r7538  
    3636      foreach (var id in target.GetInstanceDescriptors()) {
    3737        try {
    38           target.GetInstance(id);
     38          target.LoadInstance(id);
    3939        } catch (Exception ex) {
    4040          erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
  • branches/GeneralizedQAP/UnitTests/ElloumiCTAPInstanceProviderTest.cs

    r7505 r7538  
    3636      foreach (var id in target.GetInstanceDescriptors()) {
    3737        try {
    38           target.GetInstance(id);
     38          target.LoadInstance(id);
    3939        } catch (Exception ex) {
    4040          erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
  • branches/GeneralizedQAP/UnitTests/QAPLIBInstanceProviderTest.cs

    r7523 r7538  
    3737      foreach (var id in target.GetInstanceDescriptors()) {
    3838        try {
    39           target.GetInstance(id);
     39          target.LoadInstance(id);
    4040        } catch (Exception ex) {
    4141          erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
     
    5555      var target = new QAPLIBInstanceProvider();
    5656      foreach (var id in target.GetInstanceDescriptors()) {
    57         var instance = target.GetInstance(id);
     57        var instance = target.LoadInstance(id);
    5858        for (int i = 0; i < instance.Dimension; i++)
    5959          if (instance.Distances[i, i] != 0 || instance.Weights[i, i] != 0) {
  • branches/GeneralizedQAP/UnitTests/TSPLIBInstanceProviderTest.cs

    r7505 r7538  
    3636      foreach (var id in target.GetInstanceDescriptors()) {
    3737        try {
    38           target.GetInstance(id);
     38          target.LoadInstance(id);
    3939        } catch (Exception ex) {
    4040          erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
     
    5353      foreach (var id in target.GetInstanceDescriptors()) {
    5454        try {
    55           target.GetInstance(id);
     55          target.LoadInstance(id);
    5656        } catch (Exception ex) {
    5757          erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
     
    7070      foreach (var id in target.GetInstanceDescriptors()) {
    7171        try {
    72           target.GetInstance(id);
     72          target.LoadInstance(id);
    7373        } catch (Exception ex) {
    7474          erroneousInstances.AppendLine(id.Name + ": " + ex.Message);
Note: See TracChangeset for help on using the changeset viewer.