Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6086


Ignore:
Timestamp:
04/30/11 15:40:40 (13 years ago)
Author:
abeham
Message:

#1497

  • Added problem-specific local improvement operator (best improvement local search using swap2 moves)
    • Adapted ExhaustiveSwap2MoveGenerator to yield moves
  • Added a parameter BestKnownSolutions to collect possible optimal invariants
    • Adapted BestQAPSolutionAnalyzer to collect optimal invariants
  • Added a function to the QAP Evaluator that calculates the impact of a certain allele
Location:
branches/histogram
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/ExhaustiveSwap2MoveGenerator.cs

    r5933 r6086  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3940    }
    4041
     42    public static IEnumerable<Swap2Move> Generate(Permutation permutation) {
     43      int length = permutation.Length;
     44      if (length == 1) throw new ArgumentException("ExhaustiveSwap2MoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation");
     45
     46      for (int i = 0; i < length - 1; i++)
     47        for (int j = i + 1; j < length; j++) {
     48          yield return new Swap2Move(i, j);
     49        }
     50    }
     51
    4152    public static Swap2Move[] Apply(Permutation permutation) {
    4253      int length = permutation.Length;
    43       if (length == 1) throw new ArgumentException("ExhaustiveSwap2MoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation");
    4454      int totalMoves = (length) * (length - 1) / 2;
    4555      Swap2Move[] moves = new Swap2Move[totalMoves];
    4656      int count = 0;
    47 
    48       for (int i = 0; i < length - 1; i++)
    49         for (int j = i + 1; j < length; j++) {
    50           moves[count++] = new Swap2Move(i, j);
    51         }
     57      foreach (Swap2Move move in Generate(permutation)) {
     58        moves[count++] = move;
     59      }
    5260      return moves;
    5361    }
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/HeuristicLab.Problems.QuadraticAssignment.Views-3.3.csproj

    r5933 r6086  
    102102  </PropertyGroup>
    103103  <ItemGroup>
     104    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86" />
     105    <Reference Include="HeuristicLab.Data.Views-3.3">
     106      <HintPath>..\..\HeuristicLab.Data.Views\3.3\bin\x86\Debug\HeuristicLab.Data.Views-3.3.dll</HintPath>
     107    </Reference>
     108    <Reference Include="HeuristicLab.Visualization.ChartControlsExtensions-3.3">
     109      <HintPath>..\..\HeuristicLab.Visualization.ChartControlsExtensions\3.3\bin\x86\Debug\HeuristicLab.Visualization.ChartControlsExtensions-3.3.dll</HintPath>
     110    </Reference>
    104111    <Reference Include="System" />
    105112    <Reference Include="System.Core" />
     
    107114    <Reference Include="System.Drawing" />
    108115    <Reference Include="System.Windows.Forms" />
     116    <Reference Include="System.Windows.Forms.DataVisualization" />
    109117    <Reference Include="System.Xml" />
    110118  </ItemGroup>
     
    184192      <Name>HeuristicLab.MainForm-3.3</Name>
    185193    </ProjectReference>
     194    <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj">
     195      <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project>
     196      <Name>HeuristicLab.Optimization.Views-3.3</Name>
     197    </ProjectReference>
    186198    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    187199      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.Designer.cs

    r5933 r6086  
    101101      this.QAPLIBInstancesLabel.AutoSize = true;
    102102      this.QAPLIBInstancesLabel.Cursor = System.Windows.Forms.Cursors.Hand;
     103      this.QAPLIBInstancesLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     104      this.QAPLIBInstancesLabel.ForeColor = System.Drawing.Color.Blue;
    103105      this.QAPLIBInstancesLabel.Location = new System.Drawing.Point(3, 5);
    104106      this.QAPLIBInstancesLabel.Name = "QAPLIBInstancesLabel";
     
    109111              "qaplib/");
    110112      this.QAPLIBInstancesLabel.Click += new System.EventHandler(this.QAPLIBInstancesLabel_Click);
     113      this.QAPLIBInstancesLabel.MouseEnter += new System.EventHandler(this.QAPLIBInstancesLabel_MouseEnter);
     114      this.QAPLIBInstancesLabel.MouseLeave += new System.EventHandler(this.QAPLIBInstancesLabel_MouseLeave);
    111115      //
    112116      // instancesComboBox
     
    191195      this.Name = "QuadraticAssignmentProblemView";
    192196      this.Size = new System.Drawing.Size(647, 492);
    193       this.Controls.SetChildIndex(this.infoLabel, 0);
    194       this.Controls.SetChildIndex(this.parameterCollectionView, 0);
    195       this.Controls.SetChildIndex(this.nameLabel, 0);
    196       this.Controls.SetChildIndex(this.nameTextBox, 0);
    197197      this.Controls.SetChildIndex(this.QAPLIBInstancesLabel, 0);
    198198      this.Controls.SetChildIndex(this.loadInstanceButton, 0);
     
    200200      this.Controls.SetChildIndex(this.tabControl, 0);
    201201      this.Controls.SetChildIndex(this.instancesComboBox, 0);
     202      this.Controls.SetChildIndex(this.infoLabel, 0);
     203      this.Controls.SetChildIndex(this.parameterCollectionView, 0);
     204      this.Controls.SetChildIndex(this.nameLabel, 0);
     205      this.Controls.SetChildIndex(this.nameTextBox, 0);
    202206      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    203207      this.tabControl.ResumeLayout(false);
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.cs

    r5838 r6086  
    2121
    2222using System;
     23using System.Drawing;
    2324using System.Windows.Forms;
    2425using HeuristicLab.Common.Resources;
     
    120121      System.Diagnostics.Process.Start("http://www.seas.upenn.edu/qaplib/");
    121122    }
     123
     124    private void QAPLIBInstancesLabel_MouseEnter(object sender, EventArgs e) {
     125      Cursor = Cursors.Hand;
     126      QAPLIBInstancesLabel.ForeColor = Color.Red;
     127      toolTip.SetToolTip(QAPLIBInstancesLabel, "Browse to http://www.seas.upenn.edu/qaplib/");
     128    }
     129
     130    private void QAPLIBInstancesLabel_MouseLeave(object sender, EventArgs e) {
     131      Cursor = Cursors.Default;
     132      QAPLIBInstancesLabel.ForeColor = Color.Blue;
     133      toolTip.SetToolTip(QAPLIBInstancesLabel, String.Empty);
     134    }
    122135  }
    123136}
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/QuadraticAssignmentProblemView.resx

    r5583 r6086  
    121121    <value>107, 17</value>
    122122  </metadata>
     123  <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     124    <value>107, 17</value>
     125  </metadata>
    123126  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    124127    <value>17, 17</value>
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs

    r5933 r6086  
    6161      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    6262    }
     63    public LookupParameter<ItemList<Permutation>> BestKnownSolutionsParameter {
     64      get { return (LookupParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]; }
     65    }
    6366    public LookupParameter<Permutation> BestKnownSolutionParameter {
    6467      get { return (LookupParameter<Permutation>)Parameters["BestKnownSolution"]; }
     
    8184      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best QAP solution should be stored."));
    8285      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this QAP instance."));
     86      Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance."));
    8387      Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this QAP instance."));
     88    }
     89
     90    [StorableHook(HookType.AfterDeserialization)]
     91    private void AfterDeserialization() {
     92      // BackwardsCompatibility3.3
     93      #region Backwards compatible code, remove with 3.4
     94      /*if (Parameters.ContainsKey("BestKnownSolution")) {
     95        Parameters.Remove("BestKnownSolution");
     96        Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance."));
     97      }*/
     98      if (!Parameters.ContainsKey("BestKnownSolutions")) {
     99        Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance."));
     100      }
     101      #endregion
    84102    }
    85103
     
    93111      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    94112
    95       int i = -1;
    96       if (!max)
    97         i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    98       else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     113      var sorted = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).ToArray();
     114      if (max) sorted = sorted.Reverse().ToArray();
     115      int i = sorted.First().index;
    99116
    100       if (bestKnownQuality == null ||
    101           max && qualities[i].Value > bestKnownQuality.Value ||
    102           !max && qualities[i].Value < bestKnownQuality.Value) {
     117      if (bestKnownQuality == null
     118          || max && qualities[i].Value > bestKnownQuality.Value
     119          || !max && qualities[i].Value < bestKnownQuality.Value
     120          || bestKnownQuality.Value == qualities[i].Value
     121            && (BestKnownSolutionsParameter.ActualValue == null || BestKnownSolutionsParameter.ActualValue.Count == 0)) {
    103122        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    104123        BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone();
     124        BestKnownSolutionsParameter.ActualValue = new ItemList<Permutation>();
     125        BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[i].Clone());
     126      } else if (bestKnownQuality != null && qualities[i].Value == bestKnownQuality.Value) {
     127        PermutationEqualityComparer comparer = new PermutationEqualityComparer();
     128        foreach (var k in sorted) {
     129          if (!max && k.Value > qualities[i].Value
     130            || max && k.Value < qualities[i].Value) break;
     131          Permutation p = permutations[k.index];
     132          bool alreadyPresent = false;
     133          foreach (Permutation p2 in BestKnownSolutionsParameter.ActualValue) {
     134            if (comparer.Equals(p, p2)) {
     135              alreadyPresent = true;
     136              break;
     137            }
     138          }
     139          if (!alreadyPresent)
     140            BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[k.index].Clone());
     141        }
    105142      }
    106143
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPEvaluator.cs

    r5838 r6086  
    6969    }
    7070
     71    public static double Impact(int facility, Permutation assignment, DoubleMatrix weights, DoubleMatrix distances) {
     72      double impact = 0;
     73      for (int i = 0; i < assignment.Length; i++) {
     74        impact += weights[facility, i] * distances[assignment[facility], assignment[i]];
     75        impact += weights[i, facility] * distances[assignment[i], assignment[facility]];
     76      }
     77      return impact;
     78    }
     79
    7180    public override IOperation Apply() {
    7281      Permutation assignment = PermutationParameter.ActualValue;
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3/HeuristicLab.Problems.QuadraticAssignment-3.3.csproj

    r5996 r6086  
    120120    <Compile Include="Interfaces\IQAPEvaluator.cs" />
    121121    <Compile Include="Interfaces\IQAPMoveEvaluator.cs" />
     122    <Compile Include="LocalImprovement\QAPExhaustiveSwap2LocalImprovement.cs" />
    122123    <Compile Include="Parsers\QAPLIBSolutionParser.cs" />
    123124    <Compile Include="Parsers\QAPLIBParser.cs" />
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r6046 r6086  
    4949
    5050    #region Parameter Properties
     51    public IValueParameter<ItemList<Permutation>> BestKnownSolutionsParameter {
     52      get { return (IValueParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]; }
     53    }
    5154    public IValueParameter<Permutation> BestKnownSolutionParameter {
    5255      get { return (IValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
     
    6164
    6265    #region Properties
     66    public ItemList<Permutation> BestKnownSolutions {
     67      get { return BestKnownSolutionsParameter.Value; }
     68      set { BestKnownSolutionsParameter.Value = value; }
     69    }
    6370    public Permutation BestKnownSolution {
    6471      get { return BestKnownSolutionParameter.Value; }
     
    106113    public QuadraticAssignmentProblem()
    107114      : base(new QAPEvaluator(), new RandomPermutationCreator()) {
     115      Parameters.Add(new OptionalValueParameter<ItemList<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    108116      Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    109117      Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5)));
     
    138146    public override IDeepCloneable Clone(Cloner cloner) {
    139147      return new QuadraticAssignmentProblem(this, cloner);
     148    }
     149
     150    [StorableHook(HookType.AfterDeserialization)]
     151    private void AfterDeserialization() {
     152      // BackwardsCompatibility3.3
     153      #region Backwards compatible code, remove with 3.4
     154      /*if (Parameters.ContainsKey("BestKnownSolution")) {
     155        Permutation solution = ((IValueParameter<Permutation>)Parameters["BestKnownSolution"]).Value;
     156        Parameters.Remove("BestKnownSolution");
     157        Parameters.Add(new OptionalValueParameter<ItemList<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
     158        if (solution != null) {
     159          BestKnownSolutions = new ItemList<Permutation>();
     160          BestKnownSolutions.Add(solution);
     161        }
     162      }*/
     163      if (!Parameters.ContainsKey("BestKnownSolutions")) {
     164        Parameters.Add(new OptionalValueParameter<ItemList<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
     165      }
     166      #endregion
    140167    }
    141168
     
    246273      Operators.Add(new QAPAlleleFrequencyAnalyzer());
    247274      Operators.Add(new QAPPopulationDiversityAnalyzer());
     275      Operators.Add(new QAPExhaustiveSwap2LocalImprovement());
    248276      ParameterizeAnalyzers();
    249277      ParameterizeOperators();
     
    270298        BestQAPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
    271299        BestQAPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
    272         BestQAPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     300        BestQAPSolutionAnalyzer.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name;
    273301        BestQAPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
    274302      }
     
    314342      foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())
    315343        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     344
     345      QAPExhaustiveSwap2LocalImprovement localOpt = Operators.OfType<QAPExhaustiveSwap2LocalImprovement>().SingleOrDefault();
     346      if (localOpt != null) {
     347        localOpt.AssignmentParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     348        localOpt.DistancesParameter.ActualName = DistancesParameter.Name;
     349        localOpt.MaximizationParameter.ActualName = MaximizationParameter.Name;
     350        localOpt.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     351        localOpt.WeightsParameter.ActualName = WeightsParameter.Name;
     352      }
    316353    }
    317354
     
    338375      Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + ".";
    339376      BestKnownQuality = null;
    340       BestKnownSolution = null;
     377      BestKnownSolutions = null;
    341378      OnReset();
    342379    }
     
    371408            if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) {
    372409              BestKnownQuality = new DoubleValue(solParser.Quality);
     410              BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });
    373411              BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    374412            } else {
    375413              BestKnownQuality = new DoubleValue(solParser.Quality);
     414              BestKnownSolutions = null;
    376415              BestKnownSolution = null;
    377416            }
    378417          } else {
    379418            BestKnownQuality = new DoubleValue(solParser.Quality);
     419            BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });
    380420            BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    381421          }
     
    383423      } else {
    384424        BestKnownQuality = null;
     425        BestKnownSolutions = null;
    385426        BestKnownSolution = null;
    386427      }
Note: See TracChangeset for help on using the changeset viewer.