Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/10/17 22:11:10 (7 years ago)
Author:
abeham
Message:

#1614: refactored code

  • change problem to derive from basic problem
  • using a combined instance class instead of individual parameters
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/DemandEquivalentSwapEquipmentManipluator.cs

    r7813 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.IntegerVectorEncoding;
    29 using HeuristicLab.Parameters;
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130using HeuristicLab.Random;
     
    3534  [Item("DemandEquivalentSwapEquipmentManipluator", "Swaps equipment X from location A with as much equipments from location B that the demand of X is less than or equal to the demand of the swapped equipments in B.")]
    3635  [StorableClass]
    37   public class DemandEquivalentSwapEquipmentManipluator : GQAPManipulator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator {
    38 
    39     public ILookupParameter<DoubleArray> DemandsParameter {
    40       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    41     }
    42     public ILookupParameter<DoubleArray> CapacitiesParameter {
    43       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    44     }
     36  public class DemandEquivalentSwapEquipmentManipluator : GQAPManipulator {
    4537
    4638    [StorableConstructor]
     
    4941    public DemandEquivalentSwapEquipmentManipluator()
    5042      : base() {
    51       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    52       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    5343    }
    5444
     
    8575    }
    8676
    87     protected override void Manipulate(IRandom random, IntegerVector vector) {
    88       Apply(random, vector, CapacitiesParameter.ActualValue, DemandsParameter.ActualValue);
     77    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
     78      Apply(random, vector, problemInstance.Capacities, problemInstance.Demands);
    8979    }
    9080  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/GQAPManipulator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131  [Item("GQAPManipulator", "A base class for operators that manipulate assignment vectors of the GeneralizedQuadraticAssignment problems.")]
    3232  [StorableClass]
    33   public abstract class GQAPManipulator : SingleSuccessorOperator, IGQAPManipulator, IAssignmentAwareGQAPOperator, IStochasticOperator {
     33  public abstract class GQAPManipulator : SingleSuccessorOperator, IGQAPManipulator, IProblemInstanceAwareGQAPOperator, IStochasticOperator {
    3434    public override bool CanChangeName {
    3535      get { return false; }
     
    3939      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    4040    }
     41    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     42      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
     43    }
     44
    4145    public ILookupParameter<IRandom> RandomParameter {
    4246      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     
    4953      : base() {
    5054      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
     55      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
    5156      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    5257    }
    5358
    5459    public sealed override IOperation Apply() {
    55       Manipulate(RandomParameter.ActualValue, AssignmentParameter.ActualValue);
     60      Manipulate(RandomParameter.ActualValue, AssignmentParameter.ActualValue, ProblemInstanceParameter.ActualValue);
    5661      return base.Apply();
    5762    }
    5863
    59     protected abstract void Manipulate(IRandom random, IntegerVector integerVector);
     64    protected abstract void Manipulate(IRandom random, IntegerVector integerVector, GQAPInstance problemInstance);
    6065  }
    6166}
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/MultiGQAPManipulator.cs

    r11505 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("MultiGQAPManipulator", "Randomly selects and applies one of its manipulators every time it is called.")]
    3636  [StorableClass]
    37   public class MultiGQAPManipulator : StochasticMultiBranch<IGQAPManipulator>, IGQAPManipulator {
     37  public class MultiGQAPManipulator : StochasticMultiBranch<IGQAPManipulator>, IGQAPManipulator,
     38    IProblemInstanceAwareGQAPOperator {
    3839    public override bool CanChangeName {
    3940      get { return false; }
     
    4647      get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; }
    4748    }
     49    public ILookupParameter<GQAPInstance> ProblemInstanceParameter {
     50      get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; }
     51    }
    4852
    4953    [StorableConstructor]
     
    5357      : base() {
    5458      Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
     59      Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription));
     60
    5561      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IGQAPManipulator))) {
    5662        if (!typeof(MultiOperator<IGQAPManipulator>).IsAssignableFrom(type))
     
    7379
    7480    private void Parameterize() {
    75       foreach (var op in Operators.OfType<IGQAPManipulator>())
     81      foreach (var op in Operators.OfType<IGQAPManipulator>()) {
    7682        op.AssignmentParameter.ActualName = AssignmentParameter.Name;
    77       foreach (var op in Operators.OfType<IStochasticOperator>())
     83        op.AssignmentParameter.Hidden = true;
     84      }
     85      foreach (var op in Operators.OfType<IStochasticOperator>()) {
    7886        op.RandomParameter.ActualName = RandomParameter.Name;
     87        op.RandomParameter.Hidden = true;
     88      }
     89      foreach (var op in Operators.OfType<IProblemInstanceAwareGQAPOperator>()) {
     90        op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name;
     91        op.ProblemInstanceParameter.Hidden = true;
     92      }
    7993    }
    8094
    8195    public override IOperation InstrumentedApply() {
    8296      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one manipulator to choose from.");
    83       return base.Apply();
     97      return base.InstrumentedApply();
    8498    }
    8599  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/RelocateEquipmentManipluator.cs

    r7813 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.IntegerVectorEncoding;
    29 using HeuristicLab.Parameters;
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130using HeuristicLab.Random;
     
    3534  [Item("RelocateEquipmentManipluator", "Relocates a random equipment from an overstuffed location to a random one with space or a random equipment if constraints are satisfied.")]
    3635  [StorableClass]
    37   public class RelocateEquipmentManipluator : GQAPManipulator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator {
    38 
    39     public ILookupParameter<DoubleArray> CapacitiesParameter {
    40       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    41     }
    42     public ILookupParameter<DoubleArray> DemandsParameter {
    43       get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
    44     }
    45 
     36  public class RelocateEquipmentManipluator : GQAPManipulator {
     37   
    4638    [StorableConstructor]
    4739    protected RelocateEquipmentManipluator(bool deserializing) : base(deserializing) { }
     
    4941    public RelocateEquipmentManipluator()
    5042      : base() {
    51       Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    52       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    5343    }
    5444
     
    9282    }
    9383
    94     protected override void Manipulate(IRandom random, IntegerVector vector) {
    95       Apply(random, vector, CapacitiesParameter.ActualValue, DemandsParameter.ActualValue);
     84    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
     85      Apply(random, vector, problemInstance.Capacities, problemInstance.Demands);
    9686    }
    9787  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/SwapEquipmentManipluator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    5656    }
    5757
    58     protected override void Manipulate(IRandom random, IntegerVector vector) {
     58    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
    5959      Apply(random, vector);
    6060    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/SwapLocationManipulator.cs

    r7523 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2726using HeuristicLab.Encodings.IntegerVectorEncoding;
    28 using HeuristicLab.Parameters;
    2927using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3028
     
    3331  [Item("SwapLocationManipluator", "Swaps two locations by exchanging all equipments between the locations.")]
    3432  [StorableClass]
    35   public class SwapLocationManipluator : GQAPManipulator, ICapacitiesAwareGQAPOperator {
    36 
    37     public ILookupParameter<DoubleArray> CapacitiesParameter {
    38       get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
    39     }
    40 
     33  public class SwapLocationManipluator : GQAPManipulator {
     34   
    4135    [StorableConstructor]
    4236    protected SwapLocationManipluator(bool deserializing) : base(deserializing) { }
     
    4438    public SwapLocationManipluator()
    4539      : base() {
    46       Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
    4740    }
    4841
     
    7265    }
    7366
    74     protected override void Manipulate(IRandom random, IntegerVector vector) {
    75       Apply(random, vector, CapacitiesParameter.ActualValue.Length);
     67    protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) {
     68      Apply(random, vector, problemInstance.Capacities.Length);
    7669    }
    7770  }
Note: See TracChangeset for help on using the changeset viewer.