Changeset 6878 for branches/GeneralizedQAP/HeuristicLab.Optimization/3.3
- Timestamp:
- 10/05/11 21:55:55 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 4 deleted
- 9 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP
- Property svn:ignore
-
old new 1 *.docstates 2 *.psess 1 3 *.resharper 2 4 *.suo 5 *.vsp 3 6 Google.ProtocolBuffers-0.9.1.dll 7 HeuristicLab 3.3.5.1.ReSharper.user 8 HeuristicLab 3.3.6.0.ReSharper.user 4 9 HeuristicLab.4.5.resharper.user 5 10 HeuristicLab.resharper.user … … 8 13 _ReSharper.HeuristicLab 9 14 _ReSharper.HeuristicLab 3.3 15 _ReSharper.HeuristicLab.ExtLibs 16 bin 10 17 protoc.exe 11 HeuristicLab 3.3.5.1.ReSharper.user 12 *.psess 13 *.vsp 14 *.docstates 18 HeuristicLab.ExtLibs.6.0.ReSharper.user
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3
- Property svn:ignore
-
old new 4 4 *.user 5 5 *.vs10x 6 Plugin.cs
-
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/BatchRun.cs
r6534 r6878 147 147 } 148 148 149 private bool stopPending; 149 private bool batchRunStarted = false; 150 private bool batchRunPaused = false; 151 private bool batchRunStopped = false; 150 152 151 153 public BatchRun() … … 158 160 repetitionsCounter = 0; 159 161 Runs = new RunCollection(); 160 stopPending = false;161 162 } 162 163 public BatchRun(string name) … … 168 169 repetitionsCounter = 0; 169 170 Runs = new RunCollection(); 170 stopPending = false;171 171 } 172 172 public BatchRun(string name, string description) … … 177 177 repetitionsCounter = 0; 178 178 Runs = new RunCollection(); 179 stopPending = false;180 179 } 181 180 [StorableConstructor] 182 private BatchRun(bool deserializing) 183 : base(deserializing) { 184 stopPending = false; 185 } 181 private BatchRun(bool deserializing) : base(deserializing) { } 186 182 [StorableHook(HookType.AfterDeserialization)] 187 183 private void AfterDeserialization() { … … 197 193 repetitionsCounter = original.repetitionsCounter; 198 194 runs = cloner.Clone(original.runs); 199 stopPending = original.stopPending; 195 batchRunStarted = original.batchRunStarted; 196 batchRunPaused = original.batchRunPaused; 197 batchRunStopped = original.batchRunStopped; 200 198 Initialize(); 201 199 } … … 227 225 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 228 226 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 229 if (Optimizer != null) Optimizer.Start(); 227 if (Optimizer == null) return; 228 229 batchRunStarted = true; 230 batchRunPaused = false; 231 batchRunStopped = false; 232 if (Optimizer.ExecutionState == ExecutionState.Stopped) Optimizer.Prepare(); 233 Optimizer.Start(); 230 234 } 231 235 public void Pause() { 232 236 if (ExecutionState != ExecutionState.Started) 233 237 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 234 if ((Optimizer != null) && (Optimizer.ExecutionState == ExecutionState.Started)) 235 Optimizer.Pause(); 238 if (Optimizer == null) return; 239 if (Optimizer.ExecutionState != ExecutionState.Started) return; 240 241 batchRunStarted = false; 242 batchRunPaused = true; 243 batchRunStopped = false; 244 Optimizer.Pause(); 236 245 } 237 246 public void Stop() { 238 247 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 239 248 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); 240 stopPending = true; 241 if ((Optimizer != null) && 242 ((Optimizer.ExecutionState == ExecutionState.Started) || (Optimizer.ExecutionState == ExecutionState.Paused))) 243 Optimizer.Stop(); 249 if (Optimizer == null) return; 250 if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused) return; 251 batchRunStarted = false; 252 batchRunPaused = false; 253 batchRunStopped = true; 254 Optimizer.Stop(); 244 255 } 245 256 … … 324 335 } 325 336 private void Optimizer_Paused(object sender, EventArgs e) { 326 OnPaused(); 337 if (ExecutionState == ExecutionState.Started) { 338 batchRunStarted = false; 339 batchRunPaused = true; 340 batchRunStopped = false; 341 OnPaused(); 342 } 327 343 } 328 344 private void Optimizer_Prepared(object sender, EventArgs e) { 329 if ( (ExecutionState == ExecutionState.Paused) || (ExecutionState == ExecutionState.Stopped))345 if (ExecutionState == ExecutionState.Stopped || !batchRunStarted) { 330 346 OnPrepared(); 347 } 331 348 } 332 349 private void Optimizer_Started(object sender, EventArgs e) { 333 stopPending = false;334 350 if (ExecutionState != ExecutionState.Started) 335 351 OnStarted(); … … 338 354 repetitionsCounter++; 339 355 340 if (!stopPending && (repetitionsCounter < repetitions)) { 356 if (batchRunStopped) OnStopped(); 357 else if (repetitionsCounter >= repetitions) OnStopped(); 358 else if (batchRunPaused) OnPaused(); 359 else if (batchRunStarted) { 341 360 Optimizer.Prepare(); 342 361 Optimizer.Start(); 343 } else { 344 OnStopped(); 345 } 362 } else OnStopped(); 346 363 } 347 364 private void Optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { -
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/Calculator.cs
r6685 r6878 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Globalization;25 24 using System.Linq; 26 25 using System.Text.RegularExpressions; … … 29 28 using HeuristicLab.Data; 30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using System.Globalization; 31 31 32 32 namespace HeuristicLab.Optimization { … … 45 45 } 46 46 47 private static readonly Regex TokenRegex = new Regex(@"[a-zA-Z0-9._]+|""([^""]|\"")+""|[-+*/^]|log"); 47 private static readonly Regex TokenRegex = 48 new Regex(@"[a-zA-Z0-9._]+|""([^""]|\\"")*""|'([^']|\\')*'|[-+*/<>^]|dup|swap|drop|log|true|false|if|==|not|isnull|null|ismatch|rename"); 48 49 49 50 #endregion … … 54 55 protected Calculator(bool deserializing) { } 55 56 public Calculator() { } 56 p ublicCalculator(Calculator original, Cloner cloner) {57 if (original.tokens != null)58 this.tokens = original.tokens.ToList();57 protected Calculator(Calculator original, Cloner cloner) { 58 cloner.RegisterClonedObject(original, this); 59 tokens = original.tokens.ToList(); 59 60 } 60 61 public IDeepCloneable Clone(Cloner cloner) { … … 66 67 #endregion 67 68 68 p ublic IEnumerable<string> Tokenize(string s) {69 private static IEnumerable<string> Tokenize(string s) { 69 70 return TokenRegex.Matches(s).Cast<Match>().Select(m => m.Value); 70 71 } 71 72 72 private double GetVariableValue(IDictionary<string, IItem> variables, string name) {73 if (variables.ContainsKey(name)) {74 var item = variables[name];75 var intValue = item as IntValue;76 if (intValue != null) {77 return intValue.Value;78 } else {79 var doubleValue = item as DoubleValue;80 if (doubleValue != null)81 return doubleValue.Value;82 else83 throw new InvalidOperationException("Non numerical argument");84 }85 } else {86 throw new InvalidOperationException(string.Format("variable \"{0}\" not found", name));87 }88 }89 90 73 public IItem GetValue(IDictionary<string, IItem> variables) { 91 var stack = new Stack<double>(); 92 Action<Func<double, double, double>> binf = op => { 93 var b = stack.Pop(); 94 stack.Push(op(stack.Pop(), b)); 95 }; 96 try { 97 foreach (var token in tokens) { 74 var stack = new Stack<object>(); 75 int i = 0; 76 try { 77 for (; i<tokens.Count; i++) { 78 var token = tokens[i]; 98 79 double d; 99 if (double.TryParse(token, 100 NumberStyles.AllowDecimalPoint | 101 NumberStyles.AllowExponent | 102 NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out d)) { 80 if (TryParse(token, out d)) { 103 81 stack.Push(d); 104 82 } else if (token.StartsWith("\"")) { 105 83 stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace(@"\""", @""""))); 84 } else if (token.StartsWith("'")) { 85 stack.Push(token.Substring(1, token.Length-2).Replace("\'", "'")); 106 86 } else { 107 switch (token) { 108 case "log": stack.Push(Math.Log(stack.Pop())); break; 109 case "+": binf((x, y) => x + y); break; 110 case "-": binf((x, y) => x - y); break; 111 case "*": binf((x, y) => x * y); break; 112 case "/": binf((x, y) => x / y); break; 113 case "^": binf(Math.Pow); break; 114 default: stack.Push(GetVariableValue(variables, token)); break; 115 } 87 Apply(token, stack, variables); 116 88 } 117 89 } 118 } catch (InvalidOperationException x) { 119 return new StringValue(string.Format("Calculation Failed: {0}", x.Message)); 120 } 121 if (stack.Count != 1) 122 return new StringValue("Invalid final evaluation stack size != 1"); 123 return new DoubleValue(stack.Pop()); 124 } 90 } catch (Exception x) { 91 throw new Exception(string.Format( 92 "Calculation Failed at token #{1}: '{2}' {0}current stack is: {0}{3}", Environment.NewLine, 93 i, tokens[i], string.Join(Environment.NewLine, stack.Select(AsString))), 94 x); 95 } 96 if (stack.Count != 1) throw new Exception(string.Format("Invalid final evaluation stack size {0} (should be 1)", stack.Count)); 97 var result = stack.Pop(); 98 if (result is string) return new StringValue((string)result); 99 if (result is double) return new DoubleValue((double)result); 100 if (result is bool) return new BoolValue((bool)result); 101 return null; 102 } 103 104 private static void Apply(string token, Stack<object> stack, IDictionary<string, IItem> variables) { 105 switch (token) { 106 case "null": stack.Push(null); break; 107 case "true": stack.Push(true); break; 108 case "false": stack.Push(false); break; 109 110 case "drop": stack.Pop(); break; 111 case "dup": stack.Push(stack.Peek()); break; 112 case "swap": 113 var top = stack.Pop(); 114 var next = stack.Pop(); 115 stack.Push(top); 116 stack.Push(next); 117 break; 118 119 case "log": Apply(stack, x => Math.Log((double)x)); break; 120 case "+": Apply(stack, (x, y) => (double)x + (double)y); break; 121 case "-": Apply(stack, (x, y) => (double)x - (double)y); break; 122 case "*": Apply(stack, (x, y) => (double)x * (double)y); break; 123 case "/": Apply(stack, (x, y) => (double)x / (double)y); break; 124 case "^": Apply(stack, (x, y) => Math.Pow((double)x, (double)y)); break; 125 case "<": Apply(stack, (x, y) => (double)x < (double)y); break; 126 case ">": Apply(stack, (x, y) => (double)x > (double)y); break; 127 128 case "==": Apply(stack, (x, y) => Equal(x, y)); break; 129 case "not": Apply(stack, x => !(bool)x); break; 130 case "isnull": Apply(stack, x => x == null); break; 131 case "if": Apply(stack, (then, else_, cond) => (bool)cond ? then : else_); break; 132 133 case "ismatch": Apply(stack, (s, p) => new Regex((string)p).IsMatch((string)s)); break; 134 case "rename": Apply(stack, (s, p, r) => new Regex((string)p).Replace((string)s, (string)r)); break; 135 136 default: stack.Push(GetVariableValue(variables, token)); break; 137 } 138 } 139 140 #region Auxiliary Functions 141 142 #region IItem value conversion 143 private static object GetIntValue(IItem value) { 144 var v = value as IntValue; 145 if (v != null) return (double)v.Value; 146 return null; 147 } 148 149 private static object GetDoubleValue(IItem value) { 150 var v = value as DoubleValue; 151 if (v != null) return v.Value; 152 return null; 153 } 154 155 private static object GetBoolValue(IItem value) { 156 var v = value as BoolValue; 157 if (v != null) return v.Value; 158 return null; 159 } 160 161 private static object GetVariableValue(IDictionary<string, IItem> variables, string name) { 162 if (variables.ContainsKey(name)) { 163 var item = variables[name]; 164 return 165 GetIntValue(item) ?? 166 GetDoubleValue(item) ?? 167 GetBoolValue(item) ?? 168 item.ToString(); 169 } 170 return null; 171 } 172 #endregion 173 174 #region variadic equality 175 private static bool Equal(object a, object b) { return EqualNumber(a, b) || EqualBool(a, b) || EqualString(a, b) || a == b; } 176 private static bool EqualNumber(object a, object b) { return a is double && b is double && (double)a == (double)b; } 177 private static bool EqualBool(object a, object b) { return a is bool && b is bool && (bool)a == (bool)b; } 178 private static bool EqualString(object a, object b) { return a is string && b is string && ((string)a).Equals((string)b); } 179 #endregion 180 181 #region stack calculation 182 private static void Apply(Stack<object> stack, Func<object, object> func) { 183 if (stack.Count < 1) 184 throw new InvalidOperationException("Stack is empty"); 185 var a = stack.Pop(); 186 try { 187 stack.Push(func(a)); 188 } catch (Exception) { 189 stack.Push(a); 190 throw; 191 } 192 } 193 194 private static void Apply(Stack<object> stack, Func<object, object, object> func) { 195 if (stack.Count < 2) 196 throw new InvalidOperationException("Stack contains less than two elements"); 197 var b = stack.Pop(); 198 var a = stack.Pop(); 199 try { 200 stack.Push(func(a, b)); 201 } catch (Exception) { 202 stack.Push(b); 203 stack.Push(a); 204 throw; 205 } 206 } 207 208 private static void Apply(Stack<object> stack, Func<object, object, object, object> func) { 209 if (stack.Count < 3) 210 throw new InvalidOperationException("Stack contains less than three elements"); 211 var c = stack.Pop(); 212 var b = stack.Pop(); 213 var a = stack.Pop(); 214 try { 215 stack.Push(func(a, b, c)); 216 } catch (Exception) { 217 stack.Push(a); 218 stack.Push(b); 219 stack.Push(c); 220 throw; 221 } 222 } 223 #endregion 224 225 private static bool TryParse(string token, out double d) { 226 return double.TryParse(token, 227 NumberStyles.AllowDecimalPoint | 228 NumberStyles.AllowExponent | 229 NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out d); 230 } 231 232 private static string AsString(object o) { 233 if (o == null) return "null"; 234 if (o is string) return string.Format("'{0}'", o); 235 return o.ToString(); 236 } 237 238 #endregion 125 239 } 126 240 } -
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/Experiment.cs
r6534 r6878 104 104 } 105 105 106 private bool stopPending; 106 private bool experimentStarted = false; 107 private bool experimentStopped = false; 107 108 108 109 public Experiment() … … 114 115 optimizers = new OptimizerList(); 115 116 Runs = new RunCollection(); 116 stopPending = false;117 117 Initialize(); 118 118 } … … 124 124 optimizers = new OptimizerList(); 125 125 Runs = new RunCollection(); 126 stopPending = false;127 126 Initialize(); 128 127 } … … 133 132 optimizers = new OptimizerList(); 134 133 Runs = new RunCollection(); 135 stopPending = false;136 134 Initialize(); 137 135 } 138 136 [StorableConstructor] 139 private Experiment(bool deserializing) 140 : base(deserializing) { 141 stopPending = false; 142 } 137 private Experiment(bool deserializing) : base(deserializing) { } 143 138 [StorableHook(HookType.AfterDeserialization)] 144 139 private void AfterDeserialization() { … … 151 146 optimizers = cloner.Clone(original.optimizers); 152 147 runs = cloner.Clone(original.runs); 153 stopPending = original.stopPending; 148 149 experimentStarted = original.experimentStarted; 150 experimentStopped = original.experimentStopped; 154 151 Initialize(); 155 152 } … … 172 169 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 173 170 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 174 if (Optimizers.Count > 0) { 175 if (clearRuns) runs.Clear(); 176 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) 171 if (Optimizers.Count == 0) return; 172 173 if (clearRuns) runs.Clear(); 174 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) 175 if (clearRuns || optimizer.ExecutionState != ExecutionState.Prepared) 177 176 optimizer.Prepare(clearRuns); 178 }179 177 } 180 178 public void Start() { 181 179 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 182 180 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 183 stopPending = false; 184 if (Optimizers.Count > 0) { 185 IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)); 186 if (optimizer != null) optimizer.Start(); 187 } 181 if (Optimizers.Count == 0) return; 182 183 experimentStarted = true; 184 experimentStopped = false; 185 IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)); 186 if (optimizer != null) optimizer.Start(); 188 187 } 189 188 public void Pause() { 190 189 if (ExecutionState != ExecutionState.Started) 191 190 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 192 if (Optimizers.Count > 0) { 193 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) 194 optimizer.Pause(); 195 } 191 if (Optimizers.Count == 0) return; 192 193 experimentStarted = false; 194 experimentStopped = false; 195 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) 196 optimizer.Pause(); 196 197 } 197 198 public void Stop() { 198 199 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 199 200 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); 200 stopPending = true; 201 if (Optimizers.Count > 0) { 202 foreach (IOptimizer optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) 203 optimizer.Stop(); 204 } 201 if (Optimizers.Count == 0) return; 202 203 experimentStarted = false; 204 experimentStopped = true; 205 foreach (IOptimizer optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) 206 optimizer.Stop(); 205 207 } 206 208 … … 333 335 } 334 336 private void optimizer_Stopped(object sender, EventArgs e) { 335 if (!stopPending && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) { 337 if (experimentStopped && Optimizers.All(o => o.ExecutionState == ExecutionState.Stopped || o.ExecutionState == ExecutionState.Prepared)) OnStopped(); 338 else if (Optimizers.All(o => o.ExecutionState == ExecutionState.Stopped)) OnStopped(); 339 else if (Optimizers.Any(o => o.ExecutionState == ExecutionState.Paused) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused(); 340 else if (experimentStarted && !experimentStopped && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) { 336 341 Optimizers.First(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)).Start(); 337 } else {338 if (Optimizers.All(x => (x.ExecutionState != ExecutionState.Started) && (x.ExecutionState != ExecutionState.Paused))) {339 stopPending = false;340 OnStopped();341 }342 342 } 343 343 } -
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r6685 r6878 41 41 <DebugType>full</DebugType> 42 42 <Optimize>false</Optimize> 43 <OutputPath> bin\Debug\</OutputPath>43 <OutputPath>$(SolutionDir)\bin\</OutputPath> 44 44 <DefineConstants>DEBUG;TRACE</DefineConstants> 45 45 <ErrorReport>prompt</ErrorReport> … … 50 50 <DebugType>pdbonly</DebugType> 51 51 <Optimize>true</Optimize> 52 <OutputPath> bin\Release\</OutputPath>52 <OutputPath>$(SolutionDir)\bin\</OutputPath> 53 53 <DefineConstants>TRACE</DefineConstants> 54 54 <ErrorReport>prompt</ErrorReport> 55 55 <WarningLevel>4</WarningLevel> 56 <DocumentationFile>bin\Release\HeuristicLab.Optimization-3.3.XML</DocumentationFile> 56 <DocumentationFile> 57 </DocumentationFile> 57 58 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 58 59 </PropertyGroup> 59 60 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> 60 61 <DebugSymbols>true</DebugSymbols> 61 <OutputPath> bin\x86\Debug\</OutputPath>62 <OutputPath>$(SolutionDir)\bin\</OutputPath> 62 63 <DefineConstants>DEBUG;TRACE</DefineConstants> 63 64 <DebugType>full</DebugType> … … 67 68 </PropertyGroup> 68 69 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 69 <OutputPath> bin\x86\Release\</OutputPath>70 <OutputPath>$(SolutionDir)\bin\</OutputPath> 70 71 <DefineConstants>TRACE</DefineConstants> 71 <DocumentationFile>bin\x86\Release\HeuristicLab.Optimization-3.3.XML</DocumentationFile> 72 <DocumentationFile> 73 </DocumentationFile> 72 74 <Optimize>true</Optimize> 73 75 <DebugType>pdbonly</DebugType> … … 78 80 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> 79 81 <DebugSymbols>true</DebugSymbols> 80 <OutputPath> bin\x64\Debug\</OutputPath>82 <OutputPath>$(SolutionDir)\bin\</OutputPath> 81 83 <DefineConstants>DEBUG;TRACE</DefineConstants> 82 84 <DebugType>full</DebugType> … … 86 88 </PropertyGroup> 87 89 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 88 <OutputPath> bin\x64\Release\</OutputPath>90 <OutputPath>$(SolutionDir)\bin\</OutputPath> 89 91 <DefineConstants>TRACE</DefineConstants> 90 <DocumentationFile>bin\x64\Release\HeuristicLab.Optimization-3.3.XML</DocumentationFile> 92 <DocumentationFile> 93 </DocumentationFile> 91 94 <Optimize>true</Optimize> 92 95 <DebugType>pdbonly</DebugType> … … 111 114 </ItemGroup> 112 115 <ItemGroup> 116 <Compile Include="Plugin.cs" /> 117 <Compile Include="RunCollectionDiscretizer.cs" /> 118 <Compile Include="RunCollectionGroupCreater.cs" /> 113 119 <Compile Include="RunCollectionSorter.cs" /> 114 120 <Compile Include="RunCollectionValueRemover.cs" /> 115 121 <Compile Include="IRunCollectionModifier.cs" /> 116 <None Include=" HeuristicLabOptimizationPlugin.cs.frame" />122 <None Include="Plugin.cs.frame" /> 117 123 <Compile Include="Algorithms\Algorithm.cs" /> 118 124 <Compile Include="BatchRun.cs" /> … … 141 147 <Compile Include="Problems\Problem.cs" /> 142 148 <Compile Include="RunCollectionFormulaModifer.cs" /> 143 <Compile Include="RunCollectionFuzzifier.cs" />144 <Compile Include="RunCollectionModificationEvaluator.cs" />145 149 <Compile Include="RunCollectionConstraints\RunCollectionComparisonConstraint.cs" /> 146 150 <Compile Include="RunCollectionConstraints\RunCollectionConstraintCollection.cs" /> … … 192 196 <Compile Include="Algorithms\UserDefinedAlgorithm.cs" /> 193 197 <Compile Include="Algorithms\EngineAlgorithm.cs" /> 194 <Compile Include="HeuristicLabOptimizationPlugin.cs" />195 198 <Compile Include="Properties\AssemblyInfo.cs" /> 196 199 <Compile Include="ResultCollection.cs" /> … … 199 202 <ItemGroup> 200 203 <None Include="HeuristicLab.snk" /> 201 <None Include="Properties\AssemblyInfo. frame" />204 <None Include="Properties\AssemblyInfo.cs.frame" /> 202 205 </ItemGroup> 203 206 <ItemGroup> … … 205 208 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> 206 209 <Name>HeuristicLab.Collections-3.3</Name> 210 <Private>False</Private> 207 211 </ProjectReference> 208 212 <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj"> 209 213 <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project> 210 214 <Name>HeuristicLab.Common.Resources-3.3</Name> 215 <Private>False</Private> 211 216 </ProjectReference> 212 217 <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj"> 213 218 <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project> 214 219 <Name>HeuristicLab.Common-3.3</Name> 220 <Private>False</Private> 215 221 </ProjectReference> 216 222 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 217 223 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> 218 224 <Name>HeuristicLab.Core-3.3</Name> 225 <Private>False</Private> 219 226 </ProjectReference> 220 227 <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj"> 221 228 <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project> 222 229 <Name>HeuristicLab.Data-3.3</Name> 230 <Private>False</Private> 223 231 </ProjectReference> 224 232 <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj"> 225 233 <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project> 226 234 <Name>HeuristicLab.Parameters-3.3</Name> 235 <Private>False</Private> 227 236 </ProjectReference> 228 237 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj"> 229 238 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project> 230 239 <Name>HeuristicLab.Persistence-3.3</Name> 240 <Private>False</Private> 231 241 </ProjectReference> 232 242 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 233 243 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> 234 244 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 245 <Private>False</Private> 235 246 </ProjectReference> 236 247 </ItemGroup> … … 268 279 269 280 call PreBuildEvent.cmd 270 SubWCRev "%25ProjectDir%25\" "%25ProjectDir%25\HeuristicLabOptimizationPlugin.cs.frame" "%25ProjectDir%25\HeuristicLabOptimizationPlugin.cs"</PreBuildEvent>281 </PreBuildEvent> 271 282 </PropertyGroup> 272 283 </Project> -
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs
- Property svn:mergeinfo changed
-
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/RunCollection.cs
r5445 r6878 51 51 52 52 constraints = new RunCollectionConstraintCollection(original.constraints.Select(x => cloner.Clone(x))); 53 modifiers = new CheckedItemList<IRunCollectionModifier>(original.modifiers.Select(cloner.Clone)); 53 54 foreach (IRunCollectionConstraint constraint in constraints) 54 55 constraint.ConstrainedValue = this; … … 67 68 dataTypes = new Dictionary<string, HashSet<Type>>(); 68 69 constraints = new RunCollectionConstraintCollection(); 70 modifiers = new CheckedItemList<IRunCollectionModifier>(); 69 71 RegisterConstraintsEvents(); 70 72 } … … 83 85 get { return constraints; } 84 86 } 87 88 [Storable] 89 private CheckedItemList<IRunCollectionModifier> modifiers; 90 public CheckedItemList<IRunCollectionModifier> Modifiers { 91 get { return modifiers; } 92 } 93 85 94 86 95 private bool updateOfRunsInProgress; … … 98 107 private void AfterDeserialization() { 99 108 if (constraints == null) constraints = new RunCollectionConstraintCollection(); 109 if (modifiers == null) modifiers = new CheckedItemList<IRunCollectionModifier>(); 100 110 RegisterConstraintsEvents(); 101 111 RegisterConstraintEvents(constraints); … … 393 403 } 394 404 #endregion 405 406 #region Modification 407 public void Modify() { 408 UpdateOfRunsInProgress = true; 409 var runs = this.ToList(); 410 var selectedRuns = runs.Where(r => r.Visible).ToList(); 411 int nSelected = selectedRuns.Count; 412 if (nSelected > 0) { 413 foreach (var modifier in Modifiers.CheckedItems) 414 modifier.Value.Modify(selectedRuns); 415 if (nSelected != selectedRuns.Count || HaveDifferentOrder(selectedRuns, runs.Where(r => r.Visible))) { 416 Clear(); 417 AddRange(ReplaceVisibleRuns(runs, selectedRuns)); 418 } else if (runs.Count > 0) { 419 OnCollectionReset(this, runs); 420 } 421 } 422 UpdateOfRunsInProgress = false; 423 } 424 425 private static IEnumerable<IRun> ReplaceVisibleRuns(IEnumerable<IRun> runs, IEnumerable<IRun> visibleRuns) { 426 var newRuns = new List<IRun>(); 427 var runIt = runs.GetEnumerator(); 428 var visibleRunIt = visibleRuns.GetEnumerator(); 429 while (runIt.MoveNext()) { 430 if (runIt.Current != null && !runIt.Current.Visible) 431 newRuns.Add(runIt.Current); 432 else if (visibleRunIt.MoveNext()) 433 newRuns.Add(visibleRunIt.Current); 434 } 435 while (visibleRunIt.MoveNext()) 436 newRuns.Add(visibleRunIt.Current); 437 return newRuns; 438 } 439 440 private static bool HaveDifferentOrder(IEnumerable<IRun> l1, IEnumerable<IRun> l2) { 441 return l1.Zip(l2, (r1, r2) => r1 != r2).Any(); 442 } 443 #endregion 395 444 } 396 445 } -
branches/GeneralizedQAP/HeuristicLab.Optimization/3.3/RunCollectionFormulaModifer.cs
r6685 r6878 20 20 public ValueParameter<StringValue> ResultNameParameter { 21 21 get { return (ValueParameter<StringValue>)Parameters["ResultName"]; } 22 } 23 22 } 23 24 24 public ValueParameter<StringValue> FormulaParameter { 25 25 get { return (ValueParameter<StringValue>)Parameters["Formula"]; } 26 } 26 } 27 27 28 #region Construction & Cloning 28 private string ResultName { get { return ResultNameParameter.Value.Value; } } 29 private string Formula { get { return FormulaParameter.Value.Value; } } 30 31 #region Construction & Cloning 29 32 [StorableConstructor] 30 33 protected RunCollectionFormulaModifer(bool deserializing) : base(deserializing) { } … … 35 38 public RunCollectionFormulaModifer() { 36 39 Parameters.Add(new ValueParameter<StringValue>("ResultName", "The name of the result to be generated by this formula.", new StringValue("Calc.Value"))); 37 Parameters.Add(new ValueParameter<StringValue>("Formula", "RPN formula for new value. This can contain existing run parameters or results (optionally in quotes if they contain whitespace), numbers and arithmetic operators in postfix notation.", new StringValue("1 1 +"))); 40 Parameters.Add(new ValueParameter<StringValue>("Formula", 41 @"RPN formula for new value in postfix notation. 42 43 This can contain the following elements: 44 45 literals: 46 numbers, true, false, null and strings in single quotes 47 variables (run parameters or results): 48 unquoted or in double quotes if they contain special characters or whitespace 49 mathematical functions: 50 +, -, /, ^ (power), log 51 predicates: 52 ==, <, >, isnull, not 53 stack manipulation: 54 drop swap dup 55 string matching: 56 <string> <pattern> ismatch 57 string replacing: 58 <string> <pattern> <replacement> rename 59 conditionals: 60 <then> <else> <condition> if 61 62 If the final value is null, the result variable is removed if it exists.", 63 new StringValue("1 1 +"))); 38 64 UpdateName(); 39 65 RegisterEvents(); … … 58 84 59 85 private void UpdateName() { 60 name = string.Format("{0} := {1}", ResultName Parameter.Value.Value, FormulaParameter.Value.Value);86 name = string.Format("{0} := {1}", ResultName, Formula); 61 87 OnNameChanged(); 62 88 } 63 89 64 90 public void Modify(List<IRun> runs) { 65 var calc = new Calculator { Formula = FormulaParameter.Value.Value};91 var calc = new Calculator { Formula = Formula }; 66 92 foreach (var run in runs) { 67 93 var variables = new Dictionary<string, IItem>(); … … 70 96 foreach (var result in run.Results) 71 97 variables[result.Key] = result.Value; 72 run.Results[ResultNameParameter.Value.Value] = calc.GetValue(variables); 73 } 98 var value = calc.GetValue(variables); 99 if (value != null) 100 run.Results[ResultName] = value; 101 else 102 run.Results.Remove(ResultName); 103 } 74 104 } 75 105 76 106 } 77 107 }
Note: See TracChangeset
for help on using the changeset viewer.