Changeset 7407 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators
- Timestamp:
- 01/24/12 17:23:21 (13 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPEvaluator.cs
r7319 r7407 87 87 } 88 88 89 public static DoubleValue Evaluate(IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, 90 DoubleMatrix installCosts, double transportCosts, DoubleArray demands, DoubleArray capacities, 91 out double infeasibility) { 92 double quality = 0; 93 int len = assignment.Length; 94 var slack = (DoubleArray)capacities.Clone(); 95 for (int i = 0; i < len; i++) { 96 quality += installCosts[i, assignment[i]]; 97 for (int j = 0; j < len; j++) { 98 quality += transportCosts * weights[i, j] * distances[assignment[i], assignment[j]]; 99 } 100 slack[assignment[i]] -= demands[i]; 101 } 102 103 infeasibility = -slack.Where(x => x < 0).Sum(); 104 return new DoubleValue(quality); 105 } 106 89 107 public override IOperation Apply() { 90 108 IntegerVector assignment = AssignmentParameter.ActualValue; … … 96 114 DoubleArray capacities = (DoubleArray)CapacitiesParameter.ActualValue.Clone(); 97 115 double penalty = PenaltyParameter.ActualValue.Value; 98 double quality = 0;99 double infeasibility = 0;100 116 101 117 if (weights.Rows != weights.Columns || distances.Rows != distances.Columns … … 104 120 throw new InvalidOperationException("ERROR: The problem configuration is not valid! Check the sizes of the weights (NxN), distances (MxM) and installation costs (NxM) matrices as well as the length of the demand (N) and capacities (M) vectors."); 105 121 106 int len = assignment.Length; 107 for (int i = 0; i < len; i++) { 108 quality += installCosts[i, assignment[i]]; 109 for (int j = 0; j < len; j++) { 110 quality += transportCosts * weights[i, j] * distances[assignment[i], assignment[j]]; 111 } 112 capacities[assignment[i]] -= demands[i]; 113 } 114 115 infeasibility = -capacities.Where(x => x < 0).Sum(); 122 double infeasibility; 123 var quality = Evaluate(assignment, weights, distances, installCosts, transportCosts, demands, capacities, out infeasibility); 116 124 117 125 InfeasibilityParameter.ActualValue = new DoubleValue(infeasibility); 118 QualityParameter.ActualValue = new DoubleValue(quality + penalty * infeasibility);126 QualityParameter.ActualValue = new DoubleValue(quality.Value + penalty * infeasibility); 119 127 return base.Apply(); 120 128 }
Note: See TracChangeset
for help on using the changeset viewer.