24.11.2014 Views

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix A - Examples 178<br />

group start_rules<br />

fill_master, fill_slave .<br />

The Ruleset<br />

The problem starts with both jugs being empty, we can therefore limit the<br />

initial rule agenda to two rules: the rule that fills the master jug and the rule<br />

that fills the slave jug. For convenience we have put these rules in a group<br />

called start_rules. The rule agenda will subsequently be updated using<br />

the rule transition network that we defined above.<br />

We have attached scores to the rules to give them different chances of being<br />

selected according to the situation. The rules will then be selected using the<br />

conflict resolution scoring system with a threshold of 6. This means that the<br />

first rule found whose score is above 6 will be fired.<br />

The solution to the problem will be found (so we want the forward chaining<br />

engine to terminate) if at any point the contents of any container are 6.<br />

The ruleset that defines this method of selecting rules, updating the rule<br />

agenda and terminating the forward chaining is written as follows.<br />

ruleset water_jugs<br />

contains start_rules ;<br />

select rule using<br />

conflict resolution with threshold 6 ;<br />

update ruleset using rule transition network ;<br />

initiate by doing restart ;<br />

terminate when<br />

the contents of any container are 6 .<br />

The action that triggers the whole program can then be written as follows. (The<br />

spy_chain/0 built-in <strong>flex</strong> predicate causes execution information to be written to the<br />

current output stream.)<br />

action demo ;<br />

do spy_chain<br />

and invoke ruleset water_jugs .<br />

<strong>flex</strong> toolkit

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!