Changeset 11261


Ignore:
Timestamp:
08/04/14 14:12:16 (7 years ago)
Author:
pfleck
Message:

#2208

  • Added Schilde instances zip
  • Implemented additional InstanceConsumer of OPData in OrienteeringProblem
Location:
branches/HeuristicLab.Problems.Orienteering
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Instances.Orienteering/3.3/HeuristicLab.Problems.Instances.Orienteering-3.3.csproj

    r11260 r11261  
    4545  <ItemGroup>
    4646    <Compile Include="SchildeOPParser.cs" />
     47    <EmbeddedResource Include="Data\SchildeOP.zip" />
    4748    <None Include="HeuristicLab.snk" />
    4849    <None Include="Plugin.cs.frame" />
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Instances.Orienteering/3.3/SchildeOPParser.cs

    r11260 r11261  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Globalization;
    2325using System.IO;
    2426using System.Linq;
     
    2628namespace HeuristicLab.Problems.Instances.Orienteering {
    2729  public class SchildeOPParser {
     30    private static readonly IFormatProvider FormatProvider = new CultureInfo("en-US");
     31
    2832    private int currentPoint;
    2933    private int currentDistance;
     
    112116          inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    113117
    114           Coordinates[currentPoint, 0] = double.Parse(positionX);
    115           Coordinates[currentPoint, 1] = double.Parse(positionY);
     118          Coordinates[currentPoint, 0] = double.Parse(positionX, FormatProvider);
     119          Coordinates[currentPoint, 1] = double.Parse(positionY, FormatProvider);
    116120
    117121          // Extract all score values for this point
     
    122126              score = inputString.Substring(0, inputString.IndexOf(','));
    123127              inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    124               Scores[currentPoint, scoreIndex++] = int.Parse(score);
     128              Scores[currentPoint, scoreIndex++] = int.Parse(score, FormatProvider);
    125129            } else {
    126130              score = inputString;
    127               Scores[currentPoint, scoreIndex++] = int.Parse(score);
     131              Scores[currentPoint, scoreIndex++] = int.Parse(score, FormatProvider);
    128132              break;
    129133            }
     
    148152              distance = inputString.Substring(0, inputString.IndexOf(','));
    149153              inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    150               Distances[currentDistance, distanceIndex++] = double.Parse(distance);
     154              Distances[currentDistance, distanceIndex++] = double.Parse(distance, FormatProvider);
    151155            } else {
    152156              distance = inputString;
    153               Distances[currentDistance, distanceIndex++] = double.Parse(distance);
     157              Distances[currentDistance, distanceIndex++] = double.Parse(distance, FormatProvider);
    154158              break;
    155159            }
     
    165169          // Extract the number of points
    166170
    167           pointCount = int.Parse(inputString);
     171          pointCount = int.Parse(inputString, FormatProvider);
    168172          Coordinates = new double[pointCount, 2];
    169173          break;
     
    196200          // Remove the 's,'
    197201          inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    198           int scoreCount = int.Parse(inputString);
    199 
    200           pointCount = int.Parse(inputString);
     202          int scoreCount = int.Parse(inputString, FormatProvider);
     203
     204          pointCount = Coordinates.GetLength(0);
    201205          Scores = new double[pointCount, scoreCount];
    202206
     
    209213          // Remove the 'b,'
    210214          inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    211           StartingPoint = int.Parse(inputString);
     215          StartingPoint = int.Parse(inputString, FormatProvider);
    212216          break;
    213217
     
    218222          // Remove the 'e,'
    219223          inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    220           TerminusPoint = int.Parse(inputString);
     224          TerminusPoint = int.Parse(inputString, FormatProvider);
    221225          break;
    222226
     
    232236          inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    233237
    234           UpperBoundConstraint = double.Parse(inputString);
     238          UpperBoundConstraint = double.Parse(inputString, FormatProvider);
    235239          break;
    236240
     
    246250          inputString = inputString.Remove(0, inputString.IndexOf(',') + 1);
    247251
    248           LowerConstraint = double.Parse(inputString);
     252          LowerConstraint = double.Parse(inputString, FormatProvider);
    249253          break;
    250254
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r11245 r11261  
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3232using HeuristicLab.Problems.Instances;
     33using HeuristicLab.Problems.Instances.Types;
    3334
    3435namespace HeuristicLab.Problems.Orienteering {
     
    3940  public class OrienteeringProblem
    4041    : SingleObjectiveHeuristicOptimizationProblem<IOrienteeringEvaluator, IIntegerVectorCreator>,
    41     IStorableContent, IProblemInstanceConsumer<CVRPData> {
     42    IStorableContent, IProblemInstanceConsumer<CVRPData>, IProblemInstanceConsumer<OPData> {
    4243
    4344    public string Filename { get; set; }
     
    324325
    325326    public void Load(CVRPData data) {
    326 
    327327      if (data.Coordinates == null)
    328328        throw new InvalidDataException("The given instance specifies no coordinates!");
     
    353353      OnReset();
    354354    }
     355
     356    public void Load(OPData data) {
     357      if (data.Coordinates == null)
     358        throw new InvalidDataException("The given instance specifies no coordinates!");
     359      if (data.Coordinates.GetLength(1) != 2)
     360        throw new InvalidDataException("The coordinates of the given instance are not in the right format, there need to be one row for each customer and two columns for the x and y coordinates.");
     361
     362      // Clear old solutions
     363      BestKnownQuality = null;
     364      BestKnownSolution = null;
     365
     366      Name = data.Name;
     367      Description = data.Description;
     368
     369      Coordinates = new DoubleMatrix(data.Coordinates);
     370      if (data.Distances != null)
     371        DistanceMatrix = new DistanceMatrix(data.Distances);
     372      else
     373        data.GetDistanceMatrix();
     374
     375      StartingPoint = new IntValue(data.StartingPoint);
     376      TerminusPoint = new IntValue(data.TerminusPoint);
     377
     378      MaximumDistance = new DoubleValue(data.MaximumDistance);
     379      Scores = new DoubleArray(data.Scores);
     380    }
    355381  }
    356382}
Note: See TracChangeset for help on using the changeset viewer.