Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/10 02:44:07 (15 years ago)
Author:
abeham
Message:

Excluded three opt move from the project as it doesn't currently work #889

Location:
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/StochasticThreeOptMoveGenerator.cs

    r3074 r3200  
    3030  [Item("StochasticThreeOptMoveGenerator", "Randomly samples n from all possible 3-opt moves from a given permutation.")]
    3131  [StorableClass]
    32   public class StochasticThreeOptMoveGenerator : ThreeOptMoveGenerator, IStochasticOperator {
     32  public class StochasticThreeOptMultiMoveGenerator : ThreeOptMoveGenerator, IStochasticOperator, IMultiMoveGenerator {
    3333    public ILookupParameter<IRandom> RandomParameter {
    3434      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    3535    }
    36     private ValueLookupParameter<IntValue> SampleSizeParameter {
    37       get { return (ValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
     36    public IValueLookupParameter<IntValue> SampleSizeParameter {
     37      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
    3838    }
    3939
     
    4343    }
    4444
    45     public StochasticThreeOptMoveGenerator()
     45    public StochasticThreeOptMultiMoveGenerator()
    4646      : base() {
    4747      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     
    5151    public static ThreeOptMove[] Apply(Permutation permutation, IRandom random, int sampleSize) {
    5252      int length = permutation.Length;
    53       /*int totalMoves = (length) * (length - 1) / 2 - 3;
    54       // FIXME: Remove this comment if ExhaustiveThreeOptMoveGenerator exists, otherwise alter the exception message below.
    55       if (sampleSize >= totalMoves) throw new InvalidOperationException("StochasticThreeOptMoveGenerator: Sample size (" + sampleSize + ") is larger than the set of all possible moves (" + totalMoves + "), use the ExhaustiveThreeOptMoveGenerator instead.");
    56       */
    5753      ThreeOptMove[] moves = new ThreeOptMove[sampleSize];
    5854      for (int i = 0; i < sampleSize; i++) {
    5955        int index1, index2, index3;
    60         do {
    61           index1 = random.Next(length - 1);
    62           index2 = random.Next(index1 + 1, length);
    63         } while (index2 - index1 == length - 1);
    64         do {
    65           index3 = random.Next(length);
    66         } while (index1 <= index3 && index3 <= index2 + 1);
     56        index1 = random.Next(length - 1);
     57        index2 = random.Next(index1 + 1, length);
     58        index3 = length - index2 + index1 - 1;  // get insertion point in remaining part
     59        if (index3 > 0)
     60          index3 = random.Next(index3);
     61        else
     62          index3 = 0;
    6763        moves[i] = new ThreeOptMove(index1, index2, index3);
    6864      }
Note: See TracChangeset for help on using the changeset viewer.