deltablue.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // base.js
  3. ////////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2013 the V8 project authors. All rights reserved.
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following
  13. // disclaimer in the documentation and/or other materials provided
  14. // with the distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived
  17. // from this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. if(typeof(WScript) === "undefined")
  31. {
  32. var WScript = {
  33. Echo: print
  34. }
  35. }
  36. // Performance.now is used in latency benchmarks, the fallback is Date.now.
  37. var performance = performance || {};
  38. performance.now = (function() {
  39. return performance.now ||
  40. performance.mozNow ||
  41. performance.msNow ||
  42. performance.oNow ||
  43. performance.webkitNow ||
  44. Date.now;
  45. })();
  46. // Simple framework for running the benchmark suites and
  47. // computing a score based on the timing measurements.
  48. // A benchmark has a name (string) and a function that will be run to
  49. // do the performance measurement. The optional setup and tearDown
  50. // arguments are functions that will be invoked before and after
  51. // running the benchmark, but the running time of these functions will
  52. // not be accounted for in the benchmark score.
  53. function Benchmark(name, doWarmup, doDeterministic, deterministicIterations,
  54. run, setup, tearDown, rmsResult, minIterations) {
  55. this.name = name;
  56. this.doWarmup = doWarmup;
  57. this.doDeterministic = doDeterministic;
  58. this.deterministicIterations = deterministicIterations;
  59. this.run = run;
  60. this.Setup = setup ? setup : function() { };
  61. this.TearDown = tearDown ? tearDown : function() { };
  62. this.rmsResult = rmsResult ? rmsResult : null;
  63. this.minIterations = minIterations ? minIterations : 32;
  64. }
  65. // Benchmark results hold the benchmark and the measured time used to
  66. // run the benchmark. The benchmark score is computed later once a
  67. // full benchmark suite has run to completion. If latency is set to 0
  68. // then there is no latency score for this benchmark.
  69. function BenchmarkResult(benchmark, time, latency) {
  70. this.benchmark = benchmark;
  71. this.time = time;
  72. this.latency = latency;
  73. }
  74. // Automatically convert results to numbers. Used by the geometric
  75. // mean computation.
  76. BenchmarkResult.prototype.valueOf = function() {
  77. return this.time;
  78. }
  79. // Suites of benchmarks consist of a name and the set of benchmarks in
  80. // addition to the reference timing that the final score will be based
  81. // on. This way, all scores are relative to a reference run and higher
  82. // scores implies better performance.
  83. function BenchmarkSuite(name, reference, benchmarks) {
  84. this.name = name;
  85. this.reference = reference;
  86. this.benchmarks = benchmarks;
  87. BenchmarkSuite.suites.push(this);
  88. }
  89. // Keep track of all declared benchmark suites.
  90. BenchmarkSuite.suites = [];
  91. // Scores are not comparable across versions. Bump the version if
  92. // you're making changes that will affect that scores, e.g. if you add
  93. // a new benchmark or change an existing one.
  94. BenchmarkSuite.version = '9';
  95. // Defines global benchsuite running mode that overrides benchmark suite
  96. // behavior. Intended to be set by the benchmark driver. Undefined
  97. // values here allow a benchmark to define behaviour itself.
  98. BenchmarkSuite.config = {
  99. doWarmup: undefined,
  100. doDeterministic: undefined
  101. };
  102. // Override the alert function to throw an exception instead.
  103. alert = function(s) {
  104. throw "Alert called with argument: " + s;
  105. };
  106. // To make the benchmark results predictable, we replace Math.random
  107. // with a 100% deterministic alternative.
  108. BenchmarkSuite.ResetRNG = function() {
  109. Math.random = (function() {
  110. var seed = 49734321;
  111. return function() {
  112. // Robert Jenkins' 32 bit integer hash function.
  113. seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
  114. seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
  115. seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
  116. seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
  117. seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff;
  118. seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
  119. return (seed & 0xfffffff) / 0x10000000;
  120. };
  121. })();
  122. }
  123. // Runs all registered benchmark suites and optionally yields between
  124. // each individual benchmark to avoid running for too long in the
  125. // context of browsers. Once done, the final score is reported to the
  126. // runner.
  127. BenchmarkSuite.RunSuites = function(runner, skipBenchmarks) {
  128. skipBenchmarks = typeof skipBenchmarks === 'undefined' ? [] : skipBenchmarks;
  129. var continuation = null;
  130. var suites = BenchmarkSuite.suites;
  131. var length = suites.length;
  132. BenchmarkSuite.scores = [];
  133. var index = 0;
  134. function RunStep() {
  135. while (continuation || index < length) {
  136. if (continuation) {
  137. continuation = continuation();
  138. } else {
  139. var suite = suites[index++];
  140. if (runner.NotifyStart) runner.NotifyStart(suite.name);
  141. if (skipBenchmarks.indexOf(suite.name) > -1) {
  142. suite.NotifySkipped(runner);
  143. } else {
  144. continuation = suite.RunStep(runner);
  145. }
  146. }
  147. if (continuation && typeof window != 'undefined' && window.setTimeout) {
  148. window.setTimeout(RunStep, 25);
  149. return;
  150. }
  151. }
  152. // show final result
  153. if (runner.NotifyScore) {
  154. var score = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores);
  155. var formatted = BenchmarkSuite.FormatScore(100 * score);
  156. runner.NotifyScore(formatted);
  157. }
  158. }
  159. RunStep();
  160. }
  161. // Counts the total number of registered benchmarks. Useful for
  162. // showing progress as a percentage.
  163. BenchmarkSuite.CountBenchmarks = function() {
  164. var result = 0;
  165. var suites = BenchmarkSuite.suites;
  166. for (var i = 0; i < suites.length; i++) {
  167. result += suites[i].benchmarks.length;
  168. }
  169. return result;
  170. }
  171. // Computes the geometric mean of a set of numbers.
  172. BenchmarkSuite.GeometricMean = function(numbers) {
  173. var log = 0;
  174. for (var i = 0; i < numbers.length; i++) {
  175. log += Math.log(numbers[i]);
  176. }
  177. return Math.pow(Math.E, log / numbers.length);
  178. }
  179. // Computes the geometric mean of a set of throughput time measurements.
  180. BenchmarkSuite.GeometricMeanTime = function(measurements) {
  181. var log = 0;
  182. for (var i = 0; i < measurements.length; i++) {
  183. log += Math.log(measurements[i].time);
  184. }
  185. return Math.pow(Math.E, log / measurements.length);
  186. }
  187. // Computes the geometric mean of a set of rms measurements.
  188. BenchmarkSuite.GeometricMeanLatency = function(measurements) {
  189. var log = 0;
  190. var hasLatencyResult = false;
  191. for (var i = 0; i < measurements.length; i++) {
  192. if (measurements[i].latency != 0) {
  193. log += Math.log(measurements[i].latency);
  194. hasLatencyResult = true;
  195. }
  196. }
  197. if (hasLatencyResult) {
  198. return Math.pow(Math.E, log / measurements.length);
  199. } else {
  200. return 0;
  201. }
  202. }
  203. // Converts a score value to a string with at least three significant
  204. // digits.
  205. BenchmarkSuite.FormatScore = function(value) {
  206. if (value > 100) {
  207. return value.toFixed(0);
  208. } else {
  209. return value.toPrecision(3);
  210. }
  211. }
  212. // Notifies the runner that we're done running a single benchmark in
  213. // the benchmark suite. This can be useful to report progress.
  214. BenchmarkSuite.prototype.NotifyStep = function(result) {
  215. this.results.push(result);
  216. if (this.runner.NotifyStep) this.runner.NotifyStep(result.benchmark.name);
  217. }
  218. // Notifies the runner that we're done with running a suite and that
  219. // we have a result which can be reported to the user if needed.
  220. BenchmarkSuite.prototype.NotifyResult = function() {
  221. var mean = BenchmarkSuite.GeometricMeanTime(this.results);
  222. var score = this.reference[0] / mean;
  223. BenchmarkSuite.scores.push(score);
  224. if (this.runner.NotifyResult) {
  225. var formatted = BenchmarkSuite.FormatScore(100 * score);
  226. this.runner.NotifyResult(this.name, formatted);
  227. }
  228. if (this.reference.length == 2) {
  229. var meanLatency = BenchmarkSuite.GeometricMeanLatency(this.results);
  230. if (meanLatency != 0) {
  231. var scoreLatency = this.reference[1] / meanLatency;
  232. BenchmarkSuite.scores.push(scoreLatency);
  233. if (this.runner.NotifyResult) {
  234. var formattedLatency = BenchmarkSuite.FormatScore(100 * scoreLatency)
  235. this.runner.NotifyResult(this.name + "Latency", formattedLatency);
  236. }
  237. }
  238. }
  239. }
  240. BenchmarkSuite.prototype.NotifySkipped = function(runner) {
  241. BenchmarkSuite.scores.push(1); // push default reference score.
  242. if (runner.NotifyResult) {
  243. runner.NotifyResult(this.name, "Skipped");
  244. }
  245. }
  246. // Notifies the runner that running a benchmark resulted in an error.
  247. BenchmarkSuite.prototype.NotifyError = function(error) {
  248. if (this.runner.NotifyError) {
  249. this.runner.NotifyError(this.name, error);
  250. }
  251. if (this.runner.NotifyStep) {
  252. this.runner.NotifyStep(this.name);
  253. }
  254. }
  255. // Runs a single benchmark for at least a second and computes the
  256. // average time it takes to run a single iteration.
  257. BenchmarkSuite.prototype.RunSingleBenchmark = function(benchmark, data) {
  258. var config = BenchmarkSuite.config;
  259. var doWarmup = config.doWarmup !== undefined
  260. ? config.doWarmup
  261. : benchmark.doWarmup;
  262. var doDeterministic = config.doDeterministic !== undefined
  263. ? config.doDeterministic
  264. : benchmark.doDeterministic;
  265. function Measure(data) {
  266. var elapsed = 0;
  267. var start = new Date();
  268. // Run either for 1 second or for the number of iterations specified
  269. // by minIterations, depending on the config flag doDeterministic.
  270. for (var i = 0; (doDeterministic ?
  271. i<benchmark.deterministicIterations : elapsed < 1000); i++) {
  272. benchmark.run();
  273. elapsed = new Date() - start;
  274. }
  275. if (data != null) {
  276. data.runs += i;
  277. data.elapsed += elapsed;
  278. }
  279. }
  280. // Sets up data in order to skip or not the warmup phase.
  281. if (!doWarmup && data == null) {
  282. data = { runs: 0, elapsed: 0 };
  283. }
  284. if (data == null) {
  285. Measure(null);
  286. return { runs: 0, elapsed: 0 };
  287. } else {
  288. Measure(data);
  289. // If we've run too few iterations, we continue for another second.
  290. if (data.runs < benchmark.minIterations) return data;
  291. var usec = (data.elapsed * 1000) / data.runs;
  292. var rms = (benchmark.rmsResult != null) ? benchmark.rmsResult() : 0;
  293. this.NotifyStep(new BenchmarkResult(benchmark, usec, rms));
  294. return null;
  295. }
  296. }
  297. // This function starts running a suite, but stops between each
  298. // individual benchmark in the suite and returns a continuation
  299. // function which can be invoked to run the next benchmark. Once the
  300. // last benchmark has been executed, null is returned.
  301. BenchmarkSuite.prototype.RunStep = function(runner) {
  302. BenchmarkSuite.ResetRNG();
  303. this.results = [];
  304. this.runner = runner;
  305. var length = this.benchmarks.length;
  306. var index = 0;
  307. var suite = this;
  308. var data;
  309. // Run the setup, the actual benchmark, and the tear down in three
  310. // separate steps to allow the framework to yield between any of the
  311. // steps.
  312. function RunNextSetup() {
  313. if (index < length) {
  314. try {
  315. suite.benchmarks[index].Setup();
  316. } catch (e) {
  317. suite.NotifyError(e);
  318. return null;
  319. }
  320. return RunNextBenchmark;
  321. }
  322. suite.NotifyResult();
  323. return null;
  324. }
  325. function RunNextBenchmark() {
  326. try {
  327. data = suite.RunSingleBenchmark(suite.benchmarks[index], data);
  328. } catch (e) {
  329. suite.NotifyError(e);
  330. return null;
  331. }
  332. // If data is null, we're done with this benchmark.
  333. return (data == null) ? RunNextTearDown : RunNextBenchmark();
  334. }
  335. function RunNextTearDown() {
  336. try {
  337. suite.benchmarks[index++].TearDown();
  338. } catch (e) {
  339. suite.NotifyError(e);
  340. return null;
  341. }
  342. return RunNextSetup;
  343. }
  344. // Start out running the setup.
  345. return RunNextSetup();
  346. }
  347. /////////////////////////////////////////////////////////////
  348. // deltablue.js
  349. /////////////////////////////////////////////////////////////
  350. // Copyright 2008 the V8 project authors. All rights reserved.
  351. // Copyright 1996 John Maloney and Mario Wolczko.
  352. // This program is free software; you can redistribute it and/or modify
  353. // it under the terms of the GNU General Public License as published by
  354. // the Free Software Foundation; either version 2 of the License, or
  355. // (at your option) any later version.
  356. //
  357. // This program is distributed in the hope that it will be useful,
  358. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  359. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  360. // GNU General Public License for more details.
  361. //
  362. // You should have received a copy of the GNU General Public License
  363. // along with this program; if not, write to the Free Software
  364. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  365. // This implementation of the DeltaBlue benchmark is derived
  366. // from the Smalltalk implementation by John Maloney and Mario
  367. // Wolczko. Some parts have been translated directly, whereas
  368. // others have been modified more aggresively to make it feel
  369. // more like a JavaScript program.
  370. var DeltaBlue = new BenchmarkSuite('DeltaBlue', [66118], [
  371. new Benchmark('DeltaBlue', true, false, 4400, deltaBlue)
  372. ]);
  373. /**
  374. * A JavaScript implementation of the DeltaBlue constraint-solving
  375. * algorithm, as described in:
  376. *
  377. * "The DeltaBlue Algorithm: An Incremental Constraint Hierarchy Solver"
  378. * Bjorn N. Freeman-Benson and John Maloney
  379. * January 1990 Communications of the ACM,
  380. * also available as University of Washington TR 89-08-06.
  381. *
  382. * Beware: this benchmark is written in a grotesque style where
  383. * the constraint model is built by side-effects from constructors.
  384. * I've kept it this way to avoid deviating too much from the original
  385. * implementation.
  386. */
  387. /* --- O b j e c t M o d e l --- */
  388. Object.defineProperty(Object.prototype, "inheritsFrom", {
  389. value: function (shuper) {
  390. function Inheriter() { }
  391. Inheriter.prototype = shuper.prototype;
  392. this.prototype = new Inheriter();
  393. this.superConstructor = shuper;
  394. }
  395. });
  396. function OrderedCollection() {
  397. this.elms = new Array();
  398. }
  399. OrderedCollection.prototype.add = function (elm) {
  400. this.elms.push(elm);
  401. }
  402. OrderedCollection.prototype.at = function (index) {
  403. return this.elms[index];
  404. }
  405. OrderedCollection.prototype.size = function () {
  406. return this.elms.length;
  407. }
  408. OrderedCollection.prototype.removeFirst = function () {
  409. return this.elms.pop();
  410. }
  411. OrderedCollection.prototype.remove = function (elm) {
  412. var index = 0, skipped = 0;
  413. for (var i = 0; i < this.elms.length; i++) {
  414. var value = this.elms[i];
  415. if (value != elm) {
  416. this.elms[index] = value;
  417. index++;
  418. } else {
  419. skipped++;
  420. }
  421. }
  422. for (var i = 0; i < skipped; i++)
  423. this.elms.pop();
  424. }
  425. /* --- *
  426. * S t r e n g t h
  427. * --- */
  428. /**
  429. * Strengths are used to measure the relative importance of constraints.
  430. * New strengths may be inserted in the strength hierarchy without
  431. * disrupting current constraints. Strengths cannot be created outside
  432. * this class, so pointer comparison can be used for value comparison.
  433. */
  434. function Strength(strengthValue, name) {
  435. this.strengthValue = strengthValue;
  436. this.name = name;
  437. }
  438. Strength.stronger = function (s1, s2) {
  439. return s1.strengthValue < s2.strengthValue;
  440. }
  441. Strength.weaker = function (s1, s2) {
  442. return s1.strengthValue > s2.strengthValue;
  443. }
  444. Strength.weakestOf = function (s1, s2) {
  445. return this.weaker(s1, s2) ? s1 : s2;
  446. }
  447. Strength.strongest = function (s1, s2) {
  448. return this.stronger(s1, s2) ? s1 : s2;
  449. }
  450. Strength.prototype.nextWeaker = function () {
  451. switch (this.strengthValue) {
  452. case 0: return Strength.WEAKEST;
  453. case 1: return Strength.WEAK_DEFAULT;
  454. case 2: return Strength.NORMAL;
  455. case 3: return Strength.STRONG_DEFAULT;
  456. case 4: return Strength.PREFERRED;
  457. case 5: return Strength.REQUIRED;
  458. }
  459. }
  460. // Strength constants.
  461. Strength.REQUIRED = new Strength(0, "required");
  462. Strength.STONG_PREFERRED = new Strength(1, "strongPreferred");
  463. Strength.PREFERRED = new Strength(2, "preferred");
  464. Strength.STRONG_DEFAULT = new Strength(3, "strongDefault");
  465. Strength.NORMAL = new Strength(4, "normal");
  466. Strength.WEAK_DEFAULT = new Strength(5, "weakDefault");
  467. Strength.WEAKEST = new Strength(6, "weakest");
  468. /* --- *
  469. * C o n s t r a i n t
  470. * --- */
  471. /**
  472. * An abstract class representing a system-maintainable relationship
  473. * (or "constraint") between a set of variables. A constraint supplies
  474. * a strength instance variable; concrete subclasses provide a means
  475. * of storing the constrained variables and other information required
  476. * to represent a constraint.
  477. */
  478. function Constraint(strength) {
  479. this.strength = strength;
  480. }
  481. /**
  482. * Activate this constraint and attempt to satisfy it.
  483. */
  484. Constraint.prototype.addConstraint = function () {
  485. this.addToGraph();
  486. planner.incrementalAdd(this);
  487. }
  488. /**
  489. * Attempt to find a way to enforce this constraint. If successful,
  490. * record the solution, perhaps modifying the current dataflow
  491. * graph. Answer the constraint that this constraint overrides, if
  492. * there is one, or nil, if there isn't.
  493. * Assume: I am not already satisfied.
  494. */
  495. Constraint.prototype.satisfy = function (mark) {
  496. this.chooseMethod(mark);
  497. if (!this.isSatisfied()) {
  498. if (this.strength == Strength.REQUIRED)
  499. alert("Could not satisfy a required constraint!");
  500. return null;
  501. }
  502. this.markInputs(mark);
  503. var out = this.output();
  504. var overridden = out.determinedBy;
  505. if (overridden != null) overridden.markUnsatisfied();
  506. out.determinedBy = this;
  507. if (!planner.addPropagate(this, mark))
  508. alert("Cycle encountered");
  509. out.mark = mark;
  510. return overridden;
  511. }
  512. Constraint.prototype.destroyConstraint = function () {
  513. if (this.isSatisfied()) planner.incrementalRemove(this);
  514. else this.removeFromGraph();
  515. }
  516. /**
  517. * Normal constraints are not input constraints. An input constraint
  518. * is one that depends on external state, such as the mouse, the
  519. * keybord, a clock, or some arbitraty piece of imperative code.
  520. */
  521. Constraint.prototype.isInput = function () {
  522. return false;
  523. }
  524. /* --- *
  525. * U n a r y C o n s t r a i n t
  526. * --- */
  527. /**
  528. * Abstract superclass for constraints having a single possible output
  529. * variable.
  530. */
  531. function UnaryConstraint(v, strength) {
  532. UnaryConstraint.superConstructor.call(this, strength);
  533. this.myOutput = v;
  534. this.satisfied = false;
  535. this.addConstraint();
  536. }
  537. UnaryConstraint.inheritsFrom(Constraint);
  538. /**
  539. * Adds this constraint to the constraint graph
  540. */
  541. UnaryConstraint.prototype.addToGraph = function () {
  542. this.myOutput.addConstraint(this);
  543. this.satisfied = false;
  544. }
  545. /**
  546. * Decides if this constraint can be satisfied and records that
  547. * decision.
  548. */
  549. UnaryConstraint.prototype.chooseMethod = function (mark) {
  550. this.satisfied = (this.myOutput.mark != mark)
  551. && Strength.stronger(this.strength, this.myOutput.walkStrength);
  552. }
  553. /**
  554. * Returns true if this constraint is satisfied in the current solution.
  555. */
  556. UnaryConstraint.prototype.isSatisfied = function () {
  557. return this.satisfied;
  558. }
  559. UnaryConstraint.prototype.markInputs = function (mark) {
  560. // has no inputs
  561. }
  562. /**
  563. * Returns the current output variable.
  564. */
  565. UnaryConstraint.prototype.output = function () {
  566. return this.myOutput;
  567. }
  568. /**
  569. * Calculate the walkabout strength, the stay flag, and, if it is
  570. * 'stay', the value for the current output of this constraint. Assume
  571. * this constraint is satisfied.
  572. */
  573. UnaryConstraint.prototype.recalculate = function () {
  574. this.myOutput.walkStrength = this.strength;
  575. this.myOutput.stay = !this.isInput();
  576. if (this.myOutput.stay) this.execute(); // Stay optimization
  577. }
  578. /**
  579. * Records that this constraint is unsatisfied
  580. */
  581. UnaryConstraint.prototype.markUnsatisfied = function () {
  582. this.satisfied = false;
  583. }
  584. UnaryConstraint.prototype.inputsKnown = function () {
  585. return true;
  586. }
  587. UnaryConstraint.prototype.removeFromGraph = function () {
  588. if (this.myOutput != null) this.myOutput.removeConstraint(this);
  589. this.satisfied = false;
  590. }
  591. /* --- *
  592. * S t a y C o n s t r a i n t
  593. * --- */
  594. /**
  595. * Variables that should, with some level of preference, stay the same.
  596. * Planners may exploit the fact that instances, if satisfied, will not
  597. * change their output during plan execution. This is called "stay
  598. * optimization".
  599. */
  600. function StayConstraint(v, str) {
  601. StayConstraint.superConstructor.call(this, v, str);
  602. }
  603. StayConstraint.inheritsFrom(UnaryConstraint);
  604. StayConstraint.prototype.execute = function () {
  605. // Stay constraints do nothing
  606. }
  607. /* --- *
  608. * E d i t C o n s t r a i n t
  609. * --- */
  610. /**
  611. * A unary input constraint used to mark a variable that the client
  612. * wishes to change.
  613. */
  614. function EditConstraint(v, str) {
  615. EditConstraint.superConstructor.call(this, v, str);
  616. }
  617. EditConstraint.inheritsFrom(UnaryConstraint);
  618. /**
  619. * Edits indicate that a variable is to be changed by imperative code.
  620. */
  621. EditConstraint.prototype.isInput = function () {
  622. return true;
  623. }
  624. EditConstraint.prototype.execute = function () {
  625. // Edit constraints do nothing
  626. }
  627. /* --- *
  628. * B i n a r y C o n s t r a i n t
  629. * --- */
  630. var Direction = new Object();
  631. Direction.NONE = 0;
  632. Direction.FORWARD = 1;
  633. Direction.BACKWARD = -1;
  634. /**
  635. * Abstract superclass for constraints having two possible output
  636. * variables.
  637. */
  638. function BinaryConstraint(var1, var2, strength) {
  639. BinaryConstraint.superConstructor.call(this, strength);
  640. this.v1 = var1;
  641. this.v2 = var2;
  642. this.direction = Direction.NONE;
  643. this.addConstraint();
  644. }
  645. BinaryConstraint.inheritsFrom(Constraint);
  646. /**
  647. * Decides if this constraint can be satisfied and which way it
  648. * should flow based on the relative strength of the variables related,
  649. * and record that decision.
  650. */
  651. BinaryConstraint.prototype.chooseMethod = function (mark) {
  652. if (this.v1.mark == mark) {
  653. this.direction = (this.v2.mark != mark && Strength.stronger(this.strength, this.v2.walkStrength))
  654. ? Direction.FORWARD
  655. : Direction.NONE;
  656. }
  657. if (this.v2.mark == mark) {
  658. this.direction = (this.v1.mark != mark && Strength.stronger(this.strength, this.v1.walkStrength))
  659. ? Direction.BACKWARD
  660. : Direction.NONE;
  661. }
  662. if (Strength.weaker(this.v1.walkStrength, this.v2.walkStrength)) {
  663. this.direction = Strength.stronger(this.strength, this.v1.walkStrength)
  664. ? Direction.BACKWARD
  665. : Direction.NONE;
  666. } else {
  667. this.direction = Strength.stronger(this.strength, this.v2.walkStrength)
  668. ? Direction.FORWARD
  669. : Direction.BACKWARD
  670. }
  671. }
  672. /**
  673. * Add this constraint to the constraint graph
  674. */
  675. BinaryConstraint.prototype.addToGraph = function () {
  676. this.v1.addConstraint(this);
  677. this.v2.addConstraint(this);
  678. this.direction = Direction.NONE;
  679. }
  680. /**
  681. * Answer true if this constraint is satisfied in the current solution.
  682. */
  683. BinaryConstraint.prototype.isSatisfied = function () {
  684. return this.direction != Direction.NONE;
  685. }
  686. /**
  687. * Mark the input variable with the given mark.
  688. */
  689. BinaryConstraint.prototype.markInputs = function (mark) {
  690. this.input().mark = mark;
  691. }
  692. /**
  693. * Returns the current input variable
  694. */
  695. BinaryConstraint.prototype.input = function () {
  696. return (this.direction == Direction.FORWARD) ? this.v1 : this.v2;
  697. }
  698. /**
  699. * Returns the current output variable
  700. */
  701. BinaryConstraint.prototype.output = function () {
  702. return (this.direction == Direction.FORWARD) ? this.v2 : this.v1;
  703. }
  704. /**
  705. * Calculate the walkabout strength, the stay flag, and, if it is
  706. * 'stay', the value for the current output of this
  707. * constraint. Assume this constraint is satisfied.
  708. */
  709. BinaryConstraint.prototype.recalculate = function () {
  710. var ihn = this.input(), out = this.output();
  711. out.walkStrength = Strength.weakestOf(this.strength, ihn.walkStrength);
  712. out.stay = ihn.stay;
  713. if (out.stay) this.execute();
  714. }
  715. /**
  716. * Record the fact that this constraint is unsatisfied.
  717. */
  718. BinaryConstraint.prototype.markUnsatisfied = function () {
  719. this.direction = Direction.NONE;
  720. }
  721. BinaryConstraint.prototype.inputsKnown = function (mark) {
  722. var i = this.input();
  723. return i.mark == mark || i.stay || i.determinedBy == null;
  724. }
  725. BinaryConstraint.prototype.removeFromGraph = function () {
  726. if (this.v1 != null) this.v1.removeConstraint(this);
  727. if (this.v2 != null) this.v2.removeConstraint(this);
  728. this.direction = Direction.NONE;
  729. }
  730. /* --- *
  731. * S c a l e C o n s t r a i n t
  732. * --- */
  733. /**
  734. * Relates two variables by the linear scaling relationship: "v2 =
  735. * (v1 * scale) + offset". Either v1 or v2 may be changed to maintain
  736. * this relationship but the scale factor and offset are considered
  737. * read-only.
  738. */
  739. function ScaleConstraint(src, scale, offset, dest, strength) {
  740. this.direction = Direction.NONE;
  741. this.scale = scale;
  742. this.offset = offset;
  743. ScaleConstraint.superConstructor.call(this, src, dest, strength);
  744. }
  745. ScaleConstraint.inheritsFrom(BinaryConstraint);
  746. /**
  747. * Adds this constraint to the constraint graph.
  748. */
  749. ScaleConstraint.prototype.addToGraph = function () {
  750. ScaleConstraint.superConstructor.prototype.addToGraph.call(this);
  751. this.scale.addConstraint(this);
  752. this.offset.addConstraint(this);
  753. }
  754. ScaleConstraint.prototype.removeFromGraph = function () {
  755. ScaleConstraint.superConstructor.prototype.removeFromGraph.call(this);
  756. if (this.scale != null) this.scale.removeConstraint(this);
  757. if (this.offset != null) this.offset.removeConstraint(this);
  758. }
  759. ScaleConstraint.prototype.markInputs = function (mark) {
  760. ScaleConstraint.superConstructor.prototype.markInputs.call(this, mark);
  761. this.scale.mark = this.offset.mark = mark;
  762. }
  763. /**
  764. * Enforce this constraint. Assume that it is satisfied.
  765. */
  766. ScaleConstraint.prototype.execute = function () {
  767. if (this.direction == Direction.FORWARD) {
  768. this.v2.value = this.v1.value * this.scale.value + this.offset.value;
  769. } else {
  770. this.v1.value = (this.v2.value - this.offset.value) / this.scale.value;
  771. }
  772. }
  773. /**
  774. * Calculate the walkabout strength, the stay flag, and, if it is
  775. * 'stay', the value for the current output of this constraint. Assume
  776. * this constraint is satisfied.
  777. */
  778. ScaleConstraint.prototype.recalculate = function () {
  779. var ihn = this.input(), out = this.output();
  780. out.walkStrength = Strength.weakestOf(this.strength, ihn.walkStrength);
  781. out.stay = ihn.stay && this.scale.stay && this.offset.stay;
  782. if (out.stay) this.execute();
  783. }
  784. /* --- *
  785. * E q u a l i t y C o n s t r a i n t
  786. * --- */
  787. /**
  788. * Constrains two variables to have the same value.
  789. */
  790. function EqualityConstraint(var1, var2, strength) {
  791. EqualityConstraint.superConstructor.call(this, var1, var2, strength);
  792. }
  793. EqualityConstraint.inheritsFrom(BinaryConstraint);
  794. /**
  795. * Enforce this constraint. Assume that it is satisfied.
  796. */
  797. EqualityConstraint.prototype.execute = function () {
  798. this.output().value = this.input().value;
  799. }
  800. /* --- *
  801. * V a r i a b l e
  802. * --- */
  803. /**
  804. * A constrained variable. In addition to its value, it maintain the
  805. * structure of the constraint graph, the current dataflow graph, and
  806. * various parameters of interest to the DeltaBlue incremental
  807. * constraint solver.
  808. **/
  809. function Variable(name, initialValue) {
  810. this.value = initialValue || 0;
  811. this.constraints = new OrderedCollection();
  812. this.determinedBy = null;
  813. this.mark = 0;
  814. this.walkStrength = Strength.WEAKEST;
  815. this.stay = true;
  816. this.name = name;
  817. }
  818. /**
  819. * Add the given constraint to the set of all constraints that refer
  820. * this variable.
  821. */
  822. Variable.prototype.addConstraint = function (c) {
  823. this.constraints.add(c);
  824. }
  825. /**
  826. * Removes all traces of c from this variable.
  827. */
  828. Variable.prototype.removeConstraint = function (c) {
  829. this.constraints.remove(c);
  830. if (this.determinedBy == c) this.determinedBy = null;
  831. }
  832. /* --- *
  833. * P l a n n e r
  834. * --- */
  835. /**
  836. * The DeltaBlue planner
  837. */
  838. function Planner() {
  839. this.currentMark = 0;
  840. }
  841. /**
  842. * Attempt to satisfy the given constraint and, if successful,
  843. * incrementally update the dataflow graph. Details: If satifying
  844. * the constraint is successful, it may override a weaker constraint
  845. * on its output. The algorithm attempts to resatisfy that
  846. * constraint using some other method. This process is repeated
  847. * until either a) it reaches a variable that was not previously
  848. * determined by any constraint or b) it reaches a constraint that
  849. * is too weak to be satisfied using any of its methods. The
  850. * variables of constraints that have been processed are marked with
  851. * a unique mark value so that we know where we've been. This allows
  852. * the algorithm to avoid getting into an infinite loop even if the
  853. * constraint graph has an inadvertent cycle.
  854. */
  855. Planner.prototype.incrementalAdd = function (c) {
  856. var mark = this.newMark();
  857. var overridden = c.satisfy(mark);
  858. while (overridden != null)
  859. overridden = overridden.satisfy(mark);
  860. }
  861. /**
  862. * Entry point for retracting a constraint. Remove the given
  863. * constraint and incrementally update the dataflow graph.
  864. * Details: Retracting the given constraint may allow some currently
  865. * unsatisfiable downstream constraint to be satisfied. We therefore collect
  866. * a list of unsatisfied downstream constraints and attempt to
  867. * satisfy each one in turn. This list is traversed by constraint
  868. * strength, strongest first, as a heuristic for avoiding
  869. * unnecessarily adding and then overriding weak constraints.
  870. * Assume: c is satisfied.
  871. */
  872. Planner.prototype.incrementalRemove = function (c) {
  873. var out = c.output();
  874. c.markUnsatisfied();
  875. c.removeFromGraph();
  876. var unsatisfied = this.removePropagateFrom(out);
  877. var strength = Strength.REQUIRED;
  878. do {
  879. for (var i = 0; i < unsatisfied.size(); i++) {
  880. var u = unsatisfied.at(i);
  881. if (u.strength == strength)
  882. this.incrementalAdd(u);
  883. }
  884. strength = strength.nextWeaker();
  885. } while (strength != Strength.WEAKEST);
  886. }
  887. /**
  888. * Select a previously unused mark value.
  889. */
  890. Planner.prototype.newMark = function () {
  891. return ++this.currentMark;
  892. }
  893. /**
  894. * Extract a plan for resatisfaction starting from the given source
  895. * constraints, usually a set of input constraints. This method
  896. * assumes that stay optimization is desired; the plan will contain
  897. * only constraints whose output variables are not stay. Constraints
  898. * that do no computation, such as stay and edit constraints, are
  899. * not included in the plan.
  900. * Details: The outputs of a constraint are marked when it is added
  901. * to the plan under construction. A constraint may be appended to
  902. * the plan when all its input variables are known. A variable is
  903. * known if either a) the variable is marked (indicating that has
  904. * been computed by a constraint appearing earlier in the plan), b)
  905. * the variable is 'stay' (i.e. it is a constant at plan execution
  906. * time), or c) the variable is not determined by any
  907. * constraint. The last provision is for past states of history
  908. * variables, which are not stay but which are also not computed by
  909. * any constraint.
  910. * Assume: sources are all satisfied.
  911. */
  912. Planner.prototype.makePlan = function (sources) {
  913. var mark = this.newMark();
  914. var plan = new Plan();
  915. var todo = sources;
  916. while (todo.size() > 0) {
  917. var c = todo.removeFirst();
  918. if (c.output().mark != mark && c.inputsKnown(mark)) {
  919. plan.addConstraint(c);
  920. c.output().mark = mark;
  921. this.addConstraintsConsumingTo(c.output(), todo);
  922. }
  923. }
  924. return plan;
  925. }
  926. /**
  927. * Extract a plan for resatisfying starting from the output of the
  928. * given constraints, usually a set of input constraints.
  929. */
  930. Planner.prototype.extractPlanFromConstraints = function (constraints) {
  931. var sources = new OrderedCollection();
  932. for (var i = 0; i < constraints.size(); i++) {
  933. var c = constraints.at(i);
  934. if (c.isInput() && c.isSatisfied())
  935. // not in plan already and eligible for inclusion
  936. sources.add(c);
  937. }
  938. return this.makePlan(sources);
  939. }
  940. /**
  941. * Recompute the walkabout strengths and stay flags of all variables
  942. * downstream of the given constraint and recompute the actual
  943. * values of all variables whose stay flag is true. If a cycle is
  944. * detected, remove the given constraint and answer
  945. * false. Otherwise, answer true.
  946. * Details: Cycles are detected when a marked variable is
  947. * encountered downstream of the given constraint. The sender is
  948. * assumed to have marked the inputs of the given constraint with
  949. * the given mark. Thus, encountering a marked node downstream of
  950. * the output constraint means that there is a path from the
  951. * constraint's output to one of its inputs.
  952. */
  953. Planner.prototype.addPropagate = function (c, mark) {
  954. var todo = new OrderedCollection();
  955. todo.add(c);
  956. while (todo.size() > 0) {
  957. var d = todo.removeFirst();
  958. if (d.output().mark == mark) {
  959. this.incrementalRemove(c);
  960. return false;
  961. }
  962. d.recalculate();
  963. this.addConstraintsConsumingTo(d.output(), todo);
  964. }
  965. return true;
  966. }
  967. /**
  968. * Update the walkabout strengths and stay flags of all variables
  969. * downstream of the given constraint. Answer a collection of
  970. * unsatisfied constraints sorted in order of decreasing strength.
  971. */
  972. Planner.prototype.removePropagateFrom = function (out) {
  973. out.determinedBy = null;
  974. out.walkStrength = Strength.WEAKEST;
  975. out.stay = true;
  976. var unsatisfied = new OrderedCollection();
  977. var todo = new OrderedCollection();
  978. todo.add(out);
  979. while (todo.size() > 0) {
  980. var v = todo.removeFirst();
  981. for (var i = 0; i < v.constraints.size(); i++) {
  982. var c = v.constraints.at(i);
  983. if (!c.isSatisfied())
  984. unsatisfied.add(c);
  985. }
  986. var determining = v.determinedBy;
  987. for (var i = 0; i < v.constraints.size(); i++) {
  988. var next = v.constraints.at(i);
  989. if (next != determining && next.isSatisfied()) {
  990. next.recalculate();
  991. todo.add(next.output());
  992. }
  993. }
  994. }
  995. return unsatisfied;
  996. }
  997. Planner.prototype.addConstraintsConsumingTo = function (v, coll) {
  998. var determining = v.determinedBy;
  999. var cc = v.constraints;
  1000. for (var i = 0; i < cc.size(); i++) {
  1001. var c = cc.at(i);
  1002. if (c != determining && c.isSatisfied())
  1003. coll.add(c);
  1004. }
  1005. }
  1006. /* --- *
  1007. * P l a n
  1008. * --- */
  1009. /**
  1010. * A Plan is an ordered list of constraints to be executed in sequence
  1011. * to resatisfy all currently satisfiable constraints in the face of
  1012. * one or more changing inputs.
  1013. */
  1014. function Plan() {
  1015. this.v = new OrderedCollection();
  1016. }
  1017. Plan.prototype.addConstraint = function (c) {
  1018. this.v.add(c);
  1019. }
  1020. Plan.prototype.size = function () {
  1021. return this.v.size();
  1022. }
  1023. Plan.prototype.constraintAt = function (index) {
  1024. return this.v.at(index);
  1025. }
  1026. Plan.prototype.execute = function () {
  1027. for (var i = 0; i < this.size(); i++) {
  1028. var c = this.constraintAt(i);
  1029. c.execute();
  1030. }
  1031. }
  1032. /* --- *
  1033. * M a i n
  1034. * --- */
  1035. /**
  1036. * This is the standard DeltaBlue benchmark. A long chain of equality
  1037. * constraints is constructed with a stay constraint on one end. An
  1038. * edit constraint is then added to the opposite end and the time is
  1039. * measured for adding and removing this constraint, and extracting
  1040. * and executing a constraint satisfaction plan. There are two cases.
  1041. * In case 1, the added constraint is stronger than the stay
  1042. * constraint and values must propagate down the entire length of the
  1043. * chain. In case 2, the added constraint is weaker than the stay
  1044. * constraint so it cannot be accomodated. The cost in this case is,
  1045. * of course, very low. Typical situations lie somewhere between these
  1046. * two extremes.
  1047. */
  1048. function chainTest(n) {
  1049. planner = new Planner();
  1050. var prev = null, first = null, last = null;
  1051. // Build chain of n equality constraints
  1052. for (var i = 0; i <= n; i++) {
  1053. var name = "v" + i;
  1054. var v = new Variable(name);
  1055. if (prev != null)
  1056. new EqualityConstraint(prev, v, Strength.REQUIRED);
  1057. if (i == 0) first = v;
  1058. if (i == n) last = v;
  1059. prev = v;
  1060. }
  1061. new StayConstraint(last, Strength.STRONG_DEFAULT);
  1062. var edit = new EditConstraint(first, Strength.PREFERRED);
  1063. var edits = new OrderedCollection();
  1064. edits.add(edit);
  1065. var plan = planner.extractPlanFromConstraints(edits);
  1066. for (var i = 0; i < 100; i++) {
  1067. first.value = i;
  1068. plan.execute();
  1069. if (last.value != i)
  1070. alert("Chain test failed.");
  1071. }
  1072. }
  1073. /**
  1074. * This test constructs a two sets of variables related to each
  1075. * other by a simple linear transformation (scale and offset). The
  1076. * time is measured to change a variable on either side of the
  1077. * mapping and to change the scale and offset factors.
  1078. */
  1079. function projectionTest(n) {
  1080. planner = new Planner();
  1081. var scale = new Variable("scale", 10);
  1082. var offset = new Variable("offset", 1000);
  1083. var src = null, dst = null;
  1084. var dests = new OrderedCollection();
  1085. for (var i = 0; i < n; i++) {
  1086. src = new Variable("src" + i, i);
  1087. dst = new Variable("dst" + i, i);
  1088. dests.add(dst);
  1089. new StayConstraint(src, Strength.NORMAL);
  1090. new ScaleConstraint(src, scale, offset, dst, Strength.REQUIRED);
  1091. }
  1092. change(src, 17);
  1093. if (dst.value != 1170) alert("Projection 1 failed");
  1094. change(dst, 1050);
  1095. if (src.value != 5) alert("Projection 2 failed");
  1096. change(scale, 5);
  1097. for (var i = 0; i < n - 1; i++) {
  1098. if (dests.at(i).value != i * 5 + 1000)
  1099. alert("Projection 3 failed");
  1100. }
  1101. change(offset, 2000);
  1102. for (var i = 0; i < n - 1; i++) {
  1103. if (dests.at(i).value != i * 5 + 2000)
  1104. alert("Projection 4 failed");
  1105. }
  1106. }
  1107. function change(v, newValue) {
  1108. var edit = new EditConstraint(v, Strength.PREFERRED);
  1109. var edits = new OrderedCollection();
  1110. edits.add(edit);
  1111. var plan = planner.extractPlanFromConstraints(edits);
  1112. for (var i = 0; i < 10; i++) {
  1113. v.value = newValue;
  1114. plan.execute();
  1115. }
  1116. edit.destroyConstraint();
  1117. }
  1118. // Global variable holding the current planner.
  1119. var planner = null;
  1120. function deltaBlue() {
  1121. chainTest(100);
  1122. projectionTest(100);
  1123. }
  1124. ////////////////////////////////////////////////////////////////////////////////
  1125. // Runner
  1126. ////////////////////////////////////////////////////////////////////////////////
  1127. var success = true;
  1128. function NotifyStart(name) {
  1129. }
  1130. function NotifyError(name, error) {
  1131. WScript.Echo(name + " : ERROR : " +error.stack);
  1132. success = false;
  1133. }
  1134. function NotifyResult(name, score) {
  1135. if (success) {
  1136. WScript.Echo("### SCORE:", score);
  1137. }
  1138. }
  1139. function NotifyScore(score) {
  1140. }
  1141. BenchmarkSuite.RunSuites({
  1142. NotifyStart : NotifyStart,
  1143. NotifyError : NotifyError,
  1144. NotifyResult : NotifyResult,
  1145. NotifyScore : NotifyScore
  1146. });