Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/08 21:30:34 (15 years ago)
Author:
gkronber
Message:

Refactored cloning in plugins HL.Routing and HL.Scheduling

#285 (Cloning could be improved by creating objects at the bottom of the cloning chain with 'new' instead of the top with Activator.CreateInstance())

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.Scheduling.JSSP/Schedule.cs

    r2 r888  
    4141    public Schedule() : this(0, 100) { }
    4242
     43    public Schedule(Schedule original) : this(original, new Dictionary<Guid, object>()) { }
     44    protected Schedule(Schedule original, IDictionary<Guid, object> clonedObjects)
     45      : base(original, clonedObjects) {
     46      this.schedule = new ScheduleTree[original.Machines];
     47      for (int i = 0; i < original.Machines; i++) {
     48        this.schedule[i] = (ScheduleTree)Auxiliary.Clone(original.schedule[i], clonedObjects);
     49      }
     50    }
     51
    4352    public int Machines {
    4453      get { return schedule.Length; }
     
    6473    }
    6574
    66     #region IStorable Members
     75   #region IStorable Members
    6776
    6877    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     
    8796
    8897    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    89       int timespan = 0;
    90       if ((schedule != null) && (schedule.Length > 0)) {
    91         timespan = schedule[0].Timespan;
    92       }
    93       Schedule clone = new Schedule(this.Machines, timespan);
    94       clonedObjects.Add(Guid, clone);
    95       clone.schedule = new ScheduleTree[this.Machines];
    96       for(int i = 0; i < this.Machines; i++) {
    97         clone.schedule[i] = (ScheduleTree)Auxiliary.Clone(schedule[i], clonedObjects);
    98       }
    99       return clone;
     98      return new Schedule(this, clonedObjects);
    10099    }
    101100
Note: See TracChangeset for help on using the changeset viewer.