Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/25/12 18:32:44 (12 years ago)
Author:
abeham
Message:

#1614: worked on GQAP and GRASP+PR

Location:
branches/GeneralizedQAP
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP

    • Property svn:ignore
      •  

        old new  
        11*.suo
         2TestResults
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASPWithPathRelinking.cs

    r7363 r7412  
    6161      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    6262    }
     63    public IValueParameter<IntValue> MaximumIterationsParameter {
     64      get { return (IValueParameter<IntValue>)Parameters["MaximumIterations"]; }
     65    }
    6366    private IFixedValueParameter<IntValue> EliteSetSizeParameter {
    6467      get { return (IFixedValueParameter<IntValue>)Parameters["EliteSetSize"]; }
     
    7679      get { return (ConstrainedValueParameter<ICrossover>)Parameters["PathRelinking"]; }
    7780    }
    78     public ConstrainedValueParameter<IMerger> EliteSetReplacerParameter {
     81    public ConstrainedValueParameter<IMerger> EliteSetMergerParameter {
    7982      get { return (ConstrainedValueParameter<IMerger>)Parameters["EliteSetMerger"]; }
    8083    }
     
    106109      get { return (RandomCreator)OperatorGraph.InitialOperator; }
    107110    }
    108     #endregion
     111    private GRASPWithPathRelinkingMainLoop MainLoop {
     112      get { return RandomCreator.Successor as GRASPWithPathRelinkingMainLoop; }
     113    }
     114    #endregion
     115
     116    [Storable]
     117    private BestAverageWorstQualityAnalyzer analyzer;
    109118
    110119    [StorableConstructor]
     
    112121    private GRASPWithPathRelinking(GRASPWithPathRelinking original, Cloner cloner)
    113122      : base(original, cloner) {
     123      analyzer = cloner.Clone(original.analyzer);
    114124      RegisterEventHandlers();
    115125    }
     
    119129      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator."));
    120130      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each iteration.", new MultiAnalyzer()));
     131      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of iterations that the algorithm should run.", new IntValue(1000)));
    121132      Parameters.Add(new FixedValueParameter<IntValue>("EliteSetSize", "The elite set stores the best found solutions.", new IntValue(10)));
    122       Parameters.Add(new FixedValueParameter<IntValue>("LocalImprovementMaximumIterations", "The maximum number of iterations performed by the local improvement operator.", new IntValue(100)));
     133      Parameters.Add(new FixedValueParameter<IntValue>("LocalImprovementMaximumIterations", "The maximum number of iterations performed by the local improvement operator.", new IntValue(1000)));
    123134      Parameters.Add(new ConstrainedValueParameter<ILocalImprovementOperator>("LocalImprovement", "Performs a local search on the solution."));
    124       Parameters.Add(new FixedValueParameter<IntValue>("MinimumEliteSetSize", "(ρ) The minimum amount of elites for performing path relinking.", new IntValue(1)));
     135      Parameters.Add(new FixedValueParameter<IntValue>("MinimumEliteSetSize", "(ρ) The minimum amount of elites for performing path relinking.", new IntValue(2)));
    125136      Parameters.Add(new ConstrainedValueParameter<ICrossover>("PathRelinking", "The operator that performs the path relinking."));
    126137      Parameters.Add(new ConstrainedValueParameter<IMerger>("EliteSetMerger", "The operator that merges new solutions into the elite set."));
     138
     139      analyzer = new BestAverageWorstQualityAnalyzer();
     140      Analyzer.Operators.Add(analyzer);
    127141
    128142      RandomCreator randomCreator = new RandomCreator();
     
    136150
    137151      var mainLoop = new GRASPWithPathRelinkingMainLoop();
     152      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     153      mainLoop.EliteSetMergerParameter.ActualName = EliteSetMergerParameter.Name;
     154      mainLoop.EliteSetSizeParameter.ActualName = EliteSetSizeParameter.Name;
     155      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
     156      mainLoop.LocalImprovementParameter.ActualName = LocalImprovementParameter.Name;
     157      mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
     158      mainLoop.PathRelinkingParameter.ActualName = PathRelinkingParameter.Name;
     159      mainLoop.ResultsParameter.ActualName = "Results";
    138160      randomCreator.Successor = mainLoop;
    139161
     
    185207      Analyzer.Operators.Clear();
    186208      if (Problem != null) {
    187         foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
    188           foreach (var param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
     209        foreach (IAnalyzer a in Problem.Operators.OfType<IAnalyzer>()) {
     210          foreach (var param in a.Parameters.OfType<IScopeTreeLookupParameter>())
    189211            param.Depth = 1;
    190           Analyzer.Operators.Add(analyzer);
     212          Analyzer.Operators.Add(a);
    191213        }
    192214        InitializeFromInstallation(LocalImprovementParameter, x => x.ProblemType.IsAssignableFrom(Problem.GetType()));
    193215        InitializeFromProblem(PathRelinkingParameter);
    194         InitializeFromProblem(EliteSetReplacerParameter);
     216        InitializeFromProblem(EliteSetMergerParameter);
    195217      } else {
    196218        LocalImprovementParameter.ValidValues.Clear();
    197219        PathRelinkingParameter.ValidValues.Clear();
    198         EliteSetReplacerParameter.ValidValues.Clear();
    199       }
     220        EliteSetMergerParameter.ValidValues.Clear();
     221      }
     222      Analyzer.Operators.Add(analyzer);
    200223
    201224      Parameterize();
     
    203226
    204227    private void Parameterize() {
     228      if (Problem != null) {
     229        MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     230        MainLoop.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
     231
     232        analyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     233      }
    205234      foreach (var localImprovement in LocalImprovementParameter.ValidValues) {
    206235        localImprovement.MaximumIterationsParameter.ActualName = LocalImprovementMaximumIterationsParameter.Name;
     
    210239          localImprovement.Problem = Problem;
    211240      }
     241      foreach (var merger in EliteSetMergerParameter.ValidValues) {
     242        merger.PopulationSizeParameter.ActualName = EliteSetSizeParameter.Name;
     243      }
    212244    }
    213245
    214246    private void InitializeFromProblem<T>(ConstrainedValueParameter<T> parameter) where T : class, INamedItem {
    215       InitializeFromProblem(parameter, x => true);
     247      InitializeFromProblem<T>(parameter, x => true);
    216248    }
    217249    private void InitializeFromProblem<T>(ConstrainedValueParameter<T> parameter, Func<T, bool> condition) where T : class, INamedItem {
     
    228260    }
    229261    private void InitializeFromInstallation<T>(ConstrainedValueParameter<T> parameter) where T : class, INamedItem {
    230       InitializeFromInstallation(parameter, x => true);
     262      InitializeFromInstallation<T>(parameter, x => true);
    231263    }
    232264    private void InitializeFromInstallation<T>(ConstrainedValueParameter<T> parameter, Func<T, bool> condition) where T : class, INamedItem {
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASPWithPathRelinkingMainLoop.cs

    r7373 r7412  
    8989      variableCreator1.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
    9090
     91      var resultsCollector = new ResultsCollector();
     92      resultsCollector.CopyValue = new BoolValue(false);
     93      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
     94
    9195      var variableCreator2 = new VariableCreator();
    9296      variableCreator2.Name = "ActualEliteSetSize = 0";
     
    157161      placeholder2.OperatorParameter.ActualName = PathRelinkingParameter.Name;
    158162
     163      var placeholder3 = new Placeholder();
     164      placeholder3.Name = "(Evaluator)";
     165      placeholder3.OperatorParameter.ActualName = EvaluatorParameter.Name;
     166
    159167      var subScopesRemover = new SubScopesRemover();
    160168      subScopesRemover.RemoveAllSubScopes = true;
     
    162170      var ssp4 = new SubScopesProcessor();
    163171
    164       var placeholder3 = new Placeholder();
    165       placeholder3.Name = "(LocalImprovement)";
    166       placeholder3.OperatorParameter.ActualName = LocalImprovementParameter.Name;
    167 
    168172      var placeholder4 = new Placeholder();
    169       placeholder4.Name = "(EliteSetMerger)";
    170       placeholder4.OperatorParameter.ActualName = EliteSetMergerParameter.Name;
     173      placeholder4.Name = "(LocalImprovement)";
     174      placeholder4.OperatorParameter.ActualName = LocalImprovementParameter.Name;
     175
     176      var placeholder5 = new Placeholder();
     177      placeholder5.Name = "(EliteSetMerger)";
     178      placeholder5.OperatorParameter.ActualName = EliteSetMergerParameter.Name;
    171179
    172180      var counter = new IntCounter();
     
    191199
    192200      OperatorGraph.InitialOperator = variableCreator1;
    193       variableCreator1.Successor = variableCreator2;
     201      variableCreator1.Successor = resultsCollector;
     202      resultsCollector.Successor = variableCreator2;
    194203      variableCreator2.Successor = subScopesCounter1;
    195204      subScopesCounter1.Successor = comparator1;
     
    200209      ssp1.Operators.Add(eo1);
    201210      ssp1.Operators.Add(solutionsCreator);
    202       ssp1.Successor = placeholder4;
     211      ssp1.Successor = placeholder5;
    203212      eo1.Successor = null;
    204213      solutionsCreator.Successor = subScopesCounter2;
     
    216225      ssp3.Operators.Add(placeholder2);
    217226      ssp3.Successor = null;
    218       placeholder2.Successor = subScopesRemover;
     227      placeholder2.Successor = placeholder3;
     228      placeholder3.Successor = subScopesRemover;
    219229      subScopesRemover.Successor = null;
    220       ssp4.Operators.Add(placeholder3);
     230      ssp4.Operators.Add(placeholder4);
    221231      ssp4.Successor = null;
    222       placeholder4.Successor = counter;
     232      placeholder5.Successor = counter;
    223233      counter.Successor = analyzer1;
    224234      analyzer1.Successor = comparator3;
Note: See TracChangeset for help on using the changeset viewer.