Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/25/10 06:35:43 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on algorithms
Location:
trunk/sources/HeuristicLab.Routing.TSP/3.3
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Routing.TSP/3.3/HeuristicLab.Routing.TSP-3.3.csproj

    r2834 r2865  
    8080    </Reference>
    8181    <Reference Include="System.Data" />
     82    <Reference Include="System.Drawing" />
    8283    <Reference Include="System.Xml" />
    8384  </ItemGroup>
    8485  <ItemGroup>
    8586    <None Include="HeuristicLabRoutingTSPPlugin.cs.frame" />
     87    <Compile Include="TSPEvaluator.cs" />
     88    <Compile Include="ITSPEvaluator.cs" />
    8689    <Compile Include="TSPDistanceMatrixPathEvaluator.cs" />
    8790    <Compile Include="TSPLIBParser.cs" />
     
    9699      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
    97100      <Name>HeuristicLab.Collections-3.3</Name>
     101    </ProjectReference>
     102    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.2\HeuristicLab.Common.Resources-3.2.csproj">
     103      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
     104      <Name>HeuristicLab.Common.Resources-3.2</Name>
    98105    </ProjectReference>
    99106    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
  • trunk/sources/HeuristicLab.Routing.TSP/3.3/HeuristicLabRoutingTSPPlugin.cs.frame

    r2834 r2865  
    2929  [PluginFile("HeuristicLab.Routing.TSP-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Collections", "3.3")]
     31  [PluginDependency("HeuristicLab.Common.Resources", "3.2")]
    3132  [PluginDependency("HeuristicLab.Core", "3.3")]
    3233  [PluginDependency("HeuristicLab.Data", "3.3")]
  • trunk/sources/HeuristicLab.Routing.TSP/3.3/TSP.cs

    r2857 r2865  
    2020#endregion
    2121
     22using System;
     23using System.Drawing;
     24using System.Linq;
    2225using HeuristicLab.Core;
    2326using HeuristicLab.Data;
     
    2629using HeuristicLab.Permutation;
    2730using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using System;
     31using HeuristicLab.PluginInfrastructure;
    2932
    3033namespace HeuristicLab.Routing.TSP {
     
    3235  [Creatable("Problems")]
    3336  [EmptyStorableClass]
    34   public sealed class TSP : SingleObjectiveProblem {
    35     private ValueParameter<DoubleMatrixData> CoordinatesParameter {
    36       get { return (ValueParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
     37  public sealed class TSP : ParameterizedNamedItem, ISingleObjectiveProblem {
     38    public override Image ItemImage {
     39      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
    3740    }
    3841
    39     public DoubleMatrixData Coordinates {
    40       get { return CoordinatesParameter.Value; }
    41       set { CoordinatesParameter.Value = value; }
     42    private IValueParameter<BoolData> MaximizationParameter {
     43      get { return (IValueParameter<BoolData>)Parameters["Maximization"]; }
     44    }
     45    public IValueParameter<DoubleMatrixData> CoordinatesParameter {
     46      get { return (IValueParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
     47    }
     48    public IValueParameter<DoubleData> BestKnownQualityParameter {
     49      get { return (IValueParameter<DoubleData>)Parameters["BestKnownQuality"]; }
     50    }
     51    public IValueParameter<IPermutationCreator> SolutionCreatorParameter {
     52      get { return (IValueParameter<IPermutationCreator>)Parameters["SolutionCreator"]; }
     53    }
     54    public IValueParameter<ITSPEvaluator> EvaluatorParameter {
     55      get { return (IValueParameter<ITSPEvaluator>)Parameters["Evaluator"]; }
     56    }
     57
     58    public BoolData Maximization {
     59      get { return MaximizationParameter.Value; }
     60    }
     61    public ISolutionCreator SolutionCreator {
     62      get { return SolutionCreatorParameter.Value; }
     63    }
     64    public ISingleObjectiveEvaluator Evaluator {
     65      get { return EvaluatorParameter.Value; }
     66    }
     67    IEvaluator IProblem.Evaluator {
     68      get { return EvaluatorParameter.Value; }
     69    }
     70    private OperatorSet operators;
     71    public OperatorSet Operators {
     72      get { return operators; }
    4273    }
    4374
    4475    public TSP()
    4576      : base() {
    46       Maximization = new BoolData(false);
     77      ValueParameter<BoolData> maximizationParameter = new ValueParameter<BoolData>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolData(false));
     78      maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged);
     79      Parameters.Add(maximizationParameter);
     80
    4781      Parameters.Add(new ValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0)));
     82
     83      ValueParameter<IPermutationCreator> solutionCreatorParameter = new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.");
     84      solutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
     85      Parameters.Add(solutionCreatorParameter);
     86
     87      ValueParameter<ITSPEvaluator> evaluatorParameter = new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.");
     88      evaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
     89      Parameters.Add(evaluatorParameter);
     90
    4891      Parameters.Add(new ValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
     92
    4993      RandomPermutationCreator creator = new RandomPermutationCreator();
     94      creator.PermutationParameter.ActualName = "TSPTour";
    5095      creator.LengthParameter.Value = new IntData(0);
    51       SolutionCreator = creator;
    52       Evaluator = new TSPRoundedEuclideanPathEvaluator();
     96      SolutionCreatorParameter.Value = creator;
     97      TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator();
     98      evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     99      evaluator.PermutationParameter.ActualName = creator.PermutationParameter.ActualName;
     100      evaluator.QualityParameter.ActualName = "TSPTourLength";
     101      EvaluatorParameter.Value = evaluator;
     102
     103      operators = new OperatorSet();
     104      var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList();
     105      crossovers.ForEach(x => {
     106        x.ParentsParameter.ActualName = creator.PermutationParameter.ActualName;
     107        x.ChildParameter.ActualName = creator.PermutationParameter.ActualName;
     108      });
     109      var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList();
     110      manipulators.ForEach(x => x.PermutationParameter.ActualName = creator.PermutationParameter.ActualName);
     111      operators = new OperatorSet(crossovers.Cast<IOperator>().Concat(manipulators.Cast<IOperator>()));
    53112    }
    54113
     
    56115      TSPLIBParser parser = new TSPLIBParser(filename);
    57116      parser.Parse();
    58       Coordinates = new DoubleMatrixData(parser.Vertices);
    59       int cities = Coordinates.Rows;
    60       RandomPermutationCreator creator = new RandomPermutationCreator();
    61       creator.LengthParameter.Value = new IntData(cities);
    62       SolutionCreator = creator;
    63       TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator();
    64       Evaluator = evaluator;
     117      CoordinatesParameter.Value = new DoubleMatrixData(parser.Vertices);
     118      int cities = CoordinatesParameter.Value.Rows;
     119      SolutionCreatorParameter.Value.LengthParameter.Value = new IntData(cities);
     120    }
     121
     122    private void MaximizationParameter_ValueChanged(object sender, EventArgs e) {
     123      OnMaximizationChanged();
     124    }
     125    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     126      OnSolutionCreatorChanged();
     127    }
     128    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
     129      OnEvaluatorChanged();
     130    }
     131
     132    public event EventHandler MaximizationChanged;
     133    private void OnMaximizationChanged() {
     134      if (MaximizationChanged != null)
     135        MaximizationChanged(this, EventArgs.Empty);
     136    }
     137    public event EventHandler SolutionCreatorChanged;
     138    private void OnSolutionCreatorChanged() {
     139      if (SolutionCreatorChanged != null)
     140        SolutionCreatorChanged(this, EventArgs.Empty);
     141    }
     142    public event EventHandler EvaluatorChanged;
     143    private void OnEvaluatorChanged() {
     144      if (EvaluatorChanged != null)
     145        EvaluatorChanged(this, EventArgs.Empty);
    65146    }
    66147  }
  • trunk/sources/HeuristicLab.Routing.TSP/3.3/TSPDistanceMatrixPathEvaluator.cs

    r2834 r2865  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
    24 using HeuristicLab.Operators;
    2524using HeuristicLab.Parameters;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3332  [Creatable("Test")]
    3433  [EmptyStorableClass]
    35   public sealed class TSPDistanceMatrixPathEvaluator : SingleSuccessorOperator {
     34  public sealed class TSPDistanceMatrixPathEvaluator : TSPEvaluator {
    3635    public LookupParameter<DoubleMatrixData> DistanceMatrixParameter {
    3736      get { return (LookupParameter<DoubleMatrixData>)Parameters["DistanceMatrix"]; }
     
    4039      get { return (LookupParameter<Permutation.Permutation>)Parameters["Permutation"]; }
    4140    }
    42     public LookupParameter<DoubleData> QualityParameter {
    43       get { return (LookupParameter<DoubleData>)Parameters["Quality"]; }
    44     }
    4541
    4642    public TSPDistanceMatrixPathEvaluator()
     
    4844      Parameters.Add(new LookupParameter<DoubleMatrixData>("DistanceMatrix", "The distance matrix of the cities."));
    4945      Parameters.Add(new LookupParameter<Permutation.Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated."));
    50       Parameters.Add(new LookupParameter<DoubleData>("Quality", "The evaluated quality of the given TSP solution."));
    5146    }
    5247
  • trunk/sources/HeuristicLab.Routing.TSP/3.3/TSPPathEvaluator.cs

    r2852 r2865  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
    24 using HeuristicLab.Optimization;
    2524using HeuristicLab.Parameters;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3231  [Item("TSPPathEvaluator", "A base class for operators which evaluate TSP solutions given in path representation.")]
    3332  [EmptyStorableClass]
    34   public abstract class TSPPathEvaluator : SingleObjectiveEvaluator {
     33  public abstract class TSPPathEvaluator : TSPEvaluator {
    3534    public LookupParameter<DoubleMatrixData> CoordinatesParameter {
    3635      get { return (LookupParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
Note: See TracChangeset for help on using the changeset viewer.