Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Manipulators/JSMShiftChangeManipulator.cs @ 8603

Last change on this file since 8603 was 8603, checked in by gkronber, 12 years ago

#1329:

  • updated copy-right year
  • trimmed assembly and plugin references
  • removed x86 and x64 build configurations
File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix {
30
31  [Item("JSMShiftChangeManipulator", "Represents a manipulation operation where the operations of a randomly determined job are shifted in one direction for all resources.")]
32  [StorableClass]
33  public class JSMShiftChangeManipulator : JSMManipulator {
34    [StorableConstructor]
35    protected JSMShiftChangeManipulator(bool deserializing) : base(deserializing) { }
36    protected JSMShiftChangeManipulator(JSMShiftChangeManipulator original, Cloner cloner)
37      : base(original, cloner) {
38    }
39    public override IDeepCloneable Clone(Cloner cloner) {
40      return new JSMShiftChangeManipulator(this, cloner);
41    }
42
43    public JSMShiftChangeManipulator() : base() { }
44
45
46    public static void Apply(IRandom random, JSMEncoding individual) {
47      int nrOfJobs = individual.JobSequenceMatrix[0].Length;
48      int jobIndex = random.Next(nrOfJobs);
49      int signedFactor = random.Next(2);
50      for (int permutationIndex = 0; permutationIndex < individual.JobSequenceMatrix.Count; permutationIndex++) {
51        int i = 0;
52        Permutation currentPermutation = individual.JobSequenceMatrix[permutationIndex];
53        while (i < currentPermutation.Length && currentPermutation[i] != jobIndex)
54          i++;
55        int shift = (signedFactor == 0) ? random.Next(nrOfJobs / 2) * -1 : random.Next(nrOfJobs / 2);
56        int newIndex = shift + i;
57        if (newIndex < 0) newIndex = 0;
58        if (newIndex >= nrOfJobs) newIndex = nrOfJobs - 1;
59        List<int> aux = currentPermutation.ToList<int>();
60        int swap = currentPermutation[i];
61        aux.RemoveAt(i);
62        aux.Insert(newIndex, swap);
63        individual.JobSequenceMatrix[permutationIndex] = new Permutation(PermutationTypes.Absolute, aux.ToArray());
64      }
65    }
66
67    protected override void Manipulate(IRandom random, JSMEncoding individual) {
68      Apply(random, individual);
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.