Changeset 7448


Ignore:
Timestamp:
02/03/12 18:22:41 (9 years ago)
Author:
abeham
Message:

#1614

  • Added Transpose() extension method for double[,] matrices
  • Added IProblemInstanceConsumer<T> interface
  • Implemented general ProblemView which auto-detects all instances a problem can consume
  • Added ability of IProblemInstanceProvider to directly feed a consumer
  • Implemented general view for problem instance providers
  • Fixed a few bugs
Location:
branches/GeneralizedQAP
Files:
7 added
3 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common/3.3/ExtensionMethods.cs

    r7432 r7448  
    331331    }
    332332    #endregion
     333
     334    #region Matrix operations
     335    public static double[,] Transpose(this double[,] matrix) {
     336      var result = new double[matrix.GetLength(1), matrix.GetLength(0)];
     337      for (int i = 0; i < matrix.GetLength(0); i++)
     338        for (int j = 0; j < matrix.GetLength(1); j++)
     339          result[j, i] = matrix[i, j];
     340      return result;
     341    }
     342    #endregion
    333343  }
    334344}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs

    r7438 r7448  
    210210          kvp.Key.BackColor = assignmentTreeView.BackColor;
    211211          kvp.Key.ForeColor = assignmentTreeView.ForeColor;
    212         }
    213         int colorComponent = (int)(255 * Math.Pow((max - kvp.Value) / max, 2));
    214         kvp.Key.BackColor = Color.FromArgb(255, colorComponent, colorComponent);
    215         if (kvp.Key.BackColor.GetBrightness() < BrightnessLevel) kvp.Key.ForeColor = Color.White;
    216         else kvp.Key.ForeColor = Color.Black;
     212        } else {
     213          int colorComponent = (int)(255 * Math.Pow((max - kvp.Value) / max, 2));
     214          kvp.Key.BackColor = Color.FromArgb(255, colorComponent, colorComponent);
     215          if (kvp.Key.BackColor.GetBrightness() < BrightnessLevel) kvp.Key.ForeColor = Color.White;
     216          else kvp.Key.ForeColor = Color.Black;
     217        }
    217218      }
    218219    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views-3.3.csproj

    r7445 r7448  
    8888  </ItemGroup>
    8989  <ItemGroup>
    90     <Compile Include="GQAPProblemView.cs">
     90    <Compile Include="ProblemInstanceProviderView.cs">
    9191      <SubType>UserControl</SubType>
    9292    </Compile>
    93     <Compile Include="GQAPProblemView.Designer.cs">
    94       <DependentUpon>GQAPProblemView.cs</DependentUpon>
     93    <Compile Include="ProblemInstanceProviderView.Designer.cs">
     94      <DependentUpon>ProblemInstanceProviderView.cs</DependentUpon>
     95    </Compile>
     96    <Compile Include="ProblemView.cs">
     97      <SubType>UserControl</SubType>
     98    </Compile>
     99    <Compile Include="ProblemView.Designer.cs">
     100      <DependentUpon>ProblemView.cs</DependentUpon>
    95101    </Compile>
    96102    <Compile Include="GQAPAssignmentArchiveView.cs">
     
    125131  </ItemGroup>
    126132  <ItemGroup>
    127     <EmbeddedResource Include="GQAPProblemView.resx">
    128       <DependentUpon>GQAPProblemView.cs</DependentUpon>
     133    <EmbeddedResource Include="ProblemInstanceProviderView.resx">
     134      <DependentUpon>ProblemInstanceProviderView.cs</DependentUpon>
     135    </EmbeddedResource>
     136    <EmbeddedResource Include="ProblemView.resx">
     137      <DependentUpon>ProblemView.cs</DependentUpon>
    129138    </EmbeddedResource>
    130139    <EmbeddedResource Include="GQAPAssignmentArchiveView.resx">
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/GQAPSolutionArchiveUpdater.cs

    r7438 r7448  
    3131      for (int i = 0; i < front.Count - 1; i++) {
    3232        for (int j = i + 1; j < front.Count; j++) {
    33           if (front[i].FlowDistanceQuality.Value < front[j].FlowDistanceQuality.Value
    34             && front[i].InstallationQuality.Value < front[j].InstallationQuality.Value) {
     33          if (front[i].FlowDistanceQuality.Value <= front[j].FlowDistanceQuality.Value
     34            && front[i].InstallationQuality.Value <= front[j].InstallationQuality.Value) {
    3535            front.RemoveAt(j);
    3636            j--;
    37           } else if (front[i].FlowDistanceQuality.Value > front[j].FlowDistanceQuality.Value
    38             && front[i].InstallationQuality.Value > front[j].InstallationQuality.Value) {
     37          } else if (front[i].FlowDistanceQuality.Value >= front[j].FlowDistanceQuality.Value
     38            && front[i].InstallationQuality.Value >= front[j].InstallationQuality.Value) {
    3939            front.RemoveAt(i);
    4040            j = i;
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs

    r7445 r7448  
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3232using HeuristicLab.PluginInfrastructure;
     33using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common;
    3334using HeuristicLab.Problems.Instances;
    3435
     
    3738  [Creatable("Problems")]
    3839  [StorableClass]
    39   public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent {
     40  public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent, IProblemInstanceConsumer<IQAPInstance>, IProblemInstanceConsumer<ICTAPInstance> {
    4041
    4142    public override Image ItemImage {
     
    138139      set { BestKnownSolutionParameter.Value = value; }
    139140    }
     141    public GQAPAssignmentArchive BestKnownSolutions {
     142      get { return BestKnownSolutionsParameter.Value; }
     143      set { BestKnownSolutionsParameter.Value = value; }
     144    }
    140145    #endregion
    141146
     
    202207
    203208    public void LoadFrom(IQAPInstance instance) {
     209      Name = instance.Name;
     210      Description = instance.Description;
     211
    204212      Weights = new DoubleMatrix(instance.Weights);
    205213      Distances = new DoubleMatrix(instance.Distances);
     
    212220      if (instance.BestKnownAssignment != null) {
    213221        EvaluateAndLoadAssignment(instance.BestKnownAssignment);
     222      } else {
     223        BestKnownQuality = null;
     224        BestKnownSolution = null;
     225        BestKnownSolutions = null;
    214226      }
    215227    }
    216228
    217229    public void LoadFrom(ICTAPInstance instance) {
     230      Name = instance.Name;
     231      Description = instance.Description;
     232
    218233      Capacities = new DoubleArray(instance.MemoryCapacities);
    219234      Demands = new DoubleArray(instance.MemoryRequirements);
    220235      Weights = new DoubleMatrix(instance.CommunicationCosts);
    221       InstallationCosts = new DoubleMatrix(instance.ExecutionCosts);
     236      InstallationCosts = new DoubleMatrix(instance.ExecutionCosts.Transpose());
    222237      Distances = new DoubleMatrix(Capacities.Length, Capacities.Length); // all one, except diagonal
    223238      for (int i = 0; i < Capacities.Length - 1; i++)
     
    231246      if (instance.BestKnownAssignment != null) {
    232247        EvaluateAndLoadAssignment(instance.BestKnownAssignment);
     248      } else {
     249        BestKnownQuality = null;
     250        BestKnownSolution = null;
     251        BestKnownSolutions = null;
    233252      }
    234253    }
     
    242261      BestKnownSolution = new GQAPSolution(assignment, new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity));
    243262      BestKnownQuality = new DoubleValue(quality);
     263      BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);
     264      BestKnownSolutions.Solutions.Add((GQAPSolution)BestKnownSolution.Clone());
    244265    }
    245266
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPInstanceProvider.cs

    r7445 r7448  
    2929namespace HeuristicLab.Problems.Instances.ElloumiCTAP {
    3030  public class ElloumiCTAPInstanceProvider : IProblemInstanceProvider<ICTAPInstance> {
     31    private IProblemInstanceConsumer<ICTAPInstance> consumer;
     32
    3133    public string Name {
    3234      get { return "Elloumi's CTAP instances"; }
     
    3941    public Uri Link {
    4042      get { return new Uri("http://cedric.cnam.fr/oc/TAP/TAP.html"); }
     43    }
     44
     45    public bool ConsumerCanBeFed {
     46      get { return consumer != null; }
     47    }
     48
     49    public void SetConsumer(IProblemInstanceConsumer consumer) {
     50      if (consumer is IProblemInstanceConsumer<ICTAPInstance>)
     51        this.consumer = (IProblemInstanceConsumer<ICTAPInstance>)consumer;
     52      else this.consumer = null;
     53    }
     54
     55    public void FeedConsumer(IInstanceDescriptor descriptor) {
     56      consumer.LoadFrom(GetInstance(descriptor));
    4157    }
    4258
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPParser.cs

    r7445 r7448  
    8989          string[] costsTaskToTasks = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
    9090          for (int j = i + 1; j < Tasks; j++) {
    91             CommunicationCosts[i, j] = double.Parse(costsTaskToTasks[j], CultureInfo.InvariantCulture.NumberFormat);
     91            CommunicationCosts[i, j] = double.Parse(costsTaskToTasks[j - i - 1], CultureInfo.InvariantCulture.NumberFormat);
    9292            CommunicationCosts[j, i] = CommunicationCosts[i, j];
    9393          }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPSolutionParser.cs

    r7445 r7448  
    5656        for (int i = 0; i < tasks; i++) {
    5757          string[] assign = line.Split(delim, StringSplitOptions.RemoveEmptyEntries);
    58           Assignment[int.Parse(assign[0])] = int.Parse(assign[1]);
     58          Assignment[int.Parse(assign[0]) - 1] = int.Parse(assign[1]) - 1;
    5959          line = Continue(reader);
    6060        }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/HeuristicLab.Problems.Instances.ElloumiCTAP-3.3.csproj

    r7445 r7448  
    3838  </PropertyGroup>
    3939  <ItemGroup>
     40    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     41      <Private>False</Private>
     42    </Reference>
    4043    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    4144      <Private>False</Private>
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/HeuristicLab.Problems.Instances.QAPLIB-3.3.csproj

    r7445 r7448  
    3838  </PropertyGroup>
    3939  <ItemGroup>
     40    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     41      <Private>False</Private>
     42    </Reference>
    4043    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    4144      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/Plugin.cs

    r7445 r7448  
    2323
    2424namespace HeuristicLab.Problems.Instances {
    25   [Plugin("HeuristicLab.Problems.Instances.QAPLIB", "3.3.6.7444")]
     25  [Plugin("HeuristicLab.Problems.Instances.QAPLIB", "3.3.6.7445")]
    2626  [PluginFile("HeuristicLab.Problems.Instances.QAPLIB-3.3.dll", PluginFileType.Assembly)]
    2727  public class HeuristicLabProblemsInstancesQAPLIBPlugin : PluginBase {
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBInstanceProvider.cs

    r7445 r7448  
    2929namespace HeuristicLab.Problems.Instances.QAPLIB {
    3030  public class QAPLIBInstanceProvider : IProblemInstanceProvider<IQAPInstance> {
     31    IProblemInstanceConsumer<IQAPInstance> consumer;
     32
    3133    public string Name {
    3234      get { return "QAPLIB"; }
     
    3941    public Uri Link {
    4042      get { return new Uri("http://www.seas.upenn.edu/qaplib/"); }
     43    }
     44
     45    public bool ConsumerCanBeFed {
     46      get { return consumer != null; }
     47    }
     48
     49    public void SetConsumer(IProblemInstanceConsumer consumer) {
     50      if (consumer is IProblemInstanceConsumer<IQAPInstance>)
     51        this.consumer = (IProblemInstanceConsumer<IQAPInstance>)consumer;
     52      else this.consumer = null;
     53    }
     54
     55    public void FeedConsumer(IInstanceDescriptor descriptor) {
     56      consumer.LoadFrom(GetInstance(descriptor));
    4157    }
    4258
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/HeuristicLab.Problems.Instances-3.3.csproj

    r7445 r7448  
    5555    <Compile Include="IInstanceDescriptor.cs" />
    5656    <Compile Include="Instances\IQAPInstance.cs" />
     57    <Compile Include="IProblemInstanceConsumer.cs" />
    5758    <Compile Include="IProblemInstanceProvider.cs" />
    5859    <Compile Include="Plugin.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/IProblemInstanceProvider.cs

    r7445 r7448  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425
    2526namespace HeuristicLab.Problems.Instances {
    26   public interface IProblemInstanceProvider {
     27  public interface IProblemInstanceProvider : IContent {
    2728    string Name { get; }
    2829    string Description { get; }
    2930    Uri Link { get; }
     31
     32    bool ConsumerCanBeFed { get; }
     33
     34    void SetConsumer(IProblemInstanceConsumer consumer);
     35    void FeedConsumer(IInstanceDescriptor descriptor);
    3036
    3137    IEnumerable<IInstanceDescriptor> GetInstanceDescriptors();
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances/3.3/Plugin.cs

    r7445 r7448  
    2323
    2424namespace HeuristicLab.Problems.Instances {
    25   [Plugin("HeuristicLab.Problems.Instances", "3.3.6.7444")]
     25  [Plugin("HeuristicLab.Problems.Instances", "3.3.6.7445")]
    2626  [PluginFile("HeuristicLab.Problems.Instances-3.3.dll", PluginFileType.Assembly)]
    2727  public class HeuristicLabProblemsInstancesPlugin : PluginBase {
Note: See TracChangeset for help on using the changeset viewer.