Free cookie consent management tool by TermsFeed Policy Generator

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

Worked on VNS main loop (#1425)

File:
1 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  }
Note: See TracChangeset for help on using the changeset viewer.