Changeset 11325


Ignore:
Timestamp:
09/01/14 15:56:15 (5 years ago)
Author:
pfleck
Message:

#2208

  • Fixed OrienteeringSolution visualization when start or endpoint are out of range
  • Changed some parameters in OP to FixedValueParameter
  • Added start/terminal index check in OP
Location:
branches/HeuristicLab.Problems.Orienteering
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringProblemView.cs

    r11319 r11325  
    6363      } else {
    6464        orienteeringSolutionView.Content = new OrienteeringSolution(
    65           Content.BestKnownSolution, Content.Coordinates, Content.StartingPoint, Content.TerminalPoint, Content.Scores, Content.BestKnownQuality, penalty: null);
     65          Content.BestKnownSolution, Content.Coordinates, Content.StartingPointParameter.Value, Content.TerminalPointParameter.Value, Content.Scores, Content.BestKnownQuality, penalty: null);
    6666      }
    6767    }
     
    7676    }
    7777    private void StartingPointParameter_ValueChanged(object sender, EventArgs e) {
    78       orienteeringSolutionView.Content.StartingPoint = Content.StartingPoint;
     78      orienteeringSolutionView.Content.StartingPoint.Value = Content.StartingPoint;
    7979    }
    8080    private void TerminalPointParameter_ValueChanged(object sender, EventArgs e) {
    81       orienteeringSolutionView.Content.TerminalPoint = Content.TerminalPoint;
     81      orienteeringSolutionView.Content.TerminalPoint.Value = Content.TerminalPoint;
    8282    }
    8383    private void ScoresParameter_ValueChanged(object sender, EventArgs e) {
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering.Views/3.3/OrienteeringSolutionView.cs

    r11319 r11325  
    134134              Font font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
    135135              var beginSize = graphics.MeasureString("Begin", font);
    136               graphics.DrawString("Begin", font, Brushes.Black, points[startingPoint].X - beginSize.Width, points[startingPoint].Y - beginSize.Height);
    137               graphics.DrawString("End", font, Brushes.Black, points[terminalPoint].X, points[terminalPoint].Y);
     136              if (startingPoint >= 0 && startingPoint < points.Length)
     137                graphics.DrawString("Begin", font, Brushes.Black, points[startingPoint].X - beginSize.Width, points[startingPoint].Y - beginSize.Height);
     138              if (terminalPoint >= 0 && terminalPoint < points.Length)
     139                graphics.DrawString("End", font, Brushes.Black, points[terminalPoint].X, points[terminalPoint].Y);
    138140            }
    139141          } else {
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r11321 r11325  
    4848      get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    4949    }
    50     public ValueParameter<DistanceMatrix> DistanceMatrixParameter {
    51       get { return (ValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
    52     }
    53 
    54     public ValueParameter<IntValue> StartingPointParameter {
    55       get { return (ValueParameter<IntValue>)Parameters["StartingPoint"]; }
    56     }
    57     public ValueParameter<IntValue> TerminalPointParameter {
    58       get { return (ValueParameter<IntValue>)Parameters["TerminalPoint"]; }
    59     }
    60     public ValueParameter<DoubleValue> MaximumDistanceParameter {
    61       get { return (ValueParameter<DoubleValue>)Parameters["MaximumDistance"]; }
    62     }
    63     public ValueParameter<DoubleArray> ScoresParameter {
    64       get { return (ValueParameter<DoubleArray>)Parameters["Scores"]; }
    65     }
    66     public ValueParameter<DoubleValue> PointVisitingCostsParameter {
    67       get { return (ValueParameter<DoubleValue>)Parameters["PointVisitingCosts"]; }
     50    public IValueParameter<DistanceMatrix> DistanceMatrixParameter {
     51      get { return (IValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
     52    }
     53
     54    public IFixedValueParameter<IntValue> StartingPointParameter {
     55      get { return (IFixedValueParameter<IntValue>)Parameters["StartingPoint"]; }
     56    }
     57    public IFixedValueParameter<IntValue> TerminalPointParameter {
     58      get { return (IFixedValueParameter<IntValue>)Parameters["TerminalPoint"]; }
     59    }
     60    public IFixedValueParameter<DoubleValue> MaximumDistanceParameter {
     61      get { return (IFixedValueParameter<DoubleValue>)Parameters["MaximumDistance"]; }
     62    }
     63    public IValueParameter<DoubleArray> ScoresParameter {
     64      get { return (IValueParameter<DoubleArray>)Parameters["Scores"]; }
     65    }
     66    public IFixedValueParameter<DoubleValue> PointVisitingCostsParameter {
     67      get { return (IFixedValueParameter<DoubleValue>)Parameters["PointVisitingCosts"]; }
    6868    }
    6969
     
    8282      set { DistanceMatrixParameter.Value = value; }
    8383    }
    84     public IntValue StartingPoint {
    85       get { return StartingPointParameter.Value; }
    86       set { StartingPointParameter.Value = value; }
    87     }
    88     public IntValue TerminalPoint {
    89       get { return TerminalPointParameter.Value; }
    90       set { TerminalPointParameter.Value = value; }
    91     }
    92     public DoubleValue MaximumDistance {
    93       get { return MaximumDistanceParameter.Value; }
    94       set { MaximumDistanceParameter.Value = value; }
     84    public int StartingPoint {
     85      get { return StartingPointParameter.Value.Value; }
     86      set { StartingPointParameter.Value.Value = value; }
     87    }
     88    public int TerminalPoint {
     89      get { return TerminalPointParameter.Value.Value; }
     90      set { TerminalPointParameter.Value.Value = value; }
     91    }
     92    public double MaximumDistance {
     93      get { return MaximumDistanceParameter.Value.Value; }
     94      set { MaximumDistanceParameter.Value.Value = value; }
    9595    }
    9696    public DoubleArray Scores {
     
    9898      set { ScoresParameter.Value = value; }
    9999    }
    100     public DoubleValue PointVisitingCosts {
    101       get { return PointVisitingCostsParameter.Value; }
    102       set { PointVisitingCostsParameter.Value = value; }
     100    public double PointVisitingCosts {
     101      get { return PointVisitingCostsParameter.Value.Value; }
     102      set { PointVisitingCostsParameter.Value.Value = value; }
    103103    }
    104104    public IntegerVector BestKnownSolution {
     
    126126      Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the points."));
    127127      Parameters.Add(new ValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points."));
    128       Parameters.Add(new ValueParameter<IntValue>("StartingPoint", "Index of the starting point.", new IntValue(0)));
    129       Parameters.Add(new ValueParameter<IntValue>("TerminalPoint", "Index of the ending point.", new IntValue(0)));
    130       Parameters.Add(new ValueParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution."));
     128      Parameters.Add(new FixedValueParameter<IntValue>("StartingPoint", "Index of the starting point.", new IntValue(0)));
     129      Parameters.Add(new FixedValueParameter<IntValue>("TerminalPoint", "Index of the ending point.", new IntValue(0)));
     130      Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumDistance", "The maximum distance constraint for a Orienteering solution."));
    131131      Parameters.Add(new ValueParameter<DoubleArray>("Scores", "The scores of the points."));
    132       Parameters.Add(new ValueParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point."));
     132      Parameters.Add(new FixedValueParameter<DoubleValue>("PointVisitingCosts", "The costs for visiting a point."));
    133133      Parameters.Add(new OptionalValueParameter<IntegerVector>("BestKnownSolution", "The best known solution of this Orienteering instance."));
    134134
     
    173173      ParameterizeSolutionCreator();
    174174      UpdateDistanceMatrix();
     175      CheckStartingIndex();
     176      CheckTerminalIndex();
    175177    }
    176178    private void CoordinatesValue_ItemChanged(object sender, EventArgs<int, int> e) {
    177179      UpdateDistanceMatrix();
     180      CheckStartingIndex();
     181      CheckTerminalIndex();
    178182    }
    179183    private void CoordinatesValue_Reset(object sender, EventArgs e) {
    180184      ParameterizeSolutionCreator();
    181185      UpdateDistanceMatrix();
    182     }
    183     private void StartingPointParameter_ValueChanged(object sender, EventArgs e) {
    184       ParameterizeEvaluator();
    185       ParameterizeAnalyzer();
    186     }
    187 
    188     private void TerminalPointParameter_ValueChanged(object sender, EventArgs e) {
    189       ParameterizeEvaluator();
    190       ParameterizeAnalyzer();
    191     }
    192     private void MaximumDistanceParameter_ValueChanged(object sender, EventArgs e) {
    193       ParameterizeEvaluator();
    194       ParameterizeAnalyzer();
    195     }
     186      CheckStartingIndex();
     187      CheckTerminalIndex();
     188    }
     189    private void StartingPointParameterValue_ValueChanged(object sender, EventArgs e) {
     190      CheckStartingIndex();
     191    }
     192
     193    private void TerminalPointParameterValue_ValueChanged(object sender, EventArgs e) {
     194      CheckTerminalIndex();
     195    }
     196    private void MaximumDistanceParameterValue_ValueChanged(object sender, EventArgs e) { }
    196197    private void ScoresParameter_ValueChanged(object sender, EventArgs e) {
    197198      ParameterizeEvaluator();
     
    204205      ParameterizeSolutionCreator();
    205206    }
    206     private void PointVisitingCostsParameter_ValueChanged(object sender, EventArgs e) {
    207       ParameterizeEvaluator();
    208       ParameterizeAnalyzer();
    209     }
     207    private void PointVisitingCostsParameterValue_ValueChanged(object sender, EventArgs e) { }
    210208    #endregion
    211209
     
    225223      }
    226224
    227       StartingPointParameter.ValueChanged += StartingPointParameter_ValueChanged;
    228       TerminalPointParameter.ValueChanged += TerminalPointParameter_ValueChanged;
    229       MaximumDistanceParameter.ValueChanged += MaximumDistanceParameter_ValueChanged;
     225      StartingPointParameter.Value.ValueChanged += StartingPointParameterValue_ValueChanged;
     226      TerminalPointParameter.Value.ValueChanged += TerminalPointParameterValue_ValueChanged;
     227      MaximumDistanceParameter.Value.ValueChanged += MaximumDistanceParameterValue_ValueChanged;
     228      PointVisitingCostsParameter.Value.ValueChanged += PointVisitingCostsParameterValue_ValueChanged;
    230229
    231230      ScoresParameter.ValueChanged += ScoresParameter_ValueChanged;
    232231      ScoresParameter.Value.Reset += ScoresValue_Reset;
    233       PointVisitingCostsParameter.ValueChanged += PointVisitingCostsParameter_ValueChanged;
    234232    }
    235233
     
    318316      DistanceMatrix = new DistanceMatrix(distances);
    319317    }
     318    private void CheckStartingIndex() {
     319      if (StartingPoint < 0) StartingPoint = 0;
     320      if (StartingPoint >= DistanceMatrix.Rows) StartingPoint = DistanceMatrix.Rows - 1;
     321    }
     322    private void CheckTerminalIndex() {
     323      if (TerminalPoint < 0) TerminalPoint = 0;
     324      if (TerminalPoint >= DistanceMatrix.Rows) TerminalPoint = DistanceMatrix.Rows - 1;
     325    }
    320326
    321327    private void InitializeInitialOrienteeringInstance() {
     
    330336      DistanceMatrix = CalculateDistanceMatrix(coordinates);
    331337
    332       StartingPoint.Value = 0;
    333       TerminalPoint.Value = 20;
    334       MaximumDistance.Value = 30;
     338      StartingPoint = 0;
     339      TerminalPoint = 20;
     340      MaximumDistance = 30;
    335341
    336342      Scores = new DoubleArray(new double[21] { 0, 20, 20, 30, 15, 15, 10, 20, 20, 20, 15, 10, 10, 25, 40, 40, 30, 30, 50, 30, 0 });
    337343    }
    338344
     345    #region Instance consuming
    339346    public void Load(OPData data) {
    340347      if (data.Coordinates == null && data.Distances == null)
     
    356363        DistanceMatrix = new DistanceMatrix(data.GetDistanceMatrix());
    357364
    358       StartingPoint = new IntValue(data.StartingPoint);
    359       TerminalPoint = new IntValue(data.TerminalPoint);
    360 
    361       PointVisitingCosts = new DoubleValue(data.PointVisitingCosts);
    362       MaximumDistance = new DoubleValue(data.MaximumDistance);
     365      StartingPoint = data.StartingPoint;
     366      TerminalPoint = data.TerminalPoint;
     367
     368      PointVisitingCosts = data.PointVisitingCosts;
     369      MaximumDistance = data.MaximumDistance;
    363370      Scores = new DoubleArray(data.Scores);
    364371    }
     
    383390        DistanceMatrix = new DistanceMatrix(data.GetDistanceMatrix());
    384391
    385       StartingPoint = new IntValue(0); // First city is interpreted as start point
    386       TerminalPoint = new IntValue(data.Dimension - 1); // Last city is interpreted als end point
    387 
    388       PointVisitingCosts = new DoubleValue(0);
    389       MaximumDistance = new DoubleValue(DistanceMatrix.Average() * 5.0); // distance from start to end first to last city is interpreted as maximum distance
     392      StartingPoint = 0; // First city is interpreted as start point
     393      TerminalPoint = data.Dimension - 1; // Last city is interpreted als end point
     394
     395      PointVisitingCosts = 0;
     396      MaximumDistance = DistanceMatrix.Average() * 5.0; // distance from start to end first to last city is interpreted as maximum distance
    390397      Scores = new DoubleArray(Enumerable.Repeat(1.0, data.Dimension).ToArray()); // all scores are 1
    391398    }
     
    409416        : CalculateDistanceMatrix(data.Coordinates);
    410417
    411       StartingPoint = new IntValue(0); // Depot is interpreted as start point
    412       TerminalPoint = new IntValue(0); // Depot is interpreted als end point
    413 
    414       PointVisitingCosts = new DoubleValue(0);
    415       MaximumDistance = new DoubleValue(data.Capacity * 2); // capacity is interpreted as max distance
     418      StartingPoint = 0; // Depot is interpreted as start point
     419      TerminalPoint = 0; // Depot is interpreted als end point
     420
     421      PointVisitingCosts = 0;
     422      MaximumDistance = data.Capacity * 2; // capacity is interpreted as max distance
    416423      Scores = new DoubleArray(data.Demands); // demands are interpreted as scores
    417424    }
     425    #endregion
    418426  }
    419427}
Note: See TracChangeset for help on using the changeset viewer.