Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6416 for branches


Ignore:
Timestamp:
06/15/11 23:11:41 (13 years ago)
Author:
abeham
Message:

#1541

  • Added PermutationView that allows to change the permutation type
  • Updated AFA and PopDiv Analyzer
  • Simplified QAP name to just the instance when loading from embedded resource
Location:
branches/QAPAlgorithms
Files:
7 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/QAPAlgorithms/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj

    r5809 r6416  
    221221    </BootstrapperPackage>
    222222  </ItemGroup>
     223  <ItemGroup>
     224    <EmbeddedResource Include="StringConvertibleArrayView.resx">
     225      <DependentUpon>StringConvertibleArrayView.cs</DependentUpon>
     226    </EmbeddedResource>
     227  </ItemGroup>
    223228  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    224229  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • branches/QAPAlgorithms/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.Designer.cs

    r5445 r6416  
    116116    #endregion
    117117
    118     private System.Windows.Forms.Label lengthLabel;
    119     private System.Windows.Forms.TextBox lengthTextBox;
    120     private System.Windows.Forms.DataGridView dataGridView;
    121     private System.Windows.Forms.ErrorProvider errorProvider;
     118    protected System.Windows.Forms.DataGridView dataGridView;
     119    protected System.Windows.Forms.Label lengthLabel;
     120    protected System.Windows.Forms.TextBox lengthTextBox;
     121    protected System.Windows.Forms.ErrorProvider errorProvider;
    122122
    123123  }
  • branches/QAPAlgorithms/HeuristicLab.Encodings.PermutationEncoding.Views/3.3/HeuristicLab.Encodings.PermutationEncoding.Views-3.3.csproj

    r5163 r6416  
    1212    <AssemblyName>HeuristicLab.Encodings.PermutationEncoding.Views-3.3</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    14     <TargetFrameworkProfile></TargetFrameworkProfile>
     14    <TargetFrameworkProfile>
     15    </TargetFrameworkProfile>
    1516    <FileAlignment>512</FileAlignment>
    1617    <SignAssembly>true</SignAssembly>
     
    9293  </PropertyGroup>
    9394  <ItemGroup>
     95    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86" />
     96    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86" />
     97    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86" />
     98    <Reference Include="HeuristicLab.Visualization.ChartControlsExtensions-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86" />
    9499    <Reference Include="System" />
    95100    <Reference Include="System.Core">
     
    98103    <Reference Include="System.Drawing" />
    99104    <Reference Include="System.Windows.Forms" />
     105    <Reference Include="System.Windows.Forms.DataVisualization" />
    100106    <Reference Include="System.Xml.Linq">
    101107      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    115121    </Compile>
    116122    <Compile Include="HeuristicLabEncodingsPermutationEncodingViewsPlugin.cs" />
     123    <Compile Include="PermutationView.cs">
     124      <SubType>UserControl</SubType>
     125    </Compile>
     126    <Compile Include="PermutationView.Designer.cs">
     127      <DependentUpon>PermutationView.cs</DependentUpon>
     128    </Compile>
    117129    <Compile Include="Properties\AssemblyInfo.cs" />
    118130  </ItemGroup>
     
    135147      <Name>HeuristicLab.Core-3.3</Name>
    136148    </ProjectReference>
     149    <ProjectReference Include="..\..\HeuristicLab.Data.Views\3.3\HeuristicLab.Data.Views-3.3.csproj">
     150      <Project>{72104A0B-90E7-42F3-9ABE-9BBBADD4B943}</Project>
     151      <Name>HeuristicLab.Data.Views-3.3</Name>
     152    </ProjectReference>
    137153    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
    138154      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     
    150166      <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project>
    151167      <Name>HeuristicLab.MainForm-3.3</Name>
     168    </ProjectReference>
     169    <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj">
     170      <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project>
     171      <Name>HeuristicLab.Optimization.Views-3.3</Name>
    152172    </ProjectReference>
    153173    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
     
    172192      <Install>true</Install>
    173193    </BootstrapperPackage>
     194  </ItemGroup>
     195  <ItemGroup>
     196    <EmbeddedResource Include="PermutationView.resx">
     197      <DependentUpon>PermutationView.cs</DependentUpon>
     198    </EmbeddedResource>
    174199  </ItemGroup>
    175200  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/QAPAlgorithms/HeuristicLab.Encodings.PermutationEncoding.Views/3.3/HeuristicLabEncodingsPermutationEncodingViewsPlugin.cs.frame

    r6099 r6416  
    3131  [PluginDependency("HeuristicLab.Core.Views", "3.3")]
    3232  [PluginDependency("HeuristicLab.Data", "3.3")]
     33  [PluginDependency("HeuristicLab.Data.Views", "3.3")]
    3334  [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3")]
    3435  [PluginDependency("HeuristicLab.MainForm", "3.3")]
  • branches/QAPAlgorithms/HeuristicLab.Encodings.PermutationEncoding/3.3/Permutation.cs

    r5445 r6416  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3637    public PermutationTypes PermutationType {
    3738      get { return permutationType; }
     39      set {
     40        bool changed = (permutationType != value);
     41        permutationType = value;
     42        if (changed) OnPermutationTypeChanged();
     43      }
    3844    }
    3945
     
    4551    }
    4652    public Permutation() : this(PermutationTypes.RelativeUndirected) { }
    47     public Permutation(PermutationTypes type) : base() {
     53    public Permutation(PermutationTypes type)
     54      : base() {
    4855      permutationType = type;
    4956    }
     
    5865      Randomize(random);
    5966    }
    60     public Permutation(PermutationTypes type, int[] elements) : base(elements) {
     67    public Permutation(PermutationTypes type, int[] elements)
     68      : base(elements) {
    6169      permutationType = type;
    6270    }
    63     public Permutation(PermutationTypes type, IntArray elements) : this(type, elements.Length) {
     71    public Permutation(PermutationTypes type, IntArray elements)
     72      : this(type, elements.Length) {
    6473      for (int i = 0; i < array.Length; i++)
    6574        array[i] = elements[i];
     
    111120      return this[position];
    112121    }
     122
     123    public event EventHandler PermutationTypeChanged;
     124
     125    protected virtual void OnPermutationTypeChanged() {
     126      var handler = PermutationTypeChanged;
     127      if (handler != null) handler(this, EventArgs.Empty);
     128    }
    113129  }
    114130}
  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/HeuristicLab.Problems.QuadraticAssignment.Algorithms-3.3.csproj

    r6351 r6416  
    107107  </ItemGroup>
    108108  <ItemGroup>
     109    <Compile Include="QAPRandomizedRobustTabooSeachOperator.cs" />
     110    <Compile Include="RandomizedRobustTabooSearch.cs" />
    109111    <Compile Include="QAPRobustTabooSeachOperator.cs" />
    110112    <Compile Include="RobustTabooSearch.cs" />
  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/QAPRobustTabooSeachOperator.cs

    r6351 r6416  
    165165      if (bestMove == null) return base.Apply();
    166166
    167       shortTermMemory[bestMove.Index1, solution[bestMove.Index2]] = iteration;
    168       shortTermMemory[bestMove.Index2, solution[bestMove.Index1]] = iteration;
     167      shortTermMemory[bestMove.Index1, solution[bestMove.Index1]] = iteration;
     168      shortTermMemory[bestMove.Index2, solution[bestMove.Index2]] = iteration;
    169169      Swap2Manipulator.Apply(solution, bestMove.Index1, bestMove.Index2);
    170170      quality.Value += bestMoveQuality;
  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/QAPAlleleFrequencyAnalyzer.cs

    r6342 r6416  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Analysis;
    2324using HeuristicLab.Common;
     
    5657
    5758    protected override Allele[] CalculateAlleles(Permutation solution) {
    58       Allele[] alleles = new Allele[solution.Length];
     59      Allele[] alleles = new Allele[solution.Length * solution.Length];
     60      Dictionary<string, int> allelesDict = new Dictionary<string, int>();
    5961      DoubleMatrix weights = WeightsParameter.ActualValue;
    6062      DoubleMatrix distances = DistancesParameter.ActualValue;
    61       int source, target;
    6263      double impact;
    6364
    64       for (int i = 0; i < solution.Length; i++) {
    65         source = i;
    66         target = solution[i];
    67         impact = 0;
    68         for (int j = 0; j < solution.Length; j++)
    69           impact += weights[source, j] * distances[target, solution[j]];
    70         alleles[i] = new Allele(source.ToString() + "->" + target.ToString(), impact);
     65      for (int x = 0; x < solution.Length; x++) {
     66        for (int y = 0; y < solution.Length; y++) {
     67          string allele = weights[x, y].ToString() + ">" + distances[solution[x], solution[y]].ToString();
     68          int repetition = 1;
     69          if (allelesDict.ContainsKey(allele)) repetition += allelesDict[allele];
     70          allelesDict[allele] = repetition;
     71          impact = weights[x, y] * distances[solution[x], solution[y]];
     72          alleles[x * solution.Length + y] = new Allele(allele + "/" + repetition, impact);
     73        }
    7174      }
    7275
  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/QAPPopulationDiversityAnalyzer.cs

    r6342 r6416  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Data;
    2526using HeuristicLab.Encodings.PermutationEncoding;
     27using HeuristicLab.Parameters;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    3335  [StorableClass]
    3436  public sealed class QAPPopulationDiversityAnalyzer : PopulationDiversityAnalyzer<Permutation> {
     37    public IValueParameter<BoolValue> UsePhenotypeSimilarityParameter {
     38      get { return (IValueParameter<BoolValue>)Parameters["UsePhenotypeSimilarity"]; }
     39    }
     40    public ILookupParameter<DoubleMatrix> WeightsParameter {
     41      get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
     42    }
     43    public ILookupParameter<DoubleMatrix> DistancesParameter {
     44      get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
     45    }
     46
    3547    [StorableConstructor]
    3648    private QAPPopulationDiversityAnalyzer(bool deserializing) : base(deserializing) { }
    3749    private QAPPopulationDiversityAnalyzer(QAPPopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { }
    38     public QAPPopulationDiversityAnalyzer() : base() { }
     50    public QAPPopulationDiversityAnalyzer()
     51      : base() {
     52      Parameters.Add(new ValueParameter<BoolValue>("UsePhenotypeSimilarity", "True if the similarity should be measured a level closer to the phenotype (the number of similar assignments of individual weights to distances). Set to false if the number of equal assignments (facility to location) should be counted.", new BoolValue(false)));
     53      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", "The weights matrix."));
     54      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distances matrix."));
     55    }
    3956
    4057    public override IDeepCloneable Clone(Cloner cloner) {
     
    4259    }
    4360
     61    [StorableHook(HookType.AfterDeserialization)]
     62    private void AfterDeserialization() {
     63      // BackwardsCompatibility3.3
     64      #region Backwards compatible code, remove with 3.4
     65      if (!Parameters.ContainsKey("UsePhenotypeSimilarity"))
     66        Parameters.Add(new ValueParameter<BoolValue>("UsePhenotypeSimilarity", "True if the similarity should be measured a level closer to the phenotype (the number of similar assignments of individual weights to distances). Set to false if the number of equal assignments (facility to location) should be counted.", new BoolValue(false)));
     67      if (!Parameters.ContainsKey("Weights"))
     68        Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", "The weights matrix."));
     69      if (!Parameters.ContainsKey("Distances"))
     70        Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distances matrix."));
     71      #endregion
     72    }
     73
    4474    protected override double[,] CalculateSimilarities(Permutation[] solutions) {
     75      DoubleMatrix weights = WeightsParameter.ActualValue, distances = DistancesParameter.ActualValue;
     76      bool phenotypeSimilarity = UsePhenotypeSimilarityParameter.Value.Value;
    4577      int count = solutions.Length;
    4678      double[,] similarities = new double[count, count];
     
    4981        similarities[i, i] = 1;
    5082        for (int j = i + 1; j < count; j++) {
    51           similarities[i, j] = CalculateSimilarity(solutions[i], solutions[j]);
     83          if (phenotypeSimilarity)
     84            similarities[i, j] = QAPPermutationProximityCalculator.CalculatePhenotypeSimilarity(solutions[i], solutions[j], weights, distances);
     85          else similarities[i, j] = QAPPermutationProximityCalculator.CalculateGenotypeSimilarity(solutions[i], solutions[j]);
    5286          similarities[j, i] = similarities[i, j];
    5387        }
     
    5589      return similarities;
    5690    }
    57 
    58     private double CalculateSimilarity(Permutation assignment1, Permutation assignment2) {
    59       int identicalAssignments = 0;
    60       for (int i = 0; i < assignment1.Length; i++) {
    61         if (assignment1[i] == assignment2[i])
    62           identicalAssignments++;
    63       }
    64       return ((double)identicalAssignments) / assignment1.Length;
    65     }
    6691  }
    6792}
  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment/3.3/HeuristicLab.Problems.QuadraticAssignment-3.3.csproj

    r6342 r6416  
    124124    <Compile Include="Parsers\QAPLIBParser.cs" />
    125125    <Compile Include="QAPAssignment.cs" />
     126    <Compile Include="QAPPermutationProximityCalculator.cs" />
    126127    <Compile Include="QuadraticAssignmentProblem.cs" />
    127128    <EmbeddedResource Include="Data\bur26a.dat" />
  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r6342 r6416  
    390390        Distances = new DoubleMatrix(parser.Distances);
    391391        Weights = new DoubleMatrix(parser.Weights);
    392         Name = "Quadratic Assignment Problem (loaded instance " + instance + ")";
    393         Description = "Loaded embedded problem data of instance " + instance + ".";
     392        Name = instance;
     393        Description = "Loaded embedded QAPLIB problem data of instance " + instance + ".";
    394394        OnReset();
    395395      }
Note: See TracChangeset for help on using the changeset viewer.