Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12387 for branches/PTSP


Ignore:
Timestamp:
05/09/15 17:26:10 (9 years ago)
Author:
apolidur
Message:

#2221: Fixing RealizationsSize parameter not updating

Location:
branches/PTSP/HeuristicLab.Problems.PTSP/3.3
Files:
2 edited

Legend:

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

    r12380 r12387  
    2323
    2424    #region Parameter Properties
    25     public IValueParameter<ItemList<ItemList<IntValue>>> RealizationsParameter {
    26       get { return (IValueParameter<ItemList<ItemList<IntValue>>>)Parameters["Realizations"]; }
     25    public ValueParameter<ItemList<ItemList<IntValue>>> RealizationsParameter {
     26      get { return (ValueParameter<ItemList<ItemList<IntValue>>>)Parameters["Realizations"]; }
    2727    }
     28    public ValueParameter<IntValue> RealizationsSizeParameter {
     29      get { return (ValueParameter<IntValue>)Parameters["RealizationsSize"]; }
     30    }
     31
    2832    #endregion
    2933
     
    3337      set { RealizationsParameter.Value = value; }
    3438    }
     39
     40    public IntValue RealizationsSize {
     41      get { return RealizationsSizeParameter.Value; }
     42      set { RealizationsSizeParameter.Value = value; }
     43    }
    3544    #endregion
    3645
     
    3948    private EstimatedProbabilisticTravelingSalesmanProblem(EstimatedProbabilisticTravelingSalesmanProblem original, Cloner cloner)
    4049      : base(original, cloner) {
     50      RegisterEventHandlers();
     51    }
     52    public EstimatedProbabilisticTravelingSalesmanProblem() {
     53      Parameters.Add(new ValueParameter<IntValue>("RealizationsSize", "Size of the sample for the estimation-based evaluation"));
     54      Parameters.Add(new ValueParameter<ItemList<ItemList<IntValue>>>("Realizations", "The concrete..."));
     55      Operators.Add(new PTSPEstimatedInversionEvaluator());
     56      Operators.Add(new PTSPEstimatedInsertionEvaluator());
     57      Operators.Add(new PTSPExhaustiveInversionLocalImprovement());
     58      Operators.Add(new PTSPExhaustiveInsertionLocalImprovement());
     59
     60      Operators.Add(new Exhaustive25MoveGenerator());
     61      Operators.Add(new Stochastic25MultiMoveGenerator());
     62      Operators.Add(new Stochastic25SingleMoveGenerator());
     63      Operators.Add(new TwoPointFiveMoveMaker());
     64      Operators.Add(new PTSP25MoveEvaluator());
     65
     66      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
     67      foreach (var twopointfiveMoveOperator in Operators.OfType<I25MoveOperator>()) {
     68        twopointfiveMoveOperator.TwoPointFiveMoveParameter.ActualName = "Permutation.TwoPointFiveMove";
     69      }
     70      RealizationsSize = new IntValue(100);
     71      RegisterEventHandlers();
    4172    }
    4273
     
    101132    }
    102133
    103     public EstimatedProbabilisticTravelingSalesmanProblem() {
    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..."));
    106       Operators.Add(new PTSPEstimatedInversionEvaluator());
    107       Operators.Add(new PTSPEstimatedInsertionEvaluator());
    108       Operators.Add(new PTSPExhaustiveInversionLocalImprovement());
    109       Operators.Add(new PTSPExhaustiveInsertionLocalImprovement());
     134   
    110135
    111       Operators.Add(new Exhaustive25MoveGenerator());
    112       Operators.Add(new Stochastic25MultiMoveGenerator());
    113       Operators.Add(new Stochastic25SingleMoveGenerator());
    114       Operators.Add(new TwoPointFiveMoveMaker());
    115       Operators.Add(new PTSP25MoveEvaluator());
    116 
    117       Encoding.ConfigureOperators(Operators.OfType<IOperator>());
    118       foreach (var twopointfiveMoveOperator in Operators.OfType<I25MoveOperator>()) {
    119         twopointfiveMoveOperator.TwoPointFiveMoveParameter.ActualName = "Permutation.TwoPointFiveMove";
    120       }
     136    private void RegisterEventHandlers() {
     137      //RealizationsSizeParameter.ValueChanged += new EventHandler(RealizationsSizeParameter_ValueChanged);
     138      RealizationsSize.ValueChanged += new EventHandler(RealizationsSizeParameter_ValueChanged);
     139      //RealizationsSizeParameter.Value.ValueChanged += new EventHandler(RealizationsSizeParameter_ValueChanged);
    121140    }
    122141
    123     public override void Load(PTSPData data) {
    124       base.Load(data);
    125       RealizationsSize = new IntValue(100);
     142    private void RealizationsSizeParameter_ValueChanged(object sender, EventArgs e) {
     143      UpdateRealizations();
     144    }
     145
     146    private void UpdateRealizations() {
    126147      MersenneTwister r = new MersenneTwister();
    127 
    128       // TODO : This should be made in another function and attached to a listener
    129148      int countOnes = 0;
    130149      Realizations = new ItemList<ItemList<IntValue>>(RealizationsSize.Value);
     
    134153          countOnes = 0;
    135154          newRealization.Clear();
    136           for (int j = 0; j < data.Dimension; j++) {
     155          for (int j = 0; j < DistanceMatrix.Rows; j++) {
    137156            if (ProbabilityMatrix[j] > r.NextDouble()) {
    138157              newRealization.Add(new IntValue(1));
     
    146165        Realizations.Add(newRealization);
    147166      }
     167    }
     168
     169    public override void Load(PTSPData data) {
     170      base.Load(data);
     171      UpdateRealizations();
    148172
    149173      foreach (var op in Operators.OfType<PTSPMoveEvaluator>()) {
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/PTSP.cs

    r12306 r12387  
    5959      get { return (ValueParameter<DoubleArray>)Parameters["ProbabilityMatrix"]; }
    6060    }
    61     public ValueParameter<IntValue> RealizationsSizeParameter {
    62       get { return (ValueParameter<IntValue>)Parameters["RealizationsSize"]; }
    63     }
     61   
    6462
    6563    #endregion
     
    8684      set { ProbabilityMatrixParameter.Value = value; }
    8785    }
    88     public IntValue RealizationsSize {
    89       get { return RealizationsSizeParameter.Value; }
    90       set { RealizationsSizeParameter.Value = value; }
    91     }
     86   
    9287    #endregion
    9388   
Note: See TracChangeset for help on using the changeset viewer.