Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Encodings.ScheduleEncoding/3.3/PriorityRulesVector/PRVEncoding.cs @ 7624

Last change on this file since 7624 was 6406, checked in by jhelm, 14 years ago

#1329: Applied suggestions from codereview. Added unit-tests. Renamed encoding-project.

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Text;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.IntegerVectorEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.ScheduleEncoding.PriorityRulesVector {
30  [Item("PriorityRulesVectorEncoding", "Represents an encoding for a Scheduling Problem.")]
31  [StorableClass]
32  public class PRVEncoding : Item, IScheduleEncoding {
33    [Storable]
34    public IntegerVector PriorityRulesVector { get; set; }
35
36    [Storable]
37    private IntValue nrOfRules;
38    public IntValue NrOfRules {
39      get {
40        return nrOfRules;
41      }
42    }
43
44
45    [StorableConstructor]
46    protected PRVEncoding(bool deserializing) : base(deserializing) { }
47    protected PRVEncoding(PRVEncoding original, Cloner cloner)
48      : base(original, cloner) {
49      this.nrOfRules = cloner.Clone(original.NrOfRules);
50      this.PriorityRulesVector = cloner.Clone(original.PriorityRulesVector);
51    }
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new PRVEncoding(this, cloner);
54    }
55    public PRVEncoding(int nrOfRules)
56      : base() {
57      this.nrOfRules = new IntValue(nrOfRules);
58      this.PriorityRulesVector = new IntegerVector();
59    }
60    public PRVEncoding(IntegerVector iv, IntValue nrOfRules)
61      : base() {
62      this.nrOfRules = (IntValue)nrOfRules.Clone();
63      this.PriorityRulesVector = (IntegerVector)iv.Clone();
64    }
65    public PRVEncoding(int length, IRandom random, int min, int max, IntValue nrOfRules)
66      : base() {
67      this.nrOfRules = (IntValue)nrOfRules.Clone();
68      this.PriorityRulesVector = new IntegerVector(length, random, min, max);
69    }
70
71
72    public override string ToString() {
73      StringBuilder sb = new StringBuilder();
74      sb.Append("[ ");
75
76      foreach (int i in PriorityRulesVector) {
77        sb.Append(i.ToString() + " ");
78      }
79
80      sb.Append("]");
81      return sb.ToString();
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.