Ignore:
Timestamp:
12/04/15 10:35:04 (5 years ago)
Author:
mkommend
Message:

#2521: Intermediate version of schedule encoding refactoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Schedule.cs

    r12012 r13435  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
     
    3130  [Item("Schedule", "Represents the general solution for scheduling problems.")]
    3231  [StorableClass]
    33   public class Schedule : NamedItem, IScheduleEncoding {
     32  public class Schedule : NamedItem, ISchedule {
    3433
    3534    #region Properties
     
    3837    public ItemList<Resource> Resources {
    3938      get { return resources; }
    40       set {
    41         if (resources != null) DeregisterResourcesEvents();
    42         resources = value;
    43         if (resources != null) RegisterResourcesEvents();
    44         OnResourcesChanged();
    45       }
    4639    }
    4740    [Storable]
    48     private DoubleValue quality;
    49     public DoubleValue Quality {
     41    private double quality;
     42    public double Quality {
    5043      get { return quality; }
    5144      set {
    52         if (quality != value) {
    53           if (quality != null) DeregisterQualityEvents();
    54           quality = value;
    55           if (quality != null) RegisterQualityEvents();
    56           OnQualityChanged();
    57         }
     45        if (quality == value) return;
     46        quality = value;
     47        OnQualityChanged();
    5848      }
    5949    }
     
    6656    protected Schedule(Schedule original, Cloner cloner)
    6757      : base(original, cloner) {
    68       this.Resources = cloner.Clone(original.Resources);
    69       this.Quality = cloner.Clone(original.Quality);
     58      this.resources = cloner.Clone(original.Resources);
     59      this.quality = original.Quality;
     60      //TODO clone
    7061      this.lastScheduledTaskOfJob = new Dictionary<int, ScheduledTask>(original.lastScheduledTaskOfJob);
     62
     63      RegisterResourcesEvents();
    7164    }
    7265    public Schedule(int nrOfResources) {
    73       Resources = new ItemList<Resource>();
     66      resources = new ItemList<Resource>();
    7467      for (int i = 0; i < nrOfResources; i++) {
    7568        Resources.Add(new Resource(i));
    7669      }
    7770      lastScheduledTaskOfJob = new Dictionary<int, ScheduledTask>();
     71
     72      RegisterResourcesEvents();
    7873    }
    7974
     
    8984        changed(this, EventArgs.Empty);
    9085    }
    91     private void RegisterQualityEvents() {
    92       Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
    93     }
    94     private void DeregisterQualityEvents() {
    95       Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
    96     }
    97     private void Quality_ValueChanged(object sender, EventArgs e) {
    98       OnQualityChanged();
    99     }
    10086
    10187    public event EventHandler ResourcesChanged;
     
    10793    private void RegisterResourcesEvents() {
    10894      Resources.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Resources_PropertyChanged);
    109     }
    110     private void DeregisterResourcesEvents() {
    111       Resources.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Resources_PropertyChanged);
    11295    }
    11396    private void Resources_PropertyChanged(object sender, EventArgs e) {
     
    154137      return sb.ToString();
    155138    }
    156 
    157     public double CalculateMakespan() {
    158       double quality = 0;
    159       foreach (Resource r in Resources) {
    160         if (r.TotalDuration > quality) {
    161           quality = r.TotalDuration;
    162         }
    163       }
    164       return quality;
    165     }
    166139  }
    167140}
Note: See TracChangeset for help on using the changeset viewer.