private ILNode setupNode(final IFPNode fp, final DomainTuple d, final ILNode parent)
            throws Exception {

        if( ! evaluate( fp.getCondition(), d ) ) {
            return new LFalse();
        }

        final FactorCatalog factCat
                = getFactorCatalog(fp.getId());

        final GenTuple key = (fp.isFactorized() || parent == null)
                ? GenTuple.From(fp, d)
                : GenTuple.From(fp, d, parent.hashCode());

        if(factCat.contains(key))
            return factCat.get(key);

        switch(fp.getType()) {

            case NOr: return factCat.put(key, new LOr(true));
            case Not: return factCat.put(key, new LNot());
            case And: {

                final LAnd lAnd = new LAnd(false);

                // We explicit need to set two child nodes,
                // because NNode sets only one default node.
                lAnd.addChild(new LFalse());
                lAnd.addChild(new LFalse());

                return factCat.put(key, lAnd);
            }
            case Or: {

                final LOr lOr = new LOr(false);

                // We explicit need to set two child nodes,
                // because NNode sets only one default node.
                lOr.addChild(new LFalse());
                lOr.addChild(new LFalse());

                return factCat.put(key, lOr);
            }
            case Source: {

                final FPSource fpSource = (FPSource)fp;
                final LSource lSource = new LSource();

                // The mask priority is later used
                // for the probability calculation
                // in order to decide which bid's
                // need to be masked first.

                lSource.setMaskPriority(
                        fpSource.getMaskPriority());

                return factCat.put(key, lSource);
            }
            default:

                throw new Exception(String.format(
                        "Unknown formula pattern type: %s.",
                                fp.getType()));
        }
    }