Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v0.2.2

* Performance Upgrades
  * Added BetaNode indexing
  * Abstracted out JoinNode to extend BetaNode (Prevents the checking of constraints if there are not any constraints to check)
  * Refactored BetaNetwork
  * Created a new Memory Class to encapusulate left and right memory for BetaNodes
* Added new `exists` logic operator to check for existence of fact (opposite of `not`)
  • Loading branch information...
commit 11f79aa366cac166f222538e21b20f10f28eb8ef 1 parent 86eea5e
@doug-martin doug-martin authored
Showing with 13,336 additions and 8,722 deletions.
  1. +2 −0  docs-md/examples.md
  2. +11 −0 docs/History.html
  3. +2 −0  docs/examples.html
  4. +86 −20 docs/examples/browser/assets/conways.css
  5. +56 −70 docs/examples/browser/diagnose.html
  6. +3 −3 docs/examples/browser/fibonacci.html
  7. +35 −46 docs/examples/browser/manners.html
  8. +16 −0 docs/examples/browser/rules/sendMoreMoney.nools
  9. +106 −0 docs/examples/browser/sendMoreMoney.html
  10. +1 −1  docs/examples/browser/src/common.js
  11. +35 −23 docs/examples/browser/src/sudoku.js
  12. +26 −32 docs/examples/browser/sudoku.html
  13. +34 −44 docs/examples/browser/waltzDb.html
  14. +31 −1 docs/index.html
  15. +9 −8 docs/nools.js
  16. +86 −20 examples/browser/assets/conways.css
  17. +56 −70 examples/browser/diagnose.html
  18. +3 −3 examples/browser/fibonacci.html
  19. +35 −46 examples/browser/manners.html
  20. +16 −0 examples/browser/rules/sendMoreMoney.nools
  21. +106 −0 examples/browser/sendMoreMoney.html
  22. +1 −1  examples/browser/src/common.js
  23. +35 −23 examples/browser/src/sudoku.js
  24. +26 −32 examples/browser/sudoku.html
  25. +34 −44 examples/browser/waltzDb.html
  26. +9 −0 history.md
  27. +0 −1  lib/agenda.js
  28. +2 −1  lib/conflict.js
  29. +50 −15 lib/constraint.js
  30. +83 −19 lib/constraintMatcher.js
  31. +13 −1 lib/context.js
  32. +97 −1 lib/extended.js
  33. +27 −0 lib/linkedList.js
  34. +35 −0 lib/nodes/adapterNode.js
  35. +234 −0 lib/nodes/betaNode.js
  36. +3 −17 lib/nodes/equalityNode.js
  37. +99 −0 lib/nodes/existsFromNode.js
  38. +173 −0 lib/nodes/existsNode.js
  39. +5 −8 lib/nodes/fromNode.js
  40. +6 −12 lib/nodes/fromNotNode.js
  41. +24 −10 lib/nodes/index.js
  42. +16 −243 lib/nodes/joinNode.js
  43. +40 −75 lib/nodes/joinReferenceNode.js
  44. +1 −1  lib/nodes/leftAdapterNode.js
  45. +12 −0 lib/nodes/misc/leftMemory.js
  46. +219 −0 lib/nodes/misc/memory.js
  47. +12 −0 lib/nodes/misc/rightMemory.js
  48. +5 −7 lib/nodes/node.js
  49. +102 −115 lib/nodes/notNode.js
  50. +1 −1  lib/nodes/rightAdapterNode.js
  51. +1 −7 lib/nodes/terminalNode.js
  52. +2 −1  lib/nodes/typeNode.js
  53. +8 −6 lib/parser/nools/tokens.js
  54. +3 −1 lib/pattern.js
  55. +29 −1 lib/rule.js
  56. +8,908 −6,001 nools.js
  57. +9 −8 nools.min.js
  58. +2 −2 package.json
  59. +45 −0 readme.md
  60. +1 −1  test/browserling.js
  61. +65 −8 test/constraintMatcher.test.js
  62. +1 −3 test/flow.dsl.test.js
  63. +0 −1,667 test/flow.test.js
  64. +158 −0 test/flow/agendaGroups.test.js
  65. +45 −0 test/flow/async.test.js
  66. +77 −0 test/flow/events.test.js
  67. +291 −0 test/flow/exists.test.js
  68. +565 −0 test/flow/from.test.js
  69. +14 −0 test/flow/index.js
  70. +131 −0 test/flow/leftMemory.test.js
  71. +65 −0 test/flow/matchUntil.halt.js
  72. +185 −0 test/flow/not.test.js
  73. +176 −0 test/flow/or.test.js
  74. +130 −0 test/flow/rightMemory.test.js
  75. +49 −0 test/flow/rule.test.js
  76. +59 −0 test/flow/salience.test.js
  77. +49 −0 test/flow/scope.test.js
  78. +29 −0 test/flow/simple.test.js
  79. +67 −0 test/nools.test.js
  80. +20 −0 test/noolsParser.test.js
  81. +33 −2 test/rules.test.js
View
2  docs-md/examples.md
@@ -5,4 +5,6 @@
* [Sudoku](./examples/browser/sudoku.html)
* [Fibonacci](./examples/browser/fibonacci.html)
* [Miss Manners](./examples/browser/manners.html)
+ * [Waltz DB](./examples/browser/waltzDb.html)
+ * [Send More Money](./examples/browser/sendMoreMoney.html)
* [Diagnosis](./examples/browser/diagnose.html)
View
11 docs/History.html
@@ -178,6 +178,17 @@
+<h1>0.2.2</h1>
+<ul>
+<li>Performance Upgrades<ul>
+<li>Added BetaNode indexing</li>
+<li>Abstracted out JoinNode to extend BetaNode (Prevents the checking of constraints if there are not any constraints to check)</li>
+<li>Refactored BetaNetwork</li>
+<li>Created a new Memory Class to encapusulate left and right memory for BetaNodes</li>
+</ul>
+</li>
+<li>Added new <code>exists</code> logic operator to check for existence of fact (opposite of <code>not</code>)</li>
+</ul>
<h1>0.2.1</h1>
<ul>
<li>Added support for js expression in the <code>from</code> node addressing issue <a href="https://github.com/C2FO/nools/issues/86">#86</a></li>
View
2  docs/examples.html
@@ -185,6 +185,8 @@
<li><a href="./examples/browser/sudoku.html">Sudoku</a></li>
<li><a href="./examples/browser/fibonacci.html">Fibonacci</a></li>
<li><a href="./examples/browser/manners.html">Miss Manners</a></li>
+<li><a href="./examples/browser/waltzDb.html">Waltz DB</a></li>
+<li><a href="./examples/browser/sendMoreMoney.html">Send More Money</a></li>
<li><a href="./examples/browser/diagnose.html">Diagnosis</a></li>
</ul>
View
106 docs/examples/browser/assets/conways.css
@@ -16,45 +16,91 @@ body {
height: 100%;
}
-#fibonacci div.inline {
+.fibonacci div.inline {
height: 100%;
margin: 10px;
}
-#fibonacci #results_container {
+.fibonacci .results_container {
word-wrap: break-word;
max-width: 100%;
line-height: 50px;
}
-#diagnose {
- width: 500px;
- padding: 10px;
- border: 1px solid rgba(0, 0, 0, 0.1);
- -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+.diagnose {
+ width: 100%;
}
-#manners {
- width: 50%;
+.diagnose .diagnose-container{
+ width: 49%;
+ vertical-align: top;
padding: 10px;
- border: 1px solid rgba(0, 0, 0, 0.1);
- -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+}
+.waltz-db,
+.manners {
+ width: 100%;
}
-#manners #results_container {
+.waltz-db .editor-container,
+.manners .editor-container,
+.diagnose .editor-container,
+.send-more-money .editor-container {
+ width: 49%;
+ height: 100%;
+ display: inline-block;
+}
+
+.waltz-db .results_container,
+.manners .results_container {
+ width: 49%;
+ vertical-align: top;
+ display: inline-block;
+ height: 100%;
overflow: auto;
- height: 400px;
- width: 95%;
background: #dfdfdf;
color: #09C;
font-family: Tahoma, Geneva, sans-serif;
+ padding-left: 10px;
+}
+
+.editor-container {
+ width: 100%;
+ height: 400px;
+ position: relative;
+ border: 1px solid lightgray;
+}
+
+.editor-container .editor {
+ width: 100%;
+ height: 100%;
+ position: relative;
+}
+
+.send-more-money {
+ width: 100%;
+}
+
+.send-more-money .equation-container {
+ vertical-align: top;
+ width: 49%;
+}
+
+.send-more-money .equation {
+ font-size: 6em;
+ text-align: right;
+ width: 400px;
+}
+
+.send-more-money .equation > div > span {
+ width: 30px;
+ display: inline-block;
+ height: 50px;
padding: 10px;
- border-radius: 10px;
+}
+
+.send-more-money .equation > div:last-child {
+ border-top: solid black 1px;
}
.container > header {
@@ -108,6 +154,12 @@ input[type="submit"], input[type="button"] {
margin: 10px;
}
+input[type="submit"]:disabled,
+input[type="button"]:disabled {
+ background-color: lightgray;
+ cursor: not-allowed;
+}
+
#grid {
overflow: hidden;
@@ -136,6 +188,7 @@ input[type="submit"], input[type="button"] {
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
position: absolute;
bottom: 5px;
+ right: 5px;
}
.row {
@@ -152,6 +205,10 @@ input[type="submit"], input[type="button"] {
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
}
+.sudoku {
+ width: 100%;
+}
+
.sudoku .col {
width: 50px;
height: 50px;
@@ -164,11 +221,20 @@ input[type="submit"], input[type="button"] {
background-color: rgba(255, 0, 0, 0.43);
}
-.sudoku #grid{
+.sudoku #grid {
width: 465px;
height: 470px;
}
+.sudoku .grid-container {
+ vertical-align: top;
+ width: 49%;
+}
+
+.sudoku .editor-container {
+ width: 49%;
+}
+
.col.live {
background-color: black;
}
View
126 docs/examples/browser/diagnose.html
@@ -11,56 +11,58 @@
<body>
-<div id="diagnose" class="middle">
- <h1>Diagnose Me <input type="button" id="edit" value="Edit Rules"/></h1>
-
-
- <form action="#">
- <div class="errors"></div>
- <label for="name">Patient Name</label>
- <input type="text" id="name"/>
- <label for="fever">Fever</label>
- <select id="fever">
- <option value="">None</option>
- <option value="high">High</option>
- <option value="mild">Mild</option>
- </select>
-
- <div>
- <label for="spots">Spots</label>
- <input type="checkbox" id="spots"/>
- </div>
- <div>
- <label for="rash">Rash</label>
- <input type="checkbox" id="rash"/>
- </div>
- <div>
- <label for="sore_throat">Sore Throat</label>
- <input type="checkbox" id="sore_throat"/>
- </div>
- <div>
- <label for="innoculated">Innoculated</label>
- <input type="checkbox" id="innoculated"/>
- </div>
- <input type="submit" value="Diagnose"/>
- </form>
- <hr/>
- <h2>Diagnoses</h2>
-
- <div id="results_container"></div>
+<div class="diagnose middle">
+ <div class="header">
+ <h1>Diagnose Me</h1>
+ </div>
+
+ <div class="editor-container">
+ <div id="editor"></div>
+ </div>
+
+ <div class="diagnose-container inline">
+ <form action="#">
+ <div class="errors"></div>
+ <label for="name">Patient Name</label>
+ <input type="text" id="name"/>
+ <label for="fever">Fever</label>
+ <select id="fever">
+ <option value="">None</option>
+ <option value="high">High</option>
+ <option value="mild">Mild</option>
+ </select>
+
+ <div>
+ <label for="spots">Spots</label>
+ <input type="checkbox" id="spots"/>
+ </div>
+ <div>
+ <label for="rash">Rash</label>
+ <input type="checkbox" id="rash"/>
+ </div>
+ <div>
+ <label for="sore_throat">Sore Throat</label>
+ <input type="checkbox" id="sore_throat"/>
+ </div>
+ <div>
+ <label for="innoculated">Innoculated</label>
+ <input type="checkbox" id="innoculated"/>
+ </div>
+ <input type="submit" value="Diagnose"/>
+ </form>
+ <hr/>
+ <h2>Diagnoses</h2>
+
+ <div id="results_container"></div>
+ </div>
</div>
-<div id="editor-dialog">
- <div id="editor"></div>
-</div>
-
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
-<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
<script type="text/javascript" src="../../nools.js"></script>
<script type="text/javascript" src="./src/common.js"></script>
-<script type="text/javascript" src="./src/guests.js"></script>
<script type="text/javascript">
$(document).ready(function () {
@@ -126,35 +128,19 @@
return false;
});
- $("#edit").on("click", function () {
- $("#editor-dialog").dialog("open");
- return false;
- });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var session = editor.getSession();
+ session.setMode("ace/mode/javascript");
+ session.setValue(res);
+ editor.setReadOnly(true);
- $("#editor-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: window.innerWidth * 0.9,
- height: window.innerHeight * 0.9,
- open: function () {
- (editor = ace.edit("editor").getSession()).setValue(flowStr);
- },
- buttons: {
- "Save": function () {
- $(this).dialog("close");
- nools.deleteFlow("diagnosis");
- stop();
- flow = nools.compile((flowStr = editor.getValue()), {name: "diagnosis"});
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
});
- })
- ;
+ });
</script>
</body>
View
6 docs/examples/browser/fibonacci.html
@@ -9,7 +9,7 @@
</head>
<body>
-<div id="fibonacci" class="middle">
+<div class="fibonacci middle">
<h1>Fibonacci</h1>
@@ -20,7 +20,7 @@
<div class="inline">
<div class="large"><span>=</span></div>
</div>
- <div class="inline large" id="results_container">
+ <div class="inline large results_container">
</div>
</form>
</div>
@@ -90,7 +90,7 @@
}
- var resultsContainer = $("#results_container"), valInput = $("#val");
+ var resultsContainer = $(".results_container"), valInput = $("#val");
$("#fibonacci_form").on('submit', function () {
var num = parseInt(valInput.val(), 10);
resultsContainer.text("Calculating...");
View
81 docs/examples/browser/manners.html
@@ -4,43 +4,42 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" rel="stylesheet" href="assets/conways.css">
- <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
<title>Manners Benchmark</title>
</head>
<body>
-<div id="manners" class="middle">
- <h1>Manners Benchmark</h1>
+<div class="middle manners">
+ <div class="header">
+ <h1 class="inline">Manners Benchmark</h1>
- <form>
+ <form class="inline">
+ <select id="guests">
+ <option value="manners5">Manners 5</option>
+ <option value="manners8">Manners 8</option>
+ <option value="manners16">Manners 16</option>
+ <option value="manners32">Manners 32</option>
+ <option value="manners64">Manners 64</option>
+ <option value="manners128">Manners 128</option>
+ </select>
+ <input type="submit" value="Run"/>
+ </form>
+ </div>
- <select id="guests">
- <option value="manners5">Manners 5</option>
- <option value="manners8">Manners 8</option>
- <option value="manners16">Manners 16</option>
- <option value="manners32">Manners 32</option>
- <option value="manners64">Manners 64</option>
- <option value="manners128">Manners 128</option>
- </select>
- <input type="submit" value="Run"/>
- <input type="button" id="edit" value="Edit Rules"/>
+ <div class="editor-container">
+ <div id="editor"></div>
+ </div>
- <div class="middle" id="results_container">
- </div>
-
- </form>
+ <div class="results_container">
+ </div>
</div>
-<div id="editor-dialog">
- <div id="editor"></div>
-</div>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
-<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
<script type="text/javascript" src="../../nools.js"></script>
<script type="text/javascript" src="./src/common.js"></script>
<script type="text/javascript" src="./src/guests.js"></script>
@@ -52,7 +51,7 @@
}).then(function (res) {
var session, dataset,
- resultsContainer = $("#results_container"),
+ resultsContainer = $(".results_container"),
statsListener = stats(),
flowStr = res,
flow = nools.compile(res, {name: "manners"}),
@@ -83,6 +82,7 @@
session
.on("pathDone", function (obj) {
resultsContainer.append(createSeat(obj.seating));
+ resultsContainer.scrollTop(resultsContainer.prop("scrollHeight"));
})
.match().then(function () {
console.log("done");
@@ -114,30 +114,19 @@
return false;
});
- $("#editor-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: window.innerWidth * 0.9,
- height: window.innerHeight * 0.9,
- open: function () {
- (editor = ace.edit("editor").getSession()).setValue(flowStr);
- },
- buttons: {
- "Save": function () {
- $(this).dialog("close");
- nools.deleteFlow("manners");
- stop();
- flow = nools.compile((flowStr = editor.getValue()), {name: "manners"});
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+ resultsContainer.height(height);
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var editorSession = editor.getSession();
+ editorSession.setMode("ace/mode/javascript");
+ editorSession.setValue(res);
+ editor.setReadOnly(true);
});
- })
- ;
+ });
</script>
</body>
View
16 docs/examples/browser/rules/sendMoreMoney.nools
@@ -0,0 +1,16 @@
+rule SendMoreMoney {
+ when {
+ s : Number s != 0;
+ e : Number e != s;
+ n : Number n != s && n != e;
+ d : Number d != s && d != e && d != n;
+ m : Number m != 0 && m != s && m != e && m != n && m != d;
+ o : Number o != s && o != e && o != n && o != d && o != m;
+ r : Number r != s && r != e && r != n && r != d && r != m && r != o;
+ y : Number y != s && y != e && y != n && y != d && y != m && y != o && y != r
+ && (s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e) == (m*10000 + o*1000 + n*100 + e*10 + y);
+ }
+ then {
+ emit("solved", {s : s, e : e, n : n, d : d, m : m, o: o, r : r, y : y});
+ }
+}
View
106 docs/examples/browser/sendMoreMoney.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link type="text/css" rel="stylesheet" href="assets/conways.css">
+ <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
+ <link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
+ <title>Send More Money Benchmark</title>
+</head>
+<body>
+
+
+<div class="middle send-more-money">
+ <div class="header">
+ <h1>Send More Money</h1>
+ <span class="error"><b>Warning:</b> This can take a while!</span>
+ </div>
+
+ <div class="editor-container">
+ <div id="editor"></div>
+ </div>
+ <div class="inline equation-container">
+ <div class="equation middle">
+ <div>
+ <span></span>
+ <span></span>
+ <span class="s-val">S</span>
+ <span class="e-val">E</span>
+ <span class="n-val">N</span>
+ <span class="d-val">D</span>
+ </div>
+ <div>
+ <span>+</span>
+ <span></span>
+ <span class="m-val">M</span>
+ <span class="o-val">O</span>
+ <span class="r-val">R</span>
+ <span class="e-val">E</span>
+ </div>
+ <div>
+ <span></span>
+ <span class="m-val">M</span>
+ <span class="o-val">O</span>
+ <span class="n-val">N</span>
+ <span class="e-val">E</span>
+ <span class="y-val">Y</span>
+ </div>
+ </div>
+ <input class="middle calc-button" type="button" value="Calculate"/>
+ </div>
+</div>
+
+<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
+<script type="text/javascript" src="../../nools.js"></script>
+<script type="text/javascript">
+
+ $(document).ready(function () {
+ $.ajax({
+ url: "./rules/sendMoreMoney.nools"
+ }).then(function (res) {
+
+ var flow = nools.compile(res, {name: "SendMoreMoney"}),
+ calcButton = $("input.calc-button"),
+ letters = ["s", "e", "n", "d", "m", "o", "r", "y"];
+
+ function calc() {
+ session;
+ (session = flow.getSession(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
+ .on("solved",function (solved) {
+ for (var i in solved) {
+ $("." + i + "-val").text(solved[i]);
+ }
+ calcButton.val("Calculated");
+ }).match().then(function () {
+ session.dispose();
+ });
+ }
+
+ calcButton.on("click", function () {
+ calcButton.attr("disabled", "disabled");
+ calcButton.val("Calculating");
+ for (var i = 0, l = letters.length; i < l; i++) {
+ $("." + letters[i] + "-val").text("#");
+ }
+ setTimeout(calc, 100);
+ });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var session = editor.getSession();
+ session.setMode("ace/mode/javascript");
+ session.setValue(res);
+ editor.setReadOnly(true);
+
+
+ });
+ });
+</script>
+
+</body>
+</html>
View
2  docs/examples/browser/src/common.js
@@ -64,7 +64,7 @@
}
setInterval(function () {
- runningTimeSpan.text("running Time:" + Math.round(transCum / 1000 / 60) + "min");
+ runningTimeSpan.text("running time:" + Math.round(transCum / 1000 / 60) + "min");
firesSpan.text('rules fired: : ' + fires);
retractionsSpan.text('facts retracted: ' + retractions);
modifiesSpan.text('facts modified: ' + modified);
View
58 docs/examples/browser/src/sudoku.js
@@ -6,6 +6,13 @@
var allNine = [1, 2, 3, 4, 5, 6, 7, 8, 9];
+ if (typeof console === 'undefined') {
+ console = {
+ log: function () {
+ }
+ };
+ }
+
var SetOfNine = declare({
instance: {
@@ -102,7 +109,7 @@
},
valueAsString: function () {
- return this.value === null ? " ": this.value;
+ return this.value === null ? " " : this.value;
},
posAsString: function () {
@@ -206,35 +213,39 @@
},
step: function () {
- this.session.modify(this.counter, function () {
- this.count = 1;
- });
- if (!this.stepping) {
- this.session.assert(new Stepping());
- }
- return this.session.matchUntilHalt(function (err) {
- if (err) {
- console.log(err);
+ if (!this.invalid) {
+ this.session.modify(this.counter, function () {
+ this.count = 1;
+ });
+ if (!this.stepping) {
+ this.session.assert(new Stepping());
}
- });
+ return this.session.matchUntilHalt(function (err) {
+ if (err) {
+ console.log(err);
+ }
+ });
+ }
},
solve: function () {
- this.session.modify(this.counter, function () {
- this.count = Infinity;
- });
- if (this.stepping) {
- this.session.retract(this.stepping);
- }
- return this.session.match(function (err) {
- if (err) {
- console.log(err);
+ if (!this.invalid) {
+ this.session.modify(this.counter, function () {
+ this.count = Infinity;
+ });
+ if (this.stepping) {
+ this.session.retract(this.stepping);
}
- });
+ return this.session.match(function (err) {
+ if (err) {
+ console.log(err);
+ }
+ });
+ }
},
setCellValue: function setCellValue(cell) {
- cell.el.text(cell.value ? cell.value: "");
+ cell.el.text(cell.value ? cell.value : "");
return cell;
},
@@ -296,7 +307,6 @@
if (value) {
session.assert(new Setting(iRow, iCol, value));
initial++;
- //console.log(initial);
}
}
}
@@ -340,11 +350,13 @@
},
setInvalidCellValue: function setCellValue(cell) {
+ this.invalid = true;
cell.el.addClass("error");
return cell;
},
validate: function () {
+ this.invalid = false;
this.session.assert("validate");
return this.session.focus("validate")
.on("invalid", this.setInvalidCellValue)
View
58 docs/examples/browser/sudoku.html
@@ -11,28 +11,32 @@
<body>
<div class="container sudoku">
- <header>
- <h1>Sudoku</h1>
+ <div class="header">
+ <h1 class="inline">Sudoku</h1>
- <form>
- <input type="submit" id="run" value="Run!"/>
+ <form class="inline">
+ <input type="submit" id="run" value="Solve!"/>
<input type="button" id="step" value="Step"/>
<input type="button" id="stop" value="Stop"/>
<input type="button" id="clear" value="Clear"/>
- <input type="button" id="edit" value="Edit Rules"/>
<select id="patterns"></select>
</form>
- </header>
- <div id="grid"></div>
-</div>
+ </div>
+
+ <div class="editor-container inline">
+ <div id="editor"></div>
+ </div>
+
+ <div class="grid-container inline">
+ <div id="grid"></div>
+ </div>
+
-<div id="editor-dialog">
- <div id="editor"></div>
</div>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
-<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
<script type="text/javascript" src="../../nools.js"></script>
<script type="text/javascript" src="assets/declare.js"></script>
<script type="text/javascript" src="assets/extender.js"></script>
@@ -44,7 +48,6 @@
<script type="text/javascript" src="src/common.js"></script>
<script type="text/javascript" src="src/sudokuPatterns.js"></script>
<script type="text/javascript" src="src/sudoku.js"></script>
-<!--<script type="text/javascript" src="rules/sudoku.js"></script>-->
<script type="text/javascript">
(function () {
@@ -117,25 +120,16 @@
return false;
});
- $("#editor-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: window.innerWidth * 0.9,
- height: window.innerHeight * 0.9,
- open: function () {
- (editor = ace.edit("editor").getSession()).setValue(flowStr);
- },
- buttons: {
- "Save": function () {
- $(this).dialog("close");
- nools.deleteFlow("sudoku");
- flow = nools.compile((flowStr = editor.getValue()), {name: "sudoku", define: {Cell: Cell}, scope: { loop: loop}});
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var session = editor.getSession();
+ session.setMode("ace/mode/javascript");
+ session.setValue(flowStr);
+ editor.setReadOnly(true);
});
});
View
78 docs/examples/browser/waltzDb.html
@@ -4,41 +4,40 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" rel="stylesheet" href="assets/conways.css">
- <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
<title>WaltzDB Benchmark</title>
</head>
<body>
-<div id="manners" class="middle">
- <h1>WaltzDB Benchmark</h1>
+<div class="middle waltz-db">
+ <div class="header">
+ <h1 class="inline">WaltzDB Benchmark</h1>
- <form>
+ <form class="inline">
- <select id="data">
- <option value="waltzdb4">Waltzdb 4</option>
- <option value="waltzdb8">Waltzdb 8</option>
- <option value="waltzdb12">Waltzdb 12</option>
- <option value="waltzdb16">Waltzdb 16</option>
- </select>
- <input type="submit" value="Run"/>
- <input type="button" id="edit" value="Edit Rules"/>
+ <select id="data">
+ <option value="waltzdb4">Waltzdb 4</option>
+ <option value="waltzdb8">Waltzdb 8</option>
+ <option value="waltzdb12">Waltzdb 12</option>
+ <option value="waltzdb16">Waltzdb 16</option>
+ </select>
+ <input type="submit" value="Run"/>
- <div class="middle" id="results_container">
- </div>
+ </form>
+ </div>
- </form>
+ <div class="editor-container">
+ <div id="editor"></div>
+ </div>
+ <div class="results_container"></div>
</div>
-<div id="editor-dialog">
- <div id="editor"></div>
-</div>
-
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
-<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
+
<script type="text/javascript" src="../../nools.js"></script>
<script type="text/javascript" src="./src/common.js"></script>
<script type="text/javascript" src="./src/watlzdbData.js"></script>
@@ -50,10 +49,11 @@
}).then(function (res) {
var session, dataset,
- resultsContainer = $("#results_container"),
+ resultsContainer = $(".results_container"),
statsListener = stats(),
flowStr = res,
- flow = nools.compile(res, {name: "waltzDb"});
+ flow = nools.compile(res, {name: "waltzDb"})
+ .conflictResolution(["salience", "factRecency", "activationRecency"]);
function stop() {
if (session) {
@@ -81,7 +81,7 @@
session
.on("log", function (data) {
resultsContainer.append(data + "</br>");
- resultsContainer.scrollTop(resultsContainer.scrollHeight);
+ resultsContainer.scrollTop(resultsContainer.prop("scrollHeight"));
})
.match().then(function () {
console.profileEnd();
@@ -114,26 +114,16 @@
return false;
});
- $("#editor-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: window.innerWidth * 0.9,
- height: window.innerHeight * 0.9,
- open: function () {
- (editor = ace.edit("editor").getSession()).setValue(flowStr);
- },
- buttons: {
- "Save": function () {
- $(this).dialog("close");
- nools.deleteFlow("manners");
- stop();
- flow = nools.compile((flowStr = editor.getValue()), {name: "manners"});
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+ resultsContainer.height(height);
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var editorSession = editor.getSession();
+ editorSession.setMode("ace/mode/javascript");
+ editorSession.setValue(res);
+ editor.setReadOnly(true);
});
});
View
32 docs/index.html
@@ -218,6 +218,7 @@
<li><a href="#not-constraint">Not</a></li>
<li><a href="#or-constraint">Or</a></li>
<li><a href="#from-constraint">From</a></li>
+<li><a href="#exists-constraint">Exists</a></li>
</ul>
</li>
<li><a href="#action">Actions</a></li>
@@ -231,7 +232,17 @@
<h2>Resources</h2>
<ul>
<li><a href="https://groups.google.com/forum/#!forum/nools">Nools Google group</a></li>
-<li><a href="http://c2fo.github.io/nools/examples.html">Examples</a></li>
+<li><a href="http://c2fo.github.io/nools/examples.html">Examples</a><ul>
+<li><a href="http://c2fo.github.io/nools/examples/browser/conways_2d.html">Conways 2D</a></li>
+<li><a href="http://c2fo.github.io/nools/examples/browser/conways_3d.html">Conways 3D</a></li>
+<li><a href="http://c2fo.github.io/nools/examples/browser/sudoku.html">Sudoku</a></li>
+<li><a href="http://c2fo.github.io/nools/examples/browser/fibonacci.html">Fibonacci</a></li>
+<li><a href="http://c2fo.github.io/nools/examples/browser/manners.html">Miss Manners</a></li>
+<li><a href="http://c2fo.github.io/nools/examples/browser/waltzDb.html">Waltz DB</a></li>
+<li><a href="http://c2fo.github.io/nools/examples/browser/sendMoreMoney.html">Send More Money</a></li>
+<li><a href="http://c2fo.github.io/nools/examples/browser/diagnose.html">Diagnosis</a></li>
+</ul>
+</li>
<li><a href="https://github.com/C2FO/nools/tree/master/test">Tests</a></li>
</ul>
<p><a name="flow"></a></p>
@@ -1199,6 +1210,25 @@
assert(n1);
}
}</code></pre>
+<p><a name="exists-constraint"></a></p>
+<h3>Exists Constraint</h3>
+<p><code>exists</code> is the logical inversion of a <code>not</code> constraint. It checks for the existence of a fact in memory.</p>
+<p> <strong>NOTE</strong> If there are multiple facts that satisfy the constraint the rule will <strong>ONLY</strong> be fired once.</p>
+<pre class='prettyprint linenums lang-js'><code class="lang-javascript">
+ [
+ [&quot;exists&quot;, Number, &quot;n1&quot;, &quot;n1 &gt; 1&quot;]
+ ]</code></pre>
+<p> Or using the DSL.</p>
+<pre class='prettyprint linenums lang-js'><code>
+ when {
+ exists(n1: Number n1 &gt; 1);
+ }</code></pre>
+<p> Assuming the above constraint. The following facts would cause the rule to fire once since there is a number that is greater than 1.</p>
+<pre class='prettyprint linenums lang-js'><code class="lang-javascript"> session.assert(1);
+ session.assert(2);
+ session.assert(3);
+ session.assert(4);
+ session.assert(5);</code></pre>
<p><a name="action"></a></p>
<h3>Action</h3>
<p>The action is a function that should be fired when all patterns in the rule match. The action is called in the scope
View
17 docs/nools.js
9 additions, 8 deletions not shown
View
106 examples/browser/assets/conways.css
@@ -16,45 +16,91 @@ body {
height: 100%;
}
-#fibonacci div.inline {
+.fibonacci div.inline {
height: 100%;
margin: 10px;
}
-#fibonacci #results_container {
+.fibonacci .results_container {
word-wrap: break-word;
max-width: 100%;
line-height: 50px;
}
-#diagnose {
- width: 500px;
- padding: 10px;
- border: 1px solid rgba(0, 0, 0, 0.1);
- -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+.diagnose {
+ width: 100%;
}
-#manners {
- width: 50%;
+.diagnose .diagnose-container{
+ width: 49%;
+ vertical-align: top;
padding: 10px;
- border: 1px solid rgba(0, 0, 0, 0.1);
- -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
- box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1);
+}
+.waltz-db,
+.manners {
+ width: 100%;
}
-#manners #results_container {
+.waltz-db .editor-container,
+.manners .editor-container,
+.diagnose .editor-container,
+.send-more-money .editor-container {
+ width: 49%;
+ height: 100%;
+ display: inline-block;
+}
+
+.waltz-db .results_container,
+.manners .results_container {
+ width: 49%;
+ vertical-align: top;
+ display: inline-block;
+ height: 100%;
overflow: auto;
- height: 400px;
- width: 95%;
background: #dfdfdf;
color: #09C;
font-family: Tahoma, Geneva, sans-serif;
+ padding-left: 10px;
+}
+
+.editor-container {
+ width: 100%;
+ height: 400px;
+ position: relative;
+ border: 1px solid lightgray;
+}
+
+.editor-container .editor {
+ width: 100%;
+ height: 100%;
+ position: relative;
+}
+
+.send-more-money {
+ width: 100%;
+}
+
+.send-more-money .equation-container {
+ vertical-align: top;
+ width: 49%;
+}
+
+.send-more-money .equation {
+ font-size: 6em;
+ text-align: right;
+ width: 400px;
+}
+
+.send-more-money .equation > div > span {
+ width: 30px;
+ display: inline-block;
+ height: 50px;
padding: 10px;
- border-radius: 10px;
+}
+
+.send-more-money .equation > div:last-child {
+ border-top: solid black 1px;
}
.container > header {
@@ -108,6 +154,12 @@ input[type="submit"], input[type="button"] {
margin: 10px;
}
+input[type="submit"]:disabled,
+input[type="button"]:disabled {
+ background-color: lightgray;
+ cursor: not-allowed;
+}
+
#grid {
overflow: hidden;
@@ -136,6 +188,7 @@ input[type="submit"], input[type="button"] {
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
position: absolute;
bottom: 5px;
+ right: 5px;
}
.row {
@@ -152,6 +205,10 @@ input[type="submit"], input[type="button"] {
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
}
+.sudoku {
+ width: 100%;
+}
+
.sudoku .col {
width: 50px;
height: 50px;
@@ -164,11 +221,20 @@ input[type="submit"], input[type="button"] {
background-color: rgba(255, 0, 0, 0.43);
}
-.sudoku #grid{
+.sudoku #grid {
width: 465px;
height: 470px;
}
+.sudoku .grid-container {
+ vertical-align: top;
+ width: 49%;
+}
+
+.sudoku .editor-container {
+ width: 49%;
+}
+
.col.live {
background-color: black;
}
View
126 examples/browser/diagnose.html
@@ -11,56 +11,58 @@
<body>
-<div id="diagnose" class="middle">
- <h1>Diagnose Me <input type="button" id="edit" value="Edit Rules"/></h1>
-
-
- <form action="#">
- <div class="errors"></div>
- <label for="name">Patient Name</label>
- <input type="text" id="name"/>
- <label for="fever">Fever</label>
- <select id="fever">
- <option value="">None</option>
- <option value="high">High</option>
- <option value="mild">Mild</option>
- </select>
-
- <div>
- <label for="spots">Spots</label>
- <input type="checkbox" id="spots"/>
- </div>
- <div>
- <label for="rash">Rash</label>
- <input type="checkbox" id="rash"/>
- </div>
- <div>
- <label for="sore_throat">Sore Throat</label>
- <input type="checkbox" id="sore_throat"/>
- </div>
- <div>
- <label for="innoculated">Innoculated</label>
- <input type="checkbox" id="innoculated"/>
- </div>
- <input type="submit" value="Diagnose"/>
- </form>
- <hr/>
- <h2>Diagnoses</h2>
-
- <div id="results_container"></div>
+<div class="diagnose middle">
+ <div class="header">
+ <h1>Diagnose Me</h1>
+ </div>
+
+ <div class="editor-container">
+ <div id="editor"></div>
+ </div>
+
+ <div class="diagnose-container inline">
+ <form action="#">
+ <div class="errors"></div>
+ <label for="name">Patient Name</label>
+ <input type="text" id="name"/>
+ <label for="fever">Fever</label>
+ <select id="fever">
+ <option value="">None</option>
+ <option value="high">High</option>
+ <option value="mild">Mild</option>
+ </select>
+
+ <div>
+ <label for="spots">Spots</label>
+ <input type="checkbox" id="spots"/>
+ </div>
+ <div>
+ <label for="rash">Rash</label>
+ <input type="checkbox" id="rash"/>
+ </div>
+ <div>
+ <label for="sore_throat">Sore Throat</label>
+ <input type="checkbox" id="sore_throat"/>
+ </div>
+ <div>
+ <label for="innoculated">Innoculated</label>
+ <input type="checkbox" id="innoculated"/>
+ </div>
+ <input type="submit" value="Diagnose"/>
+ </form>
+ <hr/>
+ <h2>Diagnoses</h2>
+
+ <div id="results_container"></div>
+ </div>
</div>
-<div id="editor-dialog">
- <div id="editor"></div>
-</div>
-
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
-<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
<script type="text/javascript" src="../../nools.js"></script>
<script type="text/javascript" src="./src/common.js"></script>
-<script type="text/javascript" src="./src/guests.js"></script>
<script type="text/javascript">
$(document).ready(function () {
@@ -126,35 +128,19 @@
return false;
});
- $("#edit").on("click", function () {
- $("#editor-dialog").dialog("open");
- return false;
- });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var session = editor.getSession();
+ session.setMode("ace/mode/javascript");
+ session.setValue(res);
+ editor.setReadOnly(true);
- $("#editor-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: window.innerWidth * 0.9,
- height: window.innerHeight * 0.9,
- open: function () {
- (editor = ace.edit("editor").getSession()).setValue(flowStr);
- },
- buttons: {
- "Save": function () {
- $(this).dialog("close");
- nools.deleteFlow("diagnosis");
- stop();
- flow = nools.compile((flowStr = editor.getValue()), {name: "diagnosis"});
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
});
- })
- ;
+ });
</script>
</body>
View
6 examples/browser/fibonacci.html
@@ -9,7 +9,7 @@
</head>
<body>
-<div id="fibonacci" class="middle">
+<div class="fibonacci middle">
<h1>Fibonacci</h1>
@@ -20,7 +20,7 @@
<div class="inline">
<div class="large"><span>=</span></div>
</div>
- <div class="inline large" id="results_container">
+ <div class="inline large results_container">
</div>
</form>
</div>
@@ -90,7 +90,7 @@
}
- var resultsContainer = $("#results_container"), valInput = $("#val");
+ var resultsContainer = $(".results_container"), valInput = $("#val");
$("#fibonacci_form").on('submit', function () {
var num = parseInt(valInput.val(), 10);
resultsContainer.text("Calculating...");
View
81 examples/browser/manners.html
@@ -4,43 +4,42 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" rel="stylesheet" href="assets/conways.css">
- <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
<title>Manners Benchmark</title>
</head>
<body>
-<div id="manners" class="middle">
- <h1>Manners Benchmark</h1>
+<div class="middle manners">
+ <div class="header">
+ <h1 class="inline">Manners Benchmark</h1>
- <form>
+ <form class="inline">
+ <select id="guests">
+ <option value="manners5">Manners 5</option>
+ <option value="manners8">Manners 8</option>
+ <option value="manners16">Manners 16</option>
+ <option value="manners32">Manners 32</option>
+ <option value="manners64">Manners 64</option>
+ <option value="manners128">Manners 128</option>
+ </select>
+ <input type="submit" value="Run"/>
+ </form>
+ </div>
- <select id="guests">
- <option value="manners5">Manners 5</option>
- <option value="manners8">Manners 8</option>
- <option value="manners16">Manners 16</option>
- <option value="manners32">Manners 32</option>
- <option value="manners64">Manners 64</option>
- <option value="manners128">Manners 128</option>
- </select>
- <input type="submit" value="Run"/>
- <input type="button" id="edit" value="Edit Rules"/>
+ <div class="editor-container">
+ <div id="editor"></div>
+ </div>
- <div class="middle" id="results_container">
- </div>
-
- </form>
+ <div class="results_container">
+ </div>
</div>
-<div id="editor-dialog">
- <div id="editor"></div>
-</div>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
-<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
<script type="text/javascript" src="../../nools.js"></script>
<script type="text/javascript" src="./src/common.js"></script>
<script type="text/javascript" src="./src/guests.js"></script>
@@ -52,7 +51,7 @@
}).then(function (res) {
var session, dataset,
- resultsContainer = $("#results_container"),
+ resultsContainer = $(".results_container"),
statsListener = stats(),
flowStr = res,
flow = nools.compile(res, {name: "manners"}),
@@ -83,6 +82,7 @@
session
.on("pathDone", function (obj) {
resultsContainer.append(createSeat(obj.seating));
+ resultsContainer.scrollTop(resultsContainer.prop("scrollHeight"));
})
.match().then(function () {
console.log("done");
@@ -114,30 +114,19 @@
return false;
});
- $("#editor-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: window.innerWidth * 0.9,
- height: window.innerHeight * 0.9,
- open: function () {
- (editor = ace.edit("editor").getSession()).setValue(flowStr);
- },
- buttons: {
- "Save": function () {
- $(this).dialog("close");
- nools.deleteFlow("manners");
- stop();
- flow = nools.compile((flowStr = editor.getValue()), {name: "manners"});
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+ resultsContainer.height(height);
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var editorSession = editor.getSession();
+ editorSession.setMode("ace/mode/javascript");
+ editorSession.setValue(res);
+ editor.setReadOnly(true);
});
- })
- ;
+ });
</script>
</body>
View
16 examples/browser/rules/sendMoreMoney.nools
@@ -0,0 +1,16 @@
+rule SendMoreMoney {
+ when {
+ s : Number s != 0;
+ e : Number e != s;
+ n : Number n != s && n != e;
+ d : Number d != s && d != e && d != n;
+ m : Number m != 0 && m != s && m != e && m != n && m != d;
+ o : Number o != s && o != e && o != n && o != d && o != m;
+ r : Number r != s && r != e && r != n && r != d && r != m && r != o;
+ y : Number y != s && y != e && y != n && y != d && y != m && y != o && y != r
+ && (s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e) == (m*10000 + o*1000 + n*100 + e*10 + y);
+ }
+ then {
+ emit("solved", {s : s, e : e, n : n, d : d, m : m, o: o, r : r, y : y});
+ }
+}
View
106 examples/browser/sendMoreMoney.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link type="text/css" rel="stylesheet" href="assets/conways.css">
+ <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
+ <link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
+ <title>Send More Money Benchmark</title>
+</head>
+<body>
+
+
+<div class="middle send-more-money">
+ <div class="header">
+ <h1>Send More Money</h1>
+ <span class="error"><b>Warning:</b> This can take a while!</span>
+ </div>
+
+ <div class="editor-container">
+ <div id="editor"></div>
+ </div>
+ <div class="inline equation-container">
+ <div class="equation middle">
+ <div>
+ <span></span>
+ <span></span>
+ <span class="s-val">S</span>
+ <span class="e-val">E</span>
+ <span class="n-val">N</span>
+ <span class="d-val">D</span>
+ </div>
+ <div>
+ <span>+</span>
+ <span></span>
+ <span class="m-val">M</span>
+ <span class="o-val">O</span>
+ <span class="r-val">R</span>
+ <span class="e-val">E</span>
+ </div>
+ <div>
+ <span></span>
+ <span class="m-val">M</span>
+ <span class="o-val">O</span>
+ <span class="n-val">N</span>
+ <span class="e-val">E</span>
+ <span class="y-val">Y</span>
+ </div>
+ </div>
+ <input class="middle calc-button" type="button" value="Calculate"/>
+ </div>
+</div>
+
+<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
+<script type="text/javascript" src="../../nools.js"></script>
+<script type="text/javascript">
+
+ $(document).ready(function () {
+ $.ajax({
+ url: "./rules/sendMoreMoney.nools"
+ }).then(function (res) {
+
+ var flow = nools.compile(res, {name: "SendMoreMoney"}),
+ calcButton = $("input.calc-button"),
+ letters = ["s", "e", "n", "d", "m", "o", "r", "y"];
+
+ function calc() {
+ session;
+ (session = flow.getSession(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
+ .on("solved",function (solved) {
+ for (var i in solved) {
+ $("." + i + "-val").text(solved[i]);
+ }
+ calcButton.val("Calculated");
+ }).match().then(function () {
+ session.dispose();
+ });
+ }
+
+ calcButton.on("click", function () {
+ calcButton.attr("disabled", "disabled");
+ calcButton.val("Calculating");
+ for (var i = 0, l = letters.length; i < l; i++) {
+ $("." + letters[i] + "-val").text("#");
+ }
+ setTimeout(calc, 100);
+ });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var session = editor.getSession();
+ session.setMode("ace/mode/javascript");
+ session.setValue(res);
+ editor.setReadOnly(true);
+
+
+ });
+ });
+</script>
+
+</body>
+</html>
View
2  examples/browser/src/common.js
@@ -64,7 +64,7 @@
}
setInterval(function () {
- runningTimeSpan.text("running Time:" + Math.round(transCum / 1000 / 60) + "min");
+ runningTimeSpan.text("running time:" + Math.round(transCum / 1000 / 60) + "min");
firesSpan.text('rules fired: : ' + fires);
retractionsSpan.text('facts retracted: ' + retractions);
modifiesSpan.text('facts modified: ' + modified);
View
58 examples/browser/src/sudoku.js
@@ -6,6 +6,13 @@
var allNine = [1, 2, 3, 4, 5, 6, 7, 8, 9];
+ if (typeof console === 'undefined') {
+ console = {
+ log: function () {
+ }
+ };
+ }
+
var SetOfNine = declare({
instance: {
@@ -102,7 +109,7 @@
},
valueAsString: function () {
- return this.value === null ? " ": this.value;
+ return this.value === null ? " " : this.value;
},
posAsString: function () {
@@ -206,35 +213,39 @@
},
step: function () {
- this.session.modify(this.counter, function () {
- this.count = 1;
- });
- if (!this.stepping) {
- this.session.assert(new Stepping());
- }
- return this.session.matchUntilHalt(function (err) {
- if (err) {
- console.log(err);
+ if (!this.invalid) {
+ this.session.modify(this.counter, function () {
+ this.count = 1;
+ });
+ if (!this.stepping) {
+ this.session.assert(new Stepping());
}
- });
+ return this.session.matchUntilHalt(function (err) {
+ if (err) {
+ console.log(err);
+ }
+ });
+ }
},
solve: function () {
- this.session.modify(this.counter, function () {
- this.count = Infinity;
- });
- if (this.stepping) {
- this.session.retract(this.stepping);
- }
- return this.session.match(function (err) {
- if (err) {
- console.log(err);
+ if (!this.invalid) {
+ this.session.modify(this.counter, function () {
+ this.count = Infinity;
+ });
+ if (this.stepping) {
+ this.session.retract(this.stepping);
}
- });
+ return this.session.match(function (err) {
+ if (err) {
+ console.log(err);
+ }
+ });
+ }
},
setCellValue: function setCellValue(cell) {
- cell.el.text(cell.value ? cell.value: "");
+ cell.el.text(cell.value ? cell.value : "");
return cell;
},
@@ -296,7 +307,6 @@
if (value) {
session.assert(new Setting(iRow, iCol, value));
initial++;
- //console.log(initial);
}
}
}
@@ -340,11 +350,13 @@
},
setInvalidCellValue: function setCellValue(cell) {
+ this.invalid = true;
cell.el.addClass("error");
return cell;
},
validate: function () {
+ this.invalid = false;
this.session.assert("validate");
return this.session.focus("validate")
.on("invalid", this.setInvalidCellValue)
View
58 examples/browser/sudoku.html
@@ -11,28 +11,32 @@
<body>
<div class="container sudoku">
- <header>
- <h1>Sudoku</h1>
+ <div class="header">
+ <h1 class="inline">Sudoku</h1>
- <form>
- <input type="submit" id="run" value="Run!"/>
+ <form class="inline">
+ <input type="submit" id="run" value="Solve!"/>
<input type="button" id="step" value="Step"/>
<input type="button" id="stop" value="Stop"/>
<input type="button" id="clear" value="Clear"/>
- <input type="button" id="edit" value="Edit Rules"/>
<select id="patterns"></select>
</form>
- </header>
- <div id="grid"></div>
-</div>
+ </div>
+
+ <div class="editor-container inline">
+ <div id="editor"></div>
+ </div>
+
+ <div class="grid-container inline">
+ <div id="grid"></div>
+ </div>
+
-<div id="editor-dialog">
- <div id="editor"></div>
</div>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
-<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/0.2.0/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js"></script>
+<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/mode-javascript.js"></script>
<script type="text/javascript" src="../../nools.js"></script>
<script type="text/javascript" src="assets/declare.js"></script>
<script type="text/javascript" src="assets/extender.js"></script>
@@ -44,7 +48,6 @@
<script type="text/javascript" src="src/common.js"></script>
<script type="text/javascript" src="src/sudokuPatterns.js"></script>
<script type="text/javascript" src="src/sudoku.js"></script>
-<!--<script type="text/javascript" src="rules/sudoku.js"></script>-->
<script type="text/javascript">
(function () {
@@ -117,25 +120,16 @@
return false;
});
- $("#editor-dialog").dialog({
- autoOpen: false,
- modal: true,
- width: window.innerWidth * 0.9,
- height: window.innerHeight * 0.9,
- open: function () {
- (editor = ace.edit("editor").getSession()).setValue(flowStr);
- },
- buttons: {
- "Save": function () {
- $(this).dialog("close");
- nools.deleteFlow("sudoku");
- flow = nools.compile((flowStr = editor.getValue()), {name: "sudoku", define: {Cell: Cell}, scope: { loop: loop}});
- },
- Cancel: function () {
- $(this).dialog("close");
- }
- }
- });
+ var height = $(document).height() - $("#manners .header").height() - 100;
+ $(".editor-container").height(height);
+
+
+ var editor = ace.edit("editor");
+ //editor.setTheme("ace/theme/monokai");
+ var session = editor.getSession();
+ session.setMode("ace/mode/javascript");
+ session.setValue(flowStr);
+ editor.setReadOnly(true);
});
});
View
78 examples/browser/waltzDb.html
@@ -4,41 +4,40 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" rel="stylesheet" href="assets/conways.css">
- <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link href='http://fonts.googleapis.com/css?family=Londrina+Shadow' rel='stylesheet' type='text/css'>
<title>WaltzDB Benchmark</title>
</head>
<body>
-<div id="manners" class="middle">
- <h1>WaltzDB Benchmark</h1>
+<div class="middle waltz-db">
+ <div class="header">
+ <h1 class="inline">WaltzDB Benchmark</h1>
- <form>
+ <form class="inline">