Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/12/12 16:42:17 (13 years ago)
Author:
jkarder
Message:

#1331:

  • added analyzer
  • added parameters and adjusted parameter types
  • corrected ReferenceSetUpdateMethod
  • changed access levels
Location:
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs

    r7722 r7724  
    3939      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    4040    }
    41     public ValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
     41    private ValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
    4242      get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    4343    }
    44     public ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
     44    private ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
    4545      get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
    4646    }
     
    4848
    4949    #region Properties
    50     public IScope CurrentScope {
     50    private IScope CurrentScope {
    5151      get { return CurrentScopeParameter.ActualValue; }
    5252    }
    53     public IntValue NumberOfHighQualitySolutions {
     53    private IntValue NumberOfHighQualitySolutions {
    5454      get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
    5555      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
    5656    }
    57     public IntValue ReferenceSetSize {
     57    private IntValue ReferenceSetSize {
    5858      get { return ReferenceSetSizeParameter.ActualValue; }
    5959      set { ReferenceSetSizeParameter.ActualValue = value; }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r7722 r7724  
    9393          foreach (var r in CurrentScope.SubScopes[1].SubScopes) {
    9494            BinaryVector rSol = r.Variables["KnapsackSolution"].Value as BinaryVector;
    95             if (pSol != null && rSol != null) {
    96               diversity += CalculateDiversity(pSol, rSol);
    97             }
    98             if (mostDiverseSolution == null || diversity > maxDiversity)
    99               mostDiverseSolution = p;
     95            if (pSol != null && rSol != null) diversity += CalculateDiversity(pSol, rSol);
     96          }
     97          if (mostDiverseSolution == null || diversity > maxDiversity) {
     98            mostDiverseSolution = p;
     99            maxDiversity = diversity;
    100100          }
    101101        }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r7722 r7724  
    3737
    3838namespace HeuristicLab.Algorithms.ScatterSearch {
     39  /// <summary>
     40  /// A scatter search algorithm.
     41  /// </summary>
    3942  [Item("Scatter Search", "A scatter search algorithm.")]
    4043  [Creatable("Algorithms")]
     
    263266      base.OnProblemChanged();
    264267    }
    265 
    266268    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
    267269      ParameterizeStochasticOperator(Problem.SolutionCreator);
     
    269271      base.Problem_SolutionCreatorChanged(sender, e);
    270272    }
    271 
    272273    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
    273274      ParameterizeStochasticOperator(Problem.Evaluator);
     
    280281      base.Problem_EvaluatorChanged(sender, e);
    281282    }
    282 
    283283    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    284284      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     
    393393        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
    394394          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
    395             param.Depth = 0;
     395            param.Depth = 1;
    396396          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
    397397        }
     
    409409    private void ParameterizeMainLoop() {
    410410      if (Problem != null) {
    411         //MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    412         //MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    413         //MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    414       }
    415       if (MoveEvaluator != null) ;
    416       //MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
     411        MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     412        MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     413        MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     414      }
     415      if (MoveEvaluator != null)
     416        MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
    417417    }
    418418    private void ParameterizeStochasticOperator(IOperator op) {
     
    476476      }
    477477    }
    478 
    479478    private ScatterSearchMainLoop FindMainLoop(IOperator start) {
    480479      IOperator mainLoop = start;
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs

    r7722 r7724  
    4747      get { return (LookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    4848    }
     49    internal LookupParameter<BoolValue> MaximizationParameter {
     50      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     51    }
    4952    internal LookupParameter<IntValue> SampleSizeParameter {
    5053      get { return (LookupParameter<IntValue>)Parameters["SampleSize"]; }
     
    5962      get { return (LookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
    6063    }
     64    internal LookupParameter<DoubleValue> QualityParameter {
     65      get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
     66    }
     67    internal LookupParameter<DoubleValue> BestKnownQualityParameter {
     68      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     69    }
     70    internal LookupParameter<DoubleValue> MoveQualityParameter {
     71      get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
     72    }
    6173    internal LookupParameter<VariableCollection> ResultsParameter {
    6274      get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
     75    }
     76    internal LookupParameter<IOperator> MoveEvaluatorParameter {
     77      get { return (LookupParameter<IOperator>)Parameters["MoveEvaluator"]; }
     78    }
     79    internal LookupParameter<IOperator> MoveGeneratorParameter {
     80      get { return (LookupParameter<IOperator>)Parameters["MoveGenerator"]; }
     81    }
     82    internal LookupParameter<IOperator> MoveMakerParameter {
     83      get { return (LookupParameter<IOperator>)Parameters["MoveMaker"]; }
    6384    }
    6485    internal LookupParameter<IMultiAnalyzer> AnalyzerParameter {
     
    80101      set { MaximumIterationsParameter.ActualValue = value; }
    81102    }
     103    public BoolValue Maximization {
     104      get { return MaximizationParameter.ActualValue; }
     105      set { MaximizationParameter.ActualValue = value; }
     106    }
    82107    public IntValue SampleSize {
    83108      get { return SampleSizeParameter.ActualValue; }
     
    96121      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
    97122    }
     123    public DoubleValue Quality {
     124      get { return QualityParameter.ActualValue; }
     125      set { QualityParameter.ActualValue = value; }
     126    }
     127    public DoubleValue BestKnownQuality {
     128      get { return BestKnownQualityParameter.ActualValue; }
     129      set { BestKnownQualityParameter.ActualValue = value; }
     130    }
     131    public DoubleValue MoveQuality {
     132      get { return MoveQualityParameter.ActualValue; }
     133      set { MoveQualityParameter.ActualValue = value; }
     134    }
    98135    public VariableCollection Results {
    99136      get { return ResultsParameter.ActualValue; }
    100137      set { ResultsParameter.ActualValue = value; }
     138    }
     139    public IOperator MoveEvaluator {
     140      get { return MoveEvaluatorParameter.ActualValue; }
     141      set { MoveEvaluatorParameter.ActualValue = value; }
     142    }
     143    public IOperator MoveGenerator {
     144      get { return MoveGeneratorParameter.ActualValue; }
     145      set { MoveGeneratorParameter.ActualValue = value; }
     146    }
     147    public IOperator MoveMaker {
     148      get { return MoveMakerParameter.ActualValue; }
     149      set { MoveMakerParameter.ActualValue = value; }
    101150    }
    102151    public IMultiAnalyzer Analyzer {
     
    120169      Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations performed."));
    121170      Parameters.Add(new LookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
     171      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    122172      Parameters.Add(new LookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators."));
    123173      Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population."));
    124174      Parameters.Add(new LookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    125175      Parameters.Add(new LookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
     176      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     177      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far."));
     178      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
    126179      Parameters.Add(new LookupParameter<IOperator>("SolutionCreator", "The operator which is used to create new solutions."));
    127180      Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator which is used to evaluate new solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
     
    143196      IntCounter interationsCounter = new IntCounter();
    144197      LocalSearchImprovementOperator localImprovementOperator = new LocalSearchImprovementOperator();
     198      Placeholder analyzer = new Placeholder();
    145199      Placeholder solutionImprover = new Placeholder();
    146200      Placeholder solutionEvaluator = new Placeholder();
     
    204258      interationsCounter.Successor = resultsCollector;
    205259
     260      analyzer.Name = "Analyzer";
     261      analyzer.OperatorParameter.ActualName = "Analyzer";
     262
    206263      solutionImprover.Name = "SolutionImprover";
    207264      solutionImprover.OperatorParameter.ActualName = "LocalImprovementOperator";
     
    214271      populationRebuildMethod.Successor = subScopesProcessor3;
    215272
     273      resultsCollector.CopyValue = new BoolValue(false);
    216274      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name));
     275      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameter.Name, null, BestKnownQualityParameter.Name));
    217276      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
    218277      resultsCollector.Successor = iterationsChecker;
     
    221280
    222281      solutionCombinationMethod.Successor = subScopesProcessor2;
     282
     283      solutionPoolUpdateMethod.Successor = analyzer;
    223284
    224285      solutionsCreator.Name = "DiversificationGenerationMethod";
     
    257318
    258319    public override IOperation Apply() {
     320      if (MoveGeneratorParameter.ActualValue == null || MoveEvaluatorParameter.ActualValue == null || MoveMakerParameter.ActualValue == null)
     321        return null;
    259322      return base.Apply();
    260323    }
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r7722 r7724  
    4242      get { return (ValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; }
    4343    }
     44    private ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
     45      get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
     46    }
    4447    #endregion
    4548
    4649    #region Properties
    47     public IScope CurrentScope {
     50    private IScope CurrentScope {
    4851      get { return CurrentScopeParameter.ActualValue; }
    4952    }
    50     public BoolValue NewSolutions {
     53    private BoolValue NewSolutions {
    5154      get { return NewSolutionsParameter.ActualValue; }
     55    }
     56    private IntValue ReferenceSetSize {
     57      get { return ReferenceSetSizeParameter.ActualValue; }
     58      set { ReferenceSetSizeParameter.ActualValue = value; }
    5259    }
    5360    #endregion
     
    6471    private void Initialize() {
    6572      #region Create parameters
     73      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));
    6674      Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions", "Indicates if new solutions have been found."));
    67       Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));
     75      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
    6876      #endregion
    6977
     
    8694      if ((offspring.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value
    8795          > (parents.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value) {
    88         CurrentScope.SubScopes.Replace(CurrentScope.SubScopes.Union(offspring.SubScopes).OrderByDescending(o => o.Variables["Quality"].Value).Take(10));
     96        CurrentScope.SubScopes.Replace(CurrentScope.SubScopes.Union(offspring.SubScopes).OrderByDescending(o => o.Variables["Quality"].Value).Take(ReferenceSetSize.Value));
    8997        NewSolutions.Value = true;
    9098      }
Note: See TracChangeset for help on using the changeset viewer.