1 / 17

Jug problem

Jug problem. What is Jug problem?. Use only 2 kinds of jugs above, get 2 litter water. No tics on each jug. 4 litter Jug. 3 litter Jug. It’s easy for us … ?. Please consider. Answer is in the next page …. An example of answer. Fill up 3l jug .

blankm
Download Presentation

Jug problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jug problem

  2. What is Jug problem? • Use only 2 kinds of jugs above, get 2 litter water. • No tics on each jug. 4 litter Jug 3 litter Jug

  3. It’s easy for us…? • Please consider. • Answer is in the next page…

  4. An example of answer • Fill up 3l jug. • Move water in 4l jug into 3l jug as much as you can. • Empty 3l jug. • Move all water in 4l jug into 3l jug. • Fill up 4l jug. • Move water in 4l jug into 3l jug as much as you can. • 2 litter water remains in 4l jug.

  5. Solve this problem by OPS5 • Find the order of operation for jugs and water. • Of course, we should consider that program and programmer don’t know the answer. • What type of data (class) do we need? • What rules do we need?

  6. Image of program Rule Rule Rule Rule Rule Rule Move water from 4l jug to 3l jug. Fill up 4l jug Status of jugs • Each rule will be executable depending on the status of jugs. (System choose a rule from executable rules.) • Repeating rule execution, finish execution when goal status is satisfied.

  7. What rule do we need? • Write all actions for each status of jugs. Ex:If 4l jug is not full, full up 4l jug. Formal expression: if x < 4 then (x,y)-> (4,y) Here,(x,y) means amount of water in 4l and 3l jug respectively. • Exercise 1 Write all actions in Japanese(or English) and the formal expression.

  8. Make a rule • Convert a written description to a form of rule. (p rule1 (youki ^4l < 4 ^3l <Y>) --> (make youki ^4l 4 ^3l <Y>) ) • Ordinary, class should be defined before rule description, however, in this tutorial, we define rule before class definition, then class will be defined depending on the rule description.

  9. Class definition • Define classes according to the rule. • Consider about the rule in previous page… (literalize youki 4l 3l ) • Exercise 2 Convert all actions in Ex.1 into the format of rule in OPS5. Caution: It is insufficient this class definition. If you add some attribute in making rule, you should modify class definition. Making rule and class definition process will be repeated.

  10. Rule for goal • Goal status is (x,y)=(2,0), then goal rules will be… (p gole   (youki ^4l 2 ^3l 0) --> (write |Goal!|(crlf)) (halt) )

  11. Infinite loop problem… • Infinite loop will occur if you make only rules about jugs. Initial:(0,0) Fill up 4l jug (4、0) Empty 4l jug A rule for avoiding appearance of same status repeatedly is needed not to get into a infinite loop. (0、0) Fill up 4l jug (4、0)

  12. How to deal with the problem • If same status is appeared, the last one is not needed. Initial:(0,0) Fill up 4l jugs (4、0) Empty 4l jugs Same status (0、0) This status is cause of a infinite loop. Remove it. Exercise 3: Make a rule of this operation. It is needed some way to compare new or old data.

  13. From here… • In following pages, class and rules definition is described. These are just examples. • It is not only one way to define class and rules. • There are many kinds of programs to solve this problem. • In this theme, all programs that can solve this problem are accepted.

  14. Classdefinition • Class definition is following. (literalize youki 4l 3l goukei num) • “goukei” keeps the value of the total amount of water. • “num” keeps the value to compare old and new data for avoiding infinite loop.

  15. Rule definition • Rule example If 3l jug is not full and total amount of water is less than or equal to 3l, move all water in 4l jug into 3l jug (p rule (youki ^4l {<X> > 0} ^3l {<Y> < 3} ^goukei <= 3 ^num <N>) --> (make youki ^4l 0 ^3l (compute <X> + <Y>) ^goukei (compute <X> + <Y>) ^num (compute <N> + 1 )) (write |4l=0, 3l=|(compute <X> + <Y>)(crlf)) ) *In command part, ”make” command is appropriate, because it can not compare old and new data if “modify” command is used. “^num” is a attribute for compare new or old data. In each making of the data, num is increased.

  16. Rule for Infinite loops (p cut (youki ^4l <X> ^3l <Y> ^goukei <G> ^num <N>) (youki ^4l <X> ^3l <Y> ^goukei <G> ^num < <N>) --> (remove 1) ) 容器の状態が同じデータが2つあり、 1番目の条件要素のnumが<N>で、 2番目の条件要素のnumが<N>より小さいとき、 1番目の条件要素の方が新しいので、削除する

  17. Additional explanation • It is almost by implement the explanation so far. • If some error occurs, please check spaces between words or symbols.(Space is needed in any borders between words or symbols. Otherwise, errors will occur.) • Furthermore, it is able to set priority for each rules. Please refer the additional explanations in the text book.

More Related