Changeset 435
- Timestamp:
- 08/04/08 00:35:55 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Constraints
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Constraints/AllSubOperatorsTypeConstraint.cs
r2 r435 49 49 public void AddOperator(IOperator op) { 50 50 groupConstraint.AddOperator(op); 51 FireChanged(); 51 52 } 52 53 53 54 public void RemoveOperator(IOperator op) { 54 55 groupConstraint.RemoveOperator(op); 56 FireChanged(); 55 57 } 56 58 57 59 public override bool Check(IItem data) { 58 60 IOperator op = data as IOperator; 59 if 61 if(data == null) return false; 60 62 61 for (int i = 0; i < op.SubOperators.Count; i++) {63 for(int i = 0; i < op.SubOperators.Count; i++) { 62 64 groupConstraint.SubOperatorIndex.Data = i; 63 if(groupConstraint.Check(data) ==false) {65 if(groupConstraint.Check(data) == false) { 64 66 return false; 65 67 } … … 84 86 85 87 #region persistence 86 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {88 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 87 89 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 88 90 XmlNode subOperatorsNode = PersistenceManager.Persist("SubOperatorsGroupConstraint", groupConstraint, document, persistedObjects); … … 92 94 } 93 95 94 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {96 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 95 97 base.Populate(node, restoredObjects); 96 98 groupConstraint = (SubOperatorTypeConstraint)PersistenceManager.Restore(node.SelectSingleNode("SubOperatorsGroupConstraint"), restoredObjects); -
trunk/sources/HeuristicLab.Constraints/SubOperatorsTypeConstraint.cs
r430 r435 52 52 } 53 53 54 public SubOperatorTypeConstraint(int index) : base() { 55 subOperatorIndex = new IntData(index); 56 subOperators = new List<IOperator>(); 57 } 58 54 59 public void AddOperator(IOperator op) { 55 // check if already in the list of allowed functions 56 foreach(IOperator existingOp in subOperators) { 57 if(existingOp == op) { 58 return; 59 } 60 if(!subOperators.Contains(op)) { 61 subOperators.Add(op); 62 FireChanged(); 60 63 } 61 62 subOperators.Add(op);63 64 } 64 65 65 66 public void RemoveOperator(IOperator op) { 66 IOperator matchingOperator = null; 67 foreach(IOperator existingOp in subOperators) { 68 if(existingOp == op) { 69 matchingOperator = existingOp; 70 break; 71 } 72 } 73 74 if(matchingOperator != null) { 75 subOperators.Remove(matchingOperator); 67 if(subOperators.Contains(op)) { 68 subOperators.Remove(op); 69 FireChanged(); 76 70 } 77 71 } … … 84 78 return false; 85 79 } 86 87 return subOperators.Exists(delegate(IOperator curOp) { return curOp == op.SubOperators[subOperatorIndex.Data]; }); 80 return subOperators.Contains(op.SubOperators[subOperatorIndex.Data]); 88 81 } 89 82
Note: See TracChangeset
for help on using the changeset viewer.