- Timestamp:
- 08/27/14 10:53:57 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.Orienteering
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.cs
r11267 r11311 63 63 } else { 64 64 orienteeringSolutionView.Content = new OrienteeringSolution( 65 Content.BestKnownSolution, Content.Coordinates, Content.StartingPoint, Content.TerminusPoint, Content.Scores, Content.BestKnownQuality );65 Content.BestKnownSolution, Content.Coordinates, Content.StartingPoint, Content.TerminusPoint, Content.Scores, Content.BestKnownQuality, penalty: null); 66 66 } 67 67 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringSolutionView.cs
r11276 r11311 42 42 protected override void DeregisterContentEvents() { 43 43 Content.QualityChanged -= new EventHandler(Content_QualityChanged); 44 Content.PenaltyChanged -= new EventHandler(Content_PenaltyChanged); 44 45 Content.CoordinatesChanged -= new EventHandler(Content_CoordinatesChanged); 45 46 Content.StartingPointChanged -= new EventHandler(Content_StartingPointChanged); … … 52 53 base.RegisterContentEvents(); 53 54 Content.QualityChanged += new EventHandler(Content_QualityChanged); 55 Content.PenaltyChanged += new EventHandler(Content_PenaltyChanged); 54 56 Content.CoordinatesChanged += new EventHandler(Content_CoordinatesChanged); 55 57 Content.StartingPointChanged += new EventHandler(Content_StartingPointChanged); … … 114 116 tour[i] = points[integerVector[i]]; 115 117 } 116 graphics.DrawLines(Pens.Black, tour); 118 bool visualizePenalty = Content.Penalty != null && Content.Penalty.Value > 0; 119 graphics.DrawLines(visualizePenalty ? Pens.Red : Pens.Black, tour); 117 120 } 118 121 … … 154 157 qualityViewHost.Content = Content.Quality; 155 158 } 159 private void Content_PenaltyChanged(object sender, EventArgs e) { 160 if (InvokeRequired) 161 Invoke(new EventHandler(Content_PenaltyChanged), sender, e); 162 else 163 GenerateImage(); 164 } 156 165 private void Content_CoordinatesChanged(object sender, EventArgs e) { 157 166 if (InvokeRequired) -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Analyzers/BestOrienteeringSolutionAnalyser.cs
r11307 r11311 55 55 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 56 56 } 57 public ScopeTreeLookupParameter<DoubleValue> PenaltyParameter { 58 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Penalty"]; } 59 } 57 60 public LookupParameter<OrienteeringSolution> BestSolutionParameter { 58 61 get { return (LookupParameter<OrienteeringSolution>)Parameters["BestSolution"]; } … … 66 69 public LookupParameter<IntegerVector> BestKnownSolutionParameter { 67 70 get { return (LookupParameter<IntegerVector>)Parameters["BestKnownSolution"]; } 71 } 72 public LookupParameter<DoubleValue> BestKnownSolutionPenaltyParameter { 73 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownSolutionPenalty"]; } 68 74 } 69 75 … … 82 88 Parameters.Add(new LookupParameter<DoubleArray>("Scores", "The scores of the points.")); 83 89 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Orienteering solutions which should be analyzed.")); 90 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Penalty", "The applied penalty of the Orienteering solutions.")); 84 91 Parameters.Add(new LookupParameter<OrienteeringSolution>("BestSolution", "The best Orienteering solution.")); 85 92 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best Orienteering solution should be stored.")); 86 93 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this Orienteering instance.")); 87 94 Parameters.Add(new LookupParameter<IntegerVector>("BestKnownSolution", "The best known solution of this Orienteering instance.")); 95 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownSolutionPenalty", "The penalty of the best known solution of this Orienteering instance.")); 88 96 } 89 97 … … 91 99 var solutions = IntegerVector.ActualValue; 92 100 var qualities = QualityParameter.ActualValue; 101 var penalties = PenaltyParameter.ActualValue; 93 102 var results = ResultsParameter.ActualValue; 94 103 var bestKnownQuality = BestKnownQualityParameter.ActualValue; … … 99 108 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[bestIndex].Value); 100 109 BestKnownSolutionParameter.ActualValue = (IntegerVector)solutions[bestIndex].Clone(); 110 BestKnownSolutionPenaltyParameter.ActualValue = new DoubleValue(penalties[bestIndex].Value); 101 111 } 102 112 … … 113 123 terminusPoint, 114 124 scores, 115 new DoubleValue(qualities[bestIndex].Value)); 125 new DoubleValue(qualities[bestIndex].Value), 126 new DoubleValue(penalties[bestIndex].Value)); 116 127 BestSolutionParameter.ActualValue = solution; 117 128 results.Add(new Result("Best Orienteering Solution", solution)); 129 results.Add(new Result("BestKnownSolutionPenalty", solution.Penalty)); 118 130 } else { 119 131 if (solution.Quality.Value < qualities[bestIndex].Value) { … … 122 134 solution.IntegerVector = (IntegerVector)solutions[bestIndex].Clone(); 123 135 solution.Quality.Value = qualities[bestIndex].Value; 136 solution.Penalty.Value = penalties[bestIndex].Value; 137 results["BestKnownSolutionPenalty"].Value = solution.Penalty; 124 138 } 125 139 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Evaluators/OrienteeringEvaluator.cs
r11236 r11311 20 20 #endregion 21 21 22 using System.Linq; 23 using System.Security.Permissions; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; … … 30 32 namespace HeuristicLab.Problems.Orienteering { 31 33 public class OrienteeringEvaluator : InstrumentedOperator, IOrienteeringEvaluator { 34 35 #region ParameterProperties 32 36 public ILookupParameter<DoubleValue> QualityParameter { 33 37 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 38 } 39 public ILookupParameter<DoubleValue> PenaltyParameter { 40 get { return (ILookupParameter<DoubleValue>)Parameters["Penalty"]; } 41 } 42 public ILookupParameter<DoubleValue> DistancePenaltyFactorParameter { 43 get { return (ILookupParameter<DoubleValue>)Parameters["DistancePenaltyFactor"]; } 34 44 } 35 45 public ILookupParameter<IntegerVector> IntegerVectorParameter { … … 39 49 get { return (ILookupParameter<DoubleArray>)Parameters["Scores"]; } 40 50 } 51 public ILookupParameter<DistanceMatrix> DistanceMatrixParameter { 52 get { return (ILookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 53 } 54 public ILookupParameter<DoubleValue> MaximumDistanceParameter { 55 get { return (ILookupParameter<DoubleValue>)Parameters["MaximumDistance"]; } 56 } 57 public ILookupParameter<DoubleValue> FixedPenaltyParameter { 58 get { return (ILookupParameter<DoubleValue>)Parameters["FixedPenalty"]; } 59 } 60 #endregion 41 61 42 62 [StorableConstructor] … … 53 73 : base() { 54 74 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the Orienteering solution.")); 75 Parameters.Add(new LookupParameter<DoubleValue>("Penalty", "The applied penalty")); 76 Parameters.Add(new ValueLookupParameter<DoubleValue>("DistancePenaltyFactor", "The penalty applied per distance violation.", new DoubleValue(0))); 77 55 78 Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The Orienteering Solution given in path representation.")); 56 79 Parameters.Add(new LookupParameter<DoubleArray>("Scores", "The scores of the points.")); 80 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points.")); 81 Parameters.Add(new LookupParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution.")); 82 Parameters.Add(new LookupParameter<DoubleValue>("FixedPenalty", "The penalty for each visited vertex.")); 57 83 } 58 84 59 85 public class OrienteeringEvaluation { 60 86 public DoubleValue Quality; 87 public DoubleValue Penalty; 61 88 } 62 89 63 public static OrienteeringEvaluation Apply(IntegerVector solution, DoubleArray scores) { 64 // TODO distance penalty 65 double score = 0.0; 90 public static OrienteeringEvaluation Apply(IntegerVector solution, DoubleArray scores, 91 DistanceMatrix distances, DoubleValue maximumDistance, DoubleValue fixedPenalty, DoubleValue distancePenaltyFactor) { 66 92 67 for (int i = 0; i < solution.Length; i++) { 68 score += scores[solution[i]]; 69 } 93 double score = solution.Sum(t => scores[t]); 94 double distance = distances.CalculateTourLength(solution.ToList(), fixedPenalty.Value); 95 96 double distanceViolation = distance - maximumDistance.Value; 97 98 double penalty = 0.0; 99 penalty += distanceViolation > 0 ? distanceViolation * distancePenaltyFactor.Value : 0; 100 101 double quality = score - penalty; 70 102 71 103 return new OrienteeringEvaluation { 72 Quality = new DoubleValue(score) 104 Quality = new DoubleValue(quality), 105 Penalty = new DoubleValue(penalty) 73 106 }; 74 107 } 75 108 76 109 public override IOperation InstrumentedApply() { 77 var evaluation = Apply(IntegerVectorParameter.ActualValue, ScoresParameter.ActualValue); 110 var evaluation = Apply(IntegerVectorParameter.ActualValue, ScoresParameter.ActualValue, 111 DistanceMatrixParameter.ActualValue, MaximumDistanceParameter.ActualValue, 112 FixedPenaltyParameter.ActualValue, DistancePenaltyFactorParameter.ActualValue); 78 113 79 114 QualityParameter.ActualValue = evaluation.Quality; 115 PenaltyParameter.ActualValue = evaluation.Penalty; 80 116 81 117 return base.InstrumentedApply(); -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs
r11307 r11311 90 90 if (quality != null) RegisterQualityEvents(); 91 91 OnQualityChanged(); 92 } 93 } 94 } 95 [Storable] 96 private DoubleValue penalty; 97 public DoubleValue Penalty { 98 get { return penalty; } 99 set { 100 if (penalty != value) { 101 if (penalty != null) DeregisterPenaltyEvents(); 102 penalty = value; 103 if (penalty != null) RegisterPenaltyEvents(); 104 OnPenaltyChanged(); 92 105 } 93 106 } … … 102 115 this.coordinates = cloner.Clone(original.coordinates); 103 116 this.quality = cloner.Clone(original.quality); 117 this.penalty = cloner.Clone(original.penalty); 104 118 Initialize(); 105 119 } 106 120 public OrienteeringSolution(IntegerVector integerVector, DoubleMatrix coordinates, IntValue startingPoint, IntValue terminusPoint, 107 DoubleArray scores, DoubleValue quality )121 DoubleArray scores, DoubleValue quality, DoubleValue penalty) 108 122 : base() { 109 123 this.integerVector = integerVector; … … 113 127 this.scores = scores; 114 128 this.quality = quality; 129 this.penalty = penalty; 115 130 Initialize(); 116 131 } … … 132 147 if (scores != null) RegisterScoresEvents(); 133 148 if (quality != null) RegisterQualityEvents(); 149 if (penalty != null) RegisterPenaltyEvents(); 134 150 } 135 151 … … 177 193 } 178 194 195 public event EventHandler PenaltyChanged; 196 private void OnPenaltyChanged() { 197 var changed = PenaltyChanged; 198 if (changed != null) 199 changed(this, EventArgs.Empty); 200 } 201 179 202 private void RegisterIntegerVectorEvents() { 180 203 IntegerVector.ItemChanged += new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged); … … 219 242 Quality.ValueChanged -= new EventHandler(Quality_ValueChanged); 220 243 } 244 private void RegisterPenaltyEvents() { 245 Penalty.ValueChanged += new EventHandler(Penalty_ValueChanged); 246 } 247 private void DeregisterPenaltyEvents() { 248 Penalty.ValueChanged -= new EventHandler(Penalty_ValueChanged); 249 } 221 250 222 251 private void IntegerVector_ItemChanged(object sender, EventArgs<int> e) { … … 246 275 private void Quality_ValueChanged(object sender, EventArgs e) { 247 276 OnQualityChanged(); 277 } 278 private void Penalty_ValueChanged(object sender, EventArgs e) { 279 OnPenaltyChanged(); 248 280 } 249 281 #endregion
Note: See TracChangeset
for help on using the changeset viewer.