hylar/core/ReasoningEngine.js
function (FeAdd, FeDel, F, R) {        
        var Rdel = [], Rred = [], Rins = [],
            FiDel = [], FiAdd = [],
            FiDelNew = [], FiAddNew = [],
            superSet = [],

            additions, deletions,

            Fe = Logics.getOnlyExplicitFacts(F),
            Fi = Logics.getOnlyImplicitFacts(F),

            deferred = q.defer(),

            startAlgorithm = function() {                
                overDeletionEvaluationLoop();
            },

            overDeletionEvaluationLoop = function() {                
                FiDel = Utils.uniques(FiDel, FiDelNew);                
                Rdel = Logics.restrictRuleSet(R, Utils.uniques(FeDel, FiDel));                                
                Solver.evaluateRuleSet(Rdel, Utils.uniques(Utils.uniques(Fi, Fe), FeDel))
                    .then(function(values) {
                        FiDelNew = values.cons;
                        if (Utils.uniques(FiDel, FiDelNew).length > FiDel.length) {
                            overDeletionEvaluationLoop();                            
                        } else {
                            Fe = Logics.minus(Fe, FeDel);
                            Fi = Logics.minus(Fi, FiDel);
                            rederivationEvaluationLoop();
                        }                        
                    });
            },

            rederivationEvaluationLoop = function() {
                FiAdd = Utils.uniques(FiAdd, FiAddNew);
                Rred = Logics.restrictRuleSet(R, FiDel);
                Solver.evaluateRuleSet(Rred, Utils.uniques(Fe, Fi))
                    .then(function(values) {
                        FiAddNew = values.cons;
                        if (Utils.uniques(FiAdd, FiAddNew).length > FiAdd.length) {
                            rederivationEvaluationLoop();
                        } else {
                            insertionEvaluationLoop();
                        }
                    });
            },
            
            insertionEvaluationLoop = function() {    
                FiAdd = Utils.uniques(FiAdd, FiAddNew);
                superSet = Utils.uniques(Utils.uniques(Utils.uniques(Fe, Fi), FeAdd), FiAdd);
                Rins = Logics.restrictRuleSet(R, superSet);                
                Solver.evaluateRuleSet(Rins, superSet)
                    .then(function(values) {
                        FiAddNew = values.cons;                       
                        if (!Utils.containsSubset(FiAdd, FiAddNew)) {
                            insertionEvaluationLoop();
                        } else {                
                            additions = Utils.uniques(FeAdd, FiAdd);
                            deletions = Utils.uniques(FeDel, FiDel);                            
                            deferred.resolve({
                                additions: additions,
                                deletions: deletions
                            });
                        }
                    }).fail(function(err) {
                        console.error(err);
                    });
            };

        startAlgorithm();
        return deferred.promise;
    }
function (FeAdd, FeDel, F, R) {        
        var Rdel = [], Rred = [], Rins = [],
            FiDel = [], FiAdd = [],
            FiDelNew = [], FiAddNew = [],
            superSet = [],

            additions, deletions,

            Fe = Logics.getOnlyExplicitFacts(F),
            Fi = Logics.getOnlyImplicitFacts(F),

            deferred = q.defer(),

            startAlgorithm = function() {                
                overDeletionEvaluationLoop();
            },

            overDeletionEvaluationLoop = function() {                
                FiDel = Utils.uniques(FiDel, FiDelNew);                
                Rdel = Logics.restrictRuleSet(R, Utils.uniques(FeDel, FiDel));                                
                Solver.evaluateRuleSet(Rdel, Utils.uniques(Utils.uniques(Fi, Fe), FeDel))
                    .then(function(values) {
                        FiDelNew = values.cons;
                        if (Utils.uniques(FiDel, FiDelNew).length > FiDel.length) {
                            overDeletionEvaluationLoop();                            
                        } else {
                            Fe = Logics.minus(Fe, FeDel);
                            Fi = Logics.minus(Fi, FiDel);
                            rederivationEvaluationLoop();
                        }                        
                    });
            },

            rederivationEvaluationLoop = function() {
                FiAdd = Utils.uniques(FiAdd, FiAddNew);
                Rred = Logics.restrictRuleSet(R, FiDel);
                Solver.evaluateRuleSet(Rred, Utils.uniques(Fe, Fi))
                    .then(function(values) {
                        FiAddNew = values.cons;
                        if (Utils.uniques(FiAdd, FiAddNew).length > FiAdd.length) {
                            rederivationEvaluationLoop();
                        } else {
                            insertionEvaluationLoop();
                        }
                    });
            },
            
            insertionEvaluationLoop = function() {    
                FiAdd = Utils.uniques(FiAdd, FiAddNew);
                superSet = Utils.uniques(Utils.uniques(Utils.uniques(Fe, Fi), FeAdd), FiAdd);
                Rins = Logics.restrictRuleSet(R, superSet);                
                Solver.evaluateRuleSet(Rins, superSet)
                    .then(function(values) {
                        FiAddNew = values.cons;                       
                        if (!Utils.containsSubset(FiAdd, FiAddNew)) {
                            insertionEvaluationLoop();
                        } else {                
                            additions = Utils.uniques(FeAdd, FiAdd);
                            deletions = Utils.uniques(FeDel, FiDel);                            
                            deferred.resolve({
                                additions: additions,
                                deletions: deletions
                            });
                        }
                    }).fail(function(err) {
                        console.error(err);
                    });
            };

        startAlgorithm();
        return deferred.promise;
    }
function ( FeAdd , FeDel , F , R ) { var Rdel = [ ] , Rred = [ ] , Rins = [ ] , FiDel = [ ] , FiAdd = [ ] , FiDelNew = [ ] , FiAddNew = [ ] , superSet = [ ] , additions , deletions , Fe = Logics . getOnlyExplicitFacts ( F ) , Fi = Logics . getOnlyImplicitFacts ( F ) , deferred = q . defer ( ) , startAlgorithm = function ( ) { overDeletionEvaluationLoop ( ) ; } , overDeletionEvaluationLoop = function ( ) { FiDel = Utils . uniques ( FiDel , FiDelNew ) ; Rdel = Logics . restrictRuleSet ( R , Utils . uniques ( FeDel , FiDel ) ) ; Solver . evaluateRuleSet ( Rdel , Utils . uniques ( Utils . uniques ( Fi , Fe ) , FeDel ) ) . then ( function ( values ) { FiDelNew = values . cons ; if ( Utils . uniques ( FiDel , FiDelNew ) . length > FiDel . length ) { overDeletionEvaluationLoop ( ) ; } else { Fe = Logics . minus ( Fe , FeDel ) ; Fi = Logics . minus ( Fi , FiDel ) ; rederivationEvaluationLoop ( ) ; } } ) ; } , rederivationEvaluationLoop = function ( ) { FiAdd = Utils . uniques ( FiAdd , FiAddNew ) ; Rred = Logics . restrictRuleSet ( R , FiDel ) ; Solver . evaluateRuleSet ( Rred , Utils . uniques ( Fe , Fi ) ) . then ( function ( values ) { FiAddNew = values . cons ; if ( Utils . uniques ( FiAdd , FiAddNew ) . length > FiAdd . length ) { rederivationEvaluationLoop ( ) ; } else { insertionEvaluationLoop ( ) ; } } ) ; } , insertionEvaluationLoop = function ( ) { FiAdd = Utils . uniques ( FiAdd , FiAddNew ) ; superSet = Utils . uniques ( Utils . uniques ( Utils . uniques ( Fe , Fi ) , FeAdd ) , FiAdd ) ; Rins = Logics . restrictRuleSet ( R , superSet ) ; Solver . evaluateRuleSet ( Rins , superSet ) . then ( function ( values ) { FiAddNew = values . cons ; if ( ! Utils . containsSubset ( FiAdd , FiAddNew ) ) { insertionEvaluationLoop ( ) ; } else { additions = Utils . uniques ( FeAdd , FiAdd ) ; deletions = Utils . uniques ( FeDel , FiDel ) ; deferred . resolve ( { additions : additions , deletions : deletions } ) ; } } ) . fail ( function ( err ) { console . error ( err ) ; } ) ; } ; startAlgorithm ( ) ; return deferred . promise ; }
Incremental reasoning which avoids complete recalculation of facts.
Concat is preferred over merge for evaluation purposes.
@param R set of rules
@param F set of assertions
@param FeAdd set of assertions to be added
@param FeDel set of assertions to be deleted
Incremental reasoning which avoids complete recalculation of facts . Concat is preferred over merge for evaluation purposes .