Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5609 for branches/VNS


Ignore:
Timestamp:
03/04/11 17:23:40 (14 years ago)
Author:
svonolfe
Message:

Worked on VNS main loop (#1425)

Location:
branches/VNS
Files:
4 edited

Legend:

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

    r5603 r5609  
    8787      : base() {
    8888        loop = new LocalSearchMainLoop();
    89         loop.ResultsParameter.Value = new VariableCollection();
    9089
    9190        Parameters.Add(new /*Constrained*/ValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
     
    143142    public override IOperation Apply() {
    144143      Scope subScope = new Scope();
    145       subScope.Parent = ExecutionContext.Scope;
     144      Scope individual = new Scope();
    146145
    147       IAtomicOperation op = ExecutionContext.CreateChildOperation(loop, subScope);
    148       op.Operator.Execute((IExecutionContext)op, CancellationToken);
     146      foreach (Variable var in ExecutionContext.Scope.Variables) {
     147        individual.Variables.Add(var);
     148      }
     149      subScope.SubScopes.Add(individual);
    149150
    150       ExecutionContext.Scope.SubScopes.Remove(subScope);
     151      ExecutionContext.Scope.SubScopes.Add(subScope);
     152      int index = subScope.Parent.SubScopes.IndexOf(subScope);
    151153
    152       return base.Apply();
     154      SubScopesProcessor processor = new SubScopesProcessor();
     155      SubScopesRemover remover = new SubScopesRemover();
     156
     157      remover.RemoveAllSubScopes = false;
     158      remover.SubScopeIndexParameter.Value = new IntValue(index);
     159
     160      for (int i = 0; i < index; i++) {
     161        processor.Operators.Add(new EmptyOperator());
     162      }
     163
     164      loop.MoveGeneratorParameter.Value = MoveGeneratorParameter.Value;
     165      loop.MoveEvaluatorParameter.Value = MoveEvaluatorParameter.Value;
     166      loop.MoveMakerParameter.Value = MoveMakerParameter.Value;
     167      loop.MaximumIterationsParameter.Value = MaximumIterationsParameter.Value;
     168
     169      processor.Operators.Add(loop);
     170      processor.Successor = remover;
     171
     172      IOperation next = base.Apply();
     173      if (next as ExecutionContext != null) {
     174        remover.Successor = (next as ExecutionContext).Operator;
     175      }
     176
     177      return ExecutionContext.CreateOperation(processor);
    153178    }
    154179  }
  • branches/VNS/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/ShakingOperator.cs

    r5603 r5609  
    6565      IOperator successor = null;
    6666
    67       if (index >= operators.Count || index < 0) {
     67      if (index >= operators.Count - 1) {
    6868        ContinueParameter.ActualValue = new BoolValue(false);
    6969      } else {
    7070        ContinueParameter.ActualValue = new BoolValue(true);
     71      }
     72
     73      if (index >= 0 && index < operators.Count) {
    7174        successor = operators[index].Value;
    7275      }
  • branches/VNS/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearchMainLoop.cs

    r5603 r5609  
    126126      QualityComparator qualityComparator = new QualityComparator();
    127127      ConditionalBranch improvesQualityBranch = new ConditionalBranch();
     128      ConditionalBranch improvesQualityBranch2 = new ConditionalBranch();
    128129
    129130      Assigner bestQualityUpdater = new Assigner();
     
    134135      Assigner indexResetter = new Assigner();
    135136
    136       SubScopesRemover remover = new SubScopesRemover();
     137      SubScopesRemover remover1 = new SubScopesRemover();
     138      SubScopesRemover remover2 = new SubScopesRemover();
    137139      Placeholder analyzer2 = new Placeholder();
    138140
     
    145147      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
    146148      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Index", new DoubleValue(0)));
     149      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("Continue", new BoolValue(false)));
    147150      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0)));
    148151
     
    183186      evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
    184187
    185       qualityComparator.LeftSideParameter.ActualName = "OriginalQuality";
    186       qualityComparator.RightSideParameter.ActualName = QualityParameter.Name;
     188      qualityComparator.LeftSideParameter.ActualName = QualityParameter.Name;
     189      qualityComparator.RightSideParameter.ActualName = "OriginalQuality";
    187190      qualityComparator.ResultParameter.ActualName = "IsBetter";
    188191
    189192      improvesQualityBranch.ConditionParameter.ActualName = "IsBetter";
     193      improvesQualityBranch2.ConditionParameter.ActualName = "IsBetter";
    190194
    191195      bestQualityUpdater.Name = "Update BestQuality";
     
    194198
    195199      cleaner.Name = "Clean scope";
     200      cleaner.ClearSubScopesParameter.Value = new BoolValue(false);
    196201      originalRestorer.Name = "Restore original solution";
    197202
     
    204209      indexResetter.RightSideParameter.Value = new IntValue(0);
    205210
    206       remover.Name = "Remove subscope";
     211      remover1.Name = remover2.Name = "Remove subscope";
    207212
    208213      analyzer2.Name = "Analyzer (placeholder)";
     
    253258      improvesQualityBranch.TrueBranch = bestQualityUpdater;
    254259      improvesQualityBranch.FalseBranch = cleaner;
    255       improvesQualityBranch.Successor = remover;
    256260
    257261      bestQualityUpdater.Successor = indexResetter;
     262      indexResetter.Successor = remover1;
    258263
    259264      cleaner.Successor = originalRestorer;
    260       originalRestorer.Successor = indexCounter;
     265      originalRestorer.Successor = remover2;
     266      remover2.Successor = indexCounter;
    261267      /////////
    262       indexTermination.TrueBranch = null;
    263       indexTermination.FalseBranch = iterationInit;
     268      indexTermination.TrueBranch = improvesQualityBranch2;
     269      indexTermination.FalseBranch = null;
     270
     271      improvesQualityBranch2.TrueBranch = null;
     272      improvesQualityBranch2.FalseBranch = createChild;
    264273
    265274      iterationsCounter.Successor = iterationsComparator;
  • branches/VNS/HeuristicLab.Operators/3.3/ScopeCleaner.cs

    r5445 r5609  
    2424using HeuristicLab.Parameters;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Data;
    2627
    2728namespace HeuristicLab.Operators {
     
    3839      get { return CurrentScopeParameter.ActualValue; }
    3940    }
     41    public ValueParameter<BoolValue> ClearSubScopesParameter {
     42      get { return (ValueParameter<BoolValue>)Parameters["ClearSubScopes"]; }
     43    }
     44
     45    [StorableHook(HookType.AfterDeserialization)]
     46    private void AfterDeserializationHook() {
     47      #region Backwards Compatibility
     48      if (!Parameters.ContainsKey("ClearSubScopes")) {
     49        Parameters.Add(new ValueParameter<BoolValue>("ClearSubScopes", "Indicates, if the subscopes should be cleared.", new BoolValue(false)));
     50      }
     51      #endregion
     52    }
    4053
    4154    [StorableConstructor]
     
    4760      : base() {
    4861      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose variables and sub-scopes should be removed."));
     62      Parameters.Add(new ValueParameter<BoolValue>("ClearSubScopes", "Indicates, if the subscopes should be cleared.", new BoolValue(false)));
    4963    }
    5064
     
    5569    public override IOperation Apply() {
    5670      CurrentScope.Variables.Clear();
    57       CurrentScope.SubScopes.Clear();
     71      if(ClearSubScopesParameter.Value.Value)
     72        CurrentScope.SubScopes.Clear();
    5873      return base.Apply();
    5974    }
Note: See TracChangeset for help on using the changeset viewer.