- Timestamp:
- 06/09/09 00:57:49 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.3/OperatorBase.cs
r1823 r2033 30 30 /// The base class for all operators. 31 31 /// </summary> 32 public abstract class OperatorBase : ConstrainedItemBase, IOperator {32 public abstract class OperatorBase : ItemBase, IOperator { 33 33 34 34 [Storable] … … 130 130 /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param> 131 131 /// <returns>The cloned object as <see cref="OperatorBase"/>.</returns> 132 public override object Clone(IDictionary< Guid, object> clonedObjects) {132 public override object Clone(IDictionary<long, object> clonedObjects) { 133 133 OperatorBase clone = (OperatorBase)base.Clone(clonedObjects); 134 134 clone.myName = Name; … … 162 162 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1); 163 163 } 164 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator)"/>165 /// <param name="subOperator">The sub operator to add.</param>166 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>167 public virtual bool TryAddSubOperator(IOperator subOperator) {168 mySubOperators.Add(subOperator);169 if (IsValid()) {170 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);171 return true;172 } else {173 mySubOperators.RemoveAt(mySubOperators.Count - 1);174 return false;175 }176 }177 /// <inheritdoc cref="HeuristicLab.Core.IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator,178 /// out System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/>179 /// <param name="subOperator">The sub operator to add.</param>180 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>181 public virtual bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {182 mySubOperators.Add(subOperator);183 if (IsValid(out violatedConstraints)) {184 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);185 return true;186 } else {187 mySubOperators.RemoveAt(mySubOperators.Count - 1);188 return false;189 }190 }191 164 /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/> 192 165 /// <param name="subOperator">The sub operator to add.</param> … … 196 169 OnSubOperatorAdded(subOperator, index); 197 170 } 198 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int)"/>199 /// <param name="subOperator">The sub operator to add.</param>200 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>201 public virtual bool TryAddSubOperator(IOperator subOperator, int index) {202 mySubOperators.Insert(index, subOperator);203 if (IsValid()) {204 OnSubOperatorAdded(subOperator, index);205 return true;206 } else {207 mySubOperators.RemoveAt(index);208 return false;209 }210 }211 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int, out212 /// System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/>213 /// <param name="subOperator">The sub operator to add.</param>214 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>215 public virtual bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {216 mySubOperators.Insert(index, subOperator);217 if (IsValid(out violatedConstraints)) {218 OnSubOperatorAdded(subOperator, index);219 return true;220 } else {221 mySubOperators.RemoveAt(index);222 return false;223 }224 }225 171 /// <inheritdoc/> 226 172 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks> … … 229 175 mySubOperators.RemoveAt(index); 230 176 OnSubOperatorRemoved(op, index); 231 }232 /// <inheritdoc/>233 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>234 public virtual bool TryRemoveSubOperator(int index) {235 IOperator op = mySubOperators[index];236 mySubOperators.RemoveAt(index);237 if (IsValid()) {238 OnSubOperatorRemoved(op, index);239 return true;240 } else {241 mySubOperators.Insert(index, op);242 return false;243 }244 }245 /// <inheritdoc/>246 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>247 public virtual bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {248 IOperator op = mySubOperators[index];249 mySubOperators.RemoveAt(index);250 if (IsValid(out violatedConstraints)) {251 OnSubOperatorRemoved(op, index);252 return true;253 } else {254 mySubOperators.Insert(index, op);255 return false;256 }257 177 } 258 178 #endregion … … 274 194 } 275 195 /// <inheritdoc/> 276 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>277 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo) {278 myVariableInfos.Add(variableInfo.FormalName, variableInfo);279 if (IsValid()) {280 OnVariableInfoAdded(variableInfo);281 return true;282 } else {283 myVariableInfos.Remove(variableInfo.FormalName);284 return false;285 }286 }287 /// <inheritdoc/>288 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>289 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints) {290 myVariableInfos.Add(variableInfo.FormalName, variableInfo);291 if (IsValid(out violatedConstraints)) {292 OnVariableInfoAdded(variableInfo);293 return true;294 } else {295 myVariableInfos.Remove(variableInfo.FormalName);296 return false;297 }298 }299 /// <inheritdoc/>300 196 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 301 197 public virtual void RemoveVariableInfo(string formalName) { … … 305 201 OnVariableInfoRemoved(variableInfo); 306 202 } 307 }308 /// <inheritdoc/>309 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>310 public virtual bool TryRemoveVariableInfo(string formalName) {311 IVariableInfo variableInfo;312 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {313 myVariableInfos.Remove(formalName);314 if (IsValid()) {315 OnVariableInfoRemoved(variableInfo);316 return true;317 } else {318 myVariableInfos.Add(formalName, variableInfo);319 return false;320 }321 }322 return true;323 }324 /// <inheritdoc/>325 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>326 public virtual bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints) {327 IVariableInfo variableInfo;328 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {329 myVariableInfos.Remove(formalName);330 if (IsValid(out violatedConstraints)) {331 OnVariableInfoRemoved(variableInfo);332 return true;333 } else {334 myVariableInfos.Add(formalName, variableInfo);335 return false;336 }337 }338 violatedConstraints = new List<IConstraint>();339 return true;340 203 } 341 204 #endregion … … 358 221 variable.NameChanged += new EventHandler(Variable_NameChanged); 359 222 OnVariableAdded(variable); 360 }361 /// <inheritdoc/>362 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>363 /// event handlers.</remarks>364 public virtual bool TryAddVariable(IVariable variable) {365 myVariables.Add(variable.Name, variable);366 if (IsValid()) {367 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging);368 variable.NameChanged += new EventHandler(Variable_NameChanged);369 OnVariableAdded(variable);370 return true;371 } else {372 myVariableInfos.Remove(variable.Name);373 return false;374 }375 }376 /// <inheritdoc/>377 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>378 /// event handlers.</remarks>379 public virtual bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints) {380 myVariables.Add(variable.Name, variable);381 if (IsValid(out violatedConstraints)) {382 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging);383 variable.NameChanged += new EventHandler(Variable_NameChanged);384 OnVariableAdded(variable);385 return true;386 } else {387 myVariableInfos.Remove(variable.Name);388 return false;389 }390 223 } 391 224 /// <inheritdoc/> … … 400 233 OnVariableRemoved(variable); 401 234 } 402 }403 /// <inheritdoc/>404 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>405 /// event handlers.</remarks>406 public virtual bool TryRemoveVariable(string name) {407 IVariable variable;408 if (myVariables.TryGetValue(name, out variable)) {409 myVariables.Remove(name);410 if (IsValid()) {411 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging);412 variable.NameChanged -= new EventHandler(Variable_NameChanged);413 OnVariableRemoved(variable);414 return true;415 } else {416 myVariables.Add(name, variable);417 return false;418 }419 }420 return true;421 }422 /// <inheritdoc/>423 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>424 /// event handlers.</remarks>425 public virtual bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints) {426 IVariable variable;427 if (myVariables.TryGetValue(name, out variable)) {428 myVariables.Remove(name);429 if (IsValid(out violatedConstraints)) {430 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging);431 variable.NameChanged -= new EventHandler(Variable_NameChanged);432 OnVariableRemoved(variable);433 return true;434 } else {435 myVariables.Add(name, variable);436 return false;437 }438 }439 violatedConstraints = new List<IConstraint>();440 return true;441 235 } 442 236 private void Variable_NameChanging(object sender, NameChangingEventArgs e) { … … 489 283 } 490 284 #endregion 285 491 286 /// <inheritdoc/> 492 287 public virtual IOperation Execute(IScope scope) {
Note: See TracChangeset
for help on using the changeset viewer.