Question 1: ========== Consider the following class dictionary graph CUBE: CubePaths = List(A). List(S) ~ { S} . A = [B] [D] [E] . B = [A] [C] [F] . C = [B] [D] [G] . D = [A] [C] [H] . E = [A] [F] [H] . F = [B] [E] [G] . H = [D] [E] [G] . G = [C] [F] [H] . Dummy = List(Visited). Visited : A | B | C | D | E | F | H | G | Comment. Comment = DemString. 1a) === Find the unknowns in the following propagation directive and propagation graph: Traversal directive: *from* { CubePaths } *to* { A } Propagation graph for traversal: *source* { CubePaths } *target* { A } *paths* CubePaths = < paths > A_List (*inherits* ) . A = [ < b > B ] [ < d > D ] [ < e > E ] (*inherits* ) . B = [ < a > A ] [ < c > C ] [ < f > F ] (*inherits* ) . C = [ < b > B ] [ < d > D ] [ < g > G ] (*inherits* ) . D = [ < a > A ] [ < c > C ] [ < h > H ] (*inherits* ) . E = [ < a > A ] [ < f > F ] [ < h > H ] (*inherits* ) . F = [ < b > B ] [ < e > E ] [ < g > G ] (*inherits* ) . H = [ < d > D ] [ < e > E ] [ < g > G ] (*inherits* ) . G = [ < c > C ] [ < f > F ] [ < h > H ] (*inherits* ) . A_List ~ { A } (*inherits* ) . 1b) === Find the unknowns below (use class dictionary graph CUBE): Traversal directive: *from* { A } *via* { B } *via* { F } *to* { G } The propagation graph of this directive is UNKNOWN (give a description in less than 5 words). Recall that a propagation directive has information loss if the propagation graph contains a knowledge path which does not satisfy the propagation directive. Does this propagation have information loss? Answer = UNKNOWN If the answer is "yes", give a path (containing 3 edges UNKNOWN1, UNKNOWN, UNKNOWN) which is in the propagation graph but which does not satisfy the directive. 1c) === Find the unknowns in the following propagation directive and propagation graph: Traversal directive: *from* A *bypassing* -> *,e,*, -> *,f,*, -> *,c,*, -> *,d,* *to-stop* B Propagation graph for traversal: *source* { A } *target* { B } *paths* A = [ < b > B ] (*inherits* ) . B = (*inherits* ) . Question 2: =========== Consider the class dictionary graph CUBE from the previous question: CubePaths = List(A). List(S) ~ "(" {"," S} ")". A = "a" [B] [D] [E] ".". B = "b" [A] [C] [F] ".". C = "c" [B] [D] [G] ".". D = "d" [A] [C] [H] ".". E = "e" [A] [F] [H] ".". F = "f" [B] [E] [G] ".". H = "h" [D] [E] [G] ".". G = "g" [C] [F] [H] ".". Dummy = List(Visited). Visited : A | B | C | D | E | F | H | G | Comment. Comment = DemString. CubePaths = List(A). List(S) ~ UNKNOWN {UNKNOWN S} UNKNOWN. A = UNKNOWN [B] UNKNOWNy [D] [E] UNKNOWNx. B = UNKNOWN [A] UNKNOWNy [C] [F] UNKNOWNx. C = UNKNOWN [B] UNKNOWNy [D] [G] UNKNOWNx. D = UNKNOWN [A] UNKNOWNy [C] [H] UNKNOWNx. E = UNKNOWN [A] UNKNOWNy [F] [H] UNKNOWNx. F = UNKNOWN [B] UNKNOWNy [E] [G] UNKNOWNx. H = UNKNOWN [D] UNKNOWNy [E] [G] UNKNOWNx. G = UNKNOWN [C] UNKNOWNy [F] [H] UNKNOWNx. Dummy = List(Visited). Visited : A | B | C | D | E | F | H | G | Comment. Comment = DemString. Make the class dictionary graph into a class dictionary by filling in the unknowns so that the two objects : CubePaths ( < paths > : A_List { : A ( < b > : B ( < f > : F ( < g > : G ( ) ) ) ) , : A ( < b > : B ( < c > : C ( < d > : D ( < h > : H ( < e > : E ( < f > : F ( < g > : G ( ) ) ) ) ) ) ) ) } ) have the following representation as sentences: ( , a b f g . . . . , a b c d h e f g . . . . . . . . ) Question 3: =========== Consider the following propagation pattern which is customized by class dictionary CUBE from the previous question. *operation* Visited_List* f4() *init* (@ new Visited_List() @) *traverse* *from* CubePaths *to* A *wrapper* CubePaths *suffix* (@ return_val -> append(new Comment(new DemString(" f4 is done"))); @) *wrapper* A *prefix* (@ this -> ff4(return_val); @) *operation* void ff4(Visited_List* visited) *traverse* *from* A *bypassing* -> *,e,*, -> *,f,*, -> *,c,*, -> *,d,* *to-stop* B *wrapper* * *prefix* (@ visited -> append(this); cout << " visited " << endl << this << endl; @) Find the unknowns in the descriptions below: The above propagation pattern is called for the following input object: : CubePaths ( < paths > : A_List { : A ( < b > : B ( < f > : F ( < g > : G ( < h > : H ( < d > : D ( ) ) ) ) ) ) } ) which has the following representation as a sentence: ( ,a b f g h d...... ) The trace produced is: >> Visited_List* CubePaths::f4() >> void CubePaths::f4_(Visited_List* & return_val) >> void A_List::f4_(Visited_List* & return_val) >> void A::f4_(Visited_List* & return_val) >> void A::ff4(Visited_List* visited) visited a b f g h d . . . . . . >> void B::ff4(Visited_List* visited) visited b f g h d . . . . . << void B::ff4(Visited_List* visited) << void A::ff4(Visited_List* visited) >> void B::f4_(Visited_List* & return_val) >> void F::f4_(Visited_List* & return_val) >> void G::f4_(Visited_List* & return_val) >> void H::f4_(Visited_List* & return_val) >> void D::f4_(Visited_List* & return_val) << void D::f4_(Visited_List* & return_val) << void H::f4_(Visited_List* & return_val) << void G::f4_(Visited_List* & return_val) << void F::f4_(Visited_List* & return_val) << void B::f4_(Visited_List* & return_val) << void A::f4_(Visited_List* & return_val) << void A_List::f4_(Visited_List* & return_val) << void CubePaths::f4_(Visited_List* & return_val) << Visited_List* CubePaths::f4() Result returned by f4 (printed with g_print()): (, a b f g h d . . . . . . , b f g h d . . . . . , " f4 is done" ) Question 4: =========== Consider the following class dictionary BASKET: Basket = NestedBasket. NestedBasket = "nested" "basket" SeveralThings. SeveralThings : None | OneOrMore. None = "()". OneOrMore = "(" Thing SeveralThings ")". Thing : NestedBasket | Fruit. Fruit : Apple | Orange *common* DemNumber. Apple = "apple". Orange = "orange". Dummy = List(Thing). List(S) ~ "(" {S} ")". Find the unknowns below: // Add the weight of all Apple-objects. *operation* int all_apples() *init* (@ 0 @) *traverse* *from* Basket *to* Apple *wrapper* Apple *prefix* (@ return_val += *(this -> get_weight()); @) // Add the weight of all Fruit-objects. *operation* int all_fruit() *init* (@ 0 @) *traverse* *from* Basket *to* Fruit *wrapper* Fruit *prefix* (@ return_val += *(this -> get_weight()); @) // Produce a list of all Thing-objects. *operation* Thing_List* all_thing() *init* (@ new Thing_List() @) *traverse* *from* Basket *to* Thing *wrapper* Thing *prefix* (@ return_val -> append(this); @) // Produce a list of all Thing-objects which contain an Apple. *operation* Thing_List* all_thing_containing_apples(int& apple_count) *init* (@ new Thing_List() @) *traverse* *from* Basket *via* Thing *to* Apple // // transportation pattern // *carry* *in* int& apple_count = (@ 0 @) // *along* *from* Basket *to* Apple *wrapper* Apple *prefix* (@ apple_count ++ ;@) *wrapper* Thing *prefix* (@ int before = apple_count; @) *suffix* (@ if (apple_count > before) return_val -> append(this); @) //Add two to the weight of all Orange-objects. *operation* void oranges_plus_two() *traverse* *from* Basket *to* Orange *wrapper* Orange *prefix* (@ cout << "weight before change " << this-> get_weight() << endl; //set_weight(new DemNumber((this -> get_weight()) + 2)); // why no type error? this -> set_weight(new DemNumber(*(this -> get_weight()) + 2)); cout << "weight after change " << this-> get_weight() << endl; @) Question 5: =========== We reuse class dictionary BASKET. Consider the propagation pattern: //Print all Thing-objects and for each print its nesting level. // (Things in the outermost basket have level 0.) *operation* void print_nesting_level() *traverse* *from* Basket *to* Thing // transportation pattern *carry* *out* int nesting_level = (@ -1 @) *along* *from* Basket *to* Thing *wrapper* NestedBasket *prefix* (@ nesting_level = nesting_level + 1 ; @) *suffix* (@ nesting_level = nesting_level - 1 ; @) *wrapper* Thing *prefix* (@ cout << this << endl << " nesting_level " << nesting_level ; @) Which output gets produced by the above propagation pattern on input nested basket ( apple 10 (orange 15 ( nested basket ( orange 11 (apple 14 ( nested basket ( apple 8 ()) ( apple 9 ())))) ()))) Find the unknowns in the output below: nested basket ( apple 10 ( orange 15 ( nested basket ( orange 11 ( apple 14 ( nested basket ( apple 8 () ) ( apple 9 () ) ) ) ) () ) ) ) nesting_level -1 apple 10 nesting_level 0 orange 15 nesting_level 0 nested basket ( orange 11 ( apple 14 ( nested basket ( apple 8 () ) ( apple 9 () ) ) ) ) nesting_level 0 orange 11 nesting_level 1 apple 14 nesting_level 1 nested basket ( apple 8 () ) nesting_level 1 apple 8 nesting_level 2 apple 9 nesting_level 1 Question 6 : ============ Consider the propagation pattern and the corresponding C++ code which was obtained for class dictionary BASKET. Find the unknowns. //Print all Thing-objects and for each print its nesting level. // (Things in the outermost basket have level 0.) *operation* void print_nesting_level() *traverse* *from* Basket *to* Thing // transportation pattern *carry* *out* int nesting_level = (@ -1 @) *along* *from* Basket *to* Thing *wrapper* NestedBasket *prefix* (@ nesting_level = nesting_level + 1 ; @) *suffix* (@ nesting_level = nesting_level - 1 ; @) *wrapper* Thing *prefix* (@ cout << this << endl << " nesting_level " << nesting_level ; @) ============ // Basket = NestedBasket . void Basket::print_nesting_level( ) { // variables for carrying in and out int nesting_level = -1 ; // outgoing calls this->get_nested()->print_nesting_level( nesting_level ); } // NestedBasket = "nested" // "basket" // SeveralThings . void NestedBasket::print_nesting_level( int& nesting_level ) { // prefix class wrappers cout << this << endl << " nesting_level " << nesting_level ; nesting_level = nesting_level + 1 ; // outgoing calls this->get_contents()->print_nesting_level( nesting_level ); // suffix class wrappers nesting_level = nesting_level - 1 ; } // SeveralThings : None | // OneOrMore // *common* . void SeveralThings::print_nesting_level( int& nesting_level ) { } // OneOrMore = "(" // Thing // SeveralThings // ")" . void OneOrMore::print_nesting_level( int& nesting_level ) { // outgoing calls this->get_one()->print_nesting_level( nesting_level ); this->get_more()->print_nesting_level( nesting_level ); } // Thing : NestedBasket | // Fruit // *common* . void Thing::print_nesting_level( int& nesting_level ) { // prefix class wrappers cout << this << endl << " nesting_level " << nesting_level ; }