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/GQAPNMoveEvaluator.cs

    r7505 r7970  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    3534  public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator, IAssignmentAwareGQAPOperator,
    3635  IQualityAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
    37   IOverbookedCapacityPenaltyAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator,
    38   IInstallationCostsAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator {
     36  IExpectedRandomQualityAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator,
     37  IInstallationCostsAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator,
     38  IEvaluatorAwareGQAPOperator {
    3939
    4040    #region Parameter Descriptions
     
    9494      get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
    9595    }
    96     public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
    97       get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
     96    public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter {
     97      get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
    9898    }
    9999    public ILookupParameter<DoubleMatrix> WeightsParameter {
     
    111111    public ILookupParameter<DoubleArray> CapacitiesParameter {
    112112      get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
     113    }
     114    public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
     115      get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    113116    }
    114117    #endregion
     
    130133      Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", MoveInstallationQualityDescription));
    131134      Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", MoveOverbookedCapacityDescription));
    132       Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));
     135      Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription));
    133136      Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
    134137      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
     
    137140      Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
    138141      Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
     142      Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
    139143    }
    140144
     
    144148
    145149    public static double Evaluate(NMove move, IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts,
    146       DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty) {
     150      DoubleArray demands, DoubleArray capacities, double transportationCosts, double expectedRandomQuality, IGQAPEvaluator evaluator) {
    147151      double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity;
    148       Evaluate(move, assignment, weights, distances, installationCosts, demands, capacities,
     152      Evaluate(move, assignment, weights, distances, installationCosts, demands, capacities, evaluator,
    149153        out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity);
    150       return GQAPEvaluator.GetCombinedQuality(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity,
    151         transportationCosts.Value, overbookedCapacityPenalty.Value);
     154      return evaluator.GetFitness(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity,
     155        transportationCosts, expectedRandomQuality);
    152156    }
    153157
    154158    public static void Evaluate(NMove move, IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts,
    155       DoubleArray demands, DoubleArray capacities, out double moveFlowDistanceQuality, out double moveInstallationQuality, out double moveOverbookedCapacity) {
     159      DoubleArray demands, DoubleArray capacities, IGQAPEvaluator evaluator, out double moveFlowDistanceQuality, out double moveInstallationQuality, out double moveOverbookedCapacity) {
    156160      moveFlowDistanceQuality = moveInstallationQuality = moveOverbookedCapacity = 0.0;
    157161      int moves = move.N;
     
    184188      }
    185189
    186       moveOverbookedCapacity = slack.Select((v, i) => new { V = v, Index = i }).Where(x => x.V < 0.0).Select(x => -x.V / capacities[x.Index]).Sum()
    187                                - oldSlack.Select((v, i) => new { V = v, Index = i }).Where(x => x.V < 0.0).Select(x => -x.V / capacities[x.Index]).Sum();
     190      moveOverbookedCapacity = evaluator.EvaluateOverbooking(slack, capacities) - evaluator.EvaluateOverbooking(oldSlack, capacities);
    188191    }
    189192
    190193    public override IOperation Apply() {
     194      var evaluator = EvaluatorParameter.ActualValue;
    191195      double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity;
    192196      double quality = QualityParameter.ActualValue.Value;
    193197      double transportationCosts = TransportationCostsParameter.ActualValue.Value;
    194       double overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue.Value;
     198      double expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue.Value;
    195199
    196200      double flowDistanceQuality = FlowDistanceQualityParameter.ActualValue.Value;
     
    203207               InstallationCostsParameter.ActualValue,
    204208               DemandsParameter.ActualValue, CapacitiesParameter.ActualValue,
     209               evaluator,
    205210               out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity);
    206211
     
    209214      MoveOverbookedCapacityParameter.ActualValue = new DoubleValue(overbookedCapacity + moveOverbookedCapacity);
    210215
    211       MoveQualityParameter.ActualValue = new DoubleValue(GQAPEvaluator.GetCombinedQuality(
     216      MoveQualityParameter.ActualValue = new DoubleValue(evaluator.GetFitness(
    212217        flowDistanceQuality + moveFlowDistanceQuality,
    213218        installationQuality + moveInstallationQuality,
    214219        overbookedCapacity + moveOverbookedCapacity,
    215         transportationCosts,
    216         overbookedCapacityPenalty));
     220        transportationCosts, expectedRandomQuality));
    217221      return base.Apply();
    218222    }
Note: See TracChangeset for help on using the changeset viewer.