Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3134


Ignore:
Timestamp:
03/19/10 19:35:45 (15 years ago)
Author:
abeham
Message:

Updated local search to show visualization and statistics #921

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

Legend:

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

    r3131 r3134  
    155155      }
    156156      ParameterizeSolutionsCreator();
    157       ParameterizeLSMainLoop();
     157      ParameterizeMainLoop();
    158158      ParameterizeMoveEvaluator();
    159159      ParameterizeMoveMaker();
     
    170170      ParameterizeStochasticOperator(Problem.Evaluator);
    171171      ParameterizeSolutionsCreator();
    172       ParameterizeLSMainLoop();
     172      ParameterizeMainLoop();
    173173      ParameterizeMoveEvaluator();
    174174      ParameterizeMoveMaker();
    175175      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    176176      base.Problem_EvaluatorChanged(sender, e);
     177    }
     178    protected override void Problem_VisualizerChanged(object sender, EventArgs e) {
     179      ParameterizeStochasticOperator(Problem.Visualizer);
     180      ParameterizeMainLoop();
     181      base.Problem_VisualizerChanged(sender, e);
    177182    }
    178183    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     
    188193      if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire
    189194        UpdateMoveParameters();
    190       ParameterizeLSMainLoop();
     195      ParameterizeMainLoop();
    191196      ParameterizeMoveEvaluator();
    192197      ParameterizeMoveMaker();
     
    194199    }
    195200    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    196       ParameterizeLSMainLoop();
     201      ParameterizeMainLoop();
    197202      ParameterizeMoveEvaluator();
    198203      ParameterizeMoveMaker();
     
    202207    }
    203208    private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    204       ParameterizeLSMainLoop();
     209      ParameterizeMainLoop();
    205210      ParameterizeMoveEvaluator();
    206211      ParameterizeMoveMaker();
    207212    }
    208213    private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
    209       ParameterizeLSMainLoop();
     214      ParameterizeMainLoop();
    210215      ParameterizeMoveEvaluator();
    211216      ParameterizeMoveMaker();
     
    273278      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    274279    }
    275     private void ParameterizeLSMainLoop() {
     280    private void ParameterizeMainLoop() {
    276281      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    277282      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    278283      if (MoveEvaluator != null)
    279284        MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
     285      MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     286      MainLoop.VisualizerParameter.ActualName = Problem.VisualizerParameter.Name;
     287      MainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName;
    280288    }
    281289    private void ParameterizeStochasticOperator(IOperator op) {
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs

    r3103 r3134  
    4646      get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
    4747    }
     48    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
     49      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     50    }
    4851    public LookupParameter<DoubleValue> MoveQualityParameter {
    4952      get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
     
    6366    public ValueLookupParameter<IOperator> MoveMakerParameter {
    6467      get { return (ValueLookupParameter<IOperator>)Parameters["MoveMaker"]; }
     68    }
     69    public ValueLookupParameter<IOperator> VisualizerParameter {
     70      get { return (ValueLookupParameter<IOperator>)Parameters["Visualizer"]; }
     71    }
     72    public LookupParameter<IItem> VisualizationParameter {
     73      get { return (LookupParameter<IItem>)Parameters["Visualization"]; }
    6574    }
    6675
     
    7988      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    8089      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     90      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
    8191      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
    8292      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
     
    8696      Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
    8797      Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move."));
    88      
     98
     99      Parameters.Add(new ValueLookupParameter<IOperator>("Visualizer", "The operator used to visualize solutions."));
     100      Parameters.Add(new LookupParameter<IItem>("Visualization", "The item which represents the visualization of solutions."));
    89101      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the TS should be applied."));
    90102      #endregion
     
    92104      #region Create operators
    93105      VariableCreator variableCreator = new VariableCreator();
     106      BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer();
     107      BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer();
     108      DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector();
     109      QualityDifferenceCalculator qualityDifferenceCalculator1 = new QualityDifferenceCalculator();
     110      Placeholder visualizer1 = new Placeholder();
    94111      ResultsCollector resultsCollector = new ResultsCollector();
    95112      UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor();
     
    104121      Placeholder moveMaker = new Placeholder();
    105122      SubScopesRemover subScopesRemover = new SubScopesRemover();
    106       DataTableValuesCollector valuesCollector = new DataTableValuesCollector();
    107123      IntCounter iterationsCounter = new IntCounter();
    108124      Comparator iterationsComparator = new Comparator();
     125      BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer();
     126      BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer();
     127      DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector();
     128      QualityDifferenceCalculator qualityDifferenceCalculator2 = new QualityDifferenceCalculator();
     129      Placeholder visualizer2 = new Placeholder();
    109130      ConditionalBranch iterationsTermination = new ConditionalBranch();
    110       EmptyOperator finished = new EmptyOperator();
    111131
    112132      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
    113       variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities")));
     133
     134      bestQualityMemorizer1.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
     135      bestQualityMemorizer1.MaximizationParameter.ActualName = MaximizationParameter.Name;
     136      bestQualityMemorizer1.QualityParameter.ActualName = QualityParameter.Name;
     137
     138      bestQualityMemorizer2.BestQualityParameter.ActualName = "BestQuality";
     139      bestQualityMemorizer2.MaximizationParameter.ActualName = MaximizationParameter.Name;
     140      bestQualityMemorizer2.QualityParameter.ActualName = QualityParameter.Name;
     141
     142      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));
     143      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
     144      dataTableValuesCollector1.DataTableParameter.ActualName = "Qualities";
     145
     146      qualityDifferenceCalculator1.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
     147      qualityDifferenceCalculator1.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
     148      qualityDifferenceCalculator1.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
     149      qualityDifferenceCalculator1.SecondQualityParameter.ActualName = "BestQuality";
     150
     151      visualizer1.Name = "Visualizer (placeholder)";
     152      visualizer1.OperatorParameter.ActualName = VisualizerParameter.Name;
     153
     154      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
     155      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
     156      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
     157      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Absolute Difference of Best Known Quality to Best Quality", null, "AbsoluteDifferenceBestKnownToBest"));
     158      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Relative Difference of Best Known Quality to Best Quality", null, "RelativeDifferenceBestKnownToBest"));
     159      resultsCollector.CollectedValues.Add(new LookupParameter<IItem>("Solution Visualization", null, VisualizationParameter.Name));
     160      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
     161      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
    114162
    115163      mainProcessor.Name = "Solution processor (UniformSequentialSubScopesProcessor)";
    116 
    117       resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
    118       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality"));
    119       resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
    120       resultsCollector.ResultsParameter.ActualName = "Results";
    121164
    122165      moveGenerator.Name = "MoveGenerator (placeholder)";
     
    143186
    144187      subScopesRemover.RemoveAllSubScopes = true;
    145 
    146       valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality"));
    147       valuesCollector.DataTableParameter.ActualName = "Qualities";
    148188
    149189      iterationsCounter.Name = "Iterations Counter";
     
    157197      iterationsComparator.ResultParameter.ActualName = "IterationsCondition";
    158198
     199      bestQualityMemorizer3.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
     200      bestQualityMemorizer3.MaximizationParameter.ActualName = MaximizationParameter.Name;
     201      bestQualityMemorizer3.QualityParameter.ActualName = QualityParameter.Name;
     202
     203      bestQualityMemorizer4.BestQualityParameter.ActualName = "BestQuality";
     204      bestQualityMemorizer4.MaximizationParameter.ActualName = MaximizationParameter.Name;
     205      bestQualityMemorizer4.QualityParameter.ActualName = QualityParameter.Name;
     206
     207      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));
     208      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, BestKnownQualityParameter.Name));
     209      dataTableValuesCollector2.DataTableParameter.ActualName = "Qualities";
     210
     211      qualityDifferenceCalculator2.AbsoluteDifferenceParameter.ActualName = "AbsoluteDifferenceBestKnownToBest";
     212      qualityDifferenceCalculator2.FirstQualityParameter.ActualName = BestKnownQualityParameter.Name;
     213      qualityDifferenceCalculator2.RelativeDifferenceParameter.ActualName = "RelativeDifferenceBestKnownToBest";
     214      qualityDifferenceCalculator2.SecondQualityParameter.ActualName = "BestQuality";
     215
     216      visualizer2.Name = "Visualizer (placeholder)";
     217      visualizer2.OperatorParameter.ActualName = VisualizerParameter.Name;
     218
    159219      iterationsTermination.Name = "Iterations Termination Condition";
    160220      iterationsTermination.ConditionParameter.ActualName = "IterationsCondition";
     
    163223      #region Create operator graph
    164224      OperatorGraph.InitialOperator = variableCreator;
    165       variableCreator.Successor = mainProcessor;
    166       mainProcessor.Operator = resultsCollector;
     225      variableCreator.Successor = bestQualityMemorizer1;
     226      bestQualityMemorizer1.Successor = bestQualityMemorizer2;
     227      bestQualityMemorizer2.Successor = dataTableValuesCollector1;
     228      dataTableValuesCollector1.Successor = qualityDifferenceCalculator1;
     229      qualityDifferenceCalculator1.Successor = visualizer1;
     230      visualizer1.Successor = resultsCollector;
     231      resultsCollector.Successor = mainProcessor;
     232      mainProcessor.Operator = moveGenerator;
    167233      mainProcessor.Successor = iterationsCounter;
    168       resultsCollector.Successor = moveGenerator;
    169234      moveGenerator.Successor = moveEvaluationProcessor;
    170235      moveEvaluationProcessor.Operator = moveEvaluator;
     
    174239      moveMakingProcessor.Operator = qualityComparator;
    175240      moveMakingProcessor.Successor = subScopesRemover;
    176       subScopesRemover.Successor = valuesCollector;
     241      subScopesRemover.Successor = null;
    177242      qualityComparator.Successor = improvesQualityBranch;
    178243      improvesQualityBranch.TrueBranch = moveMaker;
     244      improvesQualityBranch.FalseBranch = null;
     245      improvesQualityBranch.Successor = null;
     246      moveMaker.Successor = null;
    179247      iterationsCounter.Successor = iterationsComparator;
    180       iterationsComparator.Successor = iterationsTermination;
     248      iterationsComparator.Successor = bestQualityMemorizer3;
     249      bestQualityMemorizer3.Successor = bestQualityMemorizer4;
     250      bestQualityMemorizer4.Successor = dataTableValuesCollector2;
     251      dataTableValuesCollector2.Successor = qualityDifferenceCalculator2;
     252      qualityDifferenceCalculator2.Successor = visualizer2;
     253      visualizer2.Successor = iterationsTermination;
    181254      iterationsTermination.TrueBranch = mainProcessor;
    182       iterationsTermination.FalseBranch = finished;
     255      iterationsTermination.FalseBranch = null;
    183256      #endregion
    184257    }
Note: See TracChangeset for help on using the changeset viewer.