Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Constraints/3.3/NotConstraint.cs @ 2087

Last change on this file since 2087 was 1823, checked in by epitzer, 15 years ago

Namespace refactoring: rename formatters & decomposers -> primitive and composite serializers. (#603)

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Text;
25using System.Xml;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Constraints {
31  /// <summary>
32  /// Constraint where its sub-constraint must be false to be true.
33  /// </summary>
34  public class NotConstraint : ConstraintBase {
35
36    [Storable]
37    private ConstraintBase subConstraint;
38    /// <summary>
39    /// Gets or sets the sub-constraint.
40    /// </summary>
41    /// <remarks>Calls <see cref="ItemBase.OnChanged"/> of base class
42    /// <see cref="ConstraintBase"/> in the setter.</remarks>
43    public ConstraintBase SubConstraint {
44      get { return subConstraint; }
45      set {
46        subConstraint = value;
47        OnChanged();
48      }
49    }
50    /// <inheritdoc select="summary"/>
51    public override string Description {
52      get {
53        return "Requires that a constraint must be false to be true";
54      }
55    }
56    /// <summary>
57    /// Initializes a new instance of <see cref="NotConstraint"/>.
58    /// </summary>
59    public NotConstraint()
60      : base() {
61    }
62
63    /// <summary>
64    /// Checks whether the given element fulfills the current constraint.
65    /// </summary>
66    /// <param name="data">The item to check.</param>
67    /// <returns><c>true</c> if the constraint could be fulfilled, <c>false</c> otherwise.</returns>
68    public override bool Check(IItem data) {
69      return (subConstraint == null) || (!subConstraint.Check(data));
70    }
71
72    /// <summary>
73    /// Creates a new instance of <see cref="NotConstraintView"/> to represent the current
74    /// instance visually.
75    /// </summary>
76    /// <returns>The created view as <see cref="NotConstraintView"/>.</returns>
77    public override IView CreateView() {
78      return new NotConstraintView(this);
79    }
80
81    /// <summary>
82    /// Clones the current instance (deep clone).
83    /// </summary>
84    /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param>
85    /// <returns>The cloned object as <see cref="NotConstraint"/>.</returns>
86    public override object Clone(IDictionary<Guid, object> clonedObjects) {
87      NotConstraint clone = new NotConstraint();
88      clonedObjects.Add(Guid, clone);
89      if (subConstraint != null)
90        clone.SubConstraint = (ConstraintBase)SubConstraint.Clone();
91      return clone;
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.