Free cookie consent management tool by TermsFeed Policy Generator

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

#2521: Intermediate version of schedule encoding refactoring.

Location:
branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding
Files:
5 edited

Legend:

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

    r12012 r13435  
    6363      Parameters.Add(new ValueLookupParameter<IntValue>("Resources", "The number of resources used in this problem instance."));
    6464      Parameters.Add(new LookupParameter<ItemList<Job>>("JobData", "Job data taken from the JSSP - Instance."));
    65       ScheduleEncodingParameter.ActualName = "Schedule";
     65      ScheduleParameter.ActualName = "Schedule";
    6666    }
    6767
     
    8282
    8383
    84     protected override IScheduleEncoding CreateSolution() {
     84    protected override ISchedule CreateSolution() {
    8585      try {
    8686        var jobData = (ItemList<Job>)JobDataParameter.ActualValue.Clone();
  • branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Job.cs

    r12012 r13435  
    3131  [Item("Job", "Represents a composition of tasks that require processing in a scheduling problem.")]
    3232  [StorableClass]
    33   public class Job : Item, INotifyPropertyChanged {
     33  public sealed class Job : Item, INotifyPropertyChanged {
    3434
    3535    [Storable(Name = "DueDate")]
     
    3838      get { return dueDate; }
    3939      set {
    40         bool changed = dueDate != value;
     40        if (dueDate == value) return;
    4141        dueDate = value;
    42         if (changed) {
    43           OnPropertyChanged("DueDate");
    44           OnToStringChanged();
    45         }
     42        OnPropertyChanged("DueDate");
     43        OnToStringChanged();
    4644      }
    4745    }
     
    5250      get { return index; }
    5351      set {
    54         bool changed = index != value;
     52        if (index == value) return;
    5553        index = value;
    56         if (changed) {
    57           OnPropertyChanged("Index");
    58           OnToStringChanged();
    59         }
     54        OnPropertyChanged("Index");
     55        OnToStringChanged();
    6056      }
    6157    }
     
    6561    public ItemList<Task> Tasks {
    6662      get { return tasks; }
    67       set {
    68         bool changed = tasks != value;
     63      private set {
    6964        tasks = value;
    70         if (changed) OnPropertyChanged("Tasks");
     65        OnPropertyChanged("Tasks");
    7166      }
    7267    }
    7368
    7469    [StorableConstructor]
    75     protected Job(bool deserializing) : base(deserializing) { }
    76     protected Job(Job original, Cloner cloner)
     70    private Job(bool deserializing) : base(deserializing) { }
     71    private Job(Job original, Cloner cloner)
    7772      : base(original, cloner) {
    7873      this.dueDate = original.DueDate;
     
    151146    }
    152147
    153     internal Task GetPreviousTask(Task t) {
    154       if (t.TaskNr == 0) return null;
    155       return Tasks[t.TaskNr - 1];
    156     }
    157 
    158148    public event EventHandler TasksChanged;
    159     protected virtual void OnTasksChanged() {
     149    private void OnTasksChanged() {
    160150      var handler = TasksChanged;
    161151      if (handler != null) handler(this, EventArgs.Empty);
     
    163153
    164154    public event PropertyChangedEventHandler PropertyChanged;
    165     protected virtual void OnPropertyChanged(string propertyName) {
     155    private void OnPropertyChanged(string propertyName) {
    166156      var handler = PropertyChanged;
    167157      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
  • branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Manipulators/DirectScheduleManipulator.cs

    r12012 r13435  
    3535    public DirectScheduleManipulator()
    3636      : base() {
    37       ScheduleEncodingParameter.ActualName = "Schedule";
     37      ScheduleParameter.ActualName = "Schedule";
    3838    }
    3939
     
    4141
    4242    public override IOperation InstrumentedApply() {
    43       var schedule = ScheduleEncodingParameter.ActualValue as Schedule;
     43      var schedule = ScheduleParameter.ActualValue as Schedule;
    4444      if (schedule == null) throw new InvalidOperationException("ScheduleEncoding was not found or is not of type Schedule.");
    4545      Manipulate(RandomParameter.ActualValue, schedule);
  • branches/ProblemRefactoring/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Resource.cs

    r12012 r13435  
    2020#endregion
    2121
     22using System.Linq;
    2223using System.Text;
    2324using HeuristicLab.Common;
     
    2829  [Item("ResourceClass", "Represents a resource used in scheduling problems.")]
    2930  [StorableClass]
    30   public class Resource : Item {
     31  public sealed class Resource : Item {
    3132
    3233    [Storable]
    33     public int Index {
    34       get;
    35       set;
    36     }
     34    public int Index { get; private set; }
    3735    [Storable]
    38     public ItemList<ScheduledTask> Tasks {
    39       get;
    40       set;
     36    public ItemList<ScheduledTask> Tasks { get; private set; }
     37
     38    //TODO why does a Ressource has a duration?
     39    public double TotalDuration {
     40      get {
     41        if (Tasks.Count == 0) return 0.0;
     42        return Tasks.Max(t => t.EndTime);
     43      }
    4144    }
    4245
    4346    [StorableConstructor]
    44     protected Resource(bool deserializing) : base(deserializing) { }
    45     protected Resource(Resource original, Cloner cloner)
     47    private Resource(bool deserializing) : base(deserializing) { }
     48    private Resource(Resource original, Cloner cloner)
    4649      : base(original, cloner) {
    4750      this.Index = original.Index;
     
    5861    }
    5962
    60     public double TotalDuration {
    61       get {
    62         double result = 0;
    63         foreach (ScheduledTask t in Tasks) {
    64           if (t.EndTime > result)
    65             result = t.EndTime;
    66         }
    67         return result;
    68       }
    69     }
    70 
    7163    public override string ToString() {
    7264      StringBuilder sb = new StringBuilder();
    7365      sb.Append("Resource#" + Index + " [ ");
    7466      foreach (ScheduledTask t in Tasks) {
    75         sb.Append(t+ " ");
     67        sb.Append(t + " ");
    7668      }
    7769      sb.Append("]");
  • 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.