Changeset 3621


Ignore:
Timestamp:
05/05/10 02:52:59 (12 years ago)
Author:
abeham
Message:

Updated local search to make use of Analyzers #999

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

Legend:

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

    r3616 r3621  
    3333using HeuristicLab.PluginInfrastructure;
    3434using HeuristicLab.Random;
     35using HeuristicLab.Analysis;
    3536
    3637namespace HeuristicLab.Algorithms.LocalSearch {
     
    7172      get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
    7273    }
     74    private ValueParameter<MultiAnalyzer> MoveAnalyzerParameter {
     75      get { return (ValueParameter<MultiAnalyzer>)Parameters["MoveAnalyzer"]; }
     76    }
     77    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
     78      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     79    }
    7380    #endregion
    7481
     
    102109      set { SampleSizeParameter.Value = value; }
    103110    }
     111    public MultiAnalyzer MoveAnalyzer {
     112      get { return MoveAnalyzerParameter.Value; }
     113      set { MoveAnalyzerParameter.Value = value; }
     114    }
     115    public MultiAnalyzer Analyzer {
     116      get { return AnalyzerParameter.Value; }
     117      set { AnalyzerParameter.Value = value; }
     118    }
    104119    private RandomCreator RandomCreator {
    105120      get { return (RandomCreator)OperatorGraph.InitialOperator; }
     
    111126      get { return (LocalSearchMainLoop)SolutionsCreator.Successor; }
    112127    }
    113     #endregion
    114 
     128    private BestAverageWorstQualityAnalyzer moveQualityAnalyzer;
     129    #endregion
     130
     131    [StorableConstructor]
     132    private LocalSearch(bool deserializing) : base(deserializing) { }
    115133    public LocalSearch()
    116134      : base() {
     
    122140      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    123141      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(100)));
    124 
     142      Parameters.Add(new ValueParameter<MultiAnalyzer>("MoveAnalyzer", "The operator used to analyze the moves in each iteration.", new MultiAnalyzer()));
     143      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each iteration.", new MultiAnalyzer()));
     144     
    125145      RandomCreator randomCreator = new RandomCreator();
    126146      SolutionsCreator solutionsCreator = new SolutionsCreator();
     
    144164      lsMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    145165      lsMainLoop.ResultsParameter.ActualName = "Results";
     166      lsMainLoop.MoveAnalyzerParameter.ActualName = MoveAnalyzerParameter.Name;
     167      lsMainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    146168
    147169      Initialize();
    148170    }
    149     [StorableConstructor]
    150     private LocalSearch(bool deserializing) : base(deserializing) { }
    151171
    152172    public override IDeepCloneable Clone(Cloner cloner) {
     
    173193      ParameterizeMoveEvaluators();
    174194      ParameterizeMoveMakers();
     195      ParameterizeAnalyzers();
    175196      UpdateMoveGenerator();
    176197      UpdateMoveParameters();
     198      UpdateAnalyzers();
    177199      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    178200      base.OnProblemChanged();
     
    189211      ParameterizeMoveEvaluators();
    190212      ParameterizeMoveMakers();
     213      ParameterizeAnalyzers();
    191214      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    192215      base.Problem_EvaluatorChanged(sender, e);
     
    202225      UpdateMoveGenerator();
    203226      UpdateMoveParameters();
     227      UpdateAnalyzers();
    204228      ParameterizeMainLoop();
    205229      ParameterizeMoveEvaluators();
     
    219243      ParameterizeMoveEvaluators();
    220244      ParameterizeMoveMakers();
     245      ParameterizeAnalyzers();
    221246    }
    222247    private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
     
    224249      ParameterizeMoveEvaluators();
    225250      ParameterizeMoveMakers();
     251      ParameterizeAnalyzers();
    226252    }
    227253    #endregion
     
    230256    [StorableHook(HookType.AfterDeserialization)]
    231257    private void Initialize() {
     258      InitializeAnalyzers();
     259      UpdateAnalyzers();
    232260      if (Problem != null) {
    233261        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    238266      MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
    239267      MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged);
     268    }
     269    private void InitializeAnalyzers() {
     270      moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     271      ParameterizeAnalyzers();
    240272    }
    241273    private void UpdateMoveGenerator() {
     
    281313      }
    282314    }
     315    private void UpdateAnalyzers() {
     316      Analyzer.Operators.Clear();
     317      MoveAnalyzer.Operators.Clear();
     318      MoveAnalyzer.Operators.Add(moveQualityAnalyzer);
     319      /*if (Problem != null) {
     320        foreach (ISolutionAnalyzer analyzer in Problem.Operators.OfType<ISolutionAnalyzer>().OrderBy(x => x.Name))
     321          Analyzer.Operators.Add(analyzer);
     322      }*/
     323    }
    283324    private void ClearMoveParameters() {
    284325      MoveMakerParameter.ValidValues.Clear();
     
    312353      }
    313354    }
     355    private void ParameterizeAnalyzers() {
     356      moveQualityAnalyzer.ResultsParameter.ActualName = "Results";
     357      if (Problem != null) {
     358        moveQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     359        if (MoveEvaluator != null)
     360          moveQualityAnalyzer.QualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
     361        moveQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     362      }
     363    }
    314364    #endregion
    315365  }
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs

    r3376 r3621  
    6868      get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }
    6969    }
    70     public ValueLookupParameter<IOperator> VisualizerParameter {
    71       get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; }
    72     }
    73     public LookupParameter<IItem> VisualizationParameter {
    74       get { return (LookupParameter<IItem>)Parameters["Visualization"]; }
     70    public ValueLookupParameter<IOperator> MoveAnalyzerParameter {
     71      get { return (ValueLookupParameter<IOperator>)Parameters["MoveAnalyzer"]; }
     72    }
     73    public ValueLookupParameter<IOperator> AnalyzerParameter {
     74      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
    7575    }
    7676
     
    104104      Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move."));
    105105
    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."));
     106      Parameters.Add(new ValueLookupParameter<IOperator>("MoveAnalyzer", "The operator used to analyze the moves in each iteration."));
     107      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each iteration."));
    108108      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied."));
    109109      #endregion
     
    111111      #region Create operators
    112112      VariableCreator variableCreator = new VariableCreator();
    113       BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer();
    114       BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer();
    115       DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector();
    116       QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator();
    117       Placeholder visualizer1 = new Placeholder();
    118       ResultsCollector resultsCollector = new ResultsCollector();
     113      ResultsCollector resultsCollector1 = new ResultsCollector();
     114      UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
     115      Placeholder analyzer1 = new Placeholder();
    119116      UniformSubScopesProcessor mainProcessor = new UniformSubScopesProcessor();
    120117      Placeholder moveGenerator = new Placeholder();
    121118      UniformSubScopesProcessor moveEvaluationProcessor = new UniformSubScopesProcessor();
    122119      Placeholder moveEvaluator = new Placeholder();
     120      Placeholder moveAnalyzer = new Placeholder();
    123121      BestSelector bestSelector = new BestSelector();
    124122      RightReducer rightReducer = new RightReducer();
     
    130128      IntCounter iterationsCounter = new IntCounter();
    131129      Comparator iterationsComparator = new Comparator();
    132       BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer();
    133       BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer();
    134       DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector();
    135       QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator();
    136       Placeholder visualizer2 = new Placeholder();
     130      ResultsCollector resultsCollector2 = new ResultsCollector();
     131      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
     132      Placeholder analyzer2 = new Placeholder();
    137133      ConditionalBranch iterationsTermination = new ConditionalBranch();
    138134
    139135      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
    140136
    141       bestQualityMemorizer1.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
    142       bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name;
    143       bestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name;
    144 
    145       bestQualityMemorizer2.BestQualityParameter.ActualName = "BestQuality";
    146       bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name;
    147       bestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name;
    148 
    149       dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));
    150       dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
    151       dataTableValuesCollector1.DataTableParameter.ActualName = "Qualities";
    152 
    153       qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
    154       qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
    155       qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
    156       qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
    157 
    158       visualizer1.Name = "Visualizer (placeholder)";
    159       visualizer1.OperatorParameter.ActualName = VisualizerParameter.Name;
    160 
    161       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
    162       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
    163       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
    164       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
    165       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
    166       resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, VisualizationParameter.Name));
    167       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
    168       resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
     137      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
     138      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
     139
     140      analyzer1.Name = "Analyzer (placeholder)";
     141      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
    169142
    170143      mainProcessor.Name = "Solution processor (UniformSubScopesProcessor)";
     
    175148      moveEvaluator.Name = "MoveEvaluator (placeholder)";
    176149      moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name;
     150
     151      moveAnalyzer.Name = "MoveAnalyzer (placeholder)";
     152      moveAnalyzer.OperatorParameter.ActualName = MoveAnalyzerParameter.Name;
    177153
    178154      bestSelector.CopySelected = new BoolValue(false);
     
    204180      iterationsComparator.ResultParameter.ActualName = "Terminate";
    205181
    206       bestQualityMemorizer3.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
    207       bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name;
    208       bestQualityMemorizer3.QualityParameter.ActualName = QualityParameter.Name;
    209 
    210       bestQualityMemorizer4.BestQualityParameter.ActualName = "BestQuality";
    211       bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name;
    212       bestQualityMemorizer4.QualityParameter.ActualName = QualityParameter.Name;
    213 
    214       dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));
    215       dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
    216       dataTableValuesCollector2.DataTableParameter.ActualName = "Qualities";
    217 
    218       qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
    219       qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
    220       qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
    221       qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
    222 
    223       visualizer2.Name = "Visualizer (placeholder)";
    224       visualizer2.OperatorParameter.ActualName = VisualizerParameter.Name;
     182      resultsCollector2.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
     183      resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name;
     184
     185      analyzer2.Name = "Analyzer (placeholder)";
     186      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
    225187
    226188      iterationsTermination.Name = "Iterations Termination Condition";
     
    230192      #region Create operator graph
    231193      OperatorGraph.InitialOperator = variableCreator;
    232       variableCreator.Successor = bestQualityMemorizer1;
    233       bestQualityMemorizer1.Successor = bestQualityMemorizer2;
    234       bestQualityMemorizer2.Successor = dataTableValuesCollector1;
    235       dataTableValuesCollector1.Successor = qualityDifferenceCalculator1;
    236       qualityDifferenceCalculator1.Successor = visualizer1;
    237       visualizer1.Successor = resultsCollector;
    238       resultsCollector.Successor = mainProcessor;
     194      variableCreator.Successor = resultsCollector1;
     195      resultsCollector1.Successor = uniformSubScopesProcessor0;
     196      uniformSubScopesProcessor0.Operator = analyzer1;
     197      uniformSubScopesProcessor0.Successor = mainProcessor;
     198      analyzer1.Successor = null;
    239199      mainProcessor.Operator = moveGenerator;
    240200      mainProcessor.Successor = iterationsCounter;
    241201      moveGenerator.Successor = moveEvaluationProcessor;
    242202      moveEvaluationProcessor.Operator = moveEvaluator;
    243       moveEvaluationProcessor.Successor = bestSelector;
     203      moveEvaluationProcessor.Successor = moveAnalyzer;
     204      moveAnalyzer.Successor = bestSelector;
    244205      bestSelector.Successor = rightReducer;
    245206      rightReducer.Successor = moveMakingProcessor;
     
    253214      moveMaker.Successor = null;
    254215      iterationsCounter.Successor = iterationsComparator;
    255       iterationsComparator.Successor = bestQualityMemorizer3;
    256       bestQualityMemorizer3.Successor = bestQualityMemorizer4;
    257       bestQualityMemorizer4.Successor = dataTableValuesCollector2;
    258       dataTableValuesCollector2.Successor = qualityDifferenceCalculator2;
    259       qualityDifferenceCalculator2.Successor = visualizer2;
    260       visualizer2.Successor = iterationsTermination;
     216      iterationsComparator.Successor = resultsCollector2;
     217      resultsCollector2.Successor = uniformSubScopesProcessor1;
     218      uniformSubScopesProcessor1.Operator = analyzer2;
     219      uniformSubScopesProcessor1.Successor = iterationsTermination;
     220      analyzer2.Successor = null;
    261221      iterationsTermination.TrueBranch = null;
    262222      iterationsTermination.FalseBranch = mainProcessor;
Note: See TracChangeset for help on using the changeset viewer.