| OLD | NEW |
| 1 var DeltaBlue; | 1 var DeltaBlue; |
| 2 (function(DeltaBlue) { | 2 (function(exports) { |
| 3 'use strict'; | 3 'use strict'; |
| 4 // Function main: () → dynamic | 4 // Function main: () → dynamic |
| 5 function main() { | 5 function main() { |
| 6 new DeltaBlue().report(); | 6 new DeltaBlue().report(); |
| 7 } | 7 } |
| 8 class DeltaBlue extends BenchmarkBase.BenchmarkBase { | 8 class DeltaBlue extends BenchmarkBase.BenchmarkBase { |
| 9 DeltaBlue() { | 9 DeltaBlue() { |
| 10 super.BenchmarkBase("DeltaBlue"); | 10 super.BenchmarkBase("DeltaBlue"); |
| 11 } | 11 } |
| 12 run() { | 12 run() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 41 let STRONG_DEFAULT = new Strength(3, "strongDefault"); | 41 let STRONG_DEFAULT = new Strength(3, "strongDefault"); |
| 42 let NORMAL = new Strength(4, "normal"); | 42 let NORMAL = new Strength(4, "normal"); |
| 43 let WEAK_DEFAULT = new Strength(5, "weakDefault"); | 43 let WEAK_DEFAULT = new Strength(5, "weakDefault"); |
| 44 let WEAKEST = new Strength(6, "weakest"); | 44 let WEAKEST = new Strength(6, "weakest"); |
| 45 class Constraint extends dart.Object { | 45 class Constraint extends dart.Object { |
| 46 Constraint(strength) { | 46 Constraint(strength) { |
| 47 this.strength = strength; | 47 this.strength = strength; |
| 48 } | 48 } |
| 49 addConstraint() { | 49 addConstraint() { |
| 50 this.addToGraph(); | 50 this.addToGraph(); |
| 51 DeltaBlue.planner.incrementalAdd(this); | 51 exports.planner.incrementalAdd(this); |
| 52 } | 52 } |
| 53 satisfy(mark) { | 53 satisfy(mark) { |
| 54 this.chooseMethod(dart.as(mark, core.int)); | 54 this.chooseMethod(dart.as(mark, core.int)); |
| 55 if (!dart.notNull(this.isSatisfied())) { | 55 if (!dart.notNull(this.isSatisfied())) { |
| 56 if (dart.equals(this.strength, REQUIRED)) { | 56 if (dart.equals(this.strength, REQUIRED)) { |
| 57 core.print("Could not satisfy a required constraint!"); | 57 core.print("Could not satisfy a required constraint!"); |
| 58 } | 58 } |
| 59 return null; | 59 return null; |
| 60 } | 60 } |
| 61 this.markInputs(dart.as(mark, core.int)); | 61 this.markInputs(dart.as(mark, core.int)); |
| 62 let out = this.output(); | 62 let out = this.output(); |
| 63 let overridden = out.determinedBy; | 63 let overridden = out.determinedBy; |
| 64 if (overridden !== null) | 64 if (overridden !== null) |
| 65 overridden.markUnsatisfied(); | 65 overridden.markUnsatisfied(); |
| 66 out.determinedBy = this; | 66 out.determinedBy = this; |
| 67 if (!dart.notNull(DeltaBlue.planner.addPropagate(this, dart.as(mark, core.
int)))) | 67 if (!dart.notNull(exports.planner.addPropagate(this, dart.as(mark, core.in
t)))) |
| 68 core.print("Cycle encountered"); | 68 core.print("Cycle encountered"); |
| 69 out.mark = dart.as(mark, core.int); | 69 out.mark = dart.as(mark, core.int); |
| 70 return overridden; | 70 return overridden; |
| 71 } | 71 } |
| 72 destroyConstraint() { | 72 destroyConstraint() { |
| 73 if (this.isSatisfied()) | 73 if (this.isSatisfied()) |
| 74 DeltaBlue.planner.incrementalRemove(this); | 74 exports.planner.incrementalRemove(this); |
| 75 this.removeFromGraph(); | 75 this.removeFromGraph(); |
| 76 } | 76 } |
| 77 isInput() { | 77 isInput() { |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 class UnaryConstraint extends Constraint { | 81 class UnaryConstraint extends Constraint { |
| 82 UnaryConstraint(myOutput, strength) { | 82 UnaryConstraint(myOutput, strength) { |
| 83 this.myOutput = myOutput; | 83 this.myOutput = myOutput; |
| 84 this.satisfied = false; | 84 this.satisfied = false; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 return this.list.length; | 366 return this.list.length; |
| 367 } | 367 } |
| 368 execute() { | 368 execute() { |
| 369 for (let i = 0; i < this.list.length; i++) { | 369 for (let i = 0; i < this.list.length; i++) { |
| 370 this.list.get(i).execute(); | 370 this.list.get(i).execute(); |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 // Function chainTest: (int) → void | 374 // Function chainTest: (int) → void |
| 375 function chainTest(n) { | 375 function chainTest(n) { |
| 376 DeltaBlue.planner = new Planner(); | 376 exports.planner = new Planner(); |
| 377 let prev = null, first = null, last = null; | 377 let prev = null, first = null, last = null; |
| 378 for (let i = 0; i <= n; i++) { | 378 for (let i = 0; i <= n; i++) { |
| 379 let v = new Variable("v", 0); | 379 let v = new Variable("v", 0); |
| 380 if (prev !== null) | 380 if (prev !== null) |
| 381 new EqualityConstraint(prev, v, REQUIRED); | 381 new EqualityConstraint(prev, v, REQUIRED); |
| 382 if (i === 0) | 382 if (i === 0) |
| 383 first = v; | 383 first = v; |
| 384 if (i === n) | 384 if (i === n) |
| 385 last = v; | 385 last = v; |
| 386 prev = v; | 386 prev = v; |
| 387 } | 387 } |
| 388 new StayConstraint(last, STRONG_DEFAULT); | 388 new StayConstraint(last, STRONG_DEFAULT); |
| 389 let edit = new EditConstraint(first, PREFERRED); | 389 let edit = new EditConstraint(first, PREFERRED); |
| 390 let plan = DeltaBlue.planner.extractPlanFromConstraints(new List.from([edit]
)); | 390 let plan = exports.planner.extractPlanFromConstraints(new List.from([edit]))
; |
| 391 for (let i = 0; i < 100; i++) { | 391 for (let i = 0; i < 100; i++) { |
| 392 first.value = i; | 392 first.value = i; |
| 393 plan.execute(); | 393 plan.execute(); |
| 394 if (last.value !== i) { | 394 if (last.value !== i) { |
| 395 core.print("Chain test failed:"); | 395 core.print("Chain test failed:"); |
| 396 core.print(`Expected last value to be ${i} but it was ${last.value}.`); | 396 core.print(`Expected last value to be ${i} but it was ${last.value}.`); |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 // Function projectionTest: (int) → void | 400 // Function projectionTest: (int) → void |
| 401 function projectionTest(n) { | 401 function projectionTest(n) { |
| 402 DeltaBlue.planner = new Planner(); | 402 exports.planner = new Planner(); |
| 403 let scale = new Variable("scale", 10); | 403 let scale = new Variable("scale", 10); |
| 404 let offset = new Variable("offset", 1000); | 404 let offset = new Variable("offset", 1000); |
| 405 let src = null, dst = null; | 405 let src = null, dst = null; |
| 406 let dests = new List.from([]); | 406 let dests = new List.from([]); |
| 407 for (let i = 0; i < n; i++) { | 407 for (let i = 0; i < n; i++) { |
| 408 src = new Variable("src", i); | 408 src = new Variable("src", i); |
| 409 dst = new Variable("dst", i); | 409 dst = new Variable("dst", i); |
| 410 dests.add(dst); | 410 dests.add(dst); |
| 411 new StayConstraint(src, NORMAL); | 411 new StayConstraint(src, NORMAL); |
| 412 new ScaleConstraint(src, scale, offset, dst, REQUIRED); | 412 new ScaleConstraint(src, scale, offset, dst, REQUIRED); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 424 } | 424 } |
| 425 change(offset, 2000); | 425 change(offset, 2000); |
| 426 for (let i = 0; i < n - 1; i++) { | 426 for (let i = 0; i < n - 1; i++) { |
| 427 if (dests.get(i).value !== i * 5 + 2000) | 427 if (dests.get(i).value !== i * 5 + 2000) |
| 428 core.print("Projection 4 failed"); | 428 core.print("Projection 4 failed"); |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 // Function change: (Variable, int) → void | 431 // Function change: (Variable, int) → void |
| 432 function change(v, newValue) { | 432 function change(v, newValue) { |
| 433 let edit = new EditConstraint(v, PREFERRED); | 433 let edit = new EditConstraint(v, PREFERRED); |
| 434 let plan = DeltaBlue.planner.extractPlanFromConstraints(new List.from([edit]
)); | 434 let plan = exports.planner.extractPlanFromConstraints(new List.from([edit]))
; |
| 435 for (let i = 0; i < 10; i++) { | 435 for (let i = 0; i < 10; i++) { |
| 436 v.value = newValue; | 436 v.value = newValue; |
| 437 plan.execute(); | 437 plan.execute(); |
| 438 } | 438 } |
| 439 edit.destroyConstraint(); | 439 edit.destroyConstraint(); |
| 440 } | 440 } |
| 441 DeltaBlue.planner = null; | 441 exports.planner = null; |
| 442 // Exports: | 442 // Exports: |
| 443 DeltaBlue.main = main; | 443 exports.main = main; |
| 444 DeltaBlue.DeltaBlue = DeltaBlue; | 444 exports.DeltaBlue = DeltaBlue; |
| 445 DeltaBlue.Strength = Strength; | 445 exports.Strength = Strength; |
| 446 DeltaBlue.REQUIRED = REQUIRED; | 446 exports.REQUIRED = REQUIRED; |
| 447 DeltaBlue.STRONG_PREFERRED = STRONG_PREFERRED; | 447 exports.STRONG_PREFERRED = STRONG_PREFERRED; |
| 448 DeltaBlue.PREFERRED = PREFERRED; | 448 exports.PREFERRED = PREFERRED; |
| 449 DeltaBlue.STRONG_DEFAULT = STRONG_DEFAULT; | 449 exports.STRONG_DEFAULT = STRONG_DEFAULT; |
| 450 DeltaBlue.NORMAL = NORMAL; | 450 exports.NORMAL = NORMAL; |
| 451 DeltaBlue.WEAK_DEFAULT = WEAK_DEFAULT; | 451 exports.WEAK_DEFAULT = WEAK_DEFAULT; |
| 452 DeltaBlue.WEAKEST = WEAKEST; | 452 exports.WEAKEST = WEAKEST; |
| 453 DeltaBlue.Constraint = Constraint; | 453 exports.Constraint = Constraint; |
| 454 DeltaBlue.UnaryConstraint = UnaryConstraint; | 454 exports.UnaryConstraint = UnaryConstraint; |
| 455 DeltaBlue.StayConstraint = StayConstraint; | 455 exports.StayConstraint = StayConstraint; |
| 456 DeltaBlue.EditConstraint = EditConstraint; | 456 exports.EditConstraint = EditConstraint; |
| 457 DeltaBlue.NONE = NONE; | 457 exports.NONE = NONE; |
| 458 DeltaBlue.FORWARD = FORWARD; | 458 exports.FORWARD = FORWARD; |
| 459 DeltaBlue.BACKWARD = BACKWARD; | 459 exports.BACKWARD = BACKWARD; |
| 460 DeltaBlue.BinaryConstraint = BinaryConstraint; | 460 exports.BinaryConstraint = BinaryConstraint; |
| 461 DeltaBlue.ScaleConstraint = ScaleConstraint; | 461 exports.ScaleConstraint = ScaleConstraint; |
| 462 DeltaBlue.EqualityConstraint = EqualityConstraint; | 462 exports.EqualityConstraint = EqualityConstraint; |
| 463 DeltaBlue.Variable = Variable; | 463 exports.Variable = Variable; |
| 464 DeltaBlue.Planner = Planner; | 464 exports.Planner = Planner; |
| 465 DeltaBlue.Plan = Plan; | 465 exports.Plan = Plan; |
| 466 DeltaBlue.chainTest = chainTest; | 466 exports.chainTest = chainTest; |
| 467 DeltaBlue.projectionTest = projectionTest; | 467 exports.projectionTest = projectionTest; |
| 468 DeltaBlue.change = change; | 468 exports.change = change; |
| 469 })(DeltaBlue || (DeltaBlue = {})); | 469 })(DeltaBlue || (DeltaBlue = {})); |
| OLD | NEW |