Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3074


Ignore:
Timestamp:
03/16/10 21:29:10 (15 years ago)
Author:
abeham
Message:

updated tabu search #840

Location:
trunk/sources
Files:
15 added
4 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.TS/3.3/TS.cs

    r3048 r3074  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
     
    3334namespace HeuristicLab.Algorithms.TS {
    3435  [Item("TS", "A tabu search algorithm.")]
     36  [Creatable("Algorithms")]
    3537  public sealed class TS : EngineAlgorithm {
    36     /*#region Parameter Properties
     38    #region Problem Properties
     39    public override Type ProblemType {
     40      get { return typeof(ISingleObjectiveProblem); }
     41    }
     42    public new ISingleObjectiveProblem Problem {
     43      get { return (ISingleObjectiveProblem)base.Problem; }
     44      set { base.Problem = value; }
     45    }
     46    #endregion
     47
     48    #region Parameter Properties
    3749    private ValueParameter<IntValue> SeedParameter {
    3850      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
     
    4355    private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
    4456      get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
     57    }
     58    private ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
     59      get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
     60    }
     61    private ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
     62      get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
     63    }
     64    private ConstrainedValueParameter<ITabuMoveEvaluator> TabuMoveEvaluatorParameter {
     65      get { return (ConstrainedValueParameter<ITabuMoveEvaluator>)Parameters["TabuMoveEvaluator"]; }
     66    }
     67    private ConstrainedValueParameter<ITabuMoveMaker> TabuMoveMakerParameter {
     68      get { return (ConstrainedValueParameter<ITabuMoveMaker>)Parameters["TabuMoveMaker"]; }
     69    }
     70    private ValueParameter<IntValue> TabuTenureParameter {
     71      get { return (ValueParameter<IntValue>)Parameters["TabuTenure"]; }
    4572    }
    4673    private ValueParameter<IntValue> MaximumIterationsParameter {
     
    6188      get { return MoveGeneratorParameter.Value; }
    6289      set { MoveGeneratorParameter.Value = value; }
     90    }
     91    public IMoveMaker MoveMaker {
     92      get { return MoveMakerParameter.Value; }
     93      set { MoveMakerParameter.Value = value; }
     94    }
     95    public ISingleObjectiveMoveEvaluator MoveEvaluator {
     96      get { return MoveEvaluatorParameter.Value; }
     97      set { MoveEvaluatorParameter.Value = value; }
     98    }
     99    public ITabuMoveEvaluator TabuMoveEvaluator {
     100      get { return TabuMoveEvaluatorParameter.Value; }
     101      set { TabuMoveEvaluatorParameter.Value = value; }
     102    }
     103    public ITabuMoveMaker TabuMoveMaker {
     104      get { return TabuMoveMakerParameter.Value; }
     105      set { TabuMoveMakerParameter.Value = value; }
     106    }
     107    public IntValue TabuTenure {
     108      get { return TabuTenureParameter.Value; }
     109      set { TabuTenureParameter.Value = value; }
    63110    }
    64111    public IntValue MaximumIterations {
     
    82129      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    83130      Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
     131      Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
     132      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
     133      Parameters.Add(new ConstrainedValueParameter<ITabuMoveEvaluator>("TabuMoveEvaluator", "The operator to evaluate whether a move is tabu or not."));
     134      Parameters.Add(new ConstrainedValueParameter<ITabuMoveMaker>("TabuMoveMaker", "The operator used to insert attributes of a move into the tabu list."));
     135      Parameters.Add(new ValueParameter<IntValue>("TabuTenure", "The length of the tabu list.", new IntValue(10)));
    84136      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    85137
     
    100152
    101153      tsMainLoop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
    102       tsMainLoop.MoveMakerParameter.ActualName = MoveGenerator..Name;
    103       tsMainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
    104       tsMainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
    105       tsMainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
    106       tsMainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
     154      tsMainLoop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
     155      tsMainLoop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
     156      tsMainLoop.TabuMoveEvaluatorParameter.ActualName = TabuMoveEvaluatorParameter.Name;
     157      tsMainLoop.TabuMoveMakerParameter.ActualName = TabuMoveMakerParameter.Name;
     158      tsMainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
    107159      tsMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    108160      tsMainLoop.ResultsParameter.ActualName = "Results";
    109161
    110       Initialze();
    111     }
     162      Initialize();
     163    }
     164
    112165    [StorableConstructor]
    113166    private TS(bool deserializing) : base() { }
     
    115168    public override IDeepCloneable Clone(Cloner cloner) {
    116169      TS clone = (TS)base.Clone(cloner);
    117       clone.Initialze();
     170      clone.Initialize();
    118171      return clone;
    119172    }
     
    124177      ParameterizeStochasticOperator(Problem.Evaluator);
    125178      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     179      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
     180        op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
     181      }
    126182      ParameterizeSolutionsCreator();
    127       ParameterizeSGAMainLoop();
    128       ParameterizeSelectors();
    129       UpdateCrossovers();
    130       UpdateMutators();
     183      ParameterizeTSMainLoop();
     184      ParameterizeMoveEvaluator();
     185      ParameterizeMoveMaker();
     186      UpdateMoveGenerator();
    131187      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    132188      base.OnProblemChanged();
     
    140196      ParameterizeStochasticOperator(Problem.Evaluator);
    141197      ParameterizeSolutionsCreator();
    142       ParameterizeSGAMainLoop();
    143       ParameterizeSelectors();
     198      ParameterizeTSMainLoop();
     199      ParameterizeMoveEvaluator();
     200      ParameterizeMoveMaker();
    144201      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    145202      base.Problem_EvaluatorChanged(sender, e);
     
    147204    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    148205      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    149       UpdateCrossovers();
    150       UpdateMutators();
     206      // This may seem pointless, but some operators already have the eventhandler registered, others don't
     207      // FIXME: Is there another way to solve this problem?
     208      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
     209        op.MoveQualityParameter.ActualNameChanged -= new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
     210        op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
     211      }
     212      IMoveGenerator oldMoveGenerator = MoveGenerator;
     213      UpdateMoveGenerator();
     214      if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire
     215        UpdateMoveParameters();
     216      ParameterizeTSMainLoop();
     217      ParameterizeMoveEvaluator();
     218      ParameterizeMoveMaker();
    151219      base.Problem_OperatorsChanged(sender, e);
    152220    }
    153     private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
    154       Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
    155       ParameterizeSelectors();
    156     }
    157     private void Elites_ValueChanged(object sender, EventArgs e) {
    158       ParameterizeSelectors();
    159     }
    160     private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
    161       PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
    162       ParameterizeSelectors();
    163     }
    164     private void PopulationSize_ValueChanged(object sender, EventArgs e) {
    165       ParameterizeSelectors();
    166     }
    167221    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    168       ParameterizeSGAMainLoop();
    169       ParameterizeSelectors();
     222      ParameterizeTSMainLoop();
     223      ParameterizeMoveEvaluator();
     224      ParameterizeMoveMaker();
     225    }
     226    private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
     227      UpdateMoveParameters();
     228    }
     229    private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
     230      ParameterizeTSMainLoop();
     231      ParameterizeMoveEvaluator();
     232      ParameterizeMoveMaker();
     233    }
     234    private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
     235      ParameterizeTSMainLoop();
     236      ParameterizeMoveEvaluator();
     237      ParameterizeMoveMaker();
    170238    }
    171239    #endregion
     
    173241    #region Helpers
    174242    [StorableHook(HookType.AfterDeserialization)]
    175     private void Initialze() {
    176       InitializeSelectors();
    177       UpdateSelectors();
    178       PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
    179       PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
    180       ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
    181       Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
    182       if (Problem != null)
     243    private void Initialize() {
     244      if (Problem != null) {
    183245        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    184     }
    185 
     246        foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
     247          op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
     248        }
     249      }
     250      MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
     251      MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
     252    }
     253    private void UpdateMoveGenerator() {
     254      IMoveGenerator oldMoveGenerator = MoveGenerator;
     255      MoveGeneratorParameter.ValidValues.Clear();
     256      if (Problem != null) {
     257        foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name))
     258          MoveGeneratorParameter.ValidValues.Add(generator);
     259      }
     260      if (oldMoveGenerator != null && MoveGeneratorParameter.ValidValues.Any(x => x.GetType() == oldMoveGenerator.GetType()))
     261        MoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
     262      if (MoveGenerator == null) {
     263        ClearMoveParameters();
     264      }
     265    }
     266    private void UpdateMoveParameters() {
     267      IMoveMaker oldMoveMaker = MoveMaker;
     268      ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
     269      ITabuMoveEvaluator oldTabuMoveEvaluator = TabuMoveEvaluator;
     270      ITabuMoveMaker oldTabuMoveMaker = TabuMoveMaker;
     271      ClearMoveParameters();
     272      List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
     273      foreach (Type type in moveTypes.ToList()) {
     274        if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
     275          moveTypes.Remove(type);
     276      }
     277      foreach (Type type in moveTypes) {
     278        var operators = Problem.Operators.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
     279        foreach (IMoveMaker moveMaker in operators.OfType<IMoveMaker>())
     280          MoveMakerParameter.ValidValues.Add(moveMaker);
     281        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType<ISingleObjectiveMoveEvaluator>())
     282          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     283        foreach (ITabuMoveEvaluator tabuMoveEvaluator in operators.OfType<ITabuMoveEvaluator>())
     284          TabuMoveEvaluatorParameter.ValidValues.Add(tabuMoveEvaluator);
     285        foreach (ITabuMoveMaker tabuMoveMaker in operators.OfType<ITabuMoveMaker>())
     286          TabuMoveMakerParameter.ValidValues.Add(tabuMoveMaker);
     287      }
     288      if (oldMoveMaker != null && MoveMakerParameter.ValidValues.Any(x => x.GetType() == oldMoveMaker.GetType()))
     289        MoveMaker = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
     290      if (oldMoveEvaluator != null && MoveEvaluatorParameter.ValidValues.Any(x => x.GetType() == oldMoveEvaluator.GetType()))
     291        MoveEvaluator = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
     292      if (oldTabuMoveMaker != null && TabuMoveMakerParameter.ValidValues.Any(x => x.GetType() == oldTabuMoveMaker.GetType()))
     293        TabuMoveMaker = TabuMoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveMaker.GetType());
     294      if (oldTabuMoveEvaluator != null && TabuMoveEvaluatorParameter.ValidValues.Any(x => x.GetType() == oldTabuMoveEvaluator.GetType()))
     295        TabuMoveEvaluator = TabuMoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTabuMoveEvaluator.GetType());
     296    }
     297    private void ClearMoveParameters() {
     298      MoveMakerParameter.ValidValues.Clear();
     299      MoveEvaluatorParameter.ValidValues.Clear();
     300      TabuMoveEvaluatorParameter.ValidValues.Clear();
     301      TabuMoveMakerParameter.ValidValues.Clear();
     302    }
    186303    private void ParameterizeSolutionsCreator() {
    187304      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    188305      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    189306    }
    190     private void ParameterizeSGAMainLoop() {
    191       TSMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     307    private void ParameterizeTSMainLoop() {
    192308      TSMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    193309      TSMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     310      if (MoveEvaluator != null)
     311        TSMainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
    194312    }
    195313    private void ParameterizeStochasticOperator(IOperator op) {
     
    197315        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    198316    }
    199     private void InitializeSelectors() {
    200       selectors = new List<ISelector>();
    201       if (ApplicationManager.Manager != null) {
    202         selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));
    203         ParameterizeSelectors();
    204       }
    205     }
    206     private void ParameterizeSelectors() {
    207       foreach (ISelector selector in Selectors) {
    208         selector.CopySelected = new BoolValue(true);
    209         selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value));
    210         ParameterizeStochasticOperator(selector);
    211       }
    212       if (Problem != null) {
    213         foreach (ISingleObjectiveSelector selector in Selectors.OfType<ISingleObjectiveSelector>()) {
    214           selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    215           selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    216         }
    217       }
    218     }
    219     private void UpdateSelectors() {
    220       if (ApplicationManager.Manager != null) {
    221         ISelector oldSelector = SelectorParameter.Value;
    222         SelectorParameter.ValidValues.Clear();
    223         foreach (ISelector selector in Selectors.OrderBy(x => x.Name))
    224           SelectorParameter.ValidValues.Add(selector);
    225         if (oldSelector != null)
    226           SelectorParameter.Value = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());
    227       }
    228     }
    229     private void UpdateCrossovers() {
    230       ICrossover oldCrossover = CrossoverParameter.Value;
    231       CrossoverParameter.ValidValues.Clear();
    232       foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
    233         CrossoverParameter.ValidValues.Add(crossover);
    234       if (oldCrossover != null)
    235         CrossoverParameter.Value = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
    236     }
    237     private void UpdateMutators() {
    238       IManipulator oldMutator = MutatorParameter.Value;
    239       MutatorParameter.ValidValues.Clear();
    240       foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
    241         MutatorParameter.ValidValues.Add(mutator);
    242       if (oldMutator != null)
    243         MutatorParameter.Value = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    244     }
    245     #endregion
    246      */
     317    private void ParameterizeMoveEvaluator() {
     318      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
     319        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     320      }
     321    }
     322    private void ParameterizeMoveMaker() {
     323      foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
     324        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     325        if (MoveEvaluator != null)
     326          op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
     327      }
     328    }
     329    #endregion
    247330  }
    248331}
  • trunk/sources/HeuristicLab.Algorithms.TS/3.3/TSMainLoop.cs

    r3048 r3074  
    4242      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    4343    }
    44     public SubScopesLookupParameter<DoubleValue> QualityParameter {
    45       get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; }
     44    public LookupParameter<DoubleValue> QualityParameter {
     45      get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
     46    }
     47    public LookupParameter<DoubleValue> MoveQualityParameter {
     48      get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    4649    }
    4750    public ValueLookupParameter<IntValue> MaximumIterationsParameter {
     
    5760      get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; }
    5861    }
    59     public ValueLookupParameter<IOperator> MoveQualityEvaluatorParameter {
    60       get { return (ValueLookupParameter<IOperator>)Parameters["MoveQualityEvaluator"]; }
    61     }
    62     public ValueLookupParameter<IOperator> MoveTabuEvaluatorParameter {
    63       get { return (ValueLookupParameter<IOperator>)Parameters["MoveTabuEvaluator"]; }
    64     }
    65     public ValueLookupParameter<IOperator> TabuSelectorParameter {
    66       get { return (ValueLookupParameter<IOperator>)Parameters["TabuSelector"]; }
    67     }
    68     public ValueLookupParameter<IOperator> MoveTabuMakerParameter {
    69       get { return (ValueLookupParameter<IOperator>)Parameters["MoveTabuMaker"]; }
     62    public ValueLookupParameter<IOperator> MoveEvaluatorParameter {
     63      get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; }
    7064    }
    7165    public ValueLookupParameter<IOperator> MoveMakerParameter {
    7266      get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }
     67    }
     68    public ValueLookupParameter<IOperator> TabuMoveEvaluatorParameter {
     69      get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveEvaluator"]; }
     70    }
     71    public ValueLookupParameter<IOperator> TabuMoveMakerParameter {
     72      get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveMaker"]; }
    7373    }
    7474
     
    8686      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
    8787      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    88       Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     88      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     89      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
    8990      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
    9091      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu"));
     
    9293
    9394      Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves."));
    94       Parameters.Add(new ValueLookupParameter<IOperator>("MoveQualityEvaluator", "The operator that evaluates the quality of a move."));
    95       Parameters.Add(new ValueLookupParameter<IOperator>("MoveTabuEvaluator", "The operator that evaluates whether a move is tabu."));
    96       Parameters.Add(new ValueLookupParameter<IOperator>("MoveTabuMaker", "The operator that declares a move tabu."));
    9795      Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
     96      Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move."));
     97      Parameters.Add(new ValueLookupParameter<IOperator>("TabuMoveEvaluator", "The operator that evaluates whether a move is tabu."));
     98      Parameters.Add(new ValueLookupParameter<IOperator>("TabuMoveMaker", "The operator that declares a move tabu."));
    9899
    99100      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied."));
     
    108109      Placeholder moveGenerator = new Placeholder();
    109110      UniformSequentialSubScopesProcessor moveEvaluationProcessor = new UniformSequentialSubScopesProcessor();
    110       Placeholder moveQualityEvaluator = new Placeholder();
    111       Placeholder moveTabuEvaluator = new Placeholder();
     111      Placeholder moveEvaluator = new Placeholder();
     112      Placeholder tabuMoveEvaluator = new Placeholder();
    112113      SubScopesSorter moveQualitySorter = new SubScopesSorter();
    113114      BestAverageWorstQualityCalculator bestAverageWorstMoveQualityCalculator = new BestAverageWorstQualityCalculator();
     
    115116      RightReducer rightReducer = new RightReducer();
    116117      UniformSequentialSubScopesProcessor moveMakingProcessor = new UniformSequentialSubScopesProcessor();
    117       Placeholder moveTabuMaker = new Placeholder();
     118      Placeholder tabuMoveMaker = new Placeholder();
    118119      Placeholder moveMaker = new Placeholder();
    119120      DataTableValuesCollector valuesCollector = new DataTableValuesCollector();
     
    143144      moveGenerator.OperatorParameter.ActualName = "MoveGenerator";
    144145
    145       moveQualityEvaluator.Name = "MoveQualityEvaluator (placeholder)";
    146       moveQualityEvaluator.OperatorParameter.ActualName = "MoveQualityEvaluator";
    147 
    148       moveTabuEvaluator.Name = "MoveTabuEvaluator (placeholder)";
    149       moveTabuEvaluator.OperatorParameter.ActualName = "MoveTabuEvaluator";
     146      moveEvaluator.Name = "MoveEvaluator (placeholder)";
     147      moveEvaluator.OperatorParameter.ActualName = "MoveEvaluator";
     148
     149      tabuMoveEvaluator.Name = "TabuMoveEvaluator (placeholder)";
     150      tabuMoveEvaluator.OperatorParameter.ActualName = "TabuMoveEvaluator";
    150151
    151152      moveQualitySorter.DescendingParameter.ActualName = "Maximization";
     
    162163      moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)";
    163164
    164       moveTabuMaker.Name = "MoveTabuMaker (placeholder)";
    165       moveTabuMaker.OperatorParameter.ActualName = "MoveTabuMaker";
     165      tabuMoveMaker.Name = "TabuMoveMaker (placeholder)";
     166      tabuMoveMaker.OperatorParameter.ActualName = "TabuMoveMaker";
    166167
    167168      moveMaker.Name = "MoveMaker (placeholder)";
     
    198199      mainProcessor.Successor = valuesCollector;
    199200      moveGenerator.Successor = moveEvaluationProcessor;
    200       moveEvaluationProcessor.Operator = moveQualityEvaluator;
     201      moveEvaluationProcessor.Operator = moveEvaluator;
    201202      moveEvaluationProcessor.Successor = moveQualitySorter;
    202       moveQualityEvaluator.Successor = moveTabuEvaluator;
     203      moveEvaluator.Successor = tabuMoveEvaluator;
    203204      moveQualitySorter.Successor = bestAverageWorstMoveQualityCalculator;
    204205      bestAverageWorstMoveQualityCalculator.Successor = tabuSelector;
    205206      tabuSelector.Successor = rightReducer;
    206207      rightReducer.Successor = moveMakingProcessor;
    207       moveMakingProcessor.Operator = moveTabuMaker;
     208      moveMakingProcessor.Operator = tabuMoveMaker;
    208209      moveMakingProcessor.Successor = subScopesRemover;
    209       moveTabuMaker.Successor = moveMaker;
     210      tabuMoveMaker.Successor = moveMaker;
    210211      valuesCollector.Successor = iterationsCounter;
    211212      iterationsCounter.Successor = iterationsComparator;
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj

    r3053 r3074  
    9898    <Compile Include="Interfaces\IPermutationMoveOperator.cs" />
    9999    <Compile Include="Interfaces\IPermutationOperator.cs" />
     100    <Compile Include="Interfaces\IThreeOptPermutationMoveOperator.cs" />
    100101    <Compile Include="Interfaces\ITwoOptPermutationMoveOperator.cs" />
    101102    <Compile Include="Manipulators\InsertionManipulator.cs" />
     
    106107    <Compile Include="Manipulators\TranslocationInversionManipulator.cs" />
    107108    <Compile Include="Manipulators\TranslocationManipulator.cs" />
     109    <Compile Include="Moves\ThreeIndexMove.cs" />
     110    <Compile Include="Moves\ThreeOpt\StochasticThreeOptMoveGenerator.cs" />
     111    <Compile Include="Moves\ThreeOpt\ThreeOptMove.cs" />
     112    <Compile Include="Moves\ThreeOpt\ThreeOptMoveGenerator.cs" />
    108113    <Compile Include="Moves\TwoOpt\ExhaustiveTwoOptMoveGenerator.cs">
    109114      <SubType>Code</SubType>
     
    120125      <SubType>Code</SubType>
    121126    </Compile>
    122     <Compile Include="Moves\TwoOpt\TwoOptMoveTabuAttribute.cs">
    123       <SubType>Code</SubType>
    124     </Compile>
    125     <Compile Include="Moves\TwoOpt\TwoOptMoveTabuEvaluator.cs">
    126       <SubType>Code</SubType>
    127     </Compile>
    128     <Compile Include="Moves\TwoOpt\TwoOptMoveTabuMaker.cs">
    129       <SubType>Code</SubType>
    130     </Compile>
     127    <Compile Include="Moves\TwoOpt\TwoOptTabuMoveAttribute.cs" />
     128    <Compile Include="Moves\TwoOpt\TwoOptTabuMoveEvaluator.cs" />
     129    <Compile Include="Moves\TwoOpt\TwoOptTabuMoveMaker.cs" />
    131130    <Compile Include="PermutationManipulator.cs" />
    132131    <Compile Include="PermutationCrossover.cs" />
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/StochasticTwoOptMoveGenerator.cs

    r3053 r3074  
    3838    }
    3939
     40    public IntValue SampleSize {
     41      get { return SampleSizeParameter.Value; }
     42      set { SampleSizeParameter.Value = value; }
     43    }
     44
    4045    public StochasticTwoOptMoveGenerator()
    4146      : base() {
     
    5055      TwoOptMove[] moves = new TwoOptMove[sampleSize];
    5156      for (int i = 0; i < sampleSize; i++) {
    52         int index1 = random.Next(length - 1);
    53         int index2 = random.Next(index1 + 1, length);
     57        int index1 = random.Next(length - 1), index2;
     58        if (index1 >= 2)
     59          index2 = random.Next(index1 + 1, length);
     60        else index2 = random.Next(index1 + 1, length - (2 - index1));
    5461        moves[i] = new TwoOptMove(index1, index2);
    5562      }
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/TwoOptMoveGenerator.cs

    r3053 r3074  
    3535    }
    3636    public ILookupParameter<TwoOptMove> TwoOptMoveParameter {
    37       get { return (LookupParameter<TwoOptMove>)Parameters["Move"]; }
     37      get { return (LookupParameter<TwoOptMove>)Parameters["TwoOptMove"]; }
    3838    }
    3939    protected ScopeParameter CurrentScopeParameter {
     
    4444      : base() {
    4545      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation for which moves should be generated."));
    46       Parameters.Add(new LookupParameter<TwoOptMove>("Move", "The moves that should be generated in subscopes."));
     46      Parameters.Add(new LookupParameter<TwoOptMove>("TwoOptMove", "The moves that should be generated in subscopes."));
    4747      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
    4848    }
     
    6161
    6262    protected abstract TwoOptMove[] GenerateMoves(Permutation permutation);
     63
     64    public override bool CanChangeName {
     65      get { return false; }
     66    }
    6367  }
    6468}
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/TwoOptMoveMaker.cs

    r3053 r3074  
    3333  public class TwoOptMoveMaker : SingleSuccessorOperator, ITwoOptPermutationMoveOperator, IMoveMaker {
    3434    public ILookupParameter<DoubleValue> QualityParameter {
    35       get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
     35      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    3636    }
    3737    public ILookupParameter<DoubleValue> MoveQualityParameter {
    38       get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
     38      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    3939    }
    4040    public ILookupParameter<TwoOptMove> TwoOptMoveParameter {
    41       get { return (LookupParameter<TwoOptMove>)Parameters["Move"]; }
     41      get { return (ILookupParameter<TwoOptMove>)Parameters["TwoOptMove"]; }
    4242    }
    4343    public ILookupParameter<Permutation> PermutationParameter {
     
    4848      : base() {
    4949      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
    50       Parameters.Add(new LookupParameter<TwoOptMove>("Move", "The move to evaluate."));
     50      Parameters.Add(new LookupParameter<TwoOptMove>("TwoOptMove", "The move to evaluate."));
    5151      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
    5252      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation."));
     
    6464      return base.Apply();
    6565    }
     66
     67    public override bool CanChangeName {
     68      get { return false; }
     69    }
    6670  }
    6771}
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/HeuristicLab.Problems.TSP-3.3.csproj

    r3066 r3074  
    8989    <Compile Include="Interfaces\ITSPCoordinatesPathEvaluator.cs" />
    9090    <Compile Include="Interfaces\ITSPEvaluator.cs" />
     91    <Compile Include="Interfaces\ITSPMoveEvaluator.cs" />
    9192    <Compile Include="Interfaces\ITSPPathEvaluator.cs" />
    9293    <Compile Include="HeuristicLabProblemsTSPPlugin.cs" />
    93     <Compile Include="MoveEvaluators\TwoOptMoveTSPEvaluator.cs">
     94    <Compile Include="Interfaces\ITSPPathMoveEvaluator.cs" />
     95    <Compile Include="MoveEvaluators\TwoOptMoveTSPRoundedEuclideanPathEvaluator.cs" />
     96    <Compile Include="MoveEvaluators\TSPPathMoveEvaluator.cs" />
     97    <Compile Include="MoveEvaluators\TSPMoveEvaluator.cs" />
     98    <Compile Include="MoveEvaluators\TwoOptMoveTSPCoordinatesPathEvaluator.cs">
    9499      <SubType>Code</SubType>
    95100    </Compile>
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs

    r3066 r3074  
    196196      OnEvaluatorChanged();
    197197    }
     198    private void MoveGenerator_TwoOptMoveParameter_ActualNameChanged(object sender, EventArgs e) {
     199      string name = ((ILookupParameter<TwoOptMove>)sender).ActualName;
     200      foreach (ITwoOptPermutationMoveOperator op in Operators.OfType<ITwoOptPermutationMoveOperator>()) {
     201        if (!(op is IMoveGenerator)) op.TwoOptMoveParameter.ActualName = name;
     202      }
     203    }
     204    private void MoveGenerator_ThreeOptMoveParameter_ActualNameChanged(object sender, EventArgs e) {
     205      string name = ((ILookupParameter<ThreeOptMove>)sender).ActualName;
     206      foreach (IThreeOptPermutationMoveOperator op in Operators.OfType<IThreeOptPermutationMoveOperator>()) {
     207        if (!(op is IMoveGenerator)) op.ThreeOptMoveParameter.ActualName = name;
     208      }
     209    }
    198210    #endregion
    199211
     
    228240        ParameterizeOperators();
    229241      }
     242      InitializeMoveGenerators();
    230243    }
    231244    private void ParameterizeOperators() {
     
    237250        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    238251      }
    239     }
     252      foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) {
     253        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     254      }
     255      foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>()) {
     256        op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     257        op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
     258        op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
     259      }
     260    }
     261    private void InitializeMoveGenerators() {
     262      foreach (ITwoOptPermutationMoveOperator op in Operators.OfType<ITwoOptPermutationMoveOperator>()) {
     263        if (op is IMoveGenerator) {
     264          op.TwoOptMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_TwoOptMoveParameter_ActualNameChanged);
     265        }
     266      }
     267      foreach (IThreeOptPermutationMoveOperator op in Operators.OfType<IThreeOptPermutationMoveOperator>()) {
     268        if (op is IMoveGenerator) {
     269          op.ThreeOptMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_ThreeOptMoveParameter_ActualNameChanged);
     270        }
     271      }
     272    }
     273
    240274    private void ClearDistanceMatrix() {
    241275      DistanceMatrixParameter.Value = null;
Note: See TracChangeset for help on using the changeset viewer.