我使用Salience来确定每条规则的优先级,但是当我使用fireAllRules时,它并不总是选择具有更高Salience的规则。如何让规则引擎始终选择具有更高显着性的规则?
输出
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 10
Positon1 Salience: 10
Positon2 Salience: 10
Rule Number:0
pleasant:false activation:false context:working multitasking:true state:stuck
[9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 9
Positon1 Salience: 10
Positon2 Salience: 10
Rule Number:1
pleasant:false activation:false context:working multitasking:true state:stuck
[9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 9
Positon1 Salience: 9
Positon2 Salience: 10
Rule Number:1
pleasant:false activation:false context:working multitasking:true state:stuck
[9, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 9
Positon1 Salience: 8
Positon2 Salience: 10
Rule Number:2
pleasant:false activation:false context:working multitasking:true state:stuck
[9, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 9
Positon1 Salience: 8
Positon2 Salience: 9
Rule Number:2
pleasant:false activation:false context:working multitasking:true state:stuck
[9, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 9
Positon1 Salience: 8
Positon2 Salience: 8
Rule Number:2
pleasant:false activation:false context:working multitasking:true state:stuck
[9, 8, 7, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 9
Positon1 Salience: 8
Positon2 Salience: 7
Rule Number:2
pleasant:false activation:false context:working multitasking:true state:stuck
[9, 8, 6, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0 Salience: 9
Positon1 Salience: 8
Positon2 Salience: 6
Rule Number:0
触发规则的Actionlistener
simula.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
FactHandle fact1;
fact1= new SimulaRegras(pleas, act, context.getText(), mtask, state.getText(),sal);
ksession.insert(fact1);
ksession.fireAllRules(1);
}
}
);
Drools Main
public class DroolsTest {
public static void main(String[] args) {
KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
new DroolsTest().init(kc);
}
public DroolsTest() {
}
public void init(final KieContainer kc) {
KieSession ksession = kc.newKieSession("ksession-rule");
TeleInterface t = new TeleInterface(ksession);
FactHandle fact2;
fact2 = ksession.insert(t);
}
}
规则结构
rule "Num1"
salience(sr.gSal(0))
when
t: TeleInterface ()
sr: SimulaRegras(pleasant == false && activation == false && context == "working", multitask == true, state == "stuck")
then
t.gMap.setEnabled(true);
t.gMap.setForeground(Color.GREEN);
t.background.setIcon(new ImageIcon("ponto.png"));
t.action("gMap", false);
t.infoBox("optimization", "add", "Adicionar ponto no grid map e fornecer o caminho");
t.sSal(0);
end
答案 0 :(得分:0)
我不太确定你想要实现什么,但使用显着性不是要走的路。基于事实属性中的值的显着性可以由逻辑替换,即,通过检查没有具有该属性的更高值的这种类型的其他事实。此外,修改提供显着性的属性并不是一个好主意,因为Drools不会重新评估显着性。
我不会再进行调查,因为用户界面(TeleInterface
)没有描述实际插入的内容。