Changeset 5751


Ignore:
Timestamp:
03/18/11 14:15:49 (11 years ago)
Author:
svonolfe
Message:

Modified LocalSearch main loop (#1425)

Location:
branches/VNS/HeuristicLab.Algorithms.LocalSearch/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/VNS/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs

    r5445 r5751  
    168168      variableCreator.Name = "Initialize EvaluatedMoves";
    169169      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue()));
     170      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
     171      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0)));
    170172      variableCreator.Successor = resultsCollector;
    171173
     
    182184      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
    183185      mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";
     186      mainLoop.IterationsParameter.ActualName = "Iterations";
     187      mainLoop.BestQualityParameter.ActualName = "BestQuality";
    184188
    185189      moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
  • branches/VNS/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchImprovementOperator.cs

    r5735 r5751  
    104104    public LocalSearchImprovementOperator()
    105105      : base() {
    106         loop = new LocalSearchMainLoop("LocalIterations", "BestLocalQuality");
    107 
    108         ResultsCollector rc = ((loop.OperatorGraph.InitialOperator as SingleSuccessorOperator).Successor
    109           as SingleSuccessorOperator).Successor as ResultsCollector;
     106        loop = new LocalSearchMainLoop();
     107       
     108        ResultsCollector rc = (loop.OperatorGraph.InitialOperator as SingleSuccessorOperator).Successor as ResultsCollector;
    110109        rc.CollectedValues.Remove("BestLocalQuality");
    111110
     
    286285      }
    287286
     287      VariableCreator variableCreator = new VariableCreator();
     288      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("LocalIterations", new IntValue(0)));
     289      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestLocalQuality", new DoubleValue(0)));
     290
     291      variableCreator.Successor = loop;
     292
    288293      loop.EvaluatedMovesParameter.ActualName = EvaluatedSolutionsParameter.ActualName;
    289294
    290       processor.Operators.Add(loop);
     295      processor.Operators.Add(variableCreator);
    291296      processor.Successor = remover;
    292297
  • branches/VNS/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs

    r5735 r5751  
    4646      get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
    4747    }
     48    public LookupParameter<DoubleValue> BestQualityParameter {
     49      get { return (LookupParameter<DoubleValue>)Parameters["BestLocalQuality"]; }
     50    }
    4851    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
    4952      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     
    5255      get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    5356    }
     57    public LookupParameter<IntValue> IterationsParameter {
     58      get { return (LookupParameter<IntValue>)Parameters["LocalIterations"]; }
     59    }
    5460    public ValueLookupParameter<IntValue> MaximumIterationsParameter {
    5561      get { return (ValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     
    7783    [StorableConstructor]
    7884    private LocalSearchMainLoop(bool deserializing) : base(deserializing) { }
    79     public LocalSearchMainLoop(string iterationsName, string bestQualityName)
    80       : base() {
    81         Initialize(iterationsName, bestQualityName);
    82     }
    8385    public LocalSearchMainLoop()
    8486      : base() {
    85       Initialize("Iterations", "BestQuality");
     87        Initialize();
    8688    }
    8789    private LocalSearchMainLoop(LocalSearchMainLoop original, Cloner cloner)
     
    9294    }
    9395
    94     private void Initialize(string iterationsName, string bestQualityName) {
     96    private void Initialize() {
    9597      #region Create parameters
    9698      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
    9799      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    98100      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    99       Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "The value which represents the best quality fjo."));
     101      Parameters.Add(new LookupParameter<DoubleValue>("BestLocalQuality", "The value which represents the best quality found so far."));
    100102      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
    101103      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
     104      Parameters.Add(new LookupParameter<IntValue>("LocalIterations", "The number of generations."));
    102105      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
    103106      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     
    112115
    113116      #region Create operators
    114       VariableCreator variableCreator = new VariableCreator();
    115117      SubScopesProcessor subScopesProcessor0 = new SubScopesProcessor();
    116118      Assigner bestQualityInitializer = new Assigner();
     
    137139      ConditionalBranch iterationsTermination = new ConditionalBranch();
    138140
    139       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>(iterationsName, new IntValue(0))); // Class LocalSearch expects this to be called Iterations
    140       variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>(bestQualityName, new DoubleValue(0)));
    141 
    142141      bestQualityInitializer.Name = "Initialize BestQuality";
    143       bestQualityInitializer.LeftSideParameter.ActualName = bestQualityName;
     142      bestQualityInitializer.LeftSideParameter.ActualName = BestQualityParameter.Name;
    144143      bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name;
    145144
     
    148147
    149148      resultsCollector1.CopyValue = new BoolValue(false);
    150       resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>(iterationsName));
    151       resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(bestQualityName, null, bestQualityName));
     149      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name));
     150      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(BestQualityParameter.Name, null, BestQualityParameter.Name));
    152151      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
    153152
     
    178177
    179178      bestQualityUpdater.Name = "Update BestQuality";
    180       bestQualityUpdater.LeftSideParameter.ActualName = bestQualityName;
     179      bestQualityUpdater.LeftSideParameter.ActualName = BestQualityParameter.Name;
    181180      bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name;
    182181
    183182      resultsCollector2.CopyValue = new BoolValue(false);
    184       resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(bestQualityName, null, bestQualityName));
     183      resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(BestQualityParameter.Name, null, BestQualityParameter.Name));
    185184      resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name;
    186185
     
    192191      iterationsCounter.Name = "Iterations Counter";
    193192      iterationsCounter.Increment = new IntValue(1);
    194       iterationsCounter.ValueParameter.ActualName = iterationsName;
     193      iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name;
    195194
    196195      iterationsComparator.Name = "Iterations >= MaximumIterations";
    197196      iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
    198       iterationsComparator.LeftSideParameter.ActualName = iterationsName;
     197      iterationsComparator.LeftSideParameter.ActualName = IterationsParameter.Name;
    199198      iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
    200199      iterationsComparator.ResultParameter.ActualName = "Terminate";
     
    205204
    206205      #region Create operator graph
    207       OperatorGraph.InitialOperator = variableCreator;
    208       variableCreator.Successor = subScopesProcessor0;
     206      OperatorGraph.InitialOperator = subScopesProcessor0;
    209207      subScopesProcessor0.Operators.Add(bestQualityInitializer);
    210208      subScopesProcessor0.Successor = resultsCollector1;
Note: See TracChangeset for help on using the changeset viewer.