- Timestamp:
- 06/06/09 02:09:35 (16 years ago)
- Location:
- branches/Operator Architecture Refactoring
- Files:
-
- 12 added
- 3 deleted
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/EngineBase.cs
r1815 r2027 188 188 myExecutionStack.Clear(); 189 189 if (OperatorGraph.InitialOperator != null) 190 myExecutionStack.Push(new AtomicOperation(OperatorGraph.InitialOperator, GlobalScope));190 myExecutionStack.Push(new AtomicOperation(OperatorGraph.InitialOperator, new Environment(), GlobalScope)); 191 191 OnInitialized(); 192 192 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Environment.cs
r1994 r2027 27 27 namespace HeuristicLab.Core { 28 28 public class Environment : ItemBase, IEnvironment { 29 private Environment parent; 29 private IEnvironment parent; 30 private Dictionary<string, string> aliases; 30 31 31 32 /// <summary> 32 33 /// Initializes a new instance of <see cref="Environment"/>. 33 34 /// </summary> 34 public Environment() { } 35 public Environment() { 36 aliases = new Dictionary<string, string>(); 37 } 35 38 /// <summary> 36 39 /// Initializes a new instance of <see cref="Environment"/> with the given <paramref name="parent"/>. 37 40 /// </summary> 38 41 /// <param name="parnet">The parent environment.</param> 39 public Environment(Environment parent) { 42 public Environment(IEnvironment parent) 43 : this() { 40 44 this.parent = parent; 41 45 } … … 51 55 Environment clone = new Environment(); 52 56 clonedObjects.Add(Guid, clone); 53 clone.parent = ( Environment)Auxiliary.Clone(parent, clonedObjects);57 clone.parent = (IEnvironment)Auxiliary.Clone(parent, clonedObjects); 54 58 return clone; 59 } 60 61 public void AddAlias(string oldName, string newName) { 62 aliases.Add(oldName, newName); 63 } 64 public void RemoveAlias(string name) { 65 aliases.Remove(name); 66 } 67 68 public string TranslateName(string name) { 69 string translatedName = name; 70 if (aliases.ContainsKey(translatedName)) 71 translatedName = aliases[translatedName]; 72 if (parent != null) 73 translatedName = parent.TranslateName(translatedName); 74 return translatedName; 55 75 } 56 76 … … 83 103 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 84 104 base.Populate(node, restoredObjects); 85 parent = ( Environment)PersistenceManager.Restore(node.SelectSingleNode("ParentEnvironment"), restoredObjects);105 parent = (IEnvironment)PersistenceManager.Restore(node.SelectSingleNode("ParentEnvironment"), restoredObjects); 86 106 } 87 107 #endregion -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/HeuristicLab.Core-3.2.csproj
r1994 r2027 126 126 </Compile> 127 127 <Compile Include="AliasEventArgs.cs" /> 128 <Compile Include="Interfaces\IVariablesContainer.cs" /> 129 <Compile Include="VariablesContainerView.cs"> 130 <SubType>UserControl</SubType> 131 </Compile> 132 <Compile Include="VariablesContainerView.Designer.cs"> 133 <DependentUpon>VariablesContainerView.cs</DependentUpon> 134 </Compile> 135 <Compile Include="Parameter.cs" /> 136 <Compile Include="OperatorBaseParametersView.cs"> 137 <SubType>UserControl</SubType> 138 </Compile> 139 <Compile Include="OperatorBaseParametersView.Designer.cs"> 140 <DependentUpon>OperatorBaseParametersView.cs</DependentUpon> 141 </Compile> 142 <Compile Include="ParameterView.cs"> 143 <SubType>UserControl</SubType> 144 </Compile> 145 <Compile Include="ParameterView.Designer.cs"> 146 <DependentUpon>ParameterView.cs</DependentUpon> 147 </Compile> 128 148 <Compile Include="Environment.cs" /> 149 <Compile Include="OperatorBaseView.cs"> 150 <SubType>UserControl</SubType> 151 </Compile> 152 <Compile Include="OperatorBaseView.Designer.cs"> 153 <DependentUpon>OperatorBaseView.cs</DependentUpon> 154 </Compile> 129 155 <Compile Include="ParameterEventArgs.cs" /> 130 156 <Compile Include="ParameterType.cs" /> … … 143 169 <Compile Include="NameChangingEventArgs.cs" /> 144 170 <Compile Include="OperationEventArgs.cs" /> 145 <Compile Include="OperatorBaseVariablesView.cs">146 <SubType>UserControl</SubType>147 </Compile>148 <Compile Include="OperatorBaseVariablesView.Designer.cs">149 <DependentUpon>OperatorBaseVariablesView.cs</DependentUpon>150 </Compile>151 <Compile Include="OperatorBaseVariableInfosView.cs">152 <SubType>UserControl</SubType>153 </Compile>154 <Compile Include="OperatorBaseVariableInfosView.Designer.cs">155 <DependentUpon>OperatorBaseVariableInfosView.cs</DependentUpon>156 </Compile>157 171 <Compile Include="ExceptionEventArgs.cs" /> 158 172 <Compile Include="Interfaces\IConstrainedItem.cs" /> … … 200 214 <Compile Include="OperatorIndexEventArgs.cs" /> 201 215 <Compile Include="ScopeEventArgs.cs" /> 202 <Compile Include="OperatorBaseView.cs">203 <SubType>UserControl</SubType>204 </Compile>205 <Compile Include="OperatorBaseView.Designer.cs">206 <DependentUpon>OperatorBaseView.cs</DependentUpon>207 </Compile>208 216 <Compile Include="OperatorGraphView.cs"> 209 217 <SubType>UserControl</SubType> … … 295 303 <SubType>Designer</SubType> 296 304 </EmbeddedResource> 305 <EmbeddedResource Include="OperatorBaseParametersView.resx"> 306 <DependentUpon>OperatorBaseParametersView.cs</DependentUpon> 307 <SubType>Designer</SubType> 308 </EmbeddedResource> 309 <EmbeddedResource Include="VariablesContainerView.resx"> 310 <DependentUpon>VariablesContainerView.cs</DependentUpon> 311 <SubType>Designer</SubType> 312 </EmbeddedResource> 313 <EmbeddedResource Include="ParameterView.resx"> 314 <DependentUpon>ParameterView.cs</DependentUpon> 315 <SubType>Designer</SubType> 316 </EmbeddedResource> 297 317 <EmbeddedResource Include="OperatorBaseDescriptionView.resx"> 298 318 <DependentUpon>OperatorBaseDescriptionView.cs</DependentUpon> 299 <SubType>Designer</SubType>300 </EmbeddedResource>301 <EmbeddedResource Include="OperatorBaseVariablesView.resx">302 <DependentUpon>OperatorBaseVariablesView.cs</DependentUpon>303 <SubType>Designer</SubType>304 </EmbeddedResource>305 <EmbeddedResource Include="OperatorBaseVariableInfosView.resx">306 <DependentUpon>OperatorBaseVariableInfosView.cs</DependentUpon>307 319 <SubType>Designer</SubType> 308 320 </EmbeddedResource> -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IEnvironment.cs
r1994 r2027 27 27 public interface IEnvironment : IItem { 28 28 string TranslateName(string name); 29 30 void AddAlias(string oldName, string newName); 31 void RemoveAlias(string name); 29 32 } 30 33 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IOperator.cs
r1994 r2027 49 49 50 50 /// <summary> 51 /// Gets a list of all sub operators. 52 /// </summary> 53 IList<IOperator> SubOperators { get; } 54 /// <summary> 51 55 /// Gets a collection of all variable (parameter) infos. 52 56 /// </summary> 53 57 ICollection<IParameter> Parameters { get; } 58 59 /// <summary> 60 /// Adds the given sub operator to the current instance. 61 /// </summary> 62 /// <param name="op">The operator to add.</param> 63 void AddSubOperator(IOperator op); 64 /// <summary> 65 /// Adds the given sub operator at a the specified <paramref name="index"/>. 66 /// </summary> 67 /// <param name="op">The operator to add.</param> 68 /// <param name="index">The position where to add the operator.</param> 69 void AddSubOperator(IOperator op, int index); 70 /// <summary> 71 /// Removes a sub operator at the specified <paramref name="index"/>. 72 /// </summary> 73 /// <param name="index">The position where to delete the operator.</param> 74 void RemoveSubOperator(int index); 54 75 55 76 /// <summary> … … 75 96 /// <param name="scope">The scope where to execute the current instance.</param> 76 97 /// <returns>The next operation.</returns> 77 IOperation Execute(IEnvironment env ironment, IScope scope);98 IOperation Execute(IEnvironment env, IScope scope); 78 99 /// <summary> 79 100 /// Aborts the current operator. … … 88 109 /// Occurs when the breakpoint flag of the current instance was changed. 89 110 /// </summary> 90 event EventHandler BreakpointChanged; 111 event EventHandler BreakpointChanged; 112 /// <summary> 113 /// Occurs when a sub operator has been added. 114 /// </summary> 115 event EventHandler<OperatorIndexEventArgs> SubOperatorAdded; 116 /// <summary> 117 /// Occurs when a sub operator has been deleted. 118 /// </summary> 119 event EventHandler<OperatorIndexEventArgs> SubOperatorRemoved; 91 120 /// <summary> 92 121 /// Occurs when a variable info has been added. -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Interfaces/IScope.cs
r1994 r2027 29 29 /// Interface for a hierarchical container of variables (containing variables and subscopes). 30 30 /// </summary> 31 public interface IScope : IItem {31 public interface IScope : IItem, IVariablesContainer { 32 32 /// <summary> 33 33 /// Gets the name of the current instance. … … 35 35 string Name { get; } 36 36 37 /// <summary>38 /// Gets the varibles of the current scope.39 /// </summary>40 ICollection<IVariable> Variables { get; }41 37 /// <summary> 42 38 /// Gets all subscopes in the current scope. … … 50 46 void SetParent(IScope scope); 51 47 52 /// <summary>53 /// Gets a variable with the given <paramref name="name"/>.54 /// </summary>55 /// <param name="name">The name of the variable.</param>56 /// <returns>The variable with the specified name.</returns>57 IVariable GetVariable(string name);58 /// <summary>59 /// Adds the specified variable to the curent instance.60 /// </summary>61 /// <param name="variable">The variable to add.</param>62 void AddVariable(IVariable variable);63 /// <summary>64 /// Deletes a variable with the specified <paramref name="name"/> from the current instance.65 /// </summary>66 /// <param name="name">The name of the variable to delete.</param>67 void RemoveVariable(string name);68 69 48 /// <inheritdoc cref="GetVariableValue(string, bool)"/> 70 49 /// <typeparam name="T">The type of the value that is searched.</typeparam> … … 125 104 126 105 /// <summary> 127 /// Occurs when a variable has been added to the current instance.128 /// </summary>129 event EventHandler<VariableEventArgs> VariableAdded;130 /// <summary>131 /// Occurs when a variable has been deleted from the current instance.132 /// </summary>133 event EventHandler<VariableEventArgs> VariableRemoved;134 /// <summary>135 106 /// Occurs when a sub scope has been added to the current instance. 136 107 /// </summary> -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorBase.cs
r1851 r2027 29 29 /// The base class for all operators. 30 30 /// </summary> 31 public abstract class OperatorBase : ConstrainedItemBase, IOperator {31 public abstract class OperatorBase : ItemBase, IOperator { 32 32 private string myName; 33 33 /// <summary> … … 80 80 get { return mySubOperators.AsReadOnly(); } 81 81 } 82 private Dictionary<string, IVariableInfo> myVariableInfos; 83 /// <inheritdoc/> 84 public virtual ICollection<IVariableInfo> VariableInfos { 85 get { return myVariableInfos.Values; } 86 } 87 private Dictionary<string, IVariable> myVariables; 88 /// <inheritdoc/> 89 public virtual ICollection<IVariable> Variables { 90 get { return myVariables.Values; } 82 private Dictionary<string, IParameter> myParameters; 83 /// <inheritdoc/> 84 public virtual ICollection<IParameter> Parameters { 85 get { return myParameters.Values; } 91 86 } 92 87 … … 100 95 myBreakpoint = false; 101 96 mySubOperators = new List<IOperator>(); 102 myVariableInfos = new Dictionary<string, IVariableInfo>(); 103 myVariables = new Dictionary<string, IVariable>(); 97 myParameters = new Dictionary<string, IParameter>(); 104 98 } 105 99 … … 116 110 for (int i = 0; i < SubOperators.Count; i++) 117 111 clone.AddSubOperator((IOperator)Auxiliary.Clone(SubOperators[i], clonedObjects)); 118 clone.myVariableInfos.Clear(); 119 foreach (IVariableInfo variableInfo in myVariableInfos.Values) 120 clone.AddVariableInfo((IVariableInfo)Auxiliary.Clone(variableInfo, clonedObjects)); 121 clone.myVariables.Clear(); 122 foreach (IVariable variable in myVariables.Values) 123 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 112 clone.myParameters.Clear(); 113 foreach (IParameter parameter in myParameters.Values) 114 clone.AddParameter((IParameter)Auxiliary.Clone(parameter, clonedObjects)); 124 115 return clone; 125 116 } … … 142 133 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1); 143 134 } 144 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator)"/>145 /// <param name="subOperator">The sub operator to add.</param>146 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>147 public virtual bool TryAddSubOperator(IOperator subOperator) {148 mySubOperators.Add(subOperator);149 if (IsValid()) {150 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);151 return true;152 } else {153 mySubOperators.RemoveAt(mySubOperators.Count - 1);154 return false;155 }156 }157 /// <inheritdoc cref="HeuristicLab.Core.IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator,158 /// out System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/>159 /// <param name="subOperator">The sub operator to add.</param>160 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>161 public virtual bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {162 mySubOperators.Add(subOperator);163 if (IsValid(out violatedConstraints)) {164 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);165 return true;166 } else {167 mySubOperators.RemoveAt(mySubOperators.Count - 1);168 return false;169 }170 }171 135 /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/> 172 136 /// <param name="subOperator">The sub operator to add.</param> … … 176 140 OnSubOperatorAdded(subOperator, index); 177 141 } 178 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int)"/>179 /// <param name="subOperator">The sub operator to add.</param>180 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>181 public virtual bool TryAddSubOperator(IOperator subOperator, int index) {182 mySubOperators.Insert(index, subOperator);183 if (IsValid()) {184 OnSubOperatorAdded(subOperator, index);185 return true;186 } else {187 mySubOperators.RemoveAt(index);188 return false;189 }190 }191 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int, out192 /// System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/>193 /// <param name="subOperator">The sub operator to add.</param>194 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>195 public virtual bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {196 mySubOperators.Insert(index, subOperator);197 if (IsValid(out violatedConstraints)) {198 OnSubOperatorAdded(subOperator, index);199 return true;200 } else {201 mySubOperators.RemoveAt(index);202 return false;203 }204 }205 142 /// <inheritdoc/> 206 143 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks> … … 210 147 OnSubOperatorRemoved(op, index); 211 148 } 212 /// <inheritdoc/>213 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>214 public virtual bool TryRemoveSubOperator(int index) {215 IOperator op = mySubOperators[index];216 mySubOperators.RemoveAt(index);217 if (IsValid()) {218 OnSubOperatorRemoved(op, index);219 return true;220 } else {221 mySubOperators.Insert(index, op);222 return false;223 }224 }225 /// <inheritdoc/>226 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>227 public virtual bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {228 IOperator op = mySubOperators[index];229 mySubOperators.RemoveAt(index);230 if (IsValid(out violatedConstraints)) {231 OnSubOperatorRemoved(op, index);232 return true;233 } else {234 mySubOperators.Insert(index, op);235 return false;236 }237 }238 149 #endregion 239 150 240 #region VariableInfoMethods241 /// <inheritdoc/> 242 public virtual I VariableInfo GetVariableInfo(string formalName) {243 I VariableInfoinfo;244 if (my VariableInfos.TryGetValue(formalName, out info))151 #region Parameter Methods 152 /// <inheritdoc/> 153 public virtual IParameter GetParameter(string name) { 154 IParameter info; 155 if (myParameters.TryGetValue(name, out info)) 245 156 return info; 246 157 else … … 249 160 /// <inheritdoc/> 250 161 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks> 251 public virtual void AddVariableInfo(IVariableInfo variableInfo) { 252 myVariableInfos.Add(variableInfo.FormalName, variableInfo); 253 OnVariableInfoAdded(variableInfo); 254 } 255 /// <inheritdoc/> 256 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks> 257 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo) { 258 myVariableInfos.Add(variableInfo.FormalName, variableInfo); 259 if (IsValid()) { 260 OnVariableInfoAdded(variableInfo); 261 return true; 262 } else { 263 myVariableInfos.Remove(variableInfo.FormalName); 264 return false; 265 } 266 } 267 /// <inheritdoc/> 268 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks> 269 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints) { 270 myVariableInfos.Add(variableInfo.FormalName, variableInfo); 271 if (IsValid(out violatedConstraints)) { 272 OnVariableInfoAdded(variableInfo); 273 return true; 274 } else { 275 myVariableInfos.Remove(variableInfo.FormalName); 276 return false; 277 } 162 public virtual void AddParameter(IParameter parameter) { 163 myParameters.Add(parameter.Name, parameter); 164 OnParameterAdded(parameter); 278 165 } 279 166 /// <inheritdoc/> 280 167 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 281 public virtual void RemoveVariableInfo(string formalName) { 282 IVariableInfo variableInfo; 283 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) { 284 myVariableInfos.Remove(formalName); 285 OnVariableInfoRemoved(variableInfo); 286 } 287 } 288 /// <inheritdoc/> 289 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 290 public virtual bool TryRemoveVariableInfo(string formalName) { 291 IVariableInfo variableInfo; 292 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) { 293 myVariableInfos.Remove(formalName); 294 if (IsValid()) { 295 OnVariableInfoRemoved(variableInfo); 296 return true; 297 } else { 298 myVariableInfos.Add(formalName, variableInfo); 299 return false; 300 } 301 } 302 return true; 303 } 304 /// <inheritdoc/> 305 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 306 public virtual bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints) { 307 IVariableInfo variableInfo; 308 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) { 309 myVariableInfos.Remove(formalName); 310 if (IsValid(out violatedConstraints)) { 311 OnVariableInfoRemoved(variableInfo); 312 return true; 313 } else { 314 myVariableInfos.Add(formalName, variableInfo); 315 return false; 316 } 317 } 318 violatedConstraints = new List<IConstraint>(); 319 return true; 168 public virtual void RemoveParameter(string name) { 169 IParameter parameter; 170 if (myParameters.TryGetValue(name, out parameter)) { 171 myParameters.Remove(name); 172 OnParameterRemoved(parameter); 173 } 320 174 } 321 175 #endregion 322 176 323 #region Variable Methods 324 /// <inheritdoc/> 325 public virtual IVariable GetVariable(string name) { 326 IVariable variable; 327 if (myVariables.TryGetValue(name, out variable)) 328 return variable; 329 else 330 return null; 331 } 332 /// <inheritdoc/> 333 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c> 334 /// event handlers.</remarks> 335 public virtual void AddVariable(IVariable variable) { 336 myVariables.Add(variable.Name, variable); 337 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 338 variable.NameChanged += new EventHandler(Variable_NameChanged); 339 OnVariableAdded(variable); 340 } 341 /// <inheritdoc/> 342 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c> 343 /// event handlers.</remarks> 344 public virtual bool TryAddVariable(IVariable variable) { 345 myVariables.Add(variable.Name, variable); 346 if (IsValid()) { 347 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 348 variable.NameChanged += new EventHandler(Variable_NameChanged); 349 OnVariableAdded(variable); 350 return true; 351 } else { 352 myVariableInfos.Remove(variable.Name); 353 return false; 354 } 355 } 356 /// <inheritdoc/> 357 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c> 358 /// event handlers.</remarks> 359 public virtual bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints) { 360 myVariables.Add(variable.Name, variable); 361 if (IsValid(out violatedConstraints)) { 362 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 363 variable.NameChanged += new EventHandler(Variable_NameChanged); 364 OnVariableAdded(variable); 365 return true; 366 } else { 367 myVariableInfos.Remove(variable.Name); 368 return false; 369 } 370 } 371 /// <inheritdoc/> 372 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c> 373 /// event handlers.</remarks> 374 public virtual void RemoveVariable(string name) { 375 IVariable variable; 376 if (myVariables.TryGetValue(name, out variable)) { 377 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 378 variable.NameChanged -= new EventHandler(Variable_NameChanged); 379 myVariables.Remove(name); 380 OnVariableRemoved(variable); 381 } 382 } 383 /// <inheritdoc/> 384 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c> 385 /// event handlers.</remarks> 386 public virtual bool TryRemoveVariable(string name) { 387 IVariable variable; 388 if (myVariables.TryGetValue(name, out variable)) { 389 myVariables.Remove(name); 390 if (IsValid()) { 391 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 392 variable.NameChanged -= new EventHandler(Variable_NameChanged); 393 OnVariableRemoved(variable); 394 return true; 395 } else { 396 myVariables.Add(name, variable); 397 return false; 398 } 399 } 400 return true; 401 } 402 /// <inheritdoc/> 403 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c> 404 /// event handlers.</remarks> 405 public virtual bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints) { 406 IVariable variable; 407 if (myVariables.TryGetValue(name, out variable)) { 408 myVariables.Remove(name); 409 if (IsValid(out violatedConstraints)) { 410 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 411 variable.NameChanged -= new EventHandler(Variable_NameChanged); 412 OnVariableRemoved(variable); 413 return true; 414 } else { 415 myVariables.Add(name, variable); 416 return false; 417 } 418 } 419 violatedConstraints = new List<IConstraint>(); 420 return true; 421 } 422 private void Variable_NameChanging(object sender, NameChangingEventArgs e) { 423 e.Cancel = myVariables.ContainsKey(e.Name); 424 } 425 private void Variable_NameChanged(object sender, EventArgs e) { 426 IVariable variable = (IVariable)sender; 427 string oldName = null; 428 foreach (KeyValuePair<string, IVariable> element in myVariables) { 429 if (element.Value == variable) 430 oldName = element.Key; 431 } 432 myVariables.Remove(oldName); 433 myVariables.Add(variable.Name, variable); 434 } 435 /// <inheritdoc cref="IOperator.GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool)"/> 436 /// <remarks>Calls <see cref="GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool, bool)"/> 437 /// with <c>throwOnError</c> set to <c>false</c>.</remarks> 438 public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem { 439 return GetVariableValue<T>(formalName, scope, recursiveLookup, true); 440 } 441 /// <inheritdoc cref="IOperator.GetVariableValue<T>(string, HeuristicLab.Core.IScope, bool, bool)"/> 442 /// <remarks>Calls 443 /// <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>.</remarks> 444 public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem { 445 return (T)GetVariableValue(formalName, scope, recursiveLookup, throwOnError); 446 } 447 /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/> 448 /// <remarks>Calls <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/> 449 /// with <c>throwOnError</c> set to <c>false</c>.</remarks> 450 public IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup) { 451 return GetVariableValue(formalName, scope, recursiveLookup, true); 452 } 453 /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/> 454 public virtual IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) { 455 IVariableInfo info = GetVariableInfo(formalName); 456 if (info.Local) { 457 IVariable variable; 458 if (myVariables.TryGetValue(info.ActualName, out variable)) 459 return variable.Value; 460 else { 461 if (throwOnError) 462 throw new ArgumentException("Variable " + info.ActualName + " not found"); 463 else 464 return null; 465 } 466 } else { 467 return scope.GetVariableValue(formalName, recursiveLookup, throwOnError); 468 } 469 } 470 #endregion 471 /// <inheritdoc/> 472 public virtual IOperation Execute(IScope scope) { 177 /// <inheritdoc/> 178 public virtual IOperation Execute(IEnvironment env, IScope scope) { 473 179 myCanceled = false; 474 180 475 foreach (IVariableInfo variableInfo in VariableInfos) 476 scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName); 477 478 IOperation next = Apply(scope); 479 480 foreach (IVariableInfo variableInfo in VariableInfos) 481 scope.RemoveAlias(variableInfo.FormalName); 181 IOperation next = Apply(env, scope); 482 182 483 183 OnExecuted(); … … 494 194 /// <param name="scope">The scope where to execute the operator</param> 495 195 /// <returns><c>null</c>.</returns> 496 public virtual IOperation Apply(I Scope scope) {196 public virtual IOperation Apply(IEnvironment env, IScope scope) { 497 197 return null; 498 198 } … … 540 240 } 541 241 /// <inheritdoc/> 542 public event EventHandler<VariableInfoEventArgs> VariableInfoAdded; 543 /// <summary> 544 /// Fires a new <c>VariableInfoAdded</c> event. 545 /// </summary> 546 /// <param name="variableInfo">The variable info that has been added.</param> 547 protected virtual void OnVariableInfoAdded(IVariableInfo variableInfo) { 548 if (VariableInfoAdded != null) 549 VariableInfoAdded(this, new VariableInfoEventArgs(variableInfo)); 550 } 551 /// <inheritdoc/> 552 public event EventHandler<VariableInfoEventArgs> VariableInfoRemoved; 553 /// <summary> 554 /// Fires a new <c>VariableInfoRemoved</c> event. 555 /// </summary> 556 /// <param name="variableInfo">The variable info that has been removed.</param> 557 protected virtual void OnVariableInfoRemoved(IVariableInfo variableInfo) { 558 if (VariableInfoRemoved != null) 559 VariableInfoRemoved(this, new VariableInfoEventArgs(variableInfo)); 560 } 561 /// <inheritdoc/> 562 public event EventHandler<VariableEventArgs> VariableAdded; 563 /// <summary> 564 /// Fires a new <c>VariableAdded</c> event. 565 /// </summary> 566 /// <param name="variable">The variable that has been added.</param> 567 protected virtual void OnVariableAdded(IVariable variable) { 568 if (VariableAdded != null) 569 VariableAdded(this, new VariableEventArgs(variable)); 570 } 571 /// <inheritdoc/> 572 public event EventHandler<VariableEventArgs> VariableRemoved; 573 /// <summary> 574 /// Fires a new <c>VariableRemoved</c> event. 575 /// </summary> 576 /// <param name="variable">The variable that has been removed</param> 577 protected virtual void OnVariableRemoved(IVariable variable) { 578 if (VariableRemoved != null) 579 VariableRemoved(this, new VariableEventArgs(variable)); 242 public event EventHandler<ParameterEventArgs> ParameterAdded; 243 /// <summary> 244 /// Fires a new <c>ParameterAdded</c> event. 245 /// </summary> 246 /// <param name="parameter">The parameter that has been added.</param> 247 protected virtual void OnParameterAdded(IParameter parameter) { 248 if (ParameterAdded != null) 249 ParameterAdded(this, new ParameterEventArgs(parameter)); 250 } 251 /// <inheritdoc/> 252 public event EventHandler<ParameterEventArgs> ParameterRemoved; 253 /// <summary> 254 /// Fires a new <c>ParameterRemoved</c> event. 255 /// </summary> 256 /// <param name="parameter">The parameter that has been removed.</param> 257 protected virtual void OnParameterRemoved(IParameter parameter) { 258 if (ParameterRemoved != null) 259 ParameterRemoved(this, new ParameterEventArgs(parameter)); 580 260 } 581 261 /// <inheritdoc/> … … 642 322 subOperatorsNode.AppendChild(PersistenceManager.Persist(SubOperators[i], document, persistedObjects)); 643 323 node.AppendChild(subOperatorsNode); 644 XmlNode infosNode = document.CreateNode(XmlNodeType.Element, "VariableInfos", null); 645 foreach (IVariableInfo info in myVariableInfos.Values) 646 infosNode.AppendChild(PersistenceManager.Persist(info, document, persistedObjects)); 647 node.AppendChild(infosNode); 648 XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null); 649 foreach (IVariable variable in myVariables.Values) 650 variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects)); 651 node.AppendChild(variablesNode); 324 XmlNode parametersNode = document.CreateNode(XmlNodeType.Element, "Parameters", null); 325 foreach (IParameter parameter in myParameters.Values) 326 parametersNode.AppendChild(PersistenceManager.Persist(parameter, document, persistedObjects)); 327 node.AppendChild(parametersNode); 652 328 return node; 653 329 } … … 668 344 for (int i = 0; i < subOperatorsNode.ChildNodes.Count; i++) 669 345 AddSubOperator((IOperator)PersistenceManager.Restore(subOperatorsNode.ChildNodes[i], restoredObjects)); 670 XmlNode infosNode = node.SelectSingleNode("VariableInfos"); 671 myVariableInfos.Clear(); 672 foreach (XmlNode infoNode in infosNode.ChildNodes) 673 AddVariableInfo((IVariableInfo)PersistenceManager.Restore(infoNode, restoredObjects)); 674 XmlNode variablesNode = node.SelectSingleNode("Variables"); 675 myVariables.Clear(); 676 foreach (XmlNode variableNode in variablesNode.ChildNodes) 677 AddVariable((IVariable)PersistenceManager.Restore(variableNode, restoredObjects)); 346 XmlNode parametersNode = node.SelectSingleNode("Parameters"); 347 myParameters.Clear(); 348 foreach (XmlNode parameterNode in parametersNode.ChildNodes) 349 AddParameter((IParameter)PersistenceManager.Restore(parameterNode, restoredObjects)); 678 350 } 679 351 #endregion -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorBaseView.Designer.cs
r1529 r2027 49 49 private void InitializeComponent() { 50 50 this.tabControl = new System.Windows.Forms.TabControl(); 51 this.variableInfosTabPage = new System.Windows.Forms.TabPage(); 52 this.operatorBaseVariableInfosView = new HeuristicLab.Core.OperatorBaseVariableInfosView(); 53 this.variablesTabPage = new System.Windows.Forms.TabPage(); 54 this.operatorBaseVariablesView = new HeuristicLab.Core.OperatorBaseVariablesView(); 55 this.constraintsTabPage = new System.Windows.Forms.TabPage(); 56 this.constrainedItemBaseView = new HeuristicLab.Core.ConstrainedItemBaseView(); 51 this.parametersTabPage = new System.Windows.Forms.TabPage(); 52 this.operatorBaseParametersView = new HeuristicLab.Core.OperatorBaseParametersView(); 57 53 this.descriptionTabPage = new System.Windows.Forms.TabPage(); 58 54 this.operatorBaseDescriptionView = new HeuristicLab.Core.OperatorBaseDescriptionView(); 59 55 this.tabControl.SuspendLayout(); 60 this.variableInfosTabPage.SuspendLayout(); 61 this.variablesTabPage.SuspendLayout(); 62 this.constraintsTabPage.SuspendLayout(); 56 this.parametersTabPage.SuspendLayout(); 63 57 this.descriptionTabPage.SuspendLayout(); 64 58 this.SuspendLayout(); … … 66 60 // tabControl 67 61 // 68 this.tabControl.Controls.Add(this.variableInfosTabPage); 69 this.tabControl.Controls.Add(this.variablesTabPage); 70 this.tabControl.Controls.Add(this.constraintsTabPage); 62 this.tabControl.Controls.Add(this.parametersTabPage); 71 63 this.tabControl.Controls.Add(this.descriptionTabPage); 72 64 this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill; … … 77 69 this.tabControl.TabIndex = 0; 78 70 // 79 // variableInfosTabPage71 // parametersTabPage 80 72 // 81 this. variableInfosTabPage.Controls.Add(this.operatorBaseVariableInfosView);82 this. variableInfosTabPage.Location = new System.Drawing.Point(4, 22);83 this. variableInfosTabPage.Name = "variableInfosTabPage";84 this. variableInfosTabPage.Padding = new System.Windows.Forms.Padding(3);85 this. variableInfosTabPage.Size = new System.Drawing.Size(415, 307);86 this. variableInfosTabPage.TabIndex = 0;87 this. variableInfosTabPage.Text = "Variable Infos";88 this. variableInfosTabPage.UseVisualStyleBackColor = true;73 this.parametersTabPage.Controls.Add(this.operatorBaseParametersView); 74 this.parametersTabPage.Location = new System.Drawing.Point(4, 22); 75 this.parametersTabPage.Name = "parametersTabPage"; 76 this.parametersTabPage.Padding = new System.Windows.Forms.Padding(3); 77 this.parametersTabPage.Size = new System.Drawing.Size(415, 307); 78 this.parametersTabPage.TabIndex = 0; 79 this.parametersTabPage.Text = "Parameters"; 80 this.parametersTabPage.UseVisualStyleBackColor = true; 89 81 // 90 82 // operatorBaseVariableInfosView 91 83 // 92 this.operatorBaseVariableInfosView.Caption = "Operator"; 93 this.operatorBaseVariableInfosView.Dock = System.Windows.Forms.DockStyle.Fill; 94 this.operatorBaseVariableInfosView.Location = new System.Drawing.Point(3, 3); 95 this.operatorBaseVariableInfosView.Name = "operatorBaseVariableInfosView"; 96 this.operatorBaseVariableInfosView.Operator = null; 97 this.operatorBaseVariableInfosView.Size = new System.Drawing.Size(409, 301); 98 this.operatorBaseVariableInfosView.TabIndex = 0; 99 // 100 // variablesTabPage 101 // 102 this.variablesTabPage.Controls.Add(this.operatorBaseVariablesView); 103 this.variablesTabPage.Location = new System.Drawing.Point(4, 22); 104 this.variablesTabPage.Name = "variablesTabPage"; 105 this.variablesTabPage.Padding = new System.Windows.Forms.Padding(3); 106 this.variablesTabPage.Size = new System.Drawing.Size(415, 307); 107 this.variablesTabPage.TabIndex = 1; 108 this.variablesTabPage.Text = "Local Variables"; 109 this.variablesTabPage.UseVisualStyleBackColor = true; 110 // 111 // operatorBaseVariablesView 112 // 113 this.operatorBaseVariablesView.Caption = "Operator"; 114 this.operatorBaseVariablesView.Dock = System.Windows.Forms.DockStyle.Fill; 115 this.operatorBaseVariablesView.Location = new System.Drawing.Point(3, 3); 116 this.operatorBaseVariablesView.Name = "operatorBaseVariablesView"; 117 this.operatorBaseVariablesView.Operator = null; 118 this.operatorBaseVariablesView.Size = new System.Drawing.Size(409, 301); 119 this.operatorBaseVariablesView.TabIndex = 0; 120 // 121 // constraintsTabPage 122 // 123 this.constraintsTabPage.Controls.Add(this.constrainedItemBaseView); 124 this.constraintsTabPage.Location = new System.Drawing.Point(4, 22); 125 this.constraintsTabPage.Name = "constraintsTabPage"; 126 this.constraintsTabPage.Padding = new System.Windows.Forms.Padding(3); 127 this.constraintsTabPage.Size = new System.Drawing.Size(415, 307); 128 this.constraintsTabPage.TabIndex = 2; 129 this.constraintsTabPage.Text = "Constraints"; 130 this.constraintsTabPage.UseVisualStyleBackColor = true; 131 // 132 // constrainedItemBaseView 133 // 134 this.constrainedItemBaseView.Caption = "Constrained Data"; 135 this.constrainedItemBaseView.ConstrainedItem = null; 136 this.constrainedItemBaseView.Dock = System.Windows.Forms.DockStyle.Fill; 137 this.constrainedItemBaseView.Location = new System.Drawing.Point(3, 3); 138 this.constrainedItemBaseView.Name = "constrainedItemBaseView"; 139 this.constrainedItemBaseView.Size = new System.Drawing.Size(409, 301); 140 this.constrainedItemBaseView.TabIndex = 0; 84 this.operatorBaseParametersView.Caption = "Operator"; 85 this.operatorBaseParametersView.Dock = System.Windows.Forms.DockStyle.Fill; 86 this.operatorBaseParametersView.Location = new System.Drawing.Point(3, 3); 87 this.operatorBaseParametersView.Name = "operatorBaseVariableInfosView"; 88 this.operatorBaseParametersView.Operator = null; 89 this.operatorBaseParametersView.Size = new System.Drawing.Size(409, 301); 90 this.operatorBaseParametersView.TabIndex = 0; 141 91 // 142 92 // descriptionTabPage … … 170 120 this.Size = new System.Drawing.Size(423, 333); 171 121 this.tabControl.ResumeLayout(false); 172 this.variableInfosTabPage.ResumeLayout(false); 173 this.variablesTabPage.ResumeLayout(false); 174 this.constraintsTabPage.ResumeLayout(false); 122 this.parametersTabPage.ResumeLayout(false); 175 123 this.descriptionTabPage.ResumeLayout(false); 176 124 this.ResumeLayout(false); … … 181 129 182 130 protected TabControl tabControl; 183 protected TabPage variableInfosTabPage; 184 protected TabPage variablesTabPage; 185 private TabPage constraintsTabPage; 186 protected ConstrainedItemBaseView constrainedItemBaseView; 187 protected OperatorBaseVariableInfosView operatorBaseVariableInfosView; 188 protected OperatorBaseVariablesView operatorBaseVariablesView; 131 protected TabPage parametersTabPage; 132 protected OperatorBaseParametersView operatorBaseParametersView; 189 133 private TabPage descriptionTabPage; 190 134 private OperatorBaseDescriptionView operatorBaseDescriptionView; -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorBaseView.cs
r1529 r2027 66 66 /// </summary> 67 67 protected override void RemoveItemEvents() { 68 operatorBaseVariableInfosView.Operator = null; 69 operatorBaseVariablesView.Operator = null; 70 constrainedItemBaseView.ConstrainedItem = null; 68 operatorBaseParametersView.Operator = null; 71 69 operatorBaseDescriptionView.Operator = null; 72 70 base.RemoveItemEvents(); … … 77 75 protected override void AddItemEvents() { 78 76 base.AddItemEvents(); 79 operatorBaseVariableInfosView.Operator = Operator; 80 operatorBaseVariablesView.Operator = Operator; 81 constrainedItemBaseView.ConstrainedItem = Operator; 77 operatorBaseParametersView.Operator = Operator; 82 78 operatorBaseDescriptionView.Operator = Operator; 83 79 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/OperatorGraphView.cs
r1529 r2027 350 350 IOperator newParent = (IOperator)node.Parent.Tag; 351 351 int newIndex = node.Index; 352 ICollection<IConstraint> violatedConstraints; 353 ICollection<IConstraint> violatedConstraints2; 354 oldParent.TryRemoveSubOperator(oldIndex, out violatedConstraints); 355 newParent.TryAddSubOperator(op, newIndex, out violatedConstraints2); 356 if ((violatedConstraints.Count == 0) && (violatedConstraints2.Count == 0)) { 357 graphTreeView.SelectedNode = parentNode.Nodes[newIndex]; 358 } else { 359 List<IConstraint> allViolatedConstraints = new List<IConstraint>(violatedConstraints); 360 allViolatedConstraints.AddRange(violatedConstraints2); 361 if (Auxiliary.ShowIgnoreConstraintViolationMessageBox(allViolatedConstraints) == DialogResult.Yes) { 362 if (violatedConstraints.Count > 0) 363 oldParent.RemoveSubOperator(oldIndex); 364 if (violatedConstraints2.Count > 0) 365 newParent.AddSubOperator(op, newIndex); 366 graphTreeView.SelectedNode = parentNode.Nodes[newIndex]; 367 } else { 368 if (violatedConstraints.Count == 0) 369 oldParent.AddSubOperator(op, oldIndex); 370 if (violatedConstraints2.Count == 0) 371 newParent.RemoveSubOperator(newIndex); 372 } 373 } 352 oldParent.RemoveSubOperator(oldIndex); 353 newParent.AddSubOperator(op, newIndex); 354 graphTreeView.SelectedNode = parentNode.Nodes[newIndex]; 374 355 } 375 356 } else { 376 357 if (node != null) { 377 358 IOperator parent = (IOperator)node.Tag; 378 ICollection<IConstraint> violatedConstraints; 379 if (parent.TryAddSubOperator(op, out violatedConstraints)) { 380 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1]; 381 } else if (Auxiliary.ShowIgnoreConstraintViolationMessageBox(violatedConstraints) == DialogResult.Yes) { 382 parent.AddSubOperator(op); 383 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1]; 384 } 359 parent.AddSubOperator(op); 360 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1]; 385 361 } 386 362 } -
branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/Scope.cs
r1529 r2027 45 45 get { return myVariables.Values; } 46 46 } 47 private IDictionary<string, string> myAliases;48 /// <inheritdoc/>49 public IEnumerable<KeyValuePair<string, string>> Aliases {50 get { return myAliases; }51 }52 47 private List<IScope> mySubScopes; 53 48 /// <summary> … … 65 60 myName = "Anonymous"; 66 61 myVariables = new Dictionary<string, IVariable>(); 67 myAliases = new Dictionary<string, string>();68 62 mySubScopes = new List<IScope>(); 69 63 } … … 144 138 public IItem GetVariableValue(string name, bool recursiveLookup, bool throwOnError) { 145 139 IVariable variable; 146 name = TranslateName(name);147 140 if (myVariables.TryGetValue(name, out variable)) { 148 141 return variable.Value; … … 158 151 } 159 152 } 160 /// <inheritdoc/>161 public string TranslateName(string name) {162 while (myAliases.ContainsKey(name))163 name = myAliases[name];164 if (parent != null)165 name = parent.TranslateName(name);166 return name;167 }168 /// <inheritdoc/>169 public void AddAlias(string alias, string name) {170 RemoveAlias(alias);171 if (alias != name) {172 myAliases.Add(alias, name);173 OnAliasAdded(alias);174 }175 }176 /// <inheritdoc/>177 public void RemoveAlias(string alias) {178 if (myAliases.ContainsKey(alias)) {179 myAliases.Remove(alias);180 OnAliasRemoved(alias);181 }182 }183 153 184 154 /// <inheritdoc/> … … 238 208 RemoveVariable(variableNames[j]); 239 209 240 KeyValuePair<string, string>[] aliases = new KeyValuePair<string,string>[myAliases.Count];241 myAliases.CopyTo(aliases, 0);242 for (int j = 0; j < aliases.Length; j++)243 RemoveAlias(aliases[j].Key);244 245 210 while (SubScopes.Count > 0) 246 211 RemoveSubScope(SubScopes[0]); … … 254 219 foreach (IVariable variable in myVariables.Values) 255 220 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); 256 foreach (KeyValuePair<string, string> alias in myAliases)257 clone.AddAlias(alias.Key, alias.Value);258 221 for (int i = 0; i < SubScopes.Count; i++) 259 222 clone.AddSubScope((IScope)Auxiliary.Clone(SubScopes[i], clonedObjects)); … … 281 244 if (VariableRemoved != null) 282 245 VariableRemoved(this, new VariableEventArgs(variable)); 283 }284 /// <inheritdoc />285 public event EventHandler<AliasEventArgs> AliasAdded;286 /// <summary>287 /// Fires a new <c>AliasAdded</c> event.288 /// </summary>289 /// <param name="alias">The alias that has been added.</param>290 protected virtual void OnAliasAdded(string alias) {291 if (AliasAdded != null)292 AliasAdded(this, new AliasEventArgs(alias));293 }294 /// <inheritdoc/>295 public event EventHandler<AliasEventArgs> AliasRemoved;296 /// <summary>297 /// Fires a new <c>AliasRemoved</c> event.298 /// </summary>299 /// <param name="alias">The alias that has been deleted.</param>300 protected virtual void OnAliasRemoved(string alias) {301 if (AliasRemoved != null)302 AliasRemoved(this, new AliasEventArgs(alias));303 246 } 304 247 /// <inheritdoc/> … … 380 323 node.AppendChild(variables); 381 324 382 XmlNode aliases = document.CreateNode(XmlNodeType.Element, "Aliases", null);383 foreach (KeyValuePair<string, string> alias in myAliases) {384 XmlNode aliasNode = document.CreateNode(XmlNodeType.Element, "Alias", null);385 XmlAttribute keyAttribute = document.CreateAttribute("Alias");386 keyAttribute.Value = alias.Key;387 aliasNode.Attributes.Append(keyAttribute);388 XmlAttribute valueAttribute = document.CreateAttribute("Name");389 valueAttribute.Value = alias.Value;390 aliasNode.Attributes.Append(valueAttribute);391 aliases.AppendChild(aliasNode);392 }393 node.AppendChild(aliases);394 395 325 XmlNode subScopes = document.CreateNode(XmlNodeType.Element, "SubScopes", null); 396 326 for (int i = 0; i < SubScopes.Count; i++) … … 419 349 } 420 350 421 XmlNode aliases = node.SelectSingleNode("Aliases");422 if (aliases != null) {423 foreach (XmlNode aliasNode in aliases.ChildNodes)424 AddAlias(aliasNode.Attributes["Alias"].Value, aliasNode.Attributes["Name"].Value);425 }426 427 351 XmlNode subScopes = node.SelectSingleNode("SubScopes"); 428 352 for (int i = 0; i < subScopes.ChildNodes.Count; i++) { -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ComparatorBase.cs
r1530 r2027 36 36 /// </summary> 37 37 protected ComparatorBase() { 38 Add VariableInfo(new VariableInfo("LeftSide", "Variable on the left side of the comparison", typeof(IItem), VariableKind.In));39 Add VariableInfo(new VariableInfo("RightSide", "Variable on the right side of the comparison", typeof(IItem), VariableKind.In));40 Add VariableInfo(new VariableInfo("Result", "Result of the comparison", typeof(BoolData), VariableKind.Out | VariableKind.New));38 AddParameter(new Parameter("LeftSide", "Variable on the left side of the comparison", typeof(IItem), ParameterType.In)); 39 AddParameter(new Parameter("RightSide", "Variable on the right side of the comparison", typeof(IItem), ParameterType.In)); 40 AddParameter(new Parameter("Result", "Result of the comparison", typeof(BoolData), ParameterType.Out)); 41 41 } 42 42 … … 50 50 /// <param name="scope">The scope where to apply the compare operation.</param> 51 51 /// <returns><c>null</c>.</returns> 52 public override IOperation Apply(IScope scope) { 53 BoolData result = GetVariableValue<BoolData>("Result", scope, false, false); 52 public override IOperation Apply(IEnvironment env, IScope scope) { 53 string resultName = env.TranslateName("Result"); 54 BoolData result = scope.GetVariableValue<BoolData>(resultName, false, false); 54 55 if (result == null) { 55 56 result = new BoolData(true); 56 IVariableInfo info = GetVariableInfo("Result"); 57 if (info.Local) 58 AddVariable(new Variable(info.ActualName, result)); 59 else 60 scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), result)); 57 scope.AddVariable(new Variable(resultName, result)); 61 58 } 62 IItem leftSide = GetVariableValue<IItem>("LeftSide", scope, true);59 IItem leftSide = scope.GetVariableValue<IItem>(env.TranslateName("LeftSide"), true); 63 60 if (!(leftSide is IComparable)) throw new InvalidOperationException("Comparator: Left side needs to be of type IComparable"); 64 61 IComparable left = (IComparable)leftSide; 65 IItem rightSide = GetVariableValue<IItem>("RightSide", scope, true);62 IItem rightSide = scope.GetVariableValue<IItem>(env.TranslateName("RightSide"), true); 66 63 result.Data = Compare(left, rightSide); 67 64 return null; -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ConditionalBranch.cs
r1530 r2027 45 45 public ConditionalBranch() 46 46 : base() { 47 Add VariableInfo(new VariableInfo("Condition", "A boolean variable that decides the branch", typeof(BoolData), VariableKind.In));47 AddParameter(new Parameter("Condition", "A boolean variable that decides the branch", typeof(BoolData), ParameterType.In)); 48 48 } 49 49 … … 56 56 /// <returns>A new <see cref="AtomicOperation"/> with either operator 1 or operator 2 applied 57 57 /// to the given <paramref name="scope"/> or <c>null</c>.</returns> 58 public override IOperation Apply(IScope scope) { 59 BoolData resultData = GetVariableValue<BoolData>("Condition", scope, true); 60 bool result = resultData.Data; 58 public override IOperation Apply(IEnvironment env, IScope scope) { 59 bool result = scope.GetVariableValue<BoolData>(env.TranslateName("Condition"), true).Data; 61 60 62 61 if ((result) && (SubOperators.Count > 0) && (SubOperators[0] != null)) 63 return new AtomicOperation(SubOperators[0], scope);62 return new AtomicOperation(SubOperators[0], env, scope); 64 63 else if ((!result) && (SubOperators.Count > 1) && (SubOperators[1] != null)) 65 return new AtomicOperation(SubOperators[1], scope);64 return new AtomicOperation(SubOperators[1], env, scope); 66 65 return null; 67 66 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/Counter.cs
r1530 r2027 43 43 public Counter() 44 44 : base() { 45 Add VariableInfo(new VariableInfo("Value", "Counter value", typeof(IntData), VariableKind.In | VariableKind.Out));45 AddParameter(new Parameter("Value", "Counter value", typeof(IntData), ParameterType.InOut)); 46 46 } 47 47 … … 51 51 /// <param name="scope">The scope whose variable should be incremented.</param> 52 52 /// <returns><c>null</c>.</returns> 53 public override IOperation Apply(I Scope scope) {54 IntData value = GetVariableValue<IntData>("Value", scope, true);53 public override IOperation Apply(IEnvironment env, IScope scope) { 54 IntData value = scope.GetVariableValue<IntData>(env.TranslateName("Value"), true); 55 55 value.Data++; 56 56 return null; -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/DoubleCounter.cs
r1530 r2027 44 44 public DoubleCounter() 45 45 : base() { 46 Add VariableInfo(new VariableInfo("Value", "Counter value", typeof(DoubleData), VariableKind.In | VariableKind.Out));47 Add VariableInfo(new VariableInfo("Interval", "Interval value", typeof(DoubleData), VariableKind.In));46 AddParameter(new Parameter("Value", "Counter value", typeof(DoubleData), ParameterType.InOut)); 47 AddParameter(new Parameter("Interval", "Interval value", typeof(DoubleData), ParameterType.In)); 48 48 } 49 49 … … 53 53 /// <param name="scope">The scope whose variable should be incremented.</param> 54 54 /// <returns><c>null</c>.</returns> 55 public override IOperation Apply(I Scope scope) {56 DoubleData value = GetVariableValue<DoubleData>("Value", scope, true);57 double interval = GetVariableValue<DoubleData>("Interval", scope, true).Data;55 public override IOperation Apply(IEnvironment env, IScope scope) { 56 DoubleData value = scope.GetVariableValue<DoubleData>(env.TranslateName("Value"), true); 57 double interval = scope.GetVariableValue<DoubleData>(env.TranslateName("Interval"), true).Data; 58 58 value.Data += interval; 59 59 return null; -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/EmptyOperator.cs
r1530 r2027 47 47 /// <param name="scope">The scope to apply the operator on.</param> 48 48 /// <returns><c>null</c>.</returns> 49 public override IOperation Apply(I Scope scope) {49 public override IOperation Apply(IEnvironment environment, IScope scope) { 50 50 return null; 51 51 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/HeuristicLab.Operators-3.2.csproj
r1534 r2027 81 81 </ItemGroup> 82 82 <ItemGroup> 83 <Compile Include=" AddVariableInfoDialog.cs">84 <SubType> Form</SubType>83 <Compile Include="ComparatorBase.cs"> 84 <SubType>Code</SubType> 85 85 </Compile> 86 <Compile Include="AddVariableInfoDialog.Designer.cs">87 <DependentUpon>AddVariableInfoDialog.cs</DependentUpon>88 </Compile>89 <Compile Include="CombinedOperator.cs" />90 <Compile Include="CombinedOperatorView.cs">91 <SubType>UserControl</SubType>92 </Compile>93 <Compile Include="CombinedOperatorView.Designer.cs">94 <DependentUpon>CombinedOperatorView.cs</DependentUpon>95 </Compile>96 <Compile Include="ComparatorBase.cs" />97 86 <Compile Include="ConditionalBranch.cs"> 98 87 <SubType>Code</SubType> 99 88 </Compile> 100 <Compile Include="DelegatingOperator.cs" /> 101 <Compile Include="DoubleCounter.cs" /> 102 <Compile Include="ScopeCleaner.cs" /> 103 <Compile Include="StochasticMultiBranch.cs" /> 104 <Compile Include="SubScopesMixer.cs" /> 105 <Compile Include="DataCollector.cs" /> 106 <Compile Include="EqualToComparator.cs" /> 107 <Compile Include="GreaterOrEqualThanComparator.cs" /> 108 <Compile Include="GreaterThanComparator.cs" /> 109 <Compile Include="LessOrEqualThanComparator.cs" /> 110 <Compile Include="LessThanComparator.cs" /> 111 <Compile Include="OperatorExtractor.cs" /> 112 <Compile Include="ParallelProcessor.cs" /> 113 <Compile Include="EmptyOperator.cs" /> 114 <Compile Include="SequentialProcessor.cs" /> 115 <Compile Include="SingleObjectiveEvaluatorBase.cs" /> 116 <Compile Include="Sorter.cs" /> 117 <Compile Include="StochasticBranch.cs" /> 118 <Compile Include="SubScopesRemover.cs" /> 119 <Compile Include="UnequalToComparator.cs" /> 120 <Compile Include="UniformSequentialSubScopesProcessor.cs" /> 121 <Compile Include="UniformParallelSubScopesProcessor.cs" /> 122 <Compile Include="ParallelSubScopesProcessor.cs" /> 123 <Compile Include="SequentialSubScopesProcessor.cs" /> 124 <Compile Include="SubScopesCreater.cs" /> 125 <Compile Include="Counter.cs" /> 89 <Compile Include="Counter.cs"> 90 <SubType>Code</SubType> 91 </Compile> 92 <Compile Include="DoubleCounter.cs"> 93 <SubType>Code</SubType> 94 </Compile> 95 <Compile Include="EmptyOperator.cs"> 96 <SubType>Code</SubType> 97 </Compile> 98 <Compile Include="EqualToComparator.cs"> 99 <SubType>Code</SubType> 100 </Compile> 101 <Compile Include="GreaterOrEqualThanComparator.cs"> 102 <SubType>Code</SubType> 103 </Compile> 104 <Compile Include="GreaterThanComparator.cs"> 105 <SubType>Code</SubType> 106 </Compile> 126 107 <Compile Include="HeuristicLabOperatorsPlugin.cs" /> 108 <Compile Include="LessOrEqualThanComparator.cs"> 109 <SubType>Code</SubType> 110 </Compile> 111 <Compile Include="LessThanComparator.cs"> 112 <SubType>Code</SubType> 113 </Compile> 114 <Compile Include="ParallelProcessor.cs"> 115 <SubType>Code</SubType> 116 </Compile> 117 <Compile Include="ParallelSubScopesProcessor.cs"> 118 <SubType>Code</SubType> 119 </Compile> 127 120 <Compile Include="Properties\AssemblyInfo.cs" /> 128 <Compile Include="VariableInjector.cs" /> 121 <Compile Include="SequentialProcessor.cs"> 122 <SubType>Code</SubType> 123 </Compile> 124 <Compile Include="SequentialSubScopesProcessor.cs"> 125 <SubType>Code</SubType> 126 </Compile> 127 <Compile Include="SubScopesCreater.cs"> 128 <SubType>Code</SubType> 129 </Compile> 130 <Compile Include="UnequalToComparator.cs"> 131 <SubType>Code</SubType> 132 </Compile> 133 <Compile Include="UniformParallelSubScopesProcessor.cs"> 134 <SubType>Code</SubType> 135 </Compile> 136 <Compile Include="UniformSequentialSubScopesProcessor.cs"> 137 <SubType>Code</SubType> 138 </Compile> 139 <Compile Include="VariableInjector.cs"> 140 <SubType>Code</SubType> 141 </Compile> 129 142 <Compile Include="VariableInjectorView.cs"> 130 143 <SubType>UserControl</SubType> … … 135 148 </ItemGroup> 136 149 <ItemGroup> 137 <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">138 <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>139 <Name>HeuristicLab.Constraints-3.2</Name>140 </ProjectReference>141 150 <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj"> 142 151 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> … … 157 166 </ItemGroup> 158 167 <ItemGroup> 159 <EmbeddedResource Include="AddVariableInfoDialog.resx"> 160 <DependentUpon>AddVariableInfoDialog.cs</DependentUpon> 161 <SubType>Designer</SubType> 162 </EmbeddedResource> 163 <EmbeddedResource Include="CombinedOperatorView.resx"> 164 <DependentUpon>CombinedOperatorView.cs</DependentUpon> 165 <SubType>Designer</SubType> 168 <EmbeddedResource Include="VariableInjectorView.resx"> 169 <DependentUpon>VariableInjectorView.cs</DependentUpon> 166 170 </EmbeddedResource> 167 171 </ItemGroup> -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/HeuristicLabOperatorsPlugin.cs
r1927 r2027 31 31 [ClassInfo(Name = "HeuristicLab.Operators-3.2")] 32 32 [PluginFile(Filename = "HeuristicLab.Operators-3.2.dll", Filetype = PluginFileType.Assembly)] 33 [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]34 33 [Dependency(Dependency = "HeuristicLab.Core-3.2")] 35 34 [Dependency(Dependency = "HeuristicLab.Data-3.2")] -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ParallelProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied 43 43 /// to the given <paramref name="scope"/> with the <c>ExecuteInParallel</c> set to <c>true</c>.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 next.ExecuteInParallel = true; 47 47 for (int i = 0; i < SubOperators.Count; i++) 48 next.AddOperation(new AtomicOperation(SubOperators[i], scope));48 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope)); 49 49 return next; 50 50 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ParallelSubScopesProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>i</c>th operator applied 43 43 /// on the <c>i</c>th sub scope, the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 next.ExecuteInParallel = true; 47 47 for (int i = 0; i < scope.SubScopes.Count; i++) 48 next.AddOperation(new AtomicOperation(SubOperators[i], scope.SubScopes[i]));48 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope.SubScopes[i])); 49 49 return next; 50 50 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SequentialProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied 43 43 /// to the given <paramref name="scope"/>.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 for (int i = 0; i < SubOperators.Count; i++) 47 next.AddOperation(new AtomicOperation(SubOperators[i], scope));47 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope)); 48 48 return next; 49 49 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SequentialSubScopesProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>i</c>th operator applied 43 43 /// on the <c>i</c>th sub scope.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 for (int i = 0; i < scope.SubScopes.Count; i++) 47 next.AddOperation(new AtomicOperation(SubOperators[i], scope.SubScopes[i]));47 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope.SubScopes[i])); 48 48 return next; 49 49 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SubScopesCreater.cs
r1530 r2027 41 41 public SubScopesCreater() 42 42 : base() { 43 Add VariableInfo(new VariableInfo("SubScopes", "Number of sub-scopes", typeof(IntData), VariableKind.In));43 AddParameter(new Parameter("SubScopes", "Number of sub-scopes", typeof(IntData), ParameterType.In)); 44 44 } 45 45 … … 49 49 /// <param name="scope">The scope where to create the sub scopes.</param> 50 50 /// <returns><c>null</c>.</returns> 51 public override IOperation Apply(I Scope scope) {52 IntData count = GetVariableValue<IntData>("SubScopes", scope, true);51 public override IOperation Apply(IEnvironment env, IScope scope) { 52 IntData count = scope.GetVariableValue<IntData>(env.TranslateName("SubScopes"), true); 53 53 54 54 for (int i = 0; i < count.Data; i++) -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/UniformParallelSubScopesProcessor.cs
r1530 r2027 43 43 /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes and 44 44 /// the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns> 45 public override IOperation Apply(I Scope scope) {45 public override IOperation Apply(IEnvironment env, IScope scope) { 46 46 CompositeOperation next = new CompositeOperation(); 47 47 next.ExecuteInParallel = true; 48 48 for (int i = 0; i < scope.SubScopes.Count; i++) 49 next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));49 next.AddOperation(new AtomicOperation(SubOperators[0], env, scope.SubScopes[i])); 50 50 return next; 51 51 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/UniformSequentialSubScopesProcessor.cs
r1530 r2027 42 42 /// <param name="scope">The scope on whose sub scopes the operator is applied.</param> 43 43 /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 for (int i = 0; i < scope.SubScopes.Count; i++) 47 next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));47 next.AddOperation(new AtomicOperation(SubOperators[0], env, scope.SubScopes[i])); 48 48 return next; 49 49 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjector.cs
r1530 r2027 30 30 /// Class to inject local variables into the scope. 31 31 /// </summary> 32 public class VariableInjector : OperatorBase { 33 private Dictionary<IVariable, IVariableInfo> variableVariableInfoTable; 34 private Dictionary<IVariableInfo, IVariable> variableInfoVariableTable; 32 public class VariableInjector : OperatorBase, IVariablesContainer { 33 private Dictionary<string, IVariable> myVariables; 34 /// <summary> 35 /// Gets a collection of all variables of the current operator. 36 /// </summary> 37 public virtual ICollection<IVariable> Variables { 38 get { return myVariables.Values; } 39 } 35 40 36 41 /// <inheritdoc select="summary"/> 37 42 public override string Description { 38 get { return @"TODO\r\nOperator description still missing ..."; } 43 get { return @"Injects new variable into a scope."; } 44 } 45 46 /// <summary> 47 /// Overrides the Parameters property so that a parameter is returned for each injected variable. 48 /// </summary> 49 public override ICollection<IParameter> Parameters { 50 get { 51 List<IParameter> parameters = new List<IParameter>(); 52 foreach (IVariable variable in Variables) 53 parameters.Add(new Parameter(variable.Name, "Injected variable.", variable.Value.GetType(), ParameterType.Out)); 54 return parameters; 55 } 39 56 } 40 57 … … 44 61 public VariableInjector() 45 62 : base() { 46 variableVariableInfoTable = new Dictionary<IVariable, IVariableInfo>(); 47 variableInfoVariableTable = new Dictionary<IVariableInfo, IVariable>(); 63 myVariables = new Dictionary<string, IVariable>(); 48 64 } 49 65 … … 56 72 /// <returns>The cloned object as <see cref="VariableInjector"/>.</returns> 57 73 public override object Clone(IDictionary<Guid, object> clonedObjects) { 58 VariableInjector clone = new VariableInjector(); 59 clonedObjects.Add(Guid, clone); 60 clone.Name = Name; 74 VariableInjector clone = (VariableInjector)base.Clone(clonedObjects); 61 75 foreach (IVariable variable in Variables) 62 76 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); … … 65 79 66 80 /// <summary> 67 /// Adds the specified <paramref name="variable"/> to the current instance to get injected.68 /// </summary>69 /// <param name="variable">The variable to add.</param>70 /// <remarks>Calls private method <see cref="CreateVariableInfo"/> and <see cref="OperatorBase.AddVariable"/>71 /// of base class <see cref="OperatorBase"/>.</remarks>72 public override void AddVariable(IVariable variable) {73 base.AddVariable(variable);74 CreateVariableInfo(variable);75 }76 77 /// <summary>78 /// Removes a variable with the specified <paramref name="name"/> from the current injector.79 /// </summary>80 /// <remarks>Calls private method <see cref="DeleteVariableInfo"/> and <see cref="OperatorBase.RemoveVariable"/>81 /// of base class <see cref="OperatorBase"/>.</remarks>82 /// <param name="name">The name of the </param>83 public override void RemoveVariable(string name) {84 DeleteVariableInfo(name);85 base.RemoveVariable(name);86 }87 88 /// <summary>89 81 /// Adds the specified variables to the given <paramref name="scope"/> (and removes them first, 90 82 /// if they already exist in the current scope). … … 92 84 /// <param name="scope">The scope where to inject the variables.</param> 93 85 /// <returns><c>null</c>.</returns> 94 public override IOperation Apply(I Scope scope) {86 public override IOperation Apply(IEnvironment env, IScope scope) { 95 87 foreach (IVariable variable in Variables) { 96 88 if (scope.GetVariable(variable.Name) != null) … … 109 101 } 110 102 111 private void CreateVariableInfo(IVariable variable) { 112 IVariableInfo info = new VariableInfo(Guid.NewGuid().ToString(), "Injected variable", variable.Value.GetType(), VariableKind.New); 113 info.ActualName = variable.Name; 114 AddVariableInfo(info); 115 variableVariableInfoTable.Add(variable, info); 116 variableInfoVariableTable.Add(info, variable); 117 info.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged); 103 /// <summary> 104 /// Gets a variable with the given <paramref name="name"/>. 105 /// </summary> 106 /// <param name="name">The name of the variable.</param> 107 /// <returns>The variable with the specified name.</returns> 108 public virtual IVariable GetVariable(string name) { 109 IVariable variable; 110 if (myVariables.TryGetValue(name, out variable)) 111 return variable; 112 else 113 return null; 114 } 115 /// <summary> 116 /// Adds the specified <paramref name="variable"/> to the current instance. 117 /// </summary> 118 /// <param name="variable">The variable to add.</param> 119 public virtual void AddVariable(IVariable variable) { 120 myVariables.Add(variable.Name, variable); 121 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 118 122 variable.NameChanged += new EventHandler(Variable_NameChanged); 119 } 120 private void DeleteVariableInfo(string name) { 121 IVariable variable = GetVariable(name); 122 if (variable != null) { 123 IVariableInfo info = variableVariableInfoTable[variable]; 124 RemoveVariableInfo(info.FormalName); 125 variableVariableInfoTable.Remove(variable); 126 variableInfoVariableTable.Remove(info); 127 info.ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged); 123 OnVariableAdded(variable); 124 } 125 /// <summary> 126 /// Deletes the variable with the specified <paramref name="name"/>. 127 /// </summary> 128 /// <param name="name">The name of the variable to delete.</param> 129 public virtual void RemoveVariable(string name) { 130 IVariable variable; 131 if (myVariables.TryGetValue(name, out variable)) { 132 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 128 133 variable.NameChanged -= new EventHandler(Variable_NameChanged); 129 } 130 } 131 132 #region VariableInfo and Variable Events 133 private void VariableInfo_ActualNameChanged(object sender, EventArgs e) { 134 IVariableInfo info = (IVariableInfo)sender; 135 IVariable variable = variableInfoVariableTable[info]; 136 variable.Name = info.ActualName; 134 myVariables.Remove(name); 135 OnVariableRemoved(variable); 136 } 137 } 138 private void Variable_NameChanging(object sender, NameChangingEventArgs e) { 139 e.Cancel = myVariables.ContainsKey(e.Name); 137 140 } 138 141 private void Variable_NameChanged(object sender, EventArgs e) { 139 142 IVariable variable = (IVariable)sender; 140 IVariableInfo info = variableVariableInfoTable[variable]; 141 info.ActualName = variable.Name; 142 } 143 #endregion 143 string oldName = null; 144 foreach (KeyValuePair<string, IVariable> element in myVariables) { 145 if (element.Value == variable) 146 oldName = element.Key; 147 } 148 myVariables.Remove(oldName); 149 myVariables.Add(variable.Name, variable); 150 } 151 152 /// <summary> 153 /// Occurs when a variable has been added. 154 /// </summary> 155 public event EventHandler<VariableEventArgs> VariableAdded; 156 /// <summary> 157 /// Fires a new <c>VariableAdded</c> event. 158 /// </summary> 159 /// <param name="variable">The variable that has been added.</param> 160 protected virtual void OnVariableAdded(IVariable variable) { 161 if (VariableAdded != null) 162 VariableAdded(this, new VariableEventArgs(variable)); 163 } 164 /// <summary> 165 /// Occurs when a variable has been deleted. 166 /// </summary> 167 public event EventHandler<VariableEventArgs> VariableRemoved; 168 /// <summary> 169 /// Fires a new <c>VariableRemoved</c> event. 170 /// </summary> 171 /// <param name="variable">The variable that has been removed</param> 172 protected virtual void OnVariableRemoved(IVariable variable) { 173 if (VariableRemoved != null) 174 VariableRemoved(this, new VariableEventArgs(variable)); 175 } 144 176 145 177 #region Persistence Methods 146 178 /// <summary> 147 179 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 148 /// <note type="caution"> Variable infos are not persisted!</note> 149 /// </summary> 150 /// <remarks>Calls <see cref="OperatorBase.GetXmlNode"/> of base class <see cref="OperatorBase"/>.</remarks> 180 /// </summary> 181 /// <remarks> 182 /// Calls <see cref="OperatorBase.GetXmlNode"/> of base class <see cref="OperatorBase"/>. 183 /// <br/>A quick overview how the single elements of the current instance are saved: 184 /// <list type="bullet"> 185 /// <item> 186 /// <term>Variables: </term> 187 /// <description>Saved as child node with tag name <c>Variables</c>. All variables are themselves 188 /// saved as child nodes.</description> 189 /// </item> 190 /// </list> 191 /// </remarks> 151 192 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 152 193 /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param> 153 194 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 154 195 /// <returns>The saved <see cref="XmlNode"/>.</returns> 155 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {196 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 156 197 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 157 // variable infos should not be persisted 158 XmlNode infosNode = node.SelectSingleNode("VariableInfos"); 159 infosNode.RemoveAll(); 198 XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null); 199 foreach (IVariable variable in myVariables.Values) 200 variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects)); 201 node.AppendChild(variablesNode); 160 202 return node; 203 } 204 /// <summary> 205 /// Loads the persisted variable injector from the specified <paramref name="node"/>. 206 /// </summary> 207 /// <remarks>Calls <see cref="OperatorBase.Populate"/> of base class 208 /// <see cref="OperatorBase"/>. 209 /// For informations how the different elements must be saved please see <see cref="GetXmlNode"/>.</remarks> 210 /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param> 211 /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param> 212 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 213 base.Populate(node, restoredObjects); 214 XmlNode variablesNode = node.SelectSingleNode("Variables"); 215 foreach (XmlNode variableNode in variablesNode.ChildNodes) 216 AddVariable((IVariable)PersistenceManager.Restore(variableNode, restoredObjects)); 161 217 } 162 218 #endregion -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjectorView.Designer.cs
r1530 r2027 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 components = new System.ComponentModel.Container(); 47 this.variablesTabPage = new System.Windows.Forms.TabPage(); 48 this.variablesContainerView = new HeuristicLab.Core.VariablesContainerView(); 49 this.tabControl.SuspendLayout(); 50 this.parametersTabPage.SuspendLayout(); 51 this.variablesTabPage.SuspendLayout(); 52 this.SuspendLayout(); 53 // 54 // tabControl 55 // 56 this.tabControl.Controls.Add(this.variablesTabPage); 57 this.tabControl.Controls.SetChildIndex(this.parametersTabPage, 0); 58 this.tabControl.Controls.SetChildIndex(this.variablesTabPage, 0); 59 // 60 // variablesTabPage 61 // 62 this.variablesTabPage.Controls.Add(this.variablesContainerView); 63 this.variablesTabPage.Location = new System.Drawing.Point(4, 22); 64 this.variablesTabPage.Name = "variablesTabPage"; 65 this.variablesTabPage.Padding = new System.Windows.Forms.Padding(3); 66 this.variablesTabPage.Size = new System.Drawing.Size(415, 307); 67 this.variablesTabPage.TabIndex = 4; 68 this.variablesTabPage.Text = "Variables"; 69 this.variablesTabPage.UseVisualStyleBackColor = true; 70 // 71 // variablesContainerView 72 // 73 this.variablesContainerView.Caption = "Variables Container"; 74 this.variablesContainerView.Dock = System.Windows.Forms.DockStyle.Fill; 75 this.variablesContainerView.Location = new System.Drawing.Point(3, 3); 76 this.variablesContainerView.Name = "variablesContainerView"; 77 this.variablesContainerView.Size = new System.Drawing.Size(409, 301); 78 this.variablesContainerView.TabIndex = 0; 79 this.variablesContainerView.VariablesContainer = null; 80 // 81 // VariableInjectorView 82 // 83 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 48 84 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 85 this.Name = "VariableInjectorView"; 86 this.tabControl.ResumeLayout(false); 87 this.parametersTabPage.ResumeLayout(false); 88 this.variablesTabPage.ResumeLayout(false); 89 this.ResumeLayout(false); 90 49 91 } 50 92 51 93 #endregion 94 95 private System.Windows.Forms.TabPage variablesTabPage; 96 private HeuristicLab.Core.VariablesContainerView variablesContainerView; 52 97 } 53 98 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjectorView.cs
r1530 r2027 60 60 VariableInjector = variableInjector; 61 61 } 62 63 /// <summary> 64 /// Removes event handlers in all children. 65 /// </summary> 66 protected override void RemoveItemEvents() { 67 variablesContainerView.VariablesContainer = null; 68 base.RemoveItemEvents(); 69 } 70 /// <summary> 71 /// Adds event handlers in all children. 72 /// </summary> 73 protected override void AddItemEvents() { 74 base.AddItemEvents(); 75 variablesContainerView.VariablesContainer = VariableInjector; 76 } 77 62 78 } 63 79 } -
branches/Operator Architecture Refactoring/HeuristicLab.SequentialEngine/3.2/SequentialEngine.cs
r1851 r2027 75 75 try { 76 76 currentOperator = atomicOperation.Operator; 77 next = atomicOperation.Operator.Execute(atomicOperation. Scope);77 next = atomicOperation.Operator.Execute(atomicOperation.Environment, atomicOperation.Scope); 78 78 } 79 79 catch (Exception ex) {
Note: See TracChangeset
for help on using the changeset viewer.