Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding FIFO fact recency resolution #153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/conflict.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ function factRecency(a, b) {
return ret;
}

function factRecencyInverse(a, b) {
// negate fact recency,
// but need 0 to produce 1 in ret value of strategy function
var fRI = -factRecency(a,b);
return (fRI === 0 ? 1 : fRI);
}

function activationRecency(a, b) {
return a.recency - b.recency;
}
Expand All @@ -31,7 +38,8 @@ var strategies = {
salience: salience,
bucketCounter: bucketCounter,
factRecency: factRecency,
activationRecency: activationRecency
activationRecency: activationRecency,
factRecencyInverse: factRecencyInverse
};

exports.strategies = strategies;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nools",
"description": "A rules engine for node",
"version": "0.4.1",
"version": "0.4.2",
"bin": {
"nools": "./bin/nools"
},
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ When declaring a flow it is defined with a default conflict resolution strategy.
* `activationRecency` - sort activations on activation recency. This is a `LIFO` strategy the latest activation takes precedence.
* `factRecency` - sort activations based on `fact` recency. Each time a fact is `asserted` or `modified` its recency is incremented.
* `bucketCounter` - sort activations on the internal `bucket` counter. The bucket counter is incremented after an activation is fired and the internal `workingMemory` is altered.
* `factRecencyInverse` - sort activations by the oldest fact first. This is a `FIFO` strategy, the earliest fact takes precedence.

The default conflict resolution strategy consists of `salience` and `activationRecency`.

Expand Down