Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/11/17 11:57:56 (7 years ago)
Author:
abeham
Message:

#1614: finished wiring

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  
    3434  [StorableClass]
    3535  public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator,
    36     IQualityAwareGQAPOperator, IProblemInstanceAwareGQAPOperator {
     36    IQualityAwareGQAPOperator, IProblemInstanceAwareGQAPOperator, IAssignmentAwareGQAPOperator {
    3737
    3838    #region Parameter Descriptions
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAP.cs

    r15504 r15506  
    4848    public override bool Maximization { get { return false; } }
    4949
     50    [Storable]
     51    private bool initialized; // ABE: helper variable that defines if the constructor has completed
     52
    5053    #region Parameter Descriptions
    5154    public static readonly string BestKnownQualityDescription = "The best known quality (if available).";
     
    8891      : base(original, cloner) {
    8992      RegisterEventHandlers();
     93      initialized = original.initialized;
    9094    }
    9195    public GQAP() : base() {
     
    97101      InitializeOperators();
    98102      RegisterEventHandlers();
     103      initialized = true;
     104      Parameterize();
    99105    }
    100106
     
    343349    protected override void OnOperatorsChanged() {
    344350      base.OnOperatorsChanged();
     351      if (!initialized) return;
    345352      Parameterize();
    346353    }
    347354    protected override void OnEncodingChanged() {
    348355      base.OnEncodingChanged();
     356      if (!initialized) return;
    349357      Parameterize();
    350358    }
     
    397405      Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
    398406      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 });
    401409     
    402410      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    403       Parameterize();
    404411    }
    405412
    406413    private void Parameterize() {
    407414      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      }
    409420      foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) {
    410421        op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IAssignmentAwareGQAPOperator.cs

    r15504 r15506  
    2121
    2222using HeuristicLab.Core;
     23using HeuristicLab.Encodings.IntegerVectorEncoding;
    2324
    2425namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    25   public interface IProblemInstanceAwareGQAPOperator : IGQAPOperator {
    26     ILookupParameter<GQAPInstance> ProblemInstanceParameter { get; }
     26  public interface IAssignmentAwareGQAPOperator : IGQAPOperator {
     27    ILookupParameter<IntegerVector> AssignmentParameter { get; }
    2728  }
    2829}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/CordeauCrossover.cs

    r15504 r15506  
    3535  public class CordeauCrossover : GQAPCrossover,
    3636    IQualitiesAwareGQAPOperator, IProblemInstanceAwareGQAPOperator {
    37 
    38     public ILookupParameter<BoolValue> MaximizationParameter {
    39       get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    40     }
     37   
    4138    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
    4239      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     
    5653    public CordeauCrossover()
    5754      : base() {
    58       Parameters.Add(new LookupParameter<BoolValue>("Maximization", ""));
    5955      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parents", 1));
    6056      Parameters.Add(new ScopeTreeLookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription, 1));
     
    6662    }
    6763
    68     public static IntegerVector Apply(IRandom random, bool maximization,
     64    public static IntegerVector Apply(IRandom random,
    6965      IntegerVector parent1, DoubleValue quality1,
    7066      IntegerVector parent2, DoubleValue quality2,
     
    8076     
    8177      bool onefound = false;
    82       double fbest, fbestAttempt = maximization ? double.MinValue : double.MaxValue;
     78      double fbest, fbestAttempt = double.MaxValue;
    8379      IntegerVector bestAttempt = null;
    8480      IntegerVector result = null;
    8581
    8682      fbest = quality1.Value;
    87       if (maximization && quality1.Value < quality2.Value
    88         || !maximization && quality1.Value > quality2.Value) {
     83      if (quality1.Value > quality2.Value) {
    8984        var temp = parent1;
    9085        parent1 = parent2;
     
    10297          var childFit = problemInstance.ToSingleObjective(problemInstance.Evaluate(child));
    10398          evaluatedSolutions.Value++;
    104           if (maximization && childFit >= fbest
    105             || !maximization && childFit <= fbest) {
     99          if (childFit <= fbest) {
    106100            fbest = childFit;
    107101            result = child;
    108102            onefound = true;
    109103          }
    110           if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {
     104          if (!onefound && fbestAttempt > childFit) {
    111105            bestAttempt = child;
    112106            fbestAttempt = childFit;
     
    130124        }
    131125
    132         if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) {
     126        if (!onefound && fbestAttempt > childFit) {
    133127          bestAttempt = child;
    134128          fbestAttempt = childFit;
     
    203197
    204198      var qualities = QualityParameter.ActualValue;
    205       return Apply(random, MaximizationParameter.ActualValue.Value,
     199      return Apply(random,
    206200        parents[0], qualities[0],
    207201        parents[1], qualities[1],
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs

    r15504 r15506  
    3636  [StorableClass]
    3737  public class ApproximateLocalSearch : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator,
    38     IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, IStochasticOperator {
     38    IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, IAssignmentAwareGQAPOperator, IStochasticOperator {
    3939    public IProblem Problem { get; set; }
    4040    public Type ProblemType {
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/PopulationReducers/GQAPQualitySimilarityReducer.cs

    r15504 r15506  
    3434  [Item("GQAPQualitySimilarityReducer", "Reduces two populations two one by using quality and similarity information to obtain a population of high quality, but also diverse solutions.")]
    3535  [StorableClass]
    36   public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, IQualityAwareGQAPOperator, IPopulationReducer {
     36  public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, IQualityAwareGQAPOperator, IAssignmentAwareGQAPOperator, IPopulationReducer {
    3737    public ILookupParameter<IntegerVector> AssignmentParameter {
    3838      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Shakers/NMoveShakingOperator.cs

    r15504 r15506  
    3232  [Item("NMoveShakingOperator", "Performs a number of shaking operations that increase in strength.")]
    3333  [StorableClass]
    34   public class NMoveShakingOperator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator {
     34  public class NMoveShakingOperator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator,
     35    IAssignmentAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator {
    3536
    3637
Note: See TracChangeset for help on using the changeset viewer.