Changeset 15506
- Timestamp:
- 12/11/17 11:57:56 (7 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/GQAPNMoveEvaluator.cs
r15504 r15506 34 34 [StorableClass] 35 35 public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator, 36 IQualityAwareGQAPOperator, IProblemInstanceAwareGQAPOperator {36 IQualityAwareGQAPOperator, IProblemInstanceAwareGQAPOperator, IAssignmentAwareGQAPOperator { 37 37 38 38 #region Parameter Descriptions -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAP.cs
r15504 r15506 48 48 public override bool Maximization { get { return false; } } 49 49 50 [Storable] 51 private bool initialized; // ABE: helper variable that defines if the constructor has completed 52 50 53 #region Parameter Descriptions 51 54 public static readonly string BestKnownQualityDescription = "The best known quality (if available)."; … … 88 91 : base(original, cloner) { 89 92 RegisterEventHandlers(); 93 initialized = original.initialized; 90 94 } 91 95 public GQAP() : base() { … … 97 101 InitializeOperators(); 98 102 RegisterEventHandlers(); 103 initialized = true; 104 Parameterize(); 99 105 } 100 106 … … 343 349 protected override void OnOperatorsChanged() { 344 350 base.OnOperatorsChanged(); 351 if (!initialized) return; 345 352 Parameterize(); 346 353 } 347 354 protected override void OnEncodingChanged() { 348 355 base.OnEncodingChanged(); 356 if (!initialized) return; 349 357 Parameterize(); 350 358 } … … 397 405 Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator); 398 406 Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>()); 399 Operators.Add(new HammingSimilarityCalculator() );400 Operators.Add(new QualitySimilarityCalculator() );407 Operators.Add(new HammingSimilarityCalculator() { SolutionVariableName = Encoding.Name, QualityVariableName = Evaluator.QualityParameter.ActualName }); 408 Operators.Add(new QualitySimilarityCalculator() { SolutionVariableName = Encoding.Name, QualityVariableName = Evaluator.QualityParameter.ActualName }); 401 409 402 410 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 403 Parameterize();404 411 } 405 412 406 413 private void Parameterize() { 407 414 var operators = Operators.Union(new IOperator[] { SolutionCreator, Evaluator }).ToArray(); 408 415 Encoding.ConfigureOperators(operators.OfType<IOperator>()); 416 foreach (var op in operators.OfType<IAssignmentAwareGQAPOperator>()) { 417 op.AssignmentParameter.ActualName = Encoding.Name; 418 op.AssignmentParameter.Hidden = true; 419 } 409 420 foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) { 410 421 op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IAssignmentAwareGQAPOperator.cs
r15504 r15506 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Encodings.IntegerVectorEncoding; 23 24 24 25 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 25 public interface I ProblemInstanceAwareGQAPOperator : IGQAPOperator {26 ILookupParameter< GQAPInstance> ProblemInstanceParameter { get; }26 public interface IAssignmentAwareGQAPOperator : IGQAPOperator { 27 ILookupParameter<IntegerVector> AssignmentParameter { get; } 27 28 } 28 29 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/CordeauCrossover.cs
r15504 r15506 35 35 public class CordeauCrossover : GQAPCrossover, 36 36 IQualitiesAwareGQAPOperator, IProblemInstanceAwareGQAPOperator { 37 38 public ILookupParameter<BoolValue> MaximizationParameter { 39 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 40 } 37 41 38 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 42 39 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } … … 56 53 public CordeauCrossover() 57 54 : base() { 58 Parameters.Add(new LookupParameter<BoolValue>("Maximization", ""));59 55 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parents", 1)); 60 56 Parameters.Add(new ScopeTreeLookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription, 1)); … … 66 62 } 67 63 68 public static IntegerVector Apply(IRandom random, bool maximization,64 public static IntegerVector Apply(IRandom random, 69 65 IntegerVector parent1, DoubleValue quality1, 70 66 IntegerVector parent2, DoubleValue quality2, … … 80 76 81 77 bool onefound = false; 82 double fbest, fbestAttempt = maximization ? double.MinValue :double.MaxValue;78 double fbest, fbestAttempt = double.MaxValue; 83 79 IntegerVector bestAttempt = null; 84 80 IntegerVector result = null; 85 81 86 82 fbest = quality1.Value; 87 if (maximization && quality1.Value < quality2.Value 88 || !maximization && quality1.Value > quality2.Value) { 83 if (quality1.Value > quality2.Value) { 89 84 var temp = parent1; 90 85 parent1 = parent2; … … 102 97 var childFit = problemInstance.ToSingleObjective(problemInstance.Evaluate(child)); 103 98 evaluatedSolutions.Value++; 104 if (maximization && childFit >= fbest 105 || !maximization && childFit <= fbest) { 99 if (childFit <= fbest) { 106 100 fbest = childFit; 107 101 result = child; 108 102 onefound = true; 109 103 } 110 if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {104 if (!onefound && fbestAttempt > childFit) { 111 105 bestAttempt = child; 112 106 fbestAttempt = childFit; … … 130 124 } 131 125 132 if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {126 if (!onefound && fbestAttempt > childFit) { 133 127 bestAttempt = child; 134 128 fbestAttempt = childFit; … … 203 197 204 198 var qualities = QualityParameter.ActualValue; 205 return Apply(random, MaximizationParameter.ActualValue.Value,199 return Apply(random, 206 200 parents[0], qualities[0], 207 201 parents[1], qualities[1], -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs
r15504 r15506 36 36 [StorableClass] 37 37 public class ApproximateLocalSearch : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, 38 IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, I StochasticOperator {38 IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, IAssignmentAwareGQAPOperator, IStochasticOperator { 39 39 public IProblem Problem { get; set; } 40 40 public Type ProblemType { -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/PopulationReducers/GQAPQualitySimilarityReducer.cs
r15504 r15506 34 34 [Item("GQAPQualitySimilarityReducer", "Reduces two populations two one by using quality and similarity information to obtain a population of high quality, but also diverse solutions.")] 35 35 [StorableClass] 36 public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, IQualityAwareGQAPOperator, I PopulationReducer {36 public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, IQualityAwareGQAPOperator, IAssignmentAwareGQAPOperator, IPopulationReducer { 37 37 public ILookupParameter<IntegerVector> AssignmentParameter { 38 38 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Shakers/NMoveShakingOperator.cs
r15504 r15506 32 32 [Item("NMoveShakingOperator", "Performs a number of shaking operations that increase in strength.")] 33 33 [StorableClass] 34 public class NMoveShakingOperator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator { 34 public class NMoveShakingOperator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, 35 IAssignmentAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator { 35 36 36 37
Note: See TracChangeset
for help on using the changeset viewer.