Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/08/15 15:52:05 (9 years ago)
Author:
mkommend
Message:

#2174: Worked on operators and programmable problem base classes and scripts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveGenerator.cs

    r11619 r11739  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Globalization;
    2425using System.Linq;
     
    3435  [Item("Single-objective MoveGenerator", "Calls the GetNeighbors method of the problem definition to obtain the moves.")]
    3536  [StorableClass]
    36   public class SingleObjectiveMoveGenerator : InstrumentedOperator, ISingleObjectiveMoveOperator, IMultiMoveGenerator, IStochasticOperator {
    37 
     37  public class SingleObjectiveMoveGenerator : SingleSuccessorOperator, INeighborBasedOperator, IMultiMoveGenerator, IStochasticOperator {
    3838    public ILookupParameter<IRandom> RandomParameter {
    3939      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     
    4444    }
    4545
    46     public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {
    47       get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }
    48     }
    49 
    5046    public ILookupParameter<IEncoding> EncodingParameter {
    5147      get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; }
    5248    }
     49
     50    public Func<Individual, IRandom, IEnumerable<Individual>> GetNeighborsFunc { get; set; }
    5351
    5452    [StorableConstructor]
     
    5957      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    6058      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to sample."));
    61       Parameters.Add(new LookupParameter<ISingleObjectiveProblemDefinition>("ProblemDefinition", "The host that holds the problem definition."));
    6259      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
    6360    }
     
    6764    }
    6865
    69     public override IOperation InstrumentedApply() {
     66    public override IOperation Apply() {
    7067      var random = RandomParameter.ActualValue;
    71       var definition = ProblemDefinitionParameter.ActualValue;
    72       if (definition == null) throw new InvalidOperationException("Problem definition is null.");
    7368      var sampleSize = SampleSizeParameter.ActualValue.Value;
    7469      var encoding = EncodingParameter.ActualValue;
    7570      var individual = encoding.GetIndividual(ExecutionContext.Scope);
    76       var nbhood = definition.GetNeighbors(random, individual).Take(sampleSize).ToList();
     71      var nbhood = GetNeighborsFunc(individual, random).Take(sampleSize).ToList();
    7772
    7873      var moveScopes = new Scope[nbhood.Count];
     
    8378      ExecutionContext.Scope.SubScopes.AddRange(moveScopes);
    8479
    85       return base.InstrumentedApply();
     80      return base.Apply();
    8681    }
    8782  }
Note: See TracChangeset for help on using the changeset viewer.