[2] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using System.Xml;
|
---|
| 28 | using System.Diagnostics;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Constraints {
|
---|
| 31 | public class AllSubOperatorsTypeConstraint : ConstraintBase {
|
---|
| 32 |
|
---|
| 33 | private SubOperatorTypeConstraint groupConstraint;
|
---|
| 34 | public IList<IOperator> AllowedSubOperators {
|
---|
| 35 | get {
|
---|
| 36 | return groupConstraint.AllowedSubOperators;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public override string Description {
|
---|
| 41 | get { return "All sub-operators have to be elements of a pre-defined group."; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public AllSubOperatorsTypeConstraint()
|
---|
| 45 | : base() {
|
---|
| 46 | groupConstraint = new SubOperatorTypeConstraint();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public void AddOperator(IOperator op) {
|
---|
| 50 | groupConstraint.AddOperator(op);
|
---|
[435] | 51 | FireChanged();
|
---|
[2] | 52 | }
|
---|
| 53 |
|
---|
| 54 | public void RemoveOperator(IOperator op) {
|
---|
| 55 | groupConstraint.RemoveOperator(op);
|
---|
[435] | 56 | FireChanged();
|
---|
[2] | 57 | }
|
---|
| 58 |
|
---|
| 59 | public override bool Check(IItem data) {
|
---|
| 60 | IOperator op = data as IOperator;
|
---|
[435] | 61 | if(data == null) return false;
|
---|
[2] | 62 |
|
---|
[435] | 63 | for(int i = 0; i < op.SubOperators.Count; i++) {
|
---|
[2] | 64 | groupConstraint.SubOperatorIndex.Data = i;
|
---|
[435] | 65 | if(groupConstraint.Check(data) == false) {
|
---|
[2] | 66 | return false;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | return true;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[467] | 72 | public void Clear() {
|
---|
| 73 | groupConstraint.Clear();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[2] | 76 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 77 | AllSubOperatorsTypeConstraint clone = new AllSubOperatorsTypeConstraint();
|
---|
| 78 | clonedObjects.Add(Guid, clone);
|
---|
| 79 | clone.groupConstraint = (SubOperatorTypeConstraint)Auxiliary.Clone(groupConstraint, clonedObjects);
|
---|
| 80 | return clone;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public override IView CreateView() {
|
---|
| 84 | return new AllSubOperatorsTypeConstraintView(groupConstraint);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public override void Accept(IConstraintVisitor visitor) {
|
---|
| 88 | visitor.Visit(this);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | #region persistence
|
---|
[435] | 92 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
|
---|
[2] | 93 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
| 94 | XmlNode subOperatorsNode = PersistenceManager.Persist("SubOperatorsGroupConstraint", groupConstraint, document, persistedObjects);
|
---|
| 95 | node.AppendChild(subOperatorsNode);
|
---|
| 96 |
|
---|
| 97 | return node;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[435] | 100 | public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
[2] | 101 | base.Populate(node, restoredObjects);
|
---|
| 102 | groupConstraint = (SubOperatorTypeConstraint)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorsGroupConstraint"), restoredObjects);
|
---|
| 103 | }
|
---|
| 104 | #endregion persistence
|
---|
| 105 | }
|
---|
| 106 | }
|
---|