Changeset 2524
- Timestamp:
- 11/23/09 15:17:08 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 20 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab 3.3.sln
r2520 r2524 17 17 {E226881D-315F-423D-B419-A766FE0D8685} = {E226881D-315F-423D-B419-A766FE0D8685} 18 18 {C36BD924-A541-4A00-AFA8-41701378DDC5} = {C36BD924-A541-4A00-AFA8-41701378DDC5} 19 {19C1E42A-4B48-4EFD-B697-899016F1C198} = {19C1E42A-4B48-4EFD-B697-899016F1C198}20 19 {6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6} = {6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6} 21 20 {0E27A536-1C4A-4624-A65E-DC4F4F23E3E1} = {0E27A536-1C4A-4624-A65E-DC4F4F23E3E1} … … 58 57 EndProject 59 58 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Data-3.3", "HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj", "{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}" 60 EndProject61 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Constraints-3.3", "HeuristicLab.Constraints\3.3\HeuristicLab.Constraints-3.3.csproj", "{19C1E42A-4B48-4EFD-B697-899016F1C198}"62 59 EndProject 63 60 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Operators-3.3", "HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj", "{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}" … … 213 210 {BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}.Release|x86.ActiveCfg = Release|x86 214 211 {BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}.Release|x86.Build.0 = Release|x86 215 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Debug|Any CPU.ActiveCfg = Debug|Any CPU216 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Debug|Any CPU.Build.0 = Debug|Any CPU217 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Debug|x64.ActiveCfg = Debug|x64218 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Debug|x64.Build.0 = Debug|x64219 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Debug|x86.ActiveCfg = Debug|x86220 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Debug|x86.Build.0 = Debug|x86221 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Release|Any CPU.ActiveCfg = Release|Any CPU222 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Release|Any CPU.Build.0 = Release|Any CPU223 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Release|x64.ActiveCfg = Release|x64224 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Release|x64.Build.0 = Release|x64225 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Release|x86.ActiveCfg = Release|x86226 {19C1E42A-4B48-4EFD-B697-899016F1C198}.Release|x86.Build.0 = Release|x86227 212 {23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 228 213 {23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}.Debug|Any CPU.Build.0 = Debug|Any CPU -
trunk/sources/HeuristicLab 3.3/CopyAssemblies.cmd
r2520 r2524 14 14 copy "%SolutionDir%\HeuristicLab.Core\3.3\%Outdir%\HeuristicLab.Core-3.3.dll" .\plugins 15 15 copy "%SolutionDir%\HeuristicLab.Core.Views\3.3\%Outdir%\HeuristicLab.Core.Views-3.3.dll" .\plugins 16 copy "%SolutionDir%\HeuristicLab.Constraints\3.3\%Outdir%\HeuristicLab.Constraints-3.3.dll" .\plugins17 16 copy "%SolutionDir%\HeuristicLab.Data\3.3\%Outdir%\HeuristicLab.Data-3.3.dll" .\plugins 18 17 copy "%SolutionDir%\HeuristicLab.Evolutionary\3.3\%Outdir%\HeuristicLab.Evolutionary-3.3.dll" .\plugins … … 25 24 copy "%SolutionDir%\HeuristicLab.Operators\3.3\%Outdir%\HeuristicLab.Operators-3.3.dll" .\plugins 26 25 copy "%SolutionDir%\HeuristicLab.Operators.Programmable\3.3\%Outdir%\HeuristicLab.Operators.Programmable-3.3.dll" .\plugins 27 copy "%SolutionDir%\HeuristicLab.OptimizationFrontend\3.3\%Outdir%\HeuristicLab.OptimizationFrontend-3.3.dll" .\plugins28 26 copy "%SolutionDir%\HeuristicLab.Optimizer\3.3\%Outdir%\HeuristicLab.Optimizer-3.3.dll" .\plugins 29 27 copy "%SolutionDir%\HeuristicLab.Permutation\3.3\%Outdir%\HeuristicLab.Permutation-3.3.dll" .\plugins -
trunk/sources/HeuristicLab.Core.Views/3.3/Auxiliary.cs
r2520 r2524 30 30 /// </summary> 31 31 public static class Auxiliary { 32 #region Cloning33 /// <summary>34 /// Clones the given <paramref name="obj"/> (deep clone).35 /// </summary>36 /// <remarks>Checks before clone if object has not already been cloned.</remarks>37 /// <param name="obj">The object to clone.</param>38 /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param>39 /// <returns>The cloned object.</returns>40 public static object Clone(IStorable obj, IDictionary<Guid, object> clonedObjects) {41 object clone;42 if (clonedObjects.TryGetValue(obj.Guid, out clone))43 return clone;44 else45 return obj.Clone(clonedObjects);46 }47 #endregion48 49 32 #region Error Messages 50 33 /// <summary> … … 84 67 } 85 68 #endregion 86 87 #region Constraint Violation Messages88 /// <summary>89 /// Shows a warning message box with an OK-Button, indicating that the given constraints were violated and so90 /// the operation could not be completed.91 /// </summary>92 /// <param name="violatedConstraints">The constraints that could not be fulfilled.</param>93 public static void ShowConstraintViolationMessageBox(ICollection<IConstraint> violatedConstraints) {94 string message = BuildConstraintViolationMessage(violatedConstraints);95 MessageBox.Show("The following constraints are violated. The operation could not be completed.\n\n" + message,96 "Constraint Violation",97 MessageBoxButtons.OK,98 MessageBoxIcon.Warning);99 }100 /// <summary>101 /// Shows a question message box with a yes-no option, where to choose whether to ignore102 /// the given violated constraints and to complete the operation or not.103 /// </summary>104 /// <param name="violatedConstraints">The constraints that could not be fulfilled.</param>105 /// <returns>The result of the choice ("Yes" = 6, "No" = 7).</returns>106 public static DialogResult ShowIgnoreConstraintViolationMessageBox(ICollection<IConstraint> violatedConstraints) {107 string message = BuildConstraintViolationMessage(violatedConstraints);108 return MessageBox.Show("The following constraints are violated. Do you want to complete the operation anyhow?\n\n" + message,109 "Constraint Violation",110 MessageBoxButtons.YesNo,111 MessageBoxIcon.Question);112 }113 /// <summary>114 /// Builds a message out of a given collection of violated constraints,115 /// including the constraints type and description.116 /// </summary>117 /// <param name="violatedConstraints">The constraints that could not be fulfilled.</param>118 /// <returns>The message to display.</returns>119 private static string BuildConstraintViolationMessage(ICollection<IConstraint> violatedConstraints) {120 StringBuilder sb = new StringBuilder();121 foreach (IConstraint constraint in violatedConstraints) {122 sb.AppendLine(constraint.GetType().Name);123 sb.AppendLine(constraint.Description);124 sb.AppendLine();125 }126 return sb.ToString();127 }128 #endregion129 69 } 130 70 } -
trunk/sources/HeuristicLab.Core.Views/3.3/HeuristicLab.Core.Views-3.3.csproj
r2520 r2524 70 70 <DependentUpon>ChooseTypeDialog.cs</DependentUpon> 71 71 </Compile> 72 <Compile Include="ConstrainedItemBaseView.cs">73 <SubType>UserControl</SubType>74 </Compile>75 <Compile Include="ConstrainedItemBaseView.Designer.cs">76 <DependentUpon>ConstrainedItemBaseView.cs</DependentUpon>77 </Compile>78 72 <Compile Include="EditorBase.cs"> 79 73 <SubType>UserControl</SubType> … … 210 204 <EmbeddedResource Include="ChooseTypeDialog.resx"> 211 205 <DependentUpon>ChooseTypeDialog.cs</DependentUpon> 212 </EmbeddedResource>213 <EmbeddedResource Include="ConstrainedItemBaseView.resx">214 <DependentUpon>ConstrainedItemBaseView.cs</DependentUpon>215 206 </EmbeddedResource> 216 207 <EmbeddedResource Include="EditorBase.resx"> -
trunk/sources/HeuristicLab.Core.Views/3.3/OperatorBaseView.Designer.cs
r2520 r2524 53 53 this.variablesTabPage = new System.Windows.Forms.TabPage(); 54 54 this.operatorBaseVariablesView = new HeuristicLab.Core.Views.OperatorBaseVariablesView(); 55 this.constraintsTabPage = new System.Windows.Forms.TabPage();56 this.constrainedItemBaseView = new HeuristicLab.Core.Views.ConstrainedItemBaseView();57 55 this.descriptionTabPage = new System.Windows.Forms.TabPage(); 58 56 this.operatorBaseDescriptionView = new HeuristicLab.Core.Views.OperatorBaseDescriptionView(); … … 60 58 this.variableInfosTabPage.SuspendLayout(); 61 59 this.variablesTabPage.SuspendLayout(); 62 this.constraintsTabPage.SuspendLayout();63 60 this.descriptionTabPage.SuspendLayout(); 64 61 this.SuspendLayout(); … … 68 65 this.tabControl.Controls.Add(this.variableInfosTabPage); 69 66 this.tabControl.Controls.Add(this.variablesTabPage); 70 this.tabControl.Controls.Add(this.constraintsTabPage);71 67 this.tabControl.Controls.Add(this.descriptionTabPage); 72 68 this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill; … … 119 115 this.operatorBaseVariablesView.TabIndex = 0; 120 116 // 121 // constraintsTabPage122 //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 // constrainedItemBaseView133 //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;141 //142 117 // descriptionTabPage 143 118 // … … 172 147 this.variableInfosTabPage.ResumeLayout(false); 173 148 this.variablesTabPage.ResumeLayout(false); 174 this.constraintsTabPage.ResumeLayout(false);175 149 this.descriptionTabPage.ResumeLayout(false); 176 150 this.ResumeLayout(false); … … 183 157 protected TabPage variableInfosTabPage; 184 158 protected TabPage variablesTabPage; 185 private TabPage constraintsTabPage;186 protected ConstrainedItemBaseView constrainedItemBaseView;187 159 protected OperatorBaseVariableInfosView operatorBaseVariableInfosView; 188 160 protected OperatorBaseVariablesView operatorBaseVariablesView; -
trunk/sources/HeuristicLab.Core.Views/3.3/OperatorBaseView.cs
r2520 r2524 70 70 operatorBaseVariableInfosView.Operator = null; 71 71 operatorBaseVariablesView.Operator = null; 72 constrainedItemBaseView.ConstrainedItem = null;73 72 operatorBaseDescriptionView.Operator = null; 74 73 base.RemoveItemEvents(); … … 81 80 operatorBaseVariableInfosView.Operator = Operator; 82 81 operatorBaseVariablesView.Operator = Operator; 83 constrainedItemBaseView.ConstrainedItem = Operator;84 82 operatorBaseDescriptionView.Operator = Operator; 85 83 } -
trunk/sources/HeuristicLab.Core.Views/3.3/OperatorGraphView.cs
r2520 r2524 353 353 IOperator newParent = (IOperator)node.Parent.Tag; 354 354 int newIndex = node.Index; 355 ICollection<IConstraint> violatedConstraints; 356 ICollection<IConstraint> violatedConstraints2; 357 oldParent.TryRemoveSubOperator(oldIndex, out violatedConstraints); 358 newParent.TryAddSubOperator(op, newIndex, out violatedConstraints2); 359 if ((violatedConstraints.Count == 0) && (violatedConstraints2.Count == 0)) { 360 graphTreeView.SelectedNode = parentNode.Nodes[newIndex]; 361 } else { 362 List<IConstraint> allViolatedConstraints = new List<IConstraint>(violatedConstraints); 363 allViolatedConstraints.AddRange(violatedConstraints2); 364 if (Auxiliary.ShowIgnoreConstraintViolationMessageBox(allViolatedConstraints) == DialogResult.Yes) { 365 if (violatedConstraints.Count > 0) 366 oldParent.RemoveSubOperator(oldIndex); 367 if (violatedConstraints2.Count > 0) 368 newParent.AddSubOperator(op, newIndex); 369 graphTreeView.SelectedNode = parentNode.Nodes[newIndex]; 370 } else { 371 if (violatedConstraints.Count == 0) 372 oldParent.AddSubOperator(op, oldIndex); 373 if (violatedConstraints2.Count == 0) 374 newParent.RemoveSubOperator(newIndex); 375 } 376 } 355 oldParent.RemoveSubOperator(oldIndex); 356 newParent.AddSubOperator(op, newIndex); 357 graphTreeView.SelectedNode = parentNode.Nodes[newIndex]; 377 358 } 378 359 } else { 379 360 if (node != null) { 380 361 IOperator parent = (IOperator)node.Tag; 381 ICollection<IConstraint> violatedConstraints; 382 if (parent.TryAddSubOperator(op, out violatedConstraints)) { 383 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1]; 384 } else if (Auxiliary.ShowIgnoreConstraintViolationMessageBox(violatedConstraints) == DialogResult.Yes) { 385 parent.AddSubOperator(op); 386 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1]; 387 } 362 parent.AddSubOperator(op); 363 graphTreeView.SelectedNode = node.Nodes[node.Nodes.Count - 1]; 388 364 } 389 365 } -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r2520 r2524 99 99 <ItemGroup> 100 100 <Compile Include="Auxiliary.cs" /> 101 <Compile Include="ConstrainedItemBase.cs" />102 101 <Compile Include="AtomicOperation.cs" /> 103 102 <Compile Include="CompositeOperation.cs" /> … … 106 105 <Compile Include="Interfaces\IOperatorLibrary.cs" /> 107 106 <Compile Include="Interfaces\IVisualizationItem.cs" /> 108 <Compile Include="Interfaces\IConstrainedItem.cs" />109 <Compile Include="Interfaces\IConstraint.cs" />110 107 <Compile Include="Interfaces\IItem.cs" /> 111 108 <Compile Include="ItemBase.cs" /> -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperator.cs
r2474 r2524 30 30 /// a basic instruction of an algorithm. 31 31 /// </summary> 32 public interface IOperator : I ConstrainedItem {32 public interface IOperator : IItem { 33 33 /// <summary> 34 34 /// Gets or sets the name of the current instance. … … 68 68 void AddSubOperator(IOperator op); 69 69 /// <summary> 70 /// Adds the given sub operator to the current instance if all constraints can be fulfilled.71 /// </summary>72 /// <param name="op">The operator to add.</param>73 /// <returns><c>true</c> if the operator could be added without violating constraints,74 /// <c>false</c> otherwise.</returns>75 bool TryAddSubOperator(IOperator op);76 /// <summary>77 /// Adds the given sub operator to the current instance if all constraints can be fulfilled.78 /// </summary>79 /// <param name="op">The operator to add.</param>80 /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be81 /// fulfilled.</param>82 /// <returns><c>true</c> if the operator could be added without violating constraints,83 /// <c>false</c> otherwise.</returns>84 bool TryAddSubOperator(IOperator op, out ICollection<IConstraint> violatedConstraints);85 /// <summary>86 70 /// Adds the given sub operator at a the specified <paramref name="index"/>. 87 71 /// </summary> … … 90 74 void AddSubOperator(IOperator op, int index); 91 75 /// <summary> 92 /// Adds the given operator at the specified <paramref name="index"/> to the current instance93 /// if all constraints can be fulfilled.94 /// </summary>95 /// <param name="op">The operator to add.</param>96 /// <param name="index">The position where to add the operator.</param>97 /// <returns><c>true</c> if the operator could be added without violating constraints,98 /// <c>false</c> otherwise.</returns>99 bool TryAddSubOperator(IOperator op, int index);100 /// <summary>101 /// Adds the given operator at the specified <paramref name="index"/> to the current instance102 /// if all constraints can be fulfilled.103 /// </summary>104 /// <param name="op">The operator to add.</param>105 /// <param name="index">The position where to add the operator.</param>106 /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be107 /// fulfilled.</param>108 /// <returns><c>true</c> if the operator could be added without violating constraints,109 /// <c>false</c> otherwise.</returns>110 bool TryAddSubOperator(IOperator op, int index, out ICollection<IConstraint> violatedConstraints);111 /// <summary>112 76 /// Removes a sub operator at the specified <paramref name="index"/>. 113 77 /// </summary> 114 78 /// <param name="index">The position where to delete the operator.</param> 115 79 void RemoveSubOperator(int index); 116 /// <summary>117 /// Removes a sub operator at the specified <paramref name="index"/> if all constraint can be fulfilled.118 /// </summary>119 /// <param name="index">The position where to delete the operator.</param>120 /// <returns><c>true</c> if the operator could be deleted without violating constraints,121 /// <c>false</c> otherwise.</returns>122 bool TryRemoveSubOperator(int index);123 /// <summary>124 /// Deletes the operator at the specified <paramref name="index"/>125 /// if all constraints can be fulfilled.126 /// </summary>127 /// <param name="index">The position where to delete the operator.</param>128 /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be129 /// fulfilled.</param>130 /// <returns><c>true</c> if the operator could be deleted without violating constraints,131 /// <c>false</c> otherwise.</returns>132 bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints);133 80 134 81 /// <summary> … … 144 91 void AddVariableInfo(IVariableInfo variableInfo); 145 92 /// <summary> 146 /// Adds the specified variable info to the current instance, if all constraints can be fulfilled.147 /// </summary>148 /// <param name="variableInfo">The variable info to add.</param>149 /// <returns><c>true</c> if the variable info could be added without violating constraints,150 /// <c>false</c> otherwise.</returns>151 bool TryAddVariableInfo(IVariableInfo variableInfo);152 /// <summary>153 /// Adds the specified variable info to the current instance, if all constraints can be fulfilled.154 /// </summary>155 /// <param name="variableInfo">The variable info to add.</param>156 /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be157 /// fulfilled.</param>158 /// <returns><c>true</c> if the variable info could be added without violating constraints,159 /// <c>false</c> otherwise.</returns>160 bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints);161 /// <summary>162 93 /// Removes the variable info with the given formal name. 163 94 /// </summary> 164 95 /// <param name="formalName">The formal name of the variable info to remove.</param> 165 96 void RemoveVariableInfo(string formalName); 166 /// <summary>167 /// Deletes the variable info with the given formal name,168 /// if all constraints can be fulfilled.169 /// </summary>170 /// <param name="formalName">The formal name of the variable info to remove.</param>171 /// <returns><c>true</c> if the variable info could be deleted without violating constraints,172 /// <c>false</c> otherwise.</returns>173 bool TryRemoveVariableInfo(string formalName);174 /// <summary>175 /// Deletes the variable info with the given formal name,176 /// if all constraints can be fulfilled.177 /// </summary>178 /// <param name="formalName">The formal name of the variable info to remove.</param>179 /// <param name="violatedConstraints">Output parameter; contains all constraints that could not be180 /// fulfilled.</param>181 /// <returns><c>true</c> if the variable info could be deleted without violating constraints,182 /// <c>false</c> otherwise.</returns>183 bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints);184 97 185 98 /// <summary> … … 195 108 void AddVariable(IVariable variable); 196 109 /// <summary> 197 /// Adds the specified <paramref name="variable"/> to the current instance if all constraints can198 /// be fulfilled.199 /// </summary>200 /// <param name="variable">The variable to add.</param>201 /// <returns><c>true</c> if the variable could be added without violating constraints,202 /// <c>false</c> otherwise.</returns>203 bool TryAddVariable(IVariable variable);204 /// <summary>205 /// Adds the specified <paramref name="variable"/> to the current instance if all constraints can206 /// be fulfilled.207 /// </summary>208 /// <param name="variable">The variable to add.</param>209 /// <param name="violatedConstraints">Output parameter; contains all constraints that could210 /// not be fulfillled.</param>211 /// <returns><c>true</c> if the variable could be added without violating constraints,212 /// <c>false</c> otherwise.</returns>213 bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints);214 /// <summary>215 110 /// Deletes the variable with the specified <paramref name="name"/>. 216 111 /// </summary> 217 112 /// <param name="name">The name of the variable to delete.</param> 218 113 void RemoveVariable(string name); 219 /// <summary> 220 /// Deletes the variable with the specified <paramref name="name"/> if all constraints can be 221 /// fulfilled. 222 /// </summary> 223 /// <param name="name">The name of the variable to remove.</param> 224 /// <returns><c>true</c> if the variable could be deleted without violating constraints, 225 /// <c>false</c> otherwise.</returns> 226 bool TryRemoveVariable(string name); 227 /// <summary> 228 /// Deletes the variable with the specified <paramref name="name"/> if all constraints can be 229 /// fulfilled. 230 /// </summary> 231 /// <param name="name">The name of the variable to remove.</param> 232 /// <param name="violatedConstraints">Output parameter; contains all constraints that could 233 /// not be fulfilled.</param> 234 /// <returns><c>true</c> if the variable could be deleted without violating constraints, 235 /// <c>false</c> otherwise.</returns> 236 bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints); 237 114 238 115 /// <inheritdoc cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/> 239 116 /// <typeparam name="T">The type of the value that is searched.</typeparam> -
trunk/sources/HeuristicLab.Core/3.3/OperatorBase.cs
r2520 r2524 31 31 /// The base class for all operators. 32 32 /// </summary> 33 public abstract class OperatorBase : ConstrainedItemBase, IOperator {33 public abstract class OperatorBase : ItemBase, IOperator { 34 34 35 35 [Storable] … … 154 154 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1); 155 155 } 156 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator)"/>157 /// <param name="subOperator">The sub operator to add.</param>158 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>159 public virtual bool TryAddSubOperator(IOperator subOperator) {160 mySubOperators.Add(subOperator);161 if (IsValid()) {162 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);163 return true;164 } else {165 mySubOperators.RemoveAt(mySubOperators.Count - 1);166 return false;167 }168 }169 /// <inheritdoc cref="HeuristicLab.Core.IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator,170 /// out System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/>171 /// <param name="subOperator">The sub operator to add.</param>172 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>173 public virtual bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {174 mySubOperators.Add(subOperator);175 if (IsValid(out violatedConstraints)) {176 OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);177 return true;178 } else {179 mySubOperators.RemoveAt(mySubOperators.Count - 1);180 return false;181 }182 }183 156 /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/> 184 157 /// <param name="subOperator">The sub operator to add.</param> … … 188 161 OnSubOperatorAdded(subOperator, index); 189 162 } 190 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int)"/>191 /// <param name="subOperator">The sub operator to add.</param>192 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>193 public virtual bool TryAddSubOperator(IOperator subOperator, int index) {194 mySubOperators.Insert(index, subOperator);195 if (IsValid()) {196 OnSubOperatorAdded(subOperator, index);197 return true;198 } else {199 mySubOperators.RemoveAt(index);200 return false;201 }202 }203 /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int, out204 /// System.Collections.Generic.ICollection<HeuristicLab.Core.IConstraint>)"/>205 /// <param name="subOperator">The sub operator to add.</param>206 /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>207 public virtual bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {208 mySubOperators.Insert(index, subOperator);209 if (IsValid(out violatedConstraints)) {210 OnSubOperatorAdded(subOperator, index);211 return true;212 } else {213 mySubOperators.RemoveAt(index);214 return false;215 }216 }217 163 /// <inheritdoc/> 218 164 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks> … … 221 167 mySubOperators.RemoveAt(index); 222 168 OnSubOperatorRemoved(op, index); 223 }224 /// <inheritdoc/>225 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>226 public virtual bool TryRemoveSubOperator(int index) {227 IOperator op = mySubOperators[index];228 mySubOperators.RemoveAt(index);229 if (IsValid()) {230 OnSubOperatorRemoved(op, index);231 return true;232 } else {233 mySubOperators.Insert(index, op);234 return false;235 }236 }237 /// <inheritdoc/>238 /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>239 public virtual bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {240 IOperator op = mySubOperators[index];241 mySubOperators.RemoveAt(index);242 if (IsValid(out violatedConstraints)) {243 OnSubOperatorRemoved(op, index);244 return true;245 } else {246 mySubOperators.Insert(index, op);247 return false;248 }249 169 } 250 170 #endregion … … 266 186 } 267 187 /// <inheritdoc/> 268 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>269 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo) {270 myVariableInfos.Add(variableInfo.FormalName, variableInfo);271 if (IsValid()) {272 OnVariableInfoAdded(variableInfo);273 return true;274 } else {275 myVariableInfos.Remove(variableInfo.FormalName);276 return false;277 }278 }279 /// <inheritdoc/>280 /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>281 public virtual bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints) {282 myVariableInfos.Add(variableInfo.FormalName, variableInfo);283 if (IsValid(out violatedConstraints)) {284 OnVariableInfoAdded(variableInfo);285 return true;286 } else {287 myVariableInfos.Remove(variableInfo.FormalName);288 return false;289 }290 }291 /// <inheritdoc/>292 188 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks> 293 189 public virtual void RemoveVariableInfo(string formalName) { … … 297 193 OnVariableInfoRemoved(variableInfo); 298 194 } 299 }300 /// <inheritdoc/>301 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>302 public virtual bool TryRemoveVariableInfo(string formalName) {303 IVariableInfo variableInfo;304 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {305 myVariableInfos.Remove(formalName);306 if (IsValid()) {307 OnVariableInfoRemoved(variableInfo);308 return true;309 } else {310 myVariableInfos.Add(formalName, variableInfo);311 return false;312 }313 }314 return true;315 }316 /// <inheritdoc/>317 /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>318 public virtual bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints) {319 IVariableInfo variableInfo;320 if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {321 myVariableInfos.Remove(formalName);322 if (IsValid(out violatedConstraints)) {323 OnVariableInfoRemoved(variableInfo);324 return true;325 } else {326 myVariableInfos.Add(formalName, variableInfo);327 return false;328 }329 }330 violatedConstraints = new List<IConstraint>();331 return true;332 195 } 333 196 #endregion … … 350 213 variable.NameChanged += new EventHandler(Variable_NameChanged); 351 214 OnVariableAdded(variable); 352 }353 /// <inheritdoc/>354 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>355 /// event handlers.</remarks>356 public virtual bool TryAddVariable(IVariable variable) {357 myVariables.Add(variable.Name, variable);358 if (IsValid()) {359 variable.NameChanging += new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);360 variable.NameChanged += new EventHandler(Variable_NameChanged);361 OnVariableAdded(variable);362 return true;363 } else {364 myVariableInfos.Remove(variable.Name);365 return false;366 }367 }368 /// <inheritdoc/>369 /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>370 /// event handlers.</remarks>371 public virtual bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints) {372 myVariables.Add(variable.Name, variable);373 if (IsValid(out violatedConstraints)) {374 variable.NameChanging += new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);375 variable.NameChanged += new EventHandler(Variable_NameChanged);376 OnVariableAdded(variable);377 return true;378 } else {379 myVariableInfos.Remove(variable.Name);380 return false;381 }382 215 } 383 216 /// <inheritdoc/> … … 392 225 OnVariableRemoved(variable); 393 226 } 394 }395 /// <inheritdoc/>396 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>397 /// event handlers.</remarks>398 public virtual bool TryRemoveVariable(string name) {399 IVariable variable;400 if (myVariables.TryGetValue(name, out variable)) {401 myVariables.Remove(name);402 if (IsValid()) {403 variable.NameChanging -= new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);404 variable.NameChanged -= new EventHandler(Variable_NameChanged);405 OnVariableRemoved(variable);406 return true;407 } else {408 myVariables.Add(name, variable);409 return false;410 }411 }412 return true;413 }414 /// <inheritdoc/>415 /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>416 /// event handlers.</remarks>417 public virtual bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints) {418 IVariable variable;419 if (myVariables.TryGetValue(name, out variable)) {420 myVariables.Remove(name);421 if (IsValid(out violatedConstraints)) {422 variable.NameChanging -= new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);423 variable.NameChanged -= new EventHandler(Variable_NameChanged);424 OnVariableRemoved(variable);425 return true;426 } else {427 myVariables.Add(name, variable);428 return false;429 }430 }431 violatedConstraints = new List<IConstraint>();432 return true;433 227 } 434 228 private void Variable_NameChanging(object sender, CancelEventArgs<string> e) { -
trunk/sources/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj
r2520 r2524 128 128 <DependentUpon>BoolMatrixDataView.cs</DependentUpon> 129 129 </Compile> 130 <Compile Include="ConstrainedItemList.cs" />131 <Compile Include="ConstrainedItemListView.cs">132 <SubType>UserControl</SubType>133 </Compile>134 <Compile Include="ConstrainedItemListView.Designer.cs">135 <DependentUpon>ConstrainedItemListView.cs</DependentUpon>136 </Compile>137 <Compile Include="ConstrainedObjectData.cs" />138 <Compile Include="ConstrainedIntData.cs" />139 <Compile Include="ConstrainedIntDataView.cs">140 <SubType>UserControl</SubType>141 </Compile>142 <Compile Include="ConstrainedIntDataView.Designer.cs">143 <DependentUpon>ConstrainedIntDataView.cs</DependentUpon>144 </Compile>145 <Compile Include="ConstrainedDoubleData.cs" />146 <Compile Include="ConstrainedDoubleDataView.cs">147 <SubType>UserControl</SubType>148 </Compile>149 <Compile Include="ConstrainedDoubleDataView.Designer.cs">150 <DependentUpon>ConstrainedDoubleDataView.cs</DependentUpon>151 </Compile>152 130 <Compile Include="EditKeyValueDialog.cs"> 153 131 <SubType>Form</SubType> … … 277 255 <EmbeddedResource Include="BoolDataView.resx"> 278 256 <DependentUpon>BoolDataView.cs</DependentUpon> 279 <SubType>Designer</SubType>280 </EmbeddedResource>281 <EmbeddedResource Include="ConstrainedIntDataView.resx">282 <DependentUpon>ConstrainedIntDataView.cs</DependentUpon>283 <SubType>Designer</SubType>284 </EmbeddedResource>285 <EmbeddedResource Include="ConstrainedDoubleDataView.resx">286 <DependentUpon>ConstrainedDoubleDataView.cs</DependentUpon>287 <SubType>Designer</SubType>288 </EmbeddedResource>289 <EmbeddedResource Include="ConstrainedItemListView.resx">290 <DependentUpon>ConstrainedItemListView.cs</DependentUpon>291 257 <SubType>Designer</SubType> 292 258 </EmbeddedResource> -
trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.Designer.cs
r2520 r2524 57 57 this.variablesTabPage = new System.Windows.Forms.TabPage(); 58 58 this.operatorBaseVariablesView = new HeuristicLab.Core.Views.OperatorBaseVariablesView(); 59 this.constraintsTabPage = new System.Windows.Forms.TabPage();60 this.constrainedItemBaseView = new HeuristicLab.Core.Views.ConstrainedItemBaseView();61 59 this.descriptionTabPage = new System.Windows.Forms.TabPage(); 62 60 this.descriptionTextBox = new System.Windows.Forms.TextBox(); … … 65 63 this.variableInfosTabPage.SuspendLayout(); 66 64 this.variablesTabPage.SuspendLayout(); 67 this.constraintsTabPage.SuspendLayout();68 65 this.descriptionTabPage.SuspendLayout(); 69 66 this.SuspendLayout(); … … 74 71 this.tabControl.Controls.Add(this.variableInfosTabPage); 75 72 this.tabControl.Controls.Add(this.variablesTabPage); 76 this.tabControl.Controls.Add(this.constraintsTabPage);77 73 this.tabControl.Controls.Add(this.descriptionTabPage); 78 74 this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill; … … 206 202 this.operatorBaseVariablesView.TabIndex = 0; 207 203 // 208 // constraintsTabPage209 //210 this.constraintsTabPage.Controls.Add(this.constrainedItemBaseView);211 this.constraintsTabPage.Location = new System.Drawing.Point(4, 22);212 this.constraintsTabPage.Name = "constraintsTabPage";213 this.constraintsTabPage.Padding = new System.Windows.Forms.Padding(3);214 this.constraintsTabPage.Size = new System.Drawing.Size(427, 325);215 this.constraintsTabPage.TabIndex = 3;216 this.constraintsTabPage.Text = "Constraints";217 this.constraintsTabPage.UseVisualStyleBackColor = true;218 //219 // constrainedItemBaseView220 //221 this.constrainedItemBaseView.Caption = "Constrained Item";222 this.constrainedItemBaseView.ConstrainedItem = null;223 this.constrainedItemBaseView.Dock = System.Windows.Forms.DockStyle.Fill;224 this.constrainedItemBaseView.Location = new System.Drawing.Point(3, 3);225 this.constrainedItemBaseView.Name = "constrainedItemBaseView";226 this.constrainedItemBaseView.Size = new System.Drawing.Size(421, 319);227 this.constrainedItemBaseView.TabIndex = 0;228 //229 204 // descriptionTabPage 230 205 // … … 262 237 this.variableInfosTabPage.ResumeLayout(false); 263 238 this.variablesTabPage.ResumeLayout(false); 264 this.constraintsTabPage.ResumeLayout(false);265 239 this.descriptionTabPage.ResumeLayout(false); 266 240 this.descriptionTabPage.PerformLayout(); … … 278 252 private System.Windows.Forms.TabPage variablesTabPage; 279 253 private HeuristicLab.Core.Views.OperatorBaseVariablesView operatorBaseVariablesView; 280 private System.Windows.Forms.TabPage constraintsTabPage;281 private HeuristicLab.Core.Views.ConstrainedItemBaseView constrainedItemBaseView;282 254 private System.Windows.Forms.TabPage descriptionTabPage; 283 255 private System.Windows.Forms.TextBox descriptionTextBox; -
trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.cs
r2520 r2524 51 51 operatorBaseVariableInfosView.Operator = null; 52 52 operatorBaseVariablesView.Operator = null; 53 constrainedItemBaseView.ConstrainedItem = null;54 53 ProgrammableOperator.CodeChanged -= new EventHandler(ProgrammableOperator_CodeChanged); 55 54 ProgrammableOperator.DescriptionChanged -= new EventHandler(ProgrammableOperator_DescriptionChanged); … … 61 60 operatorBaseVariableInfosView.Operator = ProgrammableOperator; 62 61 operatorBaseVariablesView.Operator = ProgrammableOperator; 63 constrainedItemBaseView.ConstrainedItem = ProgrammableOperator;64 62 ProgrammableOperator.CodeChanged += new EventHandler(ProgrammableOperator_CodeChanged); 65 63 ProgrammableOperator.DescriptionChanged += new EventHandler(ProgrammableOperator_DescriptionChanged); -
trunk/sources/HeuristicLab.Operators/3.3/CombinedOperatorView.Designer.cs
r2520 r2524 52 52 this.variablesTabPage = new System.Windows.Forms.TabPage(); 53 53 this.operatorBaseVariablesView = new HeuristicLab.Core.Views.OperatorBaseVariablesView(); 54 this.constraintsTabPage = new System.Windows.Forms.TabPage();55 this.constrainedItemBaseView = new HeuristicLab.Core.Views.ConstrainedItemBaseView();56 54 this.descriptionTabPage = new System.Windows.Forms.TabPage(); 57 55 this.descriptionTextBox = new System.Windows.Forms.TextBox(); … … 62 60 this.variableInfosTabPage.SuspendLayout(); 63 61 this.variablesTabPage.SuspendLayout(); 64 this.constraintsTabPage.SuspendLayout();65 62 this.descriptionTabPage.SuspendLayout(); 66 63 this.SuspendLayout(); … … 71 68 this.tabControl.Controls.Add(this.variableInfosTabPage); 72 69 this.tabControl.Controls.Add(this.variablesTabPage); 73 this.tabControl.Controls.Add(this.constraintsTabPage);74 70 this.tabControl.Controls.Add(this.descriptionTabPage); 75 71 this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill; … … 148 144 this.operatorBaseVariablesView.TabIndex = 0; 149 145 // 150 // constraintsTabPage151 //152 this.constraintsTabPage.Controls.Add(this.constrainedItemBaseView);153 this.constraintsTabPage.Location = new System.Drawing.Point(4, 22);154 this.constraintsTabPage.Name = "constraintsTabPage";155 this.constraintsTabPage.Padding = new System.Windows.Forms.Padding(3);156 this.constraintsTabPage.Size = new System.Drawing.Size(389, 309);157 this.constraintsTabPage.TabIndex = 3;158 this.constraintsTabPage.Text = "Constraints";159 this.constraintsTabPage.UseVisualStyleBackColor = true;160 //161 // constrainedItemBaseView162 //163 this.constrainedItemBaseView.Caption = "Constrained Item";164 this.constrainedItemBaseView.ConstrainedItem = null;165 this.constrainedItemBaseView.Dock = System.Windows.Forms.DockStyle.Fill;166 this.constrainedItemBaseView.Location = new System.Drawing.Point(3, 3);167 this.constrainedItemBaseView.Name = "constrainedItemBaseView";168 this.constrainedItemBaseView.Size = new System.Drawing.Size(383, 303);169 this.constrainedItemBaseView.TabIndex = 0;170 //171 146 // descriptionTabPage 172 147 // … … 226 201 this.variableInfosTabPage.ResumeLayout(false); 227 202 this.variablesTabPage.ResumeLayout(false); 228 this.constraintsTabPage.ResumeLayout(false);229 203 this.descriptionTabPage.ResumeLayout(false); 230 204 this.descriptionTabPage.PerformLayout(); … … 239 213 private System.Windows.Forms.TabPage variableInfosTabPage; 240 214 private System.Windows.Forms.TabPage variablesTabPage; 241 private System.Windows.Forms.TabPage constraintsTabPage;242 215 private System.Windows.Forms.TabPage descriptionTabPage; 243 216 private System.Windows.Forms.TextBox descriptionTextBox; … … 245 218 private HeuristicLab.Core.Views.OperatorBaseVariableInfosView operatorBaseVariableInfosView; 246 219 private HeuristicLab.Core.Views.OperatorBaseVariablesView operatorBaseVariablesView; 247 private HeuristicLab.Core.Views.ConstrainedItemBaseView constrainedItemBaseView;248 220 private System.Windows.Forms.Button removeVariableInfoButton; 249 221 private System.Windows.Forms.Button addVariableInfoButton; -
trunk/sources/HeuristicLab.Operators/3.3/CombinedOperatorView.cs
r2520 r2524 55 55 operatorBaseVariableInfosView.Operator = null; 56 56 operatorBaseVariablesView.Operator = null; 57 constrainedItemBaseView.ConstrainedItem = null;58 57 CombinedOperator.DescriptionChanged -= new EventHandler(CombinedOperator_DescriptionChanged); 59 58 base.RemoveItemEvents(); … … 69 68 operatorBaseVariableInfosView.Operator = CombinedOperator; 70 69 operatorBaseVariablesView.Operator = CombinedOperator; 71 constrainedItemBaseView.ConstrainedItem = CombinedOperator;72 70 CombinedOperator.DescriptionChanged += new EventHandler(CombinedOperator_DescriptionChanged); 73 71 } -
trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj
r2520 r2524 139 139 </ItemGroup> 140 140 <ItemGroup> 141 <ProjectReference Include="..\..\HeuristicLab.Constraints\3.3\HeuristicLab.Constraints-3.3.csproj">142 <Project>{19C1E42A-4B48-4EFD-B697-899016F1C198}</Project>143 <Name>HeuristicLab.Constraints-3.3</Name>144 </ProjectReference>145 141 <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj"> 146 142 <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project> -
trunk/sources/HeuristicLab.Operators/3.3/HeuristicLabOperatorsPlugin.cs
r2520 r2524 31 31 [ClassInfo(Name = "HeuristicLab.Operators-3.3")] 32 32 [PluginFile(Filename = "HeuristicLab.Operators-3.3.dll", Filetype = PluginFileType.Assembly)] 33 [Dependency(Dependency = "HeuristicLab.Constraints-3.3")]34 33 [Dependency(Dependency = "HeuristicLab.Core-3.3")] 35 34 [Dependency(Dependency = "HeuristicLab.Core.Views-3.3")] -
trunk/sources/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj
r1691 r2524 96 96 </ItemGroup> 97 97 <ItemGroup> 98 <ProjectReference Include="..\..\HeuristicLab.Constraints\3.3\HeuristicLab.Constraints-3.3.csproj">99 <Project>{19C1E42A-4B48-4EFD-B697-899016F1C198}</Project>100 <Name>HeuristicLab.Constraints-3.3</Name>101 </ProjectReference>102 98 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 103 99 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> -
trunk/sources/HeuristicLab.Random/3.3/NormalRandomAdder.cs
r1853 r2524 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Constraints;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 … … 106 105 if (value is IntData) 107 106 AddNormal((IntData)value, normal); 108 else if (value is ConstrainedIntData)109 AddNormal((ConstrainedIntData)value, normal);110 else if (value is ConstrainedDoubleData)111 AddNormal((ConstrainedDoubleData)value, normal);112 107 else if (value is DoubleData) 113 108 AddNormal((DoubleData)value, normal); … … 125 120 126 121 /// <summary> 127 /// Generates a new double random number and adds it to the value of the given <paramref name="data"/>128 /// checking its constraints.129 /// </summary>130 /// <exception cref="InvalidProgramException">Thrown when with the current settings no valid value131 /// could be found.</exception>132 /// <param name="data">The double object where to add the random number and whose constraints133 /// to fulfill.</param>134 /// <param name="normal">The continuous, normally distributed random variable.</param>135 public void AddNormal(ConstrainedDoubleData data, NormalDistributedRandom normal) {136 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {137 double newValue = data.Data + normal.NextDouble();138 if (IsIntegerConstrained(data)) {139 newValue = Math.Round(newValue);140 }141 if (data.TrySetData(newValue)) {142 return;143 }144 }145 throw new InvalidProgramException("Coudn't find a valid value");146 }147 148 /// <summary>149 122 /// Generates a new int random number and adds it to value of the given <paramref name="data"/>. 150 123 /// </summary> … … 154 127 data.Data = (int)Math.Round(data.Data + normal.NextDouble()); 155 128 } 156 157 /// <summary>158 /// Generates a new int random number and adds it to the value of the given <paramref name="data"/>159 /// checking its constraints.160 /// </summary>161 /// <exception cref="InvalidProgramException">Thrown when with the current settings no valid value162 /// could be found.</exception>163 /// <param name="data">The int object where to add the generated value and whose contraints to check.</param>164 /// <param name="normal">The continuous, normally distributed random variable.</param>165 public void AddNormal(ConstrainedIntData data, NormalDistributedRandom normal) {166 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {167 if (data.TrySetData((int)Math.Round(data.Data + normal.NextDouble())))168 return;169 }170 throw new InvalidProgramException("Couldn't find a valid value.");171 }172 173 private bool IsIntegerConstrained(ConstrainedDoubleData data) {174 foreach (IConstraint constraint in data.Constraints) {175 if (constraint is IsIntegerConstraint) {176 return true;177 }178 }179 return false;180 }181 129 } 182 130 } -
trunk/sources/HeuristicLab.Random/3.3/NormalRandomizer.cs
r1853 r2524 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Constraints;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 … … 98 97 if (value is IntData) 99 98 RandomizeNormal((IntData)value, n); 100 else if (value is ConstrainedIntData)101 RandomizeNormal((ConstrainedIntData)value, n);102 99 else if (value is DoubleData) 103 100 RandomizeNormal((DoubleData)value, n); 104 else if (value is ConstrainedDoubleData)105 RandomizeNormal((ConstrainedDoubleData)value, n);106 101 else throw new InvalidOperationException("Can't handle type " + value.GetType().Name); 107 }108 109 /// <summary>110 /// Generates a new double random variable based on a continuous, normally distributed random number generator111 /// <paramref name="normal"/> and checks some contraints.112 /// </summary>113 /// <exception cref="InvalidOperationException">Thrown when with the given settings no valid value in114 /// 100 tries could be found.115 /// </exception>116 /// <param name="data">The double object where to assign the new number to and whose constraints117 /// must be fulfilled.</param>118 /// <param name="normal">The continuous, normally distributed random variable.</param>119 public void RandomizeNormal(ConstrainedDoubleData data, NormalDistributedRandom normal) {120 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {121 double r = normal.NextDouble();122 if (IsIntegerConstrained(data)) {123 r = Math.Round(r);124 }125 if (data.TrySetData(r)) {126 return;127 }128 }129 throw new InvalidOperationException("Couldn't find a valid value in 100 tries with mu=" + normal.Mu + " sigma=" + normal.Sigma);130 }131 132 /// <summary>133 /// Generates a new int random variable based on a continuous, normally distributed random number134 /// generator <paramref name="normal"/> and checks some constraints.135 /// </summary>136 /// <exception cref="InvalidOperationException">Thrown when with the given settings no valid137 /// value could be found.</exception>138 /// <param name="data">The int object where to assign the new value to and whose constraints must139 /// be fulfilled.</param>140 /// <param name="normal">The continuous, normally distributed random variable.</param>141 public void RandomizeNormal(ConstrainedIntData data, NormalDistributedRandom normal) {142 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {143 double r = normal.NextDouble();144 if (data.TrySetData((int)Math.Round(r))) // since r is a continuous, normally distributed random variable rounding should be OK145 return;146 }147 throw new InvalidOperationException("Couldn't find a valid value");148 102 } 149 103 … … 167 121 data.Data = (int)Math.Round(normal.NextDouble()); 168 122 } 169 170 171 private bool IsIntegerConstrained(ConstrainedDoubleData data) {172 foreach (IConstraint constraint in data.Constraints) {173 if (constraint is IsIntegerConstraint) {174 return true;175 }176 }177 return false;178 }179 123 } 180 124 } -
trunk/sources/HeuristicLab.Random/3.3/UniformRandomAdder.cs
r1530 r2524 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Constraints;28 27 29 28 namespace HeuristicLab.Random { … … 91 90 if (value is IntData) 92 91 AddUniform((IntData)value, mt, min, max); 93 else if (value is ConstrainedIntData)94 AddUniform((ConstrainedIntData)value, mt, min, max);95 92 else if (value is DoubleData) 96 93 AddUniform((DoubleData)value, mt, min, max); 97 else if (value is ConstrainedDoubleData)98 AddUniform((ConstrainedDoubleData)value, mt, min, max);99 94 else throw new InvalidOperationException("Can't handle type " + value.GetType().Name); 100 }101 102 /// <summary>103 /// Adds a new double random variable being restricted to some constraints to the value of the given104 /// <paramref name="data"/>.105 /// </summary>106 /// <exception cref="InvalidProgramException">Thrown when no valid value can be found.</exception>107 /// <param name="data">The data where to add the new variable and where to assign the new value to.</param>108 /// <param name="mt">The random number generator.</param>109 /// <param name="min">The left border of the interval in which the next random number has to lie.</param>110 /// <param name="max">The right border (exclusive) of the interval in which the next random number111 /// has to lie.</param>112 public void AddUniform(ConstrainedDoubleData data, MersenneTwister mt, double min, double max) {113 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {114 double newValue = data.Data + mt.NextDouble() * (max - min) + min;115 if (IsIntegerConstrained(data)) {116 newValue = Math.Floor(newValue);117 }118 if (data.TrySetData(newValue)) {119 return;120 }121 }122 throw new InvalidProgramException("Couldn't find a valid value");123 }124 125 /// <summary>126 /// Adds a new int random variable being restricted to some constraints to the value of the given127 /// <paramref name="data"/>.128 /// </summary>129 /// <exception cref="InvalidProgramException">Thrown when no valid value could be found.</exception>130 /// <param name="data">The data where to add the random value and where to assign the new value to.</param>131 /// <param name="mt">The random number generator.</param>132 /// <param name="min">The left border of the interval in which the next random number has to lie.</param>133 /// <param name="max">The right border (exclusive) of the interval in which the next random number134 /// has to lie.</param>135 public void AddUniform(ConstrainedIntData data, MersenneTwister mt, double min, double max) {136 for (int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {137 int newValue = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min);138 if (data.TrySetData(newValue)) {139 return;140 }141 }142 throw new InvalidProgramException("Couldn't find a valid value");143 95 } 144 96 … … 168 120 data.Data = (int)Math.Floor(data.Data + mt.NextDouble() * (max - min) + min); 169 121 } 170 private bool IsIntegerConstrained(ConstrainedDoubleData data) {171 foreach (IConstraint constraint in data.Constraints) {172 if (constraint is IsIntegerConstraint) {173 return true;174 }175 }176 return false;177 }178 122 } 179 123 } -
trunk/sources/HeuristicLab.Random/3.3/UniformRandomizer.cs
r1853 r2524 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Constraints;28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 … … 105 104 if (value is DoubleData) 106 105 RandomizeUniform((DoubleData)value, mt, min, max); 107 else if (value is ConstrainedDoubleData)108 RandomizeUniform((ConstrainedDoubleData)value, mt, min, max);109 106 else if (value is IntData) 110 107 RandomizeUniform((IntData)value, mt, min, max); 111 else if (value is ConstrainedIntData)112 RandomizeUniform((ConstrainedIntData)value, mt, min, max);113 108 else throw new ArgumentException("Can't handle type " + value.GetType().Name); 114 109 } … … 137 132 data.Data = (int)Math.Floor(mt.NextDouble() * (max - min) + min); 138 133 } 139 140 /// <summary>141 /// Generates a new double random number, being restricted to some constraints.142 /// </summary>143 /// <exception cref="InvalidOperationException">Thrown when no valid value could be found.</exception>144 /// <param name="data">The double object which the new value is assigned to and whose constraints145 /// must be fulfilled.</param>146 /// <param name="mt">The random number generator.</param>147 /// <param name="min">The left border of the interval in which the next random number has to lie.</param>148 /// <param name="max">The right border (exclusive) of the interval in which the next random number149 /// has to lie.</param>150 public void RandomizeUniform(ConstrainedDoubleData data, MersenneTwister mt, double min, double max) {151 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {152 double r = mt.NextDouble() * (max - min) + min;153 if(IsIntegerConstrained(data)) {154 r = Math.Floor(r);155 }156 if(data.TrySetData(r)) {157 return;158 }159 }160 throw new InvalidOperationException("Couldn't find a valid value");161 }162 /// <summary>163 /// Generates a new int random number, being restricted to some constraints.164 /// </summary>165 /// <exception cref="InvalidOperationException">Thrown when no valid value could be found.</exception>166 /// <param name="data">The int object which the new value is assigned to and whose constraints167 /// must be fulfilled.</param>168 /// <param name="mt">The random number generator.</param>169 /// <param name="min">The left border of the interval in which the next random number has to lie.</param>170 /// <param name="max">The right border (exclusive) of the interval in which the next random number171 /// has to lie.</param>172 public void RandomizeUniform(ConstrainedIntData data, MersenneTwister mt, double min, double max) {173 for(int tries = MAX_NUMBER_OF_TRIES; tries >= 0; tries--) {174 int r = (int)Math.Floor(mt.NextDouble() * (max - min) + min);175 if(data.TrySetData(r)) {176 return;177 }178 }179 throw new InvalidOperationException("Couldn't find a valid value");180 }181 182 private bool IsIntegerConstrained(ConstrainedDoubleData data) {183 foreach(IConstraint constraint in data.Constraints) {184 if(constraint is IsIntegerConstraint) {185 return true;186 }187 }188 return false;189 }190 134 } 191 135 } -
trunk/sources/HeuristicLab.SGA/3.3/HeuristicLab.SGA-3.3.csproj
r2520 r2524 99 99 <Name>HeuristicLab.Common-3.2</Name> 100 100 </ProjectReference> 101 <ProjectReference Include="..\..\HeuristicLab.Constraints\3.3\HeuristicLab.Constraints-3.3.csproj">102 <Project>{19C1E42A-4B48-4EFD-B697-899016F1C198}</Project>103 <Name>HeuristicLab.Constraints-3.3</Name>104 </ProjectReference>105 101 <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj"> 106 102 <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project>
Note: See TracChangeset
for help on using the changeset viewer.