Changeset 7970
- Timestamp:
- 06/06/12 04:29:56 (12 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 4 added
- 1 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentArchiveView.cs
r7437 r7970 101 101 if (h.ChartElementType == ChartElementType.DataPoint) { 102 102 var solution = (GQAPSolution)((DataPoint)h.Object).Tag; 103 var assignment = new GQAPAssignment(solution.Assignment, solution.Quality, solution.FlowDistanceQuality, solution.InstallationQuality, solution.OverbookedCapacity, Content.EquipmentNames, Content.LocationNames, Content.Distances, Content.Weights, Content.InstallationCosts, Content.Demands, Content.Capacities, Content.TransportationCosts, Content. OverbookedCapacityPenalty);103 var assignment = new GQAPAssignment(solution.Assignment, solution.Quality, solution.FlowDistanceQuality, solution.InstallationQuality, solution.OverbookedCapacity, Content.EquipmentNames, Content.LocationNames, Content.Distances, Content.Weights, Content.InstallationCosts, Content.Demands, Content.Capacities, Content.TransportationCosts, Content.ExpectedRandomQuality, Content.Evaluator); 104 104 105 105 var view = MainFormManager.MainForm.ShowContent(assignment); -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs
r7593 r7970 315 315 private void recalculateButton_Click(object sender, EventArgs e) { 316 316 double fdq, iq, oc; 317 GQAPEvaluator.Evaluate(Content.Assignment, Content.Weights,317 Content.Evaluator.Evaluate(Content.Assignment, Content.Weights, 318 318 Content.Distances, Content.InstallationCosts, Content.Demands, 319 319 Content.Capacities, out fdq, out iq, out oc); … … 322 322 Content.OverbookedCapacity = new DoubleValue(oc); 323 323 Content.Quality = new DoubleValue( 324 GQAPEvaluator.GetCombinedQuality(fdq, iq, oc,325 Content.TransportationCosts.Value, Content. OverbookedCapacityPenalty.Value));324 Content.Evaluator.GetFitness(fdq, iq, oc, 325 Content.TransportationCosts.Value, Content.ExpectedRandomQuality.Value)); 326 326 } 327 327 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/BestGQAPSolutionAnalyzer.cs
r7807 r7970 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common;32 31 33 32 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { … … 40 39 IQualitiesAwareGQAPOperator, IDistancesAwareGQAPOperator, IWeightsAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, 41 40 IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 42 IOverbookedCapacityPenaltyAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator, 43 IBestKnownQualityAwareGQAPOperator, IBestKnownSolutionAwareGQAPOperator, IAnalyzer { 41 IExpectedRandomQualityAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator, 42 IBestKnownQualityAwareGQAPOperator, IBestKnownSolutionAwareGQAPOperator, 43 IEvaluatorAwareGQAPOperator, IAnalyzer { 44 44 45 45 public bool EnabledByDefault { … … 84 84 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 85 85 } 86 public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {87 get { return (IValueLookupParameter<DoubleValue>)Parameters[" OverbookedCapacityPenalty"]; }86 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 87 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 88 88 } 89 89 public ILookupParameter<StringArray> EquipmentNamesParameter { … … 104 104 public IValueLookupParameter<ResultCollection> ResultsParameter { 105 105 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 106 } 107 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 108 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 106 109 } 107 110 #endregion … … 122 125 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 123 126 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 124 Parameters.Add(new ValueLookupParameter<DoubleValue>(" OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));127 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 125 128 Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 126 129 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription)); … … 134 137 Parameters.Add(new LookupParameter<GQAPAssignment>("BestSolution", "The best GQAP solution found so far.")); 135 138 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored.")); 139 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 136 140 } 137 141 138 142 public override IOperation Apply() { 143 var evaluator = EvaluatorParameter.ActualValue; 139 144 var assignments = AssignmentParameter.ActualValue; 140 145 var qualities = QualityParameter.ActualValue; … … 150 155 var capacities = CapacitiesParameter.ActualValue; 151 156 var transportationCosts = TransportationCostsParameter.ActualValue; 152 var overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue;157 var expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue; 153 158 var results = ResultsParameter.ActualValue; 154 159 var maximization = MaximizationParameter.ActualValue.Value; … … 162 167 if (bestKnownQuality == null || HasSolutionImproved(bestKnownQuality.Value, qualities[bestIndex].Value, maximization)) { 163 168 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[bestIndex].Value); 164 BestKnownSolutionParameter.ActualValue = new GQAPAssignment((IntegerVector)assignments[bestIndex].Clone(), (DoubleValue)qualities[bestIndex].Clone(), flowDistanceQualities[bestIndex], installationQualities[bestIndex], overbookedCapacities[bestIndex], equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);169 BestKnownSolutionParameter.ActualValue = new GQAPAssignment((IntegerVector)assignments[bestIndex].Clone(), (DoubleValue)qualities[bestIndex].Clone(), flowDistanceQualities[bestIndex], installationQualities[bestIndex], overbookedCapacities[bestIndex], equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality, evaluator); 165 170 } 166 171 167 172 var assignment = BestSolutionParameter.ActualValue; 168 173 if (assignment == null) { 169 assignment = new GQAPAssignment((IntegerVector)assignments[bestIndex].Clone(), (DoubleValue)qualities[bestIndex].Clone(), flowDistanceQualities[bestIndex], installationQualities[bestIndex], overbookedCapacities[bestIndex], equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);174 assignment = new GQAPAssignment((IntegerVector)assignments[bestIndex].Clone(), (DoubleValue)qualities[bestIndex].Clone(), flowDistanceQualities[bestIndex], installationQualities[bestIndex], overbookedCapacities[bestIndex], equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality, evaluator); 170 175 assignment.Distances = distances; 171 176 BestSolutionParameter.ActualValue = assignment; … … 185 190 assignment.Capacities = capacities; 186 191 assignment.TransportationCosts = transportationCosts; 187 assignment.OverbookedCapacityPenalty = overbookedCapacityPenalty; 192 assignment.ExpectedRandomQuality = expectedRandomQuality; 193 assignment.Evaluator = evaluator; 188 194 } 189 195 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/GQAPSolutionArchiveAnalyzer.cs
r7470 r7970 39 39 IQualitiesAwareGQAPOperator, IDistancesAwareGQAPOperator, IWeightsAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, 40 40 IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 41 I OverbookedCapacityPenaltyAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator,42 IBestKnownSolutionsAwareGQAPOperator, I Analyzer {41 IExpectedRandomQualityAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator, 42 IBestKnownSolutionsAwareGQAPOperator, IEvaluatorAwareGQAPOperator, IAnalyzer { 43 43 44 44 public bool EnabledByDefault { … … 82 82 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 83 83 } 84 public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {85 get { return (IValueLookupParameter<DoubleValue>)Parameters[" OverbookedCapacityPenalty"]; }84 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 85 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 86 86 } 87 87 public ILookupParameter<StringArray> EquipmentNamesParameter { … … 96 96 public ILookupParameter<GQAPAssignmentArchive> BestKnownSolutionsParameter { 97 97 get { return (ILookupParameter<GQAPAssignmentArchive>)Parameters["BestKnownSolutions"]; } 98 } 99 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 100 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 98 101 } 99 102 … … 113 116 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 114 117 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 115 Parameters.Add(new ValueLookupParameter<DoubleValue>(" OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));118 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 116 119 Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 117 120 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription)); … … 123 126 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored.")); 124 127 Parameters.Add(new LookupParameter<GQAPAssignmentArchive>("BestKnownSolutions", GeneralizedQuadraticAssignmentProblem.BestKnownSolutionsDescription)); 128 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 125 129 } 126 130 127 131 public override IOperation Apply() { 132 var evaluator = EvaluatorParameter.ActualValue; 128 133 var assignments = AssignmentParameter.ActualValue; 129 134 var qualities = QualityParameter.ActualValue; … … 139 144 var capacities = CapacitiesParameter.ActualValue; 140 145 var transportationCosts = TransportationCostsParameter.ActualValue; 141 var overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue;146 var expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue; 142 147 var results = ResultsParameter.ActualValue; 143 148 var maximization = MaximizationParameter.ActualValue.Value; … … 145 150 GQAPAssignmentArchive archive = results.ContainsKey("Solution Archive") ? results["Solution Archive"].Value as GQAPAssignmentArchive : null; 146 151 if (archive == null) { 147 archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);152 archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality, evaluator); 148 153 results.Add(new Result("Solution Archive", archive)); 149 154 } else { … … 156 161 archive.Capacities = capacities; 157 162 archive.TransportationCosts = transportationCosts; 158 archive.OverbookedCapacityPenalty = overbookedCapacityPenalty; 163 archive.ExpectedRandomQuality = expectedRandomQuality; 164 archive.Evaluator = evaluator; 159 165 } 160 166 -
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 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignment.cs
r7470 r7970 176 176 177 177 [Storable] 178 private DoubleValue overbookedCapacityPenalty; 179 public DoubleValue OverbookedCapacityPenalty { 180 get { return overbookedCapacityPenalty; } 181 set { 182 bool changed = (overbookedCapacityPenalty != value); 183 overbookedCapacityPenalty = value; 184 if (changed) OnPropertyChanged("OverbookedCapacityPenalty"); 178 private DoubleValue expectedRandomQuality; 179 public DoubleValue ExpectedRandomQuality { 180 get { return expectedRandomQuality; } 181 set { 182 bool changed = (expectedRandomQuality != value); 183 expectedRandomQuality = value; 184 if (changed) OnPropertyChanged("ExpectedRandomQuality"); 185 } 186 } 187 188 [Storable] 189 private IGQAPEvaluator evaluator; 190 public IGQAPEvaluator Evaluator { 191 get { return evaluator; } 192 set { 193 bool changed = (evaluator != value); 194 evaluator = value; 195 if (changed) OnPropertyChanged("Evaluator"); 185 196 } 186 197 } … … 203 214 capacities = cloner.Clone(original.capacities); 204 215 transportationCosts = cloner.Clone(original.transportationCosts); 205 overbookedCapacityPenalty = cloner.Clone(original.overbookedCapacityPenalty); 206 } 207 public GQAPAssignment(IntegerVector assignment, DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity, StringArray equipmentNames, StringArray locationNames, DoubleMatrix distances, DoubleMatrix weights, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty) 216 expectedRandomQuality = cloner.Clone(original.expectedRandomQuality); 217 evaluator = cloner.Clone(original.evaluator); 218 } 219 public GQAPAssignment(IntegerVector assignment, DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity, StringArray equipmentNames, StringArray locationNames, DoubleMatrix distances, DoubleMatrix weights, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue expectedRandomQuality, IGQAPEvaluator evaluator) 208 220 : base() { 209 221 this.assignment = assignment; … … 220 232 this.capacities = capacities; 221 233 this.transportationCosts = transportationCosts; 222 this.overbookedCapacityPenalty = overbookedCapacityPenalty; 234 this.expectedRandomQuality = expectedRandomQuality; 235 this.evaluator = evaluator; 223 236 } 224 237 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignmentArchive.cs
r7935 r7970 131 131 132 132 [Storable] 133 private DoubleValue overbookedCapacityPenalty;134 public DoubleValue OverbookedCapacityPenalty {135 get { return overbookedCapacityPenalty; }133 private DoubleValue expectedRandomQuality; 134 public DoubleValue ExpectedRandomQuality { 135 get { return expectedRandomQuality; } 136 136 set { 137 bool changed = (overbookedCapacityPenalty != value); 138 overbookedCapacityPenalty = value; 139 if (changed) OnPropertyChanged("OverbookedCapacityPenalty"); 137 bool changed = (expectedRandomQuality != value); 138 expectedRandomQuality = value; 139 if (changed) OnPropertyChanged("ExpectedRandomQuality"); 140 } 141 } 142 143 [Storable] 144 private IGQAPEvaluator evaluator; 145 public IGQAPEvaluator Evaluator { 146 get { return evaluator; } 147 set { 148 bool changed = (evaluator != value); 149 evaluator = value; 150 if (changed) OnPropertyChanged("Evaluator"); 140 151 } 141 152 } … … 154 165 capacities = cloner.Clone(original.capacities); 155 166 transportationCosts = cloner.Clone(original.transportationCosts); 156 overbookedCapacityPenalty = cloner.Clone(original.overbookedCapacityPenalty); 167 expectedRandomQuality = cloner.Clone(original.expectedRandomQuality); 168 evaluator = cloner.Clone(original.evaluator); 157 169 } 158 170 public GQAPAssignmentArchive() … … 160 172 this.solutions = new ItemList<GQAPSolution>(); 161 173 } 162 public GQAPAssignmentArchive(StringArray equipmentNames, StringArray locationNames, DoubleMatrix distances, DoubleMatrix weights, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty)174 public GQAPAssignmentArchive(StringArray equipmentNames, StringArray locationNames, DoubleMatrix distances, DoubleMatrix weights, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue expectedRandomQuality, IGQAPEvaluator evaluator) 163 175 : this() { 164 176 this.distances = distances; … … 168 180 this.capacities = capacities; 169 181 this.transportationCosts = transportationCosts; 170 this.overbookedCapacityPenalty = overbookedCapacityPenalty; 182 this.expectedRandomQuality = expectedRandomQuality; 183 this.evaluator = evaluator; 171 184 } 172 185 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs
r7548 r7970 23 23 using System.Drawing; 24 24 using System.Linq; 25 using HeuristicLab.Analysis.QualityAnalysis; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 31 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 33 using HeuristicLab.PluginInfrastructure; 33 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common;34 34 using HeuristicLab.Problems.Instances; 35 35 … … 59 59 public static readonly string CapacitiesDescription = "The capacities vector describes the available space at the locations."; 60 60 public static readonly string TransportationCostsDescription = "The transportation cost represents the flow-unit per distance-unit cost factor. This value can also be set to 1 if these costs are factored into the weights matrix already."; 61 public static readonly string OverbookedCapacityPenaltyDescription = "The multiplier for the constraint violation when added to the quality.";62 61 public static readonly string BestKnownQualityDescription = "The best known quality (if available)."; 63 62 public static readonly string BestKnownSolutionDescription = "The best known solution (if available)."; … … 65 64 public static readonly string EquipmentNamesDescription = "Optional: A list of names that describes the equipments."; 66 65 public static readonly string LocationNamesDescription = "Optional: A list of names that describes the locations."; 66 public static readonly string ExpectedRandomQualityDescription = "The expected quality value of a random solution."; 67 67 #endregion 68 68 … … 86 86 get { return (FixedValueParameter<DoubleValue>)Parameters["TransportationCosts"]; } 87 87 } 88 public FixedValueParameter<DoubleValue> OverbookedCapacityPenaltyParameter {89 get { return (FixedValueParameter<DoubleValue>)Parameters[" OverbookedCapacityPenalty"]; }88 public FixedValueParameter<DoubleValue> ExpectedRandomQualityParameter { 89 get { return (FixedValueParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 90 90 } 91 91 public OptionalValueParameter<GQAPAssignment> BestKnownSolutionParameter { … … 124 124 set { CapacitiesParameter.Value = value; } 125 125 } 126 public DoubleValue TransportationCosts {127 get { return TransportationCostsParameter.Value ; }128 set { TransportationCostsParameter.Value = value; }129 } 130 public DoubleValue OverbookedCapacityPenalty {131 get { return TransportationCostsParameter.Value; }132 set { TransportationCostsParameter.Value = value; }126 public double TransportationCosts { 127 get { return TransportationCostsParameter.Value.Value; } 128 set { TransportationCostsParameter.Value.Value = value; } 129 } 130 public double ExpectedRandomQuality { 131 get { return ExpectedRandomQualityParameter.Value.Value; } 132 set { ExpectedRandomQualityParameter.Value.Value = value; } 133 133 } 134 134 public StringArray EquipmentNames { … … 164 164 } 165 165 public GeneralizedQuadraticAssignmentProblem() 166 : base(new GQAP Evaluator(), new RandomSolutionCreator()) {166 : base(new GQAPAdditivePenaltyEvaluator(), new RandomSolutionCreator()) { 167 167 Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", WeightsDescription, new DoubleMatrix(), false)); 168 168 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", DistancesDescription, new DoubleMatrix(), false)); 169 169 Parameters.Add(new ValueParameter<DoubleMatrix>("InstallationCosts", InstallationCostsDescription, new DoubleMatrix(), false)); 170 170 Parameters.Add(new FixedValueParameter<DoubleValue>("TransportationCosts", TransportationCostsDescription, new DoubleValue(1))); 171 Parameters.Add(new FixedValueParameter<DoubleValue>(" OverbookedCapacityPenalty", OverbookedCapacityPenaltyDescription, new DoubleValue(100000)));171 Parameters.Add(new FixedValueParameter<DoubleValue>("ExpectedRandomQuality", ExpectedRandomQualityDescription, new DoubleValue(0), true)); 172 172 Parameters.Add(new ValueParameter<DoubleArray>("Demands", DemandsDescription, new DoubleArray(), false)); 173 173 Parameters.Add(new ValueParameter<DoubleArray>("Capacities", CapacitiesDescription, new DoubleArray(), false)); … … 310 310 public void Load(DoubleArray demands, DoubleArray capacities, 311 311 DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 312 DoubleValue transportationCosts , DoubleValue overbookedCapacityPenalty = null) {312 DoubleValue transportationCosts) { 313 313 if (weights == null || weights.Rows == 0) 314 314 throw new System.IO.InvalidDataException( … … 316 316 if (weights.Rows != weights.Columns) 317 317 throw new System.IO.InvalidDataException( 318 @"The weights matrix of the given instance contains an unequal number of rows319 an d columns.");318 @"The weights matrix of the given instance contains 319 an unequal number of rows and columns."); 320 320 Weights = weights; 321 321 … … 325 325 if (distances.Rows != distances.Columns) 326 326 throw new System.IO.InvalidDataException( 327 @"The distances matrix of the given instance contains an unequal number of rows328 an d columns.");327 @"The distances matrix of the given instance contains 328 an unequal number of rows and columns."); 329 329 Distances = distances; 330 330 … … 335 335 || installationCosts.Columns != distances.Columns) 336 336 throw new System.IO.InvalidDataException( 337 @"The installation costs matrix of the given instance contains different number 338 of rows than given in the weights matrix and a different number of columns than 337 @"The installation costs matrix of the given instance 338 contains different number of rows than given in the 339 weights matrix and a different number of columns than 339 340 given in the distances matrix."); 340 341 InstallationCosts = installationCosts; … … 345 346 if (capacities.Length != distances.Rows) 346 347 throw new System.IO.InvalidDataException( 347 @"The given instance contains a different number of capacities than rows given in348 the distances matrix.");348 @"The given instance contains a different number of 349 capacities than rows given in the distances matrix."); 349 350 Capacities = capacities; 350 351 … … 354 355 if (demands.Length != weights.Rows) 355 356 throw new System.IO.InvalidDataException( 356 @"The given instance contains a different number of demands than rows given in357 the weights matrix.");357 @"The given instance contains a different number of 358 demands than rows given in the weights matrix."); 358 359 Demands = demands; 359 360 … … 361 362 throw new System.IO.InvalidDataException( 362 363 @"The given instance does not contain transportation costs."); 363 TransportationCosts.Value = transportationCosts.Value; 364 365 if (overbookedCapacityPenalty != null) 366 OverbookedCapacityPenalty.Value = overbookedCapacityPenalty.Value; 364 TransportationCosts = transportationCosts.Value; 367 365 368 366 BestKnownQuality = null; 369 367 BestKnownSolution = null; 370 368 BestKnownSolutions = null; 371 } 372 369 CalculateExpectedRandomQuality(); 370 } 371 372 private void CalculateExpectedRandomQuality() { 373 if (IsConfigurationValid()) { 374 double[] avgDistances = new double[Capacities.Length]; 375 for (int i = 0; i < Capacities.Length; i++) { 376 for (int j = 0; j < Capacities.Length; j++) 377 avgDistances[i] += Distances[i, j]; 378 avgDistances[i] /= Capacities.Length; 379 } 380 double[] avgWeight = new double[Demands.Length]; 381 for (int i = 0; i < Demands.Length; i++) { 382 for (int j = 0; j < Demands.Length; j++) 383 avgWeight[i] += Weights[i, j]; 384 avgWeight[i] /= Demands.Length; 385 } 386 double avgCosts = InstallationCosts.Average(); 387 double quality = 0; 388 for (int i = 0; i < Demands.Length; i++) { 389 double equipmentInfluence = 0; 390 for (int j = 0; j < Capacities.Length; j++) 391 equipmentInfluence += avgWeight[i] * avgDistances[j]; 392 quality += equipmentInfluence * Demands.Length / (double)Capacities.Length; 393 } 394 quality *= TransportationCosts; 395 quality += avgCosts * Demands.Length; 396 397 ExpectedRandomQuality = quality; 398 } 399 } 373 400 private void EvaluateAndLoadAssignment(int[] vector) { 374 401 if (vector == null || vector.Length == 0) return; … … 382 409 } 383 410 double flowDistanceQuality, installationQuality, overbookedCapacity; 384 GQAPEvaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities,411 Evaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities, 385 412 out flowDistanceQuality, out installationQuality, out overbookedCapacity); 386 double quality = GQAPEvaluator.GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts.Value, OverbookedCapacityPenalty.Value);413 double quality = Evaluator.GetFitness(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts, ExpectedRandomQuality); 387 414 BestKnownSolution = new GQAPAssignment((IntegerVector)assignment.Clone(), new DoubleValue(quality), 388 415 new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), 389 416 new DoubleValue(overbookedCapacity), EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, 390 Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);417 Demands, Capacities, new DoubleValue(TransportationCosts), new DoubleValue(ExpectedRandomQuality), Evaluator); 391 418 BestKnownQuality = new DoubleValue(quality); 392 BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);419 BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, new DoubleValue(TransportationCosts), new DoubleValue(ExpectedRandomQuality), Evaluator); 393 420 BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity))); 394 421 } … … 403 430 base.OnEvaluatorChanged(); 404 431 Parameterize(); 432 if (BestKnownSolution != null) EvaluateAndLoadAssignment(BestKnownSolution.Assignment); 405 433 Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged); 406 434 } … … 436 464 Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator); 437 465 Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>()); 466 Operators.Add(new ScaledQualityDifferenceAnalyzer()); 438 467 Parameterize(); 439 468 } … … 445 474 foreach (var op in operators.OfType<IAssignmentAwareGQAPOperator>()) { 446 475 op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 447 } 448 foreach (var op in operators.OfType<IAssignmentsAwareGQAPOperator>()) { 449 op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 476 op.AssignmentParameter.Hidden = true; 450 477 } 451 478 foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) { 452 479 op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 480 op.BestKnownQualityParameter.Hidden = true; 453 481 } 454 482 foreach (var op in operators.OfType<IBestKnownSolutionAwareGQAPOperator>()) { 455 483 op.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 484 op.BestKnownSolutionParameter.Hidden = true; 456 485 } 457 486 foreach (var op in operators.OfType<IBestKnownSolutionsAwareGQAPOperator>()) { 458 487 op.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name; 488 op.BestKnownSolutionsParameter.Hidden = true; 459 489 } 460 490 foreach (var op in operators.OfType<ICapacitiesAwareGQAPOperator>()) { 461 491 op.CapacitiesParameter.ActualName = CapacitiesParameter.Name; 492 op.CapacitiesParameter.Hidden = true; 462 493 } 463 494 foreach (var op in operators.OfType<IDemandsAwareGQAPOperator>()) { 464 495 op.DemandsParameter.ActualName = DemandsParameter.Name; 496 op.DemandsParameter.Hidden = true; 465 497 } 466 498 foreach (var op in operators.OfType<IDistancesAwareGQAPOperator>()) { 467 499 op.DistancesParameter.ActualName = DistancesParameter.Name; 500 op.DistancesParameter.Hidden = true; 468 501 } 469 502 foreach (var op in operators.OfType<IEquipmentNamesAwareGQAPOperator>()) { 470 503 op.EquipmentNamesParameter.ActualName = EquipmentNamesParameter.Name; 504 op.EquipmentNamesParameter.Hidden = true; 471 505 } 472 506 foreach (var op in operators.OfType<IGQAPCrossover>()) { 473 507 op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 508 op.ParentsParameter.Hidden = true; 474 509 op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 510 op.ChildParameter.Hidden = true; 475 511 } 476 512 foreach (var op in operators.OfType<IInstallationCostsAwareGQAPOperator>()) { 477 513 op.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name; 514 op.InstallationCostsParameter.Hidden = true; 478 515 } 479 516 foreach (var op in operators.OfType<ILocationNamesAwareGQAPOperator>()) { 480 517 op.LocationNamesParameter.ActualName = LocationNamesParameter.Name; 518 op.LocationNamesParameter.Hidden = true; 481 519 } 482 520 var moveEvaluator = operators.OfType<IGQAPMoveEvaluator>().FirstOrDefault(); … … 484 522 if (moveEvaluator != null) { 485 523 op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName; 524 op.MoveQualityParameter.Hidden = true; 486 525 op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName; 526 op.MoveFlowDistanceQualityParameter.Hidden = true; 487 527 op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName; 528 op.MoveInstallationQualityParameter.Hidden = true; 488 529 op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName; 530 op.MoveOverbookedCapacityParameter.Hidden = true; 489 531 } 490 532 } … … 492 534 if (moveEvaluator != null) { 493 535 op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName; 536 op.MoveQualityParameter.Hidden = true; 494 537 op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName; 538 op.MoveFlowDistanceQualityParameter.Hidden = true; 495 539 op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName; 540 op.MoveInstallationQualityParameter.Hidden = true; 496 541 op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName; 542 op.MoveOverbookedCapacityParameter.Hidden = true; 497 543 } 498 544 op.MaximizationParameter.ActualName = MaximizationParameter.Name; 499 } 500 foreach (var op in operators.OfType<IOverbookedCapacityPenaltyAwareGQAPOperator>()) { 501 op.OverbookedCapacityPenaltyParameter.ActualName = OverbookedCapacityPenaltyParameter.Name; 545 op.MaximizationParameter.Hidden = true; 546 } 547 foreach (var op in operators.OfType<IExpectedRandomQualityAwareGQAPOperator>()) { 548 op.ExpectedRandomQualityParameter.ActualName = ExpectedRandomQualityParameter.Name; 549 op.ExpectedRandomQualityParameter.Hidden = true; 502 550 } 503 551 foreach (var op in operators.OfType<IQualitiesAwareGQAPOperator>()) { 504 552 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 553 op.QualityParameter.Hidden = true; 505 554 op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName; 555 op.FlowDistanceQualityParameter.Hidden = true; 506 556 op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName; 557 op.InstallationQualityParameter.Hidden = true; 507 558 op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName; 559 op.OverbookedCapacityParameter.Hidden = true; 508 560 op.MaximizationParameter.ActualName = MaximizationParameter.Name; 561 op.MaximizationParameter.Hidden = true; 509 562 } 510 563 foreach (var op in operators.OfType<IQualityAwareGQAPOperator>()) { 511 564 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 565 op.QualityParameter.Hidden = true; 512 566 op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName; 567 op.FlowDistanceQualityParameter.Hidden = true; 513 568 op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName; 569 op.InstallationQualityParameter.Hidden = true; 514 570 op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName; 571 op.OverbookedCapacityParameter.Hidden = true; 515 572 op.MaximizationParameter.ActualName = MaximizationParameter.Name; 573 op.MaximizationParameter.Hidden = true; 516 574 } 517 575 foreach (var op in operators.OfType<ITransportationCostsAwareGQAPOperator>()) { 518 576 op.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name; 577 op.TransportationCostsParameter.Hidden = true; 519 578 } 520 579 foreach (var op in operators.OfType<IWeightsAwareGQAPOperator>()) { 521 580 op.WeightsParameter.ActualName = WeightsParameter.Name; 581 op.WeightsParameter.Hidden = true; 582 } 583 foreach (var op in operators.OfType<IEvaluatorAwareGQAPOperator>()) { 584 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 585 op.EvaluatorParameter.Hidden = true; 522 586 } 523 587 524 588 foreach (var op in operators.OfType<IIntegerVectorCrossover>()) { 525 589 op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 590 op.ParentsParameter.Hidden = true; 526 591 op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 592 op.ChildParameter.Hidden = true; 527 593 } 528 594 foreach (var op in operators.OfType<IIntegerVectorManipulator>()) { 529 595 op.IntegerVectorParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 596 op.IntegerVectorParameter.Hidden = true; 597 } 598 599 foreach (var op in operators.OfType<ScaledQualityDifferenceAnalyzer>()) { 600 op.MinimumQualityParameter.ActualName = BestKnownQualityParameter.Name; 601 op.MinimumQualityParameter.Hidden = true; 602 op.MaximumQualityParameter.ActualName = ExpectedRandomQualityParameter.Name; 603 op.MaximumQualityParameter.Hidden = true; 604 op.QualityParameter.ActualName = "BestQuality"; 605 op.QualityParameter.Hidden = true; 530 606 } 531 607 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.csproj
r7813 r7970 105 105 <Compile Include="Analyzers\GQAPPopulationDiversityAnalyzer.cs" /> 106 106 <Compile Include="Analyzers\GQAPSolutionArchiveAnalyzer.cs" /> 107 <Compile Include="Evaluators\GQAPPenaltyLevelEvaluator.cs" /> 108 <Compile Include="Evaluators\GQAPEvaluator.cs" /> 107 109 <Compile Include="Evaluators\GQAPNMoveEvaluator.cs" /> 108 110 <Compile Include="GQAPAssignment.cs" /> 111 <Compile Include="Interfaces\IEvaluatorAwareGQAPOperator.cs" /> 109 112 <Compile Include="Operators\Crossovers\CordeauCrossover.cs" /> 110 113 <Compile Include="SolutionCreators\SlackMinimizationSolutionCreator.cs" /> … … 115 118 <Compile Include="SolutionCreators\RandomSolutionCreator.cs" /> 116 119 <None Include="Plugin.cs.frame" /> 117 <Compile Include="Evaluators\GQAP Evaluator.cs" />120 <Compile Include="Evaluators\GQAPAdditivePenaltyEvaluator.cs" /> 118 121 <Compile Include="GeneralizedQuadraticAssignmentProblem.cs" /> 119 122 <Compile Include="GQAPAssignmentArchive.cs" /> … … 130 133 <Compile Include="Interfaces\IGQAPEvaluator.cs" /> 131 134 <Compile Include="Interfaces\IQualityAwareGQAPOperator.cs" /> 132 <Compile Include="Interfaces\I OverbookedCapacityPenaltyAwareGQAPOperator.cs" />135 <Compile Include="Interfaces\IExpectedRandomQualityAwareGQAPOperator.cs" /> 133 136 <Compile Include="Interfaces\ITransportationCostsAwareGQAPOperator.cs" /> 134 137 <Compile Include="Interfaces\IInstallationCostsAwareGQAPOperator.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/IGQAPEvaluator.cs
r7419 r7970 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 24 25 using HeuristicLab.Optimization; 25 26 … … 30 31 ILookupParameter<DoubleValue> InstallationQualityParameter { get; } 31 32 ILookupParameter<DoubleValue> OverbookedCapacityParameter { get; } 33 34 double Evaluate(IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, 35 DoubleMatrix installCosts, DoubleArray demands, DoubleArray capacities, 36 double transportationCosts, double expectedRandomQuality); 37 38 void Evaluate(IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, 39 DoubleMatrix installCosts, DoubleArray demands, DoubleArray capacities, 40 out double flowDistanceQuality, out double installationQuality, 41 out double overbookedCapacity); 42 43 double EvaluateOverbooking(DoubleArray slack, DoubleArray capacities); 44 45 double GetFitness(double flowDistanceQuality, double installationQuality, 46 double overbookedCapacity, double transportationCosts, 47 double expectedRandomQuality); 32 48 } 33 49 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/CordeauCrossover.cs
r7523 r7970 34 34 IQualitiesAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, 35 35 IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 36 I OverbookedCapacityPenaltyAwareGQAPOperator {36 IExpectedRandomQualityAwareGQAPOperator { 37 37 38 38 public ILookupParameter<BoolValue> MaximizationParameter { … … 69 69 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 70 70 } 71 public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter { 72 get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; } 71 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 72 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 73 } 74 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 75 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 73 76 } 74 77 … … 91 94 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 92 95 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 93 Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription)); 96 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 97 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator used to evaluate solutions.")); 94 98 } 95 99 … … 103 107 DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 104 108 DoubleArray demands, DoubleArray capacities, 105 DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty) {109 double transportationCosts, double expectedRandomQuality, IGQAPEvaluator evaluator) { 106 110 var mediana = Inizialize(distances); 107 111 int m = capacities.Length; … … 158 162 } 159 163 if (!nofound) { 160 double sonQual = GQAPEvaluator.Evaluate(son, weights, distances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);164 double sonQual = evaluator.Evaluate(son, weights, distances, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality); 161 165 if (sonQual < fbest) { 162 166 fbest = sonQual; … … 197 201 onefound = true; 198 202 } else { 199 double sonQual = GQAPEvaluator.Evaluate(son, weights, distances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);203 double sonQual = evaluator.Evaluate(son, weights, distances, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality); 200 204 if (sonQual < fbest) { 201 205 fbest = sonQual; … … 227 231 WeightsParameter.ActualValue, DistancesParameter.ActualValue, InstallationCostsParameter.ActualValue, 228 232 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue, 229 TransportationCostsParameter.ActualValue, OverbookedCapacityPenaltyParameter.ActualValue); 233 TransportationCostsParameter.ActualValue.Value, ExpectedRandomQualityParameter.ActualValue.Value, 234 EvaluatorParameter.ActualValue); 230 235 } 231 236 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPPathRelinking.cs
r7813 r7970 37 37 public class GQAPPathRelinking : GQAPCrossover, IQualitiesAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, 38 38 IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 39 I OverbookedCapacityPenaltyAwareGQAPOperator {39 IExpectedRandomQualityAwareGQAPOperator, IEvaluatorAwareGQAPOperator { 40 40 41 41 public ILookupParameter<BoolValue> MaximizationParameter { … … 72 72 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 73 73 } 74 public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter { 75 get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; } 74 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 75 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 76 } 77 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 78 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 76 79 } 77 80 … … 96 99 Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription)); 97 100 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 98 Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription)); 101 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 102 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 99 103 Parameters.Add(new ValueParameter<PercentValue>("CandidateSizeFactor", "(η) Determines the size of the set of feasible moves in each path-relinking step relative to the maximum size. A value of 50% means that only half of all possible moves are considered each step.", new PercentValue(0.5))); 100 104 } … … 107 111 ItemArray<DoubleValue> flowDistanceQualities, ItemArray<DoubleValue> installationQualities, ItemArray<DoubleValue> overbookedCapacities, 108 112 DoubleArray demands, DoubleArray capacities, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 109 DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty, DoubleValue candidateSizeFactor) {113 DoubleValue transportationCosts, DoubleValue expectedRandomQuality, DoubleValue candidateSizeFactor, IGQAPEvaluator evaluator) { 110 114 if (random == null) throw new ArgumentNullException("random", "No IRandom provider is given."); 111 115 if (parents == null || !parents.Any()) throw new ArgumentException("No parents given for path relinking.", "parents"); … … 145 149 146 150 double currentFDQ, currentIQ, currentOC; 147 GQAPEvaluator.Evaluate(pi2, weights, distances, installationCosts, demands, capacities,151 evaluator.Evaluate(pi2, weights, distances, installationCosts, demands, capacities, 148 152 out currentFDQ, out currentIQ, out currentOC); 149 153 150 154 if (currentOC <= 0.0) { 151 var quality = GQAPEvaluator.GetCombinedQuality(currentFDQ, currentIQ, currentOC,152 transportationCosts.Value, overbookedCapacityPenalty.Value);155 var quality = evaluator.GetFitness(currentFDQ, currentIQ, currentOC, 156 transportationCosts.Value, expectedRandomQuality.Value); 153 157 var solution = new GQAPSolution(pi2, new DoubleValue(quality), new DoubleValue(currentFDQ), 154 158 new DoubleValue(currentIQ), new DoubleValue(currentOC)); … … 211 215 CapacitiesParameter.ActualValue, WeightsParameter.ActualValue, DistancesParameter.ActualValue, 212 216 InstallationCostsParameter.ActualValue, TransportationCostsParameter.ActualValue, 213 OverbookedCapacityPenaltyParameter.ActualValue, CandidateSizeFactorParameter.Value); 217 ExpectedRandomQualityParameter.ActualValue, CandidateSizeFactorParameter.Value, 218 EvaluatorParameter.ActualValue); 214 219 } 215 220 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs
r7523 r7970 37 37 public class ApproximateLocalSearch : SingleSuccessorOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, 38 38 IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, 39 ITransportationCostsAwareGQAPOperator, IOverbookedCapacityPenaltyAwareGQAPOperator, 40 IAssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, IStochasticOperator { 39 ITransportationCostsAwareGQAPOperator, IExpectedRandomQualityAwareGQAPOperator, 40 IAssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, 41 IEvaluatorAwareGQAPOperator, IStochasticOperator { 41 42 public IProblem Problem { get; set; } 42 43 public Type ProblemType { … … 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<IntegerVector> AssignmentParameter { … … 100 101 public ILookupParameter<ResultCollection> ResultsParameter { 101 102 get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; } 103 } 104 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 105 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 102 106 } 103 107 … … 113 117 Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription)); 114 118 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 115 Parameters.Add(new ValueLookupParameter<DoubleValue>(" OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));119 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 116 120 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 117 121 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); … … 126 130 Parameters.Add(new ValueLookupParameter<PercentValue>("OneMoveProbability", "The probability for performing a 1-move, which is the opposite of performing a 2-move.", new PercentValue(.5))); 127 131 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection that stores the results.")); 132 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 128 133 } 129 134 … … 157 162 IntValue maxCLS, IntValue maximumIterations, 158 163 DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, 159 DoubleValue transportationCosts, DoubleValue overbookedCapacityPenalty, PercentValue oneMoveProbability) { 164 DoubleValue transportationCosts, DoubleValue expectedRandomQuality, PercentValue oneMoveProbability, 165 IGQAPEvaluator evaluator) { 160 166 161 167 while (true) { … … 171 177 double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity; 172 178 GQAPNMoveEvaluator.Evaluate(move, assignment, weights, distances, installationCosts, 173 demands, capacities, out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity);174 double moveQuality = GQAPEvaluator.GetCombinedQuality(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity,175 transportationCosts.Value, overbookedCapacityPenalty.Value);179 demands, capacities, evaluator, out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity); 180 double moveQuality = evaluator.GetFitness(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity, 181 transportationCosts.Value, expectedRandomQuality.Value); 176 182 177 183 if (moveOverbookedCapacity <= 0.0 && moveQuality < 0.0) { … … 216 222 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue, 217 223 TransportationCostsParameter.ActualValue, 218 OverbookedCapacityPenaltyParameter.ActualValue, 219 OneMoveProbabilityParameter.ActualValue); 224 ExpectedRandomQualityParameter.ActualValue, 225 OneMoveProbabilityParameter.ActualValue, 226 EvaluatorParameter.ActualValue); 220 227 return base.Apply(); 221 228 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GreedyRandomizedSolutionCreator.cs
r7833 r7970 35 35 [Item("GreedyRandomizedSolutionCreator", "Creates a solution according to the procedure described in Mateus, G., Resende, M., and Silva, R. 2011. GRASP with path-relinking for the generalized quadratic assignment problem. Journal of Heuristics 17, Springer Netherlands, pp. 527-565.")] 36 36 [StorableClass] 37 public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator { 37 public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 38 39 39 40 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 42 43 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 43 44 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 } 46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 44 48 } 45 49 … … 52 56 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumTries", "The maximum number of tries to create a feasible solution after which an exception is thrown. If it is set to 0 or a negative value there will be an infinite number of attempts.", new IntValue(100000))); 53 57 Parameters.Add(new ValueLookupParameter<BoolValue>("CreateMostFeasibleSolution", "If this is set to true the operator will always succeed, and outputs the solution with the least violation instead of throwing an exception.", new BoolValue(false))); 58 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 54 59 } 55 60 … … 58 63 } 59 64 60 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, int maximumTries, bool createMostFeasibleSolution, CancellationToken cancelToken) { 65 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, 66 IGQAPEvaluator evaluator, 67 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancelToken) { 61 68 int tries = 0; 62 69 var assignment = new Dictionary<int, int>(demands.Length); … … 118 125 slack[l] -= demands[f]; 119 126 } 120 double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);127 double violation = evaluator.EvaluateOverbooking(slack, capacities); 121 128 if (violation < minViolation) { 122 129 bestAssignment = assignment; … … 134 141 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 135 142 return CreateSolution(random, demands, capacities, 143 EvaluatorParameter.ActualValue, 136 144 MaximumTriesParameter.ActualValue.Value, 137 145 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs
r7813 r7970 35 35 [Item("RandomButFeasibleSolutionCreator", "Creates a random, but feasible solution to the Generalized Quadratic Assignment Problem.")] 36 36 [StorableClass] 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator { 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 38 39 39 40 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 42 43 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 43 44 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 } 46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 44 48 } 45 49 … … 51 55 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumTries", "The maximum number of tries to create a feasible solution after which an exception is thrown. If it is set to 0 or a negative value there will be an infinite number of attempts.", new IntValue(100000))); 52 56 Parameters.Add(new ValueLookupParameter<BoolValue>("CreateMostFeasibleSolution", "If this is set to true the operator will always succeed, and outputs the solution with the least violation instead of throwing an exception.", new BoolValue(false))); 57 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 53 58 } 54 59 … … 57 62 } 58 63 59 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) { 64 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, 65 DoubleArray capacities, IGQAPEvaluator evaluator, 66 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) { 60 67 IntegerVector result = null; 61 68 bool isFeasible = false; … … 80 87 slack[assignment[equipment]] -= demands[equipment]; 81 88 } 82 double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);89 double violation = evaluator.EvaluateOverbooking(slack, capacities); 83 90 isFeasible = violation == 0; 84 91 if (isFeasible || violation < minViolation) { … … 92 99 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 93 100 return CreateSolution(random, demands, capacities, 101 EvaluatorParameter.ActualValue, 94 102 MaximumTriesParameter.ActualValue.Value, 95 103 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/SlackMinimizationSolutionCreator.cs
r7813 r7970 35 35 [Item("SlackMinimizationSolutionCreator", "A heuristic that creates a solution to the Generalized Quadratic Assignment Problem by minimizing the amount of slack.")] 36 36 [StorableClass] 37 public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator { 37 public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 38 39 39 40 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 49 50 get { return (IValueLookupParameter<IntValue>)Parameters["RandomWalkLength"]; } 50 51 } 52 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 53 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 54 } 51 55 52 56 [StorableConstructor] … … 59 63 Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3))); 60 64 Parameters.Add(new ValueLookupParameter<IntValue>("RandomWalkLength", "The length of the random walk in the feasible region that is used to diversify the found assignments.", new IntValue(10))); 65 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 61 66 } 62 67 … … 75 80 } 76 81 77 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) { 82 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, 83 DoubleArray capacities, IGQAPEvaluator evaluator, 84 int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) { 78 85 IntegerVector result = null; 79 86 bool isFeasible = false; … … 118 125 } 119 126 } else RandomFeasibleWalk(random, assignment, demands, slack, randomWalkLength); 120 double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);127 double violation = evaluator.EvaluateOverbooking(slack, capacities); 121 128 isFeasible = violation == 0; 122 129 if (isFeasible || violation < minViolation) { … … 177 184 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 178 185 return CreateSolution(random, demands, capacities, 186 EvaluatorParameter.ActualValue, 179 187 DepthParameter.ActualValue.Value, 180 188 MaximumTriesParameter.ActualValue.Value, -
branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs
r7548 r7970 46 46 CordeauCrossover.Apply(random, gqap.Maximization, 47 47 parent1, 48 new DoubleValue( GQAPEvaluator.Evaluate(parent1, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.OverbookedCapacityPenalty)),48 new DoubleValue(gqap.Evaluator.Evaluate(parent1, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)), 49 49 parent2, 50 new DoubleValue( GQAPEvaluator.Evaluate(parent2, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.OverbookedCapacityPenalty)),51 gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap. OverbookedCapacityPenalty);50 new DoubleValue(gqap.Evaluator.Evaluate(parent2, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)), 51 gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality, gqap.Evaluator); 52 52 } catch { 53 53 Assert.Fail("Error during crossover"); -
branches/GeneralizedQAP/UnitTests/GQAPNMoveEvaluatorTest.cs
r7412 r7970 39 39 private static DoubleMatrix installationCosts; 40 40 private static DoubleArray demands, capacities; 41 private static DoubleValue transportationCosts, overbookedCapacityPenalty;41 private static double transportationCosts, overbookedCapacityPenalty; 42 42 private static IntegerVector assignment; 43 43 private static MersenneTwister random; … … 107 107 nonZeroDiagonalWeights[index, index] = random.Next(1, Equipments * 100); 108 108 109 transportationCosts = new DoubleValue(random.NextDouble() * 10);110 overbookedCapacityPenalty = new DoubleValue(1000 * random.NextDouble() + 100);109 transportationCosts = random.NextDouble() * 10; 110 overbookedCapacityPenalty = 1000 * random.NextDouble() + 100; 111 111 assignment = new IntegerVector(Equipments, random, 0, Locations); 112 112 } … … 119 119 [TestMethod()] 120 120 public void EvaluateTest() { 121 var evaluator = new GQAPAdditivePenaltyEvaluator(); 121 122 for (int i = 0; i < 500; i++) { 122 123 NMove currentMove = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, 3, capacities); 123 124 IntegerVector prevAssignment = (IntegerVector)assignment.Clone(); 124 125 NMoveMaker.Apply(assignment, currentMove); 125 double before = GQAPEvaluator.Evaluate(prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);126 double after = GQAPEvaluator.Evaluate(assignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);127 double moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);126 double before = evaluator.Evaluate(prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 127 double after = evaluator.Evaluate(assignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 128 double moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator); 128 129 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on symmetric matrices: " + Environment.NewLine 129 130 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 130 131 131 before = GQAPEvaluator.Evaluate(prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);132 after = GQAPEvaluator.Evaluate(assignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);133 moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);132 before = evaluator.Evaluate(prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 133 after = evaluator.Evaluate(assignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 134 moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator); 134 135 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on asymmetric matrices: " + Environment.NewLine 135 136 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 136 137 137 before = GQAPEvaluator.Evaluate(prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);138 after = GQAPEvaluator.Evaluate(assignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);139 moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);138 before = evaluator.Evaluate(prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0); 139 after = evaluator.Evaluate(assignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0); 140 moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator); 140 141 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on non-zero diagonal matrices: " + Environment.NewLine 141 142 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); -
branches/GeneralizedQAP/UnitTests/UnitTests.csproj
r7593 r7970 81 81 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 82 82 <SpecificVersion>False</SpecificVersion> 83 <Private> False</Private>83 <Private>True</Private> 84 84 </Reference> 85 85 <Reference Include="HeuristicLab.Problems.Instances.CordeauGQAP-3.3"> 86 86 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances.CordeauGQAP-3.3.dll</HintPath> 87 87 <SpecificVersion>False</SpecificVersion> 88 <Private> False</Private>88 <Private>True</Private> 89 89 </Reference> 90 90 <Reference Include="HeuristicLab.Random-3.3">
Note: See TracChangeset
for help on using the changeset viewer.