Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3141


Ignore:
Timestamp:
03/20/10 16:15:26 (15 years ago)
Author:
abeham
Message:

updated Tabu Search (reporting and visualization) #840

Location:
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3
Files:
2 edited

Legend:

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

    r3131 r3141  
    7474      get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    7575    }
     76    private ValueParameter<IntValue> SampleSizeParameter {
     77      get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
     78    }
    7679    #endregion
    7780
     
    124127    #endregion
    125128
     129    [StorableConstructor]
     130    public TabuSearch(bool deserializing) : base() { }
    126131    public TabuSearch()
    127132      : base() {
     
    135140      Parameters.Add(new ValueParameter<IntValue>("TabuTenure", "The length of the tabu list.", new IntValue(10)));
    136141      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     142      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The neighborhood size for stochastic sampling move generators", new IntValue(20)));
    137143
    138144      RandomCreator randomCreator = new RandomCreator();
     
    163169    }
    164170
    165     [StorableConstructor]
    166     private TabuSearch(bool deserializing) : base() { }
    167 
    168171    public override IDeepCloneable Clone(Cloner cloner) {
    169172      TabuSearch clone = (TabuSearch)base.Clone(cloner);
     
    185188      ParameterizeSolutionsCreator();
    186189      ParameterizeMainLoop();
     190      ParameterizeMoveGenerators();
    187191      ParameterizeMoveEvaluator();
    188192      ParameterizeMoveMaker();
     
    204208      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    205209      base.Problem_EvaluatorChanged(sender, e);
     210    }
     211    protected override void Problem_VisualizerChanged(object sender, EventArgs e) {
     212      ParameterizeStochasticOperator(Problem.Visualizer);
     213      ParameterizeMainLoop();
     214      if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
     215      base.Problem_VisualizerChanged(sender, e);
    206216    }
    207217    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     
    222232        UpdateMoveParameters();
    223233      ParameterizeMainLoop();
     234      ParameterizeMoveGenerators();
    224235      ParameterizeMoveEvaluator();
    225236      ParameterizeMoveMaker();
     
    249260    private void TabuMoveEvaluator_MoveTabuParameter_ActualNameChanged(object sender, EventArgs e) {
    250261      ParameterizeMainLoop();
     262    }
     263    private void Visualizer_VisualizationParameter_ActualNameChanged(object sender, EventArgs e) {
     264      ParameterizeMainLoop();
     265    }
     266    private void SampleSizeParameter_NameChanged(object sender, EventArgs e) {
     267      ParameterizeMoveGenerators();
    251268    }
    252269    #endregion
     
    260277          op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    261278        }
     279        if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
    262280      }
    263281      MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
    264282      MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
    265283      TabuMoveEvaluatorParameter.ValueChanged += new EventHandler(TabuMoveEvaluatorParameter_ValueChanged);
     284      SampleSizeParameter.NameChanged += new EventHandler(SampleSizeParameter_NameChanged);
    266285    }
    267286    private void UpdateMoveGenerator() {
     
    269288      MoveGeneratorParameter.ValidValues.Clear();
    270289      if (Problem != null) {
    271         foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name))
     290        foreach (IMoveGenerator generator in Problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name)) {
    272291          MoveGeneratorParameter.ValidValues.Add(generator);
     292        }
    273293      }
    274294      if (oldMoveGenerator != null && MoveGeneratorParameter.ValidValues.Any(x => x.GetType() == oldMoveGenerator.GetType()))
     
    330350    }
    331351    private void ParameterizeMainLoop() {
     352      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    332353      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    333354      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     
    336357      if (TabuMoveEvaluator != null)
    337358        MainLoop.MoveTabuParameter.ActualName = TabuMoveEvaluator.MoveTabuParameter.ActualName;
     359      MainLoop.VisualizerParameter.ActualName = Problem.VisualizerParameter.Name;
     360      if (Problem.Visualizer != null)
     361        MainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName;
    338362    }
    339363    private void ParameterizeStochasticOperator(IOperator op) {
    340364      if (op is IStochasticOperator)
    341365        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
     366    }
     367    private void ParameterizeMoveGenerators() {
     368      if (Problem != null) {
     369        foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>())
     370          generator.SampleSizeParameter.ActualName = SampleSizeParameter.Name;
     371      }
    342372    }
    343373    private void ParameterizeMoveEvaluator() {
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearchMainLoop.cs

    r3132 r3141  
    3434  [Item("TabuSearchMainLoop", "An operator which represents the main loop of a tabu search.")]
    3535  [StorableClass]
    36   public class TabuSearchMainLoop : AlgorithmOperator {
     36  public sealed class TabuSearchMainLoop : AlgorithmOperator {
    3737    #region Parameter properties
    3838    public ValueLookupParameter<IRandom> RandomParameter {
     
    4545      get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
    4646    }
     47    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
     48      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     49    }
    4750    public LookupParameter<DoubleValue> MoveQualityParameter {
    4851      get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
     
    5760      get { return (ValueLookupParameter<IntValue>)Parameters["TabuTenure"]; }
    5861    }
     62    public ValueLookupParameter<IOperator> MoveGeneratorParameter {
     63      get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; }
     64    }
     65    public ValueLookupParameter<IOperator> MoveEvaluatorParameter {
     66      get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; }
     67    }
     68    public ValueLookupParameter<IOperator> MoveMakerParameter {
     69      get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }
     70    }
     71    public ValueLookupParameter<IOperator> TabuMoveEvaluatorParameter {
     72      get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveEvaluator"]; }
     73    }
     74    public ValueLookupParameter<IOperator> TabuMoveMakerParameter {
     75      get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveMaker"]; }
     76    }
     77    public ValueLookupParameter<IOperator> VisualizerParameter {
     78      get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; }
     79    }
     80    public LookupParameter<IItem> VisualizationParameter {
     81      get { return (LookupParameter<IItem>)Parameters["Visualization"]; }
     82    }
    5983    public ValueLookupParameter<VariableCollection> ResultsParameter {
    6084      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
    61     }
    62     public ValueLookupParameter<IOperator> MoveGeneratorParameter {
    63       get { return (ValueLookupParameter<IOperator>)Parameters["MoveGenerator"]; }
    64     }
    65     public ValueLookupParameter<IOperator> MoveEvaluatorParameter {
    66       get { return (ValueLookupParameter<IOperator>)Parameters["MoveEvaluator"]; }
    67     }
    68     public ValueLookupParameter<IOperator> MoveMakerParameter {
    69       get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }
    70     }
    71     public ValueLookupParameter<IOperator> TabuMoveEvaluatorParameter {
    72       get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveEvaluator"]; }
    73     }
    74     public ValueLookupParameter<IOperator> TabuMoveMakerParameter {
    75       get { return (ValueLookupParameter<IOperator>)Parameters["TabuMoveMaker"]; }
    76     }
    77 
    78     private ScopeParameter CurrentScopeParameter {
    79       get { return (ScopeParameter)Parameters["CurrentScope"]; }
    80     }
    81     public IScope CurrentScope {
    82       get { return CurrentScopeParameter.ActualValue; }
    8385    }
    8486    #endregion
     
    9092      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    9193      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     94      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
    9295      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
    9396      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The value that indicates if a move is tabu or not."));
    9497      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
    9598      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu"));
    96       Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    97 
     99     
    98100      Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves."));
    99101      Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
     
    102104      Parameters.Add(new ValueLookupParameter<IOperator>("TabuMoveMaker", "The operator that declares a move tabu."));
    103105
    104       Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied."));
     106      Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions."));
     107      Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions."));
     108      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    105109      #endregion
    106110
     
    108112      TabuListCreator tabuListCreator = new TabuListCreator();
    109113      VariableCreator variableCreator = new VariableCreator();
    110       BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer();
     114      BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer();
     115      BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer();
     116      QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator();
     117      Placeholder visualizer1 = new Placeholder();
    111118      ResultsCollector resultsCollector = new ResultsCollector();
    112119      UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor();
     
    126133      IntCounter iterationsCounter = new IntCounter();
    127134      Comparator iterationsComparator = new Comparator();
     135      BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer();
     136      BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer();
     137      QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator();
     138      Placeholder visualizer2 = new Placeholder();
    128139      ConditionalBranch iterationsTermination = new ConditionalBranch();
    129       EmptyOperator finished = new EmptyOperator();
    130140
    131141      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
     
    135145      variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("MoveQualities", new DataTable("MoveQualities")));
    136146
     147      bestQualityMemorizer1.BestQualityParameter.ActualName = "BestQuality";
     148      bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name;
     149      bestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name;
     150
     151      bestQualityMemorizer2.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
     152      bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name;
     153      bestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name;
     154
     155      qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
     156      qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
     157      qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
     158      qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
     159
     160      visualizer1.Name = "Visualizer (placeholder)";
     161      visualizer1.OperatorParameter.ActualName = VisualizerParameter.Name;
     162
    137163      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
    138       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality") { ActualName = "BestQuality" });
     164      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
    139165      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Move Quality"));
    140166      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Move Quality"));
    141167      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Worst Move Quality"));
    142168      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("MoveQualities"));
     169      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
     170      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
     171      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
     172      resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, VisualizationParameter.Name));
    143173      resultsCollector.ResultsParameter.ActualName = "Results";
    144174
     
    146176
    147177      moveGenerator.Name = "MoveGenerator (placeholder)";
    148       moveGenerator.OperatorParameter.ActualName = "MoveGenerator";
     178      moveGenerator.OperatorParameter.ActualName = MoveGeneratorParameter.Name;
    149179
    150180      moveEvaluator.Name = "MoveEvaluator (placeholder)";
    151       moveEvaluator.OperatorParameter.ActualName = "MoveEvaluator";
     181      moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name;
    152182
    153183      tabuMoveEvaluator.Name = "TabuMoveEvaluator (placeholder)";
    154       tabuMoveEvaluator.OperatorParameter.ActualName = "TabuMoveEvaluator";
    155 
    156       moveQualitySorter.DescendingParameter.ActualName = "Maximization";
    157       moveQualitySorter.ValueParameter.ActualName = "MoveQuality";
     184      tabuMoveEvaluator.OperatorParameter.ActualName = TabuMoveEvaluatorParameter.Name;
     185
     186      moveQualitySorter.DescendingParameter.ActualName = MaximizationParameter.Name;
     187      moveQualitySorter.ValueParameter.ActualName = MoveQualityParameter.Name;
    158188
    159189      bestAverageWorstMoveQualityCalculator.AverageQualityParameter.ActualName = "Average Move Quality";
    160190      bestAverageWorstMoveQualityCalculator.BestQualityParameter.ActualName = "Best Move Quality";
    161191      bestAverageWorstMoveQualityCalculator.MaximizationParameter.ActualName = "Maximization";
    162       bestAverageWorstMoveQualityCalculator.QualityParameter.ActualName = "MoveQuality";
     192      bestAverageWorstMoveQualityCalculator.QualityParameter.ActualName = MoveQualityParameter.Name;
    163193      bestAverageWorstMoveQualityCalculator.WorstQualityParameter.ActualName = "Worst Move Quality";
    164 
    165       moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)";
    166 
    167       tabuMoveMaker.Name = "TabuMoveMaker (placeholder)";
    168       tabuMoveMaker.OperatorParameter.ActualName = "TabuMoveMaker";
    169 
    170       moveMaker.Name = "MoveMaker (placeholder)";
    171       moveMaker.OperatorParameter.ActualName = "MoveMaker";
    172 
     194     
    173195      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Move Quality"));
    174196      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Move Quality"));
     
    176198      valuesCollector.DataTableParameter.ActualName = "MoveQualities";
    177199
     200      moveMakingProcessor.Name = "MoveMaking processor (UniformSequentialSubScopesProcessor)";
     201
     202      tabuMoveMaker.Name = "TabuMoveMaker (placeholder)";
     203      tabuMoveMaker.OperatorParameter.ActualName = TabuMoveMakerParameter.Name;
     204
     205      moveMaker.Name = "MoveMaker (placeholder)";
     206      moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name;
     207
    178208      subScopesRemover.RemoveAllSubScopes = true;
    179209
     
    185215      iterationsComparator.Comparison = new Comparison(ComparisonType.Less);
    186216      iterationsComparator.LeftSideParameter.ActualName = "Iterations";
    187       iterationsComparator.RightSideParameter.ActualName = "MaximumIterations";
     217      iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
    188218      iterationsComparator.ResultParameter.ActualName = "IterationsCondition";
     219
     220      bestQualityMemorizer3.BestQualityParameter.ActualName = "BestQuality";
     221      bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name;
     222      bestQualityMemorizer3.QualityParameter.ActualName = QualityParameter.Name;
     223
     224      bestQualityMemorizer4.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
     225      bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name;
     226      bestQualityMemorizer4.QualityParameter.ActualName = QualityParameter.Name;
     227
     228      qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
     229      qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
     230      qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
     231      qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
     232
     233      visualizer2.Name = "Visualizer (placeholder)";
     234      visualizer2.OperatorParameter.ActualName = VisualizerParameter.Name;
    189235
    190236      iterationsTermination.Name = "Iterations Termination Condition";
     
    195241      OperatorGraph.InitialOperator = tabuListCreator;
    196242      tabuListCreator.Successor = variableCreator;
    197       variableCreator.Successor = bestQualityMemorizer;
    198       bestQualityMemorizer.Successor = resultsCollector;
     243      variableCreator.Successor = bestQualityMemorizer1;
     244      bestQualityMemorizer1.Successor = bestQualityMemorizer2;
     245      bestQualityMemorizer2.Successor = qualityDifferenceCalculator1;
     246      qualityDifferenceCalculator1.Successor = visualizer1;
     247      visualizer1.Successor = resultsCollector;
    199248      resultsCollector.Successor = mainProcessor;
    200249      mainProcessor.Operator = moveGenerator;
    201       mainProcessor.Successor = valuesCollector;
     250      mainProcessor.Successor = iterationsCounter;
    202251      moveGenerator.Successor = moveEvaluationProcessor;
    203252      moveEvaluationProcessor.Operator = moveEvaluator;
    204253      moveEvaluationProcessor.Successor = moveQualitySorter;
    205254      moveEvaluator.Successor = tabuMoveEvaluator;
     255      tabuMoveEvaluator.Successor = null;
    206256      moveQualitySorter.Successor = bestAverageWorstMoveQualityCalculator;
    207       bestAverageWorstMoveQualityCalculator.Successor = tabuSelector;
     257      bestAverageWorstMoveQualityCalculator.Successor = valuesCollector;
     258      valuesCollector.Successor = tabuSelector;
    208259      tabuSelector.Successor = rightReducer;
    209260      rightReducer.Successor = moveMakingProcessor;
     
    211262      moveMakingProcessor.Successor = subScopesRemover;
    212263      tabuMoveMaker.Successor = moveMaker;
    213       valuesCollector.Successor = iterationsCounter;
     264      moveMaker.Successor = null;
     265      subScopesRemover.Successor = null;
    214266      iterationsCounter.Successor = iterationsComparator;
    215       iterationsComparator.Successor = iterationsTermination;
    216       iterationsTermination.TrueBranch = bestQualityMemorizer;
    217       iterationsTermination.FalseBranch = finished;
     267      iterationsComparator.Successor = bestQualityMemorizer3;
     268      bestQualityMemorizer3.Successor = bestQualityMemorizer4;
     269      bestQualityMemorizer4.Successor = qualityDifferenceCalculator2;
     270      qualityDifferenceCalculator2.Successor = visualizer2;
     271      visualizer2.Successor = iterationsTermination;
     272      iterationsTermination.TrueBranch = mainProcessor;
     273      iterationsTermination.FalseBranch = null;
    218274      #endregion
    219275    }
Note: See TracChangeset for help on using the changeset viewer.