%----------------------------------------------------------------------------- % DESS version of the rule-based reaction system "BAGGER", which is described % in: % "Artificial Intelligence" (3rd Edition) % Patrick Henry Winston % Addison Wesley (1992), pp 129-137. %----------------------------------------------------------------------------- bag subclass of container with contents: [cardinality: multi] number_of_large_items: 0 number_of_medium_items: 0 number_of_small_items: 0; bag1 instance of bag; % Empty bags (instances). bag2 instance of bag; bag3 instance of bag; bag4 instance of bag; the is_frozen of item is no; % Items are not frozen. the in_freezer_bag of item is no; % Items are not in freezer bags. bread instance of item with % Items (instances) container_type: plastic_bag size: medium; glop instance of item with % Don't know what this is! container_type: jar size: small; granola instance of item with % Don't know what this is! container_type: cardboard_box size: large; ice_cream instance of item with container_type: cardboard_carton size: medium is_frozen: yes; % Ice cream is frozen potato_chips instance of item with container_type: plastic_bag size: medium; pepsi instance of item with container_type: bottle size: large; add frame bag1; % Load bag frames into working memory. add frame bag2; add frame bag3; add frame bag4; add frame bread; % Load item frames into working memory. add frame glop; add frame granola; add frame ice_cream; add frame potato_chips; add frame pepsi; the current_bag of order is bag1; the items_to_be_bagged of order include bread; the items_to_be_bagged of order include glop; the items_to_be_bagged of order include granola; the items_to_be_bagged of order include ice_cream; the items_to_be_bagged of order include potato_chips; 'step is check-order'; % Initial context. rule B1 if 'step is check-order' and the items_to_be_bagged of order include potato_chips and not(the items_to_be_bagged of order include pepsi) and ask 'Do you want Pepsi added to the order (y/n)? ' = y then the items_to_be_bagged of order include pepsi; rule B2 if 'step is check-order' delete 'step is check-order' add 'step is bag-large-items'; rule B3 if 'step is bag-large-items' and the items_to_be_bagged of order include Item and the size of Item is large and the container_type of Item is bottle and the current_bag of order is Bag and the number_of_large_items of Bag is L and L < 6 delete the items_to_be_bagged of order include Item and the number_of_large_items of Bag is L add the contents of Bag include Item and the number_of_large_items of Bag is L + 1; rule B4 if 'step is bag-large-items' and the items_to_be_bagged of order include Item and the size of Item is large and the current_bag of order is Bag and the number_of_large_items of Bag is L and L < 6 delete the items_to_be_bagged of order include Item and the number_of_large_items of Bag is L add the contents of Bag include Item and the number_of_large_items of Bag is L + 1; rule B5 if 'step is bag-large-items' and the items_to_be_bagged of order include Item and the size of Item is large and NewBag is an instance of bag and the number_of_large_items of NewBag is 0 and the number_of_medium_items of NewBag is 0 and the number_of_small_items of NewBag is 0 and the current_bag of order is Bag delete the current_bag of order is Bag add the current_bag of order is NewBag; rule B6 if 'step is bag-large-items' delete 'step is bag-large-items' add 'step is bag-medium-items'; rule B7 if 'step is bag-medium-items' and the items_to_be_bagged of order include Item and the size of Item is medium and the is_frozen of Item is yes and the in_freezer_bag of Item is no delete the in_freezer_bag of Item is no add the in_freezer_bag of Item is yes; rule B8 if 'step is bag-medium-items' and the items_to_be_bagged of order include Item and the size of Item is medium and the current_bag of order is Bag and the number_of_large_items of Bag is 0 and the number_of_small_items of Bag is 0 and the number_of_medium_items of Bag is M and M < 12 delete the items_to_be_bagged of order include Item and the number_of_medium_items of Bag is M add the contents of Bag include Item and the number_of_medium_items of Bag is M + 1; rule B9 if 'step is bag-medium-items' and the items_to_be_bagged of order include Item and the size of Item is medium and NewBag is an instance of bag and the number_of_large_items of NewBag is 0 and the number_of_medium_items of NewBag is 0 and the number_of_small_items of NewBag is 0 and the current_bag of order is Bag delete the current_bag of order is Bag add the current_bag of order is NewBag; rule B10 if 'step is bag-medium-items' delete 'step is bag-medium-items' add 'step is bag-small-items'; rule B11 if 'step is bag-small-items' and the items_to_be_bagged of order include Item and the size of Item is small and the current_bag of order is Bag and the number_of_large_items of Bag is 0 and the number_of_medium_items of Bag is 0 and the number_of_small_items of Bag is S and S < 18 delete the items_to_be_bagged of order include Item and the number_of_small_items of Bag is S add the contents of Bag include Item and the number_of_small_items of Bag is S + 1; rule B12 if 'step is bag-small-items' and the items_to_be_bagged of order include Item and the size of Item is small and NewBag is an instance of bag and the number_of_large_items of NewBag is 0 and the number_of_medium_items of NewBag is 0 and the number_of_small_items of NewBag is 0 and the current_bag of order is Bag delete the current_bag of order is Bag add the current_bag of order is NewBag; rule B13 if 'step is bag-small-items' delete 'step is bag-small-items' add 'step is done';