Changeset 11739 for branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveGenerator.cs
- Timestamp:
- 01/08/15 15:52:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Operators/SingleObjectiveMoveGenerator.cs
r11619 r11739 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Globalization; 24 25 using System.Linq; … … 34 35 [Item("Single-objective MoveGenerator", "Calls the GetNeighbors method of the problem definition to obtain the moves.")] 35 36 [StorableClass] 36 public class SingleObjectiveMoveGenerator : InstrumentedOperator, ISingleObjectiveMoveOperator, IMultiMoveGenerator, IStochasticOperator { 37 37 public class SingleObjectiveMoveGenerator : SingleSuccessorOperator, INeighborBasedOperator, IMultiMoveGenerator, IStochasticOperator { 38 38 public ILookupParameter<IRandom> RandomParameter { 39 39 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 44 44 } 45 45 46 public ILookupParameter<ISingleObjectiveProblemDefinition> ProblemDefinitionParameter {47 get { return (ILookupParameter<ISingleObjectiveProblemDefinition>)Parameters["ProblemDefinition"]; }48 }49 50 46 public ILookupParameter<IEncoding> EncodingParameter { 51 47 get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; } 52 48 } 49 50 public Func<Individual, IRandom, IEnumerable<Individual>> GetNeighborsFunc { get; set; } 53 51 54 52 [StorableConstructor] … … 59 57 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 60 58 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."));62 59 Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding.")); 63 60 } … … 67 64 } 68 65 69 public override IOperation InstrumentedApply() {66 public override IOperation Apply() { 70 67 var random = RandomParameter.ActualValue; 71 var definition = ProblemDefinitionParameter.ActualValue;72 if (definition == null) throw new InvalidOperationException("Problem definition is null.");73 68 var sampleSize = SampleSizeParameter.ActualValue.Value; 74 69 var encoding = EncodingParameter.ActualValue; 75 70 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(); 77 72 78 73 var moveScopes = new Scope[nbhood.Count]; … … 83 78 ExecutionContext.Scope.SubScopes.AddRange(moveScopes); 84 79 85 return base. InstrumentedApply();80 return base.Apply(); 86 81 } 87 82 }
Note: See TracChangeset
for help on using the changeset viewer.