- Timestamp:
- 12/11/17 22:10:01 (7 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
- Property svn:ignore
-
old new 1 *.user 1 2 Plugin.cs 3 bin 2 4 obj 3 bin
-
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/Evaluation.cs
r15504 r15510 1 using System.Linq; 1 using System.Collections.Generic; 2 using System.Linq; 2 3 using HeuristicLab.Common; 3 4 using HeuristicLab.Core; … … 18 19 /// </summary> 19 20 [Storable] 20 public double ExcessDemand { get; set; }21 public double ExcessDemand { get; private set; } 21 22 /// <summary> 22 23 /// The amount of slack at each location, is negative in case of excess demand. … … 26 27 /// </remarks> 27 28 [Storable] 28 public double[] Slack { get; set; } 29 private double[] slack; 30 public IReadOnlyList<double> Slack { 31 get { return slack; } 32 } 29 33 /// <summary> 30 34 /// The quadratic part of the fitness function that represents the flow or transportation costs. 31 35 /// </summary> 32 36 [Storable] 33 public double FlowCosts { get; set; }37 public double FlowCosts { get; private set; } 34 38 /// <summary> 35 39 /// The linear part of the fitness function that represents the installation costs. 36 40 /// </summary> 37 41 [Storable] 38 public double InstallationCosts { get; set; }42 public double InstallationCosts { get; private set; } 39 43 40 44 [StorableConstructor] … … 43 47 : base(original, cloner) { 44 48 ExcessDemand = original.ExcessDemand; 45 if (original. Slack != null)46 Slack = original.Slack.ToArray();49 if (original.slack != null) 50 slack = original.slack.ToArray(); 47 51 FlowCosts = original.FlowCosts; 48 52 InstallationCosts = original.InstallationCosts; 49 53 } 50 public Evaluation() { } 54 public Evaluation(double flowCosts, double installationCosts, double excessDemand, double[] slack) { 55 FlowCosts = flowCosts; 56 InstallationCosts = installationCosts; 57 ExcessDemand = excessDemand; 58 this.slack = slack; 59 } 51 60 52 61 public override IDeepCloneable Clone(Cloner cloner) { -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/GQAPNMoveEvaluator.cs
r15507 r15510 85 85 public static Evaluation Evaluate(NMove move, IntegerVector assignment, Evaluation evaluation, GQAPInstance problemInstance) { 86 86 int moves = move.N; 87 var newEvaluation = new Evaluation() { 88 ExcessDemand = evaluation.ExcessDemand, 89 FlowCosts = evaluation.FlowCosts, 90 InstallationCosts = evaluation.InstallationCosts, 91 Slack = evaluation.Slack.ToArray() 92 }; 87 var excessDemand = evaluation.ExcessDemand; 88 var flowCosts = evaluation.FlowCosts; 89 var installationCosts = evaluation.InstallationCosts; 90 var slack = evaluation.Slack.ToArray(); 91 93 92 foreach (var kvp in move.NewAssignments) { 94 93 int equip = kvp.Key; … … 96 95 int oldLoc = assignment[equip]; 97 96 var equipDemand = problemInstance.Demands[equip]; 98 newEvaluation.InstallationCosts -= problemInstance.InstallationCosts[equip, oldLoc];99 newEvaluation.InstallationCosts += problemInstance.InstallationCosts[equip, newLoc];97 installationCosts -= problemInstance.InstallationCosts[equip, oldLoc]; 98 installationCosts += problemInstance.InstallationCosts[equip, newLoc]; 100 99 for (int j = 0; j < assignment.Length; j++) { 101 100 if (!move.NewAssignments.ContainsKey(j)) { 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];101 flowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, assignment[j]]; 102 flowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]]; 103 flowCosts += problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], newLoc]; 104 flowCosts -= problemInstance.Weights[j, equip] * problemInstance.Distances[assignment[j], oldLoc]; 106 105 } else { 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]];106 flowCosts += problemInstance.Weights[equip, j] * problemInstance.Distances[newLoc, move.NewAssignments[j]]; 107 flowCosts -= problemInstance.Weights[equip, j] * problemInstance.Distances[oldLoc, assignment[j]]; 109 108 } 110 109 } 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]);110 slack[oldLoc] += equipDemand; 111 if (slack[oldLoc] < equipDemand) 112 excessDemand -= Math.Min(equipDemand, equipDemand - slack[oldLoc]); 113 slack[newLoc] -= equipDemand; 114 if (slack[newLoc] < 0) 115 excessDemand += Math.Min(equipDemand, -slack[newLoc]); 117 116 } 118 117 119 return new Evaluation;118 return new Evaluation(flowCosts, installationCosts, excessDemand, slack); 120 119 } 121 120 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAP.cs
r15506 r15510 154 154 } 155 155 var archive = archiveResult.Value as GQAPAssignmentArchive; 156 if (archive == null) archive = new GQAPAssignmentArchive(ProblemInstance); 157 else archive.ProblemInstance = ProblemInstance; 156 if (archive == null) { 157 archive = new GQAPAssignmentArchive(ProblemInstance); 158 archiveResult.Value = archive; 159 } else archive.ProblemInstance = ProblemInstance; 158 160 159 161 var combinedArchive = solutions … … 401 403 402 404 private void InitializeOperators() { 403 Operators.Clear(); 405 Operators.RemoveAll(x => x is ISingleObjectiveMoveOperator); 406 Operators.RemoveAll(x => x is SingleObjectiveImprover); 404 407 Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPOperator>()); 405 Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);406 408 Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>()); 407 409 Operators.Add(new HammingSimilarityCalculator() { SolutionVariableName = Encoding.Name, QualityVariableName = Evaluator.QualityParameter.ActualName }); -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPInstance.cs
r15504 r15510 214 214 slack[assignI] -= demands[i]; 215 215 } 216 return new Evaluation() { 217 ExcessDemand = overbookedCapacity, 218 FlowCosts = flowDistanceQuality, 219 InstallationCosts = installationQuality, 220 Slack = slack 221 }; 216 return new Evaluation(flowDistanceQuality, installationQuality, overbookedCapacity, slack); 222 217 } 223 218
Note: See TracChangeset
for help on using the changeset viewer.