Changeset 12969 for branches/gteufl/HeuristicLab.Optimization/3.3/RunCollectionModification/Calculator.cs
- Timestamp:
- 09/25/15 14:39:59 (9 years ago)
- Location:
- branches/gteufl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gteufl
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 25 obj
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/gteufl/HeuristicLab.Optimization
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HLScript/HeuristicLab.Optimization merged eligible /branches/HiveStatistics/sources/HeuristicLab.Optimization merged eligible /stable/HeuristicLab.Optimization merged eligible /trunk/sources/HeuristicLab.Optimization merged eligible /branches/1721-RandomForestPersistence/HeuristicLab.Optimization 10321-10322 /branches/Algorithms.GradientDescent/HeuristicLab.Optimization 5516-5520 /branches/Benchmarking/sources/HeuristicLab.Optimization 6917-7005 /branches/Classification-Extensions/HeuristicLab.Optimization 11687-11761 /branches/CloningRefactoring/HeuristicLab.Optimization 4656-4721 /branches/CodeEditor/HeuristicLab.Optimization 11700-11806 /branches/DataAnalysis Refactoring/HeuristicLab.Optimization 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Optimization 5815-6180 /branches/DataAnalysis/HeuristicLab.Optimization 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Optimization 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Optimization 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Optimization 5060 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Optimization 11570-12508 /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Optimization 6123-9799 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Optimization 11130-12721 /branches/LogResidualEvaluator/HeuristicLab.Optimization 10202-10483 /branches/NET40/sources/HeuristicLab.Optimization 5138-5162 /branches/NSGA-II Changes/HeuristicLab.Optimization 12033-12122 /branches/ParallelEngine/HeuristicLab.Optimization 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Optimization 7568-7810 /branches/ProgrammableProblem/HeuristicLab.Optimization 11573-11959 /branches/QAPAlgorithms/HeuristicLab.Optimization 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Optimization 6828 /branches/RuntimeOptimizer/HeuristicLab.Optimization 8943-9078 /branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization 7787-8333 /branches/SlaveShutdown/HeuristicLab.Optimization 8944-8956 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Optimization 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Optimization 5370-5682 /branches/TimeLimitRunOptimizer/HeuristicLab.Optimization 9438-12626 /branches/Trunk/HeuristicLab.Optimization 6829-6865 /branches/UnloadJobs/HeuristicLab.Optimization 9168-9215 /branches/VNS/HeuristicLab.Optimization 5594-5752 /branches/histogram/HeuristicLab.Optimization 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/gteufl/HeuristicLab.Optimization/3.3/RunCollectionModification/Calculator.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 90 90 } 91 91 } 92 } 93 catch (Exception x) { 92 } catch (Exception x) { 94 93 throw new Exception(string.Format( 95 94 "Calculation of '{1}'{0}failed at token #{2}: {3} {0}current stack is: {0}{4}", Environment.NewLine, … … 104 103 var result = stack.Pop(); 105 104 if (result is string) return new StringValue((string)result); 105 if (result is int) return new IntValue((int)result); 106 106 if (result is double) return new DoubleValue((double)result); 107 107 if (result is bool) return new BoolValue((bool)result); … … 139 139 break; 140 140 141 case "log": Apply(stack, x => Math.Log((double)x)); break; 142 case "+": Apply(stack, (x, y) => (double)x + (double)y); break; 143 case "-": Apply(stack, (x, y) => (double)x - (double)y); break; 144 case "*": Apply(stack, (x, y) => (double)x * (double)y); break; 145 case "/": Apply(stack, (x, y) => (double)x / (double)y); break; 146 case "^": Apply(stack, (x, y) => Math.Pow((double)x, (double)y)); break; 147 case "<": Apply(stack, (x, y) => (double)x < (double)y); break; 148 case ">": Apply(stack, (x, y) => (double)x > (double)y); break; 141 case "log": Apply(stack, x => Math.Log(Convert.ToDouble(x))); break; 142 case "+": Apply(stack, (x, y) => Convert.ToDouble(x) + Convert.ToDouble(y)); break; 143 case "-": Apply(stack, (x, y) => Convert.ToDouble(x) - Convert.ToDouble(y)); break; 144 case "*": Apply(stack, (x, y) => Convert.ToDouble(x) * Convert.ToDouble(y)); break; 145 case "/": Apply(stack, (x, y) => Convert.ToDouble(x) / Convert.ToDouble(y)); break; 146 case "^": Apply(stack, (x, y) => Math.Pow(Convert.ToDouble(x), Convert.ToDouble(y))); break; 147 case "<": Apply(stack, (x, y) => Convert.ToDouble(x) < Convert.ToDouble(y)); break; 148 case ">": Apply(stack, (x, y) => Convert.ToDouble(x) > Convert.ToDouble(y)); break; 149 150 case "toint": Apply(stack, x => Convert.ToInt32(x)); break; 151 case "todouble": Apply(stack, x => Convert.ToDouble(x)); break; 152 153 case "[]": Apply(stack, (a, i) => GetArrayValueAtIndex(a, Convert.ToInt32(i))); break; 149 154 150 155 case "==": Apply(stack, (x, y) => Equal(x, y)); break; 151 case "not": Apply(stack, x => ! (bool)x); break;156 case "not": Apply(stack, x => !Convert.ToBoolean(x)); break; 152 157 case "isnull": Apply(stack, x => x == null); break; 153 case "if": Apply(stack, (then, else_, cond) => (bool)cond? then : else_); break;154 155 case "ismatch": Apply(stack, (s, p) => new Regex( (string)p).IsMatch((string)s)); break;156 case "rename": Apply(stack, (s, p, r) => new Regex( (string)p).Replace((string)s, (string)r)); break;158 case "if": Apply(stack, (then, else_, cond) => Convert.ToBoolean(cond) ? then : else_); break; 159 160 case "ismatch": Apply(stack, (s, p) => new Regex(Convert.ToString(p)).IsMatch(Convert.ToString(s))); break; 161 case "rename": Apply(stack, (s, p, r) => new Regex(Convert.ToString(p)).Replace(Convert.ToString(s), Convert.ToString(r))); break; 157 162 158 163 default: stack.Push(GetVariableValue(variables, token)); break; … … 178 183 var v = value as BoolValue; 179 184 if (v != null) return v.Value; 185 return null; 186 } 187 188 private static object GetArrayValue(IItem value) { 189 if (value is IntArray || value is DoubleArray || value is BoolArray || value is StringArray) 190 return value; 180 191 return null; 181 192 } … … 188 199 GetDoubleValue(item) ?? 189 200 GetBoolValue(item) ?? 201 GetArrayValue(item) ?? 190 202 item.ToString(); 191 203 } 192 204 return null; 193 205 } 206 207 private static object GetArrayValueAtIndex(object array, int index) { 208 if (array is IntArray) 209 return ((IntArray)array)[index]; 210 if (array is DoubleArray) 211 return ((DoubleArray)array)[index]; 212 if (array is BoolArray) 213 return ((BoolArray)array)[index]; 214 if (array is StringArray) 215 return ((StringArray)array)[index]; 216 throw new NotSupportedException(string.Format("Type {0} is not a supported array type", array.GetType().Name)); 217 } 194 218 #endregion 195 219 196 220 #region variadic equality 197 private static bool Equal(object a, object b) { return EqualNumber(a, b) || EqualBool(a, b) || EqualString(a, b) || a == b; } 198 private static bool EqualNumber(object a, object b) { return a is double && b is double && (double)a == (double)b; } 221 private static bool Equal(object a, object b) { return EqualIntegerNumber(a, b) || EqualFloatingNumber(a, b) || EqualBool(a, b) || EqualString(a, b) || a == b; } 222 private static bool EqualIntegerNumber(object a, object b) { return a is int && b is int && (int)a == (int)b; } 223 private static bool EqualFloatingNumber(object a, object b) { return a is double && b is double && (double)a == (double)b; } 199 224 private static bool EqualBool(object a, object b) { return a is bool && b is bool && (bool)a == (bool)b; } 200 225 private static bool EqualString(object a, object b) { return a is string && b is string && ((string)a).Equals((string)b); } … … 208 233 try { 209 234 stack.Push(func(a)); 210 } 211 catch (Exception) { 235 } catch (Exception) { 212 236 stack.Push(a); 213 237 throw; … … 222 246 try { 223 247 stack.Push(func(a, b)); 224 } 225 catch (Exception) { 248 } catch (Exception) { 226 249 stack.Push(b); 227 250 stack.Push(a); … … 238 261 try { 239 262 stack.Push(func(a, b, c)); 240 } 241 catch (Exception) { 263 } catch (Exception) { 242 264 stack.Push(a); 243 265 stack.Push(b);
Note: See TracChangeset
for help on using the changeset viewer.