Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MemPRAlgorithm/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Moves/SplitMove.cs @ 14477

Last change on this file since 14477 was 14477, checked in by abeham, 7 years ago

#2701:

  • Added TryGetBy(First|Second) method to BidirectionalDictionary
  • Updated linear linkage encoding
    • Added move generator and moves for shift, merge, split, and extract moves
    • Added unit test (Apply/Undo)
  • Updated MemPR (linear linkage)
    • Added basic tabu walk
  • Fixed bug in MemPR (permutation)
  • Updated Tests project
File size: 1.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 HeuristicLab.Collections;
24
25namespace HeuristicLab.Encodings.LinearLinkageEncoding {
26  public class SplitMove : Move {
27
28    private int nextItem;
29
30    public SplitMove(int item) {
31      Item = item;
32      nextItem = -1;
33    }
34
35    public override void Apply(LinearLinkage lle) {
36      if (lle[Item] == Item) throw new ArgumentException("Move conditions have changed, group is already split at " + Item);
37      nextItem = lle[Item];
38      lle[Item] = Item;
39    }
40
41    public override void Undo(LinearLinkage lle) {
42      if (lle[Item] != Item) throw new ArgumentException("Move conditions have changed, group no longer terminates at " + Item);
43      if (nextItem < 0) throw new InvalidOperationException("Cannot undo move that has not been applied first.");
44      lle[Item] = nextItem;
45    }
46
47    public override void UpdateLinks(BidirectionalDictionary<int, int> links) {
48      // nothing has to be done
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.