Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/06/12 04:29:56 (12 years ago)
Author:
abeham
Message:

#1614: restructured architecture to allow for different evaluator with different penalty strategies

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPEvaluator.cs

    r7593 r7970  
    3131
    3232namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
    33   [Item("GQAPEvaluator", "Evaluates solutions to the generalized quadratic assignment problem.")]
     33  [Item("GQAPEvaluator", "Base class for solution evaluators for the generalized quadratic assignment problem.")]
    3434  [StorableClass]
    35   public class GQAPEvaluator : SingleSuccessorOperator, IGQAPEvaluator,
     35  public abstract class GQAPEvaluator : SingleSuccessorOperator, IGQAPEvaluator,
    3636  IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator,
    37   IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IAssignmentAwareGQAPOperator {
     37  IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IAssignmentAwareGQAPOperator,
     38  IExpectedRandomQualityAwareGQAPOperator {
    3839
    3940    #region Parameter Descriptions
     
    6263      get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    6364    }
    64     public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
    65       get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
     65    public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter {
     66      get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
    6667    }
    6768    public ILookupParameter<DoubleMatrix> WeightsParameter {
     
    8788    protected GQAPEvaluator(bool deserializing) : base(deserializing) { }
    8889    protected GQAPEvaluator(GQAPEvaluator original, Cloner cloner) : base(original, cloner) { }
    89     public GQAPEvaluator()
    90       : base() {
     90    public GQAPEvaluator() : base() {
    9191      Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
    9292      Parameters.Add(new LookupParameter<DoubleValue>("Quality", QualityDescription));
     
    9595      Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", OverbookedCapacityDescription));
    9696      Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
    97       Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));
     97      Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription));
    9898      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
    9999      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
     
    104104    }
    105105
    106     public override IDeepCloneable Clone(Cloner cloner) {
    107       return new GQAPEvaluator(this, cloner);
    108     }
    109 
    110     public static double Evaluate(IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances,
    111                                   DoubleMatrix installCosts, DoubleArray demands, DoubleArray capacities,
    112                                   DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty) {
     106    public virtual double Evaluate(IntegerVector assignment, DoubleMatrix weights,
     107      DoubleMatrix distances, DoubleMatrix installCosts, DoubleArray demands,
     108      DoubleArray capacities, double transportationCosts, double expectedRandomQuality) {
    113109      double flowDistanceQuality, installationQuality, overbookedCapacity;
    114110      Evaluate(assignment, weights, distances, installCosts, demands, capacities,
    115111        out flowDistanceQuality, out installationQuality, out overbookedCapacity);
    116       return GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity,
    117         transportationCosts.Value, overbookedCapacityPenalty.Value);
     112      return GetFitness(flowDistanceQuality, installationQuality, overbookedCapacity,
     113        transportationCosts, expectedRandomQuality);
    118114    }
    119115
    120     public static void Evaluate(IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances,
    121                                 DoubleMatrix installCosts, DoubleArray demands, DoubleArray capacities,
    122                                 out double flowDistanceQuality, out double installationQuality, out double overbookedCapacity) {
     116    public virtual void Evaluate(IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances,
     117      DoubleMatrix installCosts, DoubleArray demands, DoubleArray capacities,
     118      out double flowDistanceQuality, out double installationQuality,
     119      out double overbookedCapacity) {
    123120      flowDistanceQuality = 0;
    124121      installationQuality = 0;
     
    135132    }
    136133
    137     public static double EvaluateOverbooking(DoubleArray slack, DoubleArray capacities) {
    138       return slack.Select((v, i) => new { V = v, Index = i }).Where(x => x.V < 0.0).Select(x => -x.V / capacities[x.Index]).Sum();
     134    public virtual double EvaluateOverbooking(DoubleArray slack, DoubleArray capacities) {
     135      return slack.Select((v, i) => new { V = v, Index = i }).Where(x => x.V < 0.0).Select(x => -100.0 * x.V / capacities[x.Index]).Sum();
    139136    }
    140137
    141     public static double GetCombinedQuality(double flowDistanceQuality, double installationQuality, double overbookedCapacity,
    142       double transportationCosts, double overbookedCapacityPenalty) {
    143       return installationQuality
    144         + transportationCosts * flowDistanceQuality
    145         + overbookedCapacityPenalty * overbookedCapacity;
    146     }
     138    public abstract double GetFitness(double flowDistanceQuality,
     139      double installationQuality, double overbookedCapacity,
     140      double transportationCosts, double expectedRandomQuality);
    147141
    148142    public override IOperation Apply() {
     
    154148      var capacities = CapacitiesParameter.ActualValue;
    155149      var transportCosts = TransportationCostsParameter.ActualValue.Value;
    156       double penalty = OverbookedCapacityPenaltyParameter.ActualValue.Value;
     150      var expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue.Value;
    157151
    158152      if (weights.Rows != weights.Columns || distances.Rows != distances.Columns
     
    169163      OverbookedCapacityParameter.ActualValue = new DoubleValue(overbookedCapacity);
    170164
    171       QualityParameter.ActualValue = new DoubleValue(GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, transportCosts, penalty));
     165      QualityParameter.ActualValue = new DoubleValue(GetFitness(flowDistanceQuality, installationQuality, overbookedCapacity, transportCosts, expectedRandomQuality));
    172166      return base.Apply();
    173167    }
Note: See TracChangeset for help on using the changeset viewer.