Changeset 7970 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators
- Timestamp:
- 06/06/12 04:29:56 (12 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators
- Files:
-
- 2 added
- 2 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 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPNMoveEvaluator.cs
r7505 r7970 20 20 #endregion 21 21 22 using System.Linq;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 35 34 public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator, IAssignmentAwareGQAPOperator, 36 35 IQualityAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 37 IOverbookedCapacityPenaltyAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, 38 IInstallationCostsAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator { 36 IExpectedRandomQualityAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, 37 IInstallationCostsAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, 38 IEvaluatorAwareGQAPOperator { 39 39 40 40 #region Parameter Descriptions … … 94 94 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 95 95 } 96 public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {97 get { return (IValueLookupParameter<DoubleValue>)Parameters[" OverbookedCapacityPenalty"]; }96 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 97 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 98 98 } 99 99 public ILookupParameter<DoubleMatrix> WeightsParameter { … … 111 111 public ILookupParameter<DoubleArray> CapacitiesParameter { 112 112 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 113 } 114 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 115 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 113 116 } 114 117 #endregion … … 130 133 Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", MoveInstallationQualityDescription)); 131 134 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)); 133 136 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 134 137 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription)); … … 137 140 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); 138 141 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 142 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 139 143 } 140 144 … … 144 148 145 149 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) { 147 151 double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity; 148 Evaluate(move, assignment, weights, distances, installationCosts, demands, capacities, 152 Evaluate(move, assignment, weights, distances, installationCosts, demands, capacities, evaluator, 149 153 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); 152 156 } 153 157 154 158 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) { 156 160 moveFlowDistanceQuality = moveInstallationQuality = moveOverbookedCapacity = 0.0; 157 161 int moves = move.N; … … 184 188 } 185 189 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); 188 191 } 189 192 190 193 public override IOperation Apply() { 194 var evaluator = EvaluatorParameter.ActualValue; 191 195 double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity; 192 196 double quality = QualityParameter.ActualValue.Value; 193 197 double transportationCosts = TransportationCostsParameter.ActualValue.Value; 194 double overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue.Value;198 double expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue.Value; 195 199 196 200 double flowDistanceQuality = FlowDistanceQualityParameter.ActualValue.Value; … … 203 207 InstallationCostsParameter.ActualValue, 204 208 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue, 209 evaluator, 205 210 out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity); 206 211 … … 209 214 MoveOverbookedCapacityParameter.ActualValue = new DoubleValue(overbookedCapacity + moveOverbookedCapacity); 210 215 211 MoveQualityParameter.ActualValue = new DoubleValue( GQAPEvaluator.GetCombinedQuality(216 MoveQualityParameter.ActualValue = new DoubleValue(evaluator.GetFitness( 212 217 flowDistanceQuality + moveFlowDistanceQuality, 213 218 installationQuality + moveInstallationQuality, 214 219 overbookedCapacity + moveOverbookedCapacity, 215 transportationCosts, 216 overbookedCapacityPenalty)); 220 transportationCosts, expectedRandomQuality)); 217 221 return base.Apply(); 218 222 }
Note: See TracChangeset
for help on using the changeset viewer.