Changeset 15504
- Timestamp:
- 12/10/17 22:11:10 (5 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 4 added
- 17 deleted
- 44 edited
- 18 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Algorithms.GRASP/3.3/Plugin.cs.frame
r15490 r15504 35 35 [PluginDependency("HeuristicLab.Parameters", "3.3")] 36 36 [PluginDependency("HeuristicLab.Persistence", "3.3")] 37 [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")]38 37 [PluginDependency("HeuristicLab.Random", "3.3")] 39 38 [PluginDependency("HeuristicLab.Selection", "3.3")] -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentArchiveView.Designer.cs
r7438 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentArchiveView.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 85 85 if (Content == null) return; 86 86 foreach (var solution in Content.Solutions) { 87 if (solution. OverbookedCapacity.Value<= 0.0) {88 paretoFrontChart.Series[0].Points.AddXY(solution. FlowDistanceQuality.Value, solution.InstallationQuality.Value);87 if (solution.Evaluation.ExcessDemand <= 0.0) { 88 paretoFrontChart.Series[0].Points.AddXY(solution.Evaluation.FlowCosts, solution.Evaluation.InstallationCosts); 89 89 paretoFrontChart.Series[0].Points.Last().Tag = solution; 90 90 } … … 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.ExpectedRandomQuality, Content.Evaluator);103 var assignment = new GQAPAssignment(solution.Assignment, Content.ProblemInstance, solution.Evaluation); 104 104 105 105 var view = MainFormManager.MainForm.ShowContent(assignment); -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.Designer.cs
r7471 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/GQAPAssignmentView.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 28 28 using HeuristicLab.Common.Resources; 29 29 using HeuristicLab.Core.Views; 30 using HeuristicLab.Data;31 30 using HeuristicLab.Encodings.IntegerVectorEncoding; 32 31 using HeuristicLab.MainForm; … … 131 130 qualityLabel.Text = "-"; 132 131 } else { 133 qualityLabel.Text = Content. Quality.ToString();132 qualityLabel.Text = Content.ProblemInstance.ToSingleObjective(Content.Evaluation).ToString(); 134 133 } 135 134 } … … 139 138 if (InvokeRequired) Invoke((Action)UpdateFlowDistanceQuality); 140 139 else { 141 if (Content == null || Content. FlowDistanceQuality== null) {140 if (Content == null || Content.Evaluation == null) { 142 141 flowDistanceQualityLabel.Text = "-"; 143 142 } else { 144 flowDistanceQualityLabel.Text = Content. FlowDistanceQuality.ToString();143 flowDistanceQualityLabel.Text = Content.Evaluation.FlowCosts.ToString(); 145 144 } 146 145 } … … 150 149 if (InvokeRequired) Invoke((Action)UpdateInstallationQuality); 151 150 else { 152 if (Content == null || Content. InstallationQuality== null) {151 if (Content == null || Content.Evaluation == null) { 153 152 installationQualityLabel.Text = "-"; 154 153 } else { 155 installationQualityLabel.Text = Content. InstallationQuality.ToString();154 installationQualityLabel.Text = Content.Evaluation.InstallationCosts.ToString(); 156 155 } 157 156 } … … 161 160 if (InvokeRequired) Invoke((Action)UpdateOverbookedCapacity); 162 161 else { 163 if (Content == null || Content. OverbookedCapacity== null) {162 if (Content == null || Content.Evaluation == null) { 164 163 overbookedCapacityLabel.Text = "-"; 165 164 } else { 166 overbookedCapacityLabel.Text = Content. OverbookedCapacity.ToString();165 overbookedCapacityLabel.Text = Content.Evaluation.ExcessDemand.ToString(); 167 166 } 168 167 } … … 179 178 if (!locationNodes.ContainsKey(assignment[i])) { 180 179 string locationName = assignment[i].ToString(); 181 if (Content. LocationNames != null && Content.LocationNames.Length > assignment[i])182 locationName = Content. LocationNames[assignment[i]];180 if (Content.ProblemInstance.LocationNames != null && Content.ProblemInstance.LocationNames.Length > assignment[i]) 181 locationName = Content.ProblemInstance.LocationNames[assignment[i]]; 183 182 locationNodes.Add(assignment[i], new LocationNode(assignment[i], locationName)); 184 183 } 185 184 string equipmentName = i.ToString(); 186 if (Content. EquipmentNames != null && Content.EquipmentNames.Length > i)187 equipmentName = Content. EquipmentNames[i];185 if (Content.ProblemInstance.EquipmentNames != null && Content.ProblemInstance.EquipmentNames.Length > i) 186 equipmentName = Content.ProblemInstance.EquipmentNames[i]; 188 187 locationNodes[assignment[i]].Nodes.Add(new EquipmentNode(i, equipmentName)); 189 188 } … … 205 204 foreach (var node in GetAllSubNodes(assignmentTreeView.Nodes).OfType<EquipmentNode>()) { 206 205 int location = Content.Assignment[node.Equipment]; 207 installationCosts[node] = Content. InstallationCosts[node.Equipment, location];206 installationCosts[node] = Content.ProblemInstance.InstallationCosts[node.Equipment, location]; 208 207 } 209 208 double max = installationCosts.Values.Max(); … … 224 223 int equipment = selectedNode.Equipment; 225 224 double rowSum = 0, colSum = 0; 226 for (int i = 0; i < Content. Weights.Columns; i++)227 if (i != equipment) rowSum += Content. Weights[equipment, i];228 for (int i = 0; i < Content. Weights.Rows; i++)229 if (i != equipment) colSum += Content. Weights[i, equipment];225 for (int i = 0; i < Content.ProblemInstance.Weights.Columns; i++) 226 if (i != equipment) rowSum += Content.ProblemInstance.Weights[equipment, i]; 227 for (int i = 0; i < Content.ProblemInstance.Weights.Rows; i++) 228 if (i != equipment) colSum += Content.ProblemInstance.Weights[i, equipment]; 230 229 231 230 var otherEquipments = GetAllSubNodes(assignmentTreeView.Nodes) … … 240 239 other.ForeColor = assignmentTreeView.ForeColor; 241 240 } else { 242 double rowInvProportion = rowSum == 0 ? 1.0 : (rowSum - Content. Weights[equipment, other.Equipment]) / rowSum;243 double colInvProportion = colSum == 0 ? 1.0 : (colSum - Content. Weights[other.Equipment, equipment]) / colSum;241 double rowInvProportion = rowSum == 0 ? 1.0 : (rowSum - Content.ProblemInstance.Weights[equipment, other.Equipment]) / rowSum; 242 double colInvProportion = colSum == 0 ? 1.0 : (colSum - Content.ProblemInstance.Weights[other.Equipment, equipment]) / colSum; 244 243 int colorComponent = (int)(255 * Math.Pow(Math.Min(rowInvProportion, colInvProportion), 2)); 245 244 other.BackColor = Color.FromArgb(colorComponent, 255, colorComponent); … … 258 257 rowSums[e] = 0; 259 258 colSums[e] = 0; 260 for (int i = 0; i < Content. Weights.Columns; i++) {261 if (!equipments.Contains(i)) rowSums[e] += Content. Weights[e, i];262 if (!equipments.Contains(i)) colSums[e] += Content. Weights[i, e];259 for (int i = 0; i < Content.ProblemInstance.Weights.Columns; i++) { 260 if (!equipments.Contains(i)) rowSums[e] += Content.ProblemInstance.Weights[e, i]; 261 if (!equipments.Contains(i)) colSums[e] += Content.ProblemInstance.Weights[i, e]; 263 262 } 264 263 } … … 272 271 other.ForeColor = assignmentTreeView.ForeColor; 273 272 } else { 274 double rowInvProportion = relevantEquipments.Min(x => rowSums[x] == 0 ? 1.0 : (rowSums[x] - Content. Weights[x, other.Equipment]) / rowSums[x]);275 double colInvProportion = relevantEquipments.Min(x => colSums[x] == 0 ? 1.0 : (colSums[x] - Content. Weights[other.Equipment, x]) / colSums[x]);273 double rowInvProportion = relevantEquipments.Min(x => rowSums[x] == 0 ? 1.0 : (rowSums[x] - Content.ProblemInstance.Weights[x, other.Equipment]) / rowSums[x]); 274 double colInvProportion = relevantEquipments.Min(x => colSums[x] == 0 ? 1.0 : (colSums[x] - Content.ProblemInstance.Weights[other.Equipment, x]) / colSums[x]); 276 275 int colorComponent = (int)(255 * Math.Pow(Math.Min(rowInvProportion, colInvProportion), 2)); 277 276 other.BackColor = Color.FromArgb(colorComponent, 255, colorComponent); … … 314 313 315 314 private void recalculateButton_Click(object sender, EventArgs e) { 316 double fdq, iq, oc; 317 Content.Evaluator.Evaluate(Content.Assignment, Content.Weights, 318 Content.Distances, Content.InstallationCosts, Content.Demands, 319 Content.Capacities, out fdq, out iq, out oc); 320 Content.FlowDistanceQuality = new DoubleValue(fdq); 321 Content.InstallationQuality = new DoubleValue(iq); 322 Content.OverbookedCapacity = new DoubleValue(oc); 323 Content.Quality = new DoubleValue( 324 Content.Evaluator.GetFitness(fdq, iq, oc, 325 Content.TransportationCosts.Value, Content.ExpectedRandomQuality.Value)); 315 Content.Evaluation = Content.ProblemInstance.Evaluate(Content.Assignment); 326 316 } 327 317 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/Properties/AssemblyInfo.cs.frame
r7345 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 1Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 [assembly: AssemblyCompany("HEAL")] 32 32 [assembly: AssemblyProduct("HeuristicLab")] 33 [assembly: AssemblyCopyright("(c) 2002-201 1HEAL")]33 [assembly: AssemblyCopyright("(c) 2002-2017 HEAL")] 34 34 [assembly: AssemblyTrademark("")] 35 35 [assembly: AssemblyCulture("")] … … 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 55 [assembly: AssemblyVersion("3.3.0.0")] 56 [assembly: AssemblyFileVersion("3.3. 6.$WCREV$")]56 [assembly: AssemblyFileVersion("3.3.14.$WCREV$")] -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/GQAPNMoveEvaluator.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; … … 25 27 using HeuristicLab.Encodings.IntegerVectorEncoding; 26 28 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization;28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 33 [Item("N-Move Evaluator", "Evaluates an N-Move.")] 33 34 [StorableClass] 34 public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator, IAssignmentAwareGQAPOperator, 35 IQualityAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 36 IExpectedRandomQualityAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, 37 IInstallationCostsAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, 38 IEvaluatorAwareGQAPOperator { 35 public class GQAPNMoveEvaluator : SingleSuccessorOperator, IGQAPNMoveEvaluator, 36 IQualityAwareGQAPOperator, IProblemInstanceAwareGQAPOperator { 39 37 40 38 #region Parameter Descriptions 41 39 public static readonly string MoveQualityDescription = "The quality of the move if it would be applied."; 42 public static readonly string MoveFlowDistanceQualityDescription = "The quality of the move regarding the flow-distance criteria."; 43 public static readonly string MoveInstallationQualityDescription = "The quality of the move regarding the installation costs."; 44 public static readonly string MoveOverbookedCapacityDescription = "The sum of the overbooked capacities of the move relative to the capacity of each location."; 40 public static readonly string MoveEvaluationDescription = "The results of evaluating the move."; 45 41 #endregion 46 42 47 43 #region Parameter Properties 48 ILookupParameter<BoolValue> IQualityAwareGQAPOperator.MaximizationParameter {49 get { return MaximizationParameter; }50 }51 ILookupParameter<BoolValue> IGQAPMoveEvaluator.MaximizationParameter {52 get { return MaximizationParameter; }53 }54 public ILookupParameter<BoolValue> MaximizationParameter {55 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }56 }57 44 public ILookupParameter<DoubleValue> MoveQualityParameter { 58 45 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 59 46 } 60 public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { 61 get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; } 62 } 63 public ILookupParameter<DoubleValue> MoveInstallationQualityParameter { 64 get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; } 65 } 66 public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { 67 get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; } 47 public ILookupParameter<Evaluation> MoveEvaluationParameter { 48 get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; } 68 49 } 69 50 public ILookupParameter<NMove> MoveParameter { … … 73 54 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } 74 55 } 75 ILookupParameter<DoubleValue> ISingleObjectiveMoveEvaluator.QualityParameter {76 get { return QualityParameter; }77 }78 ILookupParameter<DoubleValue> IQualityAwareGQAPOperator.QualityParameter {79 get { return QualityParameter; }80 }81 56 public ILookupParameter<DoubleValue> QualityParameter { 82 57 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 83 58 } 84 public ILookupParameter< DoubleValue> FlowDistanceQualityParameter {85 get { return (ILookupParameter< DoubleValue>)Parameters["FlowDistanceQuality"]; }59 public ILookupParameter<Evaluation> EvaluationParameter { 60 get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; } 86 61 } 87 public ILookupParameter<DoubleValue> InstallationQualityParameter { 88 get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; } 89 } 90 public ILookupParameter<DoubleValue> OverbookedCapacityParameter { 91 get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; } 92 } 93 public IValueLookupParameter<DoubleValue> TransportationCostsParameter { 94 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 95 } 96 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 97 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 98 } 99 public ILookupParameter<DoubleMatrix> WeightsParameter { 100 get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; } 101 } 102 public ILookupParameter<DoubleMatrix> DistancesParameter { 103 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 104 } 105 public ILookupParameter<DoubleMatrix> InstallationCostsParameter { 106 get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; } 107 } 108 public ILookupParameter<DoubleArray> DemandsParameter { 109 get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; } 110 } 111 public ILookupParameter<DoubleArray> CapacitiesParameter { 112 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 113 } 114 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 115 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 62 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 63 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 116 64 } 117 65 #endregion … … 124 72 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 125 73 Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription)); 126 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); 127 Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription)); 128 Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription)); 129 Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription)); 130 Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription)); 74 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "")); 75 Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription)); 131 76 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", MoveQualityDescription)); 132 Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", MoveFlowDistanceQualityDescription)); 133 Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", MoveInstallationQualityDescription)); 134 Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", MoveOverbookedCapacityDescription)); 135 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 136 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 137 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription)); 138 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription)); 139 Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription)); 140 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); 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.")); 77 Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", MoveEvaluationDescription)); 78 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 143 79 } 144 80 … … 147 83 } 148 84 149 public static double Evaluate(NMove move, IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 150 DoubleArray demands, DoubleArray capacities, double transportationCosts, double expectedRandomQuality, IGQAPEvaluator evaluator) { 151 double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity; 152 Evaluate(move, assignment, weights, distances, installationCosts, demands, capacities, evaluator, 153 out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity); 154 return evaluator.GetFitness(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity, 155 transportationCosts, expectedRandomQuality); 156 } 157 158 public static void Evaluate(NMove move, IntegerVector assignment, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 159 DoubleArray demands, DoubleArray capacities, IGQAPEvaluator evaluator, out double moveFlowDistanceQuality, out double moveInstallationQuality, out double moveOverbookedCapacity) { 160 moveFlowDistanceQuality = moveInstallationQuality = moveOverbookedCapacity = 0.0; 85 public static Evaluation Evaluate(NMove move, IntegerVector assignment, Evaluation evaluation, GQAPInstance problemInstance) { 161 86 int moves = move.N; 162 var slack = (DoubleArray)capacities.Clone(); 163 var oldSlack = (DoubleArray)slack.Clone(); 164 bool first = true; 87 var newEvaluation = new Evaluation() { 88 ExcessDemand = evaluation.ExcessDemand, 89 FlowCosts = evaluation.FlowCosts, 90 InstallationCosts = evaluation.InstallationCosts, 91 Slack = evaluation.Slack.ToArray() 92 }; 165 93 foreach (var kvp in move.NewAssignments) { 166 94 int equip = kvp.Key; 167 95 int newLoc = kvp.Value; 168 moveInstallationQuality -= installationCosts[equip, assignment[equip]]; 169 moveInstallationQuality += installationCosts[equip, newLoc]; 96 int oldLoc = assignment[equip]; 97 var equipDemand = problemInstance.Demands[equip]; 98 newEvaluation.InstallationCosts -= problemInstance.InstallationCosts[equip, oldLoc]; 99 newEvaluation.InstallationCosts += problemInstance.InstallationCosts[equip, newLoc]; 170 100 for (int j = 0; j < assignment.Length; j++) { 171 101 if (!move.NewAssignments.ContainsKey(j)) { 172 moveFlowDistanceQuality += weights[equip, j] * distances[newLoc, assignment[j]]; 173 moveFlowDistanceQuality -= weights[equip, j] * distances[assignment[equip], assignment[j]]; 174 moveFlowDistanceQuality += weights[j, equip] * distances[assignment[j], newLoc]; 175 moveFlowDistanceQuality -= weights[j, equip] * distances[assignment[j], assignment[equip]]; 176 if (first) { // only once for each untouched equipment deduct the demand from the capacity 177 slack[assignment[j]] -= demands[j]; 178 oldSlack[assignment[j]] -= demands[j]; 179 } 102 newEvaluation.FlowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, assignment[j]]; 103 newEvaluation.FlowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]]; 104 newEvaluation.FlowCosts += problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], newLoc]; 105 newEvaluation.FlowCosts -= problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], oldLoc]; 180 106 } else { 181 moveFlowDistanceQuality += weights[equip, j] * distances[newLoc, move.NewAssignments[j]];182 moveFlowDistanceQuality -= weights[equip, j] * distances[assignment[equip], assignment[j]];107 newEvaluation.FlowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, move.NewAssignments[j]]; 108 newEvaluation.FlowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]]; 183 109 } 184 110 } 185 first = false; 186 slack[newLoc] -= demands[equip]; 187 oldSlack[assignment[equip]] -= demands[equip]; 111 newEvaluation.Slack[oldLoc] += equipDemand; 112 if (newEvaluation.Slack[oldLoc] < equipDemand) 113 newEvaluation.ExcessDemand -= Math.Min(equipDemand, equipDemand - newEvaluation.Slack[oldLoc]); 114 newEvaluation.Slack[newLoc] -= equipDemand; 115 if (newEvaluation.Slack[newLoc] < 0) 116 newEvaluation.ExcessDemand += Math.Min(equipDemand, -newEvaluation.Slack[newLoc]); 188 117 } 189 118 190 moveOverbookedCapacity = evaluator.EvaluateOverbooking(slack, capacities) - evaluator.EvaluateOverbooking(oldSlack, capacities);119 return newEvaluation; 191 120 } 192 121 193 122 public override IOperation Apply() { 194 var evaluator = EvaluatorParameter.ActualValue; 195 double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity; 196 double quality = QualityParameter.ActualValue.Value; 197 double transportationCosts = TransportationCostsParameter.ActualValue.Value; 198 double expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue.Value; 123 var problemInstance = ProblemInstanceParameter.ActualValue; 124 var evaluation = EvaluationParameter.ActualValue; 199 125 200 double flowDistanceQuality = FlowDistanceQualityParameter.ActualValue.Value; 201 double installationQuality = InstallationQualityParameter.ActualValue.Value; 202 double overbookedCapacity = OverbookedCapacityParameter.ActualValue.Value; 126 var moveEvaluation = Evaluate(MoveParameter.ActualValue, 127 AssignmentParameter.ActualValue, 128 evaluation, 129 problemInstance); 203 130 204 Evaluate(MoveParameter.ActualValue, 205 AssignmentParameter.ActualValue, 206 WeightsParameter.ActualValue, DistancesParameter.ActualValue, 207 InstallationCostsParameter.ActualValue, 208 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue, 209 evaluator, 210 out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity); 211 212 MoveFlowDistanceQualityParameter.ActualValue = new DoubleValue(flowDistanceQuality + moveFlowDistanceQuality); 213 MoveInstallationQualityParameter.ActualValue = new DoubleValue(installationQuality + moveInstallationQuality); 214 MoveOverbookedCapacityParameter.ActualValue = new DoubleValue(overbookedCapacity + moveOverbookedCapacity); 215 216 MoveQualityParameter.ActualValue = new DoubleValue(evaluator.GetFitness( 217 flowDistanceQuality + moveFlowDistanceQuality, 218 installationQuality + moveInstallationQuality, 219 overbookedCapacity + moveOverbookedCapacity, 220 transportationCosts, expectedRandomQuality)); 131 MoveEvaluationParameter.ActualValue = moveEvaluation; 221 132 return base.Apply(); 222 133 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAP.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System. Drawing;23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Analysis .QualityAnalysis;25 using HeuristicLab.Analysis; 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; … … 29 29 using HeuristicLab.Encodings.IntegerVectorEncoding; 30 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Optimization.Operators; 31 32 using HeuristicLab.Parameters; 32 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 38 39 [Creatable("Problems")] 39 40 [StorableClass] 40 public sealed class G eneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent,41 public sealed class GQAP : SingleObjectiveBasicProblem<IntegerVectorEncoding>, 41 42 IProblemInstanceConsumer<QAPData>, 42 43 IProblemInstanceConsumer<CTAPData>, … … 45 46 IProblemInstanceConsumer<GQAPData> { 46 47 47 public override Image ItemImage { 48 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 49 } 50 51 public string Filename { get; set; } 48 public override bool Maximization { get { return false; } } 52 49 53 50 #region Parameter Descriptions 54 public static readonly string MaximizationDescription = "False if the fitness function should be minimized (default) or otherwise True if it should be maximized.";55 public static readonly string WeightsDescription = "The weights matrix describes the flows between the equipments.";56 public static readonly string DistancesDescription = "The distances matrix describes the distances between the locations at which the equipment can be installed.";57 public static readonly string InstallationCostsDescription = "The installation costs matrix describes the installation costs of installing equipment i at location j";58 public static readonly string DemandsDescription = "The demands vector describes the space requirements of the equipments.";59 public static readonly string CapacitiesDescription = "The capacities vector describes the available space at the locations.";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 51 public static readonly string BestKnownQualityDescription = "The best known quality (if available)."; 62 52 public static readonly string BestKnownSolutionDescription = "The best known solution (if available)."; 63 53 public static readonly string BestKnownSolutionsDescription = "Contains an archive of best-known solutions regarding flow-distance quality and installation quality."; 64 public static readonly string EquipmentNamesDescription = "Optional: A list of names that describes the equipments."; 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."; 54 public static readonly string ProblemInstanceDescription = "The problem instance that is to be solved."; 55 public static readonly string EvaluationDescription = "The evaluation result of a solution to the GQAP."; 67 56 #endregion 68 57 69 58 #region Parameter Properties 70 public ValueParameter<DoubleMatrix> WeightsParameter {71 get { return (ValueParameter<DoubleMatrix>)Parameters["Weights"]; }72 }73 public ValueParameter<DoubleMatrix> DistancesParameter {74 get { return (ValueParameter<DoubleMatrix>)Parameters["Distances"]; }75 }76 public ValueParameter<DoubleMatrix> InstallationCostsParameter {77 get { return (ValueParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }78 }79 public ValueParameter<DoubleArray> DemandsParameter {80 get { return (ValueParameter<DoubleArray>)Parameters["Demands"]; }81 }82 public ValueParameter<DoubleArray> CapacitiesParameter {83 get { return (ValueParameter<DoubleArray>)Parameters["Capacities"]; }84 }85 public FixedValueParameter<DoubleValue> TransportationCostsParameter {86 get { return (FixedValueParameter<DoubleValue>)Parameters["TransportationCosts"]; }87 }88 public FixedValueParameter<DoubleValue> ExpectedRandomQualityParameter {89 get { return (FixedValueParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }90 }91 59 public OptionalValueParameter<GQAPAssignment> BestKnownSolutionParameter { 92 60 get { return (OptionalValueParameter<GQAPAssignment>)Parameters["BestKnownSolution"]; } … … 95 63 get { return (OptionalValueParameter<GQAPAssignmentArchive>)Parameters["BestKnownSolutions"]; } 96 64 } 97 public OptionalValueParameter<StringArray> EquipmentNamesParameter { 98 get { return (OptionalValueParameter<StringArray>)Parameters["EquipmentNames"]; } 99 } 100 public OptionalValueParameter<StringArray> LocationNamesParameter { 101 get { return (OptionalValueParameter<StringArray>)Parameters["LocationNames"]; } 65 public IValueParameter<GQAPInstance> ProblemInstanceParameter { 66 get { return (IValueParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 102 67 } 103 68 #endregion 104 69 105 70 #region Properties 106 public DoubleMatrix Weights {107 get { return WeightsParameter.Value; }108 set { WeightsParameter.Value = value; }109 }110 public DoubleMatrix Distances {111 get { return DistancesParameter.Value; }112 set { DistancesParameter.Value = value; }113 }114 public DoubleMatrix InstallationCosts {115 get { return InstallationCostsParameter.Value; }116 set { InstallationCostsParameter.Value = value; }117 }118 public DoubleArray Demands {119 get { return DemandsParameter.Value; }120 set { DemandsParameter.Value = value; }121 }122 public DoubleArray Capacities {123 get { return CapacitiesParameter.Value; }124 set { CapacitiesParameter.Value = value; }125 }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 }134 public StringArray EquipmentNames {135 get { return EquipmentNamesParameter.Value; }136 set { EquipmentNamesParameter.Value = value; }137 }138 public StringArray LocationNames {139 get { return LocationNamesParameter.Value; }140 set { LocationNamesParameter.Value = value; }141 }142 71 public GQAPAssignment BestKnownSolution { 143 72 get { return BestKnownSolutionParameter.Value; } … … 148 77 set { BestKnownSolutionsParameter.Value = value; } 149 78 } 150 #endregion 151 152 public BestGQAPSolutionAnalyzer BestSolutionAnalyzer { 153 get { return Operators.OfType<BestGQAPSolutionAnalyzer>().FirstOrDefault(); } 154 } 155 public GQAPSolutionArchiveAnalyzer SolutionArchiveAnalyzer { 156 get { return Operators.OfType<GQAPSolutionArchiveAnalyzer>().FirstOrDefault(); } 157 } 79 public GQAPInstance ProblemInstance { 80 get { return ProblemInstanceParameter.Value; } 81 set { ProblemInstanceParameter.Value = value; } 82 } 83 #endregion 158 84 159 85 [StorableConstructor] 160 private G eneralizedQuadraticAssignmentProblem(bool deserializing) : base(deserializing) { }161 private G eneralizedQuadraticAssignmentProblem(GeneralizedQuadraticAssignmentProblemoriginal, Cloner cloner)86 private GQAP(bool deserializing) : base(deserializing) { } 87 private GQAP(GQAP original, Cloner cloner) 162 88 : base(original, cloner) { 163 89 RegisterEventHandlers(); 164 90 } 165 public GeneralizedQuadraticAssignmentProblem() 166 : base(new GQAPAdditivePenaltyEvaluator(), new RandomSolutionCreator()) { 167 Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", WeightsDescription, new DoubleMatrix(), false)); 168 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", DistancesDescription, new DoubleMatrix(), false)); 169 Parameters.Add(new ValueParameter<DoubleMatrix>("InstallationCosts", InstallationCostsDescription, new DoubleMatrix(), false)); 170 Parameters.Add(new FixedValueParameter<DoubleValue>("TransportationCosts", TransportationCostsDescription, new DoubleValue(1))); 171 Parameters.Add(new FixedValueParameter<DoubleValue>("ExpectedRandomQuality", ExpectedRandomQualityDescription, new DoubleValue(0), true)); 172 Parameters.Add(new ValueParameter<DoubleArray>("Demands", DemandsDescription, new DoubleArray(), false)); 173 Parameters.Add(new ValueParameter<DoubleArray>("Capacities", CapacitiesDescription, new DoubleArray(), false)); 91 public GQAP() : base() { 92 Encoding = new IntegerVectorEncoding("Assignment"); 174 93 Parameters.Add(new OptionalValueParameter<GQAPAssignment>("BestKnownSolution", BestKnownSolutionDescription, null, false)); 175 94 Parameters.Add(new OptionalValueParameter<GQAPAssignmentArchive>("BestKnownSolutions", BestKnownSolutionsDescription, null, false)); 176 Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", EquipmentNamesDescription, null, false)); 177 Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", LocationNamesDescription, null, false)); 178 179 WeightsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 180 DistancesParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 181 InstallationCostsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 182 DemandsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 183 CapacitiesParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 184 185 Weights = new DoubleMatrix(5, 5); 186 Weights[0, 0] = Weights[1, 1] = Weights[2, 2] = Weights[3, 3] = Weights[4, 4] = 0; 187 Weights[0, 1] = Weights[1, 0] = Weights[0, 2] = Weights[2, 0] = Weights[0, 3] = Weights[3, 0] = Weights[0, 4] = Weights[4, 0] = 10; 188 Weights[1, 2] = Weights[2, 1] = Weights[1, 3] = Weights[3, 1] = Weights[1, 4] = Weights[4, 1] = 5; 189 Weights[2, 3] = Weights[3, 2] = Weights[2, 4] = Weights[4, 2] = 7.5; 190 Weights[3, 4] = Weights[4, 3] = 2.5; 191 192 Distances = new DoubleMatrix(3, 3); 193 Distances[0, 0] = Distances[1, 1] = Distances[2, 2] = 0; 194 Distances[0, 1] = Distances[1, 0] = Distances[1, 2] = Distances[2, 1] = 1; 195 Distances[0, 2] = Distances[2, 0] = 2; 196 197 InstallationCosts = new DoubleMatrix(5, 3); 198 199 Demands = new DoubleArray(5); 200 Demands[0] = 2; Demands[1] = 1; Demands[2] = 3; Demands[3] = 1; Demands[4] = 1; 201 202 Capacities = new DoubleArray(3); 203 Capacities[0] = 4; Capacities[1] = 1; Capacities[2] = 4; 204 205 SolutionCreator.AssignmentParameter.ActualName = "Assignment"; 95 Parameters.Add(new ValueParameter<GQAPInstance>("ProblemInstance", "The problem instance that is to be solved.", new GQAPInstance(), false)); 206 96 207 97 InitializeOperators(); … … 210 100 211 101 public override IDeepCloneable Clone(Cloner cloner) { 212 return new GeneralizedQuadraticAssignmentProblem(this, cloner); 102 return new GQAP(this, cloner); 103 } 104 105 public override double Evaluate(Individual individual, IRandom random = null) { 106 var assignment = individual.IntegerVector(); 107 var evaluation = ProblemInstance.Evaluate(assignment); 108 individual["Evaluation"] = evaluation; 109 return ProblemInstance.ToSingleObjective(evaluation); 110 } 111 112 public double Evaluate(IntegerVector assignment) { 113 var evaluation = ProblemInstance.Evaluate(assignment); 114 return ProblemInstance.ToSingleObjective(evaluation); 115 } 116 117 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 118 AnalyzeBestSolution(results, GetBestIndividual(individuals, qualities)); 119 AnalyzeParetoArchive(results, 120 individuals.Select(i => Tuple.Create((IntegerVector)i.IntegerVector().Clone(), 121 (Evaluation)i["Evaluation"]))); 122 } 123 124 private void AnalyzeBestSolution(ResultCollection results, Tuple<Individual, double> best) { 125 var bestVector = best.Item1.IntegerVector(); 126 var bestEvaluation = (Evaluation)best.Item1["Evaluation"]; 127 128 IResult bestResult; 129 if (!results.TryGetValue("Best Solution", out bestResult)) { 130 bestResult = new Result("Best Solution", typeof(GQAPAssignment)); 131 results.Add(bestResult); 132 } 133 var item = bestResult.Value as GQAPAssignment; 134 if (item == null) bestResult.Value = new GQAPAssignment((IntegerVector)bestVector.Clone(), ProblemInstance, bestEvaluation); 135 else if (ProblemInstance.ToSingleObjective(bestEvaluation) 136 < ProblemInstance.ToSingleObjective(item.Evaluation)) { 137 item.ProblemInstance = ProblemInstance; 138 item.Assignment = (IntegerVector)bestVector.Clone(); 139 item.Evaluation = bestEvaluation; 140 } 141 } 142 143 private void AnalyzeParetoArchive(ResultCollection results, IEnumerable<Tuple<IntegerVector, Evaluation>> solutions) { 144 IResult archiveResult; 145 if (!results.TryGetValue("Solution Archive", out archiveResult)) { 146 archiveResult = new Result("Solution Archive", typeof(GQAPAssignmentArchive)); 147 results.Add(archiveResult); 148 } 149 var archive = archiveResult.Value as GQAPAssignmentArchive; 150 if (archive == null) archive = new GQAPAssignmentArchive(ProblemInstance); 151 else archive.ProblemInstance = ProblemInstance; 152 153 var combinedArchive = solutions 154 .Select(x => new GQAPSolution(x.Item1, x.Item2)) 155 .Concat(archive.Solutions); 156 archive.Solutions = GetFeasibleParetoFront(combinedArchive); 157 158 if (BestKnownSolutions == null) { 159 BestKnownSolutions = archive; 160 } else { 161 var combinedArchive2 = solutions 162 .Select(x => new GQAPSolution(x.Item1, x.Item2)) 163 .Concat(BestKnownSolutions.Solutions); 164 BestKnownSolutions.Solutions = GetFeasibleParetoFront(combinedArchive2); 165 } 213 166 } 214 167 … … 304 257 305 258 if (data.BestKnownAssignment == null && data.BestKnownQuality.HasValue) { 306 BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value);259 BestKnownQuality = data.BestKnownQuality.Value; 307 260 } 308 261 } … … 318 271 @"The weights matrix of the given instance contains 319 272 an unequal number of rows and columns."); 320 Weights = weights;321 322 273 if (distances == null || distances.Rows == 0) 323 274 throw new System.IO.InvalidDataException( … … 327 278 @"The distances matrix of the given instance contains 328 279 an unequal number of rows and columns."); 329 Distances = distances;330 331 280 if (installationCosts == null || installationCosts.Rows == 0) 332 281 throw new System.IO.InvalidDataException( … … 339 288 weights matrix and a different number of columns than 340 289 given in the distances matrix."); 341 InstallationCosts = installationCosts;342 343 290 if (capacities == null || capacities.Length == 0) 344 291 throw new System.IO.InvalidDataException( … … 348 295 @"The given instance contains a different number of 349 296 capacities than rows given in the distances matrix."); 350 Capacities = capacities;351 352 297 if (demands == null || demands.Length == 0) 353 298 throw new System.IO.InvalidDataException( … … 357 302 @"The given instance contains a different number of 358 303 demands than rows given in the weights matrix."); 359 Demands = demands;360 361 304 if (transportationCosts == null) 362 305 throw new System.IO.InvalidDataException( 363 306 @"The given instance does not contain transportation costs."); 364 TransportationCosts = transportationCosts.Value; 365 366 BestKnownQuality = null; 307 308 ProblemInstance = new GQAPInstance() { 309 Weights = weights, 310 Distances = distances, 311 InstallationCosts = installationCosts, 312 Capacities = capacities, 313 Demands = demands, 314 TransportationCosts = transportationCosts.Value 315 }; 316 BestKnownQualityParameter.Value = null; 367 317 BestKnownSolution = null; 368 318 BestKnownSolutions = null; 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 } 319 ProblemInstance.CalculatePenaltyLevel(); 399 320 } 400 321 private void EvaluateAndLoadAssignment(int[] vector) { … … 403 324 } 404 325 public void EvaluateAndLoadAssignment(IntegerVector assignment) { 405 if (! IsConfigurationValid()) {406 BestKnownQuality = null;326 if (!ProblemInstance.IsValid()) { 327 BestKnownQualityParameter.Value = null; 407 328 BestKnownSolution = null; 408 329 BestKnownSolutions = null; 409 } 410 double flowDistanceQuality, installationQuality, overbookedCapacity; 411 Evaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities, 412 out flowDistanceQuality, out installationQuality, out overbookedCapacity); 413 double quality = Evaluator.GetFitness(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts, ExpectedRandomQuality); 414 BestKnownSolution = new GQAPAssignment((IntegerVector)assignment.Clone(), new DoubleValue(quality), 415 new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), 416 new DoubleValue(overbookedCapacity), EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, 417 Demands, Capacities, new DoubleValue(TransportationCosts), new DoubleValue(ExpectedRandomQuality), Evaluator); 418 BestKnownQuality = new DoubleValue(quality); 419 BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, new DoubleValue(TransportationCosts), new DoubleValue(ExpectedRandomQuality), Evaluator); 420 BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity))); 330 return; 331 } 332 var evaluation = ProblemInstance.Evaluate(assignment); 333 var quality = ProblemInstance.ToSingleObjective(evaluation); 334 335 BestKnownSolution = new GQAPAssignment((IntegerVector)assignment.Clone(), ProblemInstance, evaluation); 336 BestKnownQuality = quality; 337 BestKnownSolutions = new GQAPAssignmentArchive(ProblemInstance); 338 BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), evaluation)); 421 339 } 422 340 #endregion … … 427 345 Parameterize(); 428 346 } 429 protected override void OnEvaluatorChanged() { 430 base.OnEvaluatorChanged(); 431 Parameterize(); 432 if (BestKnownSolution != null) EvaluateAndLoadAssignment(BestKnownSolution.Assignment); 433 Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged); 434 } 435 protected override void OnSolutionCreatorChanged() { 436 base.OnSolutionCreatorChanged(); 437 Parameterize(); 438 SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged); 439 } 440 441 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 442 Parameterize(); 443 } 444 private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) { 347 protected override void OnEncodingChanged() { 348 base.OnEncodingChanged(); 445 349 Parameterize(); 446 350 } … … 454 358 455 359 private void RegisterEventHandlers() { 456 Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged); 457 SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged); 360 ProblemInstanceParameter.ValueChanged += ProblemInstanceParameterOnValueChanged; 361 ProblemInstance.CapacitiesParameter.ValueChanged += ProblemInstanceCapacitiesParameterOnValueChanged; 362 ProblemInstance.DemandsParameter.ValueChanged += ProblemInstanceDemandsParameterOnValueChanged; 363 ProblemInstance.Capacities.Reset += ProblemInstanceCapacitiesOnReset; 364 ProblemInstance.Demands.Reset += ProblemInstanceDemandsOnReset; 365 } 366 367 private void ProblemInstanceParameterOnValueChanged(object sender, EventArgs e) { 368 ProblemInstance.CapacitiesParameter.ValueChanged += ProblemInstanceCapacitiesParameterOnValueChanged; 369 ProblemInstance.Capacities.Reset += ProblemInstanceCapacitiesOnReset; 370 ProblemInstance.DemandsParameter.ValueChanged += ProblemInstanceDemandsParameterOnValueChanged; 371 ProblemInstance.Demands.Reset += ProblemInstanceDemandsOnReset; 372 UpdateEncoding(); 373 } 374 private void ProblemInstanceCapacitiesParameterOnValueChanged(object sender, EventArgs e) { 375 ProblemInstance.Capacities.Reset += ProblemInstanceCapacitiesOnReset; 376 UpdateEncoding(); 377 } 378 private void ProblemInstanceDemandsParameterOnValueChanged(object sender, EventArgs e) { 379 ProblemInstance.Demands.Reset += ProblemInstanceDemandsOnReset; 380 UpdateEncoding(); 381 } 382 private void ProblemInstanceDemandsOnReset(object sender, EventArgs e) { 383 UpdateEncoding(); 384 } 385 private void ProblemInstanceCapacitiesOnReset(object sender, EventArgs e) { 386 UpdateEncoding(); 387 } 388 389 private void UpdateEncoding() { 390 Encoding.Length = ProblemInstance.Demands.Length; 391 Encoding.Bounds = new IntMatrix(new int[,] { { 0, ProblemInstance.Capacities.Length } }); 458 392 } 459 393 … … 461 395 Operators.Clear(); 462 396 Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPOperator>()); 463 Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>());464 397 Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator); 465 398 Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>()); 466 Operators.Add(new ScaledQualityDifferenceAnalyzer()); 399 Operators.Add(new HammingSimilarityCalculator()); 400 Operators.Add(new QualitySimilarityCalculator()); 401 402 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 467 403 Parameterize(); 468 404 } 469 405 470 406 private void Parameterize() { 471 472 407 var operators = Operators.Union(new IOperator[] { SolutionCreator, Evaluator }).ToArray(); 473 474 foreach (var op in operators.OfType<IAssignmentAwareGQAPOperator>()) { 475 op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 476 op.AssignmentParameter.Hidden = true; 477 } 408 478 409 foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) { 479 410 op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; … … 488 419 op.BestKnownSolutionsParameter.Hidden = true; 489 420 } 490 foreach (var op in operators.OfType<ICapacitiesAwareGQAPOperator>()) {491 op.CapacitiesParameter.ActualName = CapacitiesParameter.Name;492 op.CapacitiesParameter.Hidden = true;493 }494 foreach (var op in operators.OfType<IDemandsAwareGQAPOperator>()) {495 op.DemandsParameter.ActualName = DemandsParameter.Name;496 op.DemandsParameter.Hidden = true;497 }498 foreach (var op in operators.OfType<IDistancesAwareGQAPOperator>()) {499 op.DistancesParameter.ActualName = DistancesParameter.Name;500 op.DistancesParameter.Hidden = true;501 }502 foreach (var op in operators.OfType<IEquipmentNamesAwareGQAPOperator>()) {503 op.EquipmentNamesParameter.ActualName = EquipmentNamesParameter.Name;504 op.EquipmentNamesParameter.Hidden = true;505 }506 421 foreach (var op in operators.OfType<IGQAPCrossover>()) { 507 op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;422 op.ParentsParameter.ActualName = Encoding.Name; 508 423 op.ParentsParameter.Hidden = true; 509 op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;424 op.ChildParameter.ActualName = Encoding.Name; 510 425 op.ChildParameter.Hidden = true; 511 }512 foreach (var op in operators.OfType<IInstallationCostsAwareGQAPOperator>()) {513 op.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;514 op.InstallationCostsParameter.Hidden = true;515 }516 foreach (var op in operators.OfType<ILocationNamesAwareGQAPOperator>()) {517 op.LocationNamesParameter.ActualName = LocationNamesParameter.Name;518 op.LocationNamesParameter.Hidden = true;519 426 } 520 427 var moveEvaluator = operators.OfType<IGQAPMoveEvaluator>().FirstOrDefault(); … … 523 430 op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName; 524 431 op.MoveQualityParameter.Hidden = true; 525 op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName; 526 op.MoveFlowDistanceQualityParameter.Hidden = true; 527 op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName; 528 op.MoveInstallationQualityParameter.Hidden = true; 529 op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName; 530 op.MoveOverbookedCapacityParameter.Hidden = true; 432 op.MoveEvaluationParameter.ActualName = "MoveEvaluation"; 433 op.MoveEvaluationParameter.Hidden = true; 531 434 } 532 435 } … … 535 438 op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName; 536 439 op.MoveQualityParameter.Hidden = true; 537 op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName; 538 op.MoveFlowDistanceQualityParameter.Hidden = true; 539 op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName; 540 op.MoveInstallationQualityParameter.Hidden = true; 541 op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName; 542 op.MoveOverbookedCapacityParameter.Hidden = true; 440 op.MoveEvaluationParameter.ActualName = "MoveEvaluation"; 441 op.MoveEvaluationParameter.Hidden = true; 543 442 } 544 op.MaximizationParameter.ActualName = MaximizationParameter.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; 443 } 444 foreach (var op in operators.OfType<IProblemInstanceAwareGQAPOperator>()) { 445 op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name; 446 op.ProblemInstanceParameter.Hidden = true; 550 447 } 551 448 foreach (var op in operators.OfType<IQualitiesAwareGQAPOperator>()) { 552 449 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 553 450 op.QualityParameter.Hidden = true; 554 op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName; 555 op.FlowDistanceQualityParameter.Hidden = true; 556 op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName; 557 op.InstallationQualityParameter.Hidden = true; 558 op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName; 559 op.OverbookedCapacityParameter.Hidden = true; 560 op.MaximizationParameter.ActualName = MaximizationParameter.Name; 561 op.MaximizationParameter.Hidden = true; 451 op.EvaluationParameter.ActualName = "Evaluation"; 452 op.EvaluationParameter.Hidden = true; 562 453 } 563 454 foreach (var op in operators.OfType<IQualityAwareGQAPOperator>()) { 564 455 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 565 456 op.QualityParameter.Hidden = true; 566 op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName; 567 op.FlowDistanceQualityParameter.Hidden = true; 568 op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName; 569 op.InstallationQualityParameter.Hidden = true; 570 op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName; 571 op.OverbookedCapacityParameter.Hidden = true; 572 op.MaximizationParameter.ActualName = MaximizationParameter.Name; 573 op.MaximizationParameter.Hidden = true; 574 } 575 foreach (var op in operators.OfType<ITransportationCostsAwareGQAPOperator>()) { 576 op.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name; 577 op.TransportationCostsParameter.Hidden = true; 578 } 579 foreach (var op in operators.OfType<IWeightsAwareGQAPOperator>()) { 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; 586 } 587 588 foreach (var op in operators.OfType<IIntegerVectorCrossover>()) { 589 op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 590 op.ParentsParameter.Hidden = true; 591 op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName; 592 op.ChildParameter.Hidden = true; 593 } 594 foreach (var op in operators.OfType<IIntegerVectorManipulator>()) { 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; 606 } 607 } 608 #endregion 609 610 public bool IsConfigurationValid() { 611 return Weights != null && Distances != null && Demands != null && Capacities != null && InstallationCosts != null 612 && Weights.Rows == Weights.Columns && Weights.Rows == InstallationCosts.Rows 613 && Distances.Rows == Distances.Columns && Distances.Rows == InstallationCosts.Columns 614 && Demands.Length == Weights.Rows && Capacities.Length == Distances.Rows; 457 op.EvaluationParameter.ActualName = "Evaluation"; 458 op.EvaluationParameter.Hidden = true; 459 } 460 } 461 #endregion 462 463 public static ItemList<GQAPSolution> GetFeasibleParetoFront(IEnumerable<GQAPSolution> solutions) { 464 var front = new ItemList<GQAPSolution>(solutions.Where(x => x.Evaluation.IsFeasible)); 465 466 for (int i = 0; i < front.Count - 1; i++) { 467 for (int j = i + 1; j < front.Count; j++) { 468 if (front[i].Evaluation.FlowCosts <= front[j].Evaluation.FlowCosts 469 && front[i].Evaluation.InstallationCosts <= front[j].Evaluation.InstallationCosts) { 470 front.RemoveAt(j); 471 j--; 472 } else if (front[i].Evaluation.FlowCosts >= front[j].Evaluation.FlowCosts 473 && front[i].Evaluation.InstallationCosts >= front[j].Evaluation.InstallationCosts) { 474 front.RemoveAt(i); 475 j = i; 476 } 477 } 478 } 479 return front; 615 480 } 616 481 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignment.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data;26 25 using HeuristicLab.Encodings.IntegerVectorEncoding; 27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 37 36 get { return assignment; } 38 37 set { 39 bool changed = (assignment != value);38 if (assignment == value) return; 40 39 assignment = value; 41 if (changed) OnPropertyChanged("Assignment");40 OnPropertyChanged(nameof(Assignment)); 42 41 } 43 42 } 44 43 45 44 [Storable] 46 private DoubleValue quality;47 public DoubleValue Quality{48 get { return quality; }45 private Evaluation evaluation; 46 public Evaluation Evaluation { 47 get { return evaluation; } 49 48 set { 50 bool changed = (quality != value);51 quality= value;52 if (changed) OnPropertyChanged("Quality");49 if (evaluation == value) return; 50 evaluation = value; 51 OnPropertyChanged(nameof(Evaluation)); 53 52 } 54 53 } 55 54 56 55 [Storable] 57 private DoubleValue flowDistanceQuality;58 public DoubleValue FlowDistanceQuality{59 get { return flowDistanceQuality; }56 private GQAPInstance problemInstance; 57 public GQAPInstance ProblemInstance { 58 get { return problemInstance; } 60 59 set { 61 bool changed = (flowDistanceQuality != value); 62 flowDistanceQuality = value; 63 if (changed) OnPropertyChanged("FlowDistanceQuality"); 64 } 65 } 66 67 [Storable] 68 private DoubleValue installationQuality; 69 public DoubleValue InstallationQuality { 70 get { return installationQuality; } 71 set { 72 bool changed = (installationQuality != value); 73 installationQuality = value; 74 if (changed) OnPropertyChanged("InstallationQuality"); 75 } 76 } 77 78 [Storable] 79 private DoubleValue overbookedCapacity; 80 public DoubleValue OverbookedCapacity { 81 get { return overbookedCapacity; } 82 set { 83 bool changed = (overbookedCapacity != value); 84 overbookedCapacity = value; 85 if (changed) OnPropertyChanged("OverbookedCapacity"); 86 } 87 } 88 89 [Storable] 90 private StringArray equipmentNames; 91 public StringArray EquipmentNames { 92 get { return equipmentNames; } 93 set { 94 bool changed = (equipmentNames != value); 95 equipmentNames = value; 96 if (changed) OnPropertyChanged("EquipmentNames"); 97 } 98 } 99 100 [Storable] 101 private StringArray locationNames; 102 public StringArray LocationNames { 103 get { return locationNames; } 104 set { 105 bool changed = (locationNames != value); 106 locationNames = value; 107 if (changed) OnPropertyChanged("LocationNames"); 108 } 109 } 110 111 [Storable] 112 private DoubleMatrix distances; 113 public DoubleMatrix Distances { 114 get { return distances; } 115 set { 116 bool changed = (distances != value); 117 distances = value; 118 if (changed) OnPropertyChanged("Distances"); 119 } 120 } 121 122 [Storable] 123 private DoubleMatrix weights; 124 public DoubleMatrix Weights { 125 get { return weights; } 126 set { 127 bool changed = (weights != value); 128 weights = value; 129 if (changed) OnPropertyChanged("Weights"); 130 } 131 } 132 133 [Storable] 134 private DoubleMatrix installationCosts; 135 public DoubleMatrix InstallationCosts { 136 get { return installationCosts; } 137 set { 138 bool changed = (installationCosts != value); 139 installationCosts = value; 140 if (changed) OnPropertyChanged("InstallationCosts"); 141 } 142 } 143 144 [Storable] 145 private DoubleArray demands; 146 public DoubleArray Demands { 147 get { return demands; } 148 set { 149 bool changed = (demands != value); 150 demands = value; 151 if (changed) OnPropertyChanged("Demands"); 152 } 153 } 154 155 [Storable] 156 private DoubleArray capacities; 157 public DoubleArray Capacities { 158 get { return capacities; } 159 set { 160 bool changed = (capacities != value); 161 capacities = value; 162 if (changed) OnPropertyChanged("Capacities"); 163 } 164 } 165 166 [Storable] 167 private DoubleValue transportationCosts; 168 public DoubleValue TransportationCosts { 169 get { return transportationCosts; } 170 set { 171 bool changed = (transportationCosts != value); 172 transportationCosts = value; 173 if (changed) OnPropertyChanged("TransportationCosts"); 174 } 175 } 176 177 [Storable] 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"); 60 if (problemInstance == value) return; 61 problemInstance = value; 62 OnPropertyChanged(nameof(ProblemInstance)); 196 63 } 197 64 } … … 202 69 : base(original, cloner) { 203 70 assignment = cloner.Clone(original.assignment); 204 quality = cloner.Clone(original.quality); 205 flowDistanceQuality = cloner.Clone(original.flowDistanceQuality); 206 installationQuality = cloner.Clone(original.installationQuality); 207 overbookedCapacity = cloner.Clone(original.overbookedCapacity); 208 equipmentNames = cloner.Clone(original.equipmentNames); 209 locationNames = cloner.Clone(original.locationNames); 210 distances = cloner.Clone(original.distances); 211 weights = cloner.Clone(original.weights); 212 installationCosts = cloner.Clone(original.installationCosts); 213 demands = cloner.Clone(original.demands); 214 capacities = cloner.Clone(original.capacities); 215 transportationCosts = cloner.Clone(original.transportationCosts); 216 expectedRandomQuality = cloner.Clone(original.expectedRandomQuality); 217 evaluator = cloner.Clone(original.evaluator); 71 evaluation = cloner.Clone(original.evaluation); 72 problemInstance = cloner.Clone(original.problemInstance); 218 73 } 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) 74 public GQAPAssignment(IntegerVector assignment, GQAPInstance problemInstance) 75 : this(assignment, problemInstance, problemInstance.Evaluate(assignment)) { } 76 public GQAPAssignment(IntegerVector assignment, GQAPInstance problemInstance, Evaluation evaluation) 220 77 : base() { 221 78 this.assignment = assignment; 222 this.quality = quality; 223 this.flowDistanceQuality = flowDistanceQuality; 224 this.installationQuality = installationQuality; 225 this.overbookedCapacity = overbookedCapacity; 226 this.equipmentNames = equipmentNames; 227 this.locationNames = locationNames; 228 this.distances = distances; 229 this.weights = weights; 230 this.installationCosts = installationCosts; 231 this.demands = demands; 232 this.capacities = capacities; 233 this.transportationCosts = transportationCosts; 234 this.expectedRandomQuality = expectedRandomQuality; 235 this.evaluator = evaluator; 79 this.evaluation = evaluation; 80 this.problemInstance = problemInstance; 236 81 } 237 82 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignmentArchive.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data;26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 26 … … 36 35 get { return solutions; } 37 36 set { 38 bool changed = (solutions != value);37 if (solutions == value) return; 39 38 solutions = value; 40 if (changed) OnPropertyChanged("Solutions");39 OnPropertyChanged(nameof(Solutions)); 41 40 } 42 41 } 43 42 44 43 [Storable] 45 private StringArray equipmentNames;46 public StringArray EquipmentNames{47 get { return equipmentNames; }44 private GQAPInstance problemInstance; 45 public GQAPInstance ProblemInstance { 46 get { return problemInstance; } 48 47 set { 49 bool changed = (equipmentNames != value); 50 equipmentNames = value; 51 if (changed) OnPropertyChanged("EquipmentNames"); 52 } 53 } 54 55 [Storable] 56 private StringArray locationNames; 57 public StringArray LocationNames { 58 get { return locationNames; } 59 set { 60 bool changed = (locationNames != value); 61 locationNames = value; 62 if (changed) OnPropertyChanged("LocationNames"); 63 } 64 } 65 66 [Storable] 67 private DoubleMatrix distances; 68 public DoubleMatrix Distances { 69 get { return distances; } 70 set { 71 bool changed = (distances != value); 72 distances = value; 73 if (changed) OnPropertyChanged("Distances"); 74 } 75 } 76 77 [Storable] 78 private DoubleMatrix weights; 79 public DoubleMatrix Weights { 80 get { return weights; } 81 set { 82 bool changed = (weights != value); 83 weights = value; 84 if (changed) OnPropertyChanged("Weights"); 85 } 86 } 87 88 [Storable] 89 private DoubleMatrix installationCosts; 90 public DoubleMatrix InstallationCosts { 91 get { return installationCosts; } 92 set { 93 bool changed = (installationCosts != value); 94 installationCosts = value; 95 if (changed) OnPropertyChanged("InstallationCosts"); 96 } 97 } 98 99 [Storable] 100 private DoubleArray demands; 101 public DoubleArray Demands { 102 get { return demands; } 103 set { 104 bool changed = (demands != value); 105 demands = value; 106 if (changed) OnPropertyChanged("Demands"); 107 } 108 } 109 110 [Storable] 111 private DoubleArray capacities; 112 public DoubleArray Capacities { 113 get { return capacities; } 114 set { 115 bool changed = (capacities != value); 116 capacities = value; 117 if (changed) OnPropertyChanged("Capacities"); 118 } 119 } 120 121 [Storable] 122 private DoubleValue transportationCosts; 123 public DoubleValue TransportationCosts { 124 get { return transportationCosts; } 125 set { 126 bool changed = (transportationCosts != value); 127 transportationCosts = value; 128 if (changed) OnPropertyChanged("TransportationCosts"); 129 } 130 } 131 132 [Storable] 133 private DoubleValue expectedRandomQuality; 134 public DoubleValue ExpectedRandomQuality { 135 get { return expectedRandomQuality; } 136 set { 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"); 48 if (problemInstance == value) return; 49 problemInstance = value; 50 OnPropertyChanged(nameof(ProblemInstance)); 151 51 } 152 52 } … … 157 57 : base(original, cloner) { 158 58 solutions = cloner.Clone(original.solutions); 159 equipmentNames = cloner.Clone(original.equipmentNames); 160 locationNames = cloner.Clone(original.locationNames); 161 distances = cloner.Clone(original.distances); 162 weights = cloner.Clone(original.weights); 163 installationCosts = cloner.Clone(original.installationCosts); 164 demands = cloner.Clone(original.demands); 165 capacities = cloner.Clone(original.capacities); 166 transportationCosts = cloner.Clone(original.transportationCosts); 167 expectedRandomQuality = cloner.Clone(original.expectedRandomQuality); 168 evaluator = cloner.Clone(original.evaluator); 59 problemInstance = cloner.Clone(original.problemInstance); 169 60 } 170 61 public GQAPAssignmentArchive() … … 172 63 this.solutions = new ItemList<GQAPSolution>(); 173 64 } 174 public GQAPAssignmentArchive( StringArray equipmentNames, StringArray locationNames, DoubleMatrix distances, DoubleMatrix weights, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, DoubleValue transportationCosts, DoubleValue expectedRandomQuality, IGQAPEvaluator evaluator)65 public GQAPAssignmentArchive(GQAPInstance problemInstance) 175 66 : this() { 176 this.distances = distances; 177 this.weights = weights; 178 this.installationCosts = installationCosts; 179 this.demands = demands; 180 this.capacities = capacities; 181 this.transportationCosts = transportationCosts; 182 this.expectedRandomQuality = expectedRandomQuality; 183 this.evaluator = evaluator; 67 this.problemInstance = problemInstance; 184 68 } 185 69 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPSolution.cs
r7418 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data;26 25 using HeuristicLab.Encodings.IntegerVectorEncoding; 27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 44 43 45 44 [Storable] 46 private DoubleValue quality;47 public DoubleValue Quality{48 get { return quality; }45 private Evaluation evaluation; 46 public Evaluation Evaluation { 47 get { return evaluation; } 49 48 set { 50 bool changed = (quality != value); 51 quality = value; 52 if (changed) OnPropertyChanged("Quality"); 53 } 54 } 55 56 [Storable] 57 private DoubleValue flowDistanceQuality; 58 public DoubleValue FlowDistanceQuality { 59 get { return flowDistanceQuality; } 60 set { 61 bool changed = (flowDistanceQuality != value); 62 flowDistanceQuality = value; 63 if (changed) OnPropertyChanged("FlowDistanceQuality"); 64 } 65 } 66 67 [Storable] 68 private DoubleValue installationQuality; 69 public DoubleValue InstallationQuality { 70 get { return installationQuality; } 71 set { 72 bool changed = (installationQuality != value); 73 installationQuality = value; 74 if (changed) OnPropertyChanged("InstallationQuality"); 75 } 76 } 77 78 [Storable] 79 private DoubleValue overbookedCapacity; 80 public DoubleValue OverbookedCapacity { 81 get { return overbookedCapacity; } 82 set { 83 bool changed = (overbookedCapacity != value); 84 overbookedCapacity = value; 85 if (changed) OnPropertyChanged("OverbookedCapacity"); 49 if (evaluation == value) return; 50 evaluation = value; 51 OnPropertyChanged(nameof(Evaluation)); 86 52 } 87 53 } … … 92 58 : base(original, cloner) { 93 59 assignment = cloner.Clone(original.assignment); 94 quality = cloner.Clone(original.quality); 95 flowDistanceQuality = cloner.Clone(original.flowDistanceQuality); 96 installationQuality = cloner.Clone(original.installationQuality); 97 overbookedCapacity = cloner.Clone(original.overbookedCapacity); 60 evaluation = cloner.Clone(original.evaluation); 98 61 } 99 public GQAPSolution(IntegerVector assignment, DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity)62 public GQAPSolution(IntegerVector assignment, Evaluation evaluation) 100 63 : base() { 101 64 this.assignment = assignment; 102 this.quality = quality; 103 this.flowDistanceQuality = flowDistanceQuality; 104 this.installationQuality = installationQuality; 105 this.overbookedCapacity = overbookedCapacity; 65 this.evaluation = evaluation; 106 66 } 107 67 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.csproj
r15492 r15504 98 98 </ItemGroup> 99 99 <ItemGroup> 100 <Compile Include="Analyzers\BestGQAPSolutionAnalyzer.cs" /> 101 <Compile Include="Analyzers\GQAPSolutionArchiveUpdater.cs" /> 102 <Compile Include="Analyzers\GQAPPopulationDiversityAnalyzer.cs" /> 103 <Compile Include="Analyzers\GQAPSolutionArchiveAnalyzer.cs" /> 104 <Compile Include="Evaluators\GQAPPenaltyLevelEvaluator.cs" /> 105 <Compile Include="Evaluators\GQAPEvaluator.cs" /> 106 <Compile Include="Evaluators\GQAPNMoveEvaluator.cs" /> 100 <Compile Include="Evaluation\Evaluation.cs" /> 101 <Compile Include="Evaluation\GQAPNMoveEvaluator.cs" /> 107 102 <Compile Include="GQAPAssignment.cs" /> 108 <Compile Include=" Interfaces\IEvaluatorAwareGQAPOperator.cs" />103 <Compile Include="GQAPInstance.cs" /> 109 104 <Compile Include="Operators\Crossovers\CordeauCrossover.cs" /> 110 105 <Compile Include="SolutionCreators\SlackMinimizationSolutionCreator.cs" /> … … 113 108 <Compile Include="SolutionCreators\GQAPStochasticSolutionCreator.cs" /> 114 109 <Compile Include="SolutionCreators\GreedyRandomizedSolutionCreator.cs" /> 115 <Compile Include="SolutionCreators\RandomSolutionCreator.cs" />116 110 <None Include="Plugin.cs.frame" /> 117 <Compile Include="Evaluators\GQAPAdditivePenaltyEvaluator.cs" /> 118 <Compile Include="GeneralizedQuadraticAssignmentProblem.cs" /> 111 <Compile Include="GQAP.cs" /> 119 112 <Compile Include="GQAPAssignmentArchive.cs" /> 120 113 <Compile Include="GQAPSolution.cs" /> 121 <Compile Include="Interfaces\IBestKnownSolutionsAwareGQAPOperator.cs" /> 122 <Compile Include="Interfaces\IGQAPManipulator.cs" /> 123 <Compile Include="Interfaces\IQualitiesAwareGQAPOperator.cs" /> 124 <Compile Include="Interfaces\IAssignmentsAwareGQAPOperator.cs" /> 125 <Compile Include="Interfaces\IBestKnownQualityAwareGQAPOperator.cs" /> 126 <Compile Include="Interfaces\IBestKnownSolutionAwareGQAPOperator.cs" /> 127 <Compile Include="Interfaces\ILocationNamesAwareGQAPOperator.cs" /> 128 <Compile Include="Interfaces\IEquipmentNamesAwareGQAPOperator.cs" /> 129 <Compile Include="Interfaces\IMoveQualityAwareGQAPOperator.cs" /> 130 <Compile Include="Interfaces\IGQAPEvaluator.cs" /> 131 <Compile Include="Interfaces\IQualityAwareGQAPOperator.cs" /> 132 <Compile Include="Interfaces\IExpectedRandomQualityAwareGQAPOperator.cs" /> 133 <Compile Include="Interfaces\ITransportationCostsAwareGQAPOperator.cs" /> 134 <Compile Include="Interfaces\IInstallationCostsAwareGQAPOperator.cs" /> 135 <Compile Include="Interfaces\IDistancesAwareGQAPOperator.cs" /> 136 <Compile Include="Interfaces\IWeightsAwareGQAPOperator.cs" /> 137 <Compile Include="Interfaces\IAssignmentAwareGQAPOperator.cs" /> 138 <Compile Include="Interfaces\IGQAPNMoveEvaluator.cs" /> 139 <Compile Include="Interfaces\IDemandsAwareGQAPOperator.cs" /> 140 <Compile Include="Interfaces\IGQAPCrossover.cs" /> 141 <Compile Include="Interfaces\IGQAPLocalImprovementOperator.cs" /> 142 <Compile Include="Interfaces\IGQAPMoveEvaluator.cs" /> 143 <Compile Include="Interfaces\IGQAPMoveOperator.cs" /> 144 <Compile Include="Interfaces\IGQAPNMoveOperator.cs" /> 145 <Compile Include="Interfaces\IGQAPOperator.cs" /> 146 <Compile Include="Interfaces\IGQAPSolutionCreator.cs" /> 147 <Compile Include="Interfaces\ICapacitiesAwareGQAPOperator.cs" /> 114 <Compile Include="Interfaces\Parameter\IBestKnownSolutionsAwareGQAPOperator.cs" /> 115 <Compile Include="Interfaces\Operator\IGQAPManipulator.cs" /> 116 <Compile Include="Interfaces\Parameter\IQualitiesAwareGQAPOperator.cs" /> 117 <Compile Include="Interfaces\Parameter\IBestKnownQualityAwareGQAPOperator.cs" /> 118 <Compile Include="Interfaces\Parameter\IBestKnownSolutionAwareGQAPOperator.cs" /> 119 <Compile Include="Interfaces\Parameter\IMoveQualityAwareGQAPOperator.cs" /> 120 <Compile Include="Interfaces\Parameter\IQualityAwareGQAPOperator.cs" /> 121 <Compile Include="Interfaces\Parameter\IProblemInstanceAwareGQAPOperator.cs" /> 122 <Compile Include="Interfaces\Operator\IGQAPNMoveEvaluator.cs" /> 123 <Compile Include="Interfaces\Operator\IGQAPCrossover.cs" /> 124 <Compile Include="Interfaces\Operator\IGQAPLocalImprovementOperator.cs" /> 125 <Compile Include="Interfaces\Operator\IGQAPMoveEvaluator.cs" /> 126 <Compile Include="Interfaces\Operator\IGQAPMoveOperator.cs" /> 127 <Compile Include="Interfaces\Operator\IGQAPNMoveOperator.cs" /> 128 <Compile Include="Interfaces\Operator\IGQAPOperator.cs" /> 129 <Compile Include="Interfaces\Operator\IGQAPSolutionCreator.cs" /> 148 130 <Compile Include="Moves\NMove.cs" /> 149 131 <Compile Include="Moves\GQAPMoveGenerator.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPCrossover.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPLocalImprovementOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 24 25 using HeuristicLab.Optimization; 25 26 … … 27 28 public interface IGQAPLocalImprovementOperator : ILocalImprovementAlgorithmOperator { 28 29 IValueLookupParameter<IntValue> MaximumCandidateListSizeParameter { get; } 30 ILookupParameter<IntegerVector> AssignmentParameter { get; } 29 31 } 30 32 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPManipulator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using HeuristicLab.Core; 23 using HeuristicLab.Encodings.IntegerVectorEncoding; 22 24 using HeuristicLab.Optimization; 23 25 24 26 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 25 public interface IGQAPManipulator : IAssignmentAwareGQAPOperator, IManipulator { } 27 public interface IGQAPManipulator : IManipulator { 28 ILookupParameter<IntegerVector> AssignmentParameter { get; } 29 } 26 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPMoveEvaluator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data;24 23 using HeuristicLab.Optimization; 25 24 26 25 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 27 26 public interface IGQAPMoveEvaluator : IGQAPMoveOperator, ISingleObjectiveMoveEvaluator { 28 ILookupParameter<BoolValue> MaximizationParameter { get; } 29 ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { get; } 30 ILookupParameter<DoubleValue> MoveInstallationQualityParameter { get; } 31 ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { get; } 27 ILookupParameter<Evaluation> MoveEvaluationParameter { get; } 32 28 } 33 29 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPMoveOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using HeuristicLab.Core; 23 using HeuristicLab.Encodings.IntegerVectorEncoding; 22 24 using HeuristicLab.Optimization; 23 25 24 26 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 25 public interface IGQAPMoveOperator : IMoveOperator { } 27 public interface IGQAPMoveOperator : IMoveOperator { 28 ILookupParameter<IntegerVector> AssignmentParameter { get; } 29 } 26 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPNMoveEvaluator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPNMoveOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Operator/IGQAPSolutionCreator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using HeuristicLab.Core;23 22 using HeuristicLab.Encodings.IntegerVectorEncoding; 24 using HeuristicLab.Optimization;25 23 26 24 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 27 public interface IGQAPSolutionCreator : ISolutionCreator { 28 ILookupParameter<IntegerVector> AssignmentParameter { get; } 29 } 25 public interface IGQAPSolutionCreator : IIntegerVectorCreator { } 30 26 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IBestKnownQualityAwareGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IBestKnownSolutionAwareGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IBestKnownSolutionsAwareGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IMoveQualityAwareGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 26 26 public interface IMoveQualityAwareGQAPOperator : IGQAPMoveOperator { 27 ILookupParameter<BoolValue> MaximizationParameter { get; }28 27 ILookupParameter<DoubleValue> MoveQualityParameter { get; } 29 ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { get; } 30 ILookupParameter<DoubleValue> MoveInstallationQualityParameter { get; } 31 ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { get; } 28 ILookupParameter<Evaluation> MoveEvaluationParameter { get; } 32 29 } 33 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IProblemInstanceAwareGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data;24 23 25 24 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 26 public interface I ExpectedRandomQualityAwareGQAPOperator : IGQAPOperator {27 I ValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { get; }25 public interface IProblemInstanceAwareGQAPOperator : IGQAPOperator { 26 ILookupParameter<GQAPInstance> ProblemInstanceParameter { get; } 28 27 } 29 28 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IQualitiesAwareGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 26 26 public interface IQualitiesAwareGQAPOperator : IGQAPOperator { 27 ILookupParameter<BoolValue> MaximizationParameter { get; }28 27 IScopeTreeLookupParameter<DoubleValue> QualityParameter { get; } 29 IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter { get; } 30 IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter { get; } 31 IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter { get; } 28 IScopeTreeLookupParameter<Evaluation> EvaluationParameter { get; } 32 29 } 33 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Interfaces/Parameter/IQualityAwareGQAPOperator.cs
r15503 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment { 26 26 public interface IQualityAwareGQAPOperator : IGQAPOperator { 27 ILookupParameter<BoolValue> MaximizationParameter { get; }28 27 ILookupParameter<DoubleValue> QualityParameter { get; } 29 ILookupParameter<DoubleValue> FlowDistanceQualityParameter { get; } 30 ILookupParameter<DoubleValue> InstallationQualityParameter { get; } 31 ILookupParameter<DoubleValue> OverbookedCapacityParameter { get; } 28 ILookupParameter<Evaluation> EvaluationParameter { get; } 32 29 } 33 30 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/GQAPMoveGenerator.cs
r7419 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 [Item("GQAPMoveGenerator", "Base class for move generators for the Generalized Quadratic Assignment Problem.")] 32 32 [StorableClass] 33 public abstract class GQAPMoveGenerator : SingleSuccessorOperator, IAssignmentAwareGQAPOperator, IMoveGenerator, IGQAPMoveOperator { 33 public abstract class GQAPMoveGenerator : SingleSuccessorOperator, IMoveGenerator, IGQAPMoveOperator, 34 IProblemInstanceAwareGQAPOperator { 34 35 35 36 public ILookupParameter<IntegerVector> AssignmentParameter { 36 37 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } 38 } 39 40 41 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 42 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 37 43 } 38 44 … … 43 49 : base() { 44 50 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 51 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 45 52 } 46 53 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/GQAPNMoveGenerator.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 58 58 int counter = 0; 59 59 string name = MoveParameter.TranslatedName; 60 foreach (var move in GenerateMoves(AssignmentParameter.ActualValue, NParameter.ActualValue.Value )) {60 foreach (var move in GenerateMoves(AssignmentParameter.ActualValue, NParameter.ActualValue.Value, ProblemInstanceParameter.ActualValue)) { 61 61 scopes.Add(new Scope(counter.ToString())); 62 62 scopes.Last().Variables.Add(new Variable(name, move)); … … 67 67 } 68 68 69 public abstract IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n );69 public abstract IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n, GQAPInstance problemInstance); 70 70 } 71 71 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMove.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveAbsoluteAttribute.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveMaker.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 32 32 [Item("N-Move Maker", "Performs an N-Move.")] 33 33 [StorableClass] 34 public class NMoveMaker : SingleSuccessorOperator, I AssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker {34 public class NMoveMaker : SingleSuccessorOperator, IQualityAwareGQAPOperator, IMoveQualityAwareGQAPOperator, IGQAPNMoveOperator, IMoveMaker { 35 35 36 36 public ILookupParameter<IntegerVector> AssignmentParameter { … … 40 40 get { return (ILookupParameter<NMove>)Parameters["Move"]; } 41 41 } 42 ILookupParameter<BoolValue> IQualityAwareGQAPOperator.MaximizationParameter {43 get { return MaximizationParameter; }44 }45 ILookupParameter<BoolValue> IMoveQualityAwareGQAPOperator.MaximizationParameter {46 get { return MaximizationParameter; }47 }48 public ILookupParameter<BoolValue> MaximizationParameter {49 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }50 }51 42 public ILookupParameter<DoubleValue> QualityParameter { 52 43 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 53 44 } 54 public ILookupParameter<DoubleValue> FlowDistanceQualityParameter { 55 get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; } 56 } 57 public ILookupParameter<DoubleValue> InstallationQualityParameter { 58 get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; } 59 } 60 public ILookupParameter<DoubleValue> OverbookedCapacityParameter { 61 get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; } 45 public ILookupParameter<Evaluation> EvaluationParameter { 46 get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; } 62 47 } 63 48 public ILookupParameter<DoubleValue> MoveQualityParameter { 64 49 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 65 50 } 66 public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { 67 get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; } 68 } 69 public ILookupParameter<DoubleValue> MoveInstallationQualityParameter { 70 get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; } 71 } 72 public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { 73 get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; } 51 public ILookupParameter<Evaluation> MoveEvaluationParameter { 52 get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; } 74 53 } 75 54 … … 81 60 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 82 61 Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription)); 83 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); 84 Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription)); 85 Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription)); 86 Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription)); 87 Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription)); 62 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "")); 63 Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription)); 88 64 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription)); 89 Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription)); 90 Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription)); 91 Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription)); 65 Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription)); 92 66 } 93 67 … … 104 78 Apply(AssignmentParameter.ActualValue, MoveParameter.ActualValue); 105 79 QualityParameter.ActualValue.Value = MoveQualityParameter.ActualValue.Value; 106 FlowDistanceQualityParameter.ActualValue.Value = MoveFlowDistanceQualityParameter.ActualValue.Value; 107 InstallationQualityParameter.ActualValue.Value = MoveInstallationQualityParameter.ActualValue.Value; 108 OverbookedCapacityParameter.ActualValue.Value = MoveOverbookedCapacityParameter.ActualValue.Value; 80 EvaluationParameter.ActualValue = MoveEvaluationParameter.ActualValue; 109 81 return base.Apply(); 110 82 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveTabuChecker.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 33 33 [StorableClass] 34 34 public class NMoveTabuChecker : SingleSuccessorOperator, ITabuChecker, 35 I AssignmentAwareGQAPOperator, IGQAPNMoveOperator, IMoveQualityAwareGQAPOperator {35 IGQAPNMoveOperator, IMoveQualityAwareGQAPOperator { 36 36 public override bool CanChangeName { 37 37 get { return false; } 38 } 39 public IValueLookupParameter<BoolValue> MaximizationParameter { 40 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 38 41 } 39 42 public ILookupParameter<NMove> MoveParameter { … … 49 52 get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; } 50 53 } 51 public IValueLookupParameter<BoolValue> MaximizationParameter {52 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }53 }54 ILookupParameter<BoolValue> IMoveQualityAwareGQAPOperator.MaximizationParameter {55 get { return MaximizationParameter; }56 }57 54 public ILookupParameter<DoubleValue> MoveQualityParameter { 58 55 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 59 56 } 60 public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { 61 get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; } 62 } 63 public ILookupParameter<DoubleValue> MoveInstallationQualityParameter { 64 get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; } 65 } 66 public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { 67 get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; } 57 public ILookupParameter<Evaluation> MoveEvaluationParameter { 58 get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; } 68 59 } 69 60 public IValueParameter<BoolValue> UseAspirationCriterionParameter { … … 81 72 public NMoveTabuChecker() 82 73 : base() { 74 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "")); 83 75 Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription)); 84 76 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 85 77 Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list contains previous move attributes.")); 86 78 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "Declares if a move is tabu or not.")); 87 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));88 79 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", GQAPNMoveEvaluator.MoveQualityDescription)); 89 Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription)); 90 Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription)); 91 Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription)); 80 Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription)); 92 81 Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether moves can be aspired.", new BoolValue(true))); 93 82 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/NMoveTabuMaker.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 26 25 using HeuristicLab.Optimization.Operators; … … 31 30 [Item("N-Move TabuMaker", "Declares an N-Move tabu.")] 32 31 [StorableClass] 33 public class NMoveTabuMaker : TabuMaker, IGQAPNMoveOperator, IAssignmentAwareGQAPOperator, 34 IMoveQualityAwareGQAPOperator { 32 public class NMoveTabuMaker : TabuMaker, IGQAPNMoveOperator, IMoveQualityAwareGQAPOperator { 35 33 36 34 public ILookupParameter<IntegerVector> AssignmentParameter { … … 40 38 get { return (ILookupParameter<NMove>)Parameters["Move"]; } 41 39 } 42 ILookupParameter<BoolValue> IMoveQualityAwareGQAPOperator.MaximizationParameter { 43 get { return (ILookupParameter<BoolValue>)MaximizationParameter; } 44 } 45 public ILookupParameter<DoubleValue> MoveFlowDistanceQualityParameter { 46 get { return (ILookupParameter<DoubleValue>)Parameters["MoveFlowDistanceQuality"]; } 47 } 48 public ILookupParameter<DoubleValue> MoveInstallationQualityParameter { 49 get { return (ILookupParameter<DoubleValue>)Parameters["MoveInstallationQuality"]; } 50 } 51 public ILookupParameter<DoubleValue> MoveOverbookedCapacityParameter { 52 get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverbookedCapacity"]; } 40 public ILookupParameter<Evaluation> MoveEvaluationParameter { 41 get { return (ILookupParameter<Evaluation>)Parameters["MoveEvaluation"]; } 53 42 } 54 43 … … 60 49 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 61 50 Parameters.Add(new LookupParameter<NMove>("Move", GQAPNMoveGenerator.MoveDescription)); 62 Parameters.Add(new LookupParameter<DoubleValue>("MoveFlowDistanceQuality", GQAPNMoveEvaluator.MoveFlowDistanceQualityDescription)); 63 Parameters.Add(new LookupParameter<DoubleValue>("MoveInstallationQuality", GQAPNMoveEvaluator.MoveInstallationQualityDescription)); 64 Parameters.Add(new LookupParameter<DoubleValue>("MoveOverbookedCapacity", GQAPNMoveEvaluator.MoveOverbookedCapacityDescription)); 51 Parameters.Add(new LookupParameter<Evaluation>("MoveEvaluation", GQAPNMoveEvaluator.MoveEvaluationDescription)); 65 52 } 66 53 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveMultiMoveGenerator.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 32 32 [Item("Stochastic N-Move MultiMoveGenerator", "Randomly samples a number of N-Moves.")] 33 33 [StorableClass] 34 public class StochasticNMoveMultiMoveGenerator : GQAPNMoveGenerator, ICapacitiesAwareGQAPOperator, IStochasticOperator, IMultiMoveGenerator { 35 36 public ILookupParameter<DoubleArray> CapacitiesParameter { 37 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 38 } 34 public class StochasticNMoveMultiMoveGenerator : GQAPNMoveGenerator, IStochasticOperator, IMultiMoveGenerator { 35 39 36 public ILookupParameter<IRandom> RandomParameter { 40 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 50 47 : base() { 51 48 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator that should be used.")); 52 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));53 49 Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate.")); 54 50 } … … 58 54 } 59 55 60 public static IEnumerable<NMove> Generate(IRandom random, IntegerVector assignment, int n, DoubleArray capacities, int sampleSize) {56 public static IEnumerable<NMove> Generate(IRandom random, IntegerVector assignment, int n, GQAPInstance problemInstance, int sampleSize) { 61 57 for (int i = 0; i < sampleSize; i++) 62 yield return StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, n, capacities);58 yield return StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, n, problemInstance.Capacities); 63 59 } 64 60 65 public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n ) {66 return Generate(RandomParameter.ActualValue, assignment, n, CapacitiesParameter.ActualValue, SampleSizeParameter.ActualValue.Value);61 public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n, GQAPInstance problemInstance) { 62 return Generate(RandomParameter.ActualValue, assignment, n, problemInstance, SampleSizeParameter.ActualValue.Value); 67 63 } 68 64 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Moves/StochasticNMoveSingleMoveGenerator.cs
r7505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 32 32 [Item("Stochastic N-Move SingleMoveGenerator", "Randomly samples a single N-Move.")] 33 33 [StorableClass] 34 public class StochasticNMoveSingleMoveGenerator : GQAPNMoveGenerator, ICapacitiesAwareGQAPOperator, IStochasticOperator, ISingleMoveGenerator { 35 36 public ILookupParameter<DoubleArray> CapacitiesParameter { 37 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 38 } 34 public class StochasticNMoveSingleMoveGenerator : GQAPNMoveGenerator, IStochasticOperator, ISingleMoveGenerator { 35 39 36 public ILookupParameter<IRandom> RandomParameter { 40 37 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 47 44 : base() { 48 45 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator that should be used.")); 49 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));50 46 } 51 47 … … 73 69 } 74 70 75 public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n ) {76 yield return GenerateUpToN(RandomParameter.ActualValue, assignment, n, CapacitiesParameter.ActualValue);71 public override IEnumerable<NMove> GenerateMoves(IntegerVector assignment, int n, GQAPInstance problemInstance) { 72 yield return GenerateUpToN(RandomParameter.ActualValue, assignment, n, problemInstance.Capacities); 77 73 } 78 74 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/CordeauCrossover.cs
r15490 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 34 34 [StorableClass] 35 35 public class CordeauCrossover : GQAPCrossover, 36 IQualitiesAwareGQAPOperator, IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, 37 IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 38 IExpectedRandomQualityAwareGQAPOperator { 36 IQualitiesAwareGQAPOperator, IProblemInstanceAwareGQAPOperator { 39 37 40 38 public ILookupParameter<BoolValue> MaximizationParameter { … … 44 42 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 45 43 } 46 public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter { 47 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; } 48 } 49 public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter { 50 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; } 51 } 52 public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter { 53 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; } 54 } 55 public ILookupParameter<DoubleMatrix> WeightsParameter { 56 get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; } 57 } 58 public ILookupParameter<DoubleMatrix> DistancesParameter { 59 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 60 } 61 public ILookupParameter<DoubleMatrix> InstallationCostsParameter { 62 get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; } 63 } 64 public ILookupParameter<DoubleArray> DemandsParameter { 65 get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; } 66 } 67 public ILookupParameter<DoubleArray> CapacitiesParameter { 68 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 69 } 70 public IValueLookupParameter<DoubleValue> TransportationCostsParameter { 71 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 72 } 73 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 74 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 75 } 76 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 77 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 44 public IScopeTreeLookupParameter<Evaluation> EvaluationParameter { 45 get { return (IScopeTreeLookupParameter<Evaluation>)Parameters["Evaluation"]; } 78 46 } 79 47 public ILookupParameter<IntValue> EvaluatedSolutionsParameter { … … 88 56 public CordeauCrossover() 89 57 : base() { 90 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); 91 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription, 1)); 92 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription, 1)); 93 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription, 1)); 94 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription, 1)); 95 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription)); 96 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription)); 97 Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription)); 98 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); 99 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 100 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 101 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 102 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator used to evaluate solutions.")); 58 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "")); 59 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality of the parents", 1)); 60 Parameters.Add(new ScopeTreeLookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription, 1)); 103 61 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions.")); 104 62 } … … 108 66 } 109 67 110 public static IntegerVector Apply(IRandom random, BoolValuemaximization,68 public static IntegerVector Apply(IRandom random, bool maximization, 111 69 IntegerVector parent1, DoubleValue quality1, 112 70 IntegerVector parent2, DoubleValue quality2, 113 DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 114 DoubleArray demands, DoubleArray capacities, 115 double transportationCosts, double expectedRandomQuality, IGQAPEvaluator evaluator, IntValue evaluatedSolutions) { 71 GQAPInstance problemInstance, IntValue evaluatedSolutions) { 72 var distances = problemInstance.Distances; 73 var capacities = problemInstance.Capacities; 74 var demands = problemInstance.Demands; 75 116 76 var medianDistances = Enumerable.Range(0, distances.Rows).Select(x => distances.GetRow(x).Median()).ToArray(); 117 77 … … 120 80 121 81 bool onefound = false; 122 double fbest, fbestAttempt = maximization .Value? double.MinValue : double.MaxValue;82 double fbest, fbestAttempt = maximization ? double.MinValue : double.MaxValue; 123 83 IntegerVector bestAttempt = null; 124 84 IntegerVector result = null; 125 85 126 86 fbest = quality1.Value; 127 if (maximization .Value&& quality1.Value < quality2.Value128 || !maximization .Value&& quality1.Value > quality2.Value) {87 if (maximization && quality1.Value < quality2.Value 88 || !maximization && quality1.Value > quality2.Value) { 129 89 var temp = parent1; 130 90 parent1 = parent2; … … 140 100 TryRandomAssignment(random, demands, capacities, m, n, cap, child, ref unassigned); 141 101 if (unassigned == 0) { 142 var childFit = evaluator.Evaluate(child, weights, distances, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality);102 var childFit = problemInstance.ToSingleObjective(problemInstance.Evaluate(child)); 143 103 evaluatedSolutions.Value++; 144 if (maximization .Value&& childFit >= fbest145 || !maximization .Value&& childFit <= fbest) {104 if (maximization && childFit >= fbest 105 || !maximization && childFit <= fbest) { 146 106 fbest = childFit; 147 107 result = child; 148 108 onefound = true; 149 109 } 150 if (!onefound && (maximization .Value && fbestAttempt < childFit || !maximization.Value&& fbestAttempt > childFit)) {110 if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) { 151 111 bestAttempt = child; 152 112 fbestAttempt = childFit; … … 162 122 RandomAssignment(random, demands, capacities, m, n, cap, child, ref unassigned); 163 123 164 var childFit = evaluator.Evaluate(child, weights, distances, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality);124 var childFit = problemInstance.ToSingleObjective(problemInstance.Evaluate(child)); 165 125 evaluatedSolutions.Value++; 166 126 if (childFit < fbest) { … … 170 130 } 171 131 172 if (!onefound && (maximization .Value && fbestAttempt < childFit || !maximization.Value&& fbestAttempt > childFit)) {132 if (!onefound && (maximization && fbestAttempt < childFit || !maximization && fbestAttempt > childFit)) { 173 133 bestAttempt = child; 174 134 fbestAttempt = childFit; … … 237 197 } 238 198 239 protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) { 199 protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents, 200 GQAPInstance problemInstance) { 240 201 if (parents == null) throw new ArgumentNullException("parents"); 241 202 if (parents.Length != 2) throw new ArgumentException(Name + " works only with exactly two parents."); 242 203 243 204 var qualities = QualityParameter.ActualValue; 244 return Apply(random, MaximizationParameter.ActualValue ,205 return Apply(random, MaximizationParameter.ActualValue.Value, 245 206 parents[0], qualities[0], 246 207 parents[1], qualities[1], 247 WeightsParameter.ActualValue, DistancesParameter.ActualValue, InstallationCostsParameter.ActualValue, 248 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue, 249 TransportationCostsParameter.ActualValue.Value, ExpectedRandomQualityParameter.ActualValue.Value, 250 EvaluatorParameter.ActualValue, EvaluatedSolutionsParameter.ActualValue); 208 problemInstance, 209 EvaluatedSolutionsParameter.ActualValue); 251 210 } 252 211 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/DiscreteLocationCrossover.cs
r7813 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.IntegerVectorEncoding; 28 using HeuristicLab.Parameters;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 29 using HeuristicLab.Random; … … 33 32 [Item("DiscreteLocationCrossover", "Combines the assignment to locations from various parents.")] 34 33 [StorableClass] 35 public class DiscreteLocationCrossover : GQAPCrossover, ICapacitiesAwareGQAPOperator { 36 37 public ILookupParameter<DoubleArray> CapacitiesParameter { 38 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 39 } 34 public class DiscreteLocationCrossover : GQAPCrossover { 40 35 41 36 [StorableConstructor] … … 45 40 public DiscreteLocationCrossover() 46 41 : base() { 47 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));48 42 } 49 43 … … 88 82 } 89 83 90 protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) { 91 return Apply(random, parents, CapacitiesParameter.ActualValue); 84 protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents, 85 GQAPInstance problemInstance) { 86 return Apply(random, parents, problemInstance.Capacities); 92 87 } 93 88 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPCrossover.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 46 46 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 47 47 } 48 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 49 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 50 } 48 51 49 52 [StorableConstructor] … … 55 58 Parameters.Add(new LookupParameter<IntegerVector>("Child", "The child vector resulting from the crossover.", "Assignment")); 56 59 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators.")); 60 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 57 61 } 58 62 59 63 public sealed override IOperation Apply() { 60 ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue );64 ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue, ProblemInstanceParameter.ActualValue); 61 65 return base.Apply(); 62 66 } 63 67 64 protected abstract IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents );68 protected abstract IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents, GQAPInstance problemInstance); 65 69 } 66 70 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/GQAPPathRelinking.cs
r15492 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 34 34 [Item("GQAPPathRelinking", "Operator that performs path relinking between two solutions. It is 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.")] 35 35 [StorableClass] 36 public class GQAPPathRelinking : GQAPCrossover, IQualitiesAwareGQAPOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, 37 IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, ITransportationCostsAwareGQAPOperator, 38 IExpectedRandomQualityAwareGQAPOperator, IEvaluatorAwareGQAPOperator { 36 public class GQAPPathRelinking : GQAPCrossover, IQualitiesAwareGQAPOperator { 39 37 40 public ILookupParameter<BoolValue> MaximizationParameter {41 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }42 }43 38 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 44 39 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 45 40 } 46 public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter { 47 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; } 48 } 49 public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter { 50 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; } 51 } 52 public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter { 53 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; } 54 } 55 public ILookupParameter<DoubleArray> DemandsParameter { 56 get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; } 57 } 58 public ILookupParameter<DoubleArray> CapacitiesParameter { 59 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 60 } 61 public ILookupParameter<DoubleMatrix> WeightsParameter { 62 get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; } 63 } 64 public ILookupParameter<DoubleMatrix> DistancesParameter { 65 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 66 } 67 public ILookupParameter<DoubleMatrix> InstallationCostsParameter { 68 get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; } 69 } 70 public IValueLookupParameter<DoubleValue> TransportationCostsParameter { 71 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 72 } 73 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 74 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 75 } 76 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 77 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 41 public IScopeTreeLookupParameter<Evaluation> EvaluationParameter { 42 get { return (IScopeTreeLookupParameter<Evaluation>)Parameters["Evaluation"]; } 78 43 } 79 44 … … 87 52 public GQAPPathRelinking() 88 53 : base() { 89 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); 90 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription)); 91 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription)); 92 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription)); 93 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription)); 94 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); 95 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 96 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription)); 97 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription)); 98 Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription)); 99 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 100 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 101 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions.")); 54 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "")); 55 Parameters.Add(new ScopeTreeLookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription)); 102 56 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))); 103 57 } … … 107 61 } 108 62 109 public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents, BoolValue maximization, ItemArray<DoubleValue> qualities, 110 ItemArray<DoubleValue> flowDistanceQualities, ItemArray<DoubleValue> installationQualities, ItemArray<DoubleValue> overbookedCapacities, 111 DoubleArray demands, DoubleArray capacities, DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, 112 DoubleValue transportationCosts, DoubleValue expectedRandomQuality, DoubleValue candidateSizeFactor, IGQAPEvaluator evaluator) { 63 public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents, ItemArray<DoubleValue> qualities, 64 GQAPInstance problemInstance, double candidateSizeFactor) { 113 65 if (random == null) throw new ArgumentNullException("random", "No IRandom provider is given."); 114 66 if (parents == null || !parents.Any()) throw new ArgumentException("No parents given for path relinking.", "parents"); … … 117 69 if (qualities == null || qualities.Length == 0) throw new ArgumentException("The qualities are not given.", "qualities"); 118 70 if (qualities.Length != parents.Length) throw new ArgumentException(String.Format("There are a different number of parents ({0}) than quality values ({1})", parents.Length.ToString(), qualities.Length.ToString())); 119 71 120 72 var source = parents[0]; 121 73 var target = parents[1]; 122 74 IntegerVector result; 123 double resultQuality , resultFDQ, resultIQ, resultOC;75 double resultQuality; 124 76 125 int betterParent = 1; 126 if ((maximization.Value && qualities[0].Value >= qualities[1].Value) 127 || (!maximization.Value && qualities[0].Value <= qualities[1].Value)) 128 betterParent = 0; 77 int betterParent = (qualities[0].Value <= qualities[1].Value) ? 0 : 1; 129 78 130 79 result = (IntegerVector)parents[betterParent].Clone(); 131 80 resultQuality = qualities[betterParent].Value; 132 resultFDQ = flowDistanceQualities[betterParent].Value; 133 resultIQ = installationQualities[betterParent].Value; 134 resultOC = overbookedCapacities[betterParent].Value; 81 82 var demands = problemInstance.Demands; 83 var capacities = problemInstance.Capacities; 84 85 var cmp = new IntegerVectorEqualityComparer(); 135 86 136 87 var pi_prime = (IntegerVector)source.Clone(); … … 140 91 141 92 while (phi.Any()) { 142 var B = new List< GQAPSolution>();93 var B = new List<Tuple<GQAPSolution, double>>(); 143 94 foreach (var v in phi) { 144 95 int oldLocation = pi_prime[v]; 145 96 pi_prime[v] = target[v]; 146 var pi2 = makeFeasible(random, pi_prime, v, nonFix, demands, capacities);97 var pi2 = MakeFeasible(random, pi_prime, v, nonFix, demands, capacities); 147 98 pi_prime[v] = oldLocation; 148 99 149 double currentFDQ, currentIQ, currentOC; 150 evaluator.Evaluate(pi2, weights, distances, installationCosts, demands, capacities, 151 out currentFDQ, out currentIQ, out currentOC); 100 var currentEval = problemInstance.Evaluate(pi2); 152 101 153 if (currentOC <= 0.0) { 154 var quality = evaluator.GetFitness(currentFDQ, currentIQ, currentOC, 155 transportationCosts.Value, expectedRandomQuality.Value); 156 var solution = new GQAPSolution(pi2, new DoubleValue(quality), new DoubleValue(currentFDQ), 157 new DoubleValue(currentIQ), new DoubleValue(currentOC)); 158 if (B.Count >= candidateSizeFactor.Value * phi.Count) { 102 if (currentEval.ExcessDemand <= 0.0) { 103 var quality = problemInstance.ToSingleObjective(currentEval); 104 105 var solution = new GQAPSolution(pi2, currentEval); 106 if (B.Count >= candidateSizeFactor * phi.Count) { 159 107 int mostSimilarIndex = -1; 160 108 double mostSimilarValue = 1.0; 161 109 for (int i = 0; i < B.Count; i++) { 162 if ( IsBetter(maximization.Value, solution.Quality.Value, B[i].Quality.Value)) {163 var similarity = HammingSimilarityCalculator.CalculateSimilarity(solution.Assignment, B[i]. Assignment);110 if (quality < B[i].Item2) { 111 var similarity = HammingSimilarityCalculator.CalculateSimilarity(solution.Assignment, B[i].Item1.Assignment); 164 112 if (similarity == 1.0) { 165 113 mostSimilarIndex = -1; … … 172 120 } 173 121 if (mostSimilarIndex >= 0) 174 B[mostSimilarIndex] = solution;122 B[mostSimilarIndex] = Tuple.Create(solution, quality); 175 123 } else { 176 124 bool contains = false; 177 125 foreach (var b in B) { 178 if ( !IntegerVectorEqualityComparer.GetDifferingIndices(solution.Assignment, b.Assignment).Any()) {126 if (cmp.Equals(solution.Assignment, b.Item1.Assignment)) { 179 127 contains = true; 180 128 break; 181 129 } 182 130 } 183 if (!contains) B.Add( solution);131 if (!contains) B.Add(Tuple.Create(solution, quality)); 184 132 } 185 133 } 186 134 } 187 135 if (B.Any()) { 188 GQAPSolution pi; 189 if (maximization.Value) pi = B.SampleProportional(random, 1, B.Select(x => x.Quality.Value), false).First(); 190 else pi = B.SampleProportional(random, 1, B.Select(x => 1.0 / x.Quality.Value), false).First(); 191 var diff = IntegerVectorEqualityComparer.GetDifferingIndices(pi.Assignment, target); 136 var pi = B.SampleProportional(random, 1, B.Select(x => 1.0 / x.Item2), false).First(); 137 var diff = IntegerVectorEqualityComparer.GetDifferingIndices(pi.Item1.Assignment, target); 192 138 var I = phi.Except(diff); 193 139 var i = I.SampleRandom(random); 194 140 fix.Add(i); 195 141 nonFix.Remove(i); 196 pi_prime = pi.Assignment; 197 if (IsBetter(maximization.Value, pi.Quality.Value, resultQuality)) { 198 result = pi.Assignment; 199 resultQuality = pi.Quality.Value; 200 resultFDQ = pi.FlowDistanceQuality.Value; 201 resultIQ = pi.InstallationQuality.Value; 202 resultOC = pi.OverbookedCapacity.Value; 142 pi_prime = pi.Item1.Assignment; 143 if (pi.Item2 < resultQuality) { 144 result = pi.Item1.Assignment; 145 resultQuality = pi.Item2; 203 146 } 204 147 } else return result; … … 209 152 } 210 153 211 protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) { 212 return Apply(random, parents, MaximizationParameter.ActualValue, QualityParameter.ActualValue, FlowDistanceQualityParameter.ActualValue, 213 InstallationQualityParameter.ActualValue, OverbookedCapacityParameter.ActualValue, DemandsParameter.ActualValue, 214 CapacitiesParameter.ActualValue, WeightsParameter.ActualValue, DistancesParameter.ActualValue, 215 InstallationCostsParameter.ActualValue, TransportationCostsParameter.ActualValue, 216 ExpectedRandomQualityParameter.ActualValue, CandidateSizeFactorParameter.Value, 217 EvaluatorParameter.ActualValue); 154 protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents, 155 GQAPInstance problemInstance) { 156 return Apply(random, parents, QualityParameter.ActualValue, problemInstance, 157 CandidateSizeFactorParameter.Value.Value); 218 158 } 219 159 220 private static IntegerVector makeFeasible(IRandom random, IntegerVector assignment, int equipment, HashSet<int> nonFix, DoubleArray demands, DoubleArray capacities, int maximumTries = 1000) {160 private static IntegerVector MakeFeasible(IRandom random, IntegerVector assignment, int equipment, HashSet<int> nonFix, DoubleArray demands, DoubleArray capacities, int maximumTries = 1000) { 221 161 int l = assignment[equipment]; 222 162 var slack = ComputeSlack(assignment, demands, capacities); … … 250 190 return slack; 251 191 } 252 253 private static bool IsBetter(bool maximization, double quality, double otherQuality) {254 return maximization && quality > otherQuality || !maximization && quality < otherQuality;255 }256 192 } 257 193 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Crossovers/MultiGQAPCrossover.cs
r11505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [Item("MultiGQAPCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 36 36 [StorableClass] 37 public class MultiGQAPCrossover : StochasticMultiBranch<IGQAPCrossover>, IGQAPCrossover {37 public class MultiGQAPCrossover : StochasticMultiBranch<IGQAPCrossover>, IGQAPCrossover, IProblemInstanceAwareGQAPOperator, IStochasticOperator { 38 38 public override bool CanChangeName { 39 39 get { return false; } … … 49 49 get { return (ILookupParameter<IntegerVector>)Parameters["Child"]; } 50 50 } 51 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 52 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 53 } 51 54 52 55 [StorableConstructor] … … 57 60 Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Parents", "The parent vectors which should be crossed.", "Assignment")); 58 61 Parameters.Add(new LookupParameter<IntegerVector>("Child", "The child vector resulting from the crossover.", "Assignment")); 62 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 63 59 64 foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IGQAPCrossover))) { 60 65 if (!typeof(MultiOperator<IGQAPCrossover>).IsAssignableFrom(type)) … … 79 84 foreach (var op in Operators.OfType<IGQAPCrossover>()) { 80 85 op.ParentsParameter.ActualName = ParentsParameter.Name; 86 op.ParentsParameter.Hidden = true; 81 87 op.ChildParameter.ActualName = ChildParameter.Name; 88 op.ChildParameter.Hidden = true; 82 89 } 83 90 foreach (var op in Operators.OfType<IStochasticOperator>()) { 84 91 op.RandomParameter.ActualName = RandomParameter.Name; 92 op.RandomParameter.Hidden = true; 93 } 94 foreach (var op in Operators.OfType<IProblemInstanceAwareGQAPOperator>()) { 95 op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name; 96 op.ProblemInstanceParameter.Hidden = true; 85 97 } 86 98 } … … 88 100 public override IOperation InstrumentedApply() { 89 101 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one crossover to choose from."); 90 return base. Apply();102 return base.InstrumentedApply(); 91 103 } 92 104 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [Item("ApproximateLocalSearch", "The approximate local search is 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 ApproximateLocalSearch : SingleSuccessorOperator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, 38 IWeightsAwareGQAPOperator, IDistancesAwareGQAPOperator, IInstallationCostsAwareGQAPOperator, 39 ITransportationCostsAwareGQAPOperator, IExpectedRandomQualityAwareGQAPOperator, 40 IAssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, 41 IEvaluatorAwareGQAPOperator, IStochasticOperator { 37 public class ApproximateLocalSearch : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, 38 IQualityAwareGQAPOperator, IGQAPLocalImprovementOperator, IStochasticOperator { 42 39 public IProblem Problem { get; set; } 43 40 public Type ProblemType { 44 get { return typeof(G eneralizedQuadraticAssignmentProblem); }41 get { return typeof(GQAP); } 45 42 } 46 43 47 public ILookupParameter<DoubleArray> DemandsParameter { 48 get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; } 49 } 50 public ILookupParameter<DoubleArray> CapacitiesParameter { 51 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 52 } 53 public ILookupParameter<DoubleMatrix> WeightsParameter { 54 get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; } 55 } 56 public ILookupParameter<DoubleMatrix> DistancesParameter { 57 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 58 } 59 public ILookupParameter<DoubleMatrix> InstallationCostsParameter { 60 get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; } 61 } 62 public IValueLookupParameter<DoubleValue> TransportationCostsParameter { 63 get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; } 64 } 65 public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter { 66 get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; } 44 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 45 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 67 46 } 68 47 public ILookupParameter<IntegerVector> AssignmentParameter { 69 48 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } 70 49 } 71 public ILookupParameter<BoolValue> MaximizationParameter {72 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }73 }74 50 public ILookupParameter<DoubleValue> QualityParameter { 75 51 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 76 52 } 77 public ILookupParameter<DoubleValue> FlowDistanceQualityParameter { 78 get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; } 79 } 80 public ILookupParameter<DoubleValue> InstallationQualityParameter { 81 get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; } 82 } 83 public ILookupParameter<DoubleValue> OverbookedCapacityParameter { 84 get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; } 53 public ILookupParameter<Evaluation> EvaluationParameter { 54 get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; } 85 55 } 86 56 public IValueLookupParameter<IntValue> MaximumIterationsParameter { … … 102 72 get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; } 103 73 } 104 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {105 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }106 }107 74 108 75 [StorableConstructor] … … 111 78 public ApproximateLocalSearch() 112 79 : base() { 113 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); 114 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 115 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription)); 116 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription)); 117 Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription)); 118 Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription)); 119 Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription)); 80 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 120 81 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 121 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); 122 Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription)); 123 Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription)); 124 Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription)); 125 Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription)); 82 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "")); 83 Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription)); 126 84 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations that should be performed.")); 127 85 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solution equivalents.")); … … 130 88 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))); 131 89 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."));133 90 } 134 91 … … 145 102 /// <param name="assignment">The equipment-location assignment vector.</param> 146 103 /// <param name="quality">The solution quality.</param> 147 /// <param name="flowDistanceQuality">The quality regarding the flow-distance criteria.</param> 148 /// <param name="installationQuality">The quality regarding the installation costs.</param> 149 /// <param name="overbookedCapacity">The sum of the overbooked capacities relative to the capacity of each location.</param> 104 /// <param name="evaluation">The evaluation result of the solution.</param> 150 105 /// <param name="maxCLS">The maximum number of candidates that should be found in each step.</param> 151 106 /// <param name="maximumIterations">The maximum number of iterations that should be performed each time the candidate list is generated.</param> 152 /// <param name="weights">The weights matrix describes the flows between the equipments.</param> 153 /// <param name="distances">The distances matrix describes the distances between the locations at which the equipment can be installed.</param> 154 /// <param name="installationCosts">The installation costs matrix describes the installation costs of installing equipment i at location j</param> 155 /// <param name="demands">The demands vector describes the space requirements of the equipments.</param> 156 /// <param name="capacities">The capacities vector describes the available space at the locations.</param> 157 /// <param name="transportationCosts">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.</param> 158 /// <param name="overbookedCapacityPenalty"></param> 107 /// <param name="problemInstance">The problem instance that contains the data.</param> 159 108 /// <param name="oneMoveProbability">The probability for performing a 1-move, which is the opposite of performing a 2-move.</param> 160 109 public static void Apply(IRandom random, IntegerVector assignment, 161 DoubleValue quality, DoubleValue flowDistanceQuality, DoubleValue installationQuality, DoubleValue overbookedCapacity, 162 IntValue maxCLS, IntValue maximumIterations, 163 DoubleMatrix weights, DoubleMatrix distances, DoubleMatrix installationCosts, DoubleArray demands, DoubleArray capacities, 164 DoubleValue transportationCosts, DoubleValue expectedRandomQuality, PercentValue oneMoveProbability, 165 IGQAPEvaluator evaluator) { 166 110 DoubleValue quality, ref Evaluation evaluation, IntValue maxCLS, IntValue maximumIterations, 111 GQAPInstance problemInstance, PercentValue oneMoveProbability) { 112 var capacities = problemInstance.Capacities; 113 var demands = problemInstance.Demands; 114 //var weights = problemInstance.Weights; 115 //var distances = problemInstance.Distances; 116 //var installationCosts = problemInstance.InstallationCosts; 167 117 while (true) { 168 118 int count = 0; 169 var CLS = new List<Tuple<NMove, double, double, double, double>>();119 var CLS = new List<Tuple<NMove, double, Evaluation>>(); 170 120 double sum = 0.0; 171 121 do { … … 174 124 move = StochasticNMoveSingleMoveGenerator.GenerateExactlyN(random, assignment, 1, capacities); 175 125 else move = StochasticNMoveSingleMoveGenerator.GenerateExactlyN(random, assignment, 2, capacities); 126 127 var moveEval = GQAPNMoveEvaluator.Evaluate(move, assignment, evaluation, problemInstance); 128 double moveQuality = problemInstance.ToSingleObjective(moveEval); 176 129 177 double moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity; 178 GQAPNMoveEvaluator.Evaluate(move, assignment, weights, distances, installationCosts, 179 demands, capacities, evaluator, out moveFlowDistanceQuality, out moveInstallationQuality, out moveOverbookedCapacity); 180 double moveQuality = evaluator.GetFitness(moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity, 181 transportationCosts.Value, expectedRandomQuality.Value); 182 183 if (moveOverbookedCapacity <= 0.0 && moveQuality < 0.0) { 184 CLS.Add(Tuple.Create(move, moveQuality, moveFlowDistanceQuality, moveInstallationQuality, moveOverbookedCapacity)); 130 if (moveEval.ExcessDemand <= 0.0 && moveQuality < 0.0) { 131 CLS.Add(Tuple.Create(move, moveQuality, moveEval)); 185 132 sum += 1.0 / moveQuality; 186 133 } … … 202 149 NMoveMaker.Apply(assignment, selected.Item1); 203 150 quality.Value += selected.Item2; 204 flowDistanceQuality.Value += selected.Item3; 205 installationQuality.Value += selected.Item4; 206 overbookedCapacity.Value += selected.Item5; 151 evaluation = selected.Item3; 207 152 } 208 153 } … … 210 155 211 156 public override IOperation Apply() { 157 var evaluation = EvaluationParameter.ActualValue; 212 158 Apply(RandomParameter.ActualValue, 213 159 AssignmentParameter.ActualValue, 214 160 QualityParameter.ActualValue, 215 FlowDistanceQualityParameter.ActualValue, 216 InstallationQualityParameter.ActualValue, 217 OverbookedCapacityParameter.ActualValue, 161 ref evaluation, 218 162 MaximumCandidateListSizeParameter.ActualValue, 219 163 MaximumIterationsParameter.ActualValue, 220 WeightsParameter.ActualValue, DistancesParameter.ActualValue, 221 InstallationCostsParameter.ActualValue, 222 DemandsParameter.ActualValue, CapacitiesParameter.ActualValue, 223 TransportationCostsParameter.ActualValue, 224 ExpectedRandomQualityParameter.ActualValue, 225 OneMoveProbabilityParameter.ActualValue, 226 EvaluatorParameter.ActualValue); 164 ProblemInstanceParameter.ActualValue, 165 OneMoveProbabilityParameter.ActualValue); 166 EvaluationParameter.ActualValue = evaluation; 227 167 return base.Apply(); 228 168 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/DemandEquivalentSwapEquipmentManipluator.cs
r7813 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.IntegerVectorEncoding; 29 using HeuristicLab.Parameters;30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 30 using HeuristicLab.Random; … … 35 34 [Item("DemandEquivalentSwapEquipmentManipluator", "Swaps equipment X from location A with as much equipments from location B that the demand of X is less than or equal to the demand of the swapped equipments in B.")] 36 35 [StorableClass] 37 public class DemandEquivalentSwapEquipmentManipluator : GQAPManipulator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator { 38 39 public ILookupParameter<DoubleArray> DemandsParameter { 40 get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; } 41 } 42 public ILookupParameter<DoubleArray> CapacitiesParameter { 43 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 44 } 36 public class DemandEquivalentSwapEquipmentManipluator : GQAPManipulator { 45 37 46 38 [StorableConstructor] … … 49 41 public DemandEquivalentSwapEquipmentManipluator() 50 42 : base() { 51 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));52 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));53 43 } 54 44 … … 85 75 } 86 76 87 protected override void Manipulate(IRandom random, IntegerVector vector ) {88 Apply(random, vector, CapacitiesParameter.ActualValue, DemandsParameter.ActualValue);77 protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) { 78 Apply(random, vector, problemInstance.Capacities, problemInstance.Demands); 89 79 } 90 80 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/GQAPManipulator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 [Item("GQAPManipulator", "A base class for operators that manipulate assignment vectors of the GeneralizedQuadraticAssignment problems.")] 32 32 [StorableClass] 33 public abstract class GQAPManipulator : SingleSuccessorOperator, IGQAPManipulator, I AssignmentAwareGQAPOperator, IStochasticOperator {33 public abstract class GQAPManipulator : SingleSuccessorOperator, IGQAPManipulator, IProblemInstanceAwareGQAPOperator, IStochasticOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } … … 39 39 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } 40 40 } 41 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 42 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 43 } 44 41 45 public ILookupParameter<IRandom> RandomParameter { 42 46 get { return (LookupParameter<IRandom>)Parameters["Random"]; } … … 49 53 : base() { 50 54 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 55 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 51 56 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 52 57 } 53 58 54 59 public sealed override IOperation Apply() { 55 Manipulate(RandomParameter.ActualValue, AssignmentParameter.ActualValue );60 Manipulate(RandomParameter.ActualValue, AssignmentParameter.ActualValue, ProblemInstanceParameter.ActualValue); 56 61 return base.Apply(); 57 62 } 58 63 59 protected abstract void Manipulate(IRandom random, IntegerVector integerVector );64 protected abstract void Manipulate(IRandom random, IntegerVector integerVector, GQAPInstance problemInstance); 60 65 } 61 66 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/MultiGQAPManipulator.cs
r11505 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [Item("MultiGQAPManipulator", "Randomly selects and applies one of its manipulators every time it is called.")] 36 36 [StorableClass] 37 public class MultiGQAPManipulator : StochasticMultiBranch<IGQAPManipulator>, IGQAPManipulator { 37 public class MultiGQAPManipulator : StochasticMultiBranch<IGQAPManipulator>, IGQAPManipulator, 38 IProblemInstanceAwareGQAPOperator { 38 39 public override bool CanChangeName { 39 40 get { return false; } … … 46 47 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } 47 48 } 49 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 50 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 51 } 48 52 49 53 [StorableConstructor] … … 53 57 : base() { 54 58 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 59 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 60 55 61 foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IGQAPManipulator))) { 56 62 if (!typeof(MultiOperator<IGQAPManipulator>).IsAssignableFrom(type)) … … 73 79 74 80 private void Parameterize() { 75 foreach (var op in Operators.OfType<IGQAPManipulator>()) 81 foreach (var op in Operators.OfType<IGQAPManipulator>()) { 76 82 op.AssignmentParameter.ActualName = AssignmentParameter.Name; 77 foreach (var op in Operators.OfType<IStochasticOperator>()) 83 op.AssignmentParameter.Hidden = true; 84 } 85 foreach (var op in Operators.OfType<IStochasticOperator>()) { 78 86 op.RandomParameter.ActualName = RandomParameter.Name; 87 op.RandomParameter.Hidden = true; 88 } 89 foreach (var op in Operators.OfType<IProblemInstanceAwareGQAPOperator>()) { 90 op.ProblemInstanceParameter.ActualName = ProblemInstanceParameter.Name; 91 op.ProblemInstanceParameter.Hidden = true; 92 } 79 93 } 80 94 81 95 public override IOperation InstrumentedApply() { 82 96 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one manipulator to choose from."); 83 return base. Apply();97 return base.InstrumentedApply(); 84 98 } 85 99 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/RelocateEquipmentManipluator.cs
r7813 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.IntegerVectorEncoding; 29 using HeuristicLab.Parameters;30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 30 using HeuristicLab.Random; … … 35 34 [Item("RelocateEquipmentManipluator", "Relocates a random equipment from an overstuffed location to a random one with space or a random equipment if constraints are satisfied.")] 36 35 [StorableClass] 37 public class RelocateEquipmentManipluator : GQAPManipulator, IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator { 38 39 public ILookupParameter<DoubleArray> CapacitiesParameter { 40 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 41 } 42 public ILookupParameter<DoubleArray> DemandsParameter { 43 get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; } 44 } 45 36 public class RelocateEquipmentManipluator : GQAPManipulator { 37 46 38 [StorableConstructor] 47 39 protected RelocateEquipmentManipluator(bool deserializing) : base(deserializing) { } … … 49 41 public RelocateEquipmentManipluator() 50 42 : base() { 51 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));52 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));53 43 } 54 44 … … 92 82 } 93 83 94 protected override void Manipulate(IRandom random, IntegerVector vector ) {95 Apply(random, vector, CapacitiesParameter.ActualValue, DemandsParameter.ActualValue);84 protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) { 85 Apply(random, vector, problemInstance.Capacities, problemInstance.Demands); 96 86 } 97 87 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/SwapEquipmentManipluator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 56 56 } 57 57 58 protected override void Manipulate(IRandom random, IntegerVector vector ) {58 protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) { 59 59 Apply(random, vector); 60 60 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Manipulators/SwapLocationManipulator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 26 using HeuristicLab.Encodings.IntegerVectorEncoding; 28 using HeuristicLab.Parameters;29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 28 … … 33 31 [Item("SwapLocationManipluator", "Swaps two locations by exchanging all equipments between the locations.")] 34 32 [StorableClass] 35 public class SwapLocationManipluator : GQAPManipulator, ICapacitiesAwareGQAPOperator { 36 37 public ILookupParameter<DoubleArray> CapacitiesParameter { 38 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 39 } 40 33 public class SwapLocationManipluator : GQAPManipulator { 34 41 35 [StorableConstructor] 42 36 protected SwapLocationManipluator(bool deserializing) : base(deserializing) { } … … 44 38 public SwapLocationManipluator() 45 39 : base() { 46 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));47 40 } 48 41 … … 72 65 } 73 66 74 protected override void Manipulate(IRandom random, IntegerVector vector ) {75 Apply(random, vector, CapacitiesParameter.ActualValue.Length);67 protected override void Manipulate(IRandom random, IntegerVector vector, GQAPInstance problemInstance) { 68 Apply(random, vector, problemInstance.Capacities.Length); 76 69 } 77 70 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/PopulationReducers/GQAPQualitySimilarityReducer.cs
r15492 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 34 34 [Item("GQAPQualitySimilarityReducer", "Reduces two populations two one by using quality and similarity information to obtain a population of high quality, but also diverse solutions.")] 35 35 [StorableClass] 36 public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, I AssignmentAwareGQAPOperator, IQualityAwareGQAPOperator, IPopulationReducer {36 public class GQAPQualitySimilarityReducer : SingleSuccessorOperator, IQualityAwareGQAPOperator, IPopulationReducer { 37 37 public ILookupParameter<IntegerVector> AssignmentParameter { 38 38 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } 39 }40 public ILookupParameter<BoolValue> MaximizationParameter {41 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }42 39 } 43 40 public ILookupParameter<DoubleValue> QualityParameter { 44 41 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 45 42 } 46 public ILookupParameter<DoubleValue> FlowDistanceQualityParameter { 47 get { return (ILookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; } 48 } 49 public ILookupParameter<DoubleValue> InstallationQualityParameter { 50 get { return (ILookupParameter<DoubleValue>)Parameters["InstallationQuality"]; } 51 } 52 public ILookupParameter<DoubleValue> OverbookedCapacityParameter { 53 get { return (ILookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; } 43 public ILookupParameter<Evaluation> EvaluationParameter { 44 get { return (ILookupParameter<Evaluation>)Parameters["Evaluation"]; } 54 45 } 55 46 public ILookupParameter<IntValue> MinimumPopulationSizeParameter { … … 66 57 : base() { 67 58 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 68 Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription)); 69 Parameters.Add(new LookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription)); 70 Parameters.Add(new LookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription)); 71 Parameters.Add(new LookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription)); 72 Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription)); 59 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "")); 60 Parameters.Add(new LookupParameter<Evaluation>("Evaluation", GQAP.EvaluationDescription)); 73 61 Parameters.Add(new LookupParameter<IntValue>("MinimumPopulationSize", "The size of the population that should not be undershot.")); 74 62 Parameters.Add(new LookupParameter<IntValue>("MaximumPopulationSize", "The size of the population that should not be surpassed.")); … … 83 71 string qualityName = QualityParameter.TranslatedName; 84 72 int populationSize = MaximumPopulationSizeParameter.ActualValue.Value; 85 bool maximization = MaximizationParameter.ActualValue.Value;86 73 87 74 IScope remaining = ExecutionContext.Scope.SubScopes[0]; … … 108 95 } else { 109 96 var replacement = population.Select((v, i) => new { V = v, Index = i }) 110 .Where(x => (maximization && x.V.Quality < candidate.Quality) 111 || (!maximization && x.V.Quality > candidate.Quality)); 97 .Where(x => x.V.Quality > candidate.Quality); 112 98 if (replacement.Any()) { 113 99 replacement.OrderBy(x => similarities[x.Index]).ToArray(); -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/Shakers/NMoveShakingOperator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 32 32 [Item("NMoveShakingOperator", "Performs a number of shaking operations that increase in strength.")] 33 33 [StorableClass] 34 public class NMoveShakingOperator : SingleSuccessorOperator, I AssignmentAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator {34 public class NMoveShakingOperator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, IMultiNeighborhoodShakingOperator, IStochasticOperator { 35 35 36 37 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 38 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 39 } 36 40 public ILookupParameter<IntegerVector> AssignmentParameter { 37 41 get { return (ILookupParameter<IntegerVector>)Parameters["Assignment"]; } 38 }39 public ILookupParameter<DoubleArray> CapacitiesParameter {40 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }41 42 } 42 43 public IValueLookupParameter<IntValue> CurrentNeighborhoodIndexParameter { … … 54 55 protected NMoveShakingOperator(NMoveShakingOperator original, Cloner cloner) : base(original, cloner) { } 55 56 public NMoveShakingOperator() { 57 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 56 58 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription)); 57 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));58 59 Parameters.Add(new ValueLookupParameter<IntValue>("CurrentNeighborhoodIndex", "The index of the operator that should be applied (k).")); 59 60 Parameters.Add(new LookupParameter<IntValue>("NeighborhoodCount", "The number of operators that are available.")); … … 68 69 var random = RandomParameter.ActualValue; 69 70 var assignment = AssignmentParameter.ActualValue; 70 var capacities = CapacitiesParameter.ActualValue;71 var capacities = ProblemInstanceParameter.ActualValue.Capacities; 71 72 72 73 if (NeighborhoodCountParameter.ActualValue == null) -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Plugin.cs.frame
r13418 r15504 37 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 38 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] 39 [PluginDependency("HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common", "3.3")]40 39 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 41 40 [PluginDependency("HeuristicLab.Random", "3.3")] -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Properties/AssemblyInfo.cs.frame
r7345 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 32 32 [assembly: AssemblyCompany("HEAL")] 33 33 [assembly: AssemblyProduct("HeuristicLab")] 34 [assembly: AssemblyCopyright("(c) 2002-201 1HEAL")]34 [assembly: AssemblyCopyright("(c) 2002-2017 HEAL")] 35 35 [assembly: AssemblyTrademark("")] 36 36 [assembly: AssemblyCulture("")] … … 55 55 // [assembly: AssemblyVersion("1.0.*")] 56 56 [assembly: AssemblyVersion("3.3.0.0")] 57 [assembly: AssemblyFileVersion("3.3. 6.$WCREV$")]57 [assembly: AssemblyFileVersion("3.3.14.$WCREV$")] -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GQAPSolutionCreator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 [Item("GQAPSolutionCreator", "Base class for solution creators of the Generalized Quadratic Assignment Problem.")] 32 32 [StorableClass] 33 public abstract class GQAPSolutionCreator : SingleSuccessorOperator, I DemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IGQAPSolutionCreator {33 public abstract class GQAPSolutionCreator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, IGQAPSolutionCreator { 34 34 35 35 #region Parameter Descriptions … … 37 37 #endregion 38 38 39 public ILookupParameter<IntegerVector> AssignmentParameter {40 get { return (ILookupParameter<IntegerVector>)Parameters[" Assignment"]; }39 public ILookupParameter<IntegerVector> IntegerVectorParameter { 40 get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; } 41 41 } 42 public ILookupParameter< DoubleArray> DemandsParameter {43 get { return (ILookupParameter< DoubleArray>)Parameters["Demands"]; }42 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 43 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 44 44 } 45 public ILookupParameter<DoubleArray> CapacitiesParameter { 46 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 45 public IValueLookupParameter<IntValue> LengthParameter { 46 get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; } 47 } 48 public IValueLookupParameter<IntMatrix> BoundsParameter { 49 get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; } 47 50 } 48 51 … … 53 56 public GQAPSolutionCreator() 54 57 : base() { 55 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", AssignmentDescription)); 56 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); 57 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 58 Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", AssignmentDescription)); 59 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 60 Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector.") { Hidden = true }); 61 Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "") { Hidden = true }); 58 62 } 59 63 60 64 public override IOperation Apply() { 61 AssignmentParameter.ActualValue = CreateSolution(DemandsParameter.ActualValue, CapacitiesParameter.ActualValue);65 IntegerVectorParameter.ActualValue = CreateSolution(ProblemInstanceParameter.ActualValue); 62 66 return base.Apply(); 63 67 } 64 68 65 protected abstract IntegerVector CreateSolution( DoubleArray demands, DoubleArray capacities);69 protected abstract IntegerVector CreateSolution(GQAPInstance problemInstance); 66 70 } 67 71 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GQAPStochasticSolutionCreator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 26 25 using HeuristicLab.Optimization; … … 46 45 } 47 46 48 protected sealed override IntegerVector CreateSolution( DoubleArray demands, DoubleArray capacities) {49 return CreateRandomSolution(RandomParameter.ActualValue, demands, capacities);47 protected sealed override IntegerVector CreateSolution(GQAPInstance problemInstance) { 48 return CreateRandomSolution(RandomParameter.ActualValue, problemInstance); 50 49 } 51 50 52 protected abstract IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities);51 protected abstract IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance); 53 52 } 54 53 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GreedyRandomizedSolutionCreator.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 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, 38 IEvaluatorAwareGQAPOperator { 37 public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator { 39 38 40 39 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 43 42 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 44 43 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 }46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }48 44 } 49 45 … … 56 52 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))); 57 53 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."));59 54 } 60 55 … … 63 58 } 64 59 65 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, 66 IGQAPEvaluator evaluator, 60 public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance, 67 61 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancelToken) { 62 var demands = problemInstance.Demands; 63 var capacities = problemInstance.Capacities; 68 64 int tries = 0; 69 65 var assignment = new Dictionary<int, int>(demands.Length); … … 125 121 slack[l] -= demands[f]; 126 122 } 127 double violation = evaluator.EvaluateOverbooking(slack, capacities);123 double violation = slack.Select(x => x < 0 ? -x : 0).Sum(); 128 124 if (violation < minViolation) { 129 125 bestAssignment = assignment; … … 139 135 } 140 136 141 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 142 return CreateSolution(random, demands, capacities, 143 EvaluatorParameter.ActualValue, 137 protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) { 138 return CreateSolution(random, problemInstance, 144 139 MaximumTriesParameter.ActualValue.Value, 145 140 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [Item("RandomButFeasibleSolutionCreator", "Creates a random, but feasible solution to the Generalized Quadratic Assignment Problem.")] 36 36 [StorableClass] 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator { 39 38 40 39 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 43 42 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 44 43 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 }46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }48 44 } 49 45 … … 55 51 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))); 56 52 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."));58 53 } 59 54 … … 62 57 } 63 58 64 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, 65 DoubleArray capacities, IGQAPEvaluator evaluator, 59 public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance, 66 60 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) { 61 var capacities = problemInstance.Capacities; 62 var demands = problemInstance.Demands; 67 63 IntegerVector result = null; 68 64 bool isFeasible = false; … … 87 83 slack[assignment[equipment]] -= demands[equipment]; 88 84 } 89 double violation = evaluator.EvaluateOverbooking(slack, capacities);85 double violation = slack.Select(x => x < 0 ? -x : 0).Sum(); 90 86 isFeasible = violation == 0; 91 87 if (isFeasible || violation < minViolation) { … … 97 93 } 98 94 99 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 100 return CreateSolution(random, demands, capacities, 101 EvaluatorParameter.ActualValue, 95 protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) { 96 return CreateSolution(random, problemInstance, 102 97 MaximumTriesParameter.ActualValue.Value, 103 98 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/SlackMinimizationSolutionCreator.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 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, 38 IEvaluatorAwareGQAPOperator { 37 public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator { 39 38 40 39 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 50 49 get { return (IValueLookupParameter<IntValue>)Parameters["RandomWalkLength"]; } 51 50 } 52 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {53 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }54 }55 51 56 52 [StorableConstructor] … … 63 59 Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3))); 64 60 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."));66 61 } 67 62 … … 70 65 } 71 66 72 [StorableHook(HookType.AfterDeserialization)] 73 private void AfterDeserialization() { 74 if (!Parameters.ContainsKey("Depth")) { 75 Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3))); 76 } 77 if (!Parameters.ContainsKey("RandomWalkLength")) { 78 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))); 79 } 80 } 67 public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance, 68 int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) { 69 var capacities = problemInstance.Capacities; 70 var demands = problemInstance.Demands; 81 71 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) {85 72 IntegerVector result = null; 86 73 bool isFeasible = false; … … 125 112 } 126 113 } else RandomFeasibleWalk(random, assignment, demands, slack, randomWalkLength); 127 double violation = evaluator.EvaluateOverbooking(slack, capacities);114 double violation = slack.Select(x => x < 0 ? -x : 0).Sum(); 128 115 isFeasible = violation == 0; 129 116 if (isFeasible || violation < minViolation) { … … 182 169 } 183 170 184 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 185 return CreateSolution(random, demands, capacities, 186 EvaluatorParameter.ActualValue, 171 protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) { 172 return CreateSolution(random, problemInstance, 187 173 DepthParameter.ActualValue.Value, 188 174 MaximumTriesParameter.ActualValue.Value, -
branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs
r15490 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 var provider = new CordeauGQAPInstanceProvider(); 36 36 var instance = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name == "20-15-75")); 37 var gqap = new G eneralizedQuadraticAssignmentProblem();37 var gqap = new GQAP(); 38 38 gqap.Load(instance); 39 39 var evaluator = gqap.Evaluator; … … 41 41 for (int i = 0; i < 100; i++) { 42 42 var random = new MersenneTwister((uint)i); 43 var parent1 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap. Demands, gqap.Capacities, gqap.Evaluator, 100, true, CancellationToken.None);44 var parent2 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap. Demands, gqap.Capacities, gqap.Evaluator, 100, true, CancellationToken.None);43 var parent1 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.ProblemInstance, 100, true, CancellationToken.None); 44 var parent2 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.ProblemInstance, 100, true, CancellationToken.None); 45 45 46 46 try { 47 47 CordeauCrossover.Apply(random, gqap.Maximization, 48 48 parent1, 49 new DoubleValue(gqap.Evaluat or.Evaluate(parent1, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)),49 new DoubleValue(gqap.Evaluate(parent1)), 50 50 parent2, 51 new DoubleValue(gqap.Evaluat or.Evaluate(parent2, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)),52 gqap. Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality, gqap.Evaluator,51 new DoubleValue(gqap.Evaluate(parent2)), 52 gqap.ProblemInstance, 53 53 new IntValue(0)); 54 54 } catch { -
branches/GeneralizedQAP/UnitTests/GQAPNMoveEvaluatorTest.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 public class GQAPNMoveEvaluatorTest { 36 36 private const int Equipments = 10, Locations = 5; 37 private static DoubleMatrix symmetricWeights, asymmetricWeights, nonZeroDiagonalWeights; 38 private static DoubleMatrix symmetricDistances, asymmetricDistances, nonZeroDiagonalDistances; 39 private static DoubleMatrix installationCosts; 40 private static DoubleArray demands, capacities; 41 private static double transportationCosts, overbookedCapacityPenalty; 37 private static GQAPInstance symmetricInstance, asymmetricInstance, nonZeroDiagonalInstance; 42 38 private static IntegerVector assignment; 43 39 private static MersenneTwister random; … … 58 54 public static void MyClassInitialize(TestContext testContext) { 59 55 random = new MersenneTwister(); 60 symmetricDistances = new DoubleMatrix(Locations, Locations);61 symmetricWeights = new DoubleMatrix(Equipments, Equipments);62 asymmetricDistances = new DoubleMatrix(Locations, Locations);63 asymmetricWeights = new DoubleMatrix(Equipments, Equipments);64 nonZeroDiagonalDistances = new DoubleMatrix(Locations, Locations);65 nonZeroDiagonalWeights = new DoubleMatrix(Equipments, Equipments);56 var symmetricDistances = new DoubleMatrix(Locations, Locations); 57 var symmetricWeights = new DoubleMatrix(Equipments, Equipments); 58 var asymmetricDistances = new DoubleMatrix(Locations, Locations); 59 var asymmetricWeights = new DoubleMatrix(Equipments, Equipments); 60 var nonZeroDiagonalDistances = new DoubleMatrix(Locations, Locations); 61 var nonZeroDiagonalWeights = new DoubleMatrix(Equipments, Equipments); 66 62 for (int i = 0; i < Equipments - 1; i++) { 67 63 for (int j = i + 1; j < Equipments; j++) { … … 86 82 nonZeroDiagonalDistances[i, i] = random.Next(Locations * 100); 87 83 } 88 installationCosts = new DoubleMatrix(Equipments, Locations);84 var installationCosts = new DoubleMatrix(Equipments, Locations); 89 85 for (int i = 0; i < Equipments; i++) { 90 86 for (int j = 0; j < Locations; j++) { … … 92 88 } 93 89 } 94 demands = new DoubleArray(Equipments);90 var demands = new DoubleArray(Equipments); 95 91 for (int i = 0; i < Equipments; i++) { 96 92 demands[i] = random.Next(1, 10); 97 93 } 98 capacities = new DoubleArray(Locations);94 var capacities = new DoubleArray(Locations); 99 95 for (int j = 0; j < Locations; j++) { 100 96 capacities[j] = random.Next(1, 10) * ((double)Equipments / (double)Locations) * 1.5; … … 107 103 nonZeroDiagonalWeights[index, index] = random.Next(1, Equipments * 100); 108 104 109 transportationCosts = random.NextDouble() * 10;110 overbookedCapacityPenalty = 1000 * random.NextDouble() + 100;105 var transportationCosts = random.NextDouble() * 10; 106 var overbookedCapacityPenalty = 1000 * random.NextDouble() + 100; 111 107 assignment = new IntegerVector(Equipments, random, 0, Locations); 108 109 symmetricInstance = new GQAPInstance() { 110 Capacities = capacities, 111 Demands = demands, 112 InstallationCosts = installationCosts, 113 PenaltyLevel = overbookedCapacityPenalty, 114 TransportationCosts = transportationCosts, 115 Weights = symmetricWeights, 116 Distances = symmetricDistances 117 }; 118 asymmetricInstance = new GQAPInstance() { 119 Capacities = capacities, 120 Demands = demands, 121 InstallationCosts = installationCosts, 122 PenaltyLevel = overbookedCapacityPenalty, 123 TransportationCosts = transportationCosts, 124 Weights = asymmetricWeights, 125 Distances = asymmetricDistances 126 }; 127 nonZeroDiagonalInstance = new GQAPInstance() { 128 Capacities = capacities, 129 Demands = demands, 130 InstallationCosts = installationCosts, 131 PenaltyLevel = overbookedCapacityPenalty, 132 TransportationCosts = transportationCosts, 133 Weights = nonZeroDiagonalWeights, 134 Distances = nonZeroDiagonalDistances 135 }; 112 136 } 113 137 #endregion … … 119 143 [TestMethod()] 120 144 public void EvaluateTest() { 121 var evaluator = new GQAPAdditivePenaltyEvaluator();122 145 for (int i = 0; i < 500; i++) { 123 NMove currentMove = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, 3, capacities);146 NMove currentMove = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, 3, symmetricInstance.Capacities); 124 147 IntegerVector prevAssignment = (IntegerVector)assignment.Clone(); 125 148 NMoveMaker.Apply(assignment, currentMove); 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); 149 var beforeEval = symmetricInstance.Evaluate(prevAssignment); 150 double before = symmetricInstance.ToSingleObjective(beforeEval); 151 double after = Evaluate(symmetricInstance, assignment); 152 double moveDiff = symmetricInstance.ToSingleObjective( 153 GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, symmetricInstance) 154 ) - symmetricInstance.ToSingleObjective(beforeEval); 129 155 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on symmetric matrices: " + Environment.NewLine 130 156 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 131 157 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); 158 beforeEval = asymmetricInstance.Evaluate(prevAssignment); 159 before = asymmetricInstance.ToSingleObjective(beforeEval); 160 after = Evaluate(asymmetricInstance, assignment); 161 moveDiff = asymmetricInstance.ToSingleObjective( 162 GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, asymmetricInstance) 163 ) - asymmetricInstance.ToSingleObjective(beforeEval); 135 164 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on asymmetric matrices: " + Environment.NewLine 136 165 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 137 166 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); 167 beforeEval = nonZeroDiagonalInstance.Evaluate(prevAssignment); 168 before = nonZeroDiagonalInstance.ToSingleObjective(beforeEval); 169 after = Evaluate(nonZeroDiagonalInstance, assignment); 170 moveDiff = nonZeroDiagonalInstance.ToSingleObjective( 171 GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, nonZeroDiagonalInstance) 172 ) - nonZeroDiagonalInstance.ToSingleObjective(beforeEval); 141 173 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on non-zero diagonal matrices: " + Environment.NewLine 142 174 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 143 175 } 144 176 } 177 178 private double Evaluate(GQAPInstance instance, IntegerVector assignment) { 179 return instance.ToSingleObjective(instance.Evaluate(assignment)); 180 } 145 181 } 146 182 } -
branches/GeneralizedQAP/UnitTests/Properties/AssemblyInfo.cs
r7412 r15504 1 1 using System.Reflection; 2 using System.Runtime.CompilerServices;3 2 using System.Runtime.InteropServices; 4 3 … … 9 8 [assembly: AssemblyDescription("")] 10 9 [assembly: AssemblyConfiguration("")] 11 [assembly: AssemblyCompany(" Microsoft")]10 [assembly: AssemblyCompany("HEAL")] 12 11 [assembly: AssemblyProduct("UnitTests")] 13 [assembly: AssemblyCopyright(" Copyright © Microsoft 2012")]12 [assembly: AssemblyCopyright("(c) 2002-2017 HEAL")] 14 13 [assembly: AssemblyTrademark("")] 15 14 [assembly: AssemblyCulture("")]
Note: See TracChangeset
for help on using the changeset viewer.