Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3809


Ignore:
Timestamp:
05/14/10 17:47:49 (15 years ago)
Author:
abeham
Message:

#893

  • fixed BestKnownQuality tracking in tabu search and local search
Location:
trunk/sources
Files:
5 edited

Legend:

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

    r3750 r3809  
    7272      get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
    7373    }
    74     private ValueParameter<MultiAnalyzer> MoveAnalyzerParameter {
    75       get { return (ValueParameter<MultiAnalyzer>)Parameters["MoveAnalyzer"]; }
    76     }
    7774    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
    7875      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     
    108105      get { return SampleSizeParameter.Value; }
    109106      set { SampleSizeParameter.Value = value; }
    110     }
    111     public MultiAnalyzer MoveAnalyzer {
    112       get { return MoveAnalyzerParameter.Value; }
    113       set { MoveAnalyzerParameter.Value = value; }
    114107    }
    115108    public MultiAnalyzer Analyzer {
     
    141134      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    142135      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(100)));
    143       Parameters.Add(new ValueParameter<MultiAnalyzer>("MoveAnalyzer", "The operator used to analyze the moves.", new MultiAnalyzer()));
    144       Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer()));
     136      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer()));
    145137     
    146138      RandomCreator randomCreator = new RandomCreator();
     
    165157      lsMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    166158      lsMainLoop.ResultsParameter.ActualName = "Results";
    167       lsMainLoop.MoveAnalyzerParameter.ActualName = MoveAnalyzerParameter.Name;
    168159      lsMainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    169160
     
    318309    private void UpdateAnalyzers() {
    319310      Analyzer.Operators.Clear();
    320       MoveAnalyzer.Operators.Clear();
    321       MoveAnalyzer.Operators.Add(moveQualityAnalyzer);
    322311      if (Problem != null) {
    323312        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
     
    327316        }
    328317      }
     318      Analyzer.Operators.Add(moveQualityAnalyzer);
    329319    }
    330320    private void ClearMoveParameters() {
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs

    r3750 r3809  
    6868      get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }
    6969    }
    70     public ValueLookupParameter<IOperator> MoveAnalyzerParameter {
    71       get { return (ValueLookupParameter<IOperator>)Parameters["MoveAnalyzer"]; }
    72     }
    7370    public ValueLookupParameter<IOperator> AnalyzerParameter {
    7471      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
     
    104101      Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move."));
    105102
    106       Parameters.Add(new ValueLookupParameter<IOperator>("MoveAnalyzer", "The operator used to analyze the moves."));
    107       Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution."));
     103      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution and moves."));
    108104      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied."));
    109105      #endregion
     
    123119      Placeholder moveAnalyzer = new Placeholder();
    124120      BestSelector bestSelector = new BestSelector();
    125       RightReducer rightReducer = new RightReducer();
    126121      SubScopesProcessor moveMakingProcessor = new SubScopesProcessor();
     122      UniformSubScopesProcessor selectedMoveMakingProcessor = new UniformSubScopesProcessor();
    127123      QualityComparator qualityComparator = new QualityComparator();
    128124      ConditionalBranch improvesQualityBranch = new ConditionalBranch();
    129125      Placeholder moveMaker = new Placeholder();
    130126      Assigner bestQualityUpdater = new Assigner();
     127      MergingReducer mergingReducer = new MergingReducer();
     128      Placeholder analyzer2 = new Placeholder();
    131129      SubScopesRemover subScopesRemover = new SubScopesRemover();
    132130      IntCounter iterationsCounter = new IntCounter();
    133131      Comparator iterationsComparator = new Comparator();
    134       SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
    135       Placeholder analyzer2 = new Placeholder();
    136132      ResultsCollector resultsCollector3 = new ResultsCollector();
    137133      ConditionalBranch iterationsTermination = new ConditionalBranch();
     
    167163      evaluatedMovesCounter.Increment = new IntValue(1);
    168164
    169       moveAnalyzer.Name = "MoveAnalyzer (placeholder)";
    170       moveAnalyzer.OperatorParameter.ActualName = MoveAnalyzerParameter.Name;
    171 
    172165      bestSelector.CopySelected = new BoolValue(false);
    173166      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
     
    187180      bestQualityUpdater.LeftSideParameter.ActualName = "BestQuality";
    188181      bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name;
     182
     183      analyzer2.Name = "Analyzer (placeholder)";
     184      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
    189185
    190186      subScopesRemover.RemoveAllSubScopes = true;
     
    199195      iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
    200196      iterationsComparator.ResultParameter.ActualName = "Terminate";
    201 
    202       analyzer2.Name = "Analyzer (placeholder)";
    203       analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
    204197
    205198      resultsCollector3.CopyValue = new BoolValue(true);
     
    228221      evaluatedMovesCounter.Successor = null;
    229222      moveAnalyzer.Successor = bestSelector;
    230       bestSelector.Successor = rightReducer;
    231       rightReducer.Successor = moveMakingProcessor;
    232       moveMakingProcessor.Operators.Add(qualityComparator);
    233       moveMakingProcessor.Successor = subScopesRemover;
    234       subScopesRemover.Successor = null;
     223      bestSelector.Successor = moveMakingProcessor;
     224      moveMakingProcessor.Operators.Add(new EmptyOperator());
     225      moveMakingProcessor.Operators.Add(selectedMoveMakingProcessor);
     226      moveMakingProcessor.Successor = mergingReducer;
     227      selectedMoveMakingProcessor.Operator = qualityComparator;
    235228      qualityComparator.Successor = improvesQualityBranch;
    236229      improvesQualityBranch.TrueBranch = moveMaker;
     
    239232      moveMaker.Successor = bestQualityUpdater;
    240233      bestQualityUpdater.Successor = null;
     234      mergingReducer.Successor = analyzer2;
     235      analyzer2.Successor = subScopesRemover;
     236      subScopesRemover.Successor = null;
    241237      iterationsCounter.Successor = iterationsComparator;
    242       iterationsComparator.Successor = subScopesProcessor1;
    243       subScopesProcessor1.Operators.Add(analyzer2);
    244       subScopesProcessor1.Successor = resultsCollector3;
    245       analyzer2.Successor = null;
     238      iterationsComparator.Successor = resultsCollector3;
    246239      resultsCollector3.Successor = iterationsTermination;
    247240      iterationsTermination.TrueBranch = null;
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuNeighborhoodAnalyzer.cs

    r3659 r3809  
    4848    public override IOperation Apply() {
    4949      ItemArray<BoolValue> tabu = IsTabuParameter.ActualValue;
    50       PercentValue value = PercentTabuParameter.ActualValue;
    51       if (value == null) {
    52         value = new PercentValue();
    53         PercentTabuParameter.ActualValue = value;
    54       }
    55       value.Value = tabu.Where(x => x.Value).Count() / (double)tabu.Length;
    56       ResultCollection results = ResultsParameter.ActualValue;
    57       if (results != null) {
    58         IResult result = null;
    59         results.TryGetValue(PercentTabuParameter.ActualName, out result);
    60         if (result != null)
    61           result.Value = value;
    62         else
    63           results.Add(new Result(PercentTabuParameter.ActualName, "Indicates how much of the neighborhood is tabu.", (IItem)value.Clone()));
     50      if (tabu.Length > 0) {
     51        PercentValue value = PercentTabuParameter.ActualValue;
     52        if (value == null) {
     53          value = new PercentValue();
     54          PercentTabuParameter.ActualValue = value;
     55        }
     56        value.Value = tabu.Where(x => x.Value).Count() / (double)tabu.Length;
     57        ResultCollection results = ResultsParameter.ActualValue;
     58        if (results != null) {
     59          IResult result = null;
     60          results.TryGetValue(PercentTabuParameter.ActualName, out result);
     61          if (result != null)
     62            result.Value = value;
     63          else
     64            results.Add(new Result(PercentTabuParameter.ActualName, "Indicates how much of the neighborhood is tabu.", (IItem)value.Clone()));
     65        }
    6466      }
    6567      return base.Apply();
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs

    r3750 r3809  
    8181      get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
    8282    }
    83     private ValueParameter<MultiAnalyzer> MoveAnalyzerParameter {
    84       get { return (ValueParameter<MultiAnalyzer>)Parameters["MoveAnalyzer"]; }
    85     }
    8683    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
    8784      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     
    125122      get { return MaximumIterationsParameter.Value; }
    126123      set { MaximumIterationsParameter.Value = value; }
    127     }
    128     public MultiAnalyzer MoveAnalyzer {
    129       get { return MoveAnalyzerParameter.Value; }
    130       set { MoveAnalyzerParameter.Value = value; }
    131124    }
    132125    public MultiAnalyzer Analyzer {
     
    161154      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    162155      Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The neighborhood size for stochastic sampling move generators", new IntValue(100)));
    163       Parameters.Add(new ValueParameter<MultiAnalyzer>("MoveAnalyzer", "The operator used to analyze the moves.", new MultiAnalyzer()));
    164156      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer()));
    165157     
     
    187179      tsMainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    188180      tsMainLoop.ResultsParameter.ActualName = "Results";
    189       tsMainLoop.MoveAnalyzerParameter.ActualName = MoveAnalyzerParameter.Name;
    190181      tsMainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    191182
     
    392383    private void UpdateAnalyzers() {
    393384      Analyzer.Operators.Clear();
    394       MoveAnalyzer.Operators.Clear();
    395       MoveAnalyzer.Operators.Add(moveQualityAnalyzer);
    396       MoveAnalyzer.Operators.Add(tabuNeighborhoodAnalyzer);
    397385      if (Problem != null) {
    398386        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
     
    402390        }
    403391      }
     392      Analyzer.Operators.Add(moveQualityAnalyzer);
     393      Analyzer.Operators.Add(tabuNeighborhoodAnalyzer);
    404394    }
    405395    private void ClearMoveParameters() {
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearchMainLoop.cs

    r3750 r3809  
    7777      get { return (ValueLookupParameter<IOperator>)Parameters["TabuMaker"]; }
    7878    }
    79     public ValueLookupParameter<IOperator> MoveAnalyzerParameter {
    80       get { return (ValueLookupParameter<IOperator>)Parameters["MoveAnalyzer"]; }
    81     }
    8279    public ValueLookupParameter<IOperator> AnalyzerParameter {
    8380      get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
     
    112109      Parameters.Add(new ValueLookupParameter<IOperator>("TabuMaker", "The operator that declares a move tabu."));
    113110
    114       Parameters.Add(new ValueLookupParameter<IOperator>("MoveAnalyzer", "The operator used to analyze the moves."));
    115       Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution."));
     111      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution and moves."));
    116112      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    117113      #endregion
     
    130126      IntCounter evaluatedMovesCounter = new IntCounter();
    131127      Placeholder tabuChecker = new Placeholder();
    132       Placeholder moveAnalyzer = new Placeholder();
    133128      SubScopesSorter moveQualitySorter = new SubScopesSorter();
    134129      TabuSelector tabuSelector = new TabuSelector();
    135130      ConditionalBranch emptyNeighborhoodBranch1 = new ConditionalBranch();
    136       RightReducer rightReducer = new RightReducer();
    137131      SubScopesProcessor moveMakingProcessor = new SubScopesProcessor();
     132      UniformSubScopesProcessor selectedMoveMakingProcesor = new UniformSubScopesProcessor();
    138133      Placeholder tabuMaker = new Placeholder();
    139134      Placeholder moveMaker = new Placeholder();
     135      MergingReducer mergingReducer = new MergingReducer();
     136      Placeholder analyzer2 = new Placeholder();
    140137      SubScopesRemover subScopesRemover = new SubScopesRemover();
    141138      ConditionalBranch emptyNeighborhoodBranch2 = new ConditionalBranch();
     
    143140      IntCounter iterationsCounter = new IntCounter();
    144141      Comparator iterationsComparator = new Comparator();
    145       SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
    146       Placeholder analyzer2 = new Placeholder();
    147142      ResultsCollector resultsCollector3 = new ResultsCollector();
    148143      ConditionalBranch iterationsTermination = new ConditionalBranch();
     
    182177      tabuChecker.Name = "TabuChecker (placeholder)";
    183178      tabuChecker.OperatorParameter.ActualName = TabuCheckerParameter.Name;
    184 
    185       moveAnalyzer.Name = "MoveAnalyzer (placeholder)";
    186       moveAnalyzer.OperatorParameter.ActualName = MoveAnalyzerParameter.Name;
    187179
    188180      moveQualitySorter.DescendingParameter.ActualName = MaximizationParameter.Name;
     
    208200      moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name;
    209201
     202      analyzer2.Name = "Analyzer (placeholder)";
     203      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
     204
    210205      subScopesRemover.RemoveAllSubScopes = true;
    211206
     
    225220      iterationsComparator.ResultParameter.ActualName = "Terminate";
    226221
    227       analyzer2.Name = "Analyzer (placeholder)";
    228       analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
    229 
    230222      resultsCollector3.CopyValue = new BoolValue(true);
    231223      resultsCollector3.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Moves", null, "EvaluatedMoves"));
     
    244236      subScopesProcessor0.Operators.Add(bestQualityInitializer);
    245237      subScopesProcessor0.Successor = resultsCollector1;
     238      bestQualityInitializer.Successor = analyzer1;
     239      analyzer1.Successor = null;
    246240      resultsCollector1.Successor = resultsCollector2;
    247241      resultsCollector2.Successor = solutionProcessor;
     
    250244      moveGenerator.Successor = moveEvaluationProcessor;
    251245      moveEvaluationProcessor.Operator = moveEvaluator;
    252       moveEvaluationProcessor.Successor = moveAnalyzer;
     246      moveEvaluationProcessor.Successor = moveQualitySorter;
    253247      moveEvaluator.Successor = evaluatedMovesCounter;
    254248      evaluatedMovesCounter.Successor = tabuChecker;
    255249      tabuChecker.Successor = null;
    256       moveAnalyzer.Successor = moveQualitySorter;
    257250      moveQualitySorter.Successor = tabuSelector;
    258251      tabuSelector.Successor = emptyNeighborhoodBranch1;
    259       emptyNeighborhoodBranch1.FalseBranch = rightReducer;
     252      emptyNeighborhoodBranch1.FalseBranch = moveMakingProcessor;
    260253      emptyNeighborhoodBranch1.TrueBranch = null;
    261254      emptyNeighborhoodBranch1.Successor = subScopesRemover;
    262       rightReducer.Successor = moveMakingProcessor;
    263       moveMakingProcessor.Operators.Add(tabuMaker);
    264       moveMakingProcessor.Successor = null;
     255      moveMakingProcessor.Operators.Add(new EmptyOperator());
     256      moveMakingProcessor.Operators.Add(selectedMoveMakingProcesor);
     257      moveMakingProcessor.Successor = mergingReducer;
     258      selectedMoveMakingProcesor.Operator = tabuMaker;
     259      selectedMoveMakingProcesor.Successor = null;
    265260      tabuMaker.Successor = moveMaker;
    266261      moveMaker.Successor = null;
     262      mergingReducer.Successor = analyzer2;
     263      analyzer2.Successor = null;
    267264      subScopesRemover.Successor = null;
    268265      iterationsCounter.Successor = iterationsComparator;
    269       iterationsComparator.Successor = subScopesProcessor1;
    270       subScopesProcessor1.Operators.Add(analyzer2);
    271       subScopesProcessor1.Successor = resultsCollector3;
     266      iterationsComparator.Successor = resultsCollector3;
    272267      resultsCollector3.Successor = emptyNeighborhoodBranch2;
    273268      emptyNeighborhoodBranch2.TrueBranch = null;
Note: See TracChangeset for help on using the changeset viewer.