Changeset 7970 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPEvaluator.cs
 Timestamp:
 06/06/12 04:29:56 (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPEvaluator.cs
r7593 r7970 31 31 32 32 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 33 [Item("GQAPEvaluator", " Evaluates solutions tothe generalized quadratic assignment problem.")]33 [Item("GQAPEvaluator", "Base class for solution evaluators for the generalized quadratic assignment problem.")] 34 34 [StorableClass] 35 public class GQAPEvaluator : SingleSuccessorOperator, IGQAPEvaluator,35 public abstract class GQAPEvaluator : SingleSuccessorOperator, IGQAPEvaluator, 36 36 IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, 37 IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IAssignmentAwareGQAPOperator { 37 IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IAssignmentAwareGQAPOperator, 38 IExpectedRandomQualityAwareGQAPOperator { 38 39 39 40 #region Parameter Descriptions … … 62 63 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 63 64 } 64 public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {65 get { return (IValueLookupParameter<DoubleValue>)Parameters[" OverbookedCapacityPenalty"]; }65 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 66 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 66 67 } 67 68 public ILookupParameter<DoubleMatrix> WeightsParameter { … … 87 88 protected GQAPEvaluator(bool deserializing) : base(deserializing) { } 88 89 protected GQAPEvaluator(GQAPEvaluator original, Cloner cloner) : base(original, cloner) { } 89 public GQAPEvaluator() 90 : base() { 90 public GQAPEvaluator() : base() { 91 91 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); 92 92 Parameters.Add(new LookupParameter<DoubleValue>("Quality", QualityDescription)); … … 95 95 Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", OverbookedCapacityDescription)); 96 96 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)); 98 98 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription)); 99 99 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription)); … … 104 104 } 105 105 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) { 113 109 double flowDistanceQuality, installationQuality, overbookedCapacity; 114 110 Evaluate(assignment, weights, distances, installCosts, demands, capacities, 115 111 out flowDistanceQuality, out installationQuality, out overbookedCapacity); 116 return Get CombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity,117 transportationCosts .Value, overbookedCapacityPenalty.Value);112 return GetFitness(flowDistanceQuality, installationQuality, overbookedCapacity, 113 transportationCosts, expectedRandomQuality); 118 114 } 119 115 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) { 123 120 flowDistanceQuality = 0; 124 121 installationQuality = 0; … … 135 132 } 136 133 137 public staticdouble 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(); 139 136 } 140 137 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); 147 141 148 142 public override IOperation Apply() { … … 154 148 var capacities = CapacitiesParameter.ActualValue; 155 149 var transportCosts = TransportationCostsParameter.ActualValue.Value; 156 double penalty = OverbookedCapacityPenaltyParameter.ActualValue.Value;150 var expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue.Value; 157 151 158 152 if (weights.Rows != weights.Columns  distances.Rows != distances.Columns … … 169 163 OverbookedCapacityParameter.ActualValue = new DoubleValue(overbookedCapacity); 170 164 171 QualityParameter.ActualValue = new DoubleValue(Get CombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, transportCosts, penalty));165 QualityParameter.ActualValue = new DoubleValue(GetFitness(flowDistanceQuality, installationQuality, overbookedCapacity, transportCosts, expectedRandomQuality)); 172 166 return base.Apply(); 173 167 }
Note: See TracChangeset
for help on using the changeset viewer.