Changeset 15698 for branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/RandomSearch
- Timestamp:
- 01/31/18 14:01:55 (7 years ago)
- Location:
- branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/RandomSearch
- Files:
-
- 1 added
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/RandomSearch/RandomSearch.cs
r15687 r15698 30 30 31 31 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSearch { 32 [Item(" Multi-start Local Search (GQAP)", "Multi-start localsearch for the GQAP.")]32 [Item("Random Search (GQAP)", "Random search for the GQAP.")] 33 33 [Creatable(CreatableAttribute.Categories.SingleSolutionAlgorithms)] 34 34 [StorableClass] 35 public sealed class MultistartLS: StochasticAlgorithm<LocalSearchContext, IntegerVectorEncoding> {35 public sealed class RandomSearch : StochasticAlgorithm<LocalSearchContext, IntegerVectorEncoding> { 36 36 37 37 public override bool SupportsPause { … … 49 49 50 50 [StorableConstructor] 51 private MultistartLS(bool deserializing) : base(deserializing) { }52 private MultistartLS(MultistartLSoriginal, Cloner cloner)51 private RandomSearch(bool deserializing) : base(deserializing) { } 52 private RandomSearch(RandomSearch original, Cloner cloner) 53 53 : base(original, cloner) { 54 54 } 55 public MultistartLS() {55 public RandomSearch() { 56 56 57 57 Problem = new GQAP(); … … 59 59 60 60 public override IDeepCloneable Clone(Cloner cloner) { 61 return new MultistartLS(this, cloner);61 return new RandomSearch(this, cloner); 62 62 } 63 63 … … 74 74 75 75 while (!StoppingCriterion()) { 76 var lsevaluations = 0;77 76 var assign = new IntegerVector(Problem.ProblemInstance.Demands.Length, Context.Random, 0, Problem.ProblemInstance.Capacities.Length); 78 77 var eval = Problem.ProblemInstance.Evaluate(assign); 78 var candidate = new GQAPSolution(assign, eval); 79 79 Context.EvaluatedSolutions++; 80 81 var candidate = new GQAPSolution(assign, eval);82 OneOptLocalSearch.Apply(Context.Random, candidate, Problem.ProblemInstance, out lsevaluations);83 Context.EvaluatedSolutions += lsevaluations;84 80 85 81 var candidateFit = Problem.ProblemInstance.ToSingleObjective(candidate.Evaluation); -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/RandomSearch/RandomSearchContext.cs
r15687 r15698 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms. LocalSearch {28 [Item(" Local Search Context", "Context for localsearch algorithms.")]27 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.RandomSearch { 28 [Item("Random Search Context", "Context for random search algorithms.")] 29 29 [StorableClass] 30 public sealed class LocalSearchContext : SingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {30 public sealed class RandomSearchContext : SingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> { 31 31 [Storable] 32 32 private IValueParameter<GQAP> problem; … … 44 44 45 45 [StorableConstructor] 46 private LocalSearchContext(bool deserializing) : base(deserializing) { }47 private LocalSearchContext(LocalSearchContext original, Cloner cloner)46 private RandomSearchContext(bool deserializing) : base(deserializing) { } 47 private RandomSearchContext(RandomSearchContext original, Cloner cloner) 48 48 : base(original, cloner) { 49 49 problem = cloner.Clone(original.problem); 50 50 bestSolution = cloner.Clone(original.bestSolution); 51 51 } 52 public LocalSearchContext() {52 public RandomSearchContext() { 53 53 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 54 54 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); … … 56 56 57 57 public override IDeepCloneable Clone(Cloner cloner) { 58 return new LocalSearchContext(this, cloner);58 return new RandomSearchContext(this, cloner); 59 59 } 60 60
Note: See TracChangeset
for help on using the changeset viewer.