Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11191


Ignore:
Timestamp:
07/15/14 16:14:09 (10 years ago)
Author:
pfleck
Message:

#2208 Implemented GreedyOrienteeringTourCreator

Location:
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Evaluators/OrienteeringEvaluator.cs

    r11187 r11191  
    3434    }
    3535    public ILookupParameter<IntegerVector> SolutionParameter {
    36       get { return (ILookupParameter<IntegerVector>)Parameters["Solution"]; }
     36      get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; }
    3737    }
    3838    public ILookupParameter<DoubleArray> ScoresParameter {
     
    5353      : base() {
    5454      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the Orienteering solution."));
    55       Parameters.Add(new LookupParameter<IntegerVector>("Solution", "The Orienteering Solution given in path representation."));
     55      Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The Orienteering Solution given in path representation."));
    5656      Parameters.Add(new LookupParameter<DoubleArray>("Scores", "The scores of the points."));
    5757    }
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/HeuristicLab.Problems.Orienteering-3.3.csproj

    r11190 r11191  
    4747  <ItemGroup>
    4848    <Compile Include="Analyzers\BestOrienteeringSolutionAnalyser.cs" />
     49    <Compile Include="Creators\GreedyOrienteeringTourCreator.cs" />
    4950    <Compile Include="DistanceMatrix.cs" />
    5051    <Compile Include="Interfaces\IOrienteeringEvaluator.cs" />
  • branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r11190 r11191  
    2222using System;
    2323using System.Linq;
    24 using HeuristicLab.Analysis;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    3029using HeuristicLab.Parameters;
    3130using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.PluginInfrastructure;
    3232using HeuristicLab.Problems.Instances;
    3333
     
    4747      get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    4848    }
    49     public OptionalValueParameter<DistanceMatrix> DistanceMatrixParameter {
    50       get { return (OptionalValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
    51     }
    52     public ValueParameter<BoolValue> UseDistanceMatrixParameter {
    53       get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
     49    public ValueParameter<DistanceMatrix> DistanceMatrixParameter {
     50      get { return (ValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
    5451    }
    5552
     
    8481      set { DistanceMatrixParameter.Value = value; }
    8582    }
    86     public BoolValue UseDistanceMatrix {
    87       get { return UseDistanceMatrixParameter.Value; }
    88       set { UseDistanceMatrixParameter.Value = value; }
    89     }
    9083    public IntValue StartingPoint {
    9184      get { return StartingPointParameter.Value; }
     
    115108      get { return Operators.OfType<BestOrienteeringSolutionAnalyser>().SingleOrDefault(); }
    116109    }
    117     private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {
    118       get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().SingleOrDefault(); }
    119     }
    120110    #endregion
    121111
     
    132122    }
    133123    public OrienteeringProblem()
    134       : base(new OrienteeringEvaluator(), new UniformRandomIntegerVectorCreator()) { // TODO: Greedy route creator for solution creator
     124      : base(new OrienteeringEvaluator(), new GreedyOrienteeringTourCreator()) {
    135125      Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the points."));
    136       Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points."));
    137       Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if the coordinates based evaluators should calculate the distance matrix from the coordinates and use it for evaluation similar to the distance matrix evaluator, otherwise false.", new BoolValue(true)));
     126      Parameters.Add(new ValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points."));
    138127      Parameters.Add(new ValueParameter<IntValue>("StartingPoint", "Index of the starting point.", new IntValue(0)));
    139128      Parameters.Add(new ValueParameter<IntValue>("TerminusPoint", "Index of the ending point.", new IntValue(0)));
     
    182171      }
    183172      ParameterizeSolutionCreator();
    184       DistanceMatrix = null;
     173      CalculateDistanceMatrix();
    185174    }
    186175    private void CoordinatesValue_ItemChanged(object sender, EventArgs<int, int> e) {
    187       DistanceMatrix = null;
     176      CalculateDistanceMatrix();
    188177    }
    189178    private void CoordinatesValue_Reset(object sender, EventArgs e) {
    190179      ParameterizeSolutionCreator();
    191       DistanceMatrix = null;
     180      CalculateDistanceMatrix();
    192181    }
    193182    private void StartingPointParameter_ValueChanged(object sender, EventArgs e) {
     
    245234
    246235    private void ParameterizeSolutionCreator() {
    247       if (SolutionCreator is UniformRandomIntegerVectorCreator) {
    248         if (SolutionCreator.LengthParameter.Value == null || SolutionCreator.LengthParameter.Value.Value != Scores.Length) {
    249           SolutionCreator.LengthParameter.Value = new IntValue(Scores.Length);
    250         }
     236      if (SolutionCreator is GreedyOrienteeringTourCreator) {
     237        var creator = (GreedyOrienteeringTourCreator)SolutionCreator;
     238        creator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
     239        creator.ScoresParameter.ActualName = ScoresParameter.Name;
     240        creator.MaximumDistanceParameter.ActualName = MaximumDistanceParameter.Name;
     241        creator.StartingPointParameter.ActualName = StartingPointParameter.Name;
     242        creator.TerminusPointParameter.ActualName = TerminusPointParameter.Name;
     243        creator.FixedPenaltyParameter.ActualName = FixedPenaltyParameter.Name;
    251244      }
    252245    }
     
    259252    }
    260253    private void ParameterizeAnalyzer() {
    261       // TODO
     254      if (BestOrienteeringSolutionAnalyser != null) {
     255        BestOrienteeringSolutionAnalyser.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     256
     257        BestOrienteeringSolutionAnalyser.IntegerVector.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
     258        BestOrienteeringSolutionAnalyser.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     259        BestOrienteeringSolutionAnalyser.ScoresParameter.ActualName = ScoresParameter.Name;
     260
     261        BestOrienteeringSolutionAnalyser.ResultsParameter.ActualName = "Results";
     262        BestOrienteeringSolutionAnalyser.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
     263        BestOrienteeringSolutionAnalyser.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     264      }
    262265    }
    263266    private void InitializeOperators() {
    264       // TODO
     267      Operators.Add(new BestOrienteeringSolutionAnalyser());
     268      ParameterizeAnalyzer();
     269
     270      var operators = ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>();
     271      Operators.AddRange(operators);
     272      ParameterizeOperators();
    265273    }
    266274    private void ParameterizeOperators() {
    267       // TODO
     275      //foreach (var op in Operators.OfType<IIntegerVectorManipulator>())
     276      //  op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
     277      foreach (var op in Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>())
     278        op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
     279      foreach (var op in Operators.OfType<ISingleObjectiveImprovementOperator>())
     280        op.SolutionParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
    268281    }
    269282    #endregion
     283
     284    private void CalculateDistanceMatrix() {
     285      var distances = new double[Coordinates.Rows, Coordinates.Rows];
     286      for (int i = 0; i < Coordinates.Rows; i++) {
     287        for (int j = 0; j < Coordinates.Rows; j++) {
     288          double distanceX = Math.Abs(Coordinates[i, 0] - Coordinates[j, 0]);
     289          double distanceY = Math.Abs(Coordinates[i, 1] - Coordinates[j, 1]);
     290          distances[i, j] = Math.Sqrt(Math.Pow(distanceX, 2) + Math.Pow(distanceY, 2));
     291        }
     292      }
     293      DistanceMatrix = new DistanceMatrix(distances);
     294    }
    270295
    271296    private void InitializeInitialOrienteeringInstance() {
     
    277302        {  5.00,  5.60 }
    278303      });
    279       UseDistanceMatrix.Value = false;
     304      CalculateDistanceMatrix();
    280305
    281306      StartingPoint.Value = 0;
     
    296321
    297322      Coordinates = data.Coordinates != null ? new DoubleMatrix(data.Coordinates) : null;
    298       UseDistanceMatrix.Value = data.Distances != null;
    299       DistanceMatrix = data.Distances != null ? new DistanceMatrix(data.Distances) : null;
     323      if (Coordinates == null)
     324        DistanceMatrix = new DistanceMatrix(data.Distances);
    300325      StartingPoint = new IntValue(0);// Depot is interpreted as start and endpoint (default)
    301326      TerminusPoint = new IntValue(0);
Note: See TracChangeset for help on using the changeset viewer.