Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1966_HeuristicLab.BinPacking/old files/GroupingVector/Moves/ChangeGrouping/ChangeGroupingMove.cs @ 16100

Last change on this file since 16100 was 14046, checked in by gkronber, 8 years ago

#1966: unified namespaces

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Joseph Helm and 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.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Problems.BinPacking;
28
29namespace HeuristicLab.Encodings.PackingEncoding.GroupingVector {
30  [Item("Change Grouping Move", "A move on a grouping vector that is specified by a single group-assignment-index.")]
31  [StorableClass]
32  public class ChangeGroupingMove : GroupingMove, IPackingMove {
33    [Storable]
34    public int Index { get; protected set; }
35    [Storable]
36    public int NewGroup { get; protected set; }
37
38    [StorableConstructor]
39    protected ChangeGroupingMove(bool deserializing) : base(deserializing) { }
40    protected ChangeGroupingMove(ChangeGroupingMove original, Cloner cloner)
41      : base(original, cloner) {
42      this.Index = original.Index;
43      this.NewGroup = original.NewGroup;
44    }
45    public ChangeGroupingMove(int index, int newGroup, GroupingVectorEncoding groupingVector)
46      : base(groupingVector) {
47      Index = index;
48    }
49
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new ChangeGroupingMove(this, cloner);
52    }
53
54    public override IPackingSolutionEncoding GetSolutionAfterMove() {
55      GroupingVectorEncoding newSolution = new GroupingVectorEncoding();
56      newSolution.GroupingVector = new IntegerVector(GroupingVector.GroupingVector);
57      newSolution.GroupingVector[Index] = NewGroup;
58      return newSolution;
59    }
60
61    public override Type GetMoveAttributeType() {
62      return typeof(ChangeGroupingMoveAttribute);
63    }
64
65    public override GroupingMoveAttribute GetAttribute(double quality) {
66      return new ChangeGroupingMoveAttribute(Index, NewGroup, quality);
67    }
68
69    public override bool BelongsToAttribute(GroupingMoveAttribute attribute, bool hardCriterion) {
70      var attr = attribute as ChangeGroupingMoveAttribute;
71      if (attr != null) {
72        if (hardCriterion) {
73          if (Index == attr.ItemIndex) //|| GroupingVector.GroupingVector[Index] == attr.AssignedBin)
74            return true;
75        } else
76          if (Index == attr.ItemIndex && GroupingVector.GroupingVector[Index] == attr.AssignedBin)
77            return true;
78      }
79      return false;
80    }
81
82    public override string ToString() {
83      return "CGM(i=" + Index + ", g=" + NewGroup + ")";
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.