Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Encodings.ScheduleEncoding/3.3/JobSequenceMatrix/Manipulators/JSMShiftChangeManipulator.cs @ 17399

Last change on this file since 17399 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.1 KB
RevLine 
[6406]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6406]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
[8887]22using System;
[6406]23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.PermutationEncoding;
[16565]28using HEAL.Attic;
[6406]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.")]
[16565]32  [StorableType("69212E02-2006-493D-92C0-0EF4EFDAAF8A")]
[6406]33  public class JSMShiftChangeManipulator : JSMManipulator {
[8887]34
[6406]35    [StorableConstructor]
[16565]36    protected JSMShiftChangeManipulator(StorableConstructorFlag _) : base(_) { }
[8887]37    protected JSMShiftChangeManipulator(JSMShiftChangeManipulator original, Cloner cloner) : base(original, cloner) { }
38    public JSMShiftChangeManipulator() : base() { }
39
[6406]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
[8887]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);
[6406]69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.