⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basewaltztest.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                                         "joined",
                                                         new Boolean( false ),
                                                         this.booleanEqualEvaluator ) );
        setFieldDeclaration( edgeColumn1,
                             "p1",
                             "edge1p1" );
        setFieldDeclaration( edgeColumn1,
                             "p2",
                             "edge1p2" );
        rule.addPattern( edgeColumn1 );
        final Declaration edge1Declaration = rule.getDeclaration( "edge1" );
        final Declaration edge1P1Declaration = rule.getDeclaration( "edge1p1" );
        final Declaration edge1P2Declaration = rule.getDeclaration( "edge1p2" );

        final Column edgeColumn2 = new Column( 2,
                                               this.edgeType,
                                               "edge2" );
        edgeColumn2.addConstraint( getLiteralConstraint( edgeColumn2,
                                                         "joined",
                                                         new Boolean( false ),
                                                         this.booleanEqualEvaluator ) );
        setFieldDeclaration( edgeColumn2,
                             "p2",
                             "edge2p2" );
        rule.addPattern( edgeColumn2 );
        final Declaration edge2Declaration = rule.getDeclaration( "edge2" );
        final Declaration edge2P2Declaration = rule.getDeclaration( "edge2p2" );
        edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
                                                               "p1",
                                                               edge1P1Declaration,
                                                               this.integerEqualEvaluator ) );
        edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
                                                               "p2",
                                                               edge1P2Declaration,
                                                               this.integerNotEqualEvaluator ) );

        final Column edgeColumn3 = new Column( 3,
                                               this.edgeType,
                                               "edge3" );
        //      final Declaration edge3Declaration = rule.getDeclaration("edge3");
        edgeColumn3.addConstraint( getBoundVariableConstraint( edgeColumn3,
                                                               "p1",
                                                               edge1P1Declaration,
                                                               this.integerEqualEvaluator ) );
        edgeColumn3.addConstraint( getBoundVariableConstraint( edgeColumn3,
                                                               "p2",
                                                               edge1P2Declaration,
                                                               this.integerNotEqualEvaluator ) );
        edgeColumn3.addConstraint( getBoundVariableConstraint( edgeColumn3,
                                                               "p2",
                                                               edge2P2Declaration,
                                                               this.integerNotEqualEvaluator ) );

        final Not notEdge = new Not();
        notEdge.addChild( edgeColumn3 );
        rule.addPattern( notEdge );

        final Consequence consequence = new Consequence() {
            public void evaluate(KnowledgeHelper drools,
                                 WorkingMemory workingMemory) throws ConsequenceException {
                try {
                    Rule rule = drools.getRule();
                    Tuple tuple = drools.getTuple();

                    Edge edge1 = (Edge) drools.get( edge1Declaration );
                    edge1.setJoined( true );
                    Edge edge2 = (Edge) drools.get( edge2Declaration );
                    edge2.setJoined( true );

                    drools.assertObject( new Junction( edge1.getP2(),
                                                       edge2.getP2(),
                                                       0,
                                                       edge1.getP1(),
                                                       Junction.L ) );
                    drools.modifyObject( tuple.get( edge1Declaration ),
                                         edge1 );
                    drools.modifyObject( tuple.get( edge2Declaration ),
                                         edge2 );

                } catch ( Exception e ) {
                    e.printStackTrace();
                    throw new ConsequenceException( e );
                }
            }
        };

        rule.setConsequence( consequence );

        return rule;
    }

    // ;If the detect junctions flag is set, and there are no more un_joined
    // edges,
    // ;set the find_initial_boundary flag
    // (p done_detecting
    // (stage ^value detect_junctions)
    // - (edge ^joined false)
    // -->
    // (modify 1 ^value find_initial_boundary))
    //   
    private Rule getDoneDetectingRule() throws IntrospectionException,
                                       InvalidRuleException {
        final Rule rule = new Rule( "done_detecting" );

        final Column stageColumn = new Column( 0,
                                               this.stageType,
                                               "stage" );
        stageColumn.addConstraint( getLiteralConstraint( stageColumn,
                                                         "value",
                                                         new Integer( Stage.DETECT_JUNCTIONS ),
                                                         this.integerEqualEvaluator ) );
        rule.addPattern( stageColumn );
        final Declaration stageDeclaration = rule.getDeclaration( "stage" );

        final Column notEdgeColumn = new Column( 1,
                                                 this.edgeType );
        notEdgeColumn.addConstraint( getLiteralConstraint( notEdgeColumn,
                                                           "joined",
                                                           new Boolean( false ),
                                                           this.booleanEqualEvaluator ) );
        final Not notEdge = new Not();
        notEdge.addChild( notEdgeColumn );
        rule.addPattern( notEdge );

        final Consequence consequence = new Consequence() {
            public void evaluate(KnowledgeHelper drools,
                                 WorkingMemory workingMemory) throws ConsequenceException {
                try {
                    Rule rule = drools.getRule();
                    Tuple tuple = drools.getTuple();

                    Stage stage = (Stage) drools.get( stageDeclaration );
                    stage.setValue( Stage.FIND_INITIAL_BOUNDARY );
                    drools.modifyObject( tuple.get( stageDeclaration ),
                                         stage );
                } catch ( Exception e ) {
                    e.printStackTrace();
                    throw new ConsequenceException( e );
                }
            }
        };
        rule.setConsequence( consequence );
        return rule;
    }

    //   
    // ;If the initial boundary junction is an L, then we know it's labelling
    // (p initial_boundary_junction_L
    // (stage ^value find_initial_boundary)
    // (junction ^type L ^base_point <base_point> ^p1 <p1> ^p2 <p2>)
    // (edge ^p1 <base_point> ^p2 <p1>)
    // (edge ^p1 <base_point> ^p2 <p2>)
    // - (junction ^base_point > <base_point>)
    // -->
    // (modify 3 ^label B)
    // (modify 4 ^label B)
    // (modify 1 ^value find_second_boundary))
    private Rule getInitialBoundaryJunctionLRule() throws IntrospectionException,
                                                  InvalidRuleException {
        final Rule rule = new Rule( "initial_boundary_junction_L" );

        final Column stageColumn = new Column( 0,
                                               this.stageType,
                                               "stage" );
        stageColumn.addConstraint( getLiteralConstraint( stageColumn,
                                                         "value",
                                                         new Integer( Stage.FIND_INITIAL_BOUNDARY ),
                                                         this.integerEqualEvaluator ) );
        rule.addPattern( stageColumn );
        final Declaration stageDeclaration = rule.getDeclaration( "stage" );

        final Column junctionColumn = new Column( 1,
                                                  this.junctionType );
        junctionColumn.addConstraint( getLiteralConstraint( junctionColumn,
                                                            "type",
                                                            Junction.L,
                                                            this.objectEqualEvaluator ) );
        setFieldDeclaration( junctionColumn,
                             "basePoint",
                             "junctionBasePoint" );
        setFieldDeclaration( junctionColumn,
                             "p1",
                             "junctionP1" );
        setFieldDeclaration( junctionColumn,
                             "p2",
                             "junctionP2" );
        rule.addPattern( junctionColumn );
        final Declaration junctionBasePointDeclaration = rule.getDeclaration( "junctionBasePoint" );
        final Declaration junctionP1Declaration = rule.getDeclaration( "junctionP1" );
        final Declaration junctionP2Declaration = rule.getDeclaration( "junctionP2" );

        final Column edgeColumn1 = new Column( 2,
                                               this.edgeType,
                                               "edge1" );
        rule.addPattern( edgeColumn1 );
        final Declaration edge1Declaration = rule.getDeclaration( "edge1" );
        edgeColumn1.addConstraint( getBoundVariableConstraint( edgeColumn1,
                                                               "p1",
                                                               junctionBasePointDeclaration,
                                                               this.integerEqualEvaluator ) );
        edgeColumn1.addConstraint( getBoundVariableConstraint( edgeColumn1,
                                                               "p2",
                                                               junctionP1Declaration,
                                                               this.integerEqualEvaluator ) );

        final Column edgeColumn2 = new Column( 3,
                                               this.edgeType,
                                               "edge2" );
        rule.addPattern( edgeColumn2 );
        final Declaration edge2Declaration = rule.getDeclaration( "edge2" );
        edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
                                                               "p1",
                                                               junctionBasePointDeclaration,
                                                               this.integerEqualEvaluator ) );
        edgeColumn2.addConstraint( getBoundVariableConstraint( edgeColumn2,
                                                               "p2",
                                                               junctionP2Declaration,
                                                               this.integerEqualEvaluator ) );

        final Column notJunctionColumn = new Column( 4,
                                                     this.junctionType );
        notJunctionColumn.addConstraint( getBoundVariableConstraint( notJunctionColumn,
                                                                     "basePoint",
                                                                     junctionBasePointDeclaration,
                                                                     this.integerGreaterEvaluator ) );
        final Not notJunction = new Not();
        notJunction.addChild( notJunctionColumn );
        rule.addPattern( notJunction );

        final Consequence consequence = new Consequence() {
            public void evaluate(KnowledgeHelper drools,
                                 WorkingMemory workingMemory) throws ConsequenceException {
                try {
                    Rule rule = drools.getRule();
                    Tuple tuple = drools.getTuple();

                    Edge edge1 = (Edge) drools.get( edge1Declaration );
                    edge1.setLabel( Edge.B );
                    Edge edge2 = (Edge) drools.get( edge2Declaration );
                    edge2.setLabel( Edge.B );
                    Stage stage = (Stage) drools.get( stageDeclaration );
                    stage.setValue( Stage.FIND_SECOND_BOUNDARY );

                    drools.modifyObject( tuple.get( stageDeclaration ),
                                         stage );
                    drools.modifyObject( tuple.get( edge1Declaration ),
                                         edge1 );
                    drools.modifyObject( tuple.get( edge2Declaration ),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -