Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12306 for branches/PTSP


Ignore:
Timestamp:
04/13/15 17:43:28 (10 years ago)
Author:
apolidur
Message:

#2221: Prepared PTSP for instance input

Location:
branches/PTSP
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/PTSP/HeuristicLab.Problems.PTSP.Views/3.3/PathPTSPTourView.cs

    r12269 r12306  
    120120              }
    121121              for (int i = 0; i < points.Length; i++)
    122                 graphics.FillRectangle(Brushes.Red, points[i].X - 2, points[i].Y - 2, Convert.ToInt32(probabilities[i] * 10), Convert.ToInt32(probabilities[i] * 10));
     122                graphics.FillRectangle(Brushes.Red, points[i].X - 2, points[i].Y - 2, Convert.ToInt32(probabilities[i] * 20), Convert.ToInt32(probabilities[i] * 20));
    123123            }
    124124          } else {
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/AnalyticalPTSP.cs

    r12269 r12306  
    1919  [StorableClass]
    2020  public sealed class AnalyticalProbabilisticTravelingSalesmanProblem : ProbabilisticTravelingSalesmanProblem, IStorableContent,
    21   IProblemInstanceConsumer<TSPData> {
     21  IProblemInstanceConsumer<PTSPData> {
    2222
    2323    [StorableConstructor]
     
    137137    }
    138138
    139     public override void Load(TSPData data) {
     139    public override void Load(PTSPData data) {
    140140      base.Load(data);
    141141      foreach (var op in Operators.OfType<PTSPAnalyticalInversionMovePathEvaluator>()) {
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs

    r12272 r12306  
    1919  [StorableClass]
    2020  public sealed class EstimatedProbabilisticTravelingSalesmanProblem : ProbabilisticTravelingSalesmanProblem, IStorableContent,
    21   IProblemInstanceConsumer<TSPData> {
     21  IProblemInstanceConsumer<PTSPData> {
    2222
    23     private ItemList<ItemList<IntValue>> realizations;
     23
     24    #region Parameter Properties
     25    public IValueParameter<ItemList<ItemList<IntValue>>> RealizationsParameter {
     26      get { return (IValueParameter<ItemList<ItemList<IntValue>>>)Parameters["Realizations"]; }
     27    }
     28    #endregion
     29
     30    #region Properties
     31    public ItemList<ItemList<IntValue>> Realizations {
     32      get { return RealizationsParameter.Value; }
     33      set { RealizationsParameter.Value = value; }
     34    }
     35    #endregion
    2436
    2537    [StorableConstructor]
     
    3850      MersenneTwister r = new MersenneTwister();
    3951      double estimatedSum = 0;
    40       for (int i = 0; i < realizations.Count; i++) {
     52      for (int i = 0; i < Realizations.Count; i++) {
    4153        int singleRealization = -1, firstNode = -1;
    42         for (int j = 0; j < realizations[i].Count; j++) {
    43           if (realizations[i][p[j]].Value == 1) {
     54        for (int j = 0; j < Realizations[i].Count; j++) {
     55          if (Realizations[i][p[j]].Value == 1) {
    4456            if (singleRealization != -1) {
    4557              estimatedSum += DistanceMatrix[singleRealization, p[j]];
     
    5466        }
    5567      }
    56       return estimatedSum / SampleSize.Value;
     68      return estimatedSum / RealizationsSize.Value;
    5769    }
    5870
     
    90102
    91103    public EstimatedProbabilisticTravelingSalesmanProblem() {
    92       Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Size of the sample for the estimation-based evaluation"));
     104      Parameters.Add(new ValueParameter<IntValue>("RealizationsSize", "Size of the sample for the estimation-based evaluation"));
     105      Parameters.Add(new ValueParameter<ItemList<ItemList<IntValue>>>("Realizations", "The concrete..."));
    93106      Operators.Add(new PTSPEstimatedInversionMovePathEvaluator());
    94107      Operators.Add(new PTSPEstimatedInsertionEvaluator());
     
    134147    }
    135148
    136     public override void Load(TSPData data) {
     149    public override void Load(PTSPData data) {
    137150      base.Load(data);
    138151      // For now uses sample size of 20 but should use Student's t-test
    139152      //Ttest(data.Dimension);
    140       SampleSize = new IntValue(100);
     153      RealizationsSize = new IntValue(100);
    141154      MersenneTwister r = new MersenneTwister();
    142155      int countOnes = 0;
    143       realizations = new ItemList<ItemList<IntValue>>(SampleSize.Value);
    144       for (int i = 0; i < SampleSize.Value; i++) {
     156      Realizations = new ItemList<ItemList<IntValue>>(RealizationsSize.Value);
     157      for (int i = 0; i < RealizationsSize.Value; i++) {
    145158        ItemList<IntValue> newRealization = new ItemList<IntValue>();
    146159        while (countOnes < 4) { //only generate realizations with at least 4 cities visited
     
    157170        }
    158171        countOnes = 0;
    159         realizations.Add(newRealization);
     172        Realizations.Add(newRealization);
    160173      }
    161174
    162175      foreach (var op in Operators.OfType<PTSPPathMoveEvaluator>()) {
    163         op.RealizationsParameter.Value = realizations;
     176        op.RealizationsParameter.Value = Realizations;
    164177      }
    165178      foreach (var op in Operators.OfType<PTSPExhaustiveInversionLocalImprovement>()) {
    166         op.RealizationsParameter.Value = realizations;
     179        op.RealizationsParameter.Value = Realizations;
    167180      }
    168181      foreach (var op in Operators.OfType<PTSP25MoveEvaluator>()) {
    169         op.RealizationsParameter.Value = realizations;
     182        op.RealizationsParameter.Value = Realizations;
    170183      }
    171184
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/PTSP.cs

    r12261 r12306  
    4040  [StorableClass]
    4141  public abstract class ProbabilisticTravelingSalesmanProblem : SingleObjectiveBasicProblem<PermutationEncoding>, IStorableContent,
    42   IProblemInstanceConsumer<TSPData> {
     42  IProblemInstanceConsumer<PTSPData> {
    4343    private static readonly int DistanceMatrixSizeLimit = 1000;
    4444
     
    5959      get { return (ValueParameter<DoubleArray>)Parameters["ProbabilityMatrix"]; }
    6060    }
    61     public ValueParameter<IntValue> SampleSizeParameter {
    62       get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
     61    public ValueParameter<IntValue> RealizationsSizeParameter {
     62      get { return (ValueParameter<IntValue>)Parameters["RealizationsSize"]; }
    6363    }
    6464
     
    8686      set { ProbabilityMatrixParameter.Value = value; }
    8787    }
    88     public IntValue SampleSize {
    89       get { return SampleSizeParameter.Value; }
    90       set { SampleSizeParameter.Value = value; }
     88    public IntValue RealizationsSize {
     89      get { return RealizationsSizeParameter.Value; }
     90      set { RealizationsSizeParameter.Value = value; }
    9191    }
    9292    #endregion
     
    121121    }
    122122
    123     public virtual void Load(TSPData data) {
     123    public virtual void Load(PTSPData data) {
    124124      if (data.Coordinates == null && data.Distances == null)
    125125        throw new System.IO.InvalidDataException("The given instance specifies neither coordinates nor distances!");
     
    134134      Description = data.Description;
    135135
    136       // Get Probabilities of cities using random with seed from hash function on the Name of the instance
    137       double[] tempMatrix = new double[data.Dimension];
    138       MersenneTwister r = new MersenneTwister((uint)data.Name.GetHashCode());
    139       for (int i = 0; i < data.Dimension; i++) {
    140         tempMatrix[i] = r.NextDouble();
    141       }
    142       ProbabilityMatrix = new DoubleArray(tempMatrix);
     136      ProbabilityMatrix = new DoubleArray(data.Probabilities);
    143137
    144138      if (data.BestKnownTour != null) {
Note: See TracChangeset for help on using the changeset viewer.