[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);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public void RemoveOperator(IOperator op) {
|
---|
| 54 | groupConstraint.RemoveOperator(op);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public override bool Check(IItem data) {
|
---|
| 58 | IOperator op = data as IOperator;
|
---|
| 59 | if (data == null) return false;
|
---|
| 60 |
|
---|
| 61 | for (int i = 0; i < op.SubOperators.Count; i++ ) {
|
---|
| 62 | groupConstraint.SubOperatorIndex.Data = i;
|
---|
| 63 | if(groupConstraint.Check(data)==false) {
|
---|
| 64 | return false;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | return true;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 71 | AllSubOperatorsTypeConstraint clone = new AllSubOperatorsTypeConstraint();
|
---|
| 72 | clonedObjects.Add(Guid, clone);
|
---|
| 73 | clone.groupConstraint = (SubOperatorTypeConstraint)Auxiliary.Clone(groupConstraint, clonedObjects);
|
---|
| 74 | return clone;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public override IView CreateView() {
|
---|
| 78 | return new AllSubOperatorsTypeConstraintView(groupConstraint);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public override void Accept(IConstraintVisitor visitor) {
|
---|
| 82 | visitor.Visit(this);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | #region persistence
|
---|
| 86 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
|
---|
| 87 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
| 88 | XmlNode subOperatorsNode = PersistenceManager.Persist("SubOperatorsGroupConstraint", groupConstraint, document, persistedObjects);
|
---|
| 89 | node.AppendChild(subOperatorsNode);
|
---|
| 90 |
|
---|
| 91 | return node;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
|
---|
| 95 | base.Populate(node, restoredObjects);
|
---|
| 96 | groupConstraint = (SubOperatorTypeConstraint)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorsGroupConstraint"), restoredObjects);
|
---|
| 97 | }
|
---|
| 98 | #endregion persistence
|
---|
| 99 | }
|
---|
| 100 | }
|
---|