Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gteufl/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Manipulators/JSMShiftChangeManipulator.cs @ 10679

Last change on this file since 10679 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.PermutationEncoding;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix {
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
35    [StorableConstructor]
36    protected JSMShiftChangeManipulator(bool deserializing) : base(deserializing) { }
37    protected JSMShiftChangeManipulator(JSMShiftChangeManipulator original, Cloner cloner) : base(original, cloner) { }
38    public JSMShiftChangeManipulator() : base() { }
39
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new JSMShiftChangeManipulator(this, cloner);
42    }
43
44    public static void Apply(IRandom random, JSMEncoding individual) {
45      int nrOfJobs = individual.JobSequenceMatrix[0].Length;
46      int jobIndex = random.Next(nrOfJobs);
47      int signedFactor = random.Next(2);
48      for (int permutationIndex = 0; permutationIndex < individual.JobSequenceMatrix.Count; permutationIndex++) {
49        int i = 0;
50        Permutation currentPermutation = individual.JobSequenceMatrix[permutationIndex];
51        while (i < currentPermutation.Length && currentPermutation[i] != jobIndex)
52          i++;
53        int shift = (signedFactor == 0) ? random.Next(nrOfJobs / 2) * -1 : random.Next(nrOfJobs / 2);
54        int newIndex = shift + i;
55        if (newIndex < 0) newIndex = 0;
56        if (newIndex >= nrOfJobs) newIndex = nrOfJobs - 1;
57        List<int> aux = currentPermutation.ToList<int>();
58        int swap = currentPermutation[i];
59        aux.RemoveAt(i);
60        aux.Insert(newIndex, swap);
61        individual.JobSequenceMatrix[permutationIndex] = new Permutation(PermutationTypes.Absolute, aux.ToArray());
62      }
63    }
64
65    protected override void Manipulate(IRandom random, IScheduleEncoding encoding) {
66      var solution = encoding as JSMEncoding;
67      if (solution == null) throw new InvalidOperationException("Encoding is not of type JSMEncoding");
68      Apply(random, solution);
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.