Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11073 for stable


Ignore:
Timestamp:
07/02/14 15:08:32 (10 years ago)
Author:
ascheibe
Message:

#2127 merged r10213, r10433, r10476, r10494 into stable

Location:
stable
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.ScheduleEncoding.Views/3.3/JobView.Designer.cs

    r9456 r11073  
    8080      this.dueDateLabel.Name = "dueDateLabel";
    8181      this.dueDateLabel.Size = new System.Drawing.Size(56, 13);
    82       this.dueDateLabel.TabIndex = 0;
     82      this.dueDateLabel.TabIndex = 2;
    8383      this.dueDateLabel.Text = "Due Date:";
    8484      //
     
    9090      this.dueDateTextBox.Name = "dueDateTextBox";
    9191      this.dueDateTextBox.Size = new System.Drawing.Size(451, 20);
    92       this.dueDateTextBox.TabIndex = 1;
     92      this.dueDateTextBox.TabIndex = 3;
    9393      this.dueDateTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.dueDateTextBox_Validating);
    9494      //
     
    101101      this.tasksGroupBox.Name = "tasksGroupBox";
    102102      this.tasksGroupBox.Size = new System.Drawing.Size(510, 214);
    103       this.tasksGroupBox.TabIndex = 2;
     103      this.tasksGroupBox.TabIndex = 4;
    104104      this.tasksGroupBox.TabStop = false;
    105105      this.tasksGroupBox.Text = "Tasks";
  • stable/HeuristicLab.Encodings.ScheduleEncoding.Views/3.3/TaskView.Designer.cs

    r9456 r11073  
    8383      this.resourceNrLabel.Name = "resourceNrLabel";
    8484      this.resourceNrLabel.Size = new System.Drawing.Size(70, 13);
    85       this.resourceNrLabel.TabIndex = 0;
     85      this.resourceNrLabel.TabIndex = 2;
    8686      this.resourceNrLabel.Text = "Resource Nr:";
    8787      //
     
    9393      this.resourceNrTextBox.Name = "resourceNrTextBox";
    9494      this.resourceNrTextBox.Size = new System.Drawing.Size(437, 20);
    95       this.resourceNrTextBox.TabIndex = 1;
     95      this.resourceNrTextBox.TabIndex = 3;
    9696      this.resourceNrTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.resourceNrTextBox_Validating);
    9797      //
     
    106106      this.jobNrLabel.Name = "jobNrLabel";
    107107      this.jobNrLabel.Size = new System.Drawing.Size(41, 13);
    108       this.jobNrLabel.TabIndex = 0;
     108      this.jobNrLabel.TabIndex = 4;
    109109      this.jobNrLabel.Text = "Job Nr:";
    110110      //
     
    116116      this.jobNrTextBox.Name = "jobNrTextBox";
    117117      this.jobNrTextBox.Size = new System.Drawing.Size(437, 20);
    118       this.jobNrTextBox.TabIndex = 1;
     118      this.jobNrTextBox.TabIndex = 5;
    119119      this.jobNrTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.jobNrTextBox_Validating);
    120120      //
     
    125125      this.durationLabel.Name = "durationLabel";
    126126      this.durationLabel.Size = new System.Drawing.Size(50, 13);
    127       this.durationLabel.TabIndex = 0;
     127      this.durationLabel.TabIndex = 6;
    128128      this.durationLabel.Text = "Duration:";
    129129      //
     
    135135      this.durationTextBox.Name = "durationTextBox";
    136136      this.durationTextBox.Size = new System.Drawing.Size(437, 20);
    137       this.durationTextBox.TabIndex = 1;
     137      this.durationTextBox.TabIndex = 7;
    138138      this.durationTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.durationTextBox_Validating);
    139139      //
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/JSMEncoding.cs

    r9456 r11073  
    2020#endregion
    2121
     22using System;
    2223using System.Text;
    2324using HeuristicLab.Common;
     
    5354
    5455      foreach (Permutation p in JobSequenceMatrix) {
    55         sb.Append(p.ToString() + " \n");
     56        sb.AppendLine(p.ToString());
    5657      }
    5758
     
    5960      return sb.ToString();
    6061    }
    61 
    62 
    63     public override bool Equals(object obj) {
    64       if (obj.GetType() == typeof(JSMEncoding))
    65         return AreEqual(this, obj as JSMEncoding);
    66 
    67       return false;
    68     }
    69     public override int GetHashCode() {
    70       if (JobSequenceMatrix.Count == 1)
    71         return JobSequenceMatrix[0].GetHashCode();
    72       if (JobSequenceMatrix.Count == 2)
    73         return JobSequenceMatrix[0].GetHashCode() ^ JobSequenceMatrix[1].GetHashCode();
    74       return 0;
    75     }
    76     private static bool AreEqual(JSMEncoding jSMEncoding1, JSMEncoding jSMEncoding2) {
    77       if (jSMEncoding1.JobSequenceMatrix.Count != jSMEncoding2.JobSequenceMatrix.Count)
    78         return false;
    79       for (int i = 0; i < jSMEncoding1.JobSequenceMatrix.Count; i++) {
    80         if (!AreEqual(jSMEncoding1.JobSequenceMatrix[i], jSMEncoding2.JobSequenceMatrix[i]))
    81           return false;
    82       }
    83       return true;
    84     }
    85 
    86     private static bool AreEqual(Permutation p1, Permutation p2) {
    87       if (p1.Length != p2.Length)
    88         return false;
    89       for (int i = 0; i < p1.Length; i++) {
    90         if (p1[i] != p2[i])
    91           return false;
    92       }
    93       return true;
    94     }
    9562  }
    9663}
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/PermutationWithRepetition/PWREncoding.cs

    r9456 r11073  
    7575      return sb.ToString();
    7676    }
    77 
    78     public override bool Equals(object obj) {
    79       if (obj.GetType() == typeof(PWREncoding))
    80         return AreEqual(this, obj as PWREncoding);
    81       else
    82         return base.Equals(obj);
    83     }
    84 
    85     public override int GetHashCode() {
    86       if (PermutationWithRepetition.Length == 1)
    87         return PermutationWithRepetition[0].GetHashCode();
    88       if (PermutationWithRepetition.Length == 2)
    89         return PermutationWithRepetition[0].GetHashCode() ^ PermutationWithRepetition[1].GetHashCode();
    90       return 0;
    91     }
    92 
    93     private bool AreEqual(PWREncoding pWREncoding1, PWREncoding pWREncoding2) {
    94       if (pWREncoding1.PermutationWithRepetition.Length != pWREncoding2.PermutationWithRepetition.Length)
    95         return false;
    96       for (int i = 0; i < pWREncoding1.PermutationWithRepetition.Length; i++) {
    97         if (pWREncoding1.PermutationWithRepetition[i] != pWREncoding2.PermutationWithRepetition[i])
    98           return false;
    99       }
    100       return true;
    101     }
    10277  }
    10378}
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/PRVEncoding.cs

    r9456 r11073  
    7474
    7575      foreach (int i in PriorityRulesVector) {
    76         sb.Append(i.ToString() + " ");
     76        sb.Append(i + " ");
    7777      }
    7878
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Job.cs

    r9456 r11073  
    2020#endregion
    2121
     22using System;
    2223using System.ComponentModel;
    2324using System.Text;
     25using HeuristicLab.Collections;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    3840        bool changed = dueDate != value;
    3941        dueDate = value;
    40         if (changed) OnPropertyChanged("DueDate");
     42        if (changed) {
     43          OnPropertyChanged("DueDate");
     44          OnToStringChanged();
     45        }
    4146      }
    4247    }
     
    4954        bool changed = index != value;
    5055        index = value;
    51         if (changed) OnPropertyChanged("Index");
     56        if (changed) {
     57          OnPropertyChanged("Index");
     58          OnToStringChanged();
     59        }
    5260      }
    5361    }
     
    6876    protected Job(Job original, Cloner cloner)
    6977      : base(original, cloner) {
    70       this.DueDate = original.DueDate;
    71       this.Index = original.Index;
    72       this.Tasks = cloner.Clone(original.Tasks);
     78      this.dueDate = original.DueDate;
     79      this.index = original.Index;
     80      this.tasks = cloner.Clone(original.Tasks);
     81      RegisterEventHandlers();
    7382    }
    7483    public Job() : this(-1, double.MaxValue) { }
    7584    public Job(int index, double dueDate)
    7685      : base() {
    77       DueDate = dueDate;
    78       Index = index;
    79       Tasks = new ItemList<Task>();
     86      this.dueDate = dueDate;
     87      this.index = index;
     88      this.tasks = new ItemList<Task>();
     89      RegisterEventHandlers();
    8090    }
    8191
     
    8494    }
    8595
     96    [StorableHook(HookType.AfterDeserialization)]
     97    private void AfterDeserialization() {
     98      RegisterEventHandlers();
     99    }
     100
     101    private void RegisterEventHandlers() {
     102      Tasks.ItemsAdded += TasksOnItemsChanged;
     103      Tasks.ItemsRemoved += TasksOnItemsChanged;
     104      Tasks.ItemsReplaced += TasksOnItemsChanged;
     105      Tasks.CollectionReset += TasksOnItemsChanged;
     106      foreach (var task in Tasks) {
     107        task.PropertyChanged += TaskOnPropertyChanged;
     108        task.ToStringChanged += TaskOnToStringChanged;
     109      }
     110    }
     111
     112    private void TasksOnItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<Task>> e) {
     113      foreach (var task in e.OldItems) {
     114        task.Value.PropertyChanged -= TaskOnPropertyChanged;
     115        task.Value.ToStringChanged -= TaskOnToStringChanged;
     116      }
     117      foreach (var task in e.Items) {
     118        task.Value.PropertyChanged += TaskOnPropertyChanged;
     119        task.Value.ToStringChanged += TaskOnToStringChanged;
     120      }
     121      OnTasksChanged();
     122      OnToStringChanged();
     123    }
     124
     125    private void TaskOnPropertyChanged(object sender, EventArgs e) {
     126      OnTasksChanged();
     127    }
     128
     129    private void TaskOnToStringChanged(object sender, EventArgs e) {
     130      OnToStringChanged();
     131    }
     132
    86133    public override string ToString() {
    87134      var sb = new StringBuilder();
    88135      sb.Append("Job#" + Index + " [ ");
    89136      foreach (Task t in Tasks) {
    90         sb.Append(t.ToString() + " ");
     137        sb.Append(t + " ");
    91138      }
    92139      sb.Append("{" + DueDate + "} ");
     
    100147    }
    101148
     149    public event EventHandler TasksChanged;
     150    protected virtual void OnTasksChanged() {
     151      var handler = TasksChanged;
     152      if (handler != null) handler(this, EventArgs.Empty);
     153    }
     154
    102155    public event PropertyChangedEventHandler PropertyChanged;
    103156    protected virtual void OnPropertyChanged(string propertyName) {
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Resource.cs

    r9456 r11073  
    7373      sb.Append("Resource#" + Index + " [ ");
    7474      foreach (ScheduledTask t in Tasks) {
    75         sb.Append(t.ToString() + " ");
     75        sb.Append(t+ " ");
    7676      }
    7777      sb.Append("]");
    7878      return sb.ToString();
    7979    }
    80 
    81 
    82     public override bool Equals(object obj) {
    83       if (obj.GetType() == typeof(Resource))
    84         return AreEqual(this, obj as Resource);
    85       else
    86         return false;
    87     }
    88 
    89     public override int GetHashCode() {
    90       if (Tasks.Count == 1)
    91         return Tasks[0].GetHashCode();
    92       if (Tasks.Count == 2)
    93         return Tasks[0].GetHashCode() ^ Tasks[1].GetHashCode();
    94       return 0;
    95     }
    96 
    97     private static bool AreEqual(Resource res1, Resource res2) {
    98       if (res1.Tasks.Count != res2.Tasks.Count)
    99         return false;
    100       for (int i = 0; i < res1.Tasks.Count; i++) {
    101         if (!res1.Tasks[i].Equals(res2.Tasks[i]))
    102           return false;
    103       }
    104 
    105       return true;
    106     }
    10780  }
    10881}
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Schedule.cs

    r9456 r11073  
    149149      sb.Append("[ ");
    150150      foreach (Resource r in Resources) {
    151         sb.Append(r.ToString() + " \n");
     151        sb.AppendLine(r.ToString());
    152152      }
    153153      sb.Append("]");
     
    164164      return quality;
    165165    }
    166 
    167     public override bool Equals(object obj) {
    168       if (obj.GetType() == typeof(Schedule))
    169         return AreEqual(this, obj as Schedule);
    170       else
    171         return false;
    172     }
    173     public override int GetHashCode() {
    174       if (Resources.Count == 1)
    175         return Resources[0].GetHashCode();
    176       if (Resources.Count == 2)
    177         return Resources[0].GetHashCode() ^ Resources[1].GetHashCode();
    178       return 0;
    179     }
    180 
    181     private static bool AreEqual(Schedule schedule1, Schedule schedule2) {
    182       if (schedule1.Resources.Count != schedule2.Resources.Count)
    183         return false;
    184       for (int i = 0; i < schedule1.Resources.Count; i++) {
    185         if (!schedule1.Resources[i].Equals(schedule2.Resources[i]))
    186           return false;
    187       }
    188 
    189       return true;
    190     }
    191 
    192166  }
    193167}
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/ScheduledTask.cs

    r9456 r11073  
    7575      return sb.ToString();
    7676    }
    77 
    78     public override bool Equals(object obj) {
    79       if (obj.GetType() == typeof(ScheduledTask))
    80         return AreEqual(this, obj as ScheduledTask);
    81       else
    82         return false;
    83     }
    84 
    85     public override int GetHashCode() {
    86       return TaskNr ^ JobNr;
    87     }
    88 
    89     public static bool AreEqual(ScheduledTask task1, ScheduledTask task2) {
    90       return (
    91         task1.TaskNr == task2.TaskNr &&
    92         task1.Duration == task2.Duration &&
    93         task1.JobNr == task2.JobNr &&
    94         task1.ResourceNr == task2.ResourceNr &&
    95         task1.StartTime == task2.StartTime &&
    96         task1.EndTime == task2.EndTime);
    97     }
    9877  }
    9978}
  • stable/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Task.cs

    r9456 r11073  
    3838        bool changed = taskNr != value;
    3939        taskNr = value;
    40         if (changed) OnPropertyChanged("TaskNr");
     40        if (changed) {
     41          OnPropertyChanged("TaskNr");
     42          OnToStringChanged();
     43        }
    4144      }
    4245    }
     
    4851        bool changed = resourceNr != value;
    4952        resourceNr = value;
    50         if (changed) OnPropertyChanged("ResourceNr");
     53        if (changed) {
     54          OnPropertyChanged("ResourceNr");
     55          OnToStringChanged();
     56        }
    5157      }
    5258    }
     
    8995    protected Task(Task original, Cloner cloner)
    9096      : base(original, cloner) {
    91       this.ResourceNr = original.ResourceNr;
    92       this.JobNr = original.JobNr;
    93       this.Duration = original.Duration;
    94       this.TaskNr = original.TaskNr;
    95       this.IsScheduled = original.IsScheduled;
     97      this.resourceNr = original.ResourceNr;
     98      this.jobNr = original.JobNr;
     99      this.duration = original.Duration;
     100      this.taskNr = original.TaskNr;
     101      this.isScheduled = original.IsScheduled;
    96102    }
    97103    public Task() : this(-1, -1, -1, 0) { }
    98104    public Task(int taskNr, int resNr, int jobNr, double duration)
    99105      : base() {
    100       Duration = duration;
    101       ResourceNr = resNr;
    102       JobNr = jobNr;
    103       TaskNr = taskNr;
    104       IsScheduled = false;
     106      this.duration = duration;
     107      this.resourceNr = resNr;
     108      this.jobNr = jobNr;
     109      this.taskNr = taskNr;
     110      this.isScheduled = false;
    105111    }
    106112
     
    115121    }
    116122
    117     public override bool Equals(object obj) {
    118       if (obj.GetType() == typeof(Task))
    119         return AreEqual(this, obj as Task);
    120       else
    121         return false;
    122     }
    123 
    124     public override int GetHashCode() {
    125       return TaskNr ^ JobNr;
    126     }
    127 
    128     public static bool AreEqual(Task task1, Task task2) {
    129       return (task1.Duration == task2.Duration &&
    130         task1.IsScheduled == task2.IsScheduled &&
    131         task1.JobNr == task2.JobNr &&
    132         task1.ResourceNr == task2.ResourceNr &&
    133         task1.TaskNr == task2.TaskNr);
    134     }
    135 
    136123    public event PropertyChangedEventHandler PropertyChanged;
    137124    protected virtual void OnPropertyChanged(string propertyName) {
  • stable/HeuristicLab.Problems.Scheduling.Views/3.3/JobShopSchedulingProblemView.cs

    r9456 r11073  
    2020#endregion
    2121
     22using System;
    2223using System.Windows.Forms;
     24using HeuristicLab.Collections;
     25using HeuristicLab.Encodings.ScheduleEncoding;
    2326using HeuristicLab.MainForm;
    2427using HeuristicLab.Optimization.Views;
     
    4346    protected override void OnContentChanged() {
    4447      base.OnContentChanged();
    45       if (Content == null) {
    46         ganttChart.Reset();
    47       } else {
    48         FillGanttChart(Content);
     48      FillGanttChart();
     49    }
     50
     51    protected override void DeregisterContentEvents() {
     52      Content.JobDataParameter.ValueChanged -= JobDataParameterOnValueChanged;
     53      Content.JobData.ItemsAdded -= JobsOnChanged;
     54      Content.JobData.ItemsRemoved -= JobsOnChanged;
     55      Content.JobData.ItemsReplaced -= JobsOnChanged;
     56      Content.JobData.CollectionReset -= JobsOnChanged;
     57      foreach (var job in Content.JobData) {
     58        job.TasksChanged -= JobOnTasksChanged;
     59      }
     60      base.DeregisterContentEvents();
     61    }
     62    protected override void RegisterContentEvents() {
     63      base.RegisterContentEvents();
     64      Content.JobDataParameter.ValueChanged += JobDataParameterOnValueChanged;
     65      Content.JobData.ItemsAdded += JobsOnChanged;
     66      Content.JobData.ItemsRemoved += JobsOnChanged;
     67      Content.JobData.ItemsReplaced += JobsOnChanged;
     68      Content.JobData.CollectionReset += JobsOnChanged;
     69      foreach (var job in Content.JobData) {
     70        job.TasksChanged += JobOnTasksChanged;
    4971      }
    5072    }
    5173
    52     private void FillGanttChart(JobShopSchedulingProblem content) {
     74    private void JobsOnChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<Job>> e) {
     75      foreach (var job in e.OldItems)
     76        job.Value.TasksChanged -= JobOnTasksChanged;
     77      foreach (var job in e.Items)
     78        job.Value.TasksChanged += JobOnTasksChanged;
     79      FillGanttChart();
     80    }
     81
     82    private void JobDataParameterOnValueChanged(object sender, EventArgs e) {
     83      Content.JobData.ItemsAdded += JobsOnChanged;
     84      Content.JobData.ItemsRemoved += JobsOnChanged;
     85      Content.JobData.ItemsReplaced += JobsOnChanged;
     86      Content.JobData.CollectionReset += JobsOnChanged;
     87      foreach (var job in Content.JobData) {
     88        job.TasksChanged += JobOnTasksChanged;
     89      }
     90      FillGanttChart();
     91    }
     92
     93    private void JobOnTasksChanged(object sender, EventArgs e) {
     94      FillGanttChart();
     95    }
     96
     97    private void FillGanttChart() {
    5398      ganttChart.Reset();
     99      if (Content == null) return;
    54100      int jobCount = 0;
    55       foreach (var j in content.JobData) {
     101      foreach (var j in Content.JobData) {
    56102        double lastEndTime = 0;
    57         foreach (var t in content.JobData[jobCount].Tasks) {
     103        foreach (var t in Content.JobData[jobCount].Tasks) {
    58104          int categoryNr = t.JobNr;
    59105          string categoryName = "Job" + categoryNr;
     
    63109            lastEndTime + 1,
    64110            lastEndTime + t.Duration,
    65             "Job" + t.JobNr + " - " + "Task#" + t.TaskNr.ToString());
     111            "Job" + t.JobNr + " - " + "Task#" + t.TaskNr);
    66112          lastEndTime += t.Duration;
    67113        }
  • stable/HeuristicLab.Tests

  • stable/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/DirectScheduleGTCrossoverTest.cs

    r9885 r11073  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition;
     
    4849      actual = DirectScheduleGTCrossover.Apply(random, parent1, parent2, jobData, mutProp);
    4950      Schedule expected = DirectScheduleRandomCreator.Apply(3, 3, new PWREncoding(3, 3, new TestRandom(new int[] { 0, 2, 1, 1, 0, 2, 1, 2, 0 }, null)), TestUtils.CreateJobData());
    50       Assert.IsTrue(actual.Equals(expected));
     51      Assert.IsTrue(TestUtils.ScheduleEquals(actual, expected));
    5152    }
     53
    5254  }
    5355}
  • stable/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/JSMJOXCrossoverTest.cs

    r9885 r11073  
    5353      actual = JSMJOXCrossover.Apply(random, p1, p2);
    5454
    55       Assert.IsTrue(expected.Equals(actual));
     55      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, actual));
    5656    }
    5757  }
  • stable/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/JSMSXXCrossoverTest.cs

    r9885 r11073  
    5353      actual = JSMSXXCrossover.Apply(random, p1, p2);
    5454
    55       Assert.IsTrue(expected.Equals(actual));
     55      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, actual));
    5656    }
    5757  }
  • stable/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/JSMShiftChangeManipulatorTest.cs

    r9885 r11073  
    5151      expected.JobSequenceMatrix = jsm;
    5252
    53       Assert.IsTrue(individual.Equals(expected));
     53      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, individual));
    5454    }
    5555  }
  • stable/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/PWRGOXCrossoverTest.cs

    r9885 r11073  
    4747      PWREncoding actual;
    4848      actual = PWRGOXCrossover.Apply(random, parent1, parent2);
    49       Assert.IsTrue(actual.Equals(expected));
     49      Assert.IsTrue(TestUtils.PRWEncodingEquals(expected, actual));
    5050    }
    5151  }
  • stable/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/PWRPPXCrossoverTest.cs

    r9885 r11073  
    4747      PWREncoding actual;
    4848      actual = PWRPPXCrossover.Apply(random, parent1, parent2);
    49       Assert.IsTrue(actual.Equals(expected));
     49      Assert.IsTrue(TestUtils.PRWEncodingEquals(expected, actual));
    5050    }
    5151  }
  • stable/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/TestUtils.cs

    r9885 r11073  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.IntegerVectorEncoding;
     
    9798      return result;
    9899    }
     100    public static bool ScheduleEquals(Schedule actual, Schedule expected) {
     101      return actual.Resources.Count == expected.Resources.Count &&
     102             actual.Resources.Zip(expected.Resources, (a, e) => ResourceEquals(a, e)).All(_ => _);
     103    }
     104
     105    public static bool ResourceEquals(Resource actual, Resource expected) {
     106      return actual.Index == expected.Index &&
     107             actual.TotalDuration == expected.TotalDuration &&
     108             actual.Tasks.Count == expected.Tasks.Count &&
     109             actual.Tasks.Zip(expected.Tasks, (a, e) => TaskEquals(a, e)).All(_ => _);
     110    }
     111
     112    public static bool TaskEquals(ScheduledTask actual, ScheduledTask expected) {
     113      return
     114        actual.StartTime == expected.StartTime &&
     115        actual.EndTime == expected.EndTime &&
     116        actual.Duration == expected.Duration &&
     117        actual.ResourceNr == expected.ResourceNr &&
     118        actual.JobNr == expected.JobNr &&
     119        actual.TaskNr == expected.TaskNr;
     120    }
     121
     122    public static bool JSMEncodingEquals(JSMEncoding expected, JSMEncoding actual) {
     123      if (expected.JobSequenceMatrix.Count != actual.JobSequenceMatrix.Count)
     124        return false;
     125      for (int i = 0; i < expected.JobSequenceMatrix.Count; i++) {
     126        if (!PermutationEquals(expected.JobSequenceMatrix[i], actual.JobSequenceMatrix[i]))
     127          return false;
     128      }
     129      return true;
     130    }
     131    private static bool PermutationEquals(Permutation p1, Permutation p2) {
     132      if (p1.Length != p2.Length)
     133        return false;
     134      for (int i = 0; i < p1.Length; i++) {
     135        if (p1[i] != p2[i])
     136          return false;
     137      }
     138      return true;
     139    }
     140
     141    public static bool PRWEncodingEquals(PWREncoding expected, PWREncoding actual) {
     142      if (expected.PermutationWithRepetition.Length != actual.PermutationWithRepetition.Length)
     143        return false;
     144      for (int i = 0; i < expected.PermutationWithRepetition.Length; i++) {
     145        if (expected.PermutationWithRepetition[i] != actual.PermutationWithRepetition[i])
     146          return false;
     147      }
     148      return true;
     149    }
    99150  }
    100151}
Note: See TracChangeset for help on using the changeset viewer.