Check-in [d386b956f2]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Reworked the way polymorphic events are dispatched. Previously, the mapping of polymorphic events to ordinary events happened before being placed on the event queue. Now the mapping happens during event dispatch and transitioning. This give a clearer picture of what is happening. Also, improved the formatting of trace messages, particularly the parameters to events and the identifiers of the instances involved in a transition. Added a relationship command to delete multi-assigner instances.
Timelines: family | ancestors | descendants | both | rosea-develop
Files: files | file ages | folders
SHA1: d386b956f29b522126b6b3fc49d7067987fbc4aa
User & Date: andrewm 2020-05-12 14:26:35
Context
2020-05-13
09:08
Corrected a problem where the delete operation was failed to be set for assigners on associative relationships. check-in: c9eedf8bcd user: andrewm tags: rosea-develop
2020-05-12
14:28
Merging fixes from the rosea-develop branch. Release of rosea 1.10. check-in: d222d3e907 user: andrewm tags: trunk, rosea_1.10
14:26
Reworked the way polymorphic events are dispatched. Previously, the mapping of polymorphic events to ordinary events happened before being placed on the event queue. Now the mapping happens during event dispatch and transitioning. This give a clearer picture of what is happening. Also, improved the formatting of trace messages, particularly the parameters to events and the identifiers of the instances involved in a transition. Added a relationship command to delete multi-assigner instances. check-in: d386b956f2 user: andrewm tags: rosea-develop
2020-05-07
14:23
Corrected a regression introduced in version 1.9.1. The changes to the mapping of polymorphic events so that it appears that the events cascade down a hierarchy disguises the origin of the event. If the original source of the event was outside of a state machine context, it would appear that the event originated from within a state machine and fail to start the required data transaction check-in: 830256cde2 user: andrewm tags: rosea-develop
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added modules/rosea-1.10.tm.















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2020 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors and
# need not follow the licensing terms described here, provided that the
# new terms are clearly indicated on the first page of each file where
# they apply.
# 
# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES
# THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# 
# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
# OR MODIFICATIONS.
# 
# GOVERNMENT USE: If you are acquiring this software on behalf of the
# U.S. government, the Government shall have only "Restricted Rights"
# in the software and related documentation as defined in the Federal
# Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
# are acquiring the software on behalf of the Department of Defense,
# the software shall be classified as "Commercial Computer Software"
# and the Government shall have only "Restricted Rights" as defined in
# Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the foregoing,
# the authors grant the U.S. Government and others acting in its behalf
# permission to use and distribute the software in accordance with the
# terms specified in this license.

package require Tcl 8.6

package require logger
package require ral
package require ralutil
package require struct::set
package require lambda

proc ::K {x y} {set x}

namespace eval ::rosea {
    namespace export configure
    
    namespace export configureFromChan
    
    namespace export configureFromFile
    
    namespace export generate
    
    namespace export populate
    
    namespace export populateFromChan
    
    namespace export populateFromFile
    
    namespace export save
    
    namespace export restore
    
    namespace export info
    
    namespace export tunnel
    
    namespace export trace
    
    namespace ensemble create

    variable version 1.10

    logger::initNamespace [namespace current]

    namespace import\
        ::ral::relation\
        ::ral::tuple\
        ::ral::relformat\
        ::ralutil::pipe
    namespace import ::ral::relvar
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation project ~ Name Type |
        relation dict ~ Name Type
    } headingQuery
    
    pipe {
        relation semijoin $class $Identifier -using {Domain Domain Name Class}\
                $IdentifyingAttribute |
        relation group ~ Attributes Attribute
    } idQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $UserSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } defaultValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $SystemSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } suppliedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $GeneratedValue -using {Domain Domain Class Class Name Attribute}
    } generatedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $ValueCheck -using {Domain Domain Class Class Name Attribute}
    } checkValuesQuery
    
    pipe {
        relation semijoin $class $StateModel -using {Domain Domain Name Model} |
        relation isnotempty
    } hasSMQuery
    
    pipe {
        relation semijoin $class $State -using {Domain Domain Name Model} |
        relation project ~ Name Parameters Action
    } statesQuery
    
    pipe {
        relation join $AttributeReference $refing\
            -using {Domain Domain ReferringClass Class\
            Relationship Relationship ReferringRole Role} |
        relation rename ~ Conditionality ReferringCond\
                Multiplicity ReferringMult |
        relation join ~ $refed -using {Domain Domain\
            ReferencedClass Class Relationship\
            Relationship ReferencedRole Role} |
        relation project ~ Domain Relationship\
            ReferringClass ReferringAttribute\
            ReferencedClass ReferencedAttribute\
            ReferringCond ReferringMult Conditionality |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } referencesQuery
    
    pipe {
        relation semijoin $cassocs $AssociatorClass\
                -using {Domain Domain Name Relationship}\
            $ReferringClass $AttributeReference\
                -using {Domain Domain Class ReferringClass\
                Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute ReferencedRole |
        relation join ~ $bothclass -using {Domain Domain Relationship Relationship\
                ReferencedClass Class ReferencedRole Role} |
        relation group ~ ReferringAttrs ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } assocrefsQuery
    
    pipe {
        relation semijoin $rships $Generalization\
                $Subclass -using {Domain Domain Name Relationship}\
                $ReferringClass $AttributeReference\
                    -using {Domain Domain Class ReferringClass\
                    Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } subrefsQuery
    
    proc configure {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Config $script
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc configureFromChan {chan} {
        tailcall configure [::chan read -nonewline $chan]
    }
    proc configureFromFile {filename} {
        set f [::open $filename r]
        try {
            configureFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc generate {{pattern *} {prefix {}}} {
        if {$prefix ne {}} {
            if {[string range $prefix 0 1] ne "::"} {
                set prefix [uplevel 1 {namespace current}]::$prefix
            }
            set prefix [string trimright $prefix :]
        } elseif {$prefix eq "::"} {
            set prefix {} ; # <1>
        }
        namespace upvar Config\
            Domain Domain\
            DomainElement DomainElement\
            Class Class\
            Attribute Attribute\
            DefaultValue DefaultValue\
            UserSuppliedValue UserSuppliedValue\
            SystemSuppliedValue SystemSuppliedValue\
            GeneratedValue GeneratedValue\
            ValueCheck ValueCheck\
            Identifier Identifier\
            IdentifyingAttribute IdentifyingAttribute\
            Relationship Relationship\
            Association Association\
            SimpleAssociation SimpleAssociation\
            SimpleReferringClass SimpleReferringClass\
            SimpleReferencedClass SimpleReferencedClass\
            ClassBasedAssociation ClassBasedAssociation\
            AssociatorClass AssociatorClass\
            SourceClass SourceClass\
            TargetClass TargetClass\
            Generalization Generalization\
            Superclass Superclass\
            Subclass Subclass\
            AttributeReference AttributeReference\
            ReferencedIdAttribute ReferencedIdAttribute\
            ReferringClass ReferringClass\
            ReferencedClass ReferencedClass\
            DomainOperation DomainOperation\
            SuppliedOperation SuppliedOperation\
            UserClassOperation UserClassOperation\
            SystemClassOperation SystemClassOperation\
            UserInstanceOperation UserInstanceOperation\
            SystemInstanceOperation SystemInstanceOperation\
            InstanceStateModel InstanceStateModel\
            StateModel StateModel\
            StatePlace StatePlace\
            State State\
            EffectiveEvent EffectiveEvent\
            DeferredEvent DeferredEvent\
            TransitionPlace TransitionPlace\
            StateTransition StateTransition\
            NonStateTransition NonStateTransition\
            AssignerStateModel AssignerStateModel\
            SingleAssigner SingleAssigner\
            MultipleAssigner MultipleAssigner\
            PolymorphicEvent PolymorphicEvent
    
        set genDomain [relation restrict $Domain dom {
            [string match $pattern [tuple extract $dom Name]]
        }]
        relation foreach domain $genDomain {
            set domainName [relation extract $domain Name]
            relvar updateone Config::Domain dtup [list Name $domainName] {
                tuple update $dtup Location $prefix
            }
            
            set domns ${prefix}::$domainName
            namespace eval $domns {
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                ral relvar create __Arch_RefLink {
                    Relationship    string
                    ReferringClass  string
                    ReferencedClass string
                    ReferringAttrs  {Relation
                            {ReferringAttribute string ReferencedAttribute string}}
                } Relationship
                ral relvar create __Arch_AssocRef {
                    Relationship    string
                    AssocClass      string
                    References      {Relation\
                        {Participant string Role string ReferringAttrs {Relation\
                            {ReferringAttribute string ReferencedAttribute string}}}}
                } Relationship
                ral relvar create __Arch_SuperLink {
                    Relationship    string
                    SuperClass      string
                } Relationship
                
                ral relvar create __Arch_SubLink {
                    Relationship    string
                    SubClass        string
                    ReferringAttrs  {Relation\
                        {ReferringAttribute string ReferencedAttribute string}}
                } {Relationship SubClass}
                
                ral relvar association __Arch_R5\
                    __Arch_SubLink Relationship +\
                    __Arch_SuperLink Relationship 1
                ral relvar create __Arch_Link {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar create __Arch_AssociationLink {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                    PrevSrcClass    string
                } {Name SrcClass}
                ral relvar association __Arch_R4\
                    __Arch_AssociationLink {Name PrevSrcClass} ?\
                    __Arch_AssociationLink {Name SrcClass} ?
                ral relvar create __Arch_PartitionLink {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar partition __Arch_R3 __Arch_Link {Name SrcClass}\
                    __Arch_AssociationLink {Name SrcClass}\
                    __Arch_PartitionLink {Name SrcClass}
                ral relvar create __Arch_PartitionDst {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                } {Name SrcClass DstClass}
                ral relvar association __Arch_R2\
                    __Arch_PartitionDst {Name SrcClass} +\
                    __Arch_PartitionLink {Name SrcClass} 1
                ral relvar create __Arch_State {
                    Class string
                    State string
                } {Class State}
                ral relvar create __Arch_Event {
                    Class string
                    Event string
                } {Class Event}
                ral relvar create __Arch_Transition {
                    Class string
                    State string
                    Event string
                    NewState string
                } {Class State Event}
                ral relvar correlation __Arch_R1 __Arch_Transition\
                    {Class State} + __Arch_State {Class State}\
                    {Class Event} + __Arch_Event {Class Event}
                ral relvar create __Arch_InitialState {
                    Class string
                    State string
                } Class
                ral relvar association __Arch_R6\
                    __Arch_InitialState {Class State} ?\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_TerminalState {
                    Class string
                    State string
                } {Class State}
                ral relvar association __Arch_R7\
                    __Arch_TerminalState {Class State} *\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_PolymorphicEvent {
                    Class           string
                    Event           string
                } {Class Event}
            }
            namespace eval $domns namespace path ::rosea::InstCmds
            set domops [relation semijoin $domain $DomainOperation -using {Name Domain}]
            relation foreach domop $domops {
                relation assign $domop\
                    {Name name} {Parameters parameters} {Body body}
                proc ${domns}::$name $parameters [list ::ral relvar eval $body] ; # <1>
            }
            
            namespace eval $domns [list\
                namespace export {*}[relation list $domops Name]\
            ]
            namespace eval $domns namespace ensemble create
            set statemodels [relation semijoin $domain $StateModel\
                -using {Name Domain}]
            
            relvar eval {
                relvar set ${domns}::__Arch_InitialState [pipe {
                    relation project $statemodels Model InitialState |
                    relation rename ~ Model Class InitialState State
                }]
                set states [relation semijoin $domain $StatePlace -using {Name Domain}]
                relvar set ${domns}::__Arch_State [pipe {
                    relation project $states Model Name |
                    relation rename ~ Model Class Name State
                }]
                relvar set ${domns}::__Arch_TerminalState [pipe {
                    relation semijoin $domain $State -using {Name Domain} |
                    relation restrict ~ termtuple {[tuple extract $termtuple IsFinal]} |
                    relation project ~ Model Name |
                    relation rename ~ Model Class Name State
                }]
                set events [relation semijoin $domain $EffectiveEvent\
                    -using {Name Domain}]
                relvar set ${domns}::__Arch_Event [pipe {
                    relation project $events Model Event |
                    relation rename ~ Model Class
                }]
                set alltrans [pipe {
                    relation join $states $events |
                    relation rename ~ Name State
                }] ; # <1>
                set statetrans [relation semijoin $domain $StateTransition\
                    -using {Name Domain}]
                set nontrans [pipe {
                    relation semijoin $domain $NonStateTransition -using {Name Domain} |
                    relation rename ~ TransRule NewState
                }]
                set deftrans [pipe {
                    relation minus $alltrans $TransitionPlace |
                    relation join ~ $StateModel |
                    relation eliminate ~ InitialState |
                    relation rename ~ DefaultTrans NewState |
                    relation update ~ dttup {[tuple extract $dttup State] eq "@"} {
                        tuple update $dttup NewState CH}
                }]
                relvar set ${domns}::__Arch_Transition [pipe {
                    relation union $statetrans $nontrans $deftrans |
                    relation eliminate ~ Domain |
                    relation rename ~ Model Class
                }]
                relvar set ${domns}::__Arch_PolymorphicEvent [pipe {
                    relation semijoin $domain $DeferredEvent\
                        -using {Name Domain} |
                    relation project ~ Model Event |
                    relation rename ~ Model Class
                }]
            }
            variable headingQuery
            variable idQuery
            variable defaultValuesQuery
            variable suppliedValuesQuery
            variable generatedValuesQuery
            variable checkValuesQuery
            variable hasSMQuery
            variable statesQuery
            
            set classes [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Class -using {Domain Domain Element Name}]
            relation foreach class $classes {
                set className ${domns}::[relation extract $class Name]
                namespace eval $className {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $className [list namespace path\
                        [list ::rosea::InstCmds $domns]]
                set heading [eval $headingQuery]
                set idset [list]
                relation foreach id [eval $idQuery] -ascending Number {
                    lappend idset [relation list\
                            [relation extract $id Attributes] Attribute]
                }
                
                relvar create $className $heading {*}$idset
                
                # <1>
                set checkvalues [eval $checkValuesQuery]
                
                if {[relation isnotempty $checkvalues]} {
                    relvar trace add variable $className {insert update set} [list\
                        ::rosea::Helpers::CheckValueTrace\
                        [relation dict $checkvalues Name Expression]\
                    ]
                }
                set defaultvalues [eval $defaultValuesQuery]
                
                if {[relation isnotempty $defaultvalues]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::UserDefaultTrace\
                        [relation dict $defaultvalues Name Type]\
                        [relation dict $defaultvalues Name Value]\
                    ]
                }
                set supplied [eval $suppliedValuesQuery]
                
                if {[relation isnotempty $supplied]} {
                    pipe {
                        relation extend $supplied stup ClassName string {
                            [string cat [tuple extract $stup Class] , [tuple extract $stup Name]]
                        } |
                        relation array ~ ${domns}::__Arch_SuppliedDefault ClassName StartValue 
                    } ; # <1>
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::SupplyDefaultTrace\
                        [relation dict $supplied Name Type]\
                    ]
                }
                set generatecmds [eval $generatedValuesQuery]
                
                if {[relation isnotempty $generatecmds]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::GenerateDefaultTrace\
                        [relation dict $generatecmds Name Type]\
                        [relation dict $generatecmds Name Cmd]\
                    ]
                }
                set hasStateModel [eval $hasSMQuery]
                if {$hasStateModel} {
                    set instid [lindex $idset 0]
                    set instheading [list]
                    foreach attr $instid {
                        lappend instheading $attr [dict get $heading $attr] ; # <1>
                    }
                    lappend instheading __State string
                    relvar create ${domns}::[relation extract $class Name]__STATEINST\
                        $instheading $instid
                    set actns ${className}::__Activity
                    namespace eval $actns {
                        namespace import\
                            ::ral::relation\
                            ::ral::tuple\
                            ::ral::relformat\
                            ::ralutil::pipe
                    }
                    namespace eval $actns [list\
                        namespace path [list\
                            ::rosea::InstCmds\
                            $className\
                            $domns\
                        ]\
                    ]
                    relation foreach state [eval $statesQuery] {
                        relation assign $state\
                            {Name stateName}\
                            {Parameters params}\
                            {Action stateAction}
                        proc ${actns}::$stateName [linsert $params 0 self] $stateAction
                    }
                }
                set opmap [dict create]
                set classops [relation semijoin $class $UserClassOperation\
                    -using {Domain Domain Name Class}]
                relation foreach classop $classops {
                    relation assign $classop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname $params $opbody
                    dict set opmap $opname ${className}::$opname
                }
                
                set sysmap [QuerySystemClassOperations $className false]
                if {$hasStateModel} {
                    set sysmap [dict merge $sysmap [QuerySystemClassOperations $className true]]
                }
                
                namespace ensemble create\
                    -command $className\
                    -map [dict merge $opmap $sysmap]
                set opmap [dict create]
                set instops [relation semijoin $class $UserInstanceOperation\
                    -using {Domain Domain Name Class}]
                relation foreach instop $instops {
                    relation assign $instop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname [linsert $params 0 self] $opbody
                    dict set opmap $opname ${className}::$opname
                }
                set sysmap [QuerySystemInstanceOperations false]
                set hasPolyEvents [relation isnotempty\
                    [relation semijoin $class $PolymorphicEvent\
                        -using {Domain Domain Name Model}]\
                ]
                if {$hasStateModel || $hasPolyEvents} {
                    set sysmap [dict merge $sysmap [QuerySystemInstanceOperations true]]
                }
                
                namespace ensemble create\
                    -command ${className}::Instance\
                    -parameters instref\
                    -map [dict merge $opmap $sysmap]
            }
            set rships [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Relationship -using {Domain Domain Element Name}]
            
            set sassocs [relation semijoin $rships $Association\
                    $SimpleAssociation]
            set refing [relation semijoin $sassocs $SimpleReferringClass\
                    -using {Domain Domain Name Relationship}]
            set refed [relation semijoin $sassocs $SimpleReferencedClass\
                    -using {Domain Domain Name Relationship}]
            variable referencesQuery
            set references [eval $referencesQuery]
            relvar eval {
                set flink [pipe {
                    relation project $references Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set blink [pipe {
                    relation project $references Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%] ; # <1>
                
                relvar union ${domns}::__Arch_Link $flink $blink
                set flink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }] ; # <1>
                set blink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_AssociationLink $flink $blink
                relvar union ${domns}::__Arch_RefLink [relation project $references\
                    Relationship ReferringClass ReferencedClass ReferringAttrs]
            }
            relation foreach reference $references {
                relation assign $reference\
                    {Relationship relationship}\
                    {ReferringClass referringClass}\
                    {ReferencedClass referencedClass}\
                    {ReferringCond referringCond}\
                    {ReferringMult referringMult}\
                    {Conditionality referencedCond}\
                    {SrcAttrs srcAttrs}\
                    {DstAttrs dstAttrs}
            
                # Create the relvar constraint.
                relvar association ${domns}::$relationship\
                     ${domns}::$referringClass $srcAttrs\
                    [MapCondMultToConstraint $referringCond $referringMult]\
                    ${domns}::$referencedClass $dstAttrs\
                    [MapCondMultToConstraint $referencedCond false]
            
                # All simple associations get a link and unlink command in their ensemble.
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkSimple $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkSimple $relationship]\
                ]
            
                # Determine if we have any assigners assocated  with the relationship.
                # Single assigners get different commands from multiple assigners.
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $reference $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $reference $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                        dict set ensemblemap delete [list\
                            ::rosea::RelCmds::deleteMultiAssigner $rpath]
                    }
                }
                # Create the relationship ensemble command.
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            set cassocs [relation semijoin $rships $Association\
                    $ClassBasedAssociation]
            set sourceclass [relation semijoin $cassocs $SourceClass\
                -using {Domain Domain Name Relationship}]
            set targetclass [relation semijoin $cassocs $TargetClass\
                -using {Domain Domain Name Relationship}]
            set bothclass [relation union $sourceclass $targetclass] ; # <1>
            variable assocrefsQuery
            set assocrefs [eval $assocrefsQuery]
            relvar eval {
                set aforw [pipe {
                    relation project $assocrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set arev [relation update $aforw lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}]
                set sources [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "source"} |
                    relation eliminate ~ ReferencedRole
                }]
                set sforw [pipe {
                    relation project $sources Relationship ReferencedClass |
                    relation rename ~ Relationship Name ReferencedClass SrcClass
                }]
                set targets [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "target"} |
                    relation eliminate ~ ReferencedRole
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_Link $aforw $arev $sforw $trev
                set sforw [pipe {
                    relation project $sources Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename ~ Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename % Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                set onerefs [relation rename $sources ReferencedClass OneClass\
                        Conditionality OneCond Multiplicity OneMult\
                        ReferringAttrs OneReferringAttrs SrcAttrs OneSrcAttrs\
                        DstAttrs OneDstAttrs ForwAttrs OneForwAttrs RevAttrs OneRevAttrs]
                set otherrefs [relation rename $targets ReferencedClass OtherClass\
                        Conditionality OtherCond Multiplicity OtherMult ReferringAttrs\
                        OtherReferringAttrs SrcAttrs OtherSrcAttrs DstAttrs OtherDstAttrs\
                        ForwAttrs OtherForwAttrs RevAttrs OtherRevAttrs]
                set bothrefs [relation join $onerefs $otherrefs\
                    -using {Domain Domain ReferringClass ReferringClass\
                        Relationship Relationship}]
                set aforw [pipe {
                    relation project $bothrefs Relationship ReferringClass OtherClass\
                        OtherForwAttrs OneClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            OtherClass DstClass OtherForwAttrs Attrs OneClass PrevSrcClass
                }]
                set arev [pipe {
                    relation project $bothrefs Relationship ReferringClass OneClass\
                            OneForwAttrs OtherClass |
                    relation rename % Relationship Name ReferringClass SrcClass\
                            OneClass DstClass OneForwAttrs Attrs OtherClass PrevSrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_AssociationLink $sforw $trev $aforw $arev
                relvar union ${domns}::__Arch_AssocRef [pipe {
                    relation project $assocrefs Relationship ReferringClass\
                        ReferencedClass ReferencedRole ReferringAttrs |
                    relation rename ~ ReferringClass AssocClass ReferencedClass Participant\
                        ReferencedRole Role |
                    relation group ~ References Participant Role ReferringAttrs
                }]
            }
            relation foreach bothref $bothrefs {
                relation assign $bothref\
                    {Relationship relationship}\
                    {ReferringClass associator}\
                    {OneClass sourceClass}\
                    {OneCond sourceCond}\
                    {OneMult sourceMult}\
                    {OneSrcAttrs sourceAssocAttrs}\
                    {OneDstAttrs sourceDstAttrs}\
                    {OtherClass targetClass}\
                    {OtherCond targetCond}\
                    {OtherMult targetMult}\
                    {OtherSrcAttrs targetAssocAttrs}\
                    {OtherDstAttrs targetDstAttrs}
            
                # Create the correlation constraint
                relvar correlation ${domns}::$relationship ${domns}::$associator\
                    $sourceAssocAttrs [MapCondMultToConstraint $targetCond $targetMult]\
                    ${domns}::$sourceClass $sourceDstAttrs\
                    $targetAssocAttrs [MapCondMultToConstraint $sourceCond $sourceMult]\
                    ${domns}::$targetClass $targetDstAttrs ; # <1>
            
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkAssoc $relationship]\
                    reference [list ::rosea::RelCmds::referenceAssoc $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkAssoc $relationship]\
                ]
                # Determine if we have any assigners
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $bothref $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $bothref $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                    }
                }
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            variable subrefsQuery
            set subrefs [eval $subrefsQuery]
            relvar eval {
                set sublinks [pipe {
                    relation project $subrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set superlinks [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_Link $sublinks $superlinks
                relvar union ${domns}::__Arch_AssociationLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferencedClass\
                            ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                relvar union ${domns}::__Arch_PartitionLink $superlinks
                relvar union ${domns}::__Arch_PartitionDst [pipe {
                    relation project $subrefs Relationship ReferencedClass\
                            ReferringClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_SuperLink [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename ~ ReferencedClass SuperClass
                }]
                relvar union ${domns}::__Arch_SubLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferringAttrs |
                    relation rename ~ ReferringClass SubClass
                }]
            }
            set partrefs [pipe {
                relation project $subrefs Relationship ReferencedClass DstAttrs\
                        ReferringClass SrcAttrs |
                relation extend ~ prs SubAttrMap list {[list\
                        ${domns}::[tuple extract $prs ReferringClass]\
                        [tuple extract $prs SrcAttrs]]} |
                relation eliminate ~ ReferringClass SrcAttrs |
                relation group ~ SubClassRefs SubAttrMap |
                relation extend ~ spt SubParts list {
                        [concat {*}[relation list [tuple extract $spt SubClassRefs]]]} |
                relation eliminate ~ SubClassRefs
            }]
            
            relation foreach partref $partrefs {
                relation assign $partref\
                    {Relationship relationship}\
                    {ReferencedClass superclass}\
                    {DstAttrs superattrs}\
                    {SubParts subparts}
            
                relvar partition ${domns}::$relationship ${domns}::$superclass\
                        $superattrs {*}$subparts
                namespace ensemble create\
                    -command ${domns}::$relationship\
                    -map [dict create migrate [list ::rosea::RelCmds::migrate\
                            $relationship]]
            }
            set assigners [relation semijoin $domain $AssignerStateModel\
                    -using {Name Domain}]
            relation foreach assigner $assigners {
                set asgnns\
                    ${domns}::[relation extract $assigner Relationship]::__Activity
                namespace eval $asgnns {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $asgnns [list\
                    namespace path [list\
                        ::rosea::InstCmds\
                        $domns\
                    ]\
                ]
                set states [pipe {
                    relation semijoin $assigner $State\
                        -using {Domain Domain Relationship Model} |
                    relation project ~ Name Parameters Action
                }]
                relation foreach state $states {
                    relation assign $state\
                        {Name stateName}\
                        {Parameters params}\
                        {Action stateAction}
                    set params [linsert $params 0 self]
                    proc ${asgnns}::$stateName $params $stateAction
                }
            }
            relation foreach sassigner\
                    [relation semijoin $domain $SingleAssigner\
                    -using {Name Domain}] {
                relation assign $sassigner {Relationship relationship}
                relvar create ${domns}::${relationship}__STATEINST {
                    Id      int
                    __State string
                } Id
                CreateInInitialState $domns $relationship {Id 0} ; # <1>
            }
            relation foreach massigner\
                    [relation semijoin $domain $MultipleAssigner\
                    -using {Name Domain}] {
                relation assign $massigner {Relationship relationship}
                set assignvar ${domns}::${relationship}__STATEINST
            
                set idattrs [pipe {
                    relation semijoin $massigner $Identifier\
                        $IdentifyingAttribute\
                        $Attribute -using {Domain Domain Class Class\
                            Attribute Name} |
                    relation dict ~ Name Type
                }]
                relvar create $assignvar\
                    [concat $idattrs [list __State string]]\
                    [dict keys $idattrs]
            }
        }
    }
    proc populate {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Populate $script ; # <1>
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc populateFromChan {chan} {
        tailcall populate [::chan read -nonewline $chan]
    }
    proc populateFromFile {filename} {
        set f [::open $filename r]
        try {
            populateFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc save {args} {
        set savecmd ::ral::serializeToFile
        set asynccmd {}
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set savecmd ::ral::storeToSQLite
                    }
                    -tclral {
                        set savecmd ::ral::serializeToFile
                    }
                    -async {
                        set options [lassign $options asynccmd]
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION save $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} { # <1>
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError SAVE_ARG_ERROR $args
        }
    
        set script "try \{$savecmd $file ${domain}::\\\[A-Za-z0-9\\\]*\}" ; # <2>
        if {$asynccmd ne {}} {
            append script " finally \{$asynccmd $domain $file\}"
        }
    
        after idle [list ::apply [list {} $script]] ; # <3>
    }
    proc restore {args} {
        set restorecmd ::ral::mergeFromFile
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set restorecmd ::ral::mergeFromSQLite
                    }
                    -tclral {
                        set restorecmd ::ral::mergeFromFile
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION restore $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} {
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError RESTORE_ARG_ERROR $args
        }
    
        eval [list $restorecmd $file $domain]
    
        # Determine the values for the system supplied defaults.  We examine all
        # the classes that have such attributes and find the maximum value of the
        # attribute.  This can then be placed in the array that is used when new
        # default values are generated.
        set domainname [namespace tail $domain]
        set supplied [pipe {
            relvar set ::rosea::Config::SystemSuppliedValue |
            relation restrictwith ~ {$Domain eq $domainname}
        }]
    
        relation foreach sup $supplied {
            relation assign $sup
            set classtups [relvar set ${domain}::$Class]
            if {[relation isempty $classtups]} {
                set maxvalue $StartValue
            } else {
                set maxvalue [pipe {
                    relation summarizeby $classtups {} cv\
                        MaxValue int {rmax($cv, $Attribute)} |
                    relation extract ~ MaxValue
                }]
            }
            set ${domain}::__Arch_SuppliedDefault($Class,$Attribute)\
                [expr {$maxvalue + 1}]
        }
        return
    }
    proc info {args} {
        set args [lassign $args subcmd]
    
        switch -exact -- $subcmd {
            domain {
                Info::domain $args
            }
            class {
                Info::class $args
            }
            statemodel {
                Info::statemodel $args
            }
            default {
                tailcall DeclError UNKNOWN_INFO_CMD $subcmd
            }
        }
    }
    proc tunnel {instref op args} {
        relvar eval {
            set result [[lindex $instref 0]::Instance $instref $op {*}$args]
        }
        return $result
    }
    proc trace {subcmd args} {
        switch -exact -- $subcmd {
            control {
                tailcall traceControl {*}$args
            }
            decode {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DecodeAllTraces
                    }
                    class {
                        tailcall Trace::DecodeClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DecodeTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            format {
                tailcall formatTraces {*}$args
            }
            diagram {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DiagAllTraces {*}[lrange $args 1 end]
                    }
                    class {
                        tailcall Trace::DiagClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DiagTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            default {
                tailcall DeclError UNKNOWN_TRACE_CMD $subcmd
            }
        }
    }
    proc traceControl {op args} {
        switch -exact -- $op {
            on {
                namespace upvar Trace traceState traceState
                set traceState on
            }
            off {
                namespace upvar Trace traceState traceState
                set traceState off
            }
            status {
                namespace upvar Trace traceState traceState
                return $traceState
            }
            clear {
                relvar eval {
                    foreach rvar {Trace Creation Polymorphic Transition} {
                        relvar set Trace::$rvar\
                                [relation emptyof [relvar set Trace::$rvar]]
                    }
                }
                namespace upvar Trace traceNumber traceNumber
                set traceNumber 0
            }
            logon {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState on
            }
            logoff {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState off
            }
            loglevel {
                namespace upvar Trace traceLogLevel traceLogLevel
                if {[llength $args] != 0} {
                    set traceLogLevel [lindex $args 0]
                }
                return $traceLogLevel
            }
            save {
                if {[llength $args] == 0} {
                    DeclError NO_SAVEFILE
                }
                ral storeToSQLite [lindex $args 0] ::rosea::Trace::*
            }
            default {
                DeclError BAD_TRACEOP $op
            }
        }
    }
    proc formatTraces {tracerecs} {
        if {[llength $tracerecs] == 0} {
            return {}
        }
        set prevtime [dict get [lindex $tracerecs 0] time]
        foreach rec $tracerecs {
            dict with rec {
                append result "[Trace::FormatTimestamp $time]: "
                append result "[Trace::FormatTimeAsSec\
                        [expr {$time - $prevtime}]]: "
                set prevtime $time
                append result [Trace::FormatTraceRec $rec] \n
            }
        }
        return [string trimright $result]
    }
    namespace eval Helpers {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        variable errFormats
        set errFormats [dict create {*}{
            SAME_CLASS   {operation is only allowed for references to the same class,\
                            got "%s" and "%s"}
            UNKNOWN_STATE   {unknown state, "%s", for class, "%s"}
            UNKNOWN_EVENT   {unknown event, "%s", for class, "%s"}
            NO_CREATION_EVENTS   {class, "%s", has no defined creation events}
            NO_CROSS_DOMAIN         {cannot link instances across domains,\
                                        got "%s" and "%s"}
            UNKNOWN_RELATIONSHIP    {unknown relationship, "%s"}
            NON_PARTICIPANTS        {"%s" and "%s" don't participate in %s,\
                                        expected "%s" and "%s"}
            MUST_BE_SINGULAR    {number of referred to instances for "%s" must be one,\
                                    got %d}
            NOT_IN_ASSOCIATION         {"%s" $relvar1 not a participant in "%s"}
            DIRECTION_REQUIRED  {direction argument is required: got "%s"}
            AMBIGUOUS_UNLINK         {"%s" is reflexive and linking via "%s" is ambiguous}
            NO_SUBCLASS         {relationship "%s" does not have a "%s"}
            NO_ASSIGNER         {relationship, "%s", does not have an assigner}
            NO_IDENTIFIER       {bad identifying attributes, expected "%s", got "%s"}
            UNKNOWN_ASSIGNER    {unknown assigner instance, "%s", for relationship, "%s"}
            UNKNOWN_LINKAGE {unknown relationship, "%s", for class, "%s"}
            PATH_ERROR      {relationship, "%s", from "%s" to "%s", does not end at "%s"}
            GEN_PATH_ERROR  {navigating from superclass, "%s", along generalization "%s",\
                            does not have "%s" as a subclass}
            ARG_ERROR           {attribute updates must be name / value pairs, got "%s"}
            ID_UPDATE           {cannot update identifying attributes, "%s"}
            UNKNOWN_ATTRIBUTE   {unknown attribute, "%s"}
            WITH_ATTR_USAGE {wrong arguments, should be,\
                    "withAttribute attrvarpair1 ?attrvarpair2 ...? body"}
            ATTR_VAR_SPEC   {attribute / variable argument must be a one or two element\
                    list, got "%s"}
            INVALID_TIME    {invalid time value, "%s"}
            SINGLE_OR_EMPTY_REF_REQUIRED {single valued or nil reference required, %d found}
            SINGLE_REF_REQUIRED     {single valued reference required, %d found}
            UNKNOWN_EVENT_TYPE     {unknown event type, \"%s\"}
            EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
            CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}
            ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
            with attributes, "%s", failed: %s}
            CONFIG_ERRORS     {encountered %d configuration script errors}
            EMPTY_NAME      {the empty string is not a valid name for a %s}
            BAD_CLASS_NAME      {class names must be begin with an alphanumeric\
                                character, got: "%s"}
            DUP_ELEMENT_NAME    {a class, relationship or domain operation named, "%s",\
                                already exists}
            RESERVED_NAME {names beginning with two underscore characters are reserved,\
                    "%s" cannot be used as a name in this context}
            INT_TYPE_REQUIRED   {attribute must be of "int" type, got "%s"}
            INT_VALUE_REQUIRED  {an integer value is required, got "%s"}
            ARG_FORMAT      {options and values must come in pairs, got "%s"}
            UNKNOWN_OPTION  {unknown %s command option, "%s"}
            DUP_OP_NAME     {operation call, "%s", already exists}
            NS_QUALIFIERS   {name, "%s", contains namespace qualifiers}
            TILDE_NAME {names beginning with the tilde character are not allowed\
                in this context, "%s"}
                
            BAD_RELATIONSHIP_SPEC  {bad relationship specifier, "%s"}
            NEED_ASSOCIATOR {relationship of type, "%s", requires associative class}
            NEED_REFLEXIVE_PATH {traversal path must be specified for reflexive\
                    association, %s, %s %s %s}
            REFLEXIVE_NOT_ALLOWED   {associations of type, "%s", cannot be reflexive}
            TOO_FEW_SUBCLASSES  {at least 2 subclasses must be specified, got %d}
            BAD_CREATION_TARGET {the target of a creation event must be a state,\
                    got "%s"}
            PSEUDO_STATE    {the transition action, "%s", is not valid as %s}
            EXPECTED_PSEUDO_STATE    {expected CH or IG, got "%s"}
            RELVAR_TRACE_OP     {unexpected relvar trace operation, "%s"}
            ATTR_CHECK_FAILED   {check for attribute, "%s", failed:\
                                instance value was, "%s": "%s" evaluated to "%s"}
            UNKNOWN_DOMAIN  {unknown domain, "%s"}
            ARG_MISMATCH      {number of population values must be a multiple of %d, got %d}
            SAVE_ARG_ERROR  {wrong number of arguments: expected:\
                    "save ?-sqlite | -tclral? ?-async <cmdprefix>?\
                    <domain> <filename>", got: "%s"}
            RESTORE_ARG_ERROR  {wrong number of arguments: expected:\
                    "restore ?-sqlite | -tclral?  <domain> <filename>", got: "%s"}
            UNKNOWN_INFO_CMD  {unknown info request, "%s"}
            UNKNOWN_CLASS  {unknown class, "%s", in domain, "%s"}
            UNKNOWN_TRACE_CMD   {unknown trace subcomand, "%s"}
            BAD_TRACEOP     {unknown trace operation, "%s"}
            NO_SAVEFILE     {no save file name provided}
            BAD_TRACETYPE   {unknown trace type, "%s"}
        }]
        proc ToRef {relvar relvalue} {
            tailcall list $relvar [relation project $relvalue\
                {*}[lindex [relvar identifiers $relvar] 0]] ; # <1>
        }
        proc nilInstRef {} {
            return {{} {{} {}}}
        }
        proc CreateStateInstance {domns class state idattrs} {
            tailcall relvar insert ${domns}::${class}__STATEINST\
                    [concat $idattrs [list __State $state]]
        }
        proc CreateInInitialState {domns class idattrs} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstance $domns $class [relation extract $initstate State]\
                    $idattrs
            }
            return
        }
        proc CreateStateInstanceFromRef {domns class state ref} {
            relation foreach inst [lindex $ref 1] { # <1>
                CreateStateInstance $domns $class $state\
                    [tuple get [relation tuple $inst]]
            }
            return
        }
        proc CreateInInitialStateFromRef {domns class ref} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstanceFromRef $domns $class\
                    [relation extract $initstate State] $ref
            }
            return
        }
        proc MultiAssignerIDAttrs {domain relationship} {
            if {[string range $domain 0 1] eq "::"} {
                set domain [string range $domain 2 end]
            }
            return [pipe {
                relvar restrictone ::rosea::Config::MultipleAssigner\
                    Domain $domain Relationship $relationship |
                relation semijoin ~ $::rosea::Config::Identifier\
                    $::rosea::Config::IdentifyingAttribute |
                relation list ~ Attribute
            }]
        }
        proc SelfInstRef {{level 2}} {
            set foundRef false
            set ref [nilInstRef]
        
            for {set ns [uplevel $level namespace current]} {$ns ne "::"}\
                    {set ns [uplevel [incr level] namespace current]} {
                if {!$foundRef} {
                    upvar $level self srcself
                    if {[info exists srcself]} {
                        set ref $srcself
                        set foundRef true
                    }
                }
                if {[string match {*__Activity*} $ns]} {
                    return $ref ; # <1>
                }
            }
            return [nilInstRef]
        }
        namespace export DeclError
        
        proc DeclError {errcode args} {
            variable errFormats
            set errmsg [format [dict get $errFormats $errcode] {*}$args]
            tailcall throw [list ROSEA $errcode {*}$args $errmsg] $errmsg
        }
        proc SplitRelvarName {relvar {dvarname domain} {cvarname class}} {
            upvar 1 $dvarname domain $cvarname class
            set domain [namespace qualifiers $relvar]
            set class [namespace tail $relvar]
        }
        proc PropagatePolyEvents {super} {
            namespace upvar ::rosea::Config\
                DeferredEvent DeferredEvent\
                LocalEvent LocalEvent\
                Superclass Superclass\
                Subclass Subclass\
                DeferralPath DeferralPath\
                Generalization Generalization ; # <1>
        
            set supername [relation extract $super Class]
        
            set subs [pipe {
                relation semijoin $super\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}
            }]
        
            relation foreach sub $subs {
                set defrdevents [pipe {
                    relation semijoin $super $DeferralPath\
                        -using {Domain Domain Class Model Relationship Relationship}\
                        $DeferredEvent |
                    relation update ~ deftup {1} {
                        tuple update $deftup Model [relation extract $sub Class]
                    }
                }]
                set multigens [relation semijoin $sub $Superclass\
                    -using {Domain Domain Class Class}]
        
                if {[relation isempty $multigens]} {
                    relvar minus ::rosea::Config::LocalEvent $defrdevents
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::EffectiveEvent $defrdevents
                    relvar union ::rosea::Config::MappedEvent [relation extend\
                        $defrdevents metuple ParentModel string {$supername}]
                } else {
                    set consumed [relation semijoin $defrdevents $LocalEvent]
                    if {[relation isnotempty $consumed]} {
                        relvar minus ::rosea::Config::LocalEvent $consumed ; # <1>
                        relvar union ::rosea::Config::MappedEvent [relation extend\
                            $consumed ctup ParentModel string {$supername}]
                        relvar union ::rosea::Config::NonLocalEvent [relation extend\
                            $consumed nletuple\
                            Relationship string {[relation extract $sub Relationship]}\
                            Role string {[relation extract $sub Role]}]
                        set defrdevents [relation minus $defrdevents $consumed] ; # <2>
                    
                        set usedinsubs [pipe {
                            FindSubclassesOf $multigens|
                            relation tclose ~ |
                            relation semijoin $consumed ~ -using {Model Super} |
                            relation semijoin ~ $LocalEvent -using {Sub Model} |
                            relation semijoin $consumed ~ -using {Domain Domain Event Event}
                        }]
                        relvar minus ::rosea::Config::LocalEvent $usedinsubs ; # <3>
                        relvar minus ::rosea::Config::EffectiveEvent $usedinsubs
                        relvar minus ::rosea::Config::Event $usedinsubs
                    }
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::DeferredEvent $defrdevents
                    relvar union ::rosea::Config::InheritedEvent $defrdevents
                    relvar union ::rosea::Config::DeferralPath [relation join\
                        $defrdevents $Superclass -using {Domain Domain Model Class}]
                }
        
                relvar union ::rosea::Config::NonLocalEvent [relation extend\
                    $defrdevents nletuple\
                    Relationship string {[relation extract $sub Relationship]}\
                    Role string {[relation extract $sub Role]}]
                relation foreach multigen $multigens {
                    PropagatePolyEvents $multigen
                }
            }
        }
        proc FindSubclassesOf {supers} {
            namespace upvar ::rosea::Config\
                Generalization Generalization\
                Superclass Superclass\
                Subclass Subclass
        
            if {[relation isempty $supers]} {# <1>
                return [relation create {Super string Sub string}]
            }
            set supnames [pipe {
                relation project $supers Class |
                relation rename ~ Class Super
            }] ; # <2>
            set subclasses [relation semijoin $supers\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}]
            set subnames [pipe {
                relation project $subclasses Class |
                relation rename ~ Class Sub
            }] ; # <3>
            
            set uses [relation times $supnames $subnames] ; # <4>
        
            set nextsupers [relation semijoin $subclasses $Superclass\
                    -using {Domain Domain Class Class}] ; # <5>
        
            return [relation union $uses [FindSubclassesOf $nextsupers]] ; # <6>
        }
        proc UserDefaultTrace {defheading defvalues op relvar tuple} {
            tuple create\
                [dict merge $defheading [tuple heading $tuple]]\
                [dict merge $defvalues [tuple get $tuple]]
        }
        proc SupplyDefaultTrace {defheading op relvar tuple} {
            set attrs [tuple attributes $tuple] ; # <1>
            SplitRelvarName $relvar domain class ; # <2>
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [set ${domain}::__Arch_SuppliedDefault($class,$attrname)] ; # <3>
                    incr ${domain}::__Arch_SuppliedDefault($class,$attrname)
                    set tuple [tuple extend $tuple $attrname $attrtype $value] ; # <4>
                }
            }
            return $tuple
        }
        proc GenerateDefaultTrace {defheading defcmds op relvar tuple} {
            set attrs [tuple attributes $tuple]
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [eval [dict get $defcmds $attrname]]
                    set tuple [tuple extend $tuple $attrname $attrtype $value]
                }
            }
            return $tuple
        }
        proc CheckValueTrace {attrchecks op relvar args} {
            if {$op eq "insert"} {
                set tuple [lindex $args 0]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "update"} {
                set tuple [lindex $args 1]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "set"} {
                set relvalue [lindex $args 0]
                relation foreach inst $relvalue {
                    set tuple [relation tuple $inst]
                    EvalAttrCheck $attrchecks $tuple
                }
                return $relvalue
            } else {
                tailcall DeclError RELVAR_TRACE_OP $op
            }
        }
        proc EvalAttrCheck {attrchecks tuple} {
            dict for {attrname checkexpr} $attrchecks {
                tuple assign $tuple
                set result [expr $checkexpr]
                if {!$result} {
                    tailcall DeclError ATTR_CHECK_FAILED $attrname [tuple get $tuple]\
                        $checkexpr $result
                }
            }
        }
        proc QuerySystemOperations {which requiresSM} {
            return [pipe {
                relvar set ::rosea::Config::SuppliedOperation |
                relation restrictwith ~ {$RequiresStateModel == $requiresSM} |
                relation join [relvar set ::rosea::Config::$which] ~
            }]
        }
        proc QuerySystemClassOperations {className requiresSM} {
            return [pipe {
                QuerySystemOperations SystemClassOperation $requiresSM |
                relation update ~ sco 1 {
                    tuple update $sco Command\
                        [concat [tuple extract $sco Command]\
                        [list $className]]
                } |
                relation dict ~ Name Command
            }]
        }
        proc QuerySystemInstanceOperations {requiresSM} {
            return [pipe {
                QuerySystemOperations SystemInstanceOperation $requiresSM |
                relation dict ~ Name Command
            }]
        }
        proc Interleave {l1 l2} {
            set result [list]
            foreach a $l1 b $l2 {
                lappend result $a $b
            }
            return $result
        }
        proc MapCondMultToConstraint {cond mult} {
            if {$cond} {
                return [expr {$mult ? "*" : "?"}]
            } else {
                return [expr {$mult ? "+" : "1"}]
            }
        }
    }
    namespace eval ClassCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers ; # <1>
        proc findAll {relvar} {
            tailcall ToRef $relvar [relvar set $relvar]
        }
        proc findById {relvar args} {
            tailcall ToRef $relvar [relvar restrictone $relvar {*}$args]
        }
        proc findWhere {relvar expr} {
            tailcall ToRef $relvar [uplevel 1 [list ::ral relation restrictwith\
                [relvar set $relvar] $expr]]
        }
        proc create {relvar args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]] ; # <1>
            SplitRelvarName $relvar domain class
            CreateInInitialStateFromRef $domain $class $ref
            return $ref
        }
        proc createin {relvar state args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $relvar domain class
            set initstate [relvar restrictone ${domain}::__Arch_State\
                Class $class State $state]
            if {[relation isempty $initstate]} { # <1>
                tailcall DeclError UNKNOWN_STATE $state $relvar
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]]
            CreateStateInstanceFromRef $domain $class $state $ref
            return $ref
        }
        proc createasync {relvar event eventparams args} {
            SplitRelvarName $relvar domain class
        
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
            if {[relation isempty [relvar restrictone ${domain}::__Arch_State\
                    Class $class State @]]} {
                tailcall DeclError NO_CREATION_EVENTS $class
            }
            set srcref [SelfInstRef]
            set eventInfo [dict create\
                type creation\
                src $srcref\
                dstClass $relvar\
                dstAttrs $args\
                event $event\
                params $eventparams\
            ]
            if {[::rosea::InstCmds::isRefEqual $srcref [nilInstRef]]} {
                lappend ::rosea::Dispatch::toc_queue $eventInfo
            } else {
                lappend ::rosea::Dispatch::event_queue $eventInfo
            }
            ::after 0 ::rosea::Dispatch::DispatchEvent
            return
        }
        proc update {relvar relvalue} {
            tailcall ToRef $relvar [relvar updateper $relvar $relvalue]
        }
    }
    namespace eval InstCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace path [namespace parent]::Helpers
        pipe {
            relvar set ${domain}::$DstClass |
            relation $op $related ~ -using $Attrs
        } relatedQuery
        proc deRef {instref args} {
            lassign $instref relvar ref
            set inst [relation semijoin $ref [relvar set $relvar]] ; # <1>
            if {[llength $args] != 0} {
                set inst [relation project $inst\
                    {*}[relation attributes $ref] {*}$args] ; # <2>
            }
            return $inst
        }
        proc isEmptyRef {instref} {
            tailcall relation isempty [lindex $instref 1]
        }
        proc isNotEmptyRef {instref} {
            tailcall relation isnotempty [lindex $instref 1]
        }
        proc refMultiplicity {instref} {
            tailcall relation cardinality [lindex $instref 1]
        }
        proc isRefSingular {instref} {
            expr {[refMultiplicity $instref] == 1}
        }
        proc limitRef {instref {count 1}} {
            lassign $instref relvar insts
            return [pipe {
                relation tag $insts __Tag |
                relation restrictwith ~ {$__Tag >= 0 && $__Tag < $count} |
                ToRef $relvar ~
            }]
        }
        proc isRefEqual {instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            return [expr {$relvar1 eq $relvar2 && [relation is $inst1 equal $inst2]}]
        }
        proc RefSetCommand {op instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            if {$relvar1 ne $relvar2} {
                tailcall DeclError SAME_CLASS $relvar1 $relvar2
            }
            return [list $relvar1 [relation $op $inst1 $inst2]]
        }
        proc refUnion {instref1 instref2} {
            tailcall RefSetCommand union $instref1 $instref2
        }
        proc refIntersect {instref1 instref2} {
            tailcall RefSetCommand intersect $instref1 $instref2
        }
        proc refMinus {instref1 instref2} {
            tailcall RefSetCommand minus $instref1 $instref2
        }
        proc forAllRefs {varname instref body} {
            lassign $instref relvar refs
            upvar 1 $varname inst
            relation foreach ref $refs {
                set inst [list $relvar $ref]
                uplevel 1 $body
            } ; # <1>
            return
        }
        proc FindRelatedInsts {instref op args} {
            set srcrelvar [lindex $instref 0]
            SplitRelvarName $srcrelvar domain class
            
            # This procedure queries the architectural data about relationship linkage,
            # so we bring the relvar variables into scope.
            namespace upvar ${domain}\
                    __Arch_Link Link\
                    __Arch_AssociationLink AssociationLink\
                    __Arch_PartitionLink PartitionLink\
                    __Arch_PartitionDst PartitionDst
            variable relatedQuery ; # <1>
            # We start by dereferencing the instance reference.
            set related [deRef $instref]
            foreach linkage $args {
                lassign $linkage lname dst ; # split out the linkage spec
                
                set link [relvar restrictone ${domain}::__Arch_Link\
                        Name $lname SrcClass $class]
                if {[ral relation isempty $link]} {
                    tailcall DeclError UNKNOWN_LINKAGE $lname $class
                }
                # First we determine if we are dealing with an associative link or a
                # partition link.
                set assoc [relation join $link $AssociationLink]
                if {[relation isnotempty $assoc]} {
                    relation assign $assoc DstClass Attrs
                    # Check if additional path information was provided.
                    if {$dst eq {}} {
                        # Find the set of instances related to the current set.
                        set related [eval $relatedQuery]
                        # We must see if this is a class-based association.  If so, then the first
                        # traversal was to the associator and we must traverse again to the other
                        # class.
                        set assoc [relation semijoin $assoc $AssociationLink\
                            -using {Name Name SrcClass PrevSrcClass}]
                        if {[relation isnotempty $assoc]} {
                            relation assign $assoc DstClass Attrs
                            set related [pipe {# <1>
                                relvar set ${domain}::$DstClass |
                                relation semijoin $related ~ -using $Attrs
                            }]
                        }
                    } else {
                        # If a destination was specified in the linkage, then we need to verify
                        # that it is actually part of the relationship.
                        if {$dst ne $DstClass} {
                            tailcall DeclError PATH_ERROR $lname $class $DstClass\
                                $dst
                        }
                        set related [eval $relatedQuery]
                    }
                } else {
                    set partdst [relvar restrictone ${domain}::__Arch_PartitionDst\
                        Name $lname SrcClass $class DstClass $dst]
                    if {[relation isempty $partdst]} {
                        tailcall DeclError GEN_PATH_ERROR $class $lname $dst
                    }
                    relation assign $partdst DstClass Attrs
                    set related [eval $relatedQuery]
                }
                # Continue the iteration by setting the next source to the current
                # destination class.
                set class $DstClass
                set srcrelvar ${domain}::$class
            }
            # N.B. that we are not returning an instance reference but rather the
            # complete relation value of the related instances. This allows us
            # to further filter the result in the "findRelatedWhere" command.
            return [list $srcrelvar $related]
        }
        proc findRelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semijoin {*}$args] ; # <1>
        }
        proc findUnrelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semiminus {*}$args] ; # <1>
        }
        proc findRelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semijoin {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]] ; # <1>
        }
        proc findUnrelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semiminus {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]]
        }
        proc idInstance {instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set idclass [pipe {
                relvar restrictone [namespace parent]::Config::MultipleAssigner\
                        Domain [string trim $domain :] Relationship $relationship |
                relation extract ~ Class
            }]
        
            return [pipe {
                relvar set ${domain}::$idclass |
                relation semijoin $insts ~ |
                ToRef ${domain}::$idclass ~
            }]
        }
        proc updateAttribute {instref args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_ERROR $args
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $args]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach {attr value} $args {
                if {![dict exists $heading $attr]} {
                    tailcall DeclError UNKNOWN_ATTRIBUTE $attr
                }
                lappend extcmd $attr [dict get $heading $attr] \{$value\}
            }
            relvar updateper $relvar [eval $extcmd]
            return
        }
        proc withAttribute {instref args} {
            if {[llength $args] < 2} {
                tailcall DeclError WITH_ATTR_USAGE
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            
            set body [lindex $args end]
            set attrspecs [lrange $args 0 end-1]
            set attrnames [list]
            set varnames [list]
            foreach attrspec $attrspecs {
                set speclen [llength $attrspec]
                if {$speclen == 1} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 0]
                } elseif {$speclen == 2} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 1]
                } else {
                    tailcall DeclError ATTR_VAR_SPEC $attrspec
                }
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $attrnames]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            uplevel 1 [list ral relation assign [deRef $instref] {*}$attrspecs]
            uplevel 1 $body
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach attr $attrnames var $varnames {
                if {[uplevel 1 [list info exists $var]]} {
                    upvar 1 $var varvalue
                    lappend extcmd $attr [dict get $heading $attr] \{$varvalue\}
                }
            }
            relvar updateper $relvar [eval $extcmd]
        
            return
        }
        proc readAttribute {ref args} {
            # We insist upon a singular reference for reading attributes.  Multiple
            # references can be handled by dereferences and using TclRAL "relation"
            # commands.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            return [expr {[llength $args] == 0 ? {} :\
                [relation extract [deRef $ref {*}$args] {*}$args]}] ; # <1>
        }
        proc assignAttribute {ref args} {
            # We must insist upon a singular references, since assigning to scalar
            # variables from a relation value doesn't make a lot of sense.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            uplevel 1 [list ral relation assign [deRef $ref] {*}$args] ; # <1>
            return
        }
        proc delete {args} {
            foreach instref $args {
                lassign $instref relvar insts
                relvar minus $relvar [deRef $instref]
        
                SplitRelvarName $relvar domain class
                set instrelvar ${domain}::${class}__STATEINST
                if {[relvar exists $instrelvar]} {
                    relvar minus $instrelvar [relation semijoin $insts\
                        [relvar set $instrelvar]]
                }
            }
        
            return
        }
        proc signal {dstset event args} {
            set srcref [SelfInstRef]
            ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args
            return
        }
        proc delaysignal {time dstset event args} {
            if {!([string is integer -strict $time] && $time >= 0)} {
                tailcall DeclError INVALID_TIME $time
            }
            set srcref [SelfInstRef]
            ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args
            return
        }
        proc canceldelayed {srcref dstset event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            forAllRefs dstref $dstset {
                ::rosea::Dispatch::CancelDelayedSignal $srcref $event $dstref
            }
            return
        }
        proc delayremaining {srcref dstref event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            if {![isRefSingular $dstref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $dstref]
            }
            tailcall ::rosea::Dispatch::SignalTimeRemaining $srcref $event $dstref
        }
        proc instop {instref op args} {
            tailcall [lindex $instref 0]::Instance $instref $op {*}$args
        }
    }
    namespace eval RelCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        proc linkSimple {rname instref1 instref2} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set reflink [relvar restrictone ${domain1}::__Arch_RefLink Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs} ; # <1>
            if {$class1 eq $referringClass && $class2 eq $referencedClass} {
                set fromrelvar $relvar1
                set frominsts $inst1
                set torelvar $relvar2
                set toinst $inst2
            } elseif {$class2 eq $referringClass && $class1 eq $referencedClass} {
                set fromrelvar $relvar2
                set frominsts $inst2
                set torelvar $relvar1
                set toinst $inst1
            } else {
                tailcall DeclError NON_PARTICIPANTS $relvar1 $relvar2 $rname\
                    $referringClass $referencedClass
            }
            if {[relation cardinality $toinst] != 1} {
                tailcall MUST_BE_SINGULAR $torelvar [relation cardinality $toinst]
            }
            set refedvalue [relation semijoin $toinst [relvar set $torelvar]]
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] { # <1>
                    tuple update $fromtup {*}$tovalues ; # <2>
                }
            }
        
            return
        }
        proc linkAssoc {rname instref1 instref2 args} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${domain1}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            set ref1 [relation restrictwith $references {$Participant eq $class1}]
            if {[relation isempty $ref1]} {
                tailcall DeclError NOT_IN_ASSOCIATION $class1 $rname
            }
            if {[relation cardinality $ref1] > 1} {
                set ref2 [relation restrictwith $ref1 {$Role eq "target"}]
                set ref1 [relation minus $ref1 $ref2] ; # <1>
            } else {
                set ref2 [relation restrictwith $references {$Participant eq $class2}]
                if {[relation isempty $ref2]} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class2 $rname
                }
            }
            
            set rattr1 [relation extract $ref1 ReferringAttrs]
            set rattr2 [relation extract $ref2 ReferringAttrs]
            set values1 [relation semijoin $inst1 [relvar set $relvar1]]
            set values2 [relation semijoin $inst2 [relvar set $relvar2]]
            set assoctuples [list]
            relation foreach v1 $values1 { # <1>
                set refto1 [pipe {
                    relation extend $rattr1 rfa RefValue string {
                        [relation extract $v1 [tuple extract $rfa ReferencedAttribute]]
                    } |
                    relation dict ~ ReferringAttribute RefValue
                }]
                relation foreach v2 $values2 {
                    set refto2 [pipe {
                        relation extend $rattr2 rfa RefValue string {
                            [relation extract $v2\
                                [tuple extract $rfa ReferencedAttribute]]
                        } |
                        relation dict ~ ReferringAttribute RefValue
                    }]
            
                    lappend assoctuples [dict merge $args $refto1 $refto2] ; # <2>
                }
            }
            set ref [ToRef ${domain1}::$assocClass\
                    [relvar insert ${domain1}::$assocClass {*}$assoctuples]]
                CreateInInitialStateFromRef $domain1 $assocClass $ref ; # <1>
            return $ref
        }
        proc referenceAssoc {rname assocref instref {dir {}}} {
            if {![isRefSingular $assocref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $assocref]
            }
            lassign $assocref assocrelvar associnst
            SplitRelvarName $assocrelvar assocdomain assocclass
            
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref instrelvar inst
            SplitRelvarName $instrelvar instdomain instclass
            
            if {$assocdomain ne $instdomain} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${instdomain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            
            if {$assocClass ne $assocclass} {
                tailcall DeclError NOT_IN_ASSOCIATION $assocclass $rname
            }
            set ref [relation restrictwith $references {$Participant eq $instclass}]
            set refcard [relation cardinality $ref]
            if {$refcard == 2} {
                switch -exact -- $dir {
                    forward {
                        set role target
                    }
                    backward {
                        set role source
                    }
                    default {
                        tailcall DeclError DIRECTION_REQUIRED $dir
                    }
                }
                set ref [relation restrictwith $ref {$Role eq $role}]
            } elseif {$refcard == 0} {
                tailcall DeclError NOT_IN_ASSOCIATION $instclass $rname
            }
            set referringAttrs [relation extract $ref ReferringAttrs]
            
            set refedvalue [relation semijoin $inst [relvar set $instrelvar]]
            
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relvar updateone $assocrelvar assoctup [tuple get [relation tuple $associnst]] {
                tuple update $assoctup {*}$tovalues
            }
        }
        proc unlinkSimple {rname instref} {
            lassign $instref relvar inst
            SplitRelvarName $relvar domain class
        
            set reflink [relvar restrictone ${domain}::__Arch_RefLink\
                    Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs}
        
            if {$class eq $referringClass} {
                set fromrelvar $relvar
                set frominsts $inst
            } elseif {$class eq $referencedClass} {
                lassign [::rosea::InstCmds::findRelated $instref ~$rname]\
                    fromrelvar frominsts
            } else {
                tailcall DeclError NOT_IN_ASSOCIATION $relvar $rname
            }
        
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {{}} |
                relation dict ~ ReferringAttribute RefValue
            }]
        
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] {
                    tuple update $fromtup {*}$tovalues
                }
            }
        
            return
        }
        proc unlinkAssoc {rname instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain class
        
            set assocref [relvar restrictone ${domain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $assocref\
                {Relationship relationship}\
                {AssocClass associator}\
                {References references}
        
            # If we are given instances to the associator class, then there is no
            # more work to do.
            if {$class ne $associator} {
                # Otherwise, we have to find the associator class instances ourselves.
                set part [relation restrictwith $references {$Participant eq $class}]
                set partcard [relation cardinality $part]
                if {$partcard == 0} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class $rname
                } elseif {$partcard > 1} {
                    tailcall DeclError AMBIGUOUS_UNLINK $rname $relvar ; # <1>
                } else {
                    # Find associative class instances.  We have to determine the
                    # direction of the relationship traversal.
                    set navdir [expr {[relation extract $part Role] eq "source" ?\
                        "$relationship" : "~$relationship"}]
                    set instref [::rosea::InstCmds::findRelated $instref\
                        [list $navdir [namespace tail $associator]]]
                    lassign $instref relvar insts
                    SplitRelvarName $relvar domain class
                }
            }
        
            # We are going to delete tuples from the relvar that holds the class
            # instances.
            set delrelvars [list ${domain}::$class]
            # If the associative class also has a state model, then we need to also
            # delete the state instance tuples.
            if {[relvar exists ${domain}::${class}__STATEINST]} {
                lappend delrelvars ${domain}::${class}__STATEINST
            }
        
            # Now, we iterate across the associative class instances and delete all the
            # tuples in class relvar and, if necessary, the state instances.
            relation foreach inst $insts {
                set idattrs [tuple get [relation tuple $inst]]
                foreach rv $delrelvars {
                    relvar deleteone $rv {*}$idattrs
                }
            }
            return $instref
        }
        proc migrate {rname instref subclass args} {
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref relvar inst
            SplitRelvarName $relvar domns class
        
            set link [relvar restrictone ${domns}::__Arch_AssociationLink Name $rname\
                    SrcClass $class]
            if {[relation isempty $link]} {
                tailcall DeclError NO_SUBCLASS $rname $relvar
            }
        
            # Traverse the relationship to the superclass. We need to get the values of
            # the referenced attributes to use in creating the new subclass instance.
            set superinst [pipe {
                relvar set ${domns}::[relation extract $link DstClass] |
                relation semijoin $inst ~ -using [relation extract $link Attrs]
            }]
        
            set sublink [relvar restrictone ${domns}::__Arch_SubLink\
                    Relationship $rname SubClass $subclass]
            if {[relation isempty $sublink]} {
                tailcall DeclError NO_SUBCLASS $rname $subclass
            }
        
            # Using the same relation extend strategy, we compute a dictionary of the
            # attribute names / values as they must appear in the subclass we are about
            # to create.
            set refedvalues [pipe {
                relation extract $sublink ReferringAttrs |
                relation extend ~ rval Value string {
                    [relation extract $superinst\
                        [tuple extract $rval ReferencedAttribute]]
                } |
                relation dict ~ ReferringAttribute Value
            }]
        
            # We use the class commands to delete the old subclass instance and create
            # the new one. This will make sure that if the subclass has a state model
            # that the initial state is set correctly.
            # N.B. this is _not_ done in a relvar transaction. The transaction
            # boundaries should be set by the current thread of control or domain
            # operation.
            ::rosea::InstCmds::delete $instref
            return [::rosea::ClassCmds::create ${domns}::$subclass\
                    {*}[dict merge $args $refedvalues]]
        }
        proc signalAssigner {rname event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set dstref [pipe {
                relvar set $assignrelvar |
                relation project ~ {*}[lindex [relvar identifiers $assignrelvar] 0] |
                list $rname ~
            }]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args
        
            return
        }
        proc signalMultiAssigner {rname idvalues event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            # We will insist that the idvalues contain the necessary identifying
            # attributes.
            if {![struct::set equal [dict keys $idvalues] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
            }
            set assigninsts [relvar set $assignrelvar]
            set assignrefs [relation project $assigninsts {*}$idattrs]
        
            # We need to find the tuple in "assignrefs" that matches the attributes and
            # values in "idvalues". We will do this by creating a relation value from
            # the idvalues list and semijoining that to "assignrefs". If we come up
            # non-empty, then we have found our multi-assigner instance.
            set heading [relation heading $assignrefs]
            set dstinst [pipe {
                tuple create $heading $idvalues |
                tuple relation ~ |
                relation semijoin ~ $assignrefs
            }]
            if {[relation isempty $dstinst]} {
                tailcall DeclError UNKNOWN_ASSIGNER $idvalues $rname
            }
        
            set dstref [list $rname $dstinst]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args ; # <1>
        
            return
        }
        proc createMultiAssigner {rname args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            CreateInInitialState $domain $relationship $args
        }
        proc deleteMultiAssigner {rname args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            relvar deleteone $assignrelvar {*}$args
            return
        }
    }
    namespace eval Dispatch {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        variable toc_queue [list]
        variable event_queue [list]
        relvar create DelayedSignal {
            RefId           int
            SrcInstRef      list
            Event           string
            DstInstRef      list
            TimerId         string
            Expire          bignum
        } RefId {SrcInstRef Event DstInstRef} TimerId
        variable DelayedSignalId 0
        pipe {
        relvar restrictone ${domain}::__Arch_Transition\
            Class $class State $currstate Event $event |
            relation extract ~ NewState
        } transitionQuery
        pipe {
            relvar set ${domain}::__Arch_PartitionDst |
            relation restrictwith ~ {$SrcClass eq $dstclass} |
            relation group ~ DstLinks DstClass Attrs
        } polymapQuery
        proc SignalEvent {srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isnotempty [relvar restrictone ${domain}::__Arch_Event\
                Class $class Event $event]]} {
                set eventType ordinary
            } elseif {[IsPolymorphicEvent $domain $class $event]} {
                set eventType polymorphic
            } else {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            set callback [namespace code DispatchEvent]
            set eventInfo [dict create\
                type $eventType\
                src $srcref\
                event $event\
                params $arglist\
            ]
            if {[isRefEqual $srcref [nilInstRef]]} {
                variable toc_queue
                forAllRefs dstref $dstset {
                    # Queue the thread of control events.
                    dict set eventInfo dst $dstref
                    lappend toc_queue $eventInfo
                    ::after 0 $callback
                }
            } else {
                variable event_queue
                forAllRefs dstref $dstset {
                    dict set eventInfo dst $dstref
                    if {[isRefEqual $srcref $dstref]} { # <1>
                        for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
                            set cmpevent [lindex $event_queue $eqindex]
                            if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
                                break
                            }
                        }
                        set event_queue [linsert [K $event_queue [set event_queue {}]]\
                            $eqindex $eventInfo] ; # <1>
                    } else {
                        # Non-self directed events are always simply appended to the
                        # event queue.
                        lappend event_queue $eventInfo
                    }
                    ::after 0 $callback
                }
            }
        }
        proc IsPolymorphicEvent {domain class event} {
            return [relation isnotempty [relvar restrictone\
                ${domain}::__Arch_PolymorphicEvent Class $class Event $event]]
        }
        proc DispatchEvent {} {
            variable event_queue
            variable toc_queue
            
            try {
                if {[llength $event_queue] != 0} {
                    set event_queue [lassign $event_queue eventInfo]
                    TransitionEvent $eventInfo
                } elseif {[llength $toc_queue] != 0} {
                    set toc_queue [lassign $toc_queue eventInfo]
                    relvar transaction begin ;                              # <1>
                    try {
                        TransitionEvent $eventInfo
                    } on error {result opts} {
                        catch {relvar transaction end} ;                    # <2>
                        return -level 0 -options $opts $result
                    }
                } else {
                    return
                }
            } on error {result opts} {
                return -options $opts $result
            }
            
            if {[llength $event_queue] == 0} {
                relvar transaction end
            }
            return
        }
        proc FindDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            return [relation restrictwith $DelayedSignal {
                    [isRefEqual $SrcInstRef $srcref] && $Event eq $event &&\
                    [isRefEqual $DstInstRef $dstref]}]
        }
        proc DeleteDelayedSignal {srcref event dstref} {
            relvar delete DelayedSignal dsig {
                [isRefEqual [tuple extract $dsig SrcInstRef] $srcref] &&\
                [tuple extract $dsig Event] eq $event &&\
                [isRefEqual [tuple extract $dsig DstInstRef] $dstref]
            }
        }
        proc SignalDelayedEvent {time srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            variable DelayedSignalId
            set eventInfo [dict create\
                id [incr DelayedSignalId]\
                type ordinary\
                src $srcref\
                event $event\
                params $arglist\
            ]
            forAllRefs dstref $dstset {
                dict set eventInfo dst $dstref
                DeleteDelayedSignal $srcref $event $dstref ; # <1>
                relvar insert DelayedSignal [list\
                    RefId       $DelayedSignalId\
                    SrcInstRef  $srcref\
                    Event       $event\
                    DstInstRef  $dstref\
                    TimerId     [::after $time [list\
                                ::rosea::Dispatch::DispatchDelayedEvent $eventInfo]]\
                    Expire      [expr {entier([clock milliseconds]) + entier($time)}]\
                ]
            }
            return
        }
        proc DispatchDelayedEvent {eventInfo} {
            relvar deleteone DelayedSignal RefId [dict get $eventInfo id]
            variable toc_queue
            lappend toc_queue $eventInfo
            tailcall DispatchEvent
        }
        proc CancelDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            set sig [FindDelayedSignal $srcref $event $dstref]
            if {[relation isnotempty $sig]} {
                ::after cancel [relation extract $sig TimerId]
                DeleteDelayedSignal $srcref $event $dstref
            } else {
                # Search the toc_queue to see if the signal delay has already expired
                # and the event is awaiting dispatch.
                variable toc_queue
                for {set i 0} {$i < [llength $toc_queue]} {incr i} {
                    set eventInfo [lindex $toc_queue $i]
                    dict update eventInfo src evtsrc dst evtdst event evtevent {
                        if {[isRefEqual $evtsrc $srcref] &&\
                                [isRefEqual $evtdst $dstref] &&\
                                $evtevent eq $event} {
                            set toc_queue [lreplace\
                                    [K $toc_queue [set toc_queue {}]] $i $i]
                            break
                        }
                    }
                }
            }
        }
        proc SignalTimeRemaining {srcref event dstref} {
            set sig [FindDelayedSignal $srcref $event $dstref]
            return [expr {[relation isempty $sig] ? 0 :\
                max([relation extract $sig Expire] - [clock milliseconds], 0)}] ; # <1>
        }
        proc TransitionEvent {eventInfo} {
            switch -exact -- [dict get $eventInfo type] {
                ordinary {
                    TransitionOrdinaryEvent $eventInfo
                }
                creation {
                    TransitionCreationEvent $eventInfo
                }
                polymorphic {
                    TransitionPolymorphicEvent $eventInfo
                }
                default {
                    tailcall DeclError UNKNOWN_EVENT_TYPE [dict get $eventInfo type]
                }
            }
        }
        proc TransitionOrdinaryEvent {eventInfo} {
            variable event_queue
            set dstref [dict get $eventInfo dst]
            lassign $dstref relvar ref
            SplitRelvarName $relvar domain class
            
            set instrelvar ${domain}::${class}__STATEINST
            set state [relation semijoin $ref [relvar set $instrelvar]]
            if {[relation isempty $state]} {
                tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
            }
            set currstate [relation extract $state __State]
            set event [dict get $eventInfo event]
            variable transitionQuery
            set newState [eval $transitionQuery]
            
            ::rosea::Trace::TraceTransition [dict get $eventInfo src]\
                $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
            if {$newState eq "CH"} {
                TransitionError [dict get $eventInfo src] $event $dstref $currstate
            } elseif {$newState ne "IG"} {
                set idattrs [tuple get [relation tuple $ref]]
                relvar updateone $instrelvar is $idattrs {
                    tuple update $is __State $newState
                }
                try {
                    ${relvar}::__Activity::$newState $dstref\
                            {*}[dict get $eventInfo params] ; # <1>
                } on error {result opts} {
                    chan puts stderr $::errorInfo
                    return -options $opts $result
                } finally {
                    set term [relvar restrictone ${domain}::__Arch_TerminalState\
                            Class $class State $newState]
                    if {[relation isnotempty $term]} {
                        relvar deleteone $relvar {*}$idattrs
                        relvar deleteone $instrelvar {*}$idattrs
                    }
                }
            }
            return
        }
        proc TransitionError {src event dst currstate} {
            tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
        }
        proc TransitionCreationEvent {eventInfo} {
            try {
                set dstref [::rosea::ClassCmds::createin\
                        [dict get $eventInfo dstClass] @\
                        {*}[dict get $eventInfo dstAttrs]] ; # <1>
            } on error {result opts} {
                tailcall DeclError ASYNC_CREATION_FAILED\
                        [dict get $eventInfo dstClass]\
                        [dict get $eventInfo dstAttrs] $result
                return -options $opts $result
            }
            ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
                [dict get $eventInfo event] $dstref [dict get $eventInfo params]
            dict set eventInfo type ordinary
            dict set eventInfo dst $dstref ; # <2>
            TransitionOrdinaryEvent $eventInfo
        }
        proc TransitionPolymorphicEvent {eventInfo} {
            lassign [dict get $eventInfo dst] dstrelvar inst
            SplitRelvarName $dstrelvar domain dstclass
            set event [dict get $eventInfo event]
        
            variable polymapQuery
            set partitions [eval $polymapQuery]
            relation foreach partition $partitions {
                relation assign $partition
                relation foreach dstlink $DstLinks {
                    relation assign $dstlink
                    set related [relation semijoin $inst\
                        [relvar set ${domain}::$DstClass] -using $Attrs]
                    if {[relation isnotempty $related]} {
                        set dstreference [ToRef ${domain}::${DstClass} $related]
                        set target [ToRef $dstrelvar $inst]
                        set srcref [dict get $eventInfo src]
                        ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\
                                [dict get $eventInfo params]
                    
                        set mappedInfo $eventInfo ;                                 # <1>
                        dict set mappedInfo src $target
                        dict set mappedInfo dst $dstreference
                        if {[IsPolymorphicEvent $domain $DstClass $event]} {
                            TransitionPolymorphicEvent $mappedInfo
                        } else {
                            dict set eventInfo type ordinary
                            TransitionOrdinaryEvent $mappedInfo
                        }
                        break
                    }
                }
            }
        }
    }
    namespace eval Config {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers
        variable evalLambda {{body} {
            upvar #0 ::rosea::Config::errcount errcount ; # <1>
            upvar #0 ::rosea::Config::configlineno configlineno
            set lineno $configlineno
            set command {}
            foreach line [split $body \n] { # <2>
                append command $line \n
                incr lineno ; # <3>
                if {[info complete $command]} {
                    try {
                        eval $command
                    } on error {result} {
                        log::error "line $configlineno: \"$result\""
                        incr errcount
                    }
                    set command {} ; # <4>
                    set configlineno $lineno
                }
            }
            return $errcount
        }}
        relvar create Domain {
            Name        string
            Location    string
        } Name
        relvar create DomainElement {
            Domain  string
            Element string
        } {Domain Element}
        relvar association R1\
            DomainElement Domain *\
            Domain Name 1
        relvar create Class {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create Relationship {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create DomainOperation {
            Domain      string
            Name        string
            Parameters  list
            Body        string
        } {Domain Name}
        relvar partition R2 DomainElement {Domain Element}\
            Class {Domain Name}\
            Relationship {Domain Name}\
            DomainOperation {Domain Name}
        relvar create Attribute {
            Domain  string
            Class   string
            Name    string
            Type    string
        } {Domain Class Name}
        relvar association R3\
            Attribute {Domain Class} +\
            Class {Domain Name} 1
        relvar create Identifier {
            Domain  string
            Class   string
            Number  int
        } {Domain Class Number}
        relvar association R4\
            Identifier {Domain Class} +\
            Class {Domain Name} 1
        relvar create IdentifyingAttribute {
            Domain      string
            Class       string
            Attribute   string
            Number      int
        } {Domain Class Attribute Number}
        relvar correlation R5 IdentifyingAttribute\
            {Domain Class Number} + Identifier {Domain Class Number}\
            {Domain Class Attribute} * Attribute {Domain Class Name}
        relvar create DefaultValue {
            Domain      string
            Class       string
            Attribute   string
        } {Domain Class Attribute}
        relvar association R6\
            DefaultValue {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create UserSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            Value       string
        } {Domain Class Attribute}
        relvar create SystemSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            StartValue  int
        } {Domain Class Attribute}
        relvar create GeneratedValue {
            Domain      string
            Class       string
            Attribute   string
            Cmd         string
        } {Domain Class Attribute}
        relvar partition R18 DefaultValue {Domain Class Attribute}\
            UserSuppliedValue {Domain Class Attribute}\
            SystemSuppliedValue {Domain Class Attribute}\
            GeneratedValue {Domain Class Attribute}
        relvar create ValueCheck {
            Domain      string
            Class       string
            Attribute   string
            Expression  string
        } {Domain Class Attribute}
        relvar association R17\
            ValueCheck {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create AttributeReference {
            Domain              string
            ReferringClass      string
            ReferringAttribute  string
            ReferringRole       string
            ReferencedClass     string
            ReferencedAttribute string
            ReferencedRole      string
            ReferencedIdNumber  int
            Relationship        string
        } {Domain ReferringClass ReferringAttribute ReferringRole\
            ReferencedClass ReferencedAttribute ReferencedRole ReferencedIdNumber\
            Relationship}
        relvar association R13\
            AttributeReference {Domain ReferringClass ReferringAttribute} *\
            Attribute {Domain Class Name} 1
        relvar create ReferencedIdAttribute {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Attribute       string
            Number          int
        } {Domain Class Relationship Role Attribute Number}
        relvar create Operation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar association R8\
            Operation {Domain Class} * Class {Domain Name} 1
        
        relvar create InstanceOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar create ClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R7 Operation {Domain Class Name}\
            InstanceOperation {Domain Class Name}\
            ClassOperation {Domain Class Name}
        
        relvar create UserInstanceOperation {
            Domain      string
            Class       string
            Name        string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemInstanceOperation {
            Domain      string
            Class       string
            Name        string
        } {Domain Class Name}
        
        relvar partition R9 InstanceOperation {Domain Class Name}\
            UserInstanceOperation {Domain Class Name}\
            SystemInstanceOperation {Domain Class Name}
        
        relvar create UserClassOperation {
            Domain  string
            Class   string
            Name    string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R10 ClassOperation {Domain Class Name}\
            UserClassOperation {Domain Class Name}\
            SystemClassOperation {Domain Class Name}
        
        relvar create SuppliedOperation {
            Name                string
            Command             string
            RequiresStateModel  boolean
        } Name
        
        relvar create SuppliedClassOperation {
            Name    string
        } Name
        
        relvar create SuppliedInstanceOperation {
            Name    string
        } Name
        
        relvar partition R14 SuppliedOperation Name\
            SuppliedClassOperation Name\
            SuppliedInstanceOperation Name
        
        relvar association R15\
            SystemClassOperation Name *\
            SuppliedClassOperation Name 1
        
        relvar association R16\
            SystemInstanceOperation Name *\
            SuppliedInstanceOperation Name 1
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findAll
                Command             ::rosea::ClassCmds::findAll
                RequiresStateModel  false
            } {
                Name                findById
                Command             ::rosea::ClassCmds::findById
                RequiresStateModel  false
            } {
                Name                findWhere
                Command             ::rosea::ClassCmds::findWhere
                RequiresStateModel  false
            } {
                Name                create
                Command             ::rosea::ClassCmds::create
                RequiresStateModel  false
            } {
                Name                createin
                Command             ::rosea::ClassCmds::createin
                RequiresStateModel  true
            } {
                Name                createasync
                Command             ::rosea::ClassCmds::createasync
                RequiresStateModel  true
            } {
                Name                update
                Command             ::rosea::ClassCmds::update
                RequiresStateModel  false
            }
        
            relvar insert SuppliedClassOperation {
                Name    findAll
            } {
                Name    findById
            } {
                Name    findWhere
            } {
                Name    create
            } {
                Name    createin
            } {
                Name    createasync
            } {
                Name    update
            }
        }
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findRelated
                Command             ::rosea::InstCmds::findRelated
                RequiresStateModel  false
            } {
                Name                findUnrelated
                Command             ::rosea::InstCmds::findById
                RequiresStateModel  false
            } {
                Name                findRelatedWhere
                Command             ::rosea::InstCmds::findRelatedWhere
                RequiresStateModel  false
            } {
                Name                findUnrelatedWhere
                Command             ::rosea::InstCmds::findUnrelatedWhere
                RequiresStateModel  false
            } {
                Name                updateAttribute
                Command             ::rosea::InstCmds::updateAttribute
                RequiresStateModel  false
            } {
                Name                withAttribute
                Command             ::rosea::InstCmds::withAttribute
                RequiresStateModel  false
            } {
                Name                readAttribute
                Command             ::rosea::InstCmds::readAttribute
                RequiresStateModel  false
            } {
                Name                assignAttribute
                Command             ::rosea::InstCmds::assignAttribute
                RequiresStateModel  false
            } {
                Name                delete
                Command             ::rosea::InstCmds::delete
                RequiresStateModel  false
            } {
                Name                signal
                Command             ::rosea::InstCmds::signal
                RequiresStateModel  true
            } {
                Name                delaysignal
                Command             ::rosea::InstCmds::delaysignal
                RequiresStateModel  true
            } {
                Name                canceldelayed
                Command             ::rosea::InstCmds::canceldelayed
                RequiresStateModel  true
            } {
                Name                delayremaining
                Command             ::rosea::InstCmds::delayremaining
                RequiresStateModel  true
            } {
                Name                instop
                Command             ::rosea::InstCmds::instop
                RequiresStateModel  false
            } {
                Name                deRef
                Command             ::rosea::InstCmds::deRef
                RequiresStateModel  false
            } {
                Name                isEmptyRef
                Command             ::rosea::InstCmds::isEmptyRef
                RequiresStateModel  false
            } {
                Name                isNotEmptyRef
                Command             ::rosea::InstCmds::isNotEmptyRef
                RequiresStateModel  false
            } {
                Name                refMultiplicity
                Command             ::rosea::InstCmds::refMultiplicity
                RequiresStateModel  false
            } {
                Name                isRefSingular
                Command             ::rosea::InstCmds::isRefSingular
                RequiresStateModel  false
            } {
                Name                limitRef
                Command             ::rosea::InstCmds::limitRef
                RequiresStateModel  false
            } {
                Name                isRefEqual
                Command             ::rosea::InstCmds::isRefEqual
                RequiresStateModel  false
            } {
                Name                forAllRefs
                Command             ::rosea::InstCmds::forAllRefs
                RequiresStateModel  false
            }
        
            relvar insert SuppliedInstanceOperation {
                Name    findRelated
            } {
                Name    findUnrelated
            } {
                Name    findRelatedWhere
            } {
                Name    findUnrelatedWhere
            } {
                Name    updateAttribute
            } {
                Name    withAttribute
            } {
                Name    readAttribute
            } {
                Name    assignAttribute
            } {
                Name    delete
            } {
                Name    signal
            } {
                Name    delaysignal
            } {
                Name    canceldelayed
            } {
                Name    delayremaining
            } {
                Name    instop
            } {
                Name    deRef
            } {
                Name    isEmptyRef
            } {
                Name    isNotEmptyRef
            } {
                Name    refMultiplicity
            } {
                Name    isRefSingular
            } {
                Name    limitRef
            } {
                Name    isRefEqual
            } {
                Name    forAllRefs
            }
        }
        relvar create Association {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create Generalization {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R30 Relationship {Domain Name}\
            Association {Domain Name}\
            Generalization {Domain Name}
        relvar create SimpleAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create ClassBasedAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R31 Association {Domain Name}\
            SimpleAssociation {Domain Name}\
            ClassBasedAssociation {Domain Name}
        relvar create SimpleReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R32\
            SimpleReferringClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SimpleReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
        } {Domain Class Relationship Role}
        relvar association R33\
            SimpleReferencedClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SourceClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R34\
            SourceClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create TargetClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R35\
            TargetClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create AssociatorClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R42\
            AssociatorClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create Superclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R36\
            Superclass {Domain Relationship} 1\
            Generalization {Domain Name} 1
        relvar create Subclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R37\
            Subclass {Domain Relationship} +\
            Generalization {Domain Name} 1
        relvar create ReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R38 ReferringClass {Domain Class Relationship Role}\
            SimpleReferringClass {Domain Class Relationship Role}\
            AssociatorClass {Domain Class Relationship Role}\
            Subclass {Domain Class Relationship Role}
        relvar create ReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R39 ReferencedClass {Domain Class Relationship Role}\
            SimpleReferencedClass {Domain Class Relationship Role}\
            SourceClass {Domain Class Relationship Role}\
            TargetClass {Domain Class Relationship Role}\
            Superclass {Domain Class Relationship Role}
        relvar create ClassRole {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R40 ClassRole {Domain Class Relationship Role}\
            ReferringClass {Domain Class Relationship Role}\
            ReferencedClass {Domain Class Relationship Role}
        relvar correlation R41 ClassRole\
            {Domain Relationship} + Relationship {Domain Name}\
            {Domain Class} * Class {Domain Name}
        relvar correlation R11 ReferencedIdAttribute\
            {Domain Class Relationship Role} +\
                ReferencedClass {Domain Class Relationship Role}\
            {Domain Class Attribute Number} *\
                IdentifyingAttribute {Domain Class Attribute Number}
        relvar correlation R12 AttributeReference\
            {Domain ReferringClass Relationship ReferringRole} +\
                ReferringClass {Domain Class Relationship Role}\
            {Domain ReferencedClass Relationship ReferencedRole ReferencedAttribute\
                    ReferencedIdNumber} +\
                ReferencedIdAttribute {Domain Class Relationship Role Attribute Number}
        relvar create Config_AssocSpec {
            Spec                string
            NeedsAssociator     boolean
            ReflexiveAllowed    boolean
            ReferringCond       boolean
            ReferringMult       boolean
            ReferencedCond      boolean
            ReferencedMult      boolean
        } Spec
        
        relvar insert Config_AssocSpec {
            Spec 1--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..*--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 1..*--0..1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 0..*--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 0..*--1..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 1..*--0..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec 0..*--0..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec ?--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec ?--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec +--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec *--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec +--? NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec *--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec +--+ NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec *--+ NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec +--* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec *--* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        }
        relvar create Config_ClassAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_NonReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            TargetClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexivePath {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            SourceAttr          string
            TargetAttr          string
        } {Domain Relationship AssocClass SourceClass SourceAttr}
        relvar partition Config1\
            Config_ClassAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_NonReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_ReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}
        relvar association Config2\
            Config_ReflexivePath {Domain Relationship AssocClass SourceClass} +\
            Config_ReflexiveAssoc {Domain Relationship AssocClass SourceClass} 1
        pipe {
            relvar set ::rosea::Config::AttributeReference |
            relation project ~ Domain ReferencedClass Relationship ReferencedRole\
                    ReferencedAttribute ReferencedIdNumber |
            relation rename ~ ReferencedClass Class ReferencedRole Role\
                    ReferencedAttribute Attribute ReferencedIdNumber Number |
            relvar union ::rosea::Config::ReferencedIdAttribute
        } refIdQuery
        relvar create StateModel {
            Domain          string
            Model           string
            InitialState    string
            DefaultTrans    string
        } {Domain Model}
        
        relvar create InstanceStateModel {
            Domain          string
            Class           string
        } {Domain Class}
        
        relvar association R51\
            InstanceStateModel {Domain Class} ?\
            Class {Domain Name} 1
        
        relvar create AssignerStateModel {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar association R52\
            AssignerStateModel {Domain Relationship} ?\
            Association {Domain Name} 1
        
        relvar partition R50 StateModel {Domain Model}\
            InstanceStateModel {Domain Class}\
            AssignerStateModel {Domain Relationship}
        
        relvar create SingleAssigner {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar create MultipleAssigner {
            Domain          string
            Relationship    string
            Class           string
            Number          int
        } {Domain Relationship}
        
        relvar partition R53 AssignerStateModel {Domain Relationship}\
            SingleAssigner {Domain Relationship}\
            MultipleAssigner {Domain Relationship}
        
        relvar association R54\
            MultipleAssigner {Domain Class Number} ?\
            Identifier {Domain Class Number} 1
        
        relvar create State {
            Domain          string
            Model           string
            Name            string
            Parameters      string
            Action          string
            IsFinal         boolean
        } {Domain Model Name}
        
        relvar association R55\
            State {Domain Model} +\
            StateModel {Domain Model} 1
        
        relvar association R58\
            StateModel {Domain Model InitialState} ?\
            State {Domain Model Name} 1
        
        relvar create TransitionRule {
            Name    string
        } Name
        
        relvar insert TransitionRule {Name IG} {Name CH}
        
        relvar association R59\
            StateModel DefaultTrans *\
            TransitionRule Name 1
        
        relvar create CreationState {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar create StatePlace {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar partition R57 StatePlace {Domain Model Name}\
            State {Domain Model Name}\
            CreationState {Domain Model Name}
        relvar create Event {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create DeferredEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create EffectiveEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R80 Event {Domain Model Event}\
            DeferredEvent {Domain Model Event}\
            EffectiveEvent {Domain Model Event}
        
        relvar create DeferralPath {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event Relationship Role}
        
        relvar correlation R86 DeferralPath\
            {Domain Model Event} + DeferredEvent {Domain Model Event}\
            {Domain Model Relationship Role} * Superclass\
                {Domain Class Relationship Role}
        
        relvar create PolymorphicEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create InheritedEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R81 DeferredEvent {Domain Model Event}\
            PolymorphicEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar create MappedEvent {
            Domain      string
            Model       string
            Event       string
            ParentModel string
        } {Domain Model Event}
        
        relvar association R84\
            MappedEvent {Domain ParentModel Event} *\
            DeferredEvent {Domain Model Event} 1
        
        relvar create LocalEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R82 EffectiveEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            LocalEvent {Domain Model Event}
        
        relvar create NonLocalEvent {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event}
        
        relvar partition R83 NonLocalEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar association R85\
            NonLocalEvent {Domain Model Relationship Role} *\
            Subclass {Domain Class Relationship Role} 1
        
        relvar association R87\
            EffectiveEvent {Domain Model} +\
            StateModel {Domain Model} 1
        relvar create TransitionPlace {
            Domain  string
            Model   string
            State   string
            Event   string
        } {Domain Model State Event}
        
        relvar correlation R70 TransitionPlace\
            {Domain Model State} * StatePlace {Domain Model Name}\
            {Domain Model Event} * EffectiveEvent {Domain Model Event}
        
        relvar create StateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            NewState    string
        } {Domain Model State Event}
        
        relvar create NonStateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            TransRule   string
        } {Domain Model State Event}
        
        relvar partition R71 TransitionPlace {Domain Model State Event}\
            StateTransition {Domain Model State Event}\
            NonStateTransition {Domain Model State Event}
        
        relvar association R72\
            StateTransition {Domain Model NewState} *\
            State {Domain Model Name} 1
        
        relvar association R73\
            NonStateTransition TransRule *\
            TransitionRule Name 1
        relvar create Config_DataError {
            Relationship        string
            RefClass            string
            RefType             string
            Format              string
        } {Relationship RefClass RefType}
        relvar insert Config_DataError {
            Relationship        R3
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no attributes}
        } {
            Relationship        R4
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no identifiers}
        } {
            Relationship        R11
            RefClass            ReferencedClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", for relationship,\
                                \"$Relationship\", no class has defined a reference\
                                to class, \"$Class\"}
        } {
            Relationship        R11
            RefClass            ReferencedIdAttribute
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references attribute,\
                                \"$Attribute\", in class, \"$Class\", which is\
                                not an identifying attribute, does not exist\
                                or \"$Relationship\" does not exist}
        } {
            Relationship        R12
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                refers to, \"$ReferencedAttribute\", in class,\
                                \"$ReferencedClass\", but the class, attribute or\
                                relationship does not exist}
        } {
            Relationship        R12
            RefClass            ReferringClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", in class, \"$Class\",\
                                makes a reference along relationship,\
                                \"$Relationship\", but $Class does not pariticipate\
                                in $Relationship}
        } {
            Relationship        R13
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                does not exist, but is used as a referential attribute}
        } {
            Relationship        R41
            RefClass            ClassRole
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references class, \"$Class\",\
                                which does not exist}
        } {
            Relationship        R52
            RefClass            AssignerStateModel
            RefType             refnone
            Format              {in domain, \"$Domain\", an assigner state model is\
                                defined on relationship, \"$Relationship\", which is\
                                not an association type relationship}
        } {
            Relationship        R70
            RefClass            TransitionPlace
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains a transition for event,\
                                \"$Event\", but $Event was a polymorphic event\
                                consumed by a superclass of $Model}
        } {
            Relationship        R72
            RefClass            StateTransition
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains the transition,\
                                \"$State - $Event -> $NewState\",\
                                but state \"$NewState\" does not exist}
        } {
            Relationship        R81
            RefClass            DeferredEvent
            RefType             multrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is both an inherited\
                                polymorphic event and a locally defined one}
        } {
            Relationship        R86
            RefClass            DeferredEvent
            RefType             notrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is defined as\
                                polymorphic but \"$Model\" is not a superclass\
                                of a generalization}
        } {
            Relationship        R87
            RefClass            EffectiveEvent
            RefType             refnone
            Format              {in domain, \"$Domain\", event, \"$Event\" has been\
                                inherited, but no state model exists for, \"$Model\"}
        }
        namespace export ConfigEvaluate
        
        proc ConfigEvaluate {ns body} {
            variable evalLambda
            tailcall ::apply [concat $evalLambda [list $ns]] $body ; # <1>
        }
        proc domain {name body} {
            namespace upvar DomainDef DomainName DomainName ; # <1>
            set DomainName $name
        
            relvar insert ::rosea::Config::Domain [list Name $name Location {}]
            try {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME domain
                }
        
                relvar eval { # <2>
                    ConfigEvaluate [namespace current]::DomainDef $body
        
                    # At this point we have the definition of the domain and enough
                    # information to tie together the referential attributes and
                    # the association definitions.
                    variable Config_NonReflexiveAssoc
                    
                    relation foreach nra $Config_NonReflexiveAssoc {
                        relation assign $nra
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferencedClass] eq $SourceClass
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable Config_ReflexivePath
                    
                    relation foreach rp $Config_ReflexivePath {
                        relation assign $rp
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferringAttribute] eq $SourceAttr
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable refIdQuery
                    
                    eval $refIdQuery
        
                    # We must also compute how polymorphic events are inherited
                    # down generalization hierarchies.
                    # Create Deferral Path instances
                    
                    variable PolymorphicEvent
                    variable DeferredEvent
                    variable Superclass
                    variable Subclass
                    variable DeferralPath
                    
                    set dpaths [pipe {
                        relation restrictwith $PolymorphicEvent {$Domain eq $name} |
                        relation semijoin ~ $DeferredEvent |
                        relation join ~ $Superclass -using {Domain Domain Model Class}
                    }]
                    relvar insert ::rosea::Config::DeferralPath {*}[relation body $dpaths]
                    set supers [relation semiminus $Subclass $Superclass\
                        -using {Domain Domain Class Class}]
                    
                    relation foreach super $supers {
                        PropagatePolyEvents $super
                    }
                }
            } on error {result} {
                # puts $::errorInfo
                ::rosea::Config::HandleConfigError $result
            }
        }
        proc HandleConfigError {result} {
            set lines [split [string trimright $result] \n]
            set nlines [llength $lines]
            set lineno 0
            upvar #0 ::rosea::Config::errcount errcount
            while {$lineno < $nlines} {
                set line [lindex $lines $lineno]
                incr lineno
                if {[regexp {^for[^:]+([^(]+)\(.+\), in relvar (.+)$} $line\
                        match rnum refclass]} {
                    set rnum [namespace tail $rnum]
                    set refclass [namespace tail $refclass]
                
                    # Now iterate over the "tuple" lines that follow the constraint message.
                    while {$lineno < $nlines} {
                        set tupline [lindex $lines $lineno]
                        if {[regexp {^tuple {(.+)} (.+)$} $tupline match tuple phrase]} {
                            incr lineno
                            incr errcount
                            if {[string match {is not referenced*} $phrase]} {
                                set reftype notrefed
                            } elseif {[string match {references no*} $phrase]} {
                                set reftype refnone
                            } elseif {[string match {*to by multiple*} $phrase]} {
                                set reftype multrefed
                            } elseif {[string match {is not referred to*} $phrase]} {
                                set reftype notrefto
                            } else {
                                log::error "unknown constraint phrasing, \"$phrase\""
                                continue
                            }
                            set cde [relvar restrictone Config_DataError Relationship $rnum RefClass\
                                    $refclass RefType $reftype]
                            if {[relation isnotempty $cde]} {
                                dict with tuple {
                                    log::error [subst -nocommands [relation extract $cde Format]]
                                }
                            } else {
                                log::error "$line\n$tupline"
                            }
                        } else {
                            break
                        }
                    }
                } else {
                    log::error "unknown configuration error, \"$result\""
                }
            }
        
            return
        }
        namespace eval DomainDef {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace import ::rosea::Config::ConfigEvaluate
            namespace import ::rosea::Helpers::DeclError
            proc class {name body} {
                namespace upvar [namespace current] DomainName DomainName ; # <1>
                namespace upvar ClassDef ClassName ClassName
                set ClassName $name
            
                if {![regexp {\A[[:alnum:]].*} $name]} {
                    tailcall DeclError BAD_CLASS_NAME $name
                }
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                } ; # <2>
                relvar insert ::rosea::Config::Class [list\
                    Domain  $DomainName\
                    Name    $name\
                ]
                set instops [pipe {
                    relvar set ::rosea::Config::SuppliedInstanceOperation |
                    relation extend ~ ioptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemInstanceOperation $instops
                relvar union ::rosea::Config::InstanceOperation $instops
                relvar union ::rosea::Config::Operation $instops
                set classops [pipe {
                    relvar set ::rosea::Config::SuppliedClassOperation |
                    relation extend ~ coptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemClassOperation $classops
                relvar union ::rosea::Config::ClassOperation $classops
                relvar union ::rosea::Config::Operation $classops
            
                ConfigEvaluate [namespace current]::ClassDef $body
            }
            proc association {name source spec target args} {
                if {[llength $args] % 2 != 0} {
                    tailcall DeclError ARG_FORMAT $args
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME association
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                # Obtain references to the domain and class context.
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
            
                set associator {}
                set path {}
                
                foreach {option value} $args {
                    switch -exact -- $option {
                        -associator {
                            set associator $value
                        }
                        -path {
                            set path $value
                            if {[llength $path] % 2 != 0} {
                                tailcall DeclError ARG_FORMAT $path
                            }
                        }
                        default {
                            tailcall DeclError UNKNOWN_OPTION association $option
                        }
                    }
                }
                set cas [relvar restrictone ::rosea::Config::Config_AssocSpec Spec $spec]
                if {[relation isempty $cas]} {
                    tailcall DeclError BAD_RELATIONSHIP_SPEC $spec
                }
                set needsassoc [relation extract $cas NeedsAssociator]
                if {$needsassoc && $associator eq {}} {
                    tailcall DeclError NEED_ASSOCIATOR $spec
                }
                if {$source eq $target} {
                    if {![relation extract $cas ReflexiveAllowed]} {
                        tailcall DeclError REFLEXIVE_NOT_ALLOWED $spec
                    }
                    if {$needsassoc && $path eq {}} {
                        tailcall DeclError NEED_REFLEXIVE_PATH $name $source $spec $target
                    }
                }
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                # Many relvars have tuples with the same heading, so we construct it
                # once here.
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
            
                # Populate the data for a Relationship and Association since that
                # is what this command defines.
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Association $reltuple
            
                # Populate the type of association we are dealing with.
                if {$associator eq {}} {
                    relvar insert ::rosea::Config::SimpleAssociation $reltuple
                    relvar insert ::rosea::Config::SimpleReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::SimpleReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                } else {
                    relvar insert ::rosea::Config::Config_ClassAssoc [list\
                        Domain              $DomainName\
                        Relationship        $name\
                        AssocClass          $associator\
                        SourceClass         $source\
                    ]
                    if {[llength $path] == 0} {
                        relvar insert ::rosea::Config::Config_NonReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                            TargetClass         $target\
                        ]
                    } else {
                        relvar insert ::rosea::Config::Config_ReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                        ]
                        foreach {sourceattr targetattr} $path {
                            relvar insert ::rosea::Config::Config_ReflexivePath [list\
                                Domain              $DomainName\
                                Relationship        $name\
                                AssocClass          $associator\
                                SourceClass         $source\
                                SourceAttr          $sourceattr\
                                TargetAttr          $targetattr\
                            ]
                        }
                    }
                    
                    relvar insert ::rosea::Config::ClassBasedAssociation $reltuple
                    relvar insert ::rosea::Config::SourceClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::TargetClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                        Multiplicity    [relation extract $cas ReferencedMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::AssociatorClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                }
            }
            proc generalization {name super args} {
                if {[llength $args] < 2} {
                    tailcall DeclError TOO_FEW_SUBCLASSES [llength $args]
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME generalization
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Generalization $reltuple
            
                set supertuple [list\
                    Domain          $DomainName\
                    Class           $super\
                    Relationship    $name\
                    Role            target\
                ]
                relvar insert ::rosea::Config::Superclass $supertuple
                relvar insert ::rosea::Config::ReferencedClass $supertuple
                relvar insert ::rosea::Config::ClassRole $supertuple
            
                set subtuple [dict create\
                    Domain          $DomainName\
                    Relationship    $name\
                    Role            source\
                ]
                foreach sub $args {
                    dict set subtuple Class $sub
                    relvar insert ::rosea::Config::Subclass $subtuple
                    relvar insert ::rosea::Config::ReferringClass $subtuple
                    relvar insert ::rosea::Config::ClassRole $subtuple
                }
            }
            proc assigner {rname body} {
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar AssignerDef\
                    RelationshipName RelationshipName\
                    multiClass multiClass\
                    multiIdNum multiIdNum\
                    InitialState InitialState\
                    DefaultTrans DefaultTrans
            
                set RelationshipName $rname
                set multiClass {}
                set multiIdNum 1
                set InitialState {}
                set DefaultTrans {}
            
                try {
                    ConfigEvaluate [namespace current]::AssignerDef $body
            
                    if {$DefaultTrans eq {}} {
                        set DefaultTrans CH
                    }
                    relvar insert ::rosea::Config::StateModel [list\
                        Domain          $DomainName\
                        Model           $rname\
                        InitialState    $InitialState\
                        DefaultTrans    $DefaultTrans\
                    ]
                    set assigntuple [list\
                        Domain          $DomainName\
                        Relationship    $rname\
                    ]
                    relvar insert ::rosea::Config::AssignerStateModel $assigntuple
                    if {$multiClass eq {}} {
                        relvar insert ::rosea::Config::SingleAssigner $assigntuple
                    } else {
                        lappend assigntuple Class $multiClass Number $multiIdNum
                        relvar insert ::rosea::Config::MultipleAssigner $assigntuple
                    }
                } on error {result opts} {
                    log::error $result
                    upvar #0 ::rosea::Config::errcount errcount
                    incr errcount
                }
            }
            proc operation {name params body} {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME operation
                }
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain      $DomainName\
                        Element     $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
                relvar insert ::rosea::Config::DomainOperation [list\
                    Domain      $DomainName\
                    Name        $name\
                    Parameters  $params\
                    Body        $body\
                ]
            }
        
            namespace eval ClassDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc attribute {name type args} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME attribute
                    }
                    if {[string range $name 0 1] eq "__"} {
                        tailcall DeclError RESERVED_NAME $name
                    }
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    relvar insert ::rosea::Config::Attribute [list\
                        Domain  $DomainName\
                        Class   $ClassName\
                        Name    $name\
                        Type    $type\
                    ]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -default {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::UserSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Value       $value\
                                ]
                            }
                            -system {
                                if {$type ne "int"} {
                                    tailcall DeclError INT_TYPE_REQUIRED $type
                                }
                                if {![string is integer -strict $value]} {
                                    tailcall DeclError INT_VALUE_REQUIRED $value
                                }
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::SystemSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    StartValue  $value\
                                ]
                            }
                            -generate {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::GeneratedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Cmd         $value\
                                ]
                            }
                            -id {
                                relvar uinsert ::rosea::Config::Identifier [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Number      $value\
                                ] ; # <1>
                                relvar insert ::rosea::Config::IdentifyingAttribute [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Number      $value\
                                ]
                            }
                            -check {
                                relvar insert ::rosea::Config::ValueCheck [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Expression  $value\
                                ]
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION attribute $option
                            }
                        }
                    }
                }
                proc reference {relname rclass args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set refnum 1
                    set linkopts [list]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -refid {
                                set refnum $value
                            }
                            -link {
                                if {[llength $value] < 1 || [llength $value] > 2} {
                                    tailcall DeclError ARG_FORMAT $value
                                }
                                lappend linkopts $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION reference $option
                            }
                        }
                    }
                
                    # We defer processing the link options until the end so as not
                    # to impose an order on the -refid option.
                    foreach linkopt $linkopts {
                        lassign $linkopt referring referenced
                        if {$referenced eq {}} {
                            set referenced $referring
                        }
                        relvar insert ::rosea::Config::AttributeReference [list\
                            Domain              $DomainName\
                            ReferringClass      $ClassName\
                            ReferringAttribute  $referring\
                            ReferringRole       source\
                            ReferencedClass     $rclass\
                            ReferencedAttribute $referenced\
                            ReferencedRole      target\
                            ReferencedIdNumber  $refnum\
                            Relationship        $relname
                        ] ; # <1>
                    }
                }
                proc classop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "class operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::ClassOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserClassOperation $optuple
                }
                proc instop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "instance operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::InstanceOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserInstanceOperation $optuple
                }
                proc statemodel {body} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    variable ClassName
                
                    namespace upvar StateModelDef\
                        InitialState InitialState\
                        DefaultTrans DefaultTrans\
                        Terminals Terminals
                
                    set InitialState {}
                    set DefaultTrans {}
                    set Terminals [list]
                
                    try {
                        ConfigEvaluate [namespace current]::StateModelDef $body
                
                        if {$DefaultTrans eq {}} {
                            set DefaultTrans CH
                        }
                        relvar insert ::rosea::Config::StateModel [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            InitialState    $InitialState\
                            DefaultTrans    $DefaultTrans\
                        ]
                        relvar insert ::rosea::Config::InstanceStateModel [list\
                            Domain          $DomainName\
                            Class           $ClassName\
                        ]
                
                        foreach terminal $Terminals {
                            relvar updateone ::rosea::Config::State stup [list\
                                    Domain $DomainName Model $ClassName Name $terminal] {
                                tuple update $stup IsFinal true
                            }
                        }
                    } on error {result opts} {
                        log::error $result
                        upvar #0 ::rosea::Config::errcount errcount
                        incr errcount
                    }
                }
                proc polymorphic {args} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    foreach polyevent $args {
                        set eventtuple [list\
                            Domain $DomainName\
                            Model $ClassName\
                            Event $polyevent\
                        ]
                        relvar insert ::rosea::Config::PolymorphicEvent $eventtuple
                        relvar insert ::rosea::Config::DeferredEvent $eventtuple
                        relvar insert ::rosea::Config::Event $eventtuple
                    }
                    return
                }
            
                namespace eval StateModelDef {
                    logger::initNamespace [namespace current]
                
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                    namespace import ::ral::relvar
                    namespace import ::rosea::Config::ConfigEvaluate
                    namespace import ::rosea::Helpers::DeclError
                
                    proc state {name params body} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME state
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name state
                        }
                    
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        variable InitialState
                    
                        if {$InitialState eq {}} {
                            set InitialState $name
                        }
                    
                        relvar insert ::rosea::Config::State [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                            Parameters      $params\
                            Action          $body\
                            IsFinal         false\
                        ]
                        relvar insert ::rosea::Config::StatePlace [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                        ]
                        return
                    }
                    proc transition {source - event -> target} {
                        if {$event eq {}} {
                            tailcall DeclError EMPTY_NAME event
                        }
                        if {$source in {CH IG}} {
                            tailcall DeclError PSEUDO_STATE $source "transition source state"
                        }
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        if {$source eq "@"} {
                            if {$target in {CH IG}} {
                                tailcall DeclError BAD_CREATION_TARGET $target
                            }
                            set cstuple [list\
                                Domain          $DomainName\
                                Model           $ClassName\
                                Name            @\
                            ]
                            relvar uinsert ::rosea::Config::CreationState $cstuple
                            relvar uinsert ::rosea::Config::StatePlace $cstuple
                        }
                    
                        set eventtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            Event   $event\
                        ]
                        relvar uinsert ::rosea::Config::Event $eventtuple ; # <1>
                        relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                        relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                    
                        set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                            Name $target]
                        set transtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            State   $source\
                            Event   $event\
                        ]
                        relvar insert ::rosea::Config::TransitionPlace $transtuple
                    
                        if {[relation isnotempty $tranrule]} {
                            lappend transtuple TransRule $target
                            set tpsubtype NonStateTransition
                        } else {
                            lappend transtuple NewState $target
                            set tpsubtype StateTransition
                        }
                        relvar insert ::rosea::Config::$tpsubtype $transtuple
                        return
                    }
                    proc initialstate {name} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME initialstate
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name initialstate
                        }
                        variable InitialState $name
                        return
                    }
                    proc defaulttrans {name} {
                        if {$name ni {CH IG}} {
                            tailcall DeclError EXPECTED_PSEUDO_STATE $name
                        }
                        variable DefaultTrans $name
                        return
                    }
                    proc terminal {args} {
                        variable Terminals
                        ::struct::set add Terminals $args
                        return
                    }
                }
            }
            namespace eval AssignerDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc state {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME state
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name state
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    variable InitialState
                
                    if {$InitialState eq {}} {
                        set InitialState $name
                    }
                
                    relvar insert ::rosea::Config::State [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                        Parameters      $params\
                        Action          $body\
                        IsFinal         false\
                    ]
                    relvar insert ::rosea::Config::StatePlace [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                    ]
                    return
                }
                proc transition {source - event -> target} {
                    if {$event eq {}} {
                        tailcall DeclError EMPTY_NAME event
                    }
                    if {$source in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name "transition source state"
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    set eventtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        Event   $event\
                    ]
                    relvar uinsert ::rosea::Config::Event $eventtuple
                    relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                    relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                
                    set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                        Name $target]
                    set transtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        State   $source\
                        Event   $event\
                    ]
                    relvar insert ::rosea::Config::TransitionPlace $transtuple
                
                    if {[relation isnotempty $tranrule]} {
                        lappend transtuple TransRule $target
                        set tpsubtype NonStateTransition
                    } else {
                        lappend transtuple NewState $target
                        set tpsubtype StateTransition
                    }
                    relvar insert ::rosea::Config::$tpsubtype $transtuple
                    return
                }
                proc initialstate {name} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME initialstate
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name initialstate
                    }
                    variable InitialState $name
                    return
                }
                proc defaulttrans {name} {
                    if {$name ni {CH IG}} {
                        tailcall DeclError EXPECTED_PSEUDO_STATE $name
                    }
                    variable DefaultTrans $name
                    return
                }
                proc identifyby {name args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    variable multiClass $name
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -id {
                                variable multiIdNum $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION identifyby $option
                            }
                        }
                    }
                
                    return
                }
            }
        }
    }
    namespace eval Populate {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Config::ConfigEvaluate
        namespace import ::rosea::Helpers::DeclError
        proc domain {name body} {
            set domain [relvar restrictone ::rosea::Config::Domain Name $name]
            if {[relation isempty $domain]} {
                tailcall DeclError UNKNOWN_DOMAIN $domain
            }
        
            namespace upvar DomainPop DomainName DomainName DomainLoc DomainLoc
            relation assign $domain {Name DomainName} {Location DomainLoc}
        
            try {
                relvar eval {
                    ConfigEvaluate [namespace current]::DomainPop $body
                }
            } on error {result opts} {
                log::error $result
                upvar #0 ::rosea::Config::errcount errcount
                incr errcount
            }
        }
        namespace eval DomainPop {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace path ::rosea::Helpers
            proc class {class heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                set body [list]
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.
                    set tuple [list]
                    foreach attr $heading value $values {
                        # Check if we are skipping a value to use a default.  We must also
                        # allow some way to specify the value as "-".
                        if {$value eq "-"} {
                            continue
                        } elseif {$value eq "\\-"} {
                            set value -
                        }
                        lappend tuple $attr $value
                    }
                    # Accumulate the tuples as a list to form the body that will be
                    # inserted into the relvar.
                    lappend body $tuple
                }
            
                # Insert the body into the relvar.
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::$class
                set insts [relvar insert $relvar {*}$body]
            
                # Now we have to deal with any state model that might be present.  We have
                # to set up the initial state properly if such a thing exists for this
                # class.
                set idattrs [lindex [relvar identifiers $relvar] 0]
                relation foreach inst $insts {
                    CreateInInitialState $domns $class [pipe {
                        relation project $inst {*}$idattrs |
                        relation tuple ~ |
                        tuple get ~
                    }]
                }
            
                return [relation body $insts]
            }
            proc assigner {rname heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::${rname}__STATEINST
                set idattrs [lindex [relvar identifiers $relvar] 0]
                if {![struct::set equal $heading $idattrs]} {
                    tailcall DeclError NO_IDENTIFIER $heading $idattrs
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.  We assume
                    # the values are in the same order as the heading -- that is the point.
                    set tuple [list]
                    foreach attr $heading value $values {
                        lappend tuple $attr $value
                    }
                    CreateInInitialState $domns $rname $tuple
                }
            
                return
            }
        }
    }
    namespace eval Info {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Helpers::DeclError
        proc domain {arglist} {
            set arglist [lassign $arglist subcmd domainname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            switch -exact -- $subcmd {
                classes {
                    return [pipe {
                        relvar set ::rosea::Config::Class |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                relationships {
                    return [pipe {
                        relvar set ::rosea::Config::Relationship |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                operations {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::DomainOperation |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc FormatOpsInfo {ops} {
            set result [list]
            relation foreach op $ops {
                relation assign $op
                lappend result $Name $Parameters $Body
            }
            return $result
        }
        proc class {arglist} {
            set arglist [lassign $arglist subcmd domainname classname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                attributes {
                    return [pipe {
                        relvar set ::rosea::Config::Attribute |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation dict ~ Name Type
                    }]
                }
                classops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserClassOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                instops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserInstanceOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc statemodel {arglist} {
            set arglist [lassign $arglist subcmd domainname classname statename]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
            set domns [string cat [relation extract $dominst Location] :: $domainname]
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                states {
                    set states [pipe {
                        relvar set ::rosea::Config::State |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation project ~ Name Parameters Action
                    }]
                    set result [list]
                    relation foreach state $states {
                        relation assign $state
                        lappend result $Name $Parameters $Action
                    }
                    return $result
                }
                events {
                    return [pipe {
                        relvar set ::rosea::Config::EffectiveEvent |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation list ~ Event
                    }]
                }
                transitions {
                    return [pipe {
                        relvar set ${domns}::__Arch_Transition |
                        relation restrictwith ~ {$Class eq $classname} |
                        relation eliminate ~ Class |
                        relation group ~ Transition Event NewState |
                        relation extend ~ trtup TranCol dict {
                            [relation dict [tuple extract $trtup Transition] Event NewState]} |
                        relation dict ~ State TranCol
                    }] ; # <1>
                }
                activityproc {
                    return ${domns}::${classname}::__Activity::${statename}
                }
            }
        }
    }
    namespace eval Trace {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        relvar create Trace {
            Trace_Id    int
            Timestamp   bignum
            Source      list
            Event       string
            Target      list
            Params      list
        } Trace_Id
        
        relvar create Creation {
            Trace_Id    int
        } Trace_Id
        
        relvar create Polymorphic {
            Trace_Id    int
            SubInst     string
            Linkage     string
        } Trace_Id
        
        relvar create Transition {
            Trace_Id    int
            CurrState   string
            NewState    string
        } Trace_Id
        
        relvar partition R1 Trace Trace_Id\
            Creation Trace_Id\
            Polymorphic Trace_Id\
            Transition Trace_Id
        variable targetCmpFunc [lambda {instrefs target} {
            lassign $target trelvar tinst
            foreach instref $instrefs {
                lassign $instref crelvar cinst
                if {$trelvar eq $crelvar && [ral relation is $tinst subsetof $cinst]} {
                    return true
                }
            }
            return false
        }]
        variable traceState off
        variable traceNumber 0
        variable traceLogState off
        variable traceLogLevel info
        variable traceLogCmd [::logger::init rosea]
        proc QueryClassTraces {classes} {
            variable Trace
            return [relation restrictwith $Trace {
                [lindex $Target 0] in $classes ||\
                    [namespace tail [lindex $Target 0]] in $classes
            }] ; # <1>
        }
        proc QueryTargetTraces {targets} {
            variable Trace
            variable targetCmpFunc
            return [relation restrictwith $Trace {[{*}$targetCmpFunc $targets $Target]}]
        }
        proc TraceCreation {source event target params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Creation [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TracePolymorphic {source event target sub link params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Polymorphic [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        SubInst     $sub\
                        Linkage     $link\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TraceTransition {source event target curr new params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Transition [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        CurrState   $curr\
                        NewState    $new\
                    ]
                }
                LogTrace $trace
            }
        }
        proc NewTrace {src event target params} {
            variable traceNumber
            return [relvar insert Trace [list\
                Trace_Id    [incr traceNumber]\
                Timestamp   [clock microseconds]\
                Source      $src\
                Event       $event\
                Target      $target\
                Params      $params\
            ]]
        }
        proc LogTrace {trace} {
            variable traceLogState
            if {$traceLogState} {
                set rec [FormatTraceRec [lindex [TracesToRecords $trace] 0]] ; # <1>
        
                variable traceLogCmd
                variable traceLogLevel
                ${traceLogCmd}::${traceLogLevel} $rec
            }
        }
        proc TracesToRecords {traces} {
            foreach rvname {Creation Polymorphic Transition} { # <1>
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            set result [list]
            relation foreach trace $traces -ascending Trace_Id { # <2>
                relation assign $trace
                set labeled [dict create\
                    id      $Trace_Id\
                    time    $Timestamp\
                    source  $Source\
                    event   $Event\
                    target  $Target\
                    params  $Params\
                    class   [lindex $Target 0]\
                ] ; # <3>
                if {[relation isnotempty $Transition]} { # <4>
                    relation assign $Transition
                    dict set labeled type transition
                    dict set labeled current $CurrState
                    dict set labeled new $NewState
                } elseif {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic
                    dict set labeled type polymorphic
                    dict set labeled sub $SubInst
                    dict set labeled link $Linkage
                } elseif {[relation isnotempty $Creation]} {
                    dict set labeled type creation
                }
        
                lappend result $labeled
            }
            return $result
        }
        proc DecodeAllTraces {} {
            variable Trace
            tailcall TracesToRecords $Trace
        }
        proc DecodeClassTraces {args} {
            return [TracesToRecords [QueryClassTraces $args]]
        }
        proc DecodeTargetTraces {args} {
            tailcall TracesToRecords [QueryTargetTraces $args]
        }
        proc FormatTraceRec {rec} {
            dict with rec {
                switch -exact -- $type {
                    transition {
                        append result\
                            "Transition: "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $current -> $new"
                    }
                    polymorphic {
                        append result\
                            "Polymorphic : "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $link -> [FormatInstRef $sub]"
                    }
                    creation {
                        append result\
                            "Creation: "\
                            "[FormatInstRef $source] - "\
                            "[FormatEvent $event $params] -> $class"\
                            " ==> [FormatInstRef $target]"
                    }
                    default {
                        DeclError BAD_TRACETYPE $type
                    }
                }
            }
            return $result
        }
        proc FormatTransition {source event params target} {
            return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
                [FormatInstRef $target]"
        }
        proc FormatInstRef {instref} {
            lassign $instref relvar inst
            return [expr {$relvar eq {} ? "()" :
                    "$relvar\([FormatNVPairs [tuple get [relation tuple $inst]]]\)"}]
        }
        proc FormatEvent {event params} {
            set result $event
        
            if {[llength $params] != 0} {
                append result "\([join $params {, }]\)"
            }
            return $result
        }
        proc FormatNVPairs {pairs} {
            return [pipe {
                lmap {attr val} $pairs {string cat $attr ": " $val} |
                join ~ {, }
            }]
        }
        proc FormatTimestamp {time} {
            set sec [clock format [expr {$time / 1000000}] -format %T] ; # <1>
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %s.%03ld.%03ld $sec $msec $usec]
        }
        proc FormatTimeAsSec {time} {
            set sec [expr {$time / 1000000}]
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %3ld.%03ld.%03ld $sec $msec $usec]
        }
        proc DiagTraces {traces args} {
            set result {}
            append result "seqdiag \{\n"
            append result "    activation = none;\n"
            foreach {option value} $args {
                append result "    $option = $value;\n"
            }
        
            foreach rvname {Creation Polymorphic Transition} {
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            relation foreach trace $traces -ascending Trace_Id {
                relation assign $trace
                if {[isEmptyRef $Source]} {
                    set Source EXTERNAL
                } else {
                    set Source [namespace tail [lindex $Source 0]]
                }
                set Target [namespace tail [lindex $Target 0]]
                set evtlabel [FormatEvent $Event $Params]
                if {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic Linkage
                    append evtlabel " <<Polymorphic $Linkage>>"
                } elseif {[relation isnotempty $Creation]} {
                    append evtlabel " <<Creation>>"
                }
                append result "    $Source ->> $Target \[label=\"$evtlabel\"\];\n"
            }
        
            append result "\}\n"
        
            return $result
        }
        proc DiagAllTraces {filename args} {
            set chan [open $filename w]
            variable Trace
            try {
                chan puts $chan [DiagTraces $Trace {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagClassTraces {filename classes args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryClassTraces $classes] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagTargetTraces {filename targets args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryTargetTraces $targets] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
    }

    namespace path ::rosea::Helpers
    namespace import ::rosea::Config::ConfigEvaluate
}

package provide rosea $::rosea::version



Deleted modules/rosea-1.9.2.tm.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2015 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors and
# need not follow the licensing terms described here, provided that the
# new terms are clearly indicated on the first page of each file where
# they apply.
# 
# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES
# THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# 
# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
# OR MODIFICATIONS.
# 
# GOVERNMENT USE: If you are acquiring this software on behalf of the
# U.S. government, the Government shall have only "Restricted Rights"
# in the software and related documentation as defined in the Federal
# Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
# are acquiring the software on behalf of the Department of Defense,
# the software shall be classified as "Commercial Computer Software"
# and the Government shall have only "Restricted Rights" as defined in
# Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the foregoing,
# the authors grant the U.S. Government and others acting in its behalf
# permission to use and distribute the software in accordance with the
# terms specified in this license.

package require Tcl 8.6

package require logger
package require ral
package require ralutil
package require struct::set
package require lambda

proc ::K {x y} {set x}

namespace eval ::rosea {
    namespace export configure
    
    namespace export configureFromChan
    
    namespace export configureFromFile
    
    namespace export generate
    
    namespace export populate
    
    namespace export populateFromChan
    
    namespace export populateFromFile
    
    namespace export save
    
    namespace export restore
    
    namespace export info
    
    namespace export tunnel
    
    namespace export trace
    
    namespace ensemble create

    variable version 1.9.2

    logger::initNamespace [namespace current]

    namespace import\
        ::ral::relation\
        ::ral::tuple\
        ::ral::relformat\
        ::ralutil::pipe
    namespace import ::ral::relvar
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation project ~ Name Type |
        relation dict ~ Name Type
    } headingQuery
    
    pipe {
        relation semijoin $class $Identifier -using {Domain Domain Name Class}\
                $IdentifyingAttribute |
        relation group ~ Attributes Attribute
    } idQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $UserSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } defaultValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $SystemSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } suppliedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $GeneratedValue -using {Domain Domain Class Class Name Attribute}
    } generatedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $ValueCheck -using {Domain Domain Class Class Name Attribute}
    } checkValuesQuery
    
    pipe {
        relation semijoin $class $StateModel -using {Domain Domain Name Model} |
        relation isnotempty
    } hasSMQuery
    
    pipe {
        relation semijoin $class $State -using {Domain Domain Name Model} |
        relation project ~ Name Parameters Action
    } statesQuery
    
    pipe {
        relation join $AttributeReference $refing\
            -using {Domain Domain ReferringClass Class\
            Relationship Relationship ReferringRole Role} |
        relation rename ~ Conditionality ReferringCond\
                Multiplicity ReferringMult |
        relation join ~ $refed -using {Domain Domain\
            ReferencedClass Class Relationship\
            Relationship ReferencedRole Role} |
        relation project ~ Domain Relationship\
            ReferringClass ReferringAttribute\
            ReferencedClass ReferencedAttribute\
            ReferringCond ReferringMult Conditionality |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } referencesQuery
    
    pipe {
        relation semijoin $cassocs $AssociatorClass\
                -using {Domain Domain Name Relationship}\
            $ReferringClass $AttributeReference\
                -using {Domain Domain Class ReferringClass\
                Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute ReferencedRole |
        relation join ~ $bothclass -using {Domain Domain Relationship Relationship\
                ReferencedClass Class ReferencedRole Role} |
        relation group ~ ReferringAttrs ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } assocrefsQuery
    
    pipe {
        relation semijoin $rships $Generalization\
                $Subclass -using {Domain Domain Name Relationship}\
                $ReferringClass $AttributeReference\
                    -using {Domain Domain Class ReferringClass\
                    Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } subrefsQuery
    
    proc configure {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Config $script
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc configureFromChan {chan} {
        tailcall configure [::chan read -nonewline $chan]
    }
    proc configureFromFile {filename} {
        set f [::open $filename r]
        try {
            configureFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc generate {{pattern *} {prefix {}}} {
        if {$prefix ne {}} {
            if {[string range $prefix 0 1] ne "::"} {
                set prefix [uplevel 1 {namespace current}]::$prefix
            }
            set prefix [string trimright $prefix :]
        } elseif {$prefix eq "::"} {
            set prefix {} ; # <1>
        }
        namespace upvar Config\
            Domain Domain\
            DomainElement DomainElement\
            Class Class\
            Attribute Attribute\
            DefaultValue DefaultValue\
            UserSuppliedValue UserSuppliedValue\
            SystemSuppliedValue SystemSuppliedValue\
            GeneratedValue GeneratedValue\
            ValueCheck ValueCheck\
            Identifier Identifier\
            IdentifyingAttribute IdentifyingAttribute\
            Relationship Relationship\
            Association Association\
            SimpleAssociation SimpleAssociation\
            SimpleReferringClass SimpleReferringClass\
            SimpleReferencedClass SimpleReferencedClass\
            ClassBasedAssociation ClassBasedAssociation\
            AssociatorClass AssociatorClass\
            SourceClass SourceClass\
            TargetClass TargetClass\
            Generalization Generalization\
            Superclass Superclass\
            Subclass Subclass\
            AttributeReference AttributeReference\
            ReferencedIdAttribute ReferencedIdAttribute\
            ReferringClass ReferringClass\
            ReferencedClass ReferencedClass\
            DomainOperation DomainOperation\
            SuppliedOperation SuppliedOperation\
            UserClassOperation UserClassOperation\
            SystemClassOperation SystemClassOperation\
            UserInstanceOperation UserInstanceOperation\
            SystemInstanceOperation SystemInstanceOperation\
            InstanceStateModel InstanceStateModel\
            StateModel StateModel\
            StatePlace StatePlace\
            State State\
            EffectiveEvent EffectiveEvent\
            DeferredEvent DeferredEvent\
            TransitionPlace TransitionPlace\
            StateTransition StateTransition\
            NonStateTransition NonStateTransition\
            AssignerStateModel AssignerStateModel\
            SingleAssigner SingleAssigner\
            MultipleAssigner MultipleAssigner\
            PolymorphicEvent PolymorphicEvent
    
        set genDomain [relation restrict $Domain dom {
            [string match $pattern [tuple extract $dom Name]]
        }]
        relation foreach domain $genDomain {
            set domainName [relation extract $domain Name]
            relvar updateone Config::Domain dtup [list Name $domainName] {
                tuple update $dtup Location $prefix
            }
            
            set domns ${prefix}::$domainName
            namespace eval $domns {
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                ral relvar create __Arch_RefLink {
                    Relationship    string
                    ReferringClass  string
                    ReferencedClass string
                    ReferringAttrs  {Relation
                            {ReferringAttribute string ReferencedAttribute string}}
                } Relationship
                ral relvar create __Arch_AssocRef {
                    Relationship    string
                    AssocClass      string
                    References      {Relation\
                        {Participant string Role string ReferringAttrs {Relation\
                            {ReferringAttribute string ReferencedAttribute string}}}}
                } Relationship
                ral relvar create __Arch_SuperLink {
                    Relationship    string
                    SuperClass      string
                } Relationship
                
                ral relvar create __Arch_SubLink {
                    Relationship    string
                    SubClass        string
                    ReferringAttrs  {Relation\
                        {ReferringAttribute string ReferencedAttribute string}}
                } {Relationship SubClass}
                
                ral relvar association __Arch_R5\
                    __Arch_SubLink Relationship +\
                    __Arch_SuperLink Relationship 1
                ral relvar create __Arch_Link {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar create __Arch_AssociationLink {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                    PrevSrcClass    string
                } {Name SrcClass}
                ral relvar association __Arch_R4\
                    __Arch_AssociationLink {Name PrevSrcClass} ?\
                    __Arch_AssociationLink {Name SrcClass} ?
                ral relvar create __Arch_PartitionLink {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar partition __Arch_R3 __Arch_Link {Name SrcClass}\
                    __Arch_AssociationLink {Name SrcClass}\
                    __Arch_PartitionLink {Name SrcClass}
                ral relvar create __Arch_PartitionDst {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                } {Name SrcClass DstClass}
                ral relvar association __Arch_R2\
                    __Arch_PartitionDst {Name SrcClass} +\
                    __Arch_PartitionLink {Name SrcClass} 1
                ral relvar create __Arch_State {
                    Class string
                    State string
                } {Class State}
                ral relvar create __Arch_Event {
                    Class string
                    Event string
                } {Class Event}
                ral relvar create __Arch_Transition {
                    Class string
                    State string
                    Event string
                    NewState string
                } {Class State Event}
                ral relvar correlation __Arch_R1 __Arch_Transition\
                    {Class State} + __Arch_State {Class State}\
                    {Class Event} + __Arch_Event {Class Event}
                ral relvar create __Arch_InitialState {
                    Class string
                    State string
                } Class
                ral relvar association __Arch_R6\
                    __Arch_InitialState {Class State} ?\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_TerminalState {
                    Class string
                    State string
                } {Class State}
                ral relvar association __Arch_R7\
                    __Arch_TerminalState {Class State} *\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_PolymorphicEvent {
                    Class           string
                    Event           string
                } {Class Event}
            }
            namespace eval $domns namespace path ::rosea::InstCmds
            set domops [relation semijoin $domain $DomainOperation -using {Name Domain}]
            relation foreach domop $domops {
                relation assign $domop\
                    {Name name} {Parameters parameters} {Body body}
                proc ${domns}::$name $parameters [list ::ral relvar eval $body] ; # <1>
            }
            
            namespace eval $domns [list\
                namespace export {*}[relation list $domops Name]\
            ]
            namespace eval $domns namespace ensemble create
            set statemodels [relation semijoin $domain $StateModel\
                -using {Name Domain}]
            
            relvar eval {
                relvar set ${domns}::__Arch_InitialState [pipe {
                    relation project $statemodels Model InitialState |
                    relation rename ~ Model Class InitialState State
                }]
                set states [relation semijoin $domain $StatePlace -using {Name Domain}]
                relvar set ${domns}::__Arch_State [pipe {
                    relation project $states Model Name |
                    relation rename ~ Model Class Name State
                }]
                relvar set ${domns}::__Arch_TerminalState [pipe {
                    relation semijoin $domain $State -using {Name Domain} |
                    relation restrict ~ termtuple {[tuple extract $termtuple IsFinal]} |
                    relation project ~ Model Name |
                    relation rename ~ Model Class Name State
                }]
                set events [relation semijoin $domain $EffectiveEvent\
                    -using {Name Domain}]
                relvar set ${domns}::__Arch_Event [pipe {
                    relation project $events Model Event |
                    relation rename ~ Model Class
                }]
                set alltrans [pipe {
                    relation join $states $events |
                    relation rename ~ Name State
                }] ; # <1>
                set statetrans [relation semijoin $domain $StateTransition\
                    -using {Name Domain}]
                set nontrans [pipe {
                    relation semijoin $domain $NonStateTransition -using {Name Domain} |
                    relation rename ~ TransRule NewState
                }]
                set deftrans [pipe {
                    relation minus $alltrans $TransitionPlace |
                    relation join ~ $StateModel |
                    relation eliminate ~ InitialState |
                    relation rename ~ DefaultTrans NewState |
                    relation update ~ dttup {[tuple extract $dttup State] eq "@"} {
                        tuple update $dttup NewState CH}
                }]
                relvar set ${domns}::__Arch_Transition [pipe {
                    relation union $statetrans $nontrans $deftrans |
                    relation eliminate ~ Domain |
                    relation rename ~ Model Class
                }]
                relvar set ${domns}::__Arch_PolymorphicEvent [pipe {
                    relation semijoin $domain $DeferredEvent\
                        -using {Name Domain} |
                    relation project ~ Model Event |
                    relation rename ~ Model Class
                }]
            }
            variable headingQuery
            variable idQuery
            variable defaultValuesQuery
            variable suppliedValuesQuery
            variable generatedValuesQuery
            variable checkValuesQuery
            variable hasSMQuery
            variable statesQuery
            
            set classes [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Class -using {Domain Domain Element Name}]
            relation foreach class $classes {
                set className ${domns}::[relation extract $class Name]
                namespace eval $className {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $className [list namespace path\
                        [list ::rosea::InstCmds $domns]]
                set heading [eval $headingQuery]
                set idset [list]
                relation foreach id [eval $idQuery] -ascending Number {
                    lappend idset [relation list\
                            [relation extract $id Attributes] Attribute]
                }
                
                relvar create $className $heading {*}$idset
                
                # <1>
                set checkvalues [eval $checkValuesQuery]
                
                if {[relation isnotempty $checkvalues]} {
                    relvar trace add variable $className {insert update set} [list\
                        ::rosea::Helpers::CheckValueTrace\
                        [relation dict $checkvalues Name Expression]\
                    ]
                }
                set defaultvalues [eval $defaultValuesQuery]
                
                if {[relation isnotempty $defaultvalues]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::UserDefaultTrace\
                        [relation dict $defaultvalues Name Type]\
                        [relation dict $defaultvalues Name Value]\
                    ]
                }
                set supplied [eval $suppliedValuesQuery]
                
                if {[relation isnotempty $supplied]} {
                    pipe {
                        relation extend $supplied stup ClassName string {
                            [string cat [tuple extract $stup Class] , [tuple extract $stup Name]]
                        } |
                        relation array ~ ${domns}::__Arch_SuppliedDefault ClassName StartValue 
                    } ; # <1>
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::SupplyDefaultTrace\
                        [relation dict $supplied Name Type]\
                    ]
                }
                set generatecmds [eval $generatedValuesQuery]
                
                if {[relation isnotempty $generatecmds]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::GenerateDefaultTrace\
                        [relation dict $generatecmds Name Type]\
                        [relation dict $generatecmds Name Cmd]\
                    ]
                }
                set hasStateModel [eval $hasSMQuery]
                if {$hasStateModel} {
                    set instid [lindex $idset 0]
                    set instheading [list]
                    foreach attr $instid {
                        lappend instheading $attr [dict get $heading $attr] ; # <1>
                    }
                    lappend instheading __State string
                    relvar create ${domns}::[relation extract $class Name]__STATEINST\
                        $instheading $instid
                    set actns ${className}::__Activity
                    namespace eval $actns {
                        namespace import\
                            ::ral::relation\
                            ::ral::tuple\
                            ::ral::relformat\
                            ::ralutil::pipe
                    }
                    namespace eval $actns [list\
                        namespace path [list\
                            ::rosea::InstCmds\
                            $className\
                            $domns\
                        ]\
                    ]
                    relation foreach state [eval $statesQuery] {
                        relation assign $state\
                            {Name stateName}\
                            {Parameters params}\
                            {Action stateAction}
                        proc ${actns}::$stateName [linsert $params 0 self] $stateAction
                    }
                }
                set opmap [dict create]
                set classops [relation semijoin $class $UserClassOperation\
                    -using {Domain Domain Name Class}]
                relation foreach classop $classops {
                    relation assign $classop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname $params $opbody
                    dict set opmap $opname ${className}::$opname
                }
                
                set sysmap [QuerySystemClassOperations $className false]
                if {$hasStateModel} {
                    set sysmap [dict merge $sysmap [QuerySystemClassOperations $className true]]
                }
                
                namespace ensemble create\
                    -command $className\
                    -map [dict merge $opmap $sysmap]
                set opmap [dict create]
                set instops [relation semijoin $class $UserInstanceOperation\
                    -using {Domain Domain Name Class}]
                relation foreach instop $instops {
                    relation assign $instop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname [linsert $params 0 self] $opbody
                    dict set opmap $opname ${className}::$opname
                }
                set sysmap [QuerySystemInstanceOperations false]
                set hasPolyEvents [relation isnotempty\
                    [relation semijoin $class $PolymorphicEvent\
                        -using {Domain Domain Name Model}]\
                ]
                if {$hasStateModel || $hasPolyEvents} {
                    set sysmap [dict merge $sysmap [QuerySystemInstanceOperations true]]
                }
                
                namespace ensemble create\
                    -command ${className}::Instance\
                    -parameters instref\
                    -map [dict merge $opmap $sysmap]
            }
            set rships [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Relationship -using {Domain Domain Element Name}]
            
            set sassocs [relation semijoin $rships $Association\
                    $SimpleAssociation]
            set refing [relation semijoin $sassocs $SimpleReferringClass\
                    -using {Domain Domain Name Relationship}]
            set refed [relation semijoin $sassocs $SimpleReferencedClass\
                    -using {Domain Domain Name Relationship}]
            variable referencesQuery
            set references [eval $referencesQuery]
            relvar eval {
                set flink [pipe {
                    relation project $references Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set blink [pipe {
                    relation project $references Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%] ; # <1>
                
                relvar union ${domns}::__Arch_Link $flink $blink
                set flink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }] ; # <1>
                set blink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_AssociationLink $flink $blink
                relvar union ${domns}::__Arch_RefLink [relation project $references\
                    Relationship ReferringClass ReferencedClass ReferringAttrs]
            }
            relation foreach reference $references {
                relation assign $reference\
                    {Relationship relationship}\
                    {ReferringClass referringClass}\
                    {ReferencedClass referencedClass}\
                    {ReferringCond referringCond}\
                    {ReferringMult referringMult}\
                    {Conditionality referencedCond}\
                    {SrcAttrs srcAttrs}\
                    {DstAttrs dstAttrs}
            
                # Create the relvar constraint.
                relvar association ${domns}::$relationship\
                     ${domns}::$referringClass $srcAttrs\
                    [MapCondMultToConstraint $referringCond $referringMult]\
                    ${domns}::$referencedClass $dstAttrs\
                    [MapCondMultToConstraint $referencedCond false]
            
                # All simple associations get a link and unlink command in their ensemble.
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkSimple $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkSimple $relationship]\
                ]
            
                # Determine if we have any assigners assocated  with the relationship.
                # Single assigners get different commands from multiple assigners.
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $reference $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $reference $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                    }
                }
                # Create the relationship ensemble command.
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            set cassocs [relation semijoin $rships $Association\
                    $ClassBasedAssociation]
            set sourceclass [relation semijoin $cassocs $SourceClass\
                -using {Domain Domain Name Relationship}]
            set targetclass [relation semijoin $cassocs $TargetClass\
                -using {Domain Domain Name Relationship}]
            set bothclass [relation union $sourceclass $targetclass] ; # <1>
            variable assocrefsQuery
            set assocrefs [eval $assocrefsQuery]
            relvar eval {
                set aforw [pipe {
                    relation project $assocrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set arev [relation update $aforw lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}]
                set sources [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "source"} |
                    relation eliminate ~ ReferencedRole
                }]
                set sforw [pipe {
                    relation project $sources Relationship ReferencedClass |
                    relation rename ~ Relationship Name ReferencedClass SrcClass
                }]
                set targets [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "target"} |
                    relation eliminate ~ ReferencedRole
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_Link $aforw $arev $sforw $trev
                set sforw [pipe {
                    relation project $sources Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename ~ Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename % Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                set onerefs [relation rename $sources ReferencedClass OneClass\
                        Conditionality OneCond Multiplicity OneMult\
                        ReferringAttrs OneReferringAttrs SrcAttrs OneSrcAttrs\
                        DstAttrs OneDstAttrs ForwAttrs OneForwAttrs RevAttrs OneRevAttrs]
                set otherrefs [relation rename $targets ReferencedClass OtherClass\
                        Conditionality OtherCond Multiplicity OtherMult ReferringAttrs\
                        OtherReferringAttrs SrcAttrs OtherSrcAttrs DstAttrs OtherDstAttrs\
                        ForwAttrs OtherForwAttrs RevAttrs OtherRevAttrs]
                set bothrefs [relation join $onerefs $otherrefs\
                    -using {Domain Domain ReferringClass ReferringClass\
                        Relationship Relationship}]
                set aforw [pipe {
                    relation project $bothrefs Relationship ReferringClass OtherClass\
                        OtherForwAttrs OneClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            OtherClass DstClass OtherForwAttrs Attrs OneClass PrevSrcClass
                }]
                set arev [pipe {
                    relation project $bothrefs Relationship ReferringClass OneClass\
                            OneForwAttrs OtherClass |
                    relation rename % Relationship Name ReferringClass SrcClass\
                            OneClass DstClass OneForwAttrs Attrs OtherClass PrevSrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_AssociationLink $sforw $trev $aforw $arev
                relvar union ${domns}::__Arch_AssocRef [pipe {
                    relation project $assocrefs Relationship ReferringClass\
                        ReferencedClass ReferencedRole ReferringAttrs |
                    relation rename ~ ReferringClass AssocClass ReferencedClass Participant\
                        ReferencedRole Role |
                    relation group ~ References Participant Role ReferringAttrs
                }]
            }
            relation foreach bothref $bothrefs {
                relation assign $bothref\
                    {Relationship relationship}\
                    {ReferringClass associator}\
                    {OneClass sourceClass}\
                    {OneCond sourceCond}\
                    {OneMult sourceMult}\
                    {OneSrcAttrs sourceAssocAttrs}\
                    {OneDstAttrs sourceDstAttrs}\
                    {OtherClass targetClass}\
                    {OtherCond targetCond}\
                    {OtherMult targetMult}\
                    {OtherSrcAttrs targetAssocAttrs}\
                    {OtherDstAttrs targetDstAttrs}
            
                # Create the correlation constraint
                relvar correlation ${domns}::$relationship ${domns}::$associator\
                    $sourceAssocAttrs [MapCondMultToConstraint $targetCond $targetMult]\
                    ${domns}::$sourceClass $sourceDstAttrs\
                    $targetAssocAttrs [MapCondMultToConstraint $sourceCond $sourceMult]\
                    ${domns}::$targetClass $targetDstAttrs ; # <1>
            
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkAssoc $relationship]\
                    reference [list ::rosea::RelCmds::referenceAssoc $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkAssoc $relationship]\
                ]
                # Determine if we have any assigners
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $bothref $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $bothref $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                    }
                }
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            variable subrefsQuery
            set subrefs [eval $subrefsQuery]
            relvar eval {
                set sublinks [pipe {
                    relation project $subrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set superlinks [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_Link $sublinks $superlinks
                relvar union ${domns}::__Arch_AssociationLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferencedClass\
                            ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                relvar union ${domns}::__Arch_PartitionLink $superlinks
                relvar union ${domns}::__Arch_PartitionDst [pipe {
                    relation project $subrefs Relationship ReferencedClass\
                            ReferringClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_SuperLink [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename ~ ReferencedClass SuperClass
                }]
                relvar union ${domns}::__Arch_SubLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferringAttrs |
                    relation rename ~ ReferringClass SubClass
                }]
            }
            set partrefs [pipe {
                relation project $subrefs Relationship ReferencedClass DstAttrs\
                        ReferringClass SrcAttrs |
                relation extend ~ prs SubAttrMap list {[list\
                        ${domns}::[tuple extract $prs ReferringClass]\
                        [tuple extract $prs SrcAttrs]]} |
                relation eliminate ~ ReferringClass SrcAttrs |
                relation group ~ SubClassRefs SubAttrMap |
                relation extend ~ spt SubParts list {
                        [concat {*}[relation list [tuple extract $spt SubClassRefs]]]} |
                relation eliminate ~ SubClassRefs
            }]
            
            relation foreach partref $partrefs {
                relation assign $partref\
                    {Relationship relationship}\
                    {ReferencedClass superclass}\
                    {DstAttrs superattrs}\
                    {SubParts subparts}
            
                relvar partition ${domns}::$relationship ${domns}::$superclass\
                        $superattrs {*}$subparts
                namespace ensemble create\
                    -command ${domns}::$relationship\
                    -map [dict create migrate [list ::rosea::RelCmds::migrate\
                            $relationship]]
            }
            set assigners [relation semijoin $domain $AssignerStateModel\
                    -using {Name Domain}]
            relation foreach assigner $assigners {
                set asgnns\
                    ${domns}::[relation extract $assigner Relationship]::__Activity
                namespace eval $asgnns {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $asgnns [list\
                    namespace path [list\
                        ::rosea::InstCmds\
                        $domns\
                    ]\
                ]
                set states [pipe {
                    relation semijoin $assigner $State\
                        -using {Domain Domain Relationship Model} |
                    relation project ~ Name Parameters Action
                }]
                relation foreach state $states {
                    relation assign $state\
                        {Name stateName}\
                        {Parameters params}\
                        {Action stateAction}
                    set params [linsert $params 0 self]
                    proc ${asgnns}::$stateName $params $stateAction
                }
            }
            relation foreach sassigner\
                    [relation semijoin $domain $SingleAssigner\
                    -using {Name Domain}] {
                relation assign $sassigner {Relationship relationship}
                relvar create ${domns}::${relationship}__STATEINST {
                    Id      int
                    __State string
                } Id
                CreateInInitialState $domns $relationship {Id 0} ; # <1>
            }
            relation foreach massigner\
                    [relation semijoin $domain $MultipleAssigner\
                    -using {Name Domain}] {
                relation assign $massigner {Relationship relationship}
                set assignvar ${domns}::${relationship}__STATEINST
            
                set idattrs [pipe {
                    relation semijoin $massigner $Identifier\
                        $IdentifyingAttribute\
                        $Attribute -using {Domain Domain Class Class\
                            Attribute Name} |
                    relation dict ~ Name Type
                }]
                relvar create $assignvar\
                    [concat $idattrs [list __State string]]\
                    [dict keys $idattrs]
            }
        }
    }
    proc populate {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Populate $script ; # <1>
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc populateFromChan {chan} {
        tailcall populate [::chan read -nonewline $chan]
    }
    proc populateFromFile {filename} {
        set f [::open $filename r]
        try {
            populateFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc save {args} {
        set savecmd ::ral::serializeToFile
        set asynccmd {}
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set savecmd ::ral::storeToSQLite
                    }
                    -tclral {
                        set savecmd ::ral::serializeToFile
                    }
                    -async {
                        set options [lassign $options asynccmd]
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION save $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} { # <1>
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError SAVE_ARG_ERROR $args
        }
    
        set script "try \{$savecmd $file ${domain}::\\\[A-Za-z0-9\\\]*\}" ; # <2>
        if {$asynccmd ne {}} {
            append script " finally \{$asynccmd $domain $file\}"
        }
    
        after idle [list ::apply [list {} $script]] ; # <3>
    }
    proc restore {args} {
        set restorecmd ::ral::mergeFromFile
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set restorecmd ::ral::mergeFromSQLite
                    }
                    -tclral {
                        set restorecmd ::ral::mergeFromFile
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION restore $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} {
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError RESTORE_ARG_ERROR $args
        }
    
        eval [list $restorecmd $file $domain]
    
        # Determine the values for the system supplied defaults.  We examine all
        # the classes that have such attributes and find the maximum value of the
        # attribute.  This can then be placed in the array that is used when new
        # default values are generated.
        set domainname [namespace tail $domain]
        set supplied [pipe {
            relvar set ::rosea::Config::SystemSuppliedValue |
            relation restrictwith ~ {$Domain eq $domainname}
        }]
    
        relation foreach sup $supplied {
            relation assign $sup
            set classtups [relvar set ${domain}::$Class]
            if {[relation isempty $classtups]} {
                set maxvalue $StartValue
            } else {
                set maxvalue [pipe {
                    relation summarizeby $classtups {} cv\
                        MaxValue int {rmax($cv, $Attribute)} |
                    relation extract ~ MaxValue
                }]
            }
            set ${domain}::__Arch_SuppliedDefault($Class,$Attribute)\
                [expr {$maxvalue + 1}]
        }
        return
    }
    proc info {args} {
        set args [lassign $args subcmd]
    
        switch -exact -- $subcmd {
            domain {
                Info::domain $args
            }
            class {
                Info::class $args
            }
            statemodel {
                Info::statemodel $args
            }
            default {
                tailcall DeclError UNKNOWN_INFO_CMD $subcmd
            }
        }
    }
    proc tunnel {instref op args} {
        relvar eval {
            set result [[lindex $instref 0]::Instance $instref $op {*}$args]
        }
        return $result
    }
    proc trace {subcmd args} {
        switch -exact -- $subcmd {
            control {
                tailcall traceControl {*}$args
            }
            decode {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DecodeAllTraces
                    }
                    class {
                        tailcall Trace::DecodeClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DecodeTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            format {
                tailcall formatTraces {*}$args
            }
            diagram {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DiagAllTraces {*}[lrange $args 1 end]
                    }
                    class {
                        tailcall Trace::DiagClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DiagTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            default {
                tailcall DeclError UNKNOWN_TRACE_CMD $subcmd
            }
        }
    }
    proc traceControl {op args} {
        switch -exact -- $op {
            on {
                namespace upvar Trace traceState traceState
                set traceState on
            }
            off {
                namespace upvar Trace traceState traceState
                set traceState off
            }
            status {
                namespace upvar Trace traceState traceState
                return $traceState
            }
            clear {
                relvar eval {
                    foreach rvar {Trace Creation Polymorphic Transition} {
                        relvar set Trace::$rvar\
                                [relation emptyof [relvar set Trace::$rvar]]
                    }
                }
                namespace upvar Trace traceNumber traceNumber
                set traceNumber 0
            }
            logon {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState on
            }
            logoff {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState off
            }
            loglevel {
                namespace upvar Trace traceLogLevel traceLogLevel
                if {[llength $args] != 0} {
                    set traceLogLevel [lindex $args 0]
                }
                return $traceLogLevel
            }
            save {
                if {[llength $args] == 0} {
                    DeclError NO_SAVEFILE
                }
                ral storeToSQLite [lindex $args 0] ::rosea::Trace::*
            }
            default {
                DeclError BAD_TRACEOP $op
            }
        }
    }
    proc formatTraces {tracerecs} {
        if {[llength $tracerecs] == 0} {
            return {}
        }
        set prevtime [dict get [lindex $tracerecs 0] time]
        foreach rec $tracerecs {
            dict with rec {
                append result "[Trace::FormatTimestamp $time]: "
                append result "[Trace::FormatTimeAsSec\
                        [expr {$time - $prevtime}]]: "
                set prevtime $time
                append result [Trace::FormatTraceRec $rec] \n
            }
        }
        return [string trimright $result]
    }
    namespace eval Helpers {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        variable errFormats
        set errFormats [dict create {*}{
            SAME_CLASS   {operation is only allowed for references to the same class,\
                            got "%s" and "%s"}
            UNKNOWN_STATE   {unknown state, "%s", for class, "%s"}
            UNKNOWN_EVENT   {unknown event, "%s", for class, "%s"}
            NO_CREATION_EVENTS   {class, "%s", has no defined creation events}
            NO_CROSS_DOMAIN         {cannot link instances across domains,\
                                        got "%s" and "%s"}
            UNKNOWN_RELATIONSHIP    {unknown relationship, "%s"}
            NON_PARTICIPANTS        {"%s" and "%s" don't participate in %s,\
                                        expected "%s" and "%s"}
            MUST_BE_SINGULAR    {number of referred to instances for "%s" must be one,\
                                    got %d}
            NOT_IN_ASSOCIATION         {"%s" $relvar1 not a participant in "%s"}
            DIRECTION_REQUIRED  {direction argument is required: got "%s"}
            AMBIGUOUS_UNLINK         {"%s" is reflexive and linking via "%s" is ambiguous}
            NO_SUBCLASS         {relationship "%s" does not have a "%s"}
            NO_ASSIGNER         {relationship, "%s", does not have an assigner}
            NO_IDENTIFIER       {bad identifying attributes, expected "%s", got "%s"}
            UNKNOWN_ASSIGNER    {unknown assigner instance, "%s", for relationship, "%s"}
            UNKNOWN_LINKAGE {unknown relationship, "%s", for class, "%s"}
            PATH_ERROR      {relationship, "%s", from "%s" to "%s", does not end at "%s"}
            GEN_PATH_ERROR  {navigating from superclass, "%s", along generalization "%s",\
                            does not have "%s" as a subclass}
            ARG_ERROR           {attribute updates must be name / value pairs, got "%s"}
            ID_UPDATE           {cannot update identifying attributes, "%s"}
            UNKNOWN_ATTRIBUTE   {unknown attribute, "%s"}
            WITH_ATTR_USAGE {wrong arguments, should be,\
                    "withAttribute attrvarpair1 ?attrvarpair2 ...? body"}
            ATTR_VAR_SPEC   {attribute / variable argument must be a one or two element\
                    list, got "%s"}
            INVALID_TIME    {invalid time value, "%s"}
            SINGLE_OR_EMPTY_REF_REQUIRED {single valued or nil reference required, %d found}
            SINGLE_REF_REQUIRED     {single valued reference required, %d found}
            ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
                with attributes, "%s", failed: %s}
            EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
            CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}
            CONFIG_ERRORS     {encountered %d configuration script errors}
            EMPTY_NAME      {the empty string is not a valid name for a %s}
            BAD_CLASS_NAME      {class names must be begin with an alphanumeric\
                                character, got: "%s"}
            DUP_ELEMENT_NAME    {a class, relationship or domain operation named, "%s",\
                                already exists}
            RESERVED_NAME {names beginning with two underscore characters are reserved,\
                    "%s" cannot be used as a name in this context}
            INT_TYPE_REQUIRED   {attribute must be of "int" type, got "%s"}
            INT_VALUE_REQUIRED  {an integer value is required, got "%s"}
            ARG_FORMAT      {options and values must come in pairs, got "%s"}
            UNKNOWN_OPTION  {unknown %s command option, "%s"}
            DUP_OP_NAME     {operation call, "%s", already exists}
            NS_QUALIFIERS   {name, "%s", contains namespace qualifiers}
            TILDE_NAME {names beginning with the tilde character are not allowed\
                in this context, "%s"}
                
            BAD_RELATIONSHIP_SPEC  {bad relationship specifier, "%s"}
            NEED_ASSOCIATOR {relationship of type, "%s", requires associative class}
            NEED_REFLEXIVE_PATH {traversal path must be specified for reflexive\
                    association, %s, %s %s %s}
            REFLEXIVE_NOT_ALLOWED   {associations of type, "%s", cannot be reflexive}
            TOO_FEW_SUBCLASSES  {at least 2 subclasses must be specified, got %d}
            BAD_CREATION_TARGET {the target of a creation event must be a state,\
                    got "%s"}
            PSEUDO_STATE    {the transition action, "%s", is not valid as %s}
            EXPECTED_PSEUDO_STATE    {expected CH or IG, got "%s"}
            RELVAR_TRACE_OP     {unexpected relvar trace operation, "%s"}
            ATTR_CHECK_FAILED   {check for attribute, "%s", failed:\
                                instance value was, "%s": "%s" evaluated to "%s"}
            UNKNOWN_DOMAIN  {unknown domain, "%s"}
            ARG_MISMATCH      {number of population values must be a multiple of %d, got %d}
            SAVE_ARG_ERROR  {wrong number of arguments: expected:\
                    "save ?-sqlite | -tclral? ?-async <cmdprefix>?\
                    <domain> <filename>", got: "%s"}
            RESTORE_ARG_ERROR  {wrong number of arguments: expected:\
                    "restore ?-sqlite | -tclral?  <domain> <filename>", got: "%s"}
            UNKNOWN_INFO_CMD  {unknown info request, "%s"}
            UNKNOWN_CLASS  {unknown class, "%s", in domain, "%s"}
            UNKNOWN_TRACE_CMD   {unknown trace subcomand, "%s"}
            BAD_TRACEOP     {unknown trace operation, "%s"}
            NO_SAVEFILE     {no save file name provided}
            BAD_TRACETYPE   {unknown trace type, "%s"}
        }]
        proc ToRef {relvar relvalue} {
            tailcall list $relvar [relation project $relvalue\
                {*}[lindex [relvar identifiers $relvar] 0]] ; # <1>
        }
        proc nilInstRef {} {
            return {{} {{} {}}}
        }
        proc CreateStateInstance {domns class state idattrs} {
            tailcall relvar insert ${domns}::${class}__STATEINST\
                    [concat $idattrs [list __State $state]]
        }
        proc CreateInInitialState {domns class idattrs} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstance $domns $class [relation extract $initstate State]\
                    $idattrs
            }
            return
        }
        proc CreateStateInstanceFromRef {domns class state ref} {
            relation foreach inst [lindex $ref 1] { # <1>
                CreateStateInstance $domns $class $state\
                    [tuple get [relation tuple $inst]]
            }
            return
        }
        proc CreateInInitialStateFromRef {domns class ref} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstanceFromRef $domns $class\
                    [relation extract $initstate State] $ref
            }
            return
        }
        proc SelfInstRef {{level 2}} {
            set foundRef false
            set ref [nilInstRef]
        
            for {set ns [uplevel $level namespace current]} {$ns ne "::"}\
                    {set ns [uplevel [incr level] namespace current]} {
                if {!$foundRef} {
                    upvar $level self srcself
                    if {[info exists srcself]} {
                        set ref $srcself
                        set foundRef true
                    }
                }
                if {[string match {*__Activity*} $ns]} {
                    return $ref ; # <1>
                }
            }
            return [nilInstRef]
        }
        namespace export DeclError
        
        proc DeclError {errcode args} {
            variable errFormats
            set errmsg [format [dict get $errFormats $errcode] {*}$args]
            tailcall throw [list ROSEA $errcode {*}$args $errmsg] $errmsg
        }
        proc SplitRelvarName {relvar {dvarname domain} {cvarname class}} {
            upvar 1 $dvarname domain $cvarname class
            set domain [namespace qualifiers $relvar]
            set class [namespace tail $relvar]
        }
        proc PropagatePolyEvents {super} {
            namespace upvar ::rosea::Config\
                DeferredEvent DeferredEvent\
                LocalEvent LocalEvent\
                Superclass Superclass\
                Subclass Subclass\
                DeferralPath DeferralPath\
                Generalization Generalization ; # <1>
        
            set supername [relation extract $super Class]
        
            set subs [pipe {
                relation semijoin $super\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}
            }]
        
            relation foreach sub $subs {
                set defrdevents [pipe {
                    relation semijoin $super $DeferralPath\
                        -using {Domain Domain Class Model Relationship Relationship}\
                        $DeferredEvent |
                    relation update ~ deftup {1} {
                        tuple update $deftup Model [relation extract $sub Class]
                    }
                }]
                set multigens [relation semijoin $sub $Superclass\
                    -using {Domain Domain Class Class}]
        
                if {[relation isempty $multigens]} {
                    relvar minus ::rosea::Config::LocalEvent $defrdevents
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::EffectiveEvent $defrdevents
                    relvar union ::rosea::Config::MappedEvent [relation extend\
                        $defrdevents metuple ParentModel string {$supername}]
                } else {
                    set consumed [relation semijoin $defrdevents $LocalEvent]
                    if {[relation isnotempty $consumed]} {
                        relvar minus ::rosea::Config::LocalEvent $consumed ; # <1>
                        relvar union ::rosea::Config::MappedEvent [relation extend\
                            $consumed ctup ParentModel string {$supername}]
                        relvar union ::rosea::Config::NonLocalEvent [relation extend\
                            $consumed nletuple\
                            Relationship string {[relation extract $sub Relationship]}\
                            Role string {[relation extract $sub Role]}]
                        set defrdevents [relation minus $defrdevents $consumed] ; # <2>
                    
                        set usedinsubs [pipe {
                            FindSubclassesOf $multigens|
                            relation tclose ~ |
                            relation semijoin $consumed ~ -using {Model Super} |
                            relation semijoin ~ $LocalEvent -using {Sub Model} |
                            relation semijoin $consumed ~ -using {Domain Domain Event Event}
                        }]
                        relvar minus ::rosea::Config::LocalEvent $usedinsubs ; # <3>
                        relvar minus ::rosea::Config::EffectiveEvent $usedinsubs
                        relvar minus ::rosea::Config::Event $usedinsubs
                    }
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::DeferredEvent $defrdevents
                    relvar union ::rosea::Config::InheritedEvent $defrdevents
                    relvar union ::rosea::Config::DeferralPath [relation join\
                        $defrdevents $Superclass -using {Domain Domain Model Class}]
                }
        
                relvar union ::rosea::Config::NonLocalEvent [relation extend\
                    $defrdevents nletuple\
                    Relationship string {[relation extract $sub Relationship]}\
                    Role string {[relation extract $sub Role]}]
                relation foreach multigen $multigens {
                    PropagatePolyEvents $multigen
                }
            }
        }
        proc FindSubclassesOf {supers} {
            namespace upvar ::rosea::Config\
                Generalization Generalization\
                Superclass Superclass\
                Subclass Subclass
        
            if {[relation isempty $supers]} {# <1>
                return [relation create {Super string Sub string}]
            }
            set supnames [pipe {
                relation project $supers Class |
                relation rename ~ Class Super
            }] ; # <2>
            set subclasses [relation semijoin $supers\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}]
            set subnames [pipe {
                relation project $subclasses Class |
                relation rename ~ Class Sub
            }] ; # <3>
            
            set uses [relation times $supnames $subnames] ; # <4>
        
            set nextsupers [relation semijoin $subclasses $Superclass\
                    -using {Domain Domain Class Class}] ; # <5>
        
            return [relation union $uses [FindSubclassesOf $nextsupers]] ; # <6>
        }
        proc UserDefaultTrace {defheading defvalues op relvar tuple} {
            tuple create\
                [dict merge $defheading [tuple heading $tuple]]\
                [dict merge $defvalues [tuple get $tuple]]
        }
        proc SupplyDefaultTrace {defheading op relvar tuple} {
            set attrs [tuple attributes $tuple] ; # <1>
            SplitRelvarName $relvar domain class ; # <2>
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [set ${domain}::__Arch_SuppliedDefault($class,$attrname)] ; # <3>
                    incr ${domain}::__Arch_SuppliedDefault($class,$attrname)
                    set tuple [tuple extend $tuple $attrname $attrtype $value] ; # <4>
                }
            }
            return $tuple
        }
        proc GenerateDefaultTrace {defheading defcmds op relvar tuple} {
            set attrs [tuple attributes $tuple]
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [eval [dict get $defcmds $attrname]]
                    set tuple [tuple extend $tuple $attrname $attrtype $value]
                }
            }
            return $tuple
        }
        proc CheckValueTrace {attrchecks op relvar args} {
            if {$op eq "insert"} {
                set tuple [lindex $args 0]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "update"} {
                set tuple [lindex $args 1]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "set"} {
                set relvalue [lindex $args 0]
                relation foreach inst $relvalue {
                    set tuple [relation tuple $inst]
                    EvalAttrCheck $attrchecks $tuple
                }
                return $relvalue
            } else {
                tailcall DeclError RELVAR_TRACE_OP $op
            }
        }
        proc EvalAttrCheck {attrchecks tuple} {
            dict for {attrname checkexpr} $attrchecks {
                tuple assign $tuple
                set result [expr $checkexpr]
                if {!$result} {
                    tailcall DeclError ATTR_CHECK_FAILED $attrname [tuple get $tuple]\
                        $checkexpr $result
                }
            }
        }
        proc QuerySystemOperations {which requiresSM} {
            return [pipe {
                relvar set ::rosea::Config::SuppliedOperation |
                relation restrictwith ~ {$RequiresStateModel == $requiresSM} |
                relation join [relvar set ::rosea::Config::$which] ~
            }]
        }
        proc QuerySystemClassOperations {className requiresSM} {
            return [pipe {
                QuerySystemOperations SystemClassOperation $requiresSM |
                relation update ~ sco 1 {
                    tuple update $sco Command\
                        [concat [tuple extract $sco Command]\
                        [list $className]]
                } |
                relation dict ~ Name Command
            }]
        }
        proc QuerySystemInstanceOperations {requiresSM} {
            return [pipe {
                QuerySystemOperations SystemInstanceOperation $requiresSM |
                relation dict ~ Name Command
            }]
        }
        proc Interleave {l1 l2} {
            set result [list]
            foreach a $l1 b $l2 {
                lappend result $a $b
            }
            return $result
        }
        proc MapCondMultToConstraint {cond mult} {
            if {$cond} {
                return [expr {$mult ? "*" : "?"}]
            } else {
                return [expr {$mult ? "+" : "1"}]
            }
        }
    }
    namespace eval ClassCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers ; # <1>
        proc findAll {relvar} {
            tailcall ToRef $relvar [relvar set $relvar]
        }
        proc findById {relvar args} {
            tailcall ToRef $relvar [relvar restrictone $relvar {*}$args]
        }
        proc findWhere {relvar expr} {
            tailcall ToRef $relvar [uplevel 1 [list ::ral relation restrictwith\
                [relvar set $relvar] $expr]]
        }
        proc create {relvar args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]] ; # <1>
            SplitRelvarName $relvar domain class
            CreateInInitialStateFromRef $domain $class $ref
            return $ref
        }
        proc createin {relvar state args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $relvar domain class
            set initstate [relvar restrictone ${domain}::__Arch_State\
                Class $class State $state]
            if {[relation isempty $initstate]} { # <1>
                tailcall DeclError UNKNOWN_STATE $state $relvar
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]]
            CreateStateInstanceFromRef $domain $class $state $ref
            return $ref
        }
        proc createasync {relvar event eventparams args} {
            SplitRelvarName $relvar domain class
        
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
            if {[relation isempty [relvar restrictone ${domain}::__Arch_State\
                    Class $class State @]]} {
                tailcall DeclError NO_CREATION_EVENTS $class
            }
            set srcref [SelfInstRef]
            set eventInfo [dict create\
                type creation\
                src $srcref\
                dstClass $relvar\
                dstAttrs $args\
                event $event\
                params $eventparams\
            ]
            if {[::rosea::InstCmds::isRefEqual $srcref [nilInstRef]]} {
                lappend ::rosea::Dispatch::toc_queue $eventInfo
            } else {
                lappend ::rosea::Dispatch::event_queue $eventInfo
            }
            ::after 0 ::rosea::Dispatch::DispatchEvent
            return
        }
        proc update {relvar relvalue} {
            tailcall ToRef $relvar [relvar updateper $relvar $relvalue]
        }
    }
    namespace eval InstCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace path [namespace parent]::Helpers
        pipe {
            relvar set ${domain}::$DstClass |
            relation $op $related ~ -using $Attrs
        } relatedQuery
        proc deRef {instref args} {
            lassign $instref relvar ref
            set inst [relation semijoin $ref [relvar set $relvar]] ; # <1>
            if {[llength $args] != 0} {
                set inst [relation project $inst\
                    {*}[relation attributes $ref] {*}$args] ; # <2>
            }
            return $inst
        }
        proc isEmptyRef {instref} {
            tailcall relation isempty [lindex $instref 1]
        }
        proc isNotEmptyRef {instref} {
            tailcall relation isnotempty [lindex $instref 1]
        }
        proc refMultiplicity {instref} {
            tailcall relation cardinality [lindex $instref 1]
        }
        proc isRefSingular {instref} {
            expr {[refMultiplicity $instref] == 1}
        }
        proc limitRef {instref {count 1}} {
            lassign $instref relvar insts
            return [pipe {
                relation tag $insts __Tag |
                relation restrictwith ~ {$__Tag >= 0 && $__Tag < $count} |
                ToRef $relvar ~
            }]
        }
        proc isRefEqual {instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            return [expr {$relvar1 eq $relvar2 && [relation is $inst1 equal $inst2]}]
        }
        proc RefSetCommand {op instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            if {$relvar1 ne $relvar2} {
                tailcall DeclError SAME_CLASS $relvar1 $relvar2
            }
            return [list $relvar1 [relation $op $inst1 $inst2]]
        }
        proc refUnion {instref1 instref2} {
            tailcall RefSetCommand union $instref1 $instref2
        }
        proc refIntersect {instref1 instref2} {
            tailcall RefSetCommand intersect $instref1 $instref2
        }
        proc refMinus {instref1 instref2} {
            tailcall RefSetCommand minus $instref1 $instref2
        }
        proc forAllRefs {varname instref body} {
            lassign $instref relvar refs
            upvar 1 $varname inst
            relation foreach ref $refs {
                set inst [list $relvar $ref]
                uplevel 1 $body
            } ; # <1>
            return
        }
        proc FindRelatedInsts {instref op args} {
            set srcrelvar [lindex $instref 0]
            SplitRelvarName $srcrelvar domain class
            
            # This procedure queries the architectural data about relationship linkage,
            # so we bring the relvar variables into scope.
            namespace upvar ${domain}\
                    __Arch_Link Link\
                    __Arch_AssociationLink AssociationLink\
                    __Arch_PartitionLink PartitionLink\
                    __Arch_PartitionDst PartitionDst
            variable relatedQuery ; # <1>
            # We start by dereferencing the instance reference.
            set related [deRef $instref]
            foreach linkage $args {
                lassign $linkage lname dst ; # split out the linkage spec
                
                set link [relvar restrictone ${domain}::__Arch_Link\
                        Name $lname SrcClass $class]
                if {[ral relation isempty $link]} {
                    tailcall DeclError UNKNOWN_LINKAGE $lname $class
                }
                # First we determine if we are dealing with an associative link or a
                # partition link.
                set assoc [relation join $link $AssociationLink]
                if {[relation isnotempty $assoc]} {
                    relation assign $assoc DstClass Attrs
                    # Check if additional path information was provided.
                    if {$dst eq {}} {
                        # Find the set of instances related to the current set.
                        set related [eval $relatedQuery]
                        # We must see if this is a class-based association.  If so, then the first
                        # traversal was to the associator and we must traverse again to the other
                        # class.
                        set assoc [relation semijoin $assoc $AssociationLink\
                            -using {Name Name SrcClass PrevSrcClass}]
                        if {[relation isnotempty $assoc]} {
                            relation assign $assoc DstClass Attrs
                            set related [pipe {# <1>
                                relvar set ${domain}::$DstClass |
                                relation semijoin $related ~ -using $Attrs
                            }]
                        }
                    } else {
                        # If a destination was specified in the linkage, then we need to verify
                        # that it is actually part of the relationship.
                        if {$dst ne $DstClass} {
                            tailcall DeclError PATH_ERROR $lname $class $DstClass\
                                $dst
                        }
                        set related [eval $relatedQuery]
                    }
                } else {
                    set partdst [relvar restrictone ${domain}::__Arch_PartitionDst\
                        Name $lname SrcClass $class DstClass $dst]
                    if {[relation isempty $partdst]} {
                        tailcall DeclError GEN_PATH_ERROR $class $lname $dst
                    }
                    relation assign $partdst DstClass Attrs
                    set related [eval $relatedQuery]
                }
                # Continue the iteration by setting the next source to the current
                # destination class.
                set class $DstClass
                set srcrelvar ${domain}::$class
            }
            # N.B. that we are not returning an instance reference but rather the
            # complete relation value of the related instances. This allows us
            # to further filter the result in the "findRelatedWhere" command.
            return [list $srcrelvar $related]
        }
        proc findRelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semijoin {*}$args] ; # <1>
        }
        proc findUnrelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semiminus {*}$args] ; # <1>
        }
        proc findRelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semijoin {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]] ; # <1>
        }
        proc findUnrelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semiminus {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]]
        }
        proc idInstance {instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set idclass [pipe {
                relvar restrictone [namespace parent]::Config::MultipleAssigner\
                        Domain [string trim $domain :] Relationship $relationship |
                relation extract ~ Class
            }]
        
            return [pipe {
                relvar set ${domain}::$idclass |
                relation semijoin $insts ~ |
                ToRef ${domain}::$idclass ~
            }]
        }
        proc updateAttribute {instref args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_ERROR $args
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $args]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach {attr value} $args {
                if {![dict exists $heading $attr]} {
                    tailcall DeclError UNKNOWN_ATTRIBUTE $attr
                }
                lappend extcmd $attr [dict get $heading $attr] \{$value\}
            }
            relvar updateper $relvar [eval $extcmd]
            return
        }
        proc withAttribute {instref args} {
            if {[llength $args] < 2} {
                tailcall DeclError WITH_ATTR_USAGE
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            
            set body [lindex $args end]
            set attrspecs [lrange $args 0 end-1]
            set attrnames [list]
            set varnames [list]
            foreach attrspec $attrspecs {
                set speclen [llength $attrspec]
                if {$speclen == 1} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 0]
                } elseif {$speclen == 2} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 1]
                } else {
                    tailcall DeclError ATTR_VAR_SPEC $attrspec
                }
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $attrnames]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            uplevel 1 [list ral relation assign [deRef $instref] {*}$attrspecs]
            uplevel 1 $body
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach attr $attrnames var $varnames {
                if {[uplevel 1 [list info exists $var]]} {
                    upvar 1 $var varvalue
                    lappend extcmd $attr [dict get $heading $attr] \{$varvalue\}
                }
            }
            relvar updateper $relvar [eval $extcmd]
        
            return
        }
        proc readAttribute {ref args} {
            # We insist upon a singular reference for reading attributes.  Multiple
            # references can be handled by dereferences and using TclRAL "relation"
            # commands.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            return [expr {[llength $args] == 0 ? {} :\
                [relation extract [deRef $ref {*}$args] {*}$args]}] ; # <1>
        }
        proc assignAttribute {ref args} {
            # We must insist upon a singular references, since assigning to scalar
            # variables from a relation value doesn't make a lot of sense.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            uplevel 1 [list ral relation assign [deRef $ref] {*}$args] ; # <1>
            return
        }
        proc delete {args} {
            foreach instref $args {
                lassign $instref relvar insts
                relvar minus $relvar [deRef $instref]
        
                SplitRelvarName $relvar domain class
                set instrelvar ${domain}::${class}__STATEINST
                if {[relvar exists $instrelvar]} {
                    relvar minus $instrelvar [relation semijoin $insts\
                        [relvar set $instrelvar]]
                }
            }
        
            return
        }
        proc signal {dstset event args} {
            set srcref [SelfInstRef]
            if {![::rosea::Dispatch::MapPolymorphicEvent ::rosea::Dispatch::SignalEvent\
                    $srcref $dstset $event $args]} {
                ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args
            }
            return
        }
        proc delaysignal {time dstset event args} {
            if {!([string is integer -strict $time] && $time >= 0)} {
                tailcall DeclError INVALID_TIME $time
            }
            set srcref [SelfInstRef]
            if {![::rosea::Dispatch::MapPolymorphicEvent\
                    [list ::rosea::Dispatch::SignalDelayedEvent $time]\
                    $srcref $dstset $event $args]} {
                ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args
            }
            return
        }
        proc canceldelayed {srcref dstset event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            forAllRefs dstref $dstset {
                ::rosea::Dispatch::CancelDelayedSignal $srcref $event $dstref
            }
            return
        }
        proc delayremaining {srcref dstref event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            if {![isRefSingular $dstref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $dstref]
            }
            tailcall ::rosea::Dispatch::SignalTimeRemaining $srcref $event $dstref
        }
        proc instop {instref op args} {
            tailcall [lindex $instref 0]::Instance $instref $op {*}$args
        }
    }
    namespace eval RelCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        proc linkSimple {rname instref1 instref2} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set reflink [relvar restrictone ${domain1}::__Arch_RefLink Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs} ; # <1>
            if {$class1 eq $referringClass && $class2 eq $referencedClass} {
                set fromrelvar $relvar1
                set frominsts $inst1
                set torelvar $relvar2
                set toinst $inst2
            } elseif {$class2 eq $referringClass && $class1 eq $referencedClass} {
                set fromrelvar $relvar2
                set frominsts $inst2
                set torelvar $relvar1
                set toinst $inst1
            } else {
                tailcall DeclError NON_PARTICIPANTS $relvar1 $relvar2 $rname\
                    $referringClass $referencedClass
            }
            if {[relation cardinality $toinst] != 1} {
                tailcall MUST_BE_SINGULAR $torelvar [relation cardinality $toinst]
            }
            set refedvalue [relation semijoin $toinst [relvar set $torelvar]]
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] { # <1>
                    tuple update $fromtup {*}$tovalues ; # <2>
                }
            }
        
            return
        }
        proc linkAssoc {rname instref1 instref2 args} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${domain1}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            set ref1 [relation restrictwith $references {$Participant eq $class1}]
            if {[relation isempty $ref1]} {
                tailcall DeclError NOT_IN_ASSOCIATION $class1 $rname
            }
            if {[relation cardinality $ref1] > 1} {
                set ref2 [relation restrictwith $ref1 {$Role eq "target"}]
                set ref1 [relation minus $ref1 $ref2] ; # <1>
            } else {
                set ref2 [relation restrictwith $references {$Participant eq $class2}]
                if {[relation isempty $ref2]} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class2 $rname
                }
            }
            
            set rattr1 [relation extract $ref1 ReferringAttrs]
            set rattr2 [relation extract $ref2 ReferringAttrs]
            set values1 [relation semijoin $inst1 [relvar set $relvar1]]
            set values2 [relation semijoin $inst2 [relvar set $relvar2]]
            set assoctuples [list]
            relation foreach v1 $values1 { # <1>
                set refto1 [pipe {
                    relation extend $rattr1 rfa RefValue string {
                        [relation extract $v1 [tuple extract $rfa ReferencedAttribute]]
                    } |
                    relation dict ~ ReferringAttribute RefValue
                }]
                relation foreach v2 $values2 {
                    set refto2 [pipe {
                        relation extend $rattr2 rfa RefValue string {
                            [relation extract $v2\
                                [tuple extract $rfa ReferencedAttribute]]
                        } |
                        relation dict ~ ReferringAttribute RefValue
                    }]
            
                    lappend assoctuples [dict merge $args $refto1 $refto2] ; # <2>
                }
            }
            set ref [ToRef ${domain1}::$assocClass\
                    [relvar insert ${domain1}::$assocClass {*}$assoctuples]]
                CreateInInitialStateFromRef $domain1 $assocClass $ref ; # <1>
            return $ref
        }
        proc referenceAssoc {rname assocref instref {dir {}}} {
            if {![isRefSingular $assocref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $assocref]
            }
            lassign $assocref assocrelvar associnst
            SplitRelvarName $assocrelvar assocdomain assocclass
            
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref instrelvar inst
            SplitRelvarName $instrelvar instdomain instclass
            
            if {$assocdomain ne $instdomain} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${instdomain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            
            if {$assocClass ne $assocclass} {
                tailcall DeclError NOT_IN_ASSOCIATION $assocclass $rname
            }
            set ref [relation restrictwith $references {$Participant eq $instclass}]
            set refcard [relation cardinality $ref]
            if {$refcard == 2} {
                switch -exact -- $dir {
                    forward {
                        set role target
                    }
                    backward {
                        set role source
                    }
                    default {
                        tailcall DeclError DIRECTION_REQUIRED $dir
                    }
                }
                set ref [relation restrictwith $ref {$Role eq $role}]
            } elseif {$refcard == 0} {
                tailcall DeclError NOT_IN_ASSOCIATION $instclass $rname
            }
            set referringAttrs [relation extract $ref ReferringAttrs]
            
            set refedvalue [relation semijoin $inst [relvar set $instrelvar]]
            
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relvar updateone $assocrelvar assoctup [tuple get [relation tuple $associnst]] {
                tuple update $assoctup {*}$tovalues
            }
        }
        proc unlinkSimple {rname instref} {
            lassign $instref relvar inst
            SplitRelvarName $relvar domain class
        
            set reflink [relvar restrictone ${domain}::__Arch_RefLink\
                    Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs}
        
            if {$class eq $referringClass} {
                set fromrelvar $relvar
                set frominsts $inst
            } elseif {$class eq $referencedClass} {
                lassign [::rosea::InstCmds::findRelated $instref ~$rname]\
                    fromrelvar frominsts
            } else {
                tailcall DeclError NOT_IN_ASSOCIATION $relvar $rname
            }
        
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {{}} |
                relation dict ~ ReferringAttribute RefValue
            }]
        
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] {
                    tuple update $fromtup {*}$tovalues
                }
            }
        
            return
        }
        proc unlinkAssoc {rname instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain class
        
            set assocref [relvar restrictone ${domain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $assocref\
                {Relationship relationship}\
                {AssocClass associator}\
                {References references}
        
            # If we are given instances to the associator class, then there is no
            # more work to do.
            if {$class ne $associator} {
                # Otherwise, we have to find the associator class instances ourselves.
                set part [relation restrictwith $references {$Participant eq $class}]
                set partcard [relation cardinality $part]
                if {$partcard == 0} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class $rname
                } elseif {$partcard > 1} {
                    tailcall DeclError AMBIGUOUS_UNLINK $rname $relvar ; # <1>
                } else {
                    # Find associative class instances.  We have to determine the
                    # direction of the relationship traversal.
                    set navdir [expr {[relation extract $part Role] eq "source" ?\
                        "$relationship" : "~$relationship"}]
                    set instref [::rosea::InstCmds::findRelated $instref\
                        [list $navdir [namespace tail $associator]]]
                    lassign $instref relvar insts
                    SplitRelvarName $relvar domain class
                }
            }
        
            # We are going to delete tuples from the relvar that holds the class
            # instances.
            set delrelvars [list ${domain}::$class]
            # If the associative class also has a state model, then we need to also
            # delete the state instance tuples.
            if {[relvar exists ${domain}::${class}__STATEINST]} {
                lappend delrelvars ${domain}::${class}__STATEINST
            }
        
            # Now, we iterate across the associative class instances and delete all the
            # tuples in class relvar and, if necessary, the state instances.
            relation foreach inst $insts {
                set idattrs [tuple get [relation tuple $inst]]
                foreach rv $delrelvars {
                    relvar deleteone $rv {*}$idattrs
                }
            }
            return $instref
        }
        proc migrate {rname instref subclass args} {
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref relvar inst
            SplitRelvarName $relvar domns class
        
            set link [relvar restrictone ${domns}::__Arch_AssociationLink Name $rname\
                    SrcClass $class]
            if {[relation isempty $link]} {
                tailcall DeclError NO_SUBCLASS $rname $relvar
            }
        
            # Traverse the relationship to the superclass. We need to get the values of
            # the referenced attributes to use in creating the new subclass instance.
            set superinst [pipe {
                relvar set ${domns}::[relation extract $link DstClass] |
                relation semijoin $inst ~ -using [relation extract $link Attrs]
            }]
        
            set sublink [relvar restrictone ${domns}::__Arch_SubLink\
                    Relationship $rname SubClass $subclass]
            if {[relation isempty $sublink]} {
                tailcall DeclError NO_SUBCLASS $rname $subclass
            }
        
            # Using the same relation extend strategy, we compute a dictionary of the
            # attribute names / values as they must appear in the subclass we are about
            # to create.
            set refedvalues [pipe {
                relation extract $sublink ReferringAttrs |
                relation extend ~ rval Value string {
                    [relation extract $superinst\
                        [tuple extract $rval ReferencedAttribute]]
                } |
                relation dict ~ ReferringAttribute Value
            }]
        
            # We use the class commands to delete the old subclass instance and create
            # the new one. This will make sure that if the subclass has a state model
            # that the initial state is set correctly.
            # N.B. this is _not_ done in a relvar transaction. The transaction
            # boundaries should be set by the current thread of control or domain
            # operation.
            ::rosea::InstCmds::delete $instref
            return [::rosea::ClassCmds::create ${domns}::$subclass\
                    {*}[dict merge $args $refedvalues]]
        }
        proc signalAssigner {rname event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set dstref [pipe {
                relvar set $assignrelvar |
                relation project ~ {*}[lindex [relvar identifiers $assignrelvar] 0] |
                list $rname ~
            }]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args
        
            return
        }
        proc signalMultiAssigner {rname idvalues event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [lindex [relvar identifiers $assignrelvar] 0]
            # We will insist that the idvalues contain the necessary identifying
            # attributes.
            if {![struct::set equal [dict keys $idvalues] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
            }
            set assigninsts [relvar set $assignrelvar]
            set assignrefs [relation project $assigninsts {*}$idattrs]
        
            # We need to find the tuple in "assignrefs" that matches the attributes and
            # values in "idvalues". We will do this by creating a relation value from
            # the idvalues list and semijoining that to "assignrefs". If we come up
            # non-empty, then we have found our multi-assigner instance.
            set heading [relation heading $assignrefs]
            set dstinst [pipe {
                tuple create $heading $idvalues |
                tuple relation ~ |
                relation semijoin ~ $assignrefs
            }]
            if {[relation isempty $dstinst]} {
                tailcall DeclError UNKNOWN_ASSIGNER $idvalues $rname
            }
        
            set dstref [list $rname $dstinst]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args ; # <1>
        
            return
        }
        proc createMultiAssigner {rname args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [lindex [relvar identifiers $assignrelvar] 0]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            CreateInInitialState $domain $relationship $args
        }
    }
    namespace eval Dispatch {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        variable toc_queue [list]
        variable event_queue [list]
        pipe {
            relvar restrictone ${domain}::__Arch_Transition\
                Class $class State $currstate Event $event |
            relation extract ~ NewState
        } transitionQuery
        relvar create DelayedSignal {
            RefId           int
            SrcInstRef      list
            Event           string
            DstInstRef      list
            TimerId         string
            Expire          bignum
        } RefId {SrcInstRef Event DstInstRef} TimerId
        variable DelayedSignalId 0
        pipe {
            relvar set ${domain}::__Arch_PartitionDst |
            relation restrictwith ~ {$SrcClass eq $dstclass} |
            relation group ~ DstLinks DstClass Attrs
        } polymapQuery
        proc SignalEvent {srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            set callback [namespace code DispatchEvent]
            set eventInfo [dict create\
                type ordinary\
                src $srcref\
                event $event\
                params $arglist\
            ]
            if {[isRefEqual $srcref [nilInstRef]]} {
                variable toc_queue
                forAllRefs dstref $dstset {
                    # Queue the thread of control events.
                    dict set eventInfo dst $dstref
                    lappend toc_queue $eventInfo
                    ::after 0 $callback
                }
            } else {
                variable event_queue
                forAllRefs dstref $dstset {
                    dict set eventInfo dst $dstref
                    if {[isRefEqual $srcref $dstref]} { # <1>
                        for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
                            set cmpevent [lindex $event_queue $eqindex]
                            if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
                                break
                            }
                        }
                        set event_queue [linsert [K $event_queue [set event_queue {}]]\
                                $eqindex $eventInfo] ; # <1>
                    } else {
                        # Non-self directed events are always simply appended to the
                        # event queue.
                        lappend event_queue $eventInfo
                    }
                    ::after 0 $callback
                }
            }
        }
        proc DispatchEvent {} {
            variable event_queue
            variable toc_queue
            
            if {[llength $event_queue] != 0} {
                set eventInfo [lindex $event_queue 0]
                set event_queue [lrange [K $event_queue [set event_queue {}]] 1 end] ; # <1>
            } elseif {[llength $toc_queue] != 0} {
                set eventInfo [lindex $toc_queue 0]
                set toc_queue [lrange [K $toc_queue [set toc_queue {}]] 1 end]
                relvar transaction begin ; # <2>
            } else {
                return
            }
            if {[dict get $eventInfo type] eq "creation"} {
                try {
                    set dstref [::rosea::ClassCmds::createin\
                            [dict get $eventInfo dstClass] @\
                            {*}[dict get $eventInfo dstAttrs]] ; # <1>
                } on error {result} {
                    catch {
                        if {[llength $event_queue] == 0} {
                            relvar transaction end
                        }
                    }
                    tailcall DeclError ASYNC_CREATION_FAILED [dict get $eventInfo dstClass]\
                        [dict get $eventInfo dstAttrs] $result
                }
                dict set eventInfo dst $dstref ; # <2>
                ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
                    [dict get $eventInfo event] $dstref [dict get $eventInfo params]
            }
            set dstref [dict get $eventInfo dst]
            lassign $dstref relvar ref
            SplitRelvarName $relvar domain class
            
            set instrelvar ${domain}::${class}__STATEINST
            set state [relation semijoin $ref [relvar set $instrelvar]]
            if {[relation isempty $state]} {
                tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
            }
            set currstate [relation extract $state __State]
            set event [dict get $eventInfo event]
            variable transitionQuery
            set newState [eval $transitionQuery]
            
            ::rosea::Trace::TraceTransition [dict get $eventInfo src]\
                $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
            try {
                if {$newState eq "CH"} {
                    TransitionError [dict get $eventInfo src] $event $dstref $currstate
                } elseif {$newState ne "IG"} {
                    set idattrs [tuple get [relation tuple $ref]]
                    relvar updateone $instrelvar is $idattrs {
                        tuple update $is __State $newState
                    }
                    try {
                        ${relvar}::__Activity::$newState $dstref\
                                {*}[dict get $eventInfo params] ; # <1>
                    } on error {result opts} {
                        return -options $opts $result
                    } finally {
                        set term [relvar restrictone ${domain}::__Arch_TerminalState\
                                Class $class State $newState]
                        if {[relation isnotempty $term]} {
                            relvar deleteone $relvar {*}$idattrs
                            relvar deleteone $instrelvar {*}$idattrs
                        }
                    }
                }
            } on error {result opts} {
                catch {
                    if {[llength $event_queue] == 0} {
                        relvar transaction end
                    }
                } ; # <1>
                return -options $opts $result
            }
            
            if {[llength $event_queue] == 0} {
                relvar transaction end
            }
            return
        }
        proc TransitionError {src event dst currstate} {
            tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
        }
        proc FindDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            return [relation restrictwith $DelayedSignal {
                    [isRefEqual $SrcInstRef $srcref] && $Event eq $event &&\
                    [isRefEqual $DstInstRef $dstref]}]
        }
        proc DeleteDelayedSignal {srcref event dstref} {
            relvar delete DelayedSignal dsig {
                [isRefEqual [tuple extract $dsig SrcInstRef] $srcref] &&\
                [tuple extract $dsig Event] eq $event &&\
                [isRefEqual [tuple extract $dsig DstInstRef] $dstref]
            }
        }
        proc SignalDelayedEvent {time srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            variable DelayedSignalId
            set eventInfo [dict create\
                id [incr DelayedSignalId]\
                type ordinary\
                src $srcref\
                event $event\
                params $arglist\
            ]
            forAllRefs dstref $dstset {
                dict set eventInfo dst $dstref
                DeleteDelayedSignal $srcref $event $dstref ; # <1>
                relvar insert DelayedSignal [list\
                    RefId       $DelayedSignalId\
                    SrcInstRef  $srcref\
                    Event       $event\
                    DstInstRef  $dstref\
                    TimerId     [::after $time [list\
                                ::rosea::Dispatch::DispatchDelayedEvent $eventInfo]]\
                    Expire      [expr {entier([clock milliseconds]) + entier($time)}]\
                ]
            }
            return
        }
        proc DispatchDelayedEvent {eventInfo} {
            relvar deleteone DelayedSignal RefId [dict get $eventInfo id]
            variable toc_queue
            lappend toc_queue $eventInfo
            tailcall DispatchEvent
        }
        proc CancelDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            set sig [FindDelayedSignal $srcref $event $dstref]
            if {[relation isnotempty $sig]} {
                ::after cancel [relation extract $sig TimerId]
                DeleteDelayedSignal $srcref $event $dstref
            } else {
                # Search the toc_queue to see if the signal delay has already expired
                # and the event is awaiting dispatch.
                variable toc_queue
                for {set i 0} {$i < [llength $toc_queue]} {incr i} {
                    set eventInfo [lindex $toc_queue $i]
                    dict update eventInfo src evtsrc dst evtdst event evtevent {
                        if {[isRefEqual $evtsrc $srcref] &&\
                                [isRefEqual $evtdst $dstref] &&\
                                $evtevent eq $event} {
                            set toc_queue [lreplace\
                                    [K $toc_queue [set toc_queue {}]] $i $i]
                            break
                        }
                    }
                }
            }
        }
        proc SignalTimeRemaining {srcref event dstref} {
            set sig [FindDelayedSignal $srcref $event $dstref]
            return [expr {[relation isempty $sig] ? 0 :\
                max([relation extract $sig Expire] - [clock milliseconds], 0)}] ; # <1>
        }
        proc MapPolymorphicEvent {frwdcmd srcref dstrefs event arglist} {
            lassign $dstrefs dstrelvar dstinsts
            SplitRelvarName $dstrelvar domain dstclass
            set polyevent [relvar restrictone ${domain}::__Arch_PolymorphicEvent\
                Class $dstclass Event $event]
            if {[relation isempty $polyevent]} {
                return false
            }
            variable polymapQuery
            set partitions [eval $polymapQuery]
            relation foreach inst $dstinsts {
                relation foreach partition $partitions {
                    relation assign $partition
                    relation foreach dstlink $DstLinks {
                        relation assign $dstlink
                        set related [relation semijoin $inst\
                            [relvar set ${domain}::$DstClass] -using $Attrs]
                        if {[relation isnotempty $related]} {
                            set dstreference [ToRef ${domain}::${DstClass} $related]
                            set target [ToRef $dstrelvar $inst]
                            ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\
                                    $arglist
                            if {![MapPolymorphicEvent $frwdcmd $srcref $dstreference $event $arglist]} {
                                {*}$frwdcmd $srcref $dstreference $event $arglist ; # <1>
                            }
                            break
                        }
                    }
                }
            }
        
            return true
        }
    }
    namespace eval Config {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers
        variable evalLambda {{body} {
            upvar #0 ::rosea::Config::errcount errcount ; # <1>
            upvar #0 ::rosea::Config::configlineno configlineno
            set lineno $configlineno
            set command {}
            foreach line [split $body \n] { # <2>
                append command $line \n
                incr lineno ; # <3>
                if {[info complete $command]} {
                    try {
                        eval $command
                    } on error {result} {
                        log::error "line $configlineno: \"$result\""
                        incr errcount
                    }
                    set command {} ; # <4>
                    set configlineno $lineno
                }
            }
            return $errcount
        }}
        relvar create Domain {
            Name        string
            Location    string
        } Name
        relvar create DomainElement {
            Domain  string
            Element string
        } {Domain Element}
        relvar association R1\
            DomainElement Domain *\
            Domain Name 1
        relvar create Class {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create Relationship {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create DomainOperation {
            Domain      string
            Name        string
            Parameters  list
            Body        string
        } {Domain Name}
        relvar partition R2 DomainElement {Domain Element}\
            Class {Domain Name}\
            Relationship {Domain Name}\
            DomainOperation {Domain Name}
        relvar create Attribute {
            Domain  string
            Class   string
            Name    string
            Type    string
        } {Domain Class Name}
        relvar association R3\
            Attribute {Domain Class} +\
            Class {Domain Name} 1
        relvar create Identifier {
            Domain  string
            Class   string
            Number  int
        } {Domain Class Number}
        relvar association R4\
            Identifier {Domain Class} +\
            Class {Domain Name} 1
        relvar create IdentifyingAttribute {
            Domain      string
            Class       string
            Attribute   string
            Number      int
        } {Domain Class Attribute Number}
        relvar correlation R5 IdentifyingAttribute\
            {Domain Class Number} + Identifier {Domain Class Number}\
            {Domain Class Attribute} * Attribute {Domain Class Name}
        relvar create DefaultValue {
            Domain      string
            Class       string
            Attribute   string
        } {Domain Class Attribute}
        relvar association R6\
            DefaultValue {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create UserSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            Value       string
        } {Domain Class Attribute}
        relvar create SystemSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            StartValue  int
        } {Domain Class Attribute}
        relvar create GeneratedValue {
            Domain      string
            Class       string
            Attribute   string
            Cmd         string
        } {Domain Class Attribute}
        relvar partition R18 DefaultValue {Domain Class Attribute}\
            UserSuppliedValue {Domain Class Attribute}\
            SystemSuppliedValue {Domain Class Attribute}\
            GeneratedValue {Domain Class Attribute}
        relvar create ValueCheck {
            Domain      string
            Class       string
            Attribute   string
            Expression  string
        } {Domain Class Attribute}
        relvar association R17\
            ValueCheck {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create AttributeReference {
            Domain              string
            ReferringClass      string
            ReferringAttribute  string
            ReferringRole       string
            ReferencedClass     string
            ReferencedAttribute string
            ReferencedRole      string
            ReferencedIdNumber  int
            Relationship        string
        } {Domain ReferringClass ReferringAttribute ReferringRole\
            ReferencedClass ReferencedAttribute ReferencedRole ReferencedIdNumber\
            Relationship}
        relvar association R13\
            AttributeReference {Domain ReferringClass ReferringAttribute} *\
            Attribute {Domain Class Name} 1
        relvar create ReferencedIdAttribute {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Attribute       string
            Number          int
        } {Domain Class Relationship Role Attribute Number}
        relvar create Operation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar association R8\
            Operation {Domain Class} * Class {Domain Name} 1
        
        relvar create InstanceOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar create ClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R7 Operation {Domain Class Name}\
            InstanceOperation {Domain Class Name}\
            ClassOperation {Domain Class Name}
        
        relvar create UserInstanceOperation {
            Domain      string
            Class       string
            Name        string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemInstanceOperation {
            Domain      string
            Class       string
            Name        string
        } {Domain Class Name}
        
        relvar partition R9 InstanceOperation {Domain Class Name}\
            UserInstanceOperation {Domain Class Name}\
            SystemInstanceOperation {Domain Class Name}
        
        relvar create UserClassOperation {
            Domain  string
            Class   string
            Name    string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R10 ClassOperation {Domain Class Name}\
            UserClassOperation {Domain Class Name}\
            SystemClassOperation {Domain Class Name}
        
        relvar create SuppliedOperation {
            Name                string
            Command             string
            RequiresStateModel  boolean
        } Name
        
        relvar create SuppliedClassOperation {
            Name    string
        } Name
        
        relvar create SuppliedInstanceOperation {
            Name    string
        } Name
        
        relvar partition R14 SuppliedOperation Name\
            SuppliedClassOperation Name\
            SuppliedInstanceOperation Name
        
        relvar association R15\
            SystemClassOperation Name *\
            SuppliedClassOperation Name 1
        
        relvar association R16\
            SystemInstanceOperation Name *\
            SuppliedInstanceOperation Name 1
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findAll
                Command             ::rosea::ClassCmds::findAll
                RequiresStateModel  false
            } {
                Name                findById
                Command             ::rosea::ClassCmds::findById
                RequiresStateModel  false
            } {
                Name                findWhere
                Command             ::rosea::ClassCmds::findWhere
                RequiresStateModel  false
            } {
                Name                create
                Command             ::rosea::ClassCmds::create
                RequiresStateModel  false
            } {
                Name                createin
                Command             ::rosea::ClassCmds::createin
                RequiresStateModel  true
            } {
                Name                createasync
                Command             ::rosea::ClassCmds::createasync
                RequiresStateModel  true
            } {
                Name                update
                Command             ::rosea::ClassCmds::update
                RequiresStateModel  false
            }
        
            relvar insert SuppliedClassOperation {
                Name    findAll
            } {
                Name    findById
            } {
                Name    findWhere
            } {
                Name    create
            } {
                Name    createin
            } {
                Name    createasync
            } {
                Name    update
            }
        }
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findRelated
                Command             ::rosea::InstCmds::findRelated
                RequiresStateModel  false
            } {
                Name                findUnrelated
                Command             ::rosea::InstCmds::findById
                RequiresStateModel  false
            } {
                Name                findRelatedWhere
                Command             ::rosea::InstCmds::findRelatedWhere
                RequiresStateModel  false
            } {
                Name                findUnrelatedWhere
                Command             ::rosea::InstCmds::findUnrelatedWhere
                RequiresStateModel  false
            } {
                Name                updateAttribute
                Command             ::rosea::InstCmds::updateAttribute
                RequiresStateModel  false
            } {
                Name                withAttribute
                Command             ::rosea::InstCmds::withAttribute
                RequiresStateModel  false
            } {
                Name                readAttribute
                Command             ::rosea::InstCmds::readAttribute
                RequiresStateModel  false
            } {
                Name                assignAttribute
                Command             ::rosea::InstCmds::assignAttribute
                RequiresStateModel  false
            } {
                Name                delete
                Command             ::rosea::InstCmds::delete
                RequiresStateModel  false
            } {
                Name                signal
                Command             ::rosea::InstCmds::signal
                RequiresStateModel  true
            } {
                Name                delaysignal
                Command             ::rosea::InstCmds::delaysignal
                RequiresStateModel  true
            } {
                Name                canceldelayed
                Command             ::rosea::InstCmds::canceldelayed
                RequiresStateModel  true
            } {
                Name                delayremaining
                Command             ::rosea::InstCmds::delayremaining
                RequiresStateModel  true
            } {
                Name                instop
                Command             ::rosea::InstCmds::instop
                RequiresStateModel  false
            } {
                Name                deRef
                Command             ::rosea::InstCmds::deRef
                RequiresStateModel  false
            } {
                Name                isEmptyRef
                Command             ::rosea::InstCmds::isEmptyRef
                RequiresStateModel  false
            } {
                Name                isNotEmptyRef
                Command             ::rosea::InstCmds::isNotEmptyRef
                RequiresStateModel  false
            } {
                Name                refMultiplicity
                Command             ::rosea::InstCmds::refMultiplicity
                RequiresStateModel  false
            } {
                Name                isRefSingular
                Command             ::rosea::InstCmds::isRefSingular
                RequiresStateModel  false
            } {
                Name                limitRef
                Command             ::rosea::InstCmds::limitRef
                RequiresStateModel  false
            } {
                Name                isRefEqual
                Command             ::rosea::InstCmds::isRefEqual
                RequiresStateModel  false
            } {
                Name                forAllRefs
                Command             ::rosea::InstCmds::forAllRefs
                RequiresStateModel  false
            }
        
            relvar insert SuppliedInstanceOperation {
                Name    findRelated
            } {
                Name    findUnrelated
            } {
                Name    findRelatedWhere
            } {
                Name    findUnrelatedWhere
            } {
                Name    updateAttribute
            } {
                Name    withAttribute
            } {
                Name    readAttribute
            } {
                Name    assignAttribute
            } {
                Name    delete
            } {
                Name    signal
            } {
                Name    delaysignal
            } {
                Name    canceldelayed
            } {
                Name    delayremaining
            } {
                Name    instop
            } {
                Name    deRef
            } {
                Name    isEmptyRef
            } {
                Name    isNotEmptyRef
            } {
                Name    refMultiplicity
            } {
                Name    isRefSingular
            } {
                Name    limitRef
            } {
                Name    isRefEqual
            } {
                Name    forAllRefs
            }
        }
        relvar create Association {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create Generalization {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R30 Relationship {Domain Name}\
            Association {Domain Name}\
            Generalization {Domain Name}
        relvar create SimpleAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create ClassBasedAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R31 Association {Domain Name}\
            SimpleAssociation {Domain Name}\
            ClassBasedAssociation {Domain Name}
        relvar create SimpleReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R32\
            SimpleReferringClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SimpleReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
        } {Domain Class Relationship Role}
        relvar association R33\
            SimpleReferencedClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SourceClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R34\
            SourceClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create TargetClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R35\
            TargetClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create AssociatorClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R42\
            AssociatorClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create Superclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R36\
            Superclass {Domain Relationship} 1\
            Generalization {Domain Name} 1
        relvar create Subclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R37\
            Subclass {Domain Relationship} +\
            Generalization {Domain Name} 1
        relvar create ReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R38 ReferringClass {Domain Class Relationship Role}\
            SimpleReferringClass {Domain Class Relationship Role}\
            AssociatorClass {Domain Class Relationship Role}\
            Subclass {Domain Class Relationship Role}
        relvar create ReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R39 ReferencedClass {Domain Class Relationship Role}\
            SimpleReferencedClass {Domain Class Relationship Role}\
            SourceClass {Domain Class Relationship Role}\
            TargetClass {Domain Class Relationship Role}\
            Superclass {Domain Class Relationship Role}
        relvar create ClassRole {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R40 ClassRole {Domain Class Relationship Role}\
            ReferringClass {Domain Class Relationship Role}\
            ReferencedClass {Domain Class Relationship Role}
        relvar correlation R41 ClassRole\
            {Domain Relationship} + Relationship {Domain Name}\
            {Domain Class} * Class {Domain Name}
        relvar correlation R11 ReferencedIdAttribute\
            {Domain Class Relationship Role} +\
                ReferencedClass {Domain Class Relationship Role}\
            {Domain Class Attribute Number} *\
                IdentifyingAttribute {Domain Class Attribute Number}
        relvar correlation R12 AttributeReference\
            {Domain ReferringClass Relationship ReferringRole} +\
                ReferringClass {Domain Class Relationship Role}\
            {Domain ReferencedClass Relationship ReferencedRole ReferencedAttribute\
                    ReferencedIdNumber} +\
                ReferencedIdAttribute {Domain Class Relationship Role Attribute Number}
        relvar create Config_AssocSpec {
            Spec                string
            NeedsAssociator     boolean
            ReflexiveAllowed    boolean
            ReferringCond       boolean
            ReferringMult       boolean
            ReferencedCond      boolean
            ReferencedMult      boolean
        } Spec
        
        relvar insert Config_AssocSpec {
            Spec 1--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..*--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 1..*--0..1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 0..*--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 0..*--1..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 1..*--0..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec 0..*--0..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec ?--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec ?--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec +--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec *--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec +--? NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec *--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec +--+ NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec *--+ NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec +--* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec *--* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        }
        relvar create Config_ClassAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_NonReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            TargetClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexivePath {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            SourceAttr          string
            TargetAttr          string
        } {Domain Relationship AssocClass SourceClass SourceAttr}
        relvar partition Config1\
            Config_ClassAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_NonReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_ReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}
        relvar association Config2\
            Config_ReflexivePath {Domain Relationship AssocClass SourceClass} +\
            Config_ReflexiveAssoc {Domain Relationship AssocClass SourceClass} 1
        pipe {
            relvar set ::rosea::Config::AttributeReference |
            relation project ~ Domain ReferencedClass Relationship ReferencedRole\
                    ReferencedAttribute ReferencedIdNumber |
            relation rename ~ ReferencedClass Class ReferencedRole Role\
                    ReferencedAttribute Attribute ReferencedIdNumber Number |
            relvar union ::rosea::Config::ReferencedIdAttribute
        } refIdQuery
        relvar create StateModel {
            Domain          string
            Model           string
            InitialState    string
            DefaultTrans    string
        } {Domain Model}
        
        relvar create InstanceStateModel {
            Domain          string
            Class           string
        } {Domain Class}
        
        relvar association R51\
            InstanceStateModel {Domain Class} ?\
            Class {Domain Name} 1
        
        relvar create AssignerStateModel {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar association R52\
            AssignerStateModel {Domain Relationship} ?\
            Association {Domain Name} 1
        
        relvar partition R50 StateModel {Domain Model}\
            InstanceStateModel {Domain Class}\
            AssignerStateModel {Domain Relationship}
        
        relvar create SingleAssigner {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar create MultipleAssigner {
            Domain          string
            Relationship    string
            Class           string
            Number          int
        } {Domain Relationship}
        
        relvar partition R53 AssignerStateModel {Domain Relationship}\
            SingleAssigner {Domain Relationship}\
            MultipleAssigner {Domain Relationship}
        
        relvar association R54\
            MultipleAssigner {Domain Class Number} ?\
            Identifier {Domain Class Number} 1
        
        relvar create State {
            Domain          string
            Model           string
            Name            string
            Parameters      string
            Action          string
            IsFinal         boolean
        } {Domain Model Name}
        
        relvar association R55\
            State {Domain Model} +\
            StateModel {Domain Model} 1
        
        relvar association R58\
            StateModel {Domain Model InitialState} ?\
            State {Domain Model Name} 1
        
        relvar create TransitionRule {
            Name    string
        } Name
        
        relvar insert TransitionRule {Name IG} {Name CH}
        
        relvar association R59\
            StateModel DefaultTrans *\
            TransitionRule Name 1
        
        relvar create CreationState {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar create StatePlace {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar partition R57 StatePlace {Domain Model Name}\
            State {Domain Model Name}\
            CreationState {Domain Model Name}
        relvar create Event {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create DeferredEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create EffectiveEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R80 Event {Domain Model Event}\
            DeferredEvent {Domain Model Event}\
            EffectiveEvent {Domain Model Event}
        
        relvar create DeferralPath {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event Relationship Role}
        
        relvar correlation R86 DeferralPath\
            {Domain Model Event} + DeferredEvent {Domain Model Event}\
            {Domain Model Relationship Role} * Superclass\
                {Domain Class Relationship Role}
        
        relvar create PolymorphicEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create InheritedEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R81 DeferredEvent {Domain Model Event}\
            PolymorphicEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar create MappedEvent {
            Domain      string
            Model       string
            Event       string
            ParentModel string
        } {Domain Model Event}
        
        relvar association R84\
            MappedEvent {Domain ParentModel Event} *\
            DeferredEvent {Domain Model Event} 1
        
        relvar create LocalEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R82 EffectiveEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            LocalEvent {Domain Model Event}
        
        relvar create NonLocalEvent {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event}
        
        relvar partition R83 NonLocalEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar association R85\
            NonLocalEvent {Domain Model Relationship Role} *\
            Subclass {Domain Class Relationship Role} 1
        
        relvar association R87\
            EffectiveEvent {Domain Model} +\
            StateModel {Domain Model} 1
        relvar create TransitionPlace {
            Domain  string
            Model   string
            State   string
            Event   string
        } {Domain Model State Event}
        
        relvar correlation R70 TransitionPlace\
            {Domain Model State} * StatePlace {Domain Model Name}\
            {Domain Model Event} * EffectiveEvent {Domain Model Event}
        
        relvar create StateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            NewState    string
        } {Domain Model State Event}
        
        relvar create NonStateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            TransRule   string
        } {Domain Model State Event}
        
        relvar partition R71 TransitionPlace {Domain Model State Event}\
            StateTransition {Domain Model State Event}\
            NonStateTransition {Domain Model State Event}
        
        relvar association R72\
            StateTransition {Domain Model NewState} *\
            State {Domain Model Name} 1
        
        relvar association R73\
            NonStateTransition TransRule *\
            TransitionRule Name 1
        relvar create Config_DataError {
            Relationship        string
            RefClass            string
            RefType             string
            Format              string
        } {Relationship RefClass RefType}
        relvar insert Config_DataError {
            Relationship        R3
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no attributes}
        } {
            Relationship        R4
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no identifiers}
        } {
            Relationship        R11
            RefClass            ReferencedClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", for relationship,\
                                \"$Relationship\", no class has defined a reference\
                                to class, \"$Class\"}
        } {
            Relationship        R11
            RefClass            ReferencedIdAttribute
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references attribute,\
                                \"$Attribute\", in class, \"$Class\", which is\
                                not an identifying attribute, does not exist\
                                or \"$Relationship\" does not exist}
        } {
            Relationship        R12
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                refers to, \"$ReferencedAttribute\", in class,\
                                \"$ReferencedClass\", but the class, attribute or\
                                relationship does not exist}
        } {
            Relationship        R12
            RefClass            ReferringClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", in class, \"$Class\",\
                                makes a reference along relationship,\
                                \"$Relationship\", but $Class does not pariticipate\
                                in $Relationship}
        } {
            Relationship        R13
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                does not exist, but is used as a referential attribute}
        } {
            Relationship        R41
            RefClass            ClassRole
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references class, \"$Class\",\
                                which does not exist}
        } {
            Relationship        R52
            RefClass            AssignerStateModel
            RefType             refnone
            Format              {in domain, \"$Domain\", an assigner state model is\
                                defined on relationship, \"$Relationship\", which is\
                                not an association type relationship}
        } {
            Relationship        R70
            RefClass            TransitionPlace
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains a transition for event,\
                                \"$Event\", but $Event was a polymorphic event\
                                consumed by a superclass of $Model}
        } {
            Relationship        R72
            RefClass            StateTransition
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains the transition,\
                                \"$State - $Event -> $NewState\",\
                                but state \"$NewState\" does not exist}
        } {
            Relationship        R81
            RefClass            DeferredEvent
            RefType             multrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is both an inherited\
                                polymorphic event and a locally defined one}
        } {
            Relationship        R86
            RefClass            DeferredEvent
            RefType             notrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is defined as\
                                polymorphic but \"$Model\" is not a superclass\
                                of a generalization}
        } {
            Relationship        R87
            RefClass            EffectiveEvent
            RefType             refnone
            Format              {in domain, \"$Domain\", event, \"$Event\" has been\
                                inherited, but no state model exists for, \"$Model\"}
        }
        namespace export ConfigEvaluate
        
        proc ConfigEvaluate {ns body} {
            variable evalLambda
            tailcall ::apply [concat $evalLambda [list $ns]] $body ; # <1>
        }
        proc domain {name body} {
            namespace upvar DomainDef DomainName DomainName ; # <1>
            set DomainName $name
        
            relvar insert ::rosea::Config::Domain [list Name $name Location {}]
            try {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME domain
                }
        
                relvar eval { # <2>
                    ConfigEvaluate [namespace current]::DomainDef $body
        
                    # At this point we have the definition of the domain and enough
                    # information to tie together the referential attributes and
                    # the association definitions.
                    variable Config_NonReflexiveAssoc
                    
                    relation foreach nra $Config_NonReflexiveAssoc {
                        relation assign $nra
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferencedClass] eq $SourceClass
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable Config_ReflexivePath
                    
                    relation foreach rp $Config_ReflexivePath {
                        relation assign $rp
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferringAttribute] eq $SourceAttr
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable refIdQuery
                    
                    eval $refIdQuery
        
                    # We must also compute how polymorphic events are inherited
                    # down generalization hierarchies.
                    # Create Deferral Path instances
                    
                    variable PolymorphicEvent
                    variable DeferredEvent
                    variable Superclass
                    variable Subclass
                    variable DeferralPath
                    
                    set dpaths [pipe {
                        relation restrictwith $PolymorphicEvent {$Domain eq $name} |
                        relation semijoin ~ $DeferredEvent |
                        relation join ~ $Superclass -using {Domain Domain Model Class}
                    }]
                    relvar insert ::rosea::Config::DeferralPath {*}[relation body $dpaths]
                    set supers [relation semiminus $Subclass $Superclass\
                        -using {Domain Domain Class Class}]
                    
                    relation foreach super $supers {
                        PropagatePolyEvents $super
                    }
                }
            } on error {result} {
                # puts $::errorInfo
                ::rosea::Config::HandleConfigError $result
            }
        }
        proc HandleConfigError {result} {
            set lines [split [string trimright $result] \n]
            set nlines [llength $lines]
            set lineno 0
            upvar #0 ::rosea::Config::errcount errcount
            while {$lineno < $nlines} {
                set line [lindex $lines $lineno]
                incr lineno
                if {[regexp {^for[^:]+([^(]+)\(.+\), in relvar (.+)$} $line\
                        match rnum refclass]} {
                    set rnum [namespace tail $rnum]
                    set refclass [namespace tail $refclass]
                
                    # Now iterate over the "tuple" lines that follow the constraint message.
                    while {$lineno < $nlines} {
                        set tupline [lindex $lines $lineno]
                        if {[regexp {^tuple {(.+)} (.+)$} $tupline match tuple phrase]} {
                            incr lineno
                            incr errcount
                            if {[string match {is not referenced*} $phrase]} {
                                set reftype notrefed
                            } elseif {[string match {references no*} $phrase]} {
                                set reftype refnone
                            } elseif {[string match {*to by multiple*} $phrase]} {
                                set reftype multrefed
                            } elseif {[string match {is not referred to*} $phrase]} {
                                set reftype notrefto
                            } else {
                                log::error "unknown constraint phrasing, \"$phrase\""
                                continue
                            }
                            set cde [relvar restrictone Config_DataError Relationship $rnum RefClass\
                                    $refclass RefType $reftype]
                            if {[relation isnotempty $cde]} {
                                dict with tuple {
                                    log::error [subst -nocommands [relation extract $cde Format]]
                                }
                            } else {
                                log::error "$line\n$tupline"
                            }
                        } else {
                            break
                        }
                    }
                } else {
                    log::error "unknown configuration error, \"$result\""
                }
            }
        
            return
        }
        namespace eval DomainDef {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace import ::rosea::Config::ConfigEvaluate
            namespace import ::rosea::Helpers::DeclError
            proc class {name body} {
                namespace upvar [namespace current] DomainName DomainName ; # <1>
                namespace upvar ClassDef ClassName ClassName
                set ClassName $name
            
                if {![regexp {\A[[:alnum:]].*} $name]} {
                    tailcall DeclError BAD_CLASS_NAME $name
                }
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                } ; # <2>
                relvar insert ::rosea::Config::Class [list\
                    Domain  $DomainName\
                    Name    $name\
                ]
                set instops [pipe {
                    relvar set ::rosea::Config::SuppliedInstanceOperation |
                    relation extend ~ ioptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemInstanceOperation $instops
                relvar union ::rosea::Config::InstanceOperation $instops
                relvar union ::rosea::Config::Operation $instops
                set classops [pipe {
                    relvar set ::rosea::Config::SuppliedClassOperation |
                    relation extend ~ coptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemClassOperation $classops
                relvar union ::rosea::Config::ClassOperation $classops
                relvar union ::rosea::Config::Operation $classops
            
                ConfigEvaluate [namespace current]::ClassDef $body
            }
            proc association {name source spec target args} {
                if {[llength $args] % 2 != 0} {
                    tailcall DeclError ARG_FORMAT $args
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME association
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                # Obtain references to the domain and class context.
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
            
                set associator {}
                set path {}
                
                foreach {option value} $args {
                    switch -exact -- $option {
                        -associator {
                            set associator $value
                        }
                        -path {
                            set path $value
                            if {[llength $path] % 2 != 0} {
                                tailcall DeclError ARG_FORMAT $path
                            }
                        }
                        default {
                            tailcall DeclError UNKNOWN_OPTION association $option
                        }
                    }
                }
                set cas [relvar restrictone ::rosea::Config::Config_AssocSpec Spec $spec]
                if {[relation isempty $cas]} {
                    tailcall DeclError BAD_RELATIONSHIP_SPEC $spec
                }
                set needsassoc [relation extract $cas NeedsAssociator]
                if {$needsassoc && $associator eq {}} {
                    tailcall DeclError NEED_ASSOCIATOR $spec
                }
                if {$source eq $target} {
                    if {![relation extract $cas ReflexiveAllowed]} {
                        tailcall DeclError REFLEXIVE_NOT_ALLOWED $spec
                    }
                    if {$needsassoc && $path eq {}} {
                        tailcall DeclError NEED_REFLEXIVE_PATH $name $source $spec $target
                    }
                }
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                # Many relvars have tuples with the same heading, so we construct it
                # once here.
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
            
                # Populate the data for a Relationship and Association since that
                # is what this command defines.
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Association $reltuple
            
                # Populate the type of association we are dealing with.
                if {$associator eq {}} {
                    relvar insert ::rosea::Config::SimpleAssociation $reltuple
                    relvar insert ::rosea::Config::SimpleReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::SimpleReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                } else {
                    relvar insert ::rosea::Config::Config_ClassAssoc [list\
                        Domain              $DomainName\
                        Relationship        $name\
                        AssocClass          $associator\
                        SourceClass         $source\
                    ]
                    if {[llength $path] == 0} {
                        relvar insert ::rosea::Config::Config_NonReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                            TargetClass         $target\
                        ]
                    } else {
                        relvar insert ::rosea::Config::Config_ReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                        ]
                        foreach {sourceattr targetattr} $path {
                            relvar insert ::rosea::Config::Config_ReflexivePath [list\
                                Domain              $DomainName\
                                Relationship        $name\
                                AssocClass          $associator\
                                SourceClass         $source\
                                SourceAttr          $sourceattr\
                                TargetAttr          $targetattr\
                            ]
                        }
                    }
                    
                    relvar insert ::rosea::Config::ClassBasedAssociation $reltuple
                    relvar insert ::rosea::Config::SourceClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::TargetClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                        Multiplicity    [relation extract $cas ReferencedMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::AssociatorClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                }
            }
            proc generalization {name super args} {
                if {[llength $args] < 2} {
                    tailcall DeclError TOO_FEW_SUBCLASSES [llength $args]
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME generalization
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Generalization $reltuple
            
                set supertuple [list\
                    Domain          $DomainName\
                    Class           $super\
                    Relationship    $name\
                    Role            target\
                ]
                relvar insert ::rosea::Config::Superclass $supertuple
                relvar insert ::rosea::Config::ReferencedClass $supertuple
                relvar insert ::rosea::Config::ClassRole $supertuple
            
                set subtuple [dict create\
                    Domain          $DomainName\
                    Relationship    $name\
                    Role            source\
                ]
                foreach sub $args {
                    dict set subtuple Class $sub
                    relvar insert ::rosea::Config::Subclass $subtuple
                    relvar insert ::rosea::Config::ReferringClass $subtuple
                    relvar insert ::rosea::Config::ClassRole $subtuple
                }
            }
            proc assigner {rname body} {
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar AssignerDef\
                    RelationshipName RelationshipName\
                    multiClass multiClass\
                    multiIdNum multiIdNum\
                    InitialState InitialState\
                    DefaultTrans DefaultTrans
            
                set RelationshipName $rname
                set multiClass {}
                set multiIdNum 1
                set InitialState {}
                set DefaultTrans {}
            
                try {
                    ConfigEvaluate [namespace current]::AssignerDef $body
            
                    if {$DefaultTrans eq {}} {
                        set DefaultTrans CH
                    }
                    relvar insert ::rosea::Config::StateModel [list\
                        Domain          $DomainName\
                        Model           $rname\
                        InitialState    $InitialState\
                        DefaultTrans    $DefaultTrans\
                    ]
                    set assigntuple [list\
                        Domain          $DomainName\
                        Relationship    $rname\
                    ]
                    relvar insert ::rosea::Config::AssignerStateModel $assigntuple
                    if {$multiClass eq {}} {
                        relvar insert ::rosea::Config::SingleAssigner $assigntuple
                    } else {
                        lappend assigntuple Class $multiClass Number $multiIdNum
                        relvar insert ::rosea::Config::MultipleAssigner $assigntuple
                    }
                } on error {result opts} {
                    log::error $result
                    upvar #0 ::rosea::Config::errcount errcount
                    incr errcount
                }
            }
            proc operation {name params body} {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME operation
                }
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain      $DomainName\
                        Element     $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
                relvar insert ::rosea::Config::DomainOperation [list\
                    Domain      $DomainName\
                    Name        $name\
                    Parameters  $params\
                    Body        $body\
                ]
            }
        
            namespace eval ClassDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc attribute {name type args} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME attribute
                    }
                    if {[string range $name 0 1] eq "__"} {
                        tailcall DeclError RESERVED_NAME $name
                    }
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    relvar insert ::rosea::Config::Attribute [list\
                        Domain  $DomainName\
                        Class   $ClassName\
                        Name    $name\
                        Type    $type\
                    ]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -default {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::UserSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Value       $value\
                                ]
                            }
                            -system {
                                if {$type ne "int"} {
                                    tailcall DeclError INT_TYPE_REQUIRED $type
                                }
                                if {![string is integer -strict $value]} {
                                    tailcall DeclError INT_VALUE_REQUIRED $value
                                }
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::SystemSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    StartValue  $value\
                                ]
                            }
                            -generate {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::GeneratedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Cmd         $value\
                                ]
                            }
                            -id {
                                relvar uinsert ::rosea::Config::Identifier [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Number      $value\
                                ] ; # <1>
                                relvar insert ::rosea::Config::IdentifyingAttribute [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Number      $value\
                                ]
                            }
                            -check {
                                relvar insert ::rosea::Config::ValueCheck [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Expression  $value\
                                ]
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION attribute $option
                            }
                        }
                    }
                }
                proc reference {relname rclass args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set refnum 1
                    set linkopts [list]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -refid {
                                set refnum $value
                            }
                            -link {
                                if {[llength $value] < 1 || [llength $value] > 2} {
                                    tailcall DeclError ARG_FORMAT $value
                                }
                                lappend linkopts $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION reference $option
                            }
                        }
                    }
                
                    # We defer processing the link options until the end so as not
                    # to impose an order on the -refid option.
                    foreach linkopt $linkopts {
                        lassign $linkopt referring referenced
                        if {$referenced eq {}} {
                            set referenced $referring
                        }
                        relvar insert ::rosea::Config::AttributeReference [list\
                            Domain              $DomainName\
                            ReferringClass      $ClassName\
                            ReferringAttribute  $referring\
                            ReferringRole       source\
                            ReferencedClass     $rclass\
                            ReferencedAttribute $referenced\
                            ReferencedRole      target\
                            ReferencedIdNumber  $refnum\
                            Relationship        $relname
                        ] ; # <1>
                    }
                }
                proc classop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "class operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::ClassOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserClassOperation $optuple
                }
                proc instop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "instance operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::InstanceOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserInstanceOperation $optuple
                }
                proc statemodel {body} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    variable ClassName
                
                    namespace upvar StateModelDef\
                        InitialState InitialState\
                        DefaultTrans DefaultTrans\
                        Terminals Terminals
                
                    set InitialState {}
                    set DefaultTrans {}
                    set Terminals [list]
                
                    try {
                        ConfigEvaluate [namespace current]::StateModelDef $body
                
                        if {$DefaultTrans eq {}} {
                            set DefaultTrans CH
                        }
                        relvar insert ::rosea::Config::StateModel [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            InitialState    $InitialState\
                            DefaultTrans    $DefaultTrans\
                        ]
                        relvar insert ::rosea::Config::InstanceStateModel [list\
                            Domain          $DomainName\
                            Class           $ClassName\
                        ]
                
                        foreach terminal $Terminals {
                            relvar updateone ::rosea::Config::State stup [list\
                                    Domain $DomainName Model $ClassName Name $terminal] {
                                tuple update $stup IsFinal true
                            }
                        }
                    } on error {result opts} {
                        log::error $result
                        upvar #0 ::rosea::Config::errcount errcount
                        incr errcount
                    }
                }
                proc polymorphic {args} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    foreach polyevent $args {
                        set eventtuple [list\
                            Domain $DomainName\
                            Model $ClassName\
                            Event $polyevent\
                        ]
                        relvar insert ::rosea::Config::PolymorphicEvent $eventtuple
                        relvar insert ::rosea::Config::DeferredEvent $eventtuple
                        relvar insert ::rosea::Config::Event $eventtuple
                    }
                    return
                }
            
                namespace eval StateModelDef {
                    logger::initNamespace [namespace current]
                
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                    namespace import ::ral::relvar
                    namespace import ::rosea::Config::ConfigEvaluate
                    namespace import ::rosea::Helpers::DeclError
                
                    proc state {name params body} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME state
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name state
                        }
                    
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        variable InitialState
                    
                        if {$InitialState eq {}} {
                            set InitialState $name
                        }
                    
                        relvar insert ::rosea::Config::State [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                            Parameters      $params\
                            Action          $body\
                            IsFinal         false\
                        ]
                        relvar insert ::rosea::Config::StatePlace [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                        ]
                        return
                    }
                    proc transition {source - event -> target} {
                        if {$event eq {}} {
                            tailcall DeclError EMPTY_NAME event
                        }
                        if {$source in {CH IG}} {
                            tailcall DeclError PSEUDO_STATE $source "transition source state"
                        }
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        if {$source eq "@"} {
                            if {$target in {CH IG}} {
                                tailcall DeclError BAD_CREATION_TARGET $target
                            }
                            set cstuple [list\
                                Domain          $DomainName\
                                Model           $ClassName\
                                Name            @\
                            ]
                            relvar uinsert ::rosea::Config::CreationState $cstuple
                            relvar uinsert ::rosea::Config::StatePlace $cstuple
                        }
                    
                        set eventtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            Event   $event\
                        ]
                        relvar uinsert ::rosea::Config::Event $eventtuple ; # <1>
                        relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                        relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                    
                        set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                            Name $target]
                        set transtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            State   $source\
                            Event   $event\
                        ]
                        relvar insert ::rosea::Config::TransitionPlace $transtuple
                    
                        if {[relation isnotempty $tranrule]} {
                            lappend transtuple TransRule $target
                            set tpsubtype NonStateTransition
                        } else {
                            lappend transtuple NewState $target
                            set tpsubtype StateTransition
                        }
                        relvar insert ::rosea::Config::$tpsubtype $transtuple
                        return
                    }
                    proc initialstate {name} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME initialstate
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name initialstate
                        }
                        variable InitialState $name
                        return
                    }
                    proc defaulttrans {name} {
                        if {$name ni {CH IG}} {
                            tailcall DeclError EXPECTED_PSEUDO_STATE $name
                        }
                        variable DefaultTrans $name
                        return
                    }
                    proc terminal {args} {
                        variable Terminals
                        ::struct::set add Terminals $args
                        return
                    }
                }
            }
            namespace eval AssignerDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc state {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME state
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name state
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    variable InitialState
                
                    if {$InitialState eq {}} {
                        set InitialState $name
                    }
                
                    relvar insert ::rosea::Config::State [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                        Parameters      $params\
                        Action          $body\
                        IsFinal         false\
                    ]
                    relvar insert ::rosea::Config::StatePlace [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                    ]
                    return
                }
                proc transition {source - event -> target} {
                    if {$event eq {}} {
                        tailcall DeclError EMPTY_NAME event
                    }
                    if {$source in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name "transition source state"
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    set eventtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        Event   $event\
                    ]
                    relvar uinsert ::rosea::Config::Event $eventtuple
                    relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                    relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                
                    set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                        Name $target]
                    set transtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        State   $source\
                        Event   $event\
                    ]
                    relvar insert ::rosea::Config::TransitionPlace $transtuple
                
                    if {[relation isnotempty $tranrule]} {
                        lappend transtuple TransRule $target
                        set tpsubtype NonStateTransition
                    } else {
                        lappend transtuple NewState $target
                        set tpsubtype StateTransition
                    }
                    relvar insert ::rosea::Config::$tpsubtype $transtuple
                    return
                }
                proc initialstate {name} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME initialstate
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name initialstate
                    }
                    variable InitialState $name
                    return
                }
                proc defaulttrans {name} {
                    if {$name ni {CH IG}} {
                        tailcall DeclError EXPECTED_PSEUDO_STATE $name
                    }
                    variable DefaultTrans $name
                    return
                }
                proc identifyby {name args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    variable multiClass $name
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -id {
                                variable multiIdNum $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION identifyby $option
                            }
                        }
                    }
                
                    return
                }
            }
        }
    }
    namespace eval Populate {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Config::ConfigEvaluate
        namespace import ::rosea::Helpers::DeclError
        proc domain {name body} {
            set domain [relvar restrictone ::rosea::Config::Domain Name $name]
            if {[relation isempty $domain]} {
                tailcall DeclError UNKNOWN_DOMAIN $domain
            }
        
            namespace upvar DomainPop DomainName DomainName DomainLoc DomainLoc
            relation assign $domain {Name DomainName} {Location DomainLoc}
        
            try {
                relvar eval {
                    ConfigEvaluate [namespace current]::DomainPop $body
                }
            } on error {result opts} {
                log::error $result
                upvar #0 ::rosea::Config::errcount errcount
                incr errcount
            }
        }
        namespace eval DomainPop {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace path ::rosea::Helpers
            proc class {class heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                set body [list]
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.
                    set tuple [list]
                    foreach attr $heading value $values {
                        # Check if we are skipping a value to use a default.  We must also
                        # allow some way to specify the value as "-".
                        if {$value eq "-"} {
                            continue
                        } elseif {$value eq "\\-"} {
                            set value -
                        }
                        lappend tuple $attr $value
                    }
                    # Accumulate the tuples as a list to form the body that will be
                    # inserted into the relvar.
                    lappend body $tuple
                }
            
                # Insert the body into the relvar.
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::$class
                set insts [relvar insert $relvar {*}$body]
            
                # Now we have to deal with any state model that might be present.  We have
                # to set up the initial state properly if such a thing exists for this
                # class.
                set idattrs [lindex [relvar identifiers $relvar] 0]
                relation foreach inst $insts {
                    CreateInInitialState $domns $class [pipe {
                        relation project $inst {*}$idattrs |
                        relation tuple ~ |
                        tuple get ~
                    }]
                }
            
                return [relation body $insts]
            }
            proc assigner {rname heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::${rname}__STATEINST
                set idattrs [lindex [relvar identifiers $relvar] 0]
                if {![struct::set equal $heading $idattrs]} {
                    tailcall DeclError NO_IDENTIFIER $heading $idattrs
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.  We assume
                    # the values are in the same order as the heading -- that is the point.
                    set tuple [list]
                    foreach attr $heading value $values {
                        lappend tuple $attr $value
                    }
                    CreateInInitialState $domns $rname $tuple
                }
            
                return
            }
        }
    }
    namespace eval Info {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Helpers::DeclError
        proc domain {arglist} {
            set arglist [lassign $arglist subcmd domainname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            switch -exact -- $subcmd {
                classes {
                    return [pipe {
                        relvar set ::rosea::Config::Class |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                relationships {
                    return [pipe {
                        relvar set ::rosea::Config::Relationship |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                operations {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::DomainOperation |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc FormatOpsInfo {ops} {
            set result [list]
            relation foreach op $ops {
                relation assign $op
                lappend result $Name $Parameters $Body
            }
            return $result
        }
        proc class {arglist} {
            set arglist [lassign $arglist subcmd domainname classname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                attributes {
                    return [pipe {
                        relvar set ::rosea::Config::Attribute |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation dict ~ Name Type
                    }]
                }
                classops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserClassOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                instops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserInstanceOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc statemodel {arglist} {
            set arglist [lassign $arglist subcmd domainname classname statename]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
            set domns [string cat [relation extract $dominst Location] :: $domainname]
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                states {
                    set states [pipe {
                        relvar set ::rosea::Config::State |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation project ~ Name Parameters Action
                    }]
                    set result [list]
                    relation foreach state $states {
                        relation assign $state
                        lappend result $Name $Parameters $Action
                    }
                    return $result
                }
                events {
                    return [pipe {
                        relvar set ::rosea::Config::EffectiveEvent |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation list ~ Event
                    }]
                }
                transitions {
                    return [pipe {
                        relvar set ${domns}::__Arch_Transition |
                        relation restrictwith ~ {$Class eq $classname} |
                        relation eliminate ~ Class |
                        relation group ~ Transition Event NewState |
                        relation extend ~ trtup TranCol dict {
                            [relation dict [tuple extract $trtup Transition] Event NewState]} |
                        relation dict ~ State TranCol
                    }] ; # <1>
                }
                activityproc {
                    return ${domns}::${classname}::__Activity::${statename}
                }
            }
        }
    }
    namespace eval Trace {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        relvar create Trace {
            Trace_Id    int
            Timestamp   bignum
            Source      list
            Event       string
            Target      list
            Params      list
        } Trace_Id
        
        relvar create Creation {
            Trace_Id    int
        } Trace_Id
        
        relvar create Polymorphic {
            Trace_Id    int
            SubInst     string
            Linkage     string
        } Trace_Id
        
        relvar create Transition {
            Trace_Id    int
            CurrState   string
            NewState    string
        } Trace_Id
        
        relvar partition R1 Trace Trace_Id\
            Creation Trace_Id\
            Polymorphic Trace_Id\
            Transition Trace_Id
        variable targetCmpFunc [lambda {instrefs target} {
            lassign $target trelvar tinst
            foreach instref $instrefs {
                lassign $instref crelvar cinst
                if {$trelvar eq $crelvar && [ral relation is $tinst subsetof $cinst]} {
                    return true
                }
            }
            return false
        }]
        variable traceState off
        variable traceNumber 0
        variable traceLogState off
        variable traceLogLevel info
        variable traceLogCmd [::logger::init rosea]
        proc QueryClassTraces {classes} {
            variable Trace
            return [relation restrictwith $Trace {
                [lindex $Target 0] in $classes ||\
                    [namespace tail [lindex $Target 0]] in $classes
            }] ; # <1>
        }
        proc QueryTargetTraces {targets} {
            variable Trace
            variable targetCmpFunc
            return [relation restrictwith $Trace {[{*}$targetCmpFunc $targets $Target]}]
        }
        proc TraceCreation {source event target params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Creation [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TracePolymorphic {source event target sub link params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Polymorphic [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        SubInst     $sub\
                        Linkage     $link\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TraceTransition {source event target curr new params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Transition [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        CurrState   $curr\
                        NewState    $new\
                    ]
                }
                LogTrace $trace
            }
        }
        proc NewTrace {src event target params} {
            variable traceNumber
            return [relvar insert Trace [list\
                Trace_Id    [incr traceNumber]\
                Timestamp   [clock microseconds]\
                Source      $src\
                Event       $event\
                Target      $target\
                Params      $params\
            ]]
        }
        proc LogTrace {trace} {
            variable traceLogState
            if {$traceLogState} {
                set rec [FormatTraceRec [lindex [TracesToRecords $trace] 0]] ; # <1>
        
                variable traceLogCmd
                variable traceLogLevel
                ${traceLogCmd}::${traceLogLevel} $rec
            }
        }
        proc TracesToRecords {traces} {
            foreach rvname {Creation Polymorphic Transition} { # <1>
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            set result [list]
            relation foreach trace $traces -ascending Trace_Id { # <2>
                relation assign $trace
                set labeled [dict create\
                    id      $Trace_Id\
                    time    $Timestamp\
                    source  $Source\
                    event   $Event\
                    target  $Target\
                    params  $Params\
                    class   [lindex $Target 0]\
                ] ; # <3>
                if {[relation isnotempty $Transition]} { # <4>
                    relation assign $Transition
                    dict set labeled type transition
                    dict set labeled current $CurrState
                    dict set labeled new $NewState
                } elseif {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic
                    dict set labeled type polymorphic
                    dict set labeled sub $SubInst
                    dict set labeled link $Linkage
                } elseif {[relation isnotempty $Creation]} {
                    dict set labeled type creation
                }
        
                lappend result $labeled
            }
            return $result
        }
        proc DecodeAllTraces {} {
            variable Trace
            tailcall TracesToRecords $Trace
        }
        proc DecodeClassTraces {args} {
            return [TracesToRecords [QueryClassTraces $args]]
        }
        proc DecodeTargetTraces {args} {
            tailcall TracesToRecords [QueryTargetTraces $args]
        }
        proc FormatTraceRec {rec} {
            dict with rec {
                switch -exact -- $type {
                    transition {
                        append result\
                            "Transition: "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $current -> $new"
                    }
                    polymorphic {
                        append result\
                            "Polymorphic : "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $link -> [FormatInstRef $sub]"
                    }
                    creation {
                        append result\
                            "Creation: "\
                            "[FormatInstRef $source] - "\
                            "[FormatEvent $event $params] -> $class\
                            " ==> [FormatInstRef $target]"
                    }
                    default {
                        DeclError BAD_TRACETYPE $type
                    }
                }
            }
            return $result
        }
        proc FormatTransition {source event params target} {
            return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
                [FormatInstRef $target]"
        }
        proc FormatEvent {event params} {
            return [string cat\
                "$event"\
                [expr {[llength $params] != 0 ? " \([join $params {, }]\)" : {}}]\
            ]
        }
        proc FormatInstRef {instref} {
            lassign $instref relvar inst
            if {$relvar eq {}} {
                return {()}
            } else {
                return "$relvar \([tuple get [relation tuple $inst]]\)"
            }
        }
        proc FormatTimestamp {time} {
            set sec [clock format [expr {$time / 1000000}] -format %T] ; # <1>
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %s.%03ld.%03ld $sec $msec $usec]
        }
        proc FormatTimeAsSec {time} {
            set sec [expr {$time / 1000000}]
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %3ld.%03ld.%03ld $sec $msec $usec]
        }
        proc DiagTraces {traces args} {
            set result {}
            append result "seqdiag \{\n"
            append result "    activation = none;\n"
            foreach {option value} $args {
                append result "    $option = $value;\n"
            }
        
            foreach rvname {Creation Polymorphic Transition} {
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            relation foreach trace $traces -ascending Trace_Id {
                relation assign $trace
                if {[isEmptyRef $Source]} {
                    set Source EXTERNAL
                } else {
                    set Source [namespace tail [lindex $Source 0]]
                }
                set Target [namespace tail [lindex $Target 0]]
                set evtlabel [FormatEvent $Event $Params]
                if {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic Linkage
                    append evtlabel " <<Polymorphic $Linkage>>"
                } elseif {[relation isnotempty $Creation]} {
                    append evtlabel " <<Creation>>"
                }
                append result "    $Source ->> $Target \[label=\"$evtlabel\"\];\n"
            }
        
            append result "\}\n"
        
            return $result
        }
        proc DiagAllTraces {filename args} {
            set chan [open $filename w]
            variable Trace
            try {
                chan puts $chan [DiagTraces $Trace {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagClassTraces {filename classes args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryClassTraces $classes] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagTargetTraces {filename targets args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryTargetTraces $targets] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
    }

    namespace path ::rosea::Helpers
    namespace import ::rosea::Config::ConfigEvaluate
}

package provide rosea $::rosea::version


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Added packages/package-rosea-1.10-tcl.tm.



















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
# ACTIVESTATE TEAPOT-PKG BEGIN TM -*- tcl -*-
# -- Tcl Module

# @@ Meta Begin
# Package rosea 1.10
# Meta description Rosea is a data and execution architecture for
# Meta description translating XUML models using Tcl as the implementation
# Meta description language.
# Meta platform    tcl
# Meta require     {Tcl 8.6}
# Meta require     logger
# Meta require     ral
# Meta require     ralutil
# Meta require     struct::set
# Meta require     lambda
# Meta summary     Rosea -- XUML Software Architecture
# @@ Meta End


# ACTIVESTATE TEAPOT-PKG BEGIN REQUIREMENTS

package require Tcl 8.6
package require logger
package require ral
package require ralutil
package require struct::set
package require lambda

# ACTIVESTATE TEAPOT-PKG END REQUIREMENTS

# ACTIVESTATE TEAPOT-PKG BEGIN DECLARE

package provide rosea 1.10

# ACTIVESTATE TEAPOT-PKG END DECLARE
# ACTIVESTATE TEAPOT-PKG END TM
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2020 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors and
# need not follow the licensing terms described here, provided that the
# new terms are clearly indicated on the first page of each file where
# they apply.
# 
# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES
# THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# 
# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
# OR MODIFICATIONS.
# 
# GOVERNMENT USE: If you are acquiring this software on behalf of the
# U.S. government, the Government shall have only "Restricted Rights"
# in the software and related documentation as defined in the Federal
# Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
# are acquiring the software on behalf of the Department of Defense,
# the software shall be classified as "Commercial Computer Software"
# and the Government shall have only "Restricted Rights" as defined in
# Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the foregoing,
# the authors grant the U.S. Government and others acting in its behalf
# permission to use and distribute the software in accordance with the
# terms specified in this license.

package require Tcl 8.6

package require logger
package require ral
package require ralutil
package require struct::set
package require lambda

proc ::K {x y} {set x}

namespace eval ::rosea {
    namespace export configure
    
    namespace export configureFromChan
    
    namespace export configureFromFile
    
    namespace export generate
    
    namespace export populate
    
    namespace export populateFromChan
    
    namespace export populateFromFile
    
    namespace export save
    
    namespace export restore
    
    namespace export info
    
    namespace export tunnel
    
    namespace export trace
    
    namespace ensemble create

    variable version 1.10

    logger::initNamespace [namespace current]

    namespace import\
        ::ral::relation\
        ::ral::tuple\
        ::ral::relformat\
        ::ralutil::pipe
    namespace import ::ral::relvar
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation project ~ Name Type |
        relation dict ~ Name Type
    } headingQuery
    
    pipe {
        relation semijoin $class $Identifier -using {Domain Domain Name Class}\
                $IdentifyingAttribute |
        relation group ~ Attributes Attribute
    } idQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $UserSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } defaultValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $SystemSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } suppliedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $GeneratedValue -using {Domain Domain Class Class Name Attribute}
    } generatedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $ValueCheck -using {Domain Domain Class Class Name Attribute}
    } checkValuesQuery
    
    pipe {
        relation semijoin $class $StateModel -using {Domain Domain Name Model} |
        relation isnotempty
    } hasSMQuery
    
    pipe {
        relation semijoin $class $State -using {Domain Domain Name Model} |
        relation project ~ Name Parameters Action
    } statesQuery
    
    pipe {
        relation join $AttributeReference $refing\
            -using {Domain Domain ReferringClass Class\
            Relationship Relationship ReferringRole Role} |
        relation rename ~ Conditionality ReferringCond\
                Multiplicity ReferringMult |
        relation join ~ $refed -using {Domain Domain\
            ReferencedClass Class Relationship\
            Relationship ReferencedRole Role} |
        relation project ~ Domain Relationship\
            ReferringClass ReferringAttribute\
            ReferencedClass ReferencedAttribute\
            ReferringCond ReferringMult Conditionality |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } referencesQuery
    
    pipe {
        relation semijoin $cassocs $AssociatorClass\
                -using {Domain Domain Name Relationship}\
            $ReferringClass $AttributeReference\
                -using {Domain Domain Class ReferringClass\
                Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute ReferencedRole |
        relation join ~ $bothclass -using {Domain Domain Relationship Relationship\
                ReferencedClass Class ReferencedRole Role} |
        relation group ~ ReferringAttrs ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } assocrefsQuery
    
    pipe {
        relation semijoin $rships $Generalization\
                $Subclass -using {Domain Domain Name Relationship}\
                $ReferringClass $AttributeReference\
                    -using {Domain Domain Class ReferringClass\
                    Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } subrefsQuery
    
    proc configure {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Config $script
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc configureFromChan {chan} {
        tailcall configure [::chan read -nonewline $chan]
    }
    proc configureFromFile {filename} {
        set f [::open $filename r]
        try {
            configureFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc generate {{pattern *} {prefix {}}} {
        if {$prefix ne {}} {
            if {[string range $prefix 0 1] ne "::"} {
                set prefix [uplevel 1 {namespace current}]::$prefix
            }
            set prefix [string trimright $prefix :]
        } elseif {$prefix eq "::"} {
            set prefix {} ; # <1>
        }
        namespace upvar Config\
            Domain Domain\
            DomainElement DomainElement\
            Class Class\
            Attribute Attribute\
            DefaultValue DefaultValue\
            UserSuppliedValue UserSuppliedValue\
            SystemSuppliedValue SystemSuppliedValue\
            GeneratedValue GeneratedValue\
            ValueCheck ValueCheck\
            Identifier Identifier\
            IdentifyingAttribute IdentifyingAttribute\
            Relationship Relationship\
            Association Association\
            SimpleAssociation SimpleAssociation\
            SimpleReferringClass SimpleReferringClass\
            SimpleReferencedClass SimpleReferencedClass\
            ClassBasedAssociation ClassBasedAssociation\
            AssociatorClass AssociatorClass\
            SourceClass SourceClass\
            TargetClass TargetClass\
            Generalization Generalization\
            Superclass Superclass\
            Subclass Subclass\
            AttributeReference AttributeReference\
            ReferencedIdAttribute ReferencedIdAttribute\
            ReferringClass ReferringClass\
            ReferencedClass ReferencedClass\
            DomainOperation DomainOperation\
            SuppliedOperation SuppliedOperation\
            UserClassOperation UserClassOperation\
            SystemClassOperation SystemClassOperation\
            UserInstanceOperation UserInstanceOperation\
            SystemInstanceOperation SystemInstanceOperation\
            InstanceStateModel InstanceStateModel\
            StateModel StateModel\
            StatePlace StatePlace\
            State State\
            EffectiveEvent EffectiveEvent\
            DeferredEvent DeferredEvent\
            TransitionPlace TransitionPlace\
            StateTransition StateTransition\
            NonStateTransition NonStateTransition\
            AssignerStateModel AssignerStateModel\
            SingleAssigner SingleAssigner\
            MultipleAssigner MultipleAssigner\
            PolymorphicEvent PolymorphicEvent
    
        set genDomain [relation restrict $Domain dom {
            [string match $pattern [tuple extract $dom Name]]
        }]
        relation foreach domain $genDomain {
            set domainName [relation extract $domain Name]
            relvar updateone Config::Domain dtup [list Name $domainName] {
                tuple update $dtup Location $prefix
            }
            
            set domns ${prefix}::$domainName
            namespace eval $domns {
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                ral relvar create __Arch_RefLink {
                    Relationship    string
                    ReferringClass  string
                    ReferencedClass string
                    ReferringAttrs  {Relation
                            {ReferringAttribute string ReferencedAttribute string}}
                } Relationship
                ral relvar create __Arch_AssocRef {
                    Relationship    string
                    AssocClass      string
                    References      {Relation\
                        {Participant string Role string ReferringAttrs {Relation\
                            {ReferringAttribute string ReferencedAttribute string}}}}
                } Relationship
                ral relvar create __Arch_SuperLink {
                    Relationship    string
                    SuperClass      string
                } Relationship
                
                ral relvar create __Arch_SubLink {
                    Relationship    string
                    SubClass        string
                    ReferringAttrs  {Relation\
                        {ReferringAttribute string ReferencedAttribute string}}
                } {Relationship SubClass}
                
                ral relvar association __Arch_R5\
                    __Arch_SubLink Relationship +\
                    __Arch_SuperLink Relationship 1
                ral relvar create __Arch_Link {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar create __Arch_AssociationLink {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                    PrevSrcClass    string
                } {Name SrcClass}
                ral relvar association __Arch_R4\
                    __Arch_AssociationLink {Name PrevSrcClass} ?\
                    __Arch_AssociationLink {Name SrcClass} ?
                ral relvar create __Arch_PartitionLink {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar partition __Arch_R3 __Arch_Link {Name SrcClass}\
                    __Arch_AssociationLink {Name SrcClass}\
                    __Arch_PartitionLink {Name SrcClass}
                ral relvar create __Arch_PartitionDst {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                } {Name SrcClass DstClass}
                ral relvar association __Arch_R2\
                    __Arch_PartitionDst {Name SrcClass} +\
                    __Arch_PartitionLink {Name SrcClass} 1
                ral relvar create __Arch_State {
                    Class string
                    State string
                } {Class State}
                ral relvar create __Arch_Event {
                    Class string
                    Event string
                } {Class Event}
                ral relvar create __Arch_Transition {
                    Class string
                    State string
                    Event string
                    NewState string
                } {Class State Event}
                ral relvar correlation __Arch_R1 __Arch_Transition\
                    {Class State} + __Arch_State {Class State}\
                    {Class Event} + __Arch_Event {Class Event}
                ral relvar create __Arch_InitialState {
                    Class string
                    State string
                } Class
                ral relvar association __Arch_R6\
                    __Arch_InitialState {Class State} ?\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_TerminalState {
                    Class string
                    State string
                } {Class State}
                ral relvar association __Arch_R7\
                    __Arch_TerminalState {Class State} *\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_PolymorphicEvent {
                    Class           string
                    Event           string
                } {Class Event}
            }
            namespace eval $domns namespace path ::rosea::InstCmds
            set domops [relation semijoin $domain $DomainOperation -using {Name Domain}]
            relation foreach domop $domops {
                relation assign $domop\
                    {Name name} {Parameters parameters} {Body body}
                proc ${domns}::$name $parameters [list ::ral relvar eval $body] ; # <1>
            }
            
            namespace eval $domns [list\
                namespace export {*}[relation list $domops Name]\
            ]
            namespace eval $domns namespace ensemble create
            set statemodels [relation semijoin $domain $StateModel\
                -using {Name Domain}]
            
            relvar eval {
                relvar set ${domns}::__Arch_InitialState [pipe {
                    relation project $statemodels Model InitialState |
                    relation rename ~ Model Class InitialState State
                }]
                set states [relation semijoin $domain $StatePlace -using {Name Domain}]
                relvar set ${domns}::__Arch_State [pipe {
                    relation project $states Model Name |
                    relation rename ~ Model Class Name State
                }]
                relvar set ${domns}::__Arch_TerminalState [pipe {
                    relation semijoin $domain $State -using {Name Domain} |
                    relation restrict ~ termtuple {[tuple extract $termtuple IsFinal]} |
                    relation project ~ Model Name |
                    relation rename ~ Model Class Name State
                }]
                set events [relation semijoin $domain $EffectiveEvent\
                    -using {Name Domain}]
                relvar set ${domns}::__Arch_Event [pipe {
                    relation project $events Model Event |
                    relation rename ~ Model Class
                }]
                set alltrans [pipe {
                    relation join $states $events |
                    relation rename ~ Name State
                }] ; # <1>
                set statetrans [relation semijoin $domain $StateTransition\
                    -using {Name Domain}]
                set nontrans [pipe {
                    relation semijoin $domain $NonStateTransition -using {Name Domain} |
                    relation rename ~ TransRule NewState
                }]
                set deftrans [pipe {
                    relation minus $alltrans $TransitionPlace |
                    relation join ~ $StateModel |
                    relation eliminate ~ InitialState |
                    relation rename ~ DefaultTrans NewState |
                    relation update ~ dttup {[tuple extract $dttup State] eq "@"} {
                        tuple update $dttup NewState CH}
                }]
                relvar set ${domns}::__Arch_Transition [pipe {
                    relation union $statetrans $nontrans $deftrans |
                    relation eliminate ~ Domain |
                    relation rename ~ Model Class
                }]
                relvar set ${domns}::__Arch_PolymorphicEvent [pipe {
                    relation semijoin $domain $DeferredEvent\
                        -using {Name Domain} |
                    relation project ~ Model Event |
                    relation rename ~ Model Class
                }]
            }
            variable headingQuery
            variable idQuery
            variable defaultValuesQuery
            variable suppliedValuesQuery
            variable generatedValuesQuery
            variable checkValuesQuery
            variable hasSMQuery
            variable statesQuery
            
            set classes [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Class -using {Domain Domain Element Name}]
            relation foreach class $classes {
                set className ${domns}::[relation extract $class Name]
                namespace eval $className {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $className [list namespace path\
                        [list ::rosea::InstCmds $domns]]
                set heading [eval $headingQuery]
                set idset [list]
                relation foreach id [eval $idQuery] -ascending Number {
                    lappend idset [relation list\
                            [relation extract $id Attributes] Attribute]
                }
                
                relvar create $className $heading {*}$idset
                
                # <1>
                set checkvalues [eval $checkValuesQuery]
                
                if {[relation isnotempty $checkvalues]} {
                    relvar trace add variable $className {insert update set} [list\
                        ::rosea::Helpers::CheckValueTrace\
                        [relation dict $checkvalues Name Expression]\
                    ]
                }
                set defaultvalues [eval $defaultValuesQuery]
                
                if {[relation isnotempty $defaultvalues]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::UserDefaultTrace\
                        [relation dict $defaultvalues Name Type]\
                        [relation dict $defaultvalues Name Value]\
                    ]
                }
                set supplied [eval $suppliedValuesQuery]
                
                if {[relation isnotempty $supplied]} {
                    pipe {
                        relation extend $supplied stup ClassName string {
                            [string cat [tuple extract $stup Class] , [tuple extract $stup Name]]
                        } |
                        relation array ~ ${domns}::__Arch_SuppliedDefault ClassName StartValue 
                    } ; # <1>
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::SupplyDefaultTrace\
                        [relation dict $supplied Name Type]\
                    ]
                }
                set generatecmds [eval $generatedValuesQuery]
                
                if {[relation isnotempty $generatecmds]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::GenerateDefaultTrace\
                        [relation dict $generatecmds Name Type]\
                        [relation dict $generatecmds Name Cmd]\
                    ]
                }
                set hasStateModel [eval $hasSMQuery]
                if {$hasStateModel} {
                    set instid [lindex $idset 0]
                    set instheading [list]
                    foreach attr $instid {
                        lappend instheading $attr [dict get $heading $attr] ; # <1>
                    }
                    lappend instheading __State string
                    relvar create ${domns}::[relation extract $class Name]__STATEINST\
                        $instheading $instid
                    set actns ${className}::__Activity
                    namespace eval $actns {
                        namespace import\
                            ::ral::relation\
                            ::ral::tuple\
                            ::ral::relformat\
                            ::ralutil::pipe
                    }
                    namespace eval $actns [list\
                        namespace path [list\
                            ::rosea::InstCmds\
                            $className\
                            $domns\
                        ]\
                    ]
                    relation foreach state [eval $statesQuery] {
                        relation assign $state\
                            {Name stateName}\
                            {Parameters params}\
                            {Action stateAction}
                        proc ${actns}::$stateName [linsert $params 0 self] $stateAction
                    }
                }
                set opmap [dict create]
                set classops [relation semijoin $class $UserClassOperation\
                    -using {Domain Domain Name Class}]
                relation foreach classop $classops {
                    relation assign $classop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname $params $opbody
                    dict set opmap $opname ${className}::$opname
                }
                
                set sysmap [QuerySystemClassOperations $className false]
                if {$hasStateModel} {
                    set sysmap [dict merge $sysmap [QuerySystemClassOperations $className true]]
                }
                
                namespace ensemble create\
                    -command $className\
                    -map [dict merge $opmap $sysmap]
                set opmap [dict create]
                set instops [relation semijoin $class $UserInstanceOperation\
                    -using {Domain Domain Name Class}]
                relation foreach instop $instops {
                    relation assign $instop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname [linsert $params 0 self] $opbody
                    dict set opmap $opname ${className}::$opname
                }
                set sysmap [QuerySystemInstanceOperations false]
                set hasPolyEvents [relation isnotempty\
                    [relation semijoin $class $PolymorphicEvent\
                        -using {Domain Domain Name Model}]\
                ]
                if {$hasStateModel || $hasPolyEvents} {
                    set sysmap [dict merge $sysmap [QuerySystemInstanceOperations true]]
                }
                
                namespace ensemble create\
                    -command ${className}::Instance\
                    -parameters instref\
                    -map [dict merge $opmap $sysmap]
            }
            set rships [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Relationship -using {Domain Domain Element Name}]
            
            set sassocs [relation semijoin $rships $Association\
                    $SimpleAssociation]
            set refing [relation semijoin $sassocs $SimpleReferringClass\
                    -using {Domain Domain Name Relationship}]
            set refed [relation semijoin $sassocs $SimpleReferencedClass\
                    -using {Domain Domain Name Relationship}]
            variable referencesQuery
            set references [eval $referencesQuery]
            relvar eval {
                set flink [pipe {
                    relation project $references Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set blink [pipe {
                    relation project $references Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%] ; # <1>
                
                relvar union ${domns}::__Arch_Link $flink $blink
                set flink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }] ; # <1>
                set blink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_AssociationLink $flink $blink
                relvar union ${domns}::__Arch_RefLink [relation project $references\
                    Relationship ReferringClass ReferencedClass ReferringAttrs]
            }
            relation foreach reference $references {
                relation assign $reference\
                    {Relationship relationship}\
                    {ReferringClass referringClass}\
                    {ReferencedClass referencedClass}\
                    {ReferringCond referringCond}\
                    {ReferringMult referringMult}\
                    {Conditionality referencedCond}\
                    {SrcAttrs srcAttrs}\
                    {DstAttrs dstAttrs}
            
                # Create the relvar constraint.
                relvar association ${domns}::$relationship\
                     ${domns}::$referringClass $srcAttrs\
                    [MapCondMultToConstraint $referringCond $referringMult]\
                    ${domns}::$referencedClass $dstAttrs\
                    [MapCondMultToConstraint $referencedCond false]
            
                # All simple associations get a link and unlink command in their ensemble.
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkSimple $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkSimple $relationship]\
                ]
            
                # Determine if we have any assigners assocated  with the relationship.
                # Single assigners get different commands from multiple assigners.
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $reference $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $reference $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                        dict set ensemblemap delete [list\
                            ::rosea::RelCmds::deleteMultiAssigner $rpath]
                    }
                }
                # Create the relationship ensemble command.
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            set cassocs [relation semijoin $rships $Association\
                    $ClassBasedAssociation]
            set sourceclass [relation semijoin $cassocs $SourceClass\
                -using {Domain Domain Name Relationship}]
            set targetclass [relation semijoin $cassocs $TargetClass\
                -using {Domain Domain Name Relationship}]
            set bothclass [relation union $sourceclass $targetclass] ; # <1>
            variable assocrefsQuery
            set assocrefs [eval $assocrefsQuery]
            relvar eval {
                set aforw [pipe {
                    relation project $assocrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set arev [relation update $aforw lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}]
                set sources [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "source"} |
                    relation eliminate ~ ReferencedRole
                }]
                set sforw [pipe {
                    relation project $sources Relationship ReferencedClass |
                    relation rename ~ Relationship Name ReferencedClass SrcClass
                }]
                set targets [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "target"} |
                    relation eliminate ~ ReferencedRole
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_Link $aforw $arev $sforw $trev
                set sforw [pipe {
                    relation project $sources Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename ~ Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename % Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                set onerefs [relation rename $sources ReferencedClass OneClass\
                        Conditionality OneCond Multiplicity OneMult\
                        ReferringAttrs OneReferringAttrs SrcAttrs OneSrcAttrs\
                        DstAttrs OneDstAttrs ForwAttrs OneForwAttrs RevAttrs OneRevAttrs]
                set otherrefs [relation rename $targets ReferencedClass OtherClass\
                        Conditionality OtherCond Multiplicity OtherMult ReferringAttrs\
                        OtherReferringAttrs SrcAttrs OtherSrcAttrs DstAttrs OtherDstAttrs\
                        ForwAttrs OtherForwAttrs RevAttrs OtherRevAttrs]
                set bothrefs [relation join $onerefs $otherrefs\
                    -using {Domain Domain ReferringClass ReferringClass\
                        Relationship Relationship}]
                set aforw [pipe {
                    relation project $bothrefs Relationship ReferringClass OtherClass\
                        OtherForwAttrs OneClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            OtherClass DstClass OtherForwAttrs Attrs OneClass PrevSrcClass
                }]
                set arev [pipe {
                    relation project $bothrefs Relationship ReferringClass OneClass\
                            OneForwAttrs OtherClass |
                    relation rename % Relationship Name ReferringClass SrcClass\
                            OneClass DstClass OneForwAttrs Attrs OtherClass PrevSrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_AssociationLink $sforw $trev $aforw $arev
                relvar union ${domns}::__Arch_AssocRef [pipe {
                    relation project $assocrefs Relationship ReferringClass\
                        ReferencedClass ReferencedRole ReferringAttrs |
                    relation rename ~ ReferringClass AssocClass ReferencedClass Participant\
                        ReferencedRole Role |
                    relation group ~ References Participant Role ReferringAttrs
                }]
            }
            relation foreach bothref $bothrefs {
                relation assign $bothref\
                    {Relationship relationship}\
                    {ReferringClass associator}\
                    {OneClass sourceClass}\
                    {OneCond sourceCond}\
                    {OneMult sourceMult}\
                    {OneSrcAttrs sourceAssocAttrs}\
                    {OneDstAttrs sourceDstAttrs}\
                    {OtherClass targetClass}\
                    {OtherCond targetCond}\
                    {OtherMult targetMult}\
                    {OtherSrcAttrs targetAssocAttrs}\
                    {OtherDstAttrs targetDstAttrs}
            
                # Create the correlation constraint
                relvar correlation ${domns}::$relationship ${domns}::$associator\
                    $sourceAssocAttrs [MapCondMultToConstraint $targetCond $targetMult]\
                    ${domns}::$sourceClass $sourceDstAttrs\
                    $targetAssocAttrs [MapCondMultToConstraint $sourceCond $sourceMult]\
                    ${domns}::$targetClass $targetDstAttrs ; # <1>
            
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkAssoc $relationship]\
                    reference [list ::rosea::RelCmds::referenceAssoc $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkAssoc $relationship]\
                ]
                # Determine if we have any assigners
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $bothref $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $bothref $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                    }
                }
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            variable subrefsQuery
            set subrefs [eval $subrefsQuery]
            relvar eval {
                set sublinks [pipe {
                    relation project $subrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set superlinks [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_Link $sublinks $superlinks
                relvar union ${domns}::__Arch_AssociationLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferencedClass\
                            ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                relvar union ${domns}::__Arch_PartitionLink $superlinks
                relvar union ${domns}::__Arch_PartitionDst [pipe {
                    relation project $subrefs Relationship ReferencedClass\
                            ReferringClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_SuperLink [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename ~ ReferencedClass SuperClass
                }]
                relvar union ${domns}::__Arch_SubLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferringAttrs |
                    relation rename ~ ReferringClass SubClass
                }]
            }
            set partrefs [pipe {
                relation project $subrefs Relationship ReferencedClass DstAttrs\
                        ReferringClass SrcAttrs |
                relation extend ~ prs SubAttrMap list {[list\
                        ${domns}::[tuple extract $prs ReferringClass]\
                        [tuple extract $prs SrcAttrs]]} |
                relation eliminate ~ ReferringClass SrcAttrs |
                relation group ~ SubClassRefs SubAttrMap |
                relation extend ~ spt SubParts list {
                        [concat {*}[relation list [tuple extract $spt SubClassRefs]]]} |
                relation eliminate ~ SubClassRefs
            }]
            
            relation foreach partref $partrefs {
                relation assign $partref\
                    {Relationship relationship}\
                    {ReferencedClass superclass}\
                    {DstAttrs superattrs}\
                    {SubParts subparts}
            
                relvar partition ${domns}::$relationship ${domns}::$superclass\
                        $superattrs {*}$subparts
                namespace ensemble create\
                    -command ${domns}::$relationship\
                    -map [dict create migrate [list ::rosea::RelCmds::migrate\
                            $relationship]]
            }
            set assigners [relation semijoin $domain $AssignerStateModel\
                    -using {Name Domain}]
            relation foreach assigner $assigners {
                set asgnns\
                    ${domns}::[relation extract $assigner Relationship]::__Activity
                namespace eval $asgnns {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $asgnns [list\
                    namespace path [list\
                        ::rosea::InstCmds\
                        $domns\
                    ]\
                ]
                set states [pipe {
                    relation semijoin $assigner $State\
                        -using {Domain Domain Relationship Model} |
                    relation project ~ Name Parameters Action
                }]
                relation foreach state $states {
                    relation assign $state\
                        {Name stateName}\
                        {Parameters params}\
                        {Action stateAction}
                    set params [linsert $params 0 self]
                    proc ${asgnns}::$stateName $params $stateAction
                }
            }
            relation foreach sassigner\
                    [relation semijoin $domain $SingleAssigner\
                    -using {Name Domain}] {
                relation assign $sassigner {Relationship relationship}
                relvar create ${domns}::${relationship}__STATEINST {
                    Id      int
                    __State string
                } Id
                CreateInInitialState $domns $relationship {Id 0} ; # <1>
            }
            relation foreach massigner\
                    [relation semijoin $domain $MultipleAssigner\
                    -using {Name Domain}] {
                relation assign $massigner {Relationship relationship}
                set assignvar ${domns}::${relationship}__STATEINST
            
                set idattrs [pipe {
                    relation semijoin $massigner $Identifier\
                        $IdentifyingAttribute\
                        $Attribute -using {Domain Domain Class Class\
                            Attribute Name} |
                    relation dict ~ Name Type
                }]
                relvar create $assignvar\
                    [concat $idattrs [list __State string]]\
                    [dict keys $idattrs]
            }
        }
    }
    proc populate {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Populate $script ; # <1>
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc populateFromChan {chan} {
        tailcall populate [::chan read -nonewline $chan]
    }
    proc populateFromFile {filename} {
        set f [::open $filename r]
        try {
            populateFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc save {args} {
        set savecmd ::ral::serializeToFile
        set asynccmd {}
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set savecmd ::ral::storeToSQLite
                    }
                    -tclral {
                        set savecmd ::ral::serializeToFile
                    }
                    -async {
                        set options [lassign $options asynccmd]
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION save $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} { # <1>
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError SAVE_ARG_ERROR $args
        }
    
        set script "try \{$savecmd $file ${domain}::\\\[A-Za-z0-9\\\]*\}" ; # <2>
        if {$asynccmd ne {}} {
            append script " finally \{$asynccmd $domain $file\}"
        }
    
        after idle [list ::apply [list {} $script]] ; # <3>
    }
    proc restore {args} {
        set restorecmd ::ral::mergeFromFile
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set restorecmd ::ral::mergeFromSQLite
                    }
                    -tclral {
                        set restorecmd ::ral::mergeFromFile
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION restore $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} {
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError RESTORE_ARG_ERROR $args
        }
    
        eval [list $restorecmd $file $domain]
    
        # Determine the values for the system supplied defaults.  We examine all
        # the classes that have such attributes and find the maximum value of the
        # attribute.  This can then be placed in the array that is used when new
        # default values are generated.
        set domainname [namespace tail $domain]
        set supplied [pipe {
            relvar set ::rosea::Config::SystemSuppliedValue |
            relation restrictwith ~ {$Domain eq $domainname}
        }]
    
        relation foreach sup $supplied {
            relation assign $sup
            set classtups [relvar set ${domain}::$Class]
            if {[relation isempty $classtups]} {
                set maxvalue $StartValue
            } else {
                set maxvalue [pipe {
                    relation summarizeby $classtups {} cv\
                        MaxValue int {rmax($cv, $Attribute)} |
                    relation extract ~ MaxValue
                }]
            }
            set ${domain}::__Arch_SuppliedDefault($Class,$Attribute)\
                [expr {$maxvalue + 1}]
        }
        return
    }
    proc info {args} {
        set args [lassign $args subcmd]
    
        switch -exact -- $subcmd {
            domain {
                Info::domain $args
            }
            class {
                Info::class $args
            }
            statemodel {
                Info::statemodel $args
            }
            default {
                tailcall DeclError UNKNOWN_INFO_CMD $subcmd
            }
        }
    }
    proc tunnel {instref op args} {
        relvar eval {
            set result [[lindex $instref 0]::Instance $instref $op {*}$args]
        }
        return $result
    }
    proc trace {subcmd args} {
        switch -exact -- $subcmd {
            control {
                tailcall traceControl {*}$args
            }
            decode {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DecodeAllTraces
                    }
                    class {
                        tailcall Trace::DecodeClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DecodeTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            format {
                tailcall formatTraces {*}$args
            }
            diagram {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DiagAllTraces {*}[lrange $args 1 end]
                    }
                    class {
                        tailcall Trace::DiagClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DiagTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            default {
                tailcall DeclError UNKNOWN_TRACE_CMD $subcmd
            }
        }
    }
    proc traceControl {op args} {
        switch -exact -- $op {
            on {
                namespace upvar Trace traceState traceState
                set traceState on
            }
            off {
                namespace upvar Trace traceState traceState
                set traceState off
            }
            status {
                namespace upvar Trace traceState traceState
                return $traceState
            }
            clear {
                relvar eval {
                    foreach rvar {Trace Creation Polymorphic Transition} {
                        relvar set Trace::$rvar\
                                [relation emptyof [relvar set Trace::$rvar]]
                    }
                }
                namespace upvar Trace traceNumber traceNumber
                set traceNumber 0
            }
            logon {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState on
            }
            logoff {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState off
            }
            loglevel {
                namespace upvar Trace traceLogLevel traceLogLevel
                if {[llength $args] != 0} {
                    set traceLogLevel [lindex $args 0]
                }
                return $traceLogLevel
            }
            save {
                if {[llength $args] == 0} {
                    DeclError NO_SAVEFILE
                }
                ral storeToSQLite [lindex $args 0] ::rosea::Trace::*
            }
            default {
                DeclError BAD_TRACEOP $op
            }
        }
    }
    proc formatTraces {tracerecs} {
        if {[llength $tracerecs] == 0} {
            return {}
        }
        set prevtime [dict get [lindex $tracerecs 0] time]
        foreach rec $tracerecs {
            dict with rec {
                append result "[Trace::FormatTimestamp $time]: "
                append result "[Trace::FormatTimeAsSec\
                        [expr {$time - $prevtime}]]: "
                set prevtime $time
                append result [Trace::FormatTraceRec $rec] \n
            }
        }
        return [string trimright $result]
    }
    namespace eval Helpers {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        variable errFormats
        set errFormats [dict create {*}{
            SAME_CLASS   {operation is only allowed for references to the same class,\
                            got "%s" and "%s"}
            UNKNOWN_STATE   {unknown state, "%s", for class, "%s"}
            UNKNOWN_EVENT   {unknown event, "%s", for class, "%s"}
            NO_CREATION_EVENTS   {class, "%s", has no defined creation events}
            NO_CROSS_DOMAIN         {cannot link instances across domains,\
                                        got "%s" and "%s"}
            UNKNOWN_RELATIONSHIP    {unknown relationship, "%s"}
            NON_PARTICIPANTS        {"%s" and "%s" don't participate in %s,\
                                        expected "%s" and "%s"}
            MUST_BE_SINGULAR    {number of referred to instances for "%s" must be one,\
                                    got %d}
            NOT_IN_ASSOCIATION         {"%s" $relvar1 not a participant in "%s"}
            DIRECTION_REQUIRED  {direction argument is required: got "%s"}
            AMBIGUOUS_UNLINK         {"%s" is reflexive and linking via "%s" is ambiguous}
            NO_SUBCLASS         {relationship "%s" does not have a "%s"}
            NO_ASSIGNER         {relationship, "%s", does not have an assigner}
            NO_IDENTIFIER       {bad identifying attributes, expected "%s", got "%s"}
            UNKNOWN_ASSIGNER    {unknown assigner instance, "%s", for relationship, "%s"}
            UNKNOWN_LINKAGE {unknown relationship, "%s", for class, "%s"}
            PATH_ERROR      {relationship, "%s", from "%s" to "%s", does not end at "%s"}
            GEN_PATH_ERROR  {navigating from superclass, "%s", along generalization "%s",\
                            does not have "%s" as a subclass}
            ARG_ERROR           {attribute updates must be name / value pairs, got "%s"}
            ID_UPDATE           {cannot update identifying attributes, "%s"}
            UNKNOWN_ATTRIBUTE   {unknown attribute, "%s"}
            WITH_ATTR_USAGE {wrong arguments, should be,\
                    "withAttribute attrvarpair1 ?attrvarpair2 ...? body"}
            ATTR_VAR_SPEC   {attribute / variable argument must be a one or two element\
                    list, got "%s"}
            INVALID_TIME    {invalid time value, "%s"}
            SINGLE_OR_EMPTY_REF_REQUIRED {single valued or nil reference required, %d found}
            SINGLE_REF_REQUIRED     {single valued reference required, %d found}
            UNKNOWN_EVENT_TYPE     {unknown event type, \"%s\"}
            EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
            CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}
            ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
            with attributes, "%s", failed: %s}
            CONFIG_ERRORS     {encountered %d configuration script errors}
            EMPTY_NAME      {the empty string is not a valid name for a %s}
            BAD_CLASS_NAME      {class names must be begin with an alphanumeric\
                                character, got: "%s"}
            DUP_ELEMENT_NAME    {a class, relationship or domain operation named, "%s",\
                                already exists}
            RESERVED_NAME {names beginning with two underscore characters are reserved,\
                    "%s" cannot be used as a name in this context}
            INT_TYPE_REQUIRED   {attribute must be of "int" type, got "%s"}
            INT_VALUE_REQUIRED  {an integer value is required, got "%s"}
            ARG_FORMAT      {options and values must come in pairs, got "%s"}
            UNKNOWN_OPTION  {unknown %s command option, "%s"}
            DUP_OP_NAME     {operation call, "%s", already exists}
            NS_QUALIFIERS   {name, "%s", contains namespace qualifiers}
            TILDE_NAME {names beginning with the tilde character are not allowed\
                in this context, "%s"}
                
            BAD_RELATIONSHIP_SPEC  {bad relationship specifier, "%s"}
            NEED_ASSOCIATOR {relationship of type, "%s", requires associative class}
            NEED_REFLEXIVE_PATH {traversal path must be specified for reflexive\
                    association, %s, %s %s %s}
            REFLEXIVE_NOT_ALLOWED   {associations of type, "%s", cannot be reflexive}
            TOO_FEW_SUBCLASSES  {at least 2 subclasses must be specified, got %d}
            BAD_CREATION_TARGET {the target of a creation event must be a state,\
                    got "%s"}
            PSEUDO_STATE    {the transition action, "%s", is not valid as %s}
            EXPECTED_PSEUDO_STATE    {expected CH or IG, got "%s"}
            RELVAR_TRACE_OP     {unexpected relvar trace operation, "%s"}
            ATTR_CHECK_FAILED   {check for attribute, "%s", failed:\
                                instance value was, "%s": "%s" evaluated to "%s"}
            UNKNOWN_DOMAIN  {unknown domain, "%s"}
            ARG_MISMATCH      {number of population values must be a multiple of %d, got %d}
            SAVE_ARG_ERROR  {wrong number of arguments: expected:\
                    "save ?-sqlite | -tclral? ?-async <cmdprefix>?\
                    <domain> <filename>", got: "%s"}
            RESTORE_ARG_ERROR  {wrong number of arguments: expected:\
                    "restore ?-sqlite | -tclral?  <domain> <filename>", got: "%s"}
            UNKNOWN_INFO_CMD  {unknown info request, "%s"}
            UNKNOWN_CLASS  {unknown class, "%s", in domain, "%s"}
            UNKNOWN_TRACE_CMD   {unknown trace subcomand, "%s"}
            BAD_TRACEOP     {unknown trace operation, "%s"}
            NO_SAVEFILE     {no save file name provided}
            BAD_TRACETYPE   {unknown trace type, "%s"}
        }]
        proc ToRef {relvar relvalue} {
            tailcall list $relvar [relation project $relvalue\
                {*}[lindex [relvar identifiers $relvar] 0]] ; # <1>
        }
        proc nilInstRef {} {
            return {{} {{} {}}}
        }
        proc CreateStateInstance {domns class state idattrs} {
            tailcall relvar insert ${domns}::${class}__STATEINST\
                    [concat $idattrs [list __State $state]]
        }
        proc CreateInInitialState {domns class idattrs} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstance $domns $class [relation extract $initstate State]\
                    $idattrs
            }
            return
        }
        proc CreateStateInstanceFromRef {domns class state ref} {
            relation foreach inst [lindex $ref 1] { # <1>
                CreateStateInstance $domns $class $state\
                    [tuple get [relation tuple $inst]]
            }
            return
        }
        proc CreateInInitialStateFromRef {domns class ref} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstanceFromRef $domns $class\
                    [relation extract $initstate State] $ref
            }
            return
        }
        proc MultiAssignerIDAttrs {domain relationship} {
            if {[string range $domain 0 1] eq "::"} {
                set domain [string range $domain 2 end]
            }
            return [pipe {
                relvar restrictone ::rosea::Config::MultipleAssigner\
                    Domain $domain Relationship $relationship |
                relation semijoin ~ $::rosea::Config::Identifier\
                    $::rosea::Config::IdentifyingAttribute |
                relation list ~ Attribute
            }]
        }
        proc SelfInstRef {{level 2}} {
            set foundRef false
            set ref [nilInstRef]
        
            for {set ns [uplevel $level namespace current]} {$ns ne "::"}\
                    {set ns [uplevel [incr level] namespace current]} {
                if {!$foundRef} {
                    upvar $level self srcself
                    if {[info exists srcself]} {
                        set ref $srcself
                        set foundRef true
                    }
                }
                if {[string match {*__Activity*} $ns]} {
                    return $ref ; # <1>
                }
            }
            return [nilInstRef]
        }
        namespace export DeclError
        
        proc DeclError {errcode args} {
            variable errFormats
            set errmsg [format [dict get $errFormats $errcode] {*}$args]
            tailcall throw [list ROSEA $errcode {*}$args $errmsg] $errmsg
        }
        proc SplitRelvarName {relvar {dvarname domain} {cvarname class}} {
            upvar 1 $dvarname domain $cvarname class
            set domain [namespace qualifiers $relvar]
            set class [namespace tail $relvar]
        }
        proc PropagatePolyEvents {super} {
            namespace upvar ::rosea::Config\
                DeferredEvent DeferredEvent\
                LocalEvent LocalEvent\
                Superclass Superclass\
                Subclass Subclass\
                DeferralPath DeferralPath\
                Generalization Generalization ; # <1>
        
            set supername [relation extract $super Class]
        
            set subs [pipe {
                relation semijoin $super\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}
            }]
        
            relation foreach sub $subs {
                set defrdevents [pipe {
                    relation semijoin $super $DeferralPath\
                        -using {Domain Domain Class Model Relationship Relationship}\
                        $DeferredEvent |
                    relation update ~ deftup {1} {
                        tuple update $deftup Model [relation extract $sub Class]
                    }
                }]
                set multigens [relation semijoin $sub $Superclass\
                    -using {Domain Domain Class Class}]
        
                if {[relation isempty $multigens]} {
                    relvar minus ::rosea::Config::LocalEvent $defrdevents
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::EffectiveEvent $defrdevents
                    relvar union ::rosea::Config::MappedEvent [relation extend\
                        $defrdevents metuple ParentModel string {$supername}]
                } else {
                    set consumed [relation semijoin $defrdevents $LocalEvent]
                    if {[relation isnotempty $consumed]} {
                        relvar minus ::rosea::Config::LocalEvent $consumed ; # <1>
                        relvar union ::rosea::Config::MappedEvent [relation extend\
                            $consumed ctup ParentModel string {$supername}]
                        relvar union ::rosea::Config::NonLocalEvent [relation extend\
                            $consumed nletuple\
                            Relationship string {[relation extract $sub Relationship]}\
                            Role string {[relation extract $sub Role]}]
                        set defrdevents [relation minus $defrdevents $consumed] ; # <2>
                    
                        set usedinsubs [pipe {
                            FindSubclassesOf $multigens|
                            relation tclose ~ |
                            relation semijoin $consumed ~ -using {Model Super} |
                            relation semijoin ~ $LocalEvent -using {Sub Model} |
                            relation semijoin $consumed ~ -using {Domain Domain Event Event}
                        }]
                        relvar minus ::rosea::Config::LocalEvent $usedinsubs ; # <3>
                        relvar minus ::rosea::Config::EffectiveEvent $usedinsubs
                        relvar minus ::rosea::Config::Event $usedinsubs
                    }
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::DeferredEvent $defrdevents
                    relvar union ::rosea::Config::InheritedEvent $defrdevents
                    relvar union ::rosea::Config::DeferralPath [relation join\
                        $defrdevents $Superclass -using {Domain Domain Model Class}]
                }
        
                relvar union ::rosea::Config::NonLocalEvent [relation extend\
                    $defrdevents nletuple\
                    Relationship string {[relation extract $sub Relationship]}\
                    Role string {[relation extract $sub Role]}]
                relation foreach multigen $multigens {
                    PropagatePolyEvents $multigen
                }
            }
        }
        proc FindSubclassesOf {supers} {
            namespace upvar ::rosea::Config\
                Generalization Generalization\
                Superclass Superclass\
                Subclass Subclass
        
            if {[relation isempty $supers]} {# <1>
                return [relation create {Super string Sub string}]
            }
            set supnames [pipe {
                relation project $supers Class |
                relation rename ~ Class Super
            }] ; # <2>
            set subclasses [relation semijoin $supers\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}]
            set subnames [pipe {
                relation project $subclasses Class |
                relation rename ~ Class Sub
            }] ; # <3>
            
            set uses [relation times $supnames $subnames] ; # <4>
        
            set nextsupers [relation semijoin $subclasses $Superclass\
                    -using {Domain Domain Class Class}] ; # <5>
        
            return [relation union $uses [FindSubclassesOf $nextsupers]] ; # <6>
        }
        proc UserDefaultTrace {defheading defvalues op relvar tuple} {
            tuple create\
                [dict merge $defheading [tuple heading $tuple]]\
                [dict merge $defvalues [tuple get $tuple]]
        }
        proc SupplyDefaultTrace {defheading op relvar tuple} {
            set attrs [tuple attributes $tuple] ; # <1>
            SplitRelvarName $relvar domain class ; # <2>
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [set ${domain}::__Arch_SuppliedDefault($class,$attrname)] ; # <3>
                    incr ${domain}::__Arch_SuppliedDefault($class,$attrname)
                    set tuple [tuple extend $tuple $attrname $attrtype $value] ; # <4>
                }
            }
            return $tuple
        }
        proc GenerateDefaultTrace {defheading defcmds op relvar tuple} {
            set attrs [tuple attributes $tuple]
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [eval [dict get $defcmds $attrname]]
                    set tuple [tuple extend $tuple $attrname $attrtype $value]
                }
            }
            return $tuple
        }
        proc CheckValueTrace {attrchecks op relvar args} {
            if {$op eq "insert"} {
                set tuple [lindex $args 0]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "update"} {
                set tuple [lindex $args 1]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "set"} {
                set relvalue [lindex $args 0]
                relation foreach inst $relvalue {
                    set tuple [relation tuple $inst]
                    EvalAttrCheck $attrchecks $tuple
                }
                return $relvalue
            } else {
                tailcall DeclError RELVAR_TRACE_OP $op
            }
        }
        proc EvalAttrCheck {attrchecks tuple} {
            dict for {attrname checkexpr} $attrchecks {
                tuple assign $tuple
                set result [expr $checkexpr]
                if {!$result} {
                    tailcall DeclError ATTR_CHECK_FAILED $attrname [tuple get $tuple]\
                        $checkexpr $result
                }
            }
        }
        proc QuerySystemOperations {which requiresSM} {
            return [pipe {
                relvar set ::rosea::Config::SuppliedOperation |
                relation restrictwith ~ {$RequiresStateModel == $requiresSM} |
                relation join [relvar set ::rosea::Config::$which] ~
            }]
        }
        proc QuerySystemClassOperations {className requiresSM} {
            return [pipe {
                QuerySystemOperations SystemClassOperation $requiresSM |
                relation update ~ sco 1 {
                    tuple update $sco Command\
                        [concat [tuple extract $sco Command]\
                        [list $className]]
                } |
                relation dict ~ Name Command
            }]
        }
        proc QuerySystemInstanceOperations {requiresSM} {
            return [pipe {
                QuerySystemOperations SystemInstanceOperation $requiresSM |
                relation dict ~ Name Command
            }]
        }
        proc Interleave {l1 l2} {
            set result [list]
            foreach a $l1 b $l2 {
                lappend result $a $b
            }
            return $result
        }
        proc MapCondMultToConstraint {cond mult} {
            if {$cond} {
                return [expr {$mult ? "*" : "?"}]
            } else {
                return [expr {$mult ? "+" : "1"}]
            }
        }
    }
    namespace eval ClassCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers ; # <1>
        proc findAll {relvar} {
            tailcall ToRef $relvar [relvar set $relvar]
        }
        proc findById {relvar args} {
            tailcall ToRef $relvar [relvar restrictone $relvar {*}$args]
        }
        proc findWhere {relvar expr} {
            tailcall ToRef $relvar [uplevel 1 [list ::ral relation restrictwith\
                [relvar set $relvar] $expr]]
        }
        proc create {relvar args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]] ; # <1>
            SplitRelvarName $relvar domain class
            CreateInInitialStateFromRef $domain $class $ref
            return $ref
        }
        proc createin {relvar state args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $relvar domain class
            set initstate [relvar restrictone ${domain}::__Arch_State\
                Class $class State $state]
            if {[relation isempty $initstate]} { # <1>
                tailcall DeclError UNKNOWN_STATE $state $relvar
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]]
            CreateStateInstanceFromRef $domain $class $state $ref
            return $ref
        }
        proc createasync {relvar event eventparams args} {
            SplitRelvarName $relvar domain class
        
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
            if {[relation isempty [relvar restrictone ${domain}::__Arch_State\
                    Class $class State @]]} {
                tailcall DeclError NO_CREATION_EVENTS $class
            }
            set srcref [SelfInstRef]
            set eventInfo [dict create\
                type creation\
                src $srcref\
                dstClass $relvar\
                dstAttrs $args\
                event $event\
                params $eventparams\
            ]
            if {[::rosea::InstCmds::isRefEqual $srcref [nilInstRef]]} {
                lappend ::rosea::Dispatch::toc_queue $eventInfo
            } else {
                lappend ::rosea::Dispatch::event_queue $eventInfo
            }
            ::after 0 ::rosea::Dispatch::DispatchEvent
            return
        }
        proc update {relvar relvalue} {
            tailcall ToRef $relvar [relvar updateper $relvar $relvalue]
        }
    }
    namespace eval InstCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace path [namespace parent]::Helpers
        pipe {
            relvar set ${domain}::$DstClass |
            relation $op $related ~ -using $Attrs
        } relatedQuery
        proc deRef {instref args} {
            lassign $instref relvar ref
            set inst [relation semijoin $ref [relvar set $relvar]] ; # <1>
            if {[llength $args] != 0} {
                set inst [relation project $inst\
                    {*}[relation attributes $ref] {*}$args] ; # <2>
            }
            return $inst
        }
        proc isEmptyRef {instref} {
            tailcall relation isempty [lindex $instref 1]
        }
        proc isNotEmptyRef {instref} {
            tailcall relation isnotempty [lindex $instref 1]
        }
        proc refMultiplicity {instref} {
            tailcall relation cardinality [lindex $instref 1]
        }
        proc isRefSingular {instref} {
            expr {[refMultiplicity $instref] == 1}
        }
        proc limitRef {instref {count 1}} {
            lassign $instref relvar insts
            return [pipe {
                relation tag $insts __Tag |
                relation restrictwith ~ {$__Tag >= 0 && $__Tag < $count} |
                ToRef $relvar ~
            }]
        }
        proc isRefEqual {instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            return [expr {$relvar1 eq $relvar2 && [relation is $inst1 equal $inst2]}]
        }
        proc RefSetCommand {op instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            if {$relvar1 ne $relvar2} {
                tailcall DeclError SAME_CLASS $relvar1 $relvar2
            }
            return [list $relvar1 [relation $op $inst1 $inst2]]
        }
        proc refUnion {instref1 instref2} {
            tailcall RefSetCommand union $instref1 $instref2
        }
        proc refIntersect {instref1 instref2} {
            tailcall RefSetCommand intersect $instref1 $instref2
        }
        proc refMinus {instref1 instref2} {
            tailcall RefSetCommand minus $instref1 $instref2
        }
        proc forAllRefs {varname instref body} {
            lassign $instref relvar refs
            upvar 1 $varname inst
            relation foreach ref $refs {
                set inst [list $relvar $ref]
                uplevel 1 $body
            } ; # <1>
            return
        }
        proc FindRelatedInsts {instref op args} {
            set srcrelvar [lindex $instref 0]
            SplitRelvarName $srcrelvar domain class
            
            # This procedure queries the architectural data about relationship linkage,
            # so we bring the relvar variables into scope.
            namespace upvar ${domain}\
                    __Arch_Link Link\
                    __Arch_AssociationLink AssociationLink\
                    __Arch_PartitionLink PartitionLink\
                    __Arch_PartitionDst PartitionDst
            variable relatedQuery ; # <1>
            # We start by dereferencing the instance reference.
            set related [deRef $instref]
            foreach linkage $args {
                lassign $linkage lname dst ; # split out the linkage spec
                
                set link [relvar restrictone ${domain}::__Arch_Link\
                        Name $lname SrcClass $class]
                if {[ral relation isempty $link]} {
                    tailcall DeclError UNKNOWN_LINKAGE $lname $class
                }
                # First we determine if we are dealing with an associative link or a
                # partition link.
                set assoc [relation join $link $AssociationLink]
                if {[relation isnotempty $assoc]} {
                    relation assign $assoc DstClass Attrs
                    # Check if additional path information was provided.
                    if {$dst eq {}} {
                        # Find the set of instances related to the current set.
                        set related [eval $relatedQuery]
                        # We must see if this is a class-based association.  If so, then the first
                        # traversal was to the associator and we must traverse again to the other
                        # class.
                        set assoc [relation semijoin $assoc $AssociationLink\
                            -using {Name Name SrcClass PrevSrcClass}]
                        if {[relation isnotempty $assoc]} {
                            relation assign $assoc DstClass Attrs
                            set related [pipe {# <1>
                                relvar set ${domain}::$DstClass |
                                relation semijoin $related ~ -using $Attrs
                            }]
                        }
                    } else {
                        # If a destination was specified in the linkage, then we need to verify
                        # that it is actually part of the relationship.
                        if {$dst ne $DstClass} {
                            tailcall DeclError PATH_ERROR $lname $class $DstClass\
                                $dst
                        }
                        set related [eval $relatedQuery]
                    }
                } else {
                    set partdst [relvar restrictone ${domain}::__Arch_PartitionDst\
                        Name $lname SrcClass $class DstClass $dst]
                    if {[relation isempty $partdst]} {
                        tailcall DeclError GEN_PATH_ERROR $class $lname $dst
                    }
                    relation assign $partdst DstClass Attrs
                    set related [eval $relatedQuery]
                }
                # Continue the iteration by setting the next source to the current
                # destination class.
                set class $DstClass
                set srcrelvar ${domain}::$class
            }
            # N.B. that we are not returning an instance reference but rather the
            # complete relation value of the related instances. This allows us
            # to further filter the result in the "findRelatedWhere" command.
            return [list $srcrelvar $related]
        }
        proc findRelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semijoin {*}$args] ; # <1>
        }
        proc findUnrelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semiminus {*}$args] ; # <1>
        }
        proc findRelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semijoin {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]] ; # <1>
        }
        proc findUnrelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semiminus {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]]
        }
        proc idInstance {instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set idclass [pipe {
                relvar restrictone [namespace parent]::Config::MultipleAssigner\
                        Domain [string trim $domain :] Relationship $relationship |
                relation extract ~ Class
            }]
        
            return [pipe {
                relvar set ${domain}::$idclass |
                relation semijoin $insts ~ |
                ToRef ${domain}::$idclass ~
            }]
        }
        proc updateAttribute {instref args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_ERROR $args
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $args]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach {attr value} $args {
                if {![dict exists $heading $attr]} {
                    tailcall DeclError UNKNOWN_ATTRIBUTE $attr
                }
                lappend extcmd $attr [dict get $heading $attr] \{$value\}
            }
            relvar updateper $relvar [eval $extcmd]
            return
        }
        proc withAttribute {instref args} {
            if {[llength $args] < 2} {
                tailcall DeclError WITH_ATTR_USAGE
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            
            set body [lindex $args end]
            set attrspecs [lrange $args 0 end-1]
            set attrnames [list]
            set varnames [list]
            foreach attrspec $attrspecs {
                set speclen [llength $attrspec]
                if {$speclen == 1} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 0]
                } elseif {$speclen == 2} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 1]
                } else {
                    tailcall DeclError ATTR_VAR_SPEC $attrspec
                }
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $attrnames]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            uplevel 1 [list ral relation assign [deRef $instref] {*}$attrspecs]
            uplevel 1 $body
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach attr $attrnames var $varnames {
                if {[uplevel 1 [list info exists $var]]} {
                    upvar 1 $var varvalue
                    lappend extcmd $attr [dict get $heading $attr] \{$varvalue\}
                }
            }
            relvar updateper $relvar [eval $extcmd]
        
            return
        }
        proc readAttribute {ref args} {
            # We insist upon a singular reference for reading attributes.  Multiple
            # references can be handled by dereferences and using TclRAL "relation"
            # commands.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            return [expr {[llength $args] == 0 ? {} :\
                [relation extract [deRef $ref {*}$args] {*}$args]}] ; # <1>
        }
        proc assignAttribute {ref args} {
            # We must insist upon a singular references, since assigning to scalar
            # variables from a relation value doesn't make a lot of sense.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            uplevel 1 [list ral relation assign [deRef $ref] {*}$args] ; # <1>
            return
        }
        proc delete {args} {
            foreach instref $args {
                lassign $instref relvar insts
                relvar minus $relvar [deRef $instref]
        
                SplitRelvarName $relvar domain class
                set instrelvar ${domain}::${class}__STATEINST
                if {[relvar exists $instrelvar]} {
                    relvar minus $instrelvar [relation semijoin $insts\
                        [relvar set $instrelvar]]
                }
            }
        
            return
        }
        proc signal {dstset event args} {
            set srcref [SelfInstRef]
            ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args
            return
        }
        proc delaysignal {time dstset event args} {
            if {!([string is integer -strict $time] && $time >= 0)} {
                tailcall DeclError INVALID_TIME $time
            }
            set srcref [SelfInstRef]
            ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args
            return
        }
        proc canceldelayed {srcref dstset event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            forAllRefs dstref $dstset {
                ::rosea::Dispatch::CancelDelayedSignal $srcref $event $dstref
            }
            return
        }
        proc delayremaining {srcref dstref event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            if {![isRefSingular $dstref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $dstref]
            }
            tailcall ::rosea::Dispatch::SignalTimeRemaining $srcref $event $dstref
        }
        proc instop {instref op args} {
            tailcall [lindex $instref 0]::Instance $instref $op {*}$args
        }
    }
    namespace eval RelCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        proc linkSimple {rname instref1 instref2} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set reflink [relvar restrictone ${domain1}::__Arch_RefLink Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs} ; # <1>
            if {$class1 eq $referringClass && $class2 eq $referencedClass} {
                set fromrelvar $relvar1
                set frominsts $inst1
                set torelvar $relvar2
                set toinst $inst2
            } elseif {$class2 eq $referringClass && $class1 eq $referencedClass} {
                set fromrelvar $relvar2
                set frominsts $inst2
                set torelvar $relvar1
                set toinst $inst1
            } else {
                tailcall DeclError NON_PARTICIPANTS $relvar1 $relvar2 $rname\
                    $referringClass $referencedClass
            }
            if {[relation cardinality $toinst] != 1} {
                tailcall MUST_BE_SINGULAR $torelvar [relation cardinality $toinst]
            }
            set refedvalue [relation semijoin $toinst [relvar set $torelvar]]
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] { # <1>
                    tuple update $fromtup {*}$tovalues ; # <2>
                }
            }
        
            return
        }
        proc linkAssoc {rname instref1 instref2 args} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${domain1}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            set ref1 [relation restrictwith $references {$Participant eq $class1}]
            if {[relation isempty $ref1]} {
                tailcall DeclError NOT_IN_ASSOCIATION $class1 $rname
            }
            if {[relation cardinality $ref1] > 1} {
                set ref2 [relation restrictwith $ref1 {$Role eq "target"}]
                set ref1 [relation minus $ref1 $ref2] ; # <1>
            } else {
                set ref2 [relation restrictwith $references {$Participant eq $class2}]
                if {[relation isempty $ref2]} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class2 $rname
                }
            }
            
            set rattr1 [relation extract $ref1 ReferringAttrs]
            set rattr2 [relation extract $ref2 ReferringAttrs]
            set values1 [relation semijoin $inst1 [relvar set $relvar1]]
            set values2 [relation semijoin $inst2 [relvar set $relvar2]]
            set assoctuples [list]
            relation foreach v1 $values1 { # <1>
                set refto1 [pipe {
                    relation extend $rattr1 rfa RefValue string {
                        [relation extract $v1 [tuple extract $rfa ReferencedAttribute]]
                    } |
                    relation dict ~ ReferringAttribute RefValue
                }]
                relation foreach v2 $values2 {
                    set refto2 [pipe {
                        relation extend $rattr2 rfa RefValue string {
                            [relation extract $v2\
                                [tuple extract $rfa ReferencedAttribute]]
                        } |
                        relation dict ~ ReferringAttribute RefValue
                    }]
            
                    lappend assoctuples [dict merge $args $refto1 $refto2] ; # <2>
                }
            }
            set ref [ToRef ${domain1}::$assocClass\
                    [relvar insert ${domain1}::$assocClass {*}$assoctuples]]
                CreateInInitialStateFromRef $domain1 $assocClass $ref ; # <1>
            return $ref
        }
        proc referenceAssoc {rname assocref instref {dir {}}} {
            if {![isRefSingular $assocref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $assocref]
            }
            lassign $assocref assocrelvar associnst
            SplitRelvarName $assocrelvar assocdomain assocclass
            
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref instrelvar inst
            SplitRelvarName $instrelvar instdomain instclass
            
            if {$assocdomain ne $instdomain} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${instdomain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            
            if {$assocClass ne $assocclass} {
                tailcall DeclError NOT_IN_ASSOCIATION $assocclass $rname
            }
            set ref [relation restrictwith $references {$Participant eq $instclass}]
            set refcard [relation cardinality $ref]
            if {$refcard == 2} {
                switch -exact -- $dir {
                    forward {
                        set role target
                    }
                    backward {
                        set role source
                    }
                    default {
                        tailcall DeclError DIRECTION_REQUIRED $dir
                    }
                }
                set ref [relation restrictwith $ref {$Role eq $role}]
            } elseif {$refcard == 0} {
                tailcall DeclError NOT_IN_ASSOCIATION $instclass $rname
            }
            set referringAttrs [relation extract $ref ReferringAttrs]
            
            set refedvalue [relation semijoin $inst [relvar set $instrelvar]]
            
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relvar updateone $assocrelvar assoctup [tuple get [relation tuple $associnst]] {
                tuple update $assoctup {*}$tovalues
            }
        }
        proc unlinkSimple {rname instref} {
            lassign $instref relvar inst
            SplitRelvarName $relvar domain class
        
            set reflink [relvar restrictone ${domain}::__Arch_RefLink\
                    Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs}
        
            if {$class eq $referringClass} {
                set fromrelvar $relvar
                set frominsts $inst
            } elseif {$class eq $referencedClass} {
                lassign [::rosea::InstCmds::findRelated $instref ~$rname]\
                    fromrelvar frominsts
            } else {
                tailcall DeclError NOT_IN_ASSOCIATION $relvar $rname
            }
        
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {{}} |
                relation dict ~ ReferringAttribute RefValue
            }]
        
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] {
                    tuple update $fromtup {*}$tovalues
                }
            }
        
            return
        }
        proc unlinkAssoc {rname instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain class
        
            set assocref [relvar restrictone ${domain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $assocref\
                {Relationship relationship}\
                {AssocClass associator}\
                {References references}
        
            # If we are given instances to the associator class, then there is no
            # more work to do.
            if {$class ne $associator} {
                # Otherwise, we have to find the associator class instances ourselves.
                set part [relation restrictwith $references {$Participant eq $class}]
                set partcard [relation cardinality $part]
                if {$partcard == 0} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class $rname
                } elseif {$partcard > 1} {
                    tailcall DeclError AMBIGUOUS_UNLINK $rname $relvar ; # <1>
                } else {
                    # Find associative class instances.  We have to determine the
                    # direction of the relationship traversal.
                    set navdir [expr {[relation extract $part Role] eq "source" ?\
                        "$relationship" : "~$relationship"}]
                    set instref [::rosea::InstCmds::findRelated $instref\
                        [list $navdir [namespace tail $associator]]]
                    lassign $instref relvar insts
                    SplitRelvarName $relvar domain class
                }
            }
        
            # We are going to delete tuples from the relvar that holds the class
            # instances.
            set delrelvars [list ${domain}::$class]
            # If the associative class also has a state model, then we need to also
            # delete the state instance tuples.
            if {[relvar exists ${domain}::${class}__STATEINST]} {
                lappend delrelvars ${domain}::${class}__STATEINST
            }
        
            # Now, we iterate across the associative class instances and delete all the
            # tuples in class relvar and, if necessary, the state instances.
            relation foreach inst $insts {
                set idattrs [tuple get [relation tuple $inst]]
                foreach rv $delrelvars {
                    relvar deleteone $rv {*}$idattrs
                }
            }
            return $instref
        }
        proc migrate {rname instref subclass args} {
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref relvar inst
            SplitRelvarName $relvar domns class
        
            set link [relvar restrictone ${domns}::__Arch_AssociationLink Name $rname\
                    SrcClass $class]
            if {[relation isempty $link]} {
                tailcall DeclError NO_SUBCLASS $rname $relvar
            }
        
            # Traverse the relationship to the superclass. We need to get the values of
            # the referenced attributes to use in creating the new subclass instance.
            set superinst [pipe {
                relvar set ${domns}::[relation extract $link DstClass] |
                relation semijoin $inst ~ -using [relation extract $link Attrs]
            }]
        
            set sublink [relvar restrictone ${domns}::__Arch_SubLink\
                    Relationship $rname SubClass $subclass]
            if {[relation isempty $sublink]} {
                tailcall DeclError NO_SUBCLASS $rname $subclass
            }
        
            # Using the same relation extend strategy, we compute a dictionary of the
            # attribute names / values as they must appear in the subclass we are about
            # to create.
            set refedvalues [pipe {
                relation extract $sublink ReferringAttrs |
                relation extend ~ rval Value string {
                    [relation extract $superinst\
                        [tuple extract $rval ReferencedAttribute]]
                } |
                relation dict ~ ReferringAttribute Value
            }]
        
            # We use the class commands to delete the old subclass instance and create
            # the new one. This will make sure that if the subclass has a state model
            # that the initial state is set correctly.
            # N.B. this is _not_ done in a relvar transaction. The transaction
            # boundaries should be set by the current thread of control or domain
            # operation.
            ::rosea::InstCmds::delete $instref
            return [::rosea::ClassCmds::create ${domns}::$subclass\
                    {*}[dict merge $args $refedvalues]]
        }
        proc signalAssigner {rname event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set dstref [pipe {
                relvar set $assignrelvar |
                relation project ~ {*}[lindex [relvar identifiers $assignrelvar] 0] |
                list $rname ~
            }]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args
        
            return
        }
        proc signalMultiAssigner {rname idvalues event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            # We will insist that the idvalues contain the necessary identifying
            # attributes.
            if {![struct::set equal [dict keys $idvalues] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
            }
            set assigninsts [relvar set $assignrelvar]
            set assignrefs [relation project $assigninsts {*}$idattrs]
        
            # We need to find the tuple in "assignrefs" that matches the attributes and
            # values in "idvalues". We will do this by creating a relation value from
            # the idvalues list and semijoining that to "assignrefs". If we come up
            # non-empty, then we have found our multi-assigner instance.
            set heading [relation heading $assignrefs]
            set dstinst [pipe {
                tuple create $heading $idvalues |
                tuple relation ~ |
                relation semijoin ~ $assignrefs
            }]
            if {[relation isempty $dstinst]} {
                tailcall DeclError UNKNOWN_ASSIGNER $idvalues $rname
            }
        
            set dstref [list $rname $dstinst]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args ; # <1>
        
            return
        }
        proc createMultiAssigner {rname args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            CreateInInitialState $domain $relationship $args
        }
        proc deleteMultiAssigner {rname args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            relvar deleteone $assignrelvar {*}$args
            return
        }
    }
    namespace eval Dispatch {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        variable toc_queue [list]
        variable event_queue [list]
        relvar create DelayedSignal {
            RefId           int
            SrcInstRef      list
            Event           string
            DstInstRef      list
            TimerId         string
            Expire          bignum
        } RefId {SrcInstRef Event DstInstRef} TimerId
        variable DelayedSignalId 0
        pipe {
        relvar restrictone ${domain}::__Arch_Transition\
            Class $class State $currstate Event $event |
            relation extract ~ NewState
        } transitionQuery
        pipe {
            relvar set ${domain}::__Arch_PartitionDst |
            relation restrictwith ~ {$SrcClass eq $dstclass} |
            relation group ~ DstLinks DstClass Attrs
        } polymapQuery
        proc SignalEvent {srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isnotempty [relvar restrictone ${domain}::__Arch_Event\
                Class $class Event $event]]} {
                set eventType ordinary
            } elseif {[IsPolymorphicEvent $domain $class $event]} {
                set eventType polymorphic
            } else {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            set callback [namespace code DispatchEvent]
            set eventInfo [dict create\
                type $eventType\
                src $srcref\
                event $event\
                params $arglist\
            ]
            if {[isRefEqual $srcref [nilInstRef]]} {
                variable toc_queue
                forAllRefs dstref $dstset {
                    # Queue the thread of control events.
                    dict set eventInfo dst $dstref
                    lappend toc_queue $eventInfo
                    ::after 0 $callback
                }
            } else {
                variable event_queue
                forAllRefs dstref $dstset {
                    dict set eventInfo dst $dstref
                    if {[isRefEqual $srcref $dstref]} { # <1>
                        for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
                            set cmpevent [lindex $event_queue $eqindex]
                            if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
                                break
                            }
                        }
                        set event_queue [linsert [K $event_queue [set event_queue {}]]\
                            $eqindex $eventInfo] ; # <1>
                    } else {
                        # Non-self directed events are always simply appended to the
                        # event queue.
                        lappend event_queue $eventInfo
                    }
                    ::after 0 $callback
                }
            }
        }
        proc IsPolymorphicEvent {domain class event} {
            return [relation isnotempty [relvar restrictone\
                ${domain}::__Arch_PolymorphicEvent Class $class Event $event]]
        }
        proc DispatchEvent {} {
            variable event_queue
            variable toc_queue
            
            try {
                if {[llength $event_queue] != 0} {
                    set event_queue [lassign $event_queue eventInfo]
                    TransitionEvent $eventInfo
                } elseif {[llength $toc_queue] != 0} {
                    set toc_queue [lassign $toc_queue eventInfo]
                    relvar transaction begin ;                              # <1>
                    try {
                        TransitionEvent $eventInfo
                    } on error {result opts} {
                        catch {relvar transaction end} ;                    # <2>
                        return -level 0 -options $opts $result
                    }
                } else {
                    return
                }
            } on error {result opts} {
                return -options $opts $result
            }
            
            if {[llength $event_queue] == 0} {
                relvar transaction end
            }
            return
        }
        proc FindDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            return [relation restrictwith $DelayedSignal {
                    [isRefEqual $SrcInstRef $srcref] && $Event eq $event &&\
                    [isRefEqual $DstInstRef $dstref]}]
        }
        proc DeleteDelayedSignal {srcref event dstref} {
            relvar delete DelayedSignal dsig {
                [isRefEqual [tuple extract $dsig SrcInstRef] $srcref] &&\
                [tuple extract $dsig Event] eq $event &&\
                [isRefEqual [tuple extract $dsig DstInstRef] $dstref]
            }
        }
        proc SignalDelayedEvent {time srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            variable DelayedSignalId
            set eventInfo [dict create\
                id [incr DelayedSignalId]\
                type ordinary\
                src $srcref\
                event $event\
                params $arglist\
            ]
            forAllRefs dstref $dstset {
                dict set eventInfo dst $dstref
                DeleteDelayedSignal $srcref $event $dstref ; # <1>
                relvar insert DelayedSignal [list\
                    RefId       $DelayedSignalId\
                    SrcInstRef  $srcref\
                    Event       $event\
                    DstInstRef  $dstref\
                    TimerId     [::after $time [list\
                                ::rosea::Dispatch::DispatchDelayedEvent $eventInfo]]\
                    Expire      [expr {entier([clock milliseconds]) + entier($time)}]\
                ]
            }
            return
        }
        proc DispatchDelayedEvent {eventInfo} {
            relvar deleteone DelayedSignal RefId [dict get $eventInfo id]
            variable toc_queue
            lappend toc_queue $eventInfo
            tailcall DispatchEvent
        }
        proc CancelDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            set sig [FindDelayedSignal $srcref $event $dstref]
            if {[relation isnotempty $sig]} {
                ::after cancel [relation extract $sig TimerId]
                DeleteDelayedSignal $srcref $event $dstref
            } else {
                # Search the toc_queue to see if the signal delay has already expired
                # and the event is awaiting dispatch.
                variable toc_queue
                for {set i 0} {$i < [llength $toc_queue]} {incr i} {
                    set eventInfo [lindex $toc_queue $i]
                    dict update eventInfo src evtsrc dst evtdst event evtevent {
                        if {[isRefEqual $evtsrc $srcref] &&\
                                [isRefEqual $evtdst $dstref] &&\
                                $evtevent eq $event} {
                            set toc_queue [lreplace\
                                    [K $toc_queue [set toc_queue {}]] $i $i]
                            break
                        }
                    }
                }
            }
        }
        proc SignalTimeRemaining {srcref event dstref} {
            set sig [FindDelayedSignal $srcref $event $dstref]
            return [expr {[relation isempty $sig] ? 0 :\
                max([relation extract $sig Expire] - [clock milliseconds], 0)}] ; # <1>
        }
        proc TransitionEvent {eventInfo} {
            switch -exact -- [dict get $eventInfo type] {
                ordinary {
                    TransitionOrdinaryEvent $eventInfo
                }
                creation {
                    TransitionCreationEvent $eventInfo
                }
                polymorphic {
                    TransitionPolymorphicEvent $eventInfo
                }
                default {
                    tailcall DeclError UNKNOWN_EVENT_TYPE [dict get $eventInfo type]
                }
            }
        }
        proc TransitionOrdinaryEvent {eventInfo} {
            variable event_queue
            set dstref [dict get $eventInfo dst]
            lassign $dstref relvar ref
            SplitRelvarName $relvar domain class
            
            set instrelvar ${domain}::${class}__STATEINST
            set state [relation semijoin $ref [relvar set $instrelvar]]
            if {[relation isempty $state]} {
                tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
            }
            set currstate [relation extract $state __State]
            set event [dict get $eventInfo event]
            variable transitionQuery
            set newState [eval $transitionQuery]
            
            ::rosea::Trace::TraceTransition [dict get $eventInfo src]\
                $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
            if {$newState eq "CH"} {
                TransitionError [dict get $eventInfo src] $event $dstref $currstate
            } elseif {$newState ne "IG"} {
                set idattrs [tuple get [relation tuple $ref]]
                relvar updateone $instrelvar is $idattrs {
                    tuple update $is __State $newState
                }
                try {
                    ${relvar}::__Activity::$newState $dstref\
                            {*}[dict get $eventInfo params] ; # <1>
                } on error {result opts} {
                    chan puts stderr $::errorInfo
                    return -options $opts $result
                } finally {
                    set term [relvar restrictone ${domain}::__Arch_TerminalState\
                            Class $class State $newState]
                    if {[relation isnotempty $term]} {
                        relvar deleteone $relvar {*}$idattrs
                        relvar deleteone $instrelvar {*}$idattrs
                    }
                }
            }
            return
        }
        proc TransitionError {src event dst currstate} {
            tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
        }
        proc TransitionCreationEvent {eventInfo} {
            try {
                set dstref [::rosea::ClassCmds::createin\
                        [dict get $eventInfo dstClass] @\
                        {*}[dict get $eventInfo dstAttrs]] ; # <1>
            } on error {result opts} {
                tailcall DeclError ASYNC_CREATION_FAILED\
                        [dict get $eventInfo dstClass]\
                        [dict get $eventInfo dstAttrs] $result
                return -options $opts $result
            }
            ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
                [dict get $eventInfo event] $dstref [dict get $eventInfo params]
            dict set eventInfo type ordinary
            dict set eventInfo dst $dstref ; # <2>
            TransitionOrdinaryEvent $eventInfo
        }
        proc TransitionPolymorphicEvent {eventInfo} {
            lassign [dict get $eventInfo dst] dstrelvar inst
            SplitRelvarName $dstrelvar domain dstclass
            set event [dict get $eventInfo event]
        
            variable polymapQuery
            set partitions [eval $polymapQuery]
            relation foreach partition $partitions {
                relation assign $partition
                relation foreach dstlink $DstLinks {
                    relation assign $dstlink
                    set related [relation semijoin $inst\
                        [relvar set ${domain}::$DstClass] -using $Attrs]
                    if {[relation isnotempty $related]} {
                        set dstreference [ToRef ${domain}::${DstClass} $related]
                        set target [ToRef $dstrelvar $inst]
                        set srcref [dict get $eventInfo src]
                        ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\
                                [dict get $eventInfo params]
                    
                        set mappedInfo $eventInfo ;                                 # <1>
                        dict set mappedInfo src $target
                        dict set mappedInfo dst $dstreference
                        if {[IsPolymorphicEvent $domain $DstClass $event]} {
                            TransitionPolymorphicEvent $mappedInfo
                        } else {
                            dict set eventInfo type ordinary
                            TransitionOrdinaryEvent $mappedInfo
                        }
                        break
                    }
                }
            }
        }
    }
    namespace eval Config {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers
        variable evalLambda {{body} {
            upvar #0 ::rosea::Config::errcount errcount ; # <1>
            upvar #0 ::rosea::Config::configlineno configlineno
            set lineno $configlineno
            set command {}
            foreach line [split $body \n] { # <2>
                append command $line \n
                incr lineno ; # <3>
                if {[info complete $command]} {
                    try {
                        eval $command
                    } on error {result} {
                        log::error "line $configlineno: \"$result\""
                        incr errcount
                    }
                    set command {} ; # <4>
                    set configlineno $lineno
                }
            }
            return $errcount
        }}
        relvar create Domain {
            Name        string
            Location    string
        } Name
        relvar create DomainElement {
            Domain  string
            Element string
        } {Domain Element}
        relvar association R1\
            DomainElement Domain *\
            Domain Name 1
        relvar create Class {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create Relationship {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create DomainOperation {
            Domain      string
            Name        string
            Parameters  list
            Body        string
        } {Domain Name}
        relvar partition R2 DomainElement {Domain Element}\
            Class {Domain Name}\
            Relationship {Domain Name}\
            DomainOperation {Domain Name}
        relvar create Attribute {
            Domain  string
            Class   string
            Name    string
            Type    string
        } {Domain Class Name}
        relvar association R3\
            Attribute {Domain Class} +\
            Class {Domain Name} 1
        relvar create Identifier {
            Domain  string
            Class   string
            Number  int
        } {Domain Class Number}
        relvar association R4\
            Identifier {Domain Class} +\
            Class {Domain Name} 1
        relvar create IdentifyingAttribute {
            Domain      string
            Class       string
            Attribute   string
            Number      int
        } {Domain Class Attribute Number}
        relvar correlation R5 IdentifyingAttribute\
            {Domain Class Number} + Identifier {Domain Class Number}\
            {Domain Class Attribute} * Attribute {Domain Class Name}
        relvar create DefaultValue {
            Domain      string
            Class       string
            Attribute   string
        } {Domain Class Attribute}
        relvar association R6\
            DefaultValue {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create UserSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            Value       string
        } {Domain Class Attribute}
        relvar create SystemSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            StartValue  int
        } {Domain Class Attribute}
        relvar create GeneratedValue {
            Domain      string
            Class       string
            Attribute   string
            Cmd         string
        } {Domain Class Attribute}
        relvar partition R18 DefaultValue {Domain Class Attribute}\
            UserSuppliedValue {Domain Class Attribute}\
            SystemSuppliedValue {Domain Class Attribute}\
            GeneratedValue {Domain Class Attribute}
        relvar create ValueCheck {
            Domain      string
            Class       string
            Attribute   string
            Expression  string
        } {Domain Class Attribute}
        relvar association R17\
            ValueCheck {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create AttributeReference {
            Domain              string
            ReferringClass      string
            ReferringAttribute  string
            ReferringRole       string
            ReferencedClass     string
            ReferencedAttribute string
            ReferencedRole      string
            ReferencedIdNumber  int
            Relationship        string
        } {Domain ReferringClass ReferringAttribute ReferringRole\
            ReferencedClass ReferencedAttribute ReferencedRole ReferencedIdNumber\
            Relationship}
        relvar association R13\
            AttributeReference {Domain ReferringClass ReferringAttribute} *\
            Attribute {Domain Class Name} 1
        relvar create ReferencedIdAttribute {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Attribute       string
            Number          int
        } {Domain Class Relationship Role Attribute Number}
        relvar create Operation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar association R8\
            Operation {Domain Class} * Class {Domain Name} 1
        
        relvar create InstanceOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar create ClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R7 Operation {Domain Class Name}\
            InstanceOperation {Domain Class Name}\
            ClassOperation {Domain Class Name}
        
        relvar create UserInstanceOperation {
            Domain      string
            Class       string
            Name        string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemInstanceOperation {
            Domain      string
            Class       string
            Name        string
        } {Domain Class Name}
        
        relvar partition R9 InstanceOperation {Domain Class Name}\
            UserInstanceOperation {Domain Class Name}\
            SystemInstanceOperation {Domain Class Name}
        
        relvar create UserClassOperation {
            Domain  string
            Class   string
            Name    string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R10 ClassOperation {Domain Class Name}\
            UserClassOperation {Domain Class Name}\
            SystemClassOperation {Domain Class Name}
        
        relvar create SuppliedOperation {
            Name                string
            Command             string
            RequiresStateModel  boolean
        } Name
        
        relvar create SuppliedClassOperation {
            Name    string
        } Name
        
        relvar create SuppliedInstanceOperation {
            Name    string
        } Name
        
        relvar partition R14 SuppliedOperation Name\
            SuppliedClassOperation Name\
            SuppliedInstanceOperation Name
        
        relvar association R15\
            SystemClassOperation Name *\
            SuppliedClassOperation Name 1
        
        relvar association R16\
            SystemInstanceOperation Name *\
            SuppliedInstanceOperation Name 1
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findAll
                Command             ::rosea::ClassCmds::findAll
                RequiresStateModel  false
            } {
                Name                findById
                Command             ::rosea::ClassCmds::findById
                RequiresStateModel  false
            } {
                Name                findWhere
                Command             ::rosea::ClassCmds::findWhere
                RequiresStateModel  false
            } {
                Name                create
                Command             ::rosea::ClassCmds::create
                RequiresStateModel  false
            } {
                Name                createin
                Command             ::rosea::ClassCmds::createin
                RequiresStateModel  true
            } {
                Name                createasync
                Command             ::rosea::ClassCmds::createasync
                RequiresStateModel  true
            } {
                Name                update
                Command             ::rosea::ClassCmds::update
                RequiresStateModel  false
            }
        
            relvar insert SuppliedClassOperation {
                Name    findAll
            } {
                Name    findById
            } {
                Name    findWhere
            } {
                Name    create
            } {
                Name    createin
            } {
                Name    createasync
            } {
                Name    update
            }
        }
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findRelated
                Command             ::rosea::InstCmds::findRelated
                RequiresStateModel  false
            } {
                Name                findUnrelated
                Command             ::rosea::InstCmds::findById
                RequiresStateModel  false
            } {
                Name                findRelatedWhere
                Command             ::rosea::InstCmds::findRelatedWhere
                RequiresStateModel  false
            } {
                Name                findUnrelatedWhere
                Command             ::rosea::InstCmds::findUnrelatedWhere
                RequiresStateModel  false
            } {
                Name                updateAttribute
                Command             ::rosea::InstCmds::updateAttribute
                RequiresStateModel  false
            } {
                Name                withAttribute
                Command             ::rosea::InstCmds::withAttribute
                RequiresStateModel  false
            } {
                Name                readAttribute
                Command             ::rosea::InstCmds::readAttribute
                RequiresStateModel  false
            } {
                Name                assignAttribute
                Command             ::rosea::InstCmds::assignAttribute
                RequiresStateModel  false
            } {
                Name                delete
                Command             ::rosea::InstCmds::delete
                RequiresStateModel  false
            } {
                Name                signal
                Command             ::rosea::InstCmds::signal
                RequiresStateModel  true
            } {
                Name                delaysignal
                Command             ::rosea::InstCmds::delaysignal
                RequiresStateModel  true
            } {
                Name                canceldelayed
                Command             ::rosea::InstCmds::canceldelayed
                RequiresStateModel  true
            } {
                Name                delayremaining
                Command             ::rosea::InstCmds::delayremaining
                RequiresStateModel  true
            } {
                Name                instop
                Command             ::rosea::InstCmds::instop
                RequiresStateModel  false
            } {
                Name                deRef
                Command             ::rosea::InstCmds::deRef
                RequiresStateModel  false
            } {
                Name                isEmptyRef
                Command             ::rosea::InstCmds::isEmptyRef
                RequiresStateModel  false
            } {
                Name                isNotEmptyRef
                Command             ::rosea::InstCmds::isNotEmptyRef
                RequiresStateModel  false
            } {
                Name                refMultiplicity
                Command             ::rosea::InstCmds::refMultiplicity
                RequiresStateModel  false
            } {
                Name                isRefSingular
                Command             ::rosea::InstCmds::isRefSingular
                RequiresStateModel  false
            } {
                Name                limitRef
                Command             ::rosea::InstCmds::limitRef
                RequiresStateModel  false
            } {
                Name                isRefEqual
                Command             ::rosea::InstCmds::isRefEqual
                RequiresStateModel  false
            } {
                Name                forAllRefs
                Command             ::rosea::InstCmds::forAllRefs
                RequiresStateModel  false
            }
        
            relvar insert SuppliedInstanceOperation {
                Name    findRelated
            } {
                Name    findUnrelated
            } {
                Name    findRelatedWhere
            } {
                Name    findUnrelatedWhere
            } {
                Name    updateAttribute
            } {
                Name    withAttribute
            } {
                Name    readAttribute
            } {
                Name    assignAttribute
            } {
                Name    delete
            } {
                Name    signal
            } {
                Name    delaysignal
            } {
                Name    canceldelayed
            } {
                Name    delayremaining
            } {
                Name    instop
            } {
                Name    deRef
            } {
                Name    isEmptyRef
            } {
                Name    isNotEmptyRef
            } {
                Name    refMultiplicity
            } {
                Name    isRefSingular
            } {
                Name    limitRef
            } {
                Name    isRefEqual
            } {
                Name    forAllRefs
            }
        }
        relvar create Association {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create Generalization {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R30 Relationship {Domain Name}\
            Association {Domain Name}\
            Generalization {Domain Name}
        relvar create SimpleAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create ClassBasedAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R31 Association {Domain Name}\
            SimpleAssociation {Domain Name}\
            ClassBasedAssociation {Domain Name}
        relvar create SimpleReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R32\
            SimpleReferringClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SimpleReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
        } {Domain Class Relationship Role}
        relvar association R33\
            SimpleReferencedClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SourceClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R34\
            SourceClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create TargetClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R35\
            TargetClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create AssociatorClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R42\
            AssociatorClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create Superclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R36\
            Superclass {Domain Relationship} 1\
            Generalization {Domain Name} 1
        relvar create Subclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R37\
            Subclass {Domain Relationship} +\
            Generalization {Domain Name} 1
        relvar create ReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R38 ReferringClass {Domain Class Relationship Role}\
            SimpleReferringClass {Domain Class Relationship Role}\
            AssociatorClass {Domain Class Relationship Role}\
            Subclass {Domain Class Relationship Role}
        relvar create ReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R39 ReferencedClass {Domain Class Relationship Role}\
            SimpleReferencedClass {Domain Class Relationship Role}\
            SourceClass {Domain Class Relationship Role}\
            TargetClass {Domain Class Relationship Role}\
            Superclass {Domain Class Relationship Role}
        relvar create ClassRole {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R40 ClassRole {Domain Class Relationship Role}\
            ReferringClass {Domain Class Relationship Role}\
            ReferencedClass {Domain Class Relationship Role}
        relvar correlation R41 ClassRole\
            {Domain Relationship} + Relationship {Domain Name}\
            {Domain Class} * Class {Domain Name}
        relvar correlation R11 ReferencedIdAttribute\
            {Domain Class Relationship Role} +\
                ReferencedClass {Domain Class Relationship Role}\
            {Domain Class Attribute Number} *\
                IdentifyingAttribute {Domain Class Attribute Number}
        relvar correlation R12 AttributeReference\
            {Domain ReferringClass Relationship ReferringRole} +\
                ReferringClass {Domain Class Relationship Role}\
            {Domain ReferencedClass Relationship ReferencedRole ReferencedAttribute\
                    ReferencedIdNumber} +\
                ReferencedIdAttribute {Domain Class Relationship Role Attribute Number}
        relvar create Config_AssocSpec {
            Spec                string
            NeedsAssociator     boolean
            ReflexiveAllowed    boolean
            ReferringCond       boolean
            ReferringMult       boolean
            ReferencedCond      boolean
            ReferencedMult      boolean
        } Spec
        
        relvar insert Config_AssocSpec {
            Spec 1--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..*--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 1..*--0..1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 0..*--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 0..*--1..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 1..*--0..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec 0..*--0..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec ?--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec ?--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec +--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec *--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec +--? NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec *--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec +--+ NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec *--+ NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec +--* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec *--* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        }
        relvar create Config_ClassAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_NonReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            TargetClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexivePath {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            SourceAttr          string
            TargetAttr          string
        } {Domain Relationship AssocClass SourceClass SourceAttr}
        relvar partition Config1\
            Config_ClassAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_NonReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_ReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}
        relvar association Config2\
            Config_ReflexivePath {Domain Relationship AssocClass SourceClass} +\
            Config_ReflexiveAssoc {Domain Relationship AssocClass SourceClass} 1
        pipe {
            relvar set ::rosea::Config::AttributeReference |
            relation project ~ Domain ReferencedClass Relationship ReferencedRole\
                    ReferencedAttribute ReferencedIdNumber |
            relation rename ~ ReferencedClass Class ReferencedRole Role\
                    ReferencedAttribute Attribute ReferencedIdNumber Number |
            relvar union ::rosea::Config::ReferencedIdAttribute
        } refIdQuery
        relvar create StateModel {
            Domain          string
            Model           string
            InitialState    string
            DefaultTrans    string
        } {Domain Model}
        
        relvar create InstanceStateModel {
            Domain          string
            Class           string
        } {Domain Class}
        
        relvar association R51\
            InstanceStateModel {Domain Class} ?\
            Class {Domain Name} 1
        
        relvar create AssignerStateModel {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar association R52\
            AssignerStateModel {Domain Relationship} ?\
            Association {Domain Name} 1
        
        relvar partition R50 StateModel {Domain Model}\
            InstanceStateModel {Domain Class}\
            AssignerStateModel {Domain Relationship}
        
        relvar create SingleAssigner {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar create MultipleAssigner {
            Domain          string
            Relationship    string
            Class           string
            Number          int
        } {Domain Relationship}
        
        relvar partition R53 AssignerStateModel {Domain Relationship}\
            SingleAssigner {Domain Relationship}\
            MultipleAssigner {Domain Relationship}
        
        relvar association R54\
            MultipleAssigner {Domain Class Number} ?\
            Identifier {Domain Class Number} 1
        
        relvar create State {
            Domain          string
            Model           string
            Name            string
            Parameters      string
            Action          string
            IsFinal         boolean
        } {Domain Model Name}
        
        relvar association R55\
            State {Domain Model} +\
            StateModel {Domain Model} 1
        
        relvar association R58\
            StateModel {Domain Model InitialState} ?\
            State {Domain Model Name} 1
        
        relvar create TransitionRule {
            Name    string
        } Name
        
        relvar insert TransitionRule {Name IG} {Name CH}
        
        relvar association R59\
            StateModel DefaultTrans *\
            TransitionRule Name 1
        
        relvar create CreationState {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar create StatePlace {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar partition R57 StatePlace {Domain Model Name}\
            State {Domain Model Name}\
            CreationState {Domain Model Name}
        relvar create Event {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create DeferredEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create EffectiveEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R80 Event {Domain Model Event}\
            DeferredEvent {Domain Model Event}\
            EffectiveEvent {Domain Model Event}
        
        relvar create DeferralPath {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event Relationship Role}
        
        relvar correlation R86 DeferralPath\
            {Domain Model Event} + DeferredEvent {Domain Model Event}\
            {Domain Model Relationship Role} * Superclass\
                {Domain Class Relationship Role}
        
        relvar create PolymorphicEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create InheritedEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R81 DeferredEvent {Domain Model Event}\
            PolymorphicEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar create MappedEvent {
            Domain      string
            Model       string
            Event       string
            ParentModel string
        } {Domain Model Event}
        
        relvar association R84\
            MappedEvent {Domain ParentModel Event} *\
            DeferredEvent {Domain Model Event} 1
        
        relvar create LocalEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R82 EffectiveEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            LocalEvent {Domain Model Event}
        
        relvar create NonLocalEvent {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event}
        
        relvar partition R83 NonLocalEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar association R85\
            NonLocalEvent {Domain Model Relationship Role} *\
            Subclass {Domain Class Relationship Role} 1
        
        relvar association R87\
            EffectiveEvent {Domain Model} +\
            StateModel {Domain Model} 1
        relvar create TransitionPlace {
            Domain  string
            Model   string
            State   string
            Event   string
        } {Domain Model State Event}
        
        relvar correlation R70 TransitionPlace\
            {Domain Model State} * StatePlace {Domain Model Name}\
            {Domain Model Event} * EffectiveEvent {Domain Model Event}
        
        relvar create StateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            NewState    string
        } {Domain Model State Event}
        
        relvar create NonStateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            TransRule   string
        } {Domain Model State Event}
        
        relvar partition R71 TransitionPlace {Domain Model State Event}\
            StateTransition {Domain Model State Event}\
            NonStateTransition {Domain Model State Event}
        
        relvar association R72\
            StateTransition {Domain Model NewState} *\
            State {Domain Model Name} 1
        
        relvar association R73\
            NonStateTransition TransRule *\
            TransitionRule Name 1
        relvar create Config_DataError {
            Relationship        string
            RefClass            string
            RefType             string
            Format              string
        } {Relationship RefClass RefType}
        relvar insert Config_DataError {
            Relationship        R3
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no attributes}
        } {
            Relationship        R4
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no identifiers}
        } {
            Relationship        R11
            RefClass            ReferencedClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", for relationship,\
                                \"$Relationship\", no class has defined a reference\
                                to class, \"$Class\"}
        } {
            Relationship        R11
            RefClass            ReferencedIdAttribute
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references attribute,\
                                \"$Attribute\", in class, \"$Class\", which is\
                                not an identifying attribute, does not exist\
                                or \"$Relationship\" does not exist}
        } {
            Relationship        R12
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                refers to, \"$ReferencedAttribute\", in class,\
                                \"$ReferencedClass\", but the class, attribute or\
                                relationship does not exist}
        } {
            Relationship        R12
            RefClass            ReferringClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", in class, \"$Class\",\
                                makes a reference along relationship,\
                                \"$Relationship\", but $Class does not pariticipate\
                                in $Relationship}
        } {
            Relationship        R13
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                does not exist, but is used as a referential attribute}
        } {
            Relationship        R41
            RefClass            ClassRole
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references class, \"$Class\",\
                                which does not exist}
        } {
            Relationship        R52
            RefClass            AssignerStateModel
            RefType             refnone
            Format              {in domain, \"$Domain\", an assigner state model is\
                                defined on relationship, \"$Relationship\", which is\
                                not an association type relationship}
        } {
            Relationship        R70
            RefClass            TransitionPlace
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains a transition for event,\
                                \"$Event\", but $Event was a polymorphic event\
                                consumed by a superclass of $Model}
        } {
            Relationship        R72
            RefClass            StateTransition
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains the transition,\
                                \"$State - $Event -> $NewState\",\
                                but state \"$NewState\" does not exist}
        } {
            Relationship        R81
            RefClass            DeferredEvent
            RefType             multrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is both an inherited\
                                polymorphic event and a locally defined one}
        } {
            Relationship        R86
            RefClass            DeferredEvent
            RefType             notrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is defined as\
                                polymorphic but \"$Model\" is not a superclass\
                                of a generalization}
        } {
            Relationship        R87
            RefClass            EffectiveEvent
            RefType             refnone
            Format              {in domain, \"$Domain\", event, \"$Event\" has been\
                                inherited, but no state model exists for, \"$Model\"}
        }
        namespace export ConfigEvaluate
        
        proc ConfigEvaluate {ns body} {
            variable evalLambda
            tailcall ::apply [concat $evalLambda [list $ns]] $body ; # <1>
        }
        proc domain {name body} {
            namespace upvar DomainDef DomainName DomainName ; # <1>
            set DomainName $name
        
            relvar insert ::rosea::Config::Domain [list Name $name Location {}]
            try {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME domain
                }
        
                relvar eval { # <2>
                    ConfigEvaluate [namespace current]::DomainDef $body
        
                    # At this point we have the definition of the domain and enough
                    # information to tie together the referential attributes and
                    # the association definitions.
                    variable Config_NonReflexiveAssoc
                    
                    relation foreach nra $Config_NonReflexiveAssoc {
                        relation assign $nra
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferencedClass] eq $SourceClass
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable Config_ReflexivePath
                    
                    relation foreach rp $Config_ReflexivePath {
                        relation assign $rp
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferringAttribute] eq $SourceAttr
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable refIdQuery
                    
                    eval $refIdQuery
        
                    # We must also compute how polymorphic events are inherited
                    # down generalization hierarchies.
                    # Create Deferral Path instances
                    
                    variable PolymorphicEvent
                    variable DeferredEvent
                    variable Superclass
                    variable Subclass
                    variable DeferralPath
                    
                    set dpaths [pipe {
                        relation restrictwith $PolymorphicEvent {$Domain eq $name} |
                        relation semijoin ~ $DeferredEvent |
                        relation join ~ $Superclass -using {Domain Domain Model Class}
                    }]
                    relvar insert ::rosea::Config::DeferralPath {*}[relation body $dpaths]
                    set supers [relation semiminus $Subclass $Superclass\
                        -using {Domain Domain Class Class}]
                    
                    relation foreach super $supers {
                        PropagatePolyEvents $super
                    }
                }
            } on error {result} {
                # puts $::errorInfo
                ::rosea::Config::HandleConfigError $result
            }
        }
        proc HandleConfigError {result} {
            set lines [split [string trimright $result] \n]
            set nlines [llength $lines]
            set lineno 0
            upvar #0 ::rosea::Config::errcount errcount
            while {$lineno < $nlines} {
                set line [lindex $lines $lineno]
                incr lineno
                if {[regexp {^for[^:]+([^(]+)\(.+\), in relvar (.+)$} $line\
                        match rnum refclass]} {
                    set rnum [namespace tail $rnum]
                    set refclass [namespace tail $refclass]
                
                    # Now iterate over the "tuple" lines that follow the constraint message.
                    while {$lineno < $nlines} {
                        set tupline [lindex $lines $lineno]
                        if {[regexp {^tuple {(.+)} (.+)$} $tupline match tuple phrase]} {
                            incr lineno
                            incr errcount
                            if {[string match {is not referenced*} $phrase]} {
                                set reftype notrefed
                            } elseif {[string match {references no*} $phrase]} {
                                set reftype refnone
                            } elseif {[string match {*to by multiple*} $phrase]} {
                                set reftype multrefed
                            } elseif {[string match {is not referred to*} $phrase]} {
                                set reftype notrefto
                            } else {
                                log::error "unknown constraint phrasing, \"$phrase\""
                                continue
                            }
                            set cde [relvar restrictone Config_DataError Relationship $rnum RefClass\
                                    $refclass RefType $reftype]
                            if {[relation isnotempty $cde]} {
                                dict with tuple {
                                    log::error [subst -nocommands [relation extract $cde Format]]
                                }
                            } else {
                                log::error "$line\n$tupline"
                            }
                        } else {
                            break
                        }
                    }
                } else {
                    log::error "unknown configuration error, \"$result\""
                }
            }
        
            return
        }
        namespace eval DomainDef {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace import ::rosea::Config::ConfigEvaluate
            namespace import ::rosea::Helpers::DeclError
            proc class {name body} {
                namespace upvar [namespace current] DomainName DomainName ; # <1>
                namespace upvar ClassDef ClassName ClassName
                set ClassName $name
            
                if {![regexp {\A[[:alnum:]].*} $name]} {
                    tailcall DeclError BAD_CLASS_NAME $name
                }
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                } ; # <2>
                relvar insert ::rosea::Config::Class [list\
                    Domain  $DomainName\
                    Name    $name\
                ]
                set instops [pipe {
                    relvar set ::rosea::Config::SuppliedInstanceOperation |
                    relation extend ~ ioptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemInstanceOperation $instops
                relvar union ::rosea::Config::InstanceOperation $instops
                relvar union ::rosea::Config::Operation $instops
                set classops [pipe {
                    relvar set ::rosea::Config::SuppliedClassOperation |
                    relation extend ~ coptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemClassOperation $classops
                relvar union ::rosea::Config::ClassOperation $classops
                relvar union ::rosea::Config::Operation $classops
            
                ConfigEvaluate [namespace current]::ClassDef $body
            }
            proc association {name source spec target args} {
                if {[llength $args] % 2 != 0} {
                    tailcall DeclError ARG_FORMAT $args
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME association
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                # Obtain references to the domain and class context.
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
            
                set associator {}
                set path {}
                
                foreach {option value} $args {
                    switch -exact -- $option {
                        -associator {
                            set associator $value
                        }
                        -path {
                            set path $value
                            if {[llength $path] % 2 != 0} {
                                tailcall DeclError ARG_FORMAT $path
                            }
                        }
                        default {
                            tailcall DeclError UNKNOWN_OPTION association $option
                        }
                    }
                }
                set cas [relvar restrictone ::rosea::Config::Config_AssocSpec Spec $spec]
                if {[relation isempty $cas]} {
                    tailcall DeclError BAD_RELATIONSHIP_SPEC $spec
                }
                set needsassoc [relation extract $cas NeedsAssociator]
                if {$needsassoc && $associator eq {}} {
                    tailcall DeclError NEED_ASSOCIATOR $spec
                }
                if {$source eq $target} {
                    if {![relation extract $cas ReflexiveAllowed]} {
                        tailcall DeclError REFLEXIVE_NOT_ALLOWED $spec
                    }
                    if {$needsassoc && $path eq {}} {
                        tailcall DeclError NEED_REFLEXIVE_PATH $name $source $spec $target
                    }
                }
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                # Many relvars have tuples with the same heading, so we construct it
                # once here.
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
            
                # Populate the data for a Relationship and Association since that
                # is what this command defines.
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Association $reltuple
            
                # Populate the type of association we are dealing with.
                if {$associator eq {}} {
                    relvar insert ::rosea::Config::SimpleAssociation $reltuple
                    relvar insert ::rosea::Config::SimpleReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::SimpleReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                } else {
                    relvar insert ::rosea::Config::Config_ClassAssoc [list\
                        Domain              $DomainName\
                        Relationship        $name\
                        AssocClass          $associator\
                        SourceClass         $source\
                    ]
                    if {[llength $path] == 0} {
                        relvar insert ::rosea::Config::Config_NonReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                            TargetClass         $target\
                        ]
                    } else {
                        relvar insert ::rosea::Config::Config_ReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                        ]
                        foreach {sourceattr targetattr} $path {
                            relvar insert ::rosea::Config::Config_ReflexivePath [list\
                                Domain              $DomainName\
                                Relationship        $name\
                                AssocClass          $associator\
                                SourceClass         $source\
                                SourceAttr          $sourceattr\
                                TargetAttr          $targetattr\
                            ]
                        }
                    }
                    
                    relvar insert ::rosea::Config::ClassBasedAssociation $reltuple
                    relvar insert ::rosea::Config::SourceClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::TargetClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                        Multiplicity    [relation extract $cas ReferencedMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::AssociatorClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                }
            }
            proc generalization {name super args} {
                if {[llength $args] < 2} {
                    tailcall DeclError TOO_FEW_SUBCLASSES [llength $args]
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME generalization
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Generalization $reltuple
            
                set supertuple [list\
                    Domain          $DomainName\
                    Class           $super\
                    Relationship    $name\
                    Role            target\
                ]
                relvar insert ::rosea::Config::Superclass $supertuple
                relvar insert ::rosea::Config::ReferencedClass $supertuple
                relvar insert ::rosea::Config::ClassRole $supertuple
            
                set subtuple [dict create\
                    Domain          $DomainName\
                    Relationship    $name\
                    Role            source\
                ]
                foreach sub $args {
                    dict set subtuple Class $sub
                    relvar insert ::rosea::Config::Subclass $subtuple
                    relvar insert ::rosea::Config::ReferringClass $subtuple
                    relvar insert ::rosea::Config::ClassRole $subtuple
                }
            }
            proc assigner {rname body} {
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar AssignerDef\
                    RelationshipName RelationshipName\
                    multiClass multiClass\
                    multiIdNum multiIdNum\
                    InitialState InitialState\
                    DefaultTrans DefaultTrans
            
                set RelationshipName $rname
                set multiClass {}
                set multiIdNum 1
                set InitialState {}
                set DefaultTrans {}
            
                try {
                    ConfigEvaluate [namespace current]::AssignerDef $body
            
                    if {$DefaultTrans eq {}} {
                        set DefaultTrans CH
                    }
                    relvar insert ::rosea::Config::StateModel [list\
                        Domain          $DomainName\
                        Model           $rname\
                        InitialState    $InitialState\
                        DefaultTrans    $DefaultTrans\
                    ]
                    set assigntuple [list\
                        Domain          $DomainName\
                        Relationship    $rname\
                    ]
                    relvar insert ::rosea::Config::AssignerStateModel $assigntuple
                    if {$multiClass eq {}} {
                        relvar insert ::rosea::Config::SingleAssigner $assigntuple
                    } else {
                        lappend assigntuple Class $multiClass Number $multiIdNum
                        relvar insert ::rosea::Config::MultipleAssigner $assigntuple
                    }
                } on error {result opts} {
                    log::error $result
                    upvar #0 ::rosea::Config::errcount errcount
                    incr errcount
                }
            }
            proc operation {name params body} {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME operation
                }
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain      $DomainName\
                        Element     $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
                relvar insert ::rosea::Config::DomainOperation [list\
                    Domain      $DomainName\
                    Name        $name\
                    Parameters  $params\
                    Body        $body\
                ]
            }
        
            namespace eval ClassDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc attribute {name type args} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME attribute
                    }
                    if {[string range $name 0 1] eq "__"} {
                        tailcall DeclError RESERVED_NAME $name
                    }
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    relvar insert ::rosea::Config::Attribute [list\
                        Domain  $DomainName\
                        Class   $ClassName\
                        Name    $name\
                        Type    $type\
                    ]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -default {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::UserSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Value       $value\
                                ]
                            }
                            -system {
                                if {$type ne "int"} {
                                    tailcall DeclError INT_TYPE_REQUIRED $type
                                }
                                if {![string is integer -strict $value]} {
                                    tailcall DeclError INT_VALUE_REQUIRED $value
                                }
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::SystemSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    StartValue  $value\
                                ]
                            }
                            -generate {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::GeneratedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Cmd         $value\
                                ]
                            }
                            -id {
                                relvar uinsert ::rosea::Config::Identifier [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Number      $value\
                                ] ; # <1>
                                relvar insert ::rosea::Config::IdentifyingAttribute [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Number      $value\
                                ]
                            }
                            -check {
                                relvar insert ::rosea::Config::ValueCheck [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Expression  $value\
                                ]
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION attribute $option
                            }
                        }
                    }
                }
                proc reference {relname rclass args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set refnum 1
                    set linkopts [list]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -refid {
                                set refnum $value
                            }
                            -link {
                                if {[llength $value] < 1 || [llength $value] > 2} {
                                    tailcall DeclError ARG_FORMAT $value
                                }
                                lappend linkopts $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION reference $option
                            }
                        }
                    }
                
                    # We defer processing the link options until the end so as not
                    # to impose an order on the -refid option.
                    foreach linkopt $linkopts {
                        lassign $linkopt referring referenced
                        if {$referenced eq {}} {
                            set referenced $referring
                        }
                        relvar insert ::rosea::Config::AttributeReference [list\
                            Domain              $DomainName\
                            ReferringClass      $ClassName\
                            ReferringAttribute  $referring\
                            ReferringRole       source\
                            ReferencedClass     $rclass\
                            ReferencedAttribute $referenced\
                            ReferencedRole      target\
                            ReferencedIdNumber  $refnum\
                            Relationship        $relname
                        ] ; # <1>
                    }
                }
                proc classop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "class operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::ClassOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserClassOperation $optuple
                }
                proc instop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "instance operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::InstanceOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserInstanceOperation $optuple
                }
                proc statemodel {body} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    variable ClassName
                
                    namespace upvar StateModelDef\
                        InitialState InitialState\
                        DefaultTrans DefaultTrans\
                        Terminals Terminals
                
                    set InitialState {}
                    set DefaultTrans {}
                    set Terminals [list]
                
                    try {
                        ConfigEvaluate [namespace current]::StateModelDef $body
                
                        if {$DefaultTrans eq {}} {
                            set DefaultTrans CH
                        }
                        relvar insert ::rosea::Config::StateModel [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            InitialState    $InitialState\
                            DefaultTrans    $DefaultTrans\
                        ]
                        relvar insert ::rosea::Config::InstanceStateModel [list\
                            Domain          $DomainName\
                            Class           $ClassName\
                        ]
                
                        foreach terminal $Terminals {
                            relvar updateone ::rosea::Config::State stup [list\
                                    Domain $DomainName Model $ClassName Name $terminal] {
                                tuple update $stup IsFinal true
                            }
                        }
                    } on error {result opts} {
                        log::error $result
                        upvar #0 ::rosea::Config::errcount errcount
                        incr errcount
                    }
                }
                proc polymorphic {args} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    foreach polyevent $args {
                        set eventtuple [list\
                            Domain $DomainName\
                            Model $ClassName\
                            Event $polyevent\
                        ]
                        relvar insert ::rosea::Config::PolymorphicEvent $eventtuple
                        relvar insert ::rosea::Config::DeferredEvent $eventtuple
                        relvar insert ::rosea::Config::Event $eventtuple
                    }
                    return
                }
            
                namespace eval StateModelDef {
                    logger::initNamespace [namespace current]
                
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                    namespace import ::ral::relvar
                    namespace import ::rosea::Config::ConfigEvaluate
                    namespace import ::rosea::Helpers::DeclError
                
                    proc state {name params body} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME state
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name state
                        }
                    
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        variable InitialState
                    
                        if {$InitialState eq {}} {
                            set InitialState $name
                        }
                    
                        relvar insert ::rosea::Config::State [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                            Parameters      $params\
                            Action          $body\
                            IsFinal         false\
                        ]
                        relvar insert ::rosea::Config::StatePlace [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                        ]
                        return
                    }
                    proc transition {source - event -> target} {
                        if {$event eq {}} {
                            tailcall DeclError EMPTY_NAME event
                        }
                        if {$source in {CH IG}} {
                            tailcall DeclError PSEUDO_STATE $source "transition source state"
                        }
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        if {$source eq "@"} {
                            if {$target in {CH IG}} {
                                tailcall DeclError BAD_CREATION_TARGET $target
                            }
                            set cstuple [list\
                                Domain          $DomainName\
                                Model           $ClassName\
                                Name            @\
                            ]
                            relvar uinsert ::rosea::Config::CreationState $cstuple
                            relvar uinsert ::rosea::Config::StatePlace $cstuple
                        }
                    
                        set eventtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            Event   $event\
                        ]
                        relvar uinsert ::rosea::Config::Event $eventtuple ; # <1>
                        relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                        relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                    
                        set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                            Name $target]
                        set transtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            State   $source\
                            Event   $event\
                        ]
                        relvar insert ::rosea::Config::TransitionPlace $transtuple
                    
                        if {[relation isnotempty $tranrule]} {
                            lappend transtuple TransRule $target
                            set tpsubtype NonStateTransition
                        } else {
                            lappend transtuple NewState $target
                            set tpsubtype StateTransition
                        }
                        relvar insert ::rosea::Config::$tpsubtype $transtuple
                        return
                    }
                    proc initialstate {name} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME initialstate
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name initialstate
                        }
                        variable InitialState $name
                        return
                    }
                    proc defaulttrans {name} {
                        if {$name ni {CH IG}} {
                            tailcall DeclError EXPECTED_PSEUDO_STATE $name
                        }
                        variable DefaultTrans $name
                        return
                    }
                    proc terminal {args} {
                        variable Terminals
                        ::struct::set add Terminals $args
                        return
                    }
                }
            }
            namespace eval AssignerDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc state {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME state
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name state
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    variable InitialState
                
                    if {$InitialState eq {}} {
                        set InitialState $name
                    }
                
                    relvar insert ::rosea::Config::State [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                        Parameters      $params\
                        Action          $body\
                        IsFinal         false\
                    ]
                    relvar insert ::rosea::Config::StatePlace [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                    ]
                    return
                }
                proc transition {source - event -> target} {
                    if {$event eq {}} {
                        tailcall DeclError EMPTY_NAME event
                    }
                    if {$source in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name "transition source state"
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    set eventtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        Event   $event\
                    ]
                    relvar uinsert ::rosea::Config::Event $eventtuple
                    relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                    relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                
                    set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                        Name $target]
                    set transtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        State   $source\
                        Event   $event\
                    ]
                    relvar insert ::rosea::Config::TransitionPlace $transtuple
                
                    if {[relation isnotempty $tranrule]} {
                        lappend transtuple TransRule $target
                        set tpsubtype NonStateTransition
                    } else {
                        lappend transtuple NewState $target
                        set tpsubtype StateTransition
                    }
                    relvar insert ::rosea::Config::$tpsubtype $transtuple
                    return
                }
                proc initialstate {name} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME initialstate
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name initialstate
                    }
                    variable InitialState $name
                    return
                }
                proc defaulttrans {name} {
                    if {$name ni {CH IG}} {
                        tailcall DeclError EXPECTED_PSEUDO_STATE $name
                    }
                    variable DefaultTrans $name
                    return
                }
                proc identifyby {name args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    variable multiClass $name
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -id {
                                variable multiIdNum $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION identifyby $option
                            }
                        }
                    }
                
                    return
                }
            }
        }
    }
    namespace eval Populate {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Config::ConfigEvaluate
        namespace import ::rosea::Helpers::DeclError
        proc domain {name body} {
            set domain [relvar restrictone ::rosea::Config::Domain Name $name]
            if {[relation isempty $domain]} {
                tailcall DeclError UNKNOWN_DOMAIN $domain
            }
        
            namespace upvar DomainPop DomainName DomainName DomainLoc DomainLoc
            relation assign $domain {Name DomainName} {Location DomainLoc}
        
            try {
                relvar eval {
                    ConfigEvaluate [namespace current]::DomainPop $body
                }
            } on error {result opts} {
                log::error $result
                upvar #0 ::rosea::Config::errcount errcount
                incr errcount
            }
        }
        namespace eval DomainPop {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace path ::rosea::Helpers
            proc class {class heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                set body [list]
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.
                    set tuple [list]
                    foreach attr $heading value $values {
                        # Check if we are skipping a value to use a default.  We must also
                        # allow some way to specify the value as "-".
                        if {$value eq "-"} {
                            continue
                        } elseif {$value eq "\\-"} {
                            set value -
                        }
                        lappend tuple $attr $value
                    }
                    # Accumulate the tuples as a list to form the body that will be
                    # inserted into the relvar.
                    lappend body $tuple
                }
            
                # Insert the body into the relvar.
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::$class
                set insts [relvar insert $relvar {*}$body]
            
                # Now we have to deal with any state model that might be present.  We have
                # to set up the initial state properly if such a thing exists for this
                # class.
                set idattrs [lindex [relvar identifiers $relvar] 0]
                relation foreach inst $insts {
                    CreateInInitialState $domns $class [pipe {
                        relation project $inst {*}$idattrs |
                        relation tuple ~ |
                        tuple get ~
                    }]
                }
            
                return [relation body $insts]
            }
            proc assigner {rname heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::${rname}__STATEINST
                set idattrs [lindex [relvar identifiers $relvar] 0]
                if {![struct::set equal $heading $idattrs]} {
                    tailcall DeclError NO_IDENTIFIER $heading $idattrs
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.  We assume
                    # the values are in the same order as the heading -- that is the point.
                    set tuple [list]
                    foreach attr $heading value $values {
                        lappend tuple $attr $value
                    }
                    CreateInInitialState $domns $rname $tuple
                }
            
                return
            }
        }
    }
    namespace eval Info {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Helpers::DeclError
        proc domain {arglist} {
            set arglist [lassign $arglist subcmd domainname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            switch -exact -- $subcmd {
                classes {
                    return [pipe {
                        relvar set ::rosea::Config::Class |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                relationships {
                    return [pipe {
                        relvar set ::rosea::Config::Relationship |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                operations {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::DomainOperation |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc FormatOpsInfo {ops} {
            set result [list]
            relation foreach op $ops {
                relation assign $op
                lappend result $Name $Parameters $Body
            }
            return $result
        }
        proc class {arglist} {
            set arglist [lassign $arglist subcmd domainname classname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                attributes {
                    return [pipe {
                        relvar set ::rosea::Config::Attribute |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation dict ~ Name Type
                    }]
                }
                classops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserClassOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                instops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserInstanceOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc statemodel {arglist} {
            set arglist [lassign $arglist subcmd domainname classname statename]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
            set domns [string cat [relation extract $dominst Location] :: $domainname]
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                states {
                    set states [pipe {
                        relvar set ::rosea::Config::State |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation project ~ Name Parameters Action
                    }]
                    set result [list]
                    relation foreach state $states {
                        relation assign $state
                        lappend result $Name $Parameters $Action
                    }
                    return $result
                }
                events {
                    return [pipe {
                        relvar set ::rosea::Config::EffectiveEvent |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation list ~ Event
                    }]
                }
                transitions {
                    return [pipe {
                        relvar set ${domns}::__Arch_Transition |
                        relation restrictwith ~ {$Class eq $classname} |
                        relation eliminate ~ Class |
                        relation group ~ Transition Event NewState |
                        relation extend ~ trtup TranCol dict {
                            [relation dict [tuple extract $trtup Transition] Event NewState]} |
                        relation dict ~ State TranCol
                    }] ; # <1>
                }
                activityproc {
                    return ${domns}::${classname}::__Activity::${statename}
                }
            }
        }
    }
    namespace eval Trace {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        relvar create Trace {
            Trace_Id    int
            Timestamp   bignum
            Source      list
            Event       string
            Target      list
            Params      list
        } Trace_Id
        
        relvar create Creation {
            Trace_Id    int
        } Trace_Id
        
        relvar create Polymorphic {
            Trace_Id    int
            SubInst     string
            Linkage     string
        } Trace_Id
        
        relvar create Transition {
            Trace_Id    int
            CurrState   string
            NewState    string
        } Trace_Id
        
        relvar partition R1 Trace Trace_Id\
            Creation Trace_Id\
            Polymorphic Trace_Id\
            Transition Trace_Id
        variable targetCmpFunc [lambda {instrefs target} {
            lassign $target trelvar tinst
            foreach instref $instrefs {
                lassign $instref crelvar cinst
                if {$trelvar eq $crelvar && [ral relation is $tinst subsetof $cinst]} {
                    return true
                }
            }
            return false
        }]
        variable traceState off
        variable traceNumber 0
        variable traceLogState off
        variable traceLogLevel info
        variable traceLogCmd [::logger::init rosea]
        proc QueryClassTraces {classes} {
            variable Trace
            return [relation restrictwith $Trace {
                [lindex $Target 0] in $classes ||\
                    [namespace tail [lindex $Target 0]] in $classes
            }] ; # <1>
        }
        proc QueryTargetTraces {targets} {
            variable Trace
            variable targetCmpFunc
            return [relation restrictwith $Trace {[{*}$targetCmpFunc $targets $Target]}]
        }
        proc TraceCreation {source event target params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Creation [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TracePolymorphic {source event target sub link params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Polymorphic [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        SubInst     $sub\
                        Linkage     $link\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TraceTransition {source event target curr new params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Transition [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        CurrState   $curr\
                        NewState    $new\
                    ]
                }
                LogTrace $trace
            }
        }
        proc NewTrace {src event target params} {
            variable traceNumber
            return [relvar insert Trace [list\
                Trace_Id    [incr traceNumber]\
                Timestamp   [clock microseconds]\
                Source      $src\
                Event       $event\
                Target      $target\
                Params      $params\
            ]]
        }
        proc LogTrace {trace} {
            variable traceLogState
            if {$traceLogState} {
                set rec [FormatTraceRec [lindex [TracesToRecords $trace] 0]] ; # <1>
        
                variable traceLogCmd
                variable traceLogLevel
                ${traceLogCmd}::${traceLogLevel} $rec
            }
        }
        proc TracesToRecords {traces} {
            foreach rvname {Creation Polymorphic Transition} { # <1>
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            set result [list]
            relation foreach trace $traces -ascending Trace_Id { # <2>
                relation assign $trace
                set labeled [dict create\
                    id      $Trace_Id\
                    time    $Timestamp\
                    source  $Source\
                    event   $Event\
                    target  $Target\
                    params  $Params\
                    class   [lindex $Target 0]\
                ] ; # <3>
                if {[relation isnotempty $Transition]} { # <4>
                    relation assign $Transition
                    dict set labeled type transition
                    dict set labeled current $CurrState
                    dict set labeled new $NewState
                } elseif {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic
                    dict set labeled type polymorphic
                    dict set labeled sub $SubInst
                    dict set labeled link $Linkage
                } elseif {[relation isnotempty $Creation]} {
                    dict set labeled type creation
                }
        
                lappend result $labeled
            }
            return $result
        }
        proc DecodeAllTraces {} {
            variable Trace
            tailcall TracesToRecords $Trace
        }
        proc DecodeClassTraces {args} {
            return [TracesToRecords [QueryClassTraces $args]]
        }
        proc DecodeTargetTraces {args} {
            tailcall TracesToRecords [QueryTargetTraces $args]
        }
        proc FormatTraceRec {rec} {
            dict with rec {
                switch -exact -- $type {
                    transition {
                        append result\
                            "Transition: "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $current -> $new"
                    }
                    polymorphic {
                        append result\
                            "Polymorphic : "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $link -> [FormatInstRef $sub]"
                    }
                    creation {
                        append result\
                            "Creation: "\
                            "[FormatInstRef $source] - "\
                            "[FormatEvent $event $params] -> $class"\
                            " ==> [FormatInstRef $target]"
                    }
                    default {
                        DeclError BAD_TRACETYPE $type
                    }
                }
            }
            return $result
        }
        proc FormatTransition {source event params target} {
            return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
                [FormatInstRef $target]"
        }
        proc FormatInstRef {instref} {
            lassign $instref relvar inst
            return [expr {$relvar eq {} ? "()" :
                    "$relvar\([FormatNVPairs [tuple get [relation tuple $inst]]]\)"}]
        }
        proc FormatEvent {event params} {
            set result $event
        
            if {[llength $params] != 0} {
                append result "\([join $params {, }]\)"
            }
            return $result
        }
        proc FormatNVPairs {pairs} {
            return [pipe {
                lmap {attr val} $pairs {string cat $attr ": " $val} |
                join ~ {, }
            }]
        }
        proc FormatTimestamp {time} {
            set sec [clock format [expr {$time / 1000000}] -format %T] ; # <1>
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %s.%03ld.%03ld $sec $msec $usec]
        }
        proc FormatTimeAsSec {time} {
            set sec [expr {$time / 1000000}]
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %3ld.%03ld.%03ld $sec $msec $usec]
        }
        proc DiagTraces {traces args} {
            set result {}
            append result "seqdiag \{\n"
            append result "    activation = none;\n"
            foreach {option value} $args {
                append result "    $option = $value;\n"
            }
        
            foreach rvname {Creation Polymorphic Transition} {
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            relation foreach trace $traces -ascending Trace_Id {
                relation assign $trace
                if {[isEmptyRef $Source]} {
                    set Source EXTERNAL
                } else {
                    set Source [namespace tail [lindex $Source 0]]
                }
                set Target [namespace tail [lindex $Target 0]]
                set evtlabel [FormatEvent $Event $Params]
                if {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic Linkage
                    append evtlabel " <<Polymorphic $Linkage>>"
                } elseif {[relation isnotempty $Creation]} {
                    append evtlabel " <<Creation>>"
                }
                append result "    $Source ->> $Target \[label=\"$evtlabel\"\];\n"
            }
        
            append result "\}\n"
        
            return $result
        }
        proc DiagAllTraces {filename args} {
            set chan [open $filename w]
            variable Trace
            try {
                chan puts $chan [DiagTraces $Trace {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagClassTraces {filename classes args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryClassTraces $classes] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagTargetTraces {filename targets args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryTargetTraces $targets] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
    }

    namespace path ::rosea::Helpers
    namespace import ::rosea::Config::ConfigEvaluate
}

package provide rosea $::rosea::version

Deleted packages/package-rosea-1.9.2-tcl.tm.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
# ACTIVESTATE TEAPOT-PKG BEGIN TM -*- tcl -*-
# -- Tcl Module

# @@ Meta Begin
# Package rosea 1.9.2
# Meta description Rosea is a data and execution architecture for
# Meta description translating XUML models using Tcl as the implementation
# Meta description language.
# Meta platform    tcl
# Meta require     {Tcl 8.6}
# Meta require     logger
# Meta require     ral
# Meta require     ralutil
# Meta require     struct::set
# Meta require     lambda
# Meta summary     Rosea -- XUML Software Architecture
# @@ Meta End


# ACTIVESTATE TEAPOT-PKG BEGIN REQUIREMENTS

package require Tcl 8.6
package require logger
package require ral
package require ralutil
package require struct::set
package require lambda

# ACTIVESTATE TEAPOT-PKG END REQUIREMENTS

# ACTIVESTATE TEAPOT-PKG BEGIN DECLARE

package provide rosea 1.9.2

# ACTIVESTATE TEAPOT-PKG END DECLARE
# ACTIVESTATE TEAPOT-PKG END TM
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2015 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors and
# need not follow the licensing terms described here, provided that the
# new terms are clearly indicated on the first page of each file where
# they apply.
# 
# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES
# THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# 
# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
# OR MODIFICATIONS.
# 
# GOVERNMENT USE: If you are acquiring this software on behalf of the
# U.S. government, the Government shall have only "Restricted Rights"
# in the software and related documentation as defined in the Federal
# Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
# are acquiring the software on behalf of the Department of Defense,
# the software shall be classified as "Commercial Computer Software"
# and the Government shall have only "Restricted Rights" as defined in
# Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the foregoing,
# the authors grant the U.S. Government and others acting in its behalf
# permission to use and distribute the software in accordance with the
# terms specified in this license.

package require Tcl 8.6

package require logger
package require ral
package require ralutil
package require struct::set
package require lambda

proc ::K {x y} {set x}

namespace eval ::rosea {
    namespace export configure
    
    namespace export configureFromChan
    
    namespace export configureFromFile
    
    namespace export generate
    
    namespace export populate
    
    namespace export populateFromChan
    
    namespace export populateFromFile
    
    namespace export save
    
    namespace export restore
    
    namespace export info
    
    namespace export tunnel
    
    namespace export trace
    
    namespace ensemble create

    variable version 1.9.2

    logger::initNamespace [namespace current]

    namespace import\
        ::ral::relation\
        ::ral::tuple\
        ::ral::relformat\
        ::ralutil::pipe
    namespace import ::ral::relvar
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation project ~ Name Type |
        relation dict ~ Name Type
    } headingQuery
    
    pipe {
        relation semijoin $class $Identifier -using {Domain Domain Name Class}\
                $IdentifyingAttribute |
        relation group ~ Attributes Attribute
    } idQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $UserSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } defaultValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $SystemSuppliedValue -using {Domain Domain Class Class Name Attribute}
    } suppliedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $GeneratedValue -using {Domain Domain Class Class Name Attribute}
    } generatedValuesQuery
    
    pipe {
        relation semijoin $class $Attribute -using {Domain Domain Name Class} |
        relation join ~ $ValueCheck -using {Domain Domain Class Class Name Attribute}
    } checkValuesQuery
    
    pipe {
        relation semijoin $class $StateModel -using {Domain Domain Name Model} |
        relation isnotempty
    } hasSMQuery
    
    pipe {
        relation semijoin $class $State -using {Domain Domain Name Model} |
        relation project ~ Name Parameters Action
    } statesQuery
    
    pipe {
        relation join $AttributeReference $refing\
            -using {Domain Domain ReferringClass Class\
            Relationship Relationship ReferringRole Role} |
        relation rename ~ Conditionality ReferringCond\
                Multiplicity ReferringMult |
        relation join ~ $refed -using {Domain Domain\
            ReferencedClass Class Relationship\
            Relationship ReferencedRole Role} |
        relation project ~ Domain Relationship\
            ReferringClass ReferringAttribute\
            ReferencedClass ReferencedAttribute\
            ReferringCond ReferringMult Conditionality |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } referencesQuery
    
    pipe {
        relation semijoin $cassocs $AssociatorClass\
                -using {Domain Domain Name Relationship}\
            $ReferringClass $AttributeReference\
                -using {Domain Domain Class ReferringClass\
                Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute ReferencedRole |
        relation join ~ $bothclass -using {Domain Domain Relationship Relationship\
                ReferencedClass Class ReferencedRole Role} |
        relation group ~ ReferringAttrs ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } assocrefsQuery
    
    pipe {
        relation semijoin $rships $Generalization\
                $Subclass -using {Domain Domain Name Relationship}\
                $ReferringClass $AttributeReference\
                    -using {Domain Domain Class ReferringClass\
                    Relationship Relationship Role ReferringRole} |
        relation project ~ Domain Relationship ReferringClass ReferringAttribute\
                ReferencedClass ReferencedAttribute |
        relation group ~ ReferringAttrs\
                ReferringAttribute ReferencedAttribute |
        relation extend ~ rfa\
            TagReferringAttrs {Relation {RefOrder int ReferringAttribute string\
                ReferencedAttribute string}} {
                    [relation tag [tuple extract $rfa ReferringAttrs] RefOrder]
                } |
        relation extend ~ wfa\
            SrcAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferringAttribute -ascending RefOrder]
            }\
            DstAttrs list {
                [relation list [tuple extract $wfa TagReferringAttrs]\
                    ReferencedAttribute -ascending RefOrder]
            } |
        relation extend ~ ram\
            ForwAttrs list {
                [Interleave [tuple extract $ram SrcAttrs]\
                    [tuple extract $ram DstAttrs]]
            }\
            RevAttrs list {
                [Interleave [tuple extract $ram DstAttrs]\
                    [tuple extract $ram SrcAttrs]]
            } |
        relation eliminate ~ TagReferringAttrs
    } subrefsQuery
    
    proc configure {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Config $script
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc configureFromChan {chan} {
        tailcall configure [::chan read -nonewline $chan]
    }
    proc configureFromFile {filename} {
        set f [::open $filename r]
        try {
            configureFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc generate {{pattern *} {prefix {}}} {
        if {$prefix ne {}} {
            if {[string range $prefix 0 1] ne "::"} {
                set prefix [uplevel 1 {namespace current}]::$prefix
            }
            set prefix [string trimright $prefix :]
        } elseif {$prefix eq "::"} {
            set prefix {} ; # <1>
        }
        namespace upvar Config\
            Domain Domain\
            DomainElement DomainElement\
            Class Class\
            Attribute Attribute\
            DefaultValue DefaultValue\
            UserSuppliedValue UserSuppliedValue\
            SystemSuppliedValue SystemSuppliedValue\
            GeneratedValue GeneratedValue\
            ValueCheck ValueCheck\
            Identifier Identifier\
            IdentifyingAttribute IdentifyingAttribute\
            Relationship Relationship\
            Association Association\
            SimpleAssociation SimpleAssociation\
            SimpleReferringClass SimpleReferringClass\
            SimpleReferencedClass SimpleReferencedClass\
            ClassBasedAssociation ClassBasedAssociation\
            AssociatorClass AssociatorClass\
            SourceClass SourceClass\
            TargetClass TargetClass\
            Generalization Generalization\
            Superclass Superclass\
            Subclass Subclass\
            AttributeReference AttributeReference\
            ReferencedIdAttribute ReferencedIdAttribute\
            ReferringClass ReferringClass\
            ReferencedClass ReferencedClass\
            DomainOperation DomainOperation\
            SuppliedOperation SuppliedOperation\
            UserClassOperation UserClassOperation\
            SystemClassOperation SystemClassOperation\
            UserInstanceOperation UserInstanceOperation\
            SystemInstanceOperation SystemInstanceOperation\
            InstanceStateModel InstanceStateModel\
            StateModel StateModel\
            StatePlace StatePlace\
            State State\
            EffectiveEvent EffectiveEvent\
            DeferredEvent DeferredEvent\
            TransitionPlace TransitionPlace\
            StateTransition StateTransition\
            NonStateTransition NonStateTransition\
            AssignerStateModel AssignerStateModel\
            SingleAssigner SingleAssigner\
            MultipleAssigner MultipleAssigner\
            PolymorphicEvent PolymorphicEvent
    
        set genDomain [relation restrict $Domain dom {
            [string match $pattern [tuple extract $dom Name]]
        }]
        relation foreach domain $genDomain {
            set domainName [relation extract $domain Name]
            relvar updateone Config::Domain dtup [list Name $domainName] {
                tuple update $dtup Location $prefix
            }
            
            set domns ${prefix}::$domainName
            namespace eval $domns {
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                ral relvar create __Arch_RefLink {
                    Relationship    string
                    ReferringClass  string
                    ReferencedClass string
                    ReferringAttrs  {Relation
                            {ReferringAttribute string ReferencedAttribute string}}
                } Relationship
                ral relvar create __Arch_AssocRef {
                    Relationship    string
                    AssocClass      string
                    References      {Relation\
                        {Participant string Role string ReferringAttrs {Relation\
                            {ReferringAttribute string ReferencedAttribute string}}}}
                } Relationship
                ral relvar create __Arch_SuperLink {
                    Relationship    string
                    SuperClass      string
                } Relationship
                
                ral relvar create __Arch_SubLink {
                    Relationship    string
                    SubClass        string
                    ReferringAttrs  {Relation\
                        {ReferringAttribute string ReferencedAttribute string}}
                } {Relationship SubClass}
                
                ral relvar association __Arch_R5\
                    __Arch_SubLink Relationship +\
                    __Arch_SuperLink Relationship 1
                ral relvar create __Arch_Link {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar create __Arch_AssociationLink {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                    PrevSrcClass    string
                } {Name SrcClass}
                ral relvar association __Arch_R4\
                    __Arch_AssociationLink {Name PrevSrcClass} ?\
                    __Arch_AssociationLink {Name SrcClass} ?
                ral relvar create __Arch_PartitionLink {
                    Name            string
                    SrcClass        string
                } {Name SrcClass}
                ral relvar partition __Arch_R3 __Arch_Link {Name SrcClass}\
                    __Arch_AssociationLink {Name SrcClass}\
                    __Arch_PartitionLink {Name SrcClass}
                ral relvar create __Arch_PartitionDst {
                    Name            string
                    SrcClass        string
                    DstClass        string
                    Attrs           list
                } {Name SrcClass DstClass}
                ral relvar association __Arch_R2\
                    __Arch_PartitionDst {Name SrcClass} +\
                    __Arch_PartitionLink {Name SrcClass} 1
                ral relvar create __Arch_State {
                    Class string
                    State string
                } {Class State}
                ral relvar create __Arch_Event {
                    Class string
                    Event string
                } {Class Event}
                ral relvar create __Arch_Transition {
                    Class string
                    State string
                    Event string
                    NewState string
                } {Class State Event}
                ral relvar correlation __Arch_R1 __Arch_Transition\
                    {Class State} + __Arch_State {Class State}\
                    {Class Event} + __Arch_Event {Class Event}
                ral relvar create __Arch_InitialState {
                    Class string
                    State string
                } Class
                ral relvar association __Arch_R6\
                    __Arch_InitialState {Class State} ?\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_TerminalState {
                    Class string
                    State string
                } {Class State}
                ral relvar association __Arch_R7\
                    __Arch_TerminalState {Class State} *\
                    __Arch_State {Class State} 1
                ral relvar create __Arch_PolymorphicEvent {
                    Class           string
                    Event           string
                } {Class Event}
            }
            namespace eval $domns namespace path ::rosea::InstCmds
            set domops [relation semijoin $domain $DomainOperation -using {Name Domain}]
            relation foreach domop $domops {
                relation assign $domop\
                    {Name name} {Parameters parameters} {Body body}
                proc ${domns}::$name $parameters [list ::ral relvar eval $body] ; # <1>
            }
            
            namespace eval $domns [list\
                namespace export {*}[relation list $domops Name]\
            ]
            namespace eval $domns namespace ensemble create
            set statemodels [relation semijoin $domain $StateModel\
                -using {Name Domain}]
            
            relvar eval {
                relvar set ${domns}::__Arch_InitialState [pipe {
                    relation project $statemodels Model InitialState |
                    relation rename ~ Model Class InitialState State
                }]
                set states [relation semijoin $domain $StatePlace -using {Name Domain}]
                relvar set ${domns}::__Arch_State [pipe {
                    relation project $states Model Name |
                    relation rename ~ Model Class Name State
                }]
                relvar set ${domns}::__Arch_TerminalState [pipe {
                    relation semijoin $domain $State -using {Name Domain} |
                    relation restrict ~ termtuple {[tuple extract $termtuple IsFinal]} |
                    relation project ~ Model Name |
                    relation rename ~ Model Class Name State
                }]
                set events [relation semijoin $domain $EffectiveEvent\
                    -using {Name Domain}]
                relvar set ${domns}::__Arch_Event [pipe {
                    relation project $events Model Event |
                    relation rename ~ Model Class
                }]
                set alltrans [pipe {
                    relation join $states $events |
                    relation rename ~ Name State
                }] ; # <1>
                set statetrans [relation semijoin $domain $StateTransition\
                    -using {Name Domain}]
                set nontrans [pipe {
                    relation semijoin $domain $NonStateTransition -using {Name Domain} |
                    relation rename ~ TransRule NewState
                }]
                set deftrans [pipe {
                    relation minus $alltrans $TransitionPlace |
                    relation join ~ $StateModel |
                    relation eliminate ~ InitialState |
                    relation rename ~ DefaultTrans NewState |
                    relation update ~ dttup {[tuple extract $dttup State] eq "@"} {
                        tuple update $dttup NewState CH}
                }]
                relvar set ${domns}::__Arch_Transition [pipe {
                    relation union $statetrans $nontrans $deftrans |
                    relation eliminate ~ Domain |
                    relation rename ~ Model Class
                }]
                relvar set ${domns}::__Arch_PolymorphicEvent [pipe {
                    relation semijoin $domain $DeferredEvent\
                        -using {Name Domain} |
                    relation project ~ Model Event |
                    relation rename ~ Model Class
                }]
            }
            variable headingQuery
            variable idQuery
            variable defaultValuesQuery
            variable suppliedValuesQuery
            variable generatedValuesQuery
            variable checkValuesQuery
            variable hasSMQuery
            variable statesQuery
            
            set classes [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Class -using {Domain Domain Element Name}]
            relation foreach class $classes {
                set className ${domns}::[relation extract $class Name]
                namespace eval $className {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $className [list namespace path\
                        [list ::rosea::InstCmds $domns]]
                set heading [eval $headingQuery]
                set idset [list]
                relation foreach id [eval $idQuery] -ascending Number {
                    lappend idset [relation list\
                            [relation extract $id Attributes] Attribute]
                }
                
                relvar create $className $heading {*}$idset
                
                # <1>
                set checkvalues [eval $checkValuesQuery]
                
                if {[relation isnotempty $checkvalues]} {
                    relvar trace add variable $className {insert update set} [list\
                        ::rosea::Helpers::CheckValueTrace\
                        [relation dict $checkvalues Name Expression]\
                    ]
                }
                set defaultvalues [eval $defaultValuesQuery]
                
                if {[relation isnotempty $defaultvalues]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::UserDefaultTrace\
                        [relation dict $defaultvalues Name Type]\
                        [relation dict $defaultvalues Name Value]\
                    ]
                }
                set supplied [eval $suppliedValuesQuery]
                
                if {[relation isnotempty $supplied]} {
                    pipe {
                        relation extend $supplied stup ClassName string {
                            [string cat [tuple extract $stup Class] , [tuple extract $stup Name]]
                        } |
                        relation array ~ ${domns}::__Arch_SuppliedDefault ClassName StartValue 
                    } ; # <1>
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::SupplyDefaultTrace\
                        [relation dict $supplied Name Type]\
                    ]
                }
                set generatecmds [eval $generatedValuesQuery]
                
                if {[relation isnotempty $generatecmds]} {
                    relvar trace add variable $className insert [list\
                        ::rosea::Helpers::GenerateDefaultTrace\
                        [relation dict $generatecmds Name Type]\
                        [relation dict $generatecmds Name Cmd]\
                    ]
                }
                set hasStateModel [eval $hasSMQuery]
                if {$hasStateModel} {
                    set instid [lindex $idset 0]
                    set instheading [list]
                    foreach attr $instid {
                        lappend instheading $attr [dict get $heading $attr] ; # <1>
                    }
                    lappend instheading __State string
                    relvar create ${domns}::[relation extract $class Name]__STATEINST\
                        $instheading $instid
                    set actns ${className}::__Activity
                    namespace eval $actns {
                        namespace import\
                            ::ral::relation\
                            ::ral::tuple\
                            ::ral::relformat\
                            ::ralutil::pipe
                    }
                    namespace eval $actns [list\
                        namespace path [list\
                            ::rosea::InstCmds\
                            $className\
                            $domns\
                        ]\
                    ]
                    relation foreach state [eval $statesQuery] {
                        relation assign $state\
                            {Name stateName}\
                            {Parameters params}\
                            {Action stateAction}
                        proc ${actns}::$stateName [linsert $params 0 self] $stateAction
                    }
                }
                set opmap [dict create]
                set classops [relation semijoin $class $UserClassOperation\
                    -using {Domain Domain Name Class}]
                relation foreach classop $classops {
                    relation assign $classop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname $params $opbody
                    dict set opmap $opname ${className}::$opname
                }
                
                set sysmap [QuerySystemClassOperations $className false]
                if {$hasStateModel} {
                    set sysmap [dict merge $sysmap [QuerySystemClassOperations $className true]]
                }
                
                namespace ensemble create\
                    -command $className\
                    -map [dict merge $opmap $sysmap]
                set opmap [dict create]
                set instops [relation semijoin $class $UserInstanceOperation\
                    -using {Domain Domain Name Class}]
                relation foreach instop $instops {
                    relation assign $instop\
                        {Name opname}\
                        {Parameters params}\
                        {Body opbody}
                
                    proc ${className}::$opname [linsert $params 0 self] $opbody
                    dict set opmap $opname ${className}::$opname
                }
                set sysmap [QuerySystemInstanceOperations false]
                set hasPolyEvents [relation isnotempty\
                    [relation semijoin $class $PolymorphicEvent\
                        -using {Domain Domain Name Model}]\
                ]
                if {$hasStateModel || $hasPolyEvents} {
                    set sysmap [dict merge $sysmap [QuerySystemInstanceOperations true]]
                }
                
                namespace ensemble create\
                    -command ${className}::Instance\
                    -parameters instref\
                    -map [dict merge $opmap $sysmap]
            }
            set rships [relation semijoin $domain $DomainElement -using {Name Domain}\
                    $Relationship -using {Domain Domain Element Name}]
            
            set sassocs [relation semijoin $rships $Association\
                    $SimpleAssociation]
            set refing [relation semijoin $sassocs $SimpleReferringClass\
                    -using {Domain Domain Name Relationship}]
            set refed [relation semijoin $sassocs $SimpleReferencedClass\
                    -using {Domain Domain Name Relationship}]
            variable referencesQuery
            set references [eval $referencesQuery]
            relvar eval {
                set flink [pipe {
                    relation project $references Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set blink [pipe {
                    relation project $references Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%] ; # <1>
                
                relvar union ${domns}::__Arch_Link $flink $blink
                set flink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }] ; # <1>
                set blink [pipe {
                    relation project $references Relationship ReferringClass\
                            ReferencedClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_AssociationLink $flink $blink
                relvar union ${domns}::__Arch_RefLink [relation project $references\
                    Relationship ReferringClass ReferencedClass ReferringAttrs]
            }
            relation foreach reference $references {
                relation assign $reference\
                    {Relationship relationship}\
                    {ReferringClass referringClass}\
                    {ReferencedClass referencedClass}\
                    {ReferringCond referringCond}\
                    {ReferringMult referringMult}\
                    {Conditionality referencedCond}\
                    {SrcAttrs srcAttrs}\
                    {DstAttrs dstAttrs}
            
                # Create the relvar constraint.
                relvar association ${domns}::$relationship\
                     ${domns}::$referringClass $srcAttrs\
                    [MapCondMultToConstraint $referringCond $referringMult]\
                    ${domns}::$referencedClass $dstAttrs\
                    [MapCondMultToConstraint $referencedCond false]
            
                # All simple associations get a link and unlink command in their ensemble.
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkSimple $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkSimple $relationship]\
                ]
            
                # Determine if we have any assigners assocated  with the relationship.
                # Single assigners get different commands from multiple assigners.
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $reference $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $reference $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                    }
                }
                # Create the relationship ensemble command.
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            set cassocs [relation semijoin $rships $Association\
                    $ClassBasedAssociation]
            set sourceclass [relation semijoin $cassocs $SourceClass\
                -using {Domain Domain Name Relationship}]
            set targetclass [relation semijoin $cassocs $TargetClass\
                -using {Domain Domain Name Relationship}]
            set bothclass [relation union $sourceclass $targetclass] ; # <1>
            variable assocrefsQuery
            set assocrefs [eval $assocrefsQuery]
            relvar eval {
                set aforw [pipe {
                    relation project $assocrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set arev [relation update $aforw lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}]
                set sources [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "source"} |
                    relation eliminate ~ ReferencedRole
                }]
                set sforw [pipe {
                    relation project $sources Relationship ReferencedClass |
                    relation rename ~ Relationship Name ReferencedClass SrcClass
                }]
                set targets [pipe {
                    relation restrict $assocrefs aref {
                        [tuple extract $aref ReferencedRole] eq "target"} |
                    relation eliminate ~ ReferencedRole
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_Link $aforw $arev $sforw $trev
                set sforw [pipe {
                    relation project $sources Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename ~ Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                set trev [pipe {
                    relation project $targets Relationship ReferringClass ReferencedClass\
                        RevAttrs |
                    relation rename % Relationship Name ReferringClass DstClass\
                        ReferencedClass SrcClass RevAttrs Attrs |
                    relation extend % al PrevSrcClass string {{}} |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                set onerefs [relation rename $sources ReferencedClass OneClass\
                        Conditionality OneCond Multiplicity OneMult\
                        ReferringAttrs OneReferringAttrs SrcAttrs OneSrcAttrs\
                        DstAttrs OneDstAttrs ForwAttrs OneForwAttrs RevAttrs OneRevAttrs]
                set otherrefs [relation rename $targets ReferencedClass OtherClass\
                        Conditionality OtherCond Multiplicity OtherMult ReferringAttrs\
                        OtherReferringAttrs SrcAttrs OtherSrcAttrs DstAttrs OtherDstAttrs\
                        ForwAttrs OtherForwAttrs RevAttrs OtherRevAttrs]
                set bothrefs [relation join $onerefs $otherrefs\
                    -using {Domain Domain ReferringClass ReferringClass\
                        Relationship Relationship}]
                set aforw [pipe {
                    relation project $bothrefs Relationship ReferringClass OtherClass\
                        OtherForwAttrs OneClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            OtherClass DstClass OtherForwAttrs Attrs OneClass PrevSrcClass
                }]
                set arev [pipe {
                    relation project $bothrefs Relationship ReferringClass OneClass\
                            OneForwAttrs OtherClass |
                    relation rename % Relationship Name ReferringClass SrcClass\
                            OneClass DstClass OneForwAttrs Attrs OtherClass PrevSrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_AssociationLink $sforw $trev $aforw $arev
                relvar union ${domns}::__Arch_AssocRef [pipe {
                    relation project $assocrefs Relationship ReferringClass\
                        ReferencedClass ReferencedRole ReferringAttrs |
                    relation rename ~ ReferringClass AssocClass ReferencedClass Participant\
                        ReferencedRole Role |
                    relation group ~ References Participant Role ReferringAttrs
                }]
            }
            relation foreach bothref $bothrefs {
                relation assign $bothref\
                    {Relationship relationship}\
                    {ReferringClass associator}\
                    {OneClass sourceClass}\
                    {OneCond sourceCond}\
                    {OneMult sourceMult}\
                    {OneSrcAttrs sourceAssocAttrs}\
                    {OneDstAttrs sourceDstAttrs}\
                    {OtherClass targetClass}\
                    {OtherCond targetCond}\
                    {OtherMult targetMult}\
                    {OtherSrcAttrs targetAssocAttrs}\
                    {OtherDstAttrs targetDstAttrs}
            
                # Create the correlation constraint
                relvar correlation ${domns}::$relationship ${domns}::$associator\
                    $sourceAssocAttrs [MapCondMultToConstraint $targetCond $targetMult]\
                    ${domns}::$sourceClass $sourceDstAttrs\
                    $targetAssocAttrs [MapCondMultToConstraint $sourceCond $sourceMult]\
                    ${domns}::$targetClass $targetDstAttrs ; # <1>
            
                set ensemblemap [dict create\
                    link [list ::rosea::RelCmds::linkAssoc $relationship]\
                    reference [list ::rosea::RelCmds::referenceAssoc $relationship]\
                    unlink [list ::rosea::RelCmds::unlinkAssoc $relationship]\
                ]
                # Determine if we have any assigners
                set rpath ${domns}::$relationship
                set assigner [relation semijoin $bothref $SingleAssigner\
                    -using {Domain Domain Relationship Relationship}]
                if {[relation isnotempty $assigner]} {
                    dict set ensemblemap signal\
                        [list ::rosea::RelCmds::signalAssigner $rpath]
                } else {
                    set assigner [relation semijoin $bothref $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                    }
                }
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            variable subrefsQuery
            set subrefs [eval $subrefsQuery]
            relvar eval {
                set sublinks [pipe {
                    relation project $subrefs Relationship ReferringClass |
                    relation rename ~ Relationship Name ReferringClass SrcClass
                }]
                set superlinks [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename % Relationship Name ReferencedClass SrcClass |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                
                relvar union ${domns}::__Arch_Link $sublinks $superlinks
                relvar union ${domns}::__Arch_AssociationLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferencedClass\
                            ForwAttrs |
                    relation rename ~ Relationship Name ReferringClass SrcClass\
                            ReferencedClass DstClass ForwAttrs Attrs |
                    relation extend ~ al PrevSrcClass string {{}}
                }]
                relvar union ${domns}::__Arch_PartitionLink $superlinks
                relvar union ${domns}::__Arch_PartitionDst [pipe {
                    relation project $subrefs Relationship ReferencedClass\
                            ReferringClass RevAttrs |
                    relation rename % Relationship Name ReferencedClass SrcClass\
                            ReferringClass DstClass RevAttrs Attrs |
                    relation update % lnk {1} {
                        tuple update $lnk Name ~[tuple extract $lnk Name]}
                } {} |%]
                relvar union ${domns}::__Arch_SuperLink [pipe {
                    relation project $subrefs Relationship ReferencedClass |
                    relation rename ~ ReferencedClass SuperClass
                }]
                relvar union ${domns}::__Arch_SubLink [pipe {
                    relation project $subrefs Relationship ReferringClass ReferringAttrs |
                    relation rename ~ ReferringClass SubClass
                }]
            }
            set partrefs [pipe {
                relation project $subrefs Relationship ReferencedClass DstAttrs\
                        ReferringClass SrcAttrs |
                relation extend ~ prs SubAttrMap list {[list\
                        ${domns}::[tuple extract $prs ReferringClass]\
                        [tuple extract $prs SrcAttrs]]} |
                relation eliminate ~ ReferringClass SrcAttrs |
                relation group ~ SubClassRefs SubAttrMap |
                relation extend ~ spt SubParts list {
                        [concat {*}[relation list [tuple extract $spt SubClassRefs]]]} |
                relation eliminate ~ SubClassRefs
            }]
            
            relation foreach partref $partrefs {
                relation assign $partref\
                    {Relationship relationship}\
                    {ReferencedClass superclass}\
                    {DstAttrs superattrs}\
                    {SubParts subparts}
            
                relvar partition ${domns}::$relationship ${domns}::$superclass\
                        $superattrs {*}$subparts
                namespace ensemble create\
                    -command ${domns}::$relationship\
                    -map [dict create migrate [list ::rosea::RelCmds::migrate\
                            $relationship]]
            }
            set assigners [relation semijoin $domain $AssignerStateModel\
                    -using {Name Domain}]
            relation foreach assigner $assigners {
                set asgnns\
                    ${domns}::[relation extract $assigner Relationship]::__Activity
                namespace eval $asgnns {
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                }
                namespace eval $asgnns [list\
                    namespace path [list\
                        ::rosea::InstCmds\
                        $domns\
                    ]\
                ]
                set states [pipe {
                    relation semijoin $assigner $State\
                        -using {Domain Domain Relationship Model} |
                    relation project ~ Name Parameters Action
                }]
                relation foreach state $states {
                    relation assign $state\
                        {Name stateName}\
                        {Parameters params}\
                        {Action stateAction}
                    set params [linsert $params 0 self]
                    proc ${asgnns}::$stateName $params $stateAction
                }
            }
            relation foreach sassigner\
                    [relation semijoin $domain $SingleAssigner\
                    -using {Name Domain}] {
                relation assign $sassigner {Relationship relationship}
                relvar create ${domns}::${relationship}__STATEINST {
                    Id      int
                    __State string
                } Id
                CreateInInitialState $domns $relationship {Id 0} ; # <1>
            }
            relation foreach massigner\
                    [relation semijoin $domain $MultipleAssigner\
                    -using {Name Domain}] {
                relation assign $massigner {Relationship relationship}
                set assignvar ${domns}::${relationship}__STATEINST
            
                set idattrs [pipe {
                    relation semijoin $massigner $Identifier\
                        $IdentifyingAttribute\
                        $Attribute -using {Domain Domain Class Class\
                            Attribute Name} |
                    relation dict ~ Name Type
                }]
                relvar create $assignvar\
                    [concat $idattrs [list __State string]]\
                    [dict keys $idattrs]
            }
        }
    }
    proc populate {script} {
        namespace upvar Config errcount errcount configlineno configlineno
        set errcount 0
        set configlineno 1
    
        ConfigEvaluate ::rosea::Populate $script ; # <1>
    
        if {$errcount > 0} {
            tailcall DeclError CONFIG_ERRORS $errcount
        }
        return $errcount
    }
    proc populateFromChan {chan} {
        tailcall populate [::chan read -nonewline $chan]
    }
    proc populateFromFile {filename} {
        set f [::open $filename r]
        try {
            populateFromChan $f
        } finally {
            ::chan close $f
        }
    }
    proc save {args} {
        set savecmd ::ral::serializeToFile
        set asynccmd {}
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set savecmd ::ral::storeToSQLite
                    }
                    -tclral {
                        set savecmd ::ral::serializeToFile
                    }
                    -async {
                        set options [lassign $options asynccmd]
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION save $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} { # <1>
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError SAVE_ARG_ERROR $args
        }
    
        set script "try \{$savecmd $file ${domain}::\\\[A-Za-z0-9\\\]*\}" ; # <2>
        if {$asynccmd ne {}} {
            append script " finally \{$asynccmd $domain $file\}"
        }
    
        after idle [list ::apply [list {} $script]] ; # <3>
    }
    proc restore {args} {
        set restorecmd ::ral::mergeFromFile
    
        set options $args
        while {1} {
            if {[string index [lindex $options 0] 0] eq "-"} {
                set options [lassign $options option]
                switch -exact -- $option {
                    -sqlite {
                        set restorecmd ::ral::mergeFromSQLite
                    }
                    -tclral {
                        set restorecmd ::ral::mergeFromFile
                    }
                    default {
                        tailcall DeclError UNKNOWN_OPTION restore $option
                    }
                }
            } else {
                break
            }
        }
    
        if {[llength $options] == 2} {
            lassign $options domain file
            if {[string range $domain 0 1] ne "::"} {
                set domrel [relvar restrictone ::rosea::Config::Domain Name $domain]
                if {[relation isempty $domrel]} {
                    tailcall DeclError UNKNOWN_DOMAIN $domain
                }
                set domain [string cat [relation extract $domrel Location]\
                        :: $domain]
            }
        } else {
            tailcall DeclError RESTORE_ARG_ERROR $args
        }
    
        eval [list $restorecmd $file $domain]
    
        # Determine the values for the system supplied defaults.  We examine all
        # the classes that have such attributes and find the maximum value of the
        # attribute.  This can then be placed in the array that is used when new
        # default values are generated.
        set domainname [namespace tail $domain]
        set supplied [pipe {
            relvar set ::rosea::Config::SystemSuppliedValue |
            relation restrictwith ~ {$Domain eq $domainname}
        }]
    
        relation foreach sup $supplied {
            relation assign $sup
            set classtups [relvar set ${domain}::$Class]
            if {[relation isempty $classtups]} {
                set maxvalue $StartValue
            } else {
                set maxvalue [pipe {
                    relation summarizeby $classtups {} cv\
                        MaxValue int {rmax($cv, $Attribute)} |
                    relation extract ~ MaxValue
                }]
            }
            set ${domain}::__Arch_SuppliedDefault($Class,$Attribute)\
                [expr {$maxvalue + 1}]
        }
        return
    }
    proc info {args} {
        set args [lassign $args subcmd]
    
        switch -exact -- $subcmd {
            domain {
                Info::domain $args
            }
            class {
                Info::class $args
            }
            statemodel {
                Info::statemodel $args
            }
            default {
                tailcall DeclError UNKNOWN_INFO_CMD $subcmd
            }
        }
    }
    proc tunnel {instref op args} {
        relvar eval {
            set result [[lindex $instref 0]::Instance $instref $op {*}$args]
        }
        return $result
    }
    proc trace {subcmd args} {
        switch -exact -- $subcmd {
            control {
                tailcall traceControl {*}$args
            }
            decode {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DecodeAllTraces
                    }
                    class {
                        tailcall Trace::DecodeClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DecodeTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            format {
                tailcall formatTraces {*}$args
            }
            diagram {
                switch -exact -- [lindex $args 0] {
                    all {
                        tailcall Trace::DiagAllTraces {*}[lrange $args 1 end]
                    }
                    class {
                        tailcall Trace::DiagClassTraces {*}[lrange $args 1 end]
                    }
                    target {
                        tailcall Trace::DiagTargetTraces {*}[lrange $args 1 end]
                    }
                    default {
                        tailcall DeclError UNKNOWN_TRACE_CMD [lindex $args 0]
                    }
                }
            }
            default {
                tailcall DeclError UNKNOWN_TRACE_CMD $subcmd
            }
        }
    }
    proc traceControl {op args} {
        switch -exact -- $op {
            on {
                namespace upvar Trace traceState traceState
                set traceState on
            }
            off {
                namespace upvar Trace traceState traceState
                set traceState off
            }
            status {
                namespace upvar Trace traceState traceState
                return $traceState
            }
            clear {
                relvar eval {
                    foreach rvar {Trace Creation Polymorphic Transition} {
                        relvar set Trace::$rvar\
                                [relation emptyof [relvar set Trace::$rvar]]
                    }
                }
                namespace upvar Trace traceNumber traceNumber
                set traceNumber 0
            }
            logon {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState on
            }
            logoff {
                namespace upvar Trace traceLogState traceLogState
                set traceLogState off
            }
            loglevel {
                namespace upvar Trace traceLogLevel traceLogLevel
                if {[llength $args] != 0} {
                    set traceLogLevel [lindex $args 0]
                }
                return $traceLogLevel
            }
            save {
                if {[llength $args] == 0} {
                    DeclError NO_SAVEFILE
                }
                ral storeToSQLite [lindex $args 0] ::rosea::Trace::*
            }
            default {
                DeclError BAD_TRACEOP $op
            }
        }
    }
    proc formatTraces {tracerecs} {
        if {[llength $tracerecs] == 0} {
            return {}
        }
        set prevtime [dict get [lindex $tracerecs 0] time]
        foreach rec $tracerecs {
            dict with rec {
                append result "[Trace::FormatTimestamp $time]: "
                append result "[Trace::FormatTimeAsSec\
                        [expr {$time - $prevtime}]]: "
                set prevtime $time
                append result [Trace::FormatTraceRec $rec] \n
            }
        }
        return [string trimright $result]
    }
    namespace eval Helpers {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        variable errFormats
        set errFormats [dict create {*}{
            SAME_CLASS   {operation is only allowed for references to the same class,\
                            got "%s" and "%s"}
            UNKNOWN_STATE   {unknown state, "%s", for class, "%s"}
            UNKNOWN_EVENT   {unknown event, "%s", for class, "%s"}
            NO_CREATION_EVENTS   {class, "%s", has no defined creation events}
            NO_CROSS_DOMAIN         {cannot link instances across domains,\
                                        got "%s" and "%s"}
            UNKNOWN_RELATIONSHIP    {unknown relationship, "%s"}
            NON_PARTICIPANTS        {"%s" and "%s" don't participate in %s,\
                                        expected "%s" and "%s"}
            MUST_BE_SINGULAR    {number of referred to instances for "%s" must be one,\
                                    got %d}
            NOT_IN_ASSOCIATION         {"%s" $relvar1 not a participant in "%s"}
            DIRECTION_REQUIRED  {direction argument is required: got "%s"}
            AMBIGUOUS_UNLINK         {"%s" is reflexive and linking via "%s" is ambiguous}
            NO_SUBCLASS         {relationship "%s" does not have a "%s"}
            NO_ASSIGNER         {relationship, "%s", does not have an assigner}
            NO_IDENTIFIER       {bad identifying attributes, expected "%s", got "%s"}
            UNKNOWN_ASSIGNER    {unknown assigner instance, "%s", for relationship, "%s"}
            UNKNOWN_LINKAGE {unknown relationship, "%s", for class, "%s"}
            PATH_ERROR      {relationship, "%s", from "%s" to "%s", does not end at "%s"}
            GEN_PATH_ERROR  {navigating from superclass, "%s", along generalization "%s",\
                            does not have "%s" as a subclass}
            ARG_ERROR           {attribute updates must be name / value pairs, got "%s"}
            ID_UPDATE           {cannot update identifying attributes, "%s"}
            UNKNOWN_ATTRIBUTE   {unknown attribute, "%s"}
            WITH_ATTR_USAGE {wrong arguments, should be,\
                    "withAttribute attrvarpair1 ?attrvarpair2 ...? body"}
            ATTR_VAR_SPEC   {attribute / variable argument must be a one or two element\
                    list, got "%s"}
            INVALID_TIME    {invalid time value, "%s"}
            SINGLE_OR_EMPTY_REF_REQUIRED {single valued or nil reference required, %d found}
            SINGLE_REF_REQUIRED     {single valued reference required, %d found}
            ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
                with attributes, "%s", failed: %s}
            EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
            CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}
            CONFIG_ERRORS     {encountered %d configuration script errors}
            EMPTY_NAME      {the empty string is not a valid name for a %s}
            BAD_CLASS_NAME      {class names must be begin with an alphanumeric\
                                character, got: "%s"}
            DUP_ELEMENT_NAME    {a class, relationship or domain operation named, "%s",\
                                already exists}
            RESERVED_NAME {names beginning with two underscore characters are reserved,\
                    "%s" cannot be used as a name in this context}
            INT_TYPE_REQUIRED   {attribute must be of "int" type, got "%s"}
            INT_VALUE_REQUIRED  {an integer value is required, got "%s"}
            ARG_FORMAT      {options and values must come in pairs, got "%s"}
            UNKNOWN_OPTION  {unknown %s command option, "%s"}
            DUP_OP_NAME     {operation call, "%s", already exists}
            NS_QUALIFIERS   {name, "%s", contains namespace qualifiers}
            TILDE_NAME {names beginning with the tilde character are not allowed\
                in this context, "%s"}
                
            BAD_RELATIONSHIP_SPEC  {bad relationship specifier, "%s"}
            NEED_ASSOCIATOR {relationship of type, "%s", requires associative class}
            NEED_REFLEXIVE_PATH {traversal path must be specified for reflexive\
                    association, %s, %s %s %s}
            REFLEXIVE_NOT_ALLOWED   {associations of type, "%s", cannot be reflexive}
            TOO_FEW_SUBCLASSES  {at least 2 subclasses must be specified, got %d}
            BAD_CREATION_TARGET {the target of a creation event must be a state,\
                    got "%s"}
            PSEUDO_STATE    {the transition action, "%s", is not valid as %s}
            EXPECTED_PSEUDO_STATE    {expected CH or IG, got "%s"}
            RELVAR_TRACE_OP     {unexpected relvar trace operation, "%s"}
            ATTR_CHECK_FAILED   {check for attribute, "%s", failed:\
                                instance value was, "%s": "%s" evaluated to "%s"}
            UNKNOWN_DOMAIN  {unknown domain, "%s"}
            ARG_MISMATCH      {number of population values must be a multiple of %d, got %d}
            SAVE_ARG_ERROR  {wrong number of arguments: expected:\
                    "save ?-sqlite | -tclral? ?-async <cmdprefix>?\
                    <domain> <filename>", got: "%s"}
            RESTORE_ARG_ERROR  {wrong number of arguments: expected:\
                    "restore ?-sqlite | -tclral?  <domain> <filename>", got: "%s"}
            UNKNOWN_INFO_CMD  {unknown info request, "%s"}
            UNKNOWN_CLASS  {unknown class, "%s", in domain, "%s"}
            UNKNOWN_TRACE_CMD   {unknown trace subcomand, "%s"}
            BAD_TRACEOP     {unknown trace operation, "%s"}
            NO_SAVEFILE     {no save file name provided}
            BAD_TRACETYPE   {unknown trace type, "%s"}
        }]
        proc ToRef {relvar relvalue} {
            tailcall list $relvar [relation project $relvalue\
                {*}[lindex [relvar identifiers $relvar] 0]] ; # <1>
        }
        proc nilInstRef {} {
            return {{} {{} {}}}
        }
        proc CreateStateInstance {domns class state idattrs} {
            tailcall relvar insert ${domns}::${class}__STATEINST\
                    [concat $idattrs [list __State $state]]
        }
        proc CreateInInitialState {domns class idattrs} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstance $domns $class [relation extract $initstate State]\
                    $idattrs
            }
            return
        }
        proc CreateStateInstanceFromRef {domns class state ref} {
            relation foreach inst [lindex $ref 1] { # <1>
                CreateStateInstance $domns $class $state\
                    [tuple get [relation tuple $inst]]
            }
            return
        }
        proc CreateInInitialStateFromRef {domns class ref} {
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstanceFromRef $domns $class\
                    [relation extract $initstate State] $ref
            }
            return
        }
        proc SelfInstRef {{level 2}} {
            set foundRef false
            set ref [nilInstRef]
        
            for {set ns [uplevel $level namespace current]} {$ns ne "::"}\
                    {set ns [uplevel [incr level] namespace current]} {
                if {!$foundRef} {
                    upvar $level self srcself
                    if {[info exists srcself]} {
                        set ref $srcself
                        set foundRef true
                    }
                }
                if {[string match {*__Activity*} $ns]} {
                    return $ref ; # <1>
                }
            }
            return [nilInstRef]
        }
        namespace export DeclError
        
        proc DeclError {errcode args} {
            variable errFormats
            set errmsg [format [dict get $errFormats $errcode] {*}$args]
            tailcall throw [list ROSEA $errcode {*}$args $errmsg] $errmsg
        }
        proc SplitRelvarName {relvar {dvarname domain} {cvarname class}} {
            upvar 1 $dvarname domain $cvarname class
            set domain [namespace qualifiers $relvar]
            set class [namespace tail $relvar]
        }
        proc PropagatePolyEvents {super} {
            namespace upvar ::rosea::Config\
                DeferredEvent DeferredEvent\
                LocalEvent LocalEvent\
                Superclass Superclass\
                Subclass Subclass\
                DeferralPath DeferralPath\
                Generalization Generalization ; # <1>
        
            set supername [relation extract $super Class]
        
            set subs [pipe {
                relation semijoin $super\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}
            }]
        
            relation foreach sub $subs {
                set defrdevents [pipe {
                    relation semijoin $super $DeferralPath\
                        -using {Domain Domain Class Model Relationship Relationship}\
                        $DeferredEvent |
                    relation update ~ deftup {1} {
                        tuple update $deftup Model [relation extract $sub Class]
                    }
                }]
                set multigens [relation semijoin $sub $Superclass\
                    -using {Domain Domain Class Class}]
        
                if {[relation isempty $multigens]} {
                    relvar minus ::rosea::Config::LocalEvent $defrdevents
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::EffectiveEvent $defrdevents
                    relvar union ::rosea::Config::MappedEvent [relation extend\
                        $defrdevents metuple ParentModel string {$supername}]
                } else {
                    set consumed [relation semijoin $defrdevents $LocalEvent]
                    if {[relation isnotempty $consumed]} {
                        relvar minus ::rosea::Config::LocalEvent $consumed ; # <1>
                        relvar union ::rosea::Config::MappedEvent [relation extend\
                            $consumed ctup ParentModel string {$supername}]
                        relvar union ::rosea::Config::NonLocalEvent [relation extend\
                            $consumed nletuple\
                            Relationship string {[relation extract $sub Relationship]}\
                            Role string {[relation extract $sub Role]}]
                        set defrdevents [relation minus $defrdevents $consumed] ; # <2>
                    
                        set usedinsubs [pipe {
                            FindSubclassesOf $multigens|
                            relation tclose ~ |
                            relation semijoin $consumed ~ -using {Model Super} |
                            relation semijoin ~ $LocalEvent -using {Sub Model} |
                            relation semijoin $consumed ~ -using {Domain Domain Event Event}
                        }]
                        relvar minus ::rosea::Config::LocalEvent $usedinsubs ; # <3>
                        relvar minus ::rosea::Config::EffectiveEvent $usedinsubs
                        relvar minus ::rosea::Config::Event $usedinsubs
                    }
                    relvar union ::rosea::Config::Event $defrdevents
                    relvar union ::rosea::Config::DeferredEvent $defrdevents
                    relvar union ::rosea::Config::InheritedEvent $defrdevents
                    relvar union ::rosea::Config::DeferralPath [relation join\
                        $defrdevents $Superclass -using {Domain Domain Model Class}]
                }
        
                relvar union ::rosea::Config::NonLocalEvent [relation extend\
                    $defrdevents nletuple\
                    Relationship string {[relation extract $sub Relationship]}\
                    Role string {[relation extract $sub Role]}]
                relation foreach multigen $multigens {
                    PropagatePolyEvents $multigen
                }
            }
        }
        proc FindSubclassesOf {supers} {
            namespace upvar ::rosea::Config\
                Generalization Generalization\
                Superclass Superclass\
                Subclass Subclass
        
            if {[relation isempty $supers]} {# <1>
                return [relation create {Super string Sub string}]
            }
            set supnames [pipe {
                relation project $supers Class |
                relation rename ~ Class Super
            }] ; # <2>
            set subclasses [relation semijoin $supers\
                    $Generalization -using {Domain Domain Relationship Name}\
                    $Subclass -using {Domain Domain Name Relationship}]
            set subnames [pipe {
                relation project $subclasses Class |
                relation rename ~ Class Sub
            }] ; # <3>
            
            set uses [relation times $supnames $subnames] ; # <4>
        
            set nextsupers [relation semijoin $subclasses $Superclass\
                    -using {Domain Domain Class Class}] ; # <5>
        
            return [relation union $uses [FindSubclassesOf $nextsupers]] ; # <6>
        }
        proc UserDefaultTrace {defheading defvalues op relvar tuple} {
            tuple create\
                [dict merge $defheading [tuple heading $tuple]]\
                [dict merge $defvalues [tuple get $tuple]]
        }
        proc SupplyDefaultTrace {defheading op relvar tuple} {
            set attrs [tuple attributes $tuple] ; # <1>
            SplitRelvarName $relvar domain class ; # <2>
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [set ${domain}::__Arch_SuppliedDefault($class,$attrname)] ; # <3>
                    incr ${domain}::__Arch_SuppliedDefault($class,$attrname)
                    set tuple [tuple extend $tuple $attrname $attrtype $value] ; # <4>
                }
            }
            return $tuple
        }
        proc GenerateDefaultTrace {defheading defcmds op relvar tuple} {
            set attrs [tuple attributes $tuple]
            foreach {attrname attrtype} $defheading {
                if {$attrname ni $attrs} {
                    set value [eval [dict get $defcmds $attrname]]
                    set tuple [tuple extend $tuple $attrname $attrtype $value]
                }
            }
            return $tuple
        }
        proc CheckValueTrace {attrchecks op relvar args} {
            if {$op eq "insert"} {
                set tuple [lindex $args 0]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "update"} {
                set tuple [lindex $args 1]
                EvalAttrCheck $attrchecks $tuple
                return $tuple
            } elseif {$op eq "set"} {
                set relvalue [lindex $args 0]
                relation foreach inst $relvalue {
                    set tuple [relation tuple $inst]
                    EvalAttrCheck $attrchecks $tuple
                }
                return $relvalue
            } else {
                tailcall DeclError RELVAR_TRACE_OP $op
            }
        }
        proc EvalAttrCheck {attrchecks tuple} {
            dict for {attrname checkexpr} $attrchecks {
                tuple assign $tuple
                set result [expr $checkexpr]
                if {!$result} {
                    tailcall DeclError ATTR_CHECK_FAILED $attrname [tuple get $tuple]\
                        $checkexpr $result
                }
            }
        }
        proc QuerySystemOperations {which requiresSM} {
            return [pipe {
                relvar set ::rosea::Config::SuppliedOperation |
                relation restrictwith ~ {$RequiresStateModel == $requiresSM} |
                relation join [relvar set ::rosea::Config::$which] ~
            }]
        }
        proc QuerySystemClassOperations {className requiresSM} {
            return [pipe {
                QuerySystemOperations SystemClassOperation $requiresSM |
                relation update ~ sco 1 {
                    tuple update $sco Command\
                        [concat [tuple extract $sco Command]\
                        [list $className]]
                } |
                relation dict ~ Name Command
            }]
        }
        proc QuerySystemInstanceOperations {requiresSM} {
            return [pipe {
                QuerySystemOperations SystemInstanceOperation $requiresSM |
                relation dict ~ Name Command
            }]
        }
        proc Interleave {l1 l2} {
            set result [list]
            foreach a $l1 b $l2 {
                lappend result $a $b
            }
            return $result
        }
        proc MapCondMultToConstraint {cond mult} {
            if {$cond} {
                return [expr {$mult ? "*" : "?"}]
            } else {
                return [expr {$mult ? "+" : "1"}]
            }
        }
    }
    namespace eval ClassCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers ; # <1>
        proc findAll {relvar} {
            tailcall ToRef $relvar [relvar set $relvar]
        }
        proc findById {relvar args} {
            tailcall ToRef $relvar [relvar restrictone $relvar {*}$args]
        }
        proc findWhere {relvar expr} {
            tailcall ToRef $relvar [uplevel 1 [list ::ral relation restrictwith\
                [relvar set $relvar] $expr]]
        }
        proc create {relvar args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]] ; # <1>
            SplitRelvarName $relvar domain class
            CreateInInitialStateFromRef $domain $class $ref
            return $ref
        }
        proc createin {relvar state args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $relvar domain class
            set initstate [relvar restrictone ${domain}::__Arch_State\
                Class $class State $state]
            if {[relation isempty $initstate]} { # <1>
                tailcall DeclError UNKNOWN_STATE $state $relvar
            }
            set ref [ToRef $relvar [relvar insert $relvar $args]]
            CreateStateInstanceFromRef $domain $class $state $ref
            return $ref
        }
        proc createasync {relvar event eventparams args} {
            SplitRelvarName $relvar domain class
        
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
            if {[relation isempty [relvar restrictone ${domain}::__Arch_State\
                    Class $class State @]]} {
                tailcall DeclError NO_CREATION_EVENTS $class
            }
            set srcref [SelfInstRef]
            set eventInfo [dict create\
                type creation\
                src $srcref\
                dstClass $relvar\
                dstAttrs $args\
                event $event\
                params $eventparams\
            ]
            if {[::rosea::InstCmds::isRefEqual $srcref [nilInstRef]]} {
                lappend ::rosea::Dispatch::toc_queue $eventInfo
            } else {
                lappend ::rosea::Dispatch::event_queue $eventInfo
            }
            ::after 0 ::rosea::Dispatch::DispatchEvent
            return
        }
        proc update {relvar relvalue} {
            tailcall ToRef $relvar [relvar updateper $relvar $relvalue]
        }
    }
    namespace eval InstCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace path [namespace parent]::Helpers
        pipe {
            relvar set ${domain}::$DstClass |
            relation $op $related ~ -using $Attrs
        } relatedQuery
        proc deRef {instref args} {
            lassign $instref relvar ref
            set inst [relation semijoin $ref [relvar set $relvar]] ; # <1>
            if {[llength $args] != 0} {
                set inst [relation project $inst\
                    {*}[relation attributes $ref] {*}$args] ; # <2>
            }
            return $inst
        }
        proc isEmptyRef {instref} {
            tailcall relation isempty [lindex $instref 1]
        }
        proc isNotEmptyRef {instref} {
            tailcall relation isnotempty [lindex $instref 1]
        }
        proc refMultiplicity {instref} {
            tailcall relation cardinality [lindex $instref 1]
        }
        proc isRefSingular {instref} {
            expr {[refMultiplicity $instref] == 1}
        }
        proc limitRef {instref {count 1}} {
            lassign $instref relvar insts
            return [pipe {
                relation tag $insts __Tag |
                relation restrictwith ~ {$__Tag >= 0 && $__Tag < $count} |
                ToRef $relvar ~
            }]
        }
        proc isRefEqual {instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            return [expr {$relvar1 eq $relvar2 && [relation is $inst1 equal $inst2]}]
        }
        proc RefSetCommand {op instref1 instref2} {
            lassign $instref1 relvar1 inst1
            lassign $instref2 relvar2 inst2
            if {$relvar1 ne $relvar2} {
                tailcall DeclError SAME_CLASS $relvar1 $relvar2
            }
            return [list $relvar1 [relation $op $inst1 $inst2]]
        }
        proc refUnion {instref1 instref2} {
            tailcall RefSetCommand union $instref1 $instref2
        }
        proc refIntersect {instref1 instref2} {
            tailcall RefSetCommand intersect $instref1 $instref2
        }
        proc refMinus {instref1 instref2} {
            tailcall RefSetCommand minus $instref1 $instref2
        }
        proc forAllRefs {varname instref body} {
            lassign $instref relvar refs
            upvar 1 $varname inst
            relation foreach ref $refs {
                set inst [list $relvar $ref]
                uplevel 1 $body
            } ; # <1>
            return
        }
        proc FindRelatedInsts {instref op args} {
            set srcrelvar [lindex $instref 0]
            SplitRelvarName $srcrelvar domain class
            
            # This procedure queries the architectural data about relationship linkage,
            # so we bring the relvar variables into scope.
            namespace upvar ${domain}\
                    __Arch_Link Link\
                    __Arch_AssociationLink AssociationLink\
                    __Arch_PartitionLink PartitionLink\
                    __Arch_PartitionDst PartitionDst
            variable relatedQuery ; # <1>
            # We start by dereferencing the instance reference.
            set related [deRef $instref]
            foreach linkage $args {
                lassign $linkage lname dst ; # split out the linkage spec
                
                set link [relvar restrictone ${domain}::__Arch_Link\
                        Name $lname SrcClass $class]
                if {[ral relation isempty $link]} {
                    tailcall DeclError UNKNOWN_LINKAGE $lname $class
                }
                # First we determine if we are dealing with an associative link or a
                # partition link.
                set assoc [relation join $link $AssociationLink]
                if {[relation isnotempty $assoc]} {
                    relation assign $assoc DstClass Attrs
                    # Check if additional path information was provided.
                    if {$dst eq {}} {
                        # Find the set of instances related to the current set.
                        set related [eval $relatedQuery]
                        # We must see if this is a class-based association.  If so, then the first
                        # traversal was to the associator and we must traverse again to the other
                        # class.
                        set assoc [relation semijoin $assoc $AssociationLink\
                            -using {Name Name SrcClass PrevSrcClass}]
                        if {[relation isnotempty $assoc]} {
                            relation assign $assoc DstClass Attrs
                            set related [pipe {# <1>
                                relvar set ${domain}::$DstClass |
                                relation semijoin $related ~ -using $Attrs
                            }]
                        }
                    } else {
                        # If a destination was specified in the linkage, then we need to verify
                        # that it is actually part of the relationship.
                        if {$dst ne $DstClass} {
                            tailcall DeclError PATH_ERROR $lname $class $DstClass\
                                $dst
                        }
                        set related [eval $relatedQuery]
                    }
                } else {
                    set partdst [relvar restrictone ${domain}::__Arch_PartitionDst\
                        Name $lname SrcClass $class DstClass $dst]
                    if {[relation isempty $partdst]} {
                        tailcall DeclError GEN_PATH_ERROR $class $lname $dst
                    }
                    relation assign $partdst DstClass Attrs
                    set related [eval $relatedQuery]
                }
                # Continue the iteration by setting the next source to the current
                # destination class.
                set class $DstClass
                set srcrelvar ${domain}::$class
            }
            # N.B. that we are not returning an instance reference but rather the
            # complete relation value of the related instances. This allows us
            # to further filter the result in the "findRelatedWhere" command.
            return [list $srcrelvar $related]
        }
        proc findRelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semijoin {*}$args] ; # <1>
        }
        proc findUnrelated {instref args} {
            tailcall ToRef {*}[FindRelatedInsts $instref semiminus {*}$args] ; # <1>
        }
        proc findRelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semijoin {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]] ; # <1>
        }
        proc findUnrelatedWhere {instref rchain expr} {
            lassign [FindRelatedInsts $instref semiminus {*}$rchain] relvar insts
            tailcall ToRef $relvar [uplevel 1\
                [list ::ral relation restrictwith $insts $expr]]
        }
        proc idInstance {instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set idclass [pipe {
                relvar restrictone [namespace parent]::Config::MultipleAssigner\
                        Domain [string trim $domain :] Relationship $relationship |
                relation extract ~ Class
            }]
        
            return [pipe {
                relvar set ${domain}::$idclass |
                relation semijoin $insts ~ |
                ToRef ${domain}::$idclass ~
            }]
        }
        proc updateAttribute {instref args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_ERROR $args
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $args]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach {attr value} $args {
                if {![dict exists $heading $attr]} {
                    tailcall DeclError UNKNOWN_ATTRIBUTE $attr
                }
                lappend extcmd $attr [dict get $heading $attr] \{$value\}
            }
            relvar updateper $relvar [eval $extcmd]
            return
        }
        proc withAttribute {instref args} {
            if {[llength $args] < 2} {
                tailcall DeclError WITH_ATTR_USAGE
            }
            
            lassign $instref relvar insts
            if {[relation cardinality $insts] != 1} {
                tailcall MUST_BE_SINGULAR $relvar [relation cardinality $insts]
            }
            
            set body [lindex $args end]
            set attrspecs [lrange $args 0 end-1]
            set attrnames [list]
            set varnames [list]
            foreach attrspec $attrspecs {
                set speclen [llength $attrspec]
                if {$speclen == 1} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 0]
                } elseif {$speclen == 2} {
                    lappend attrnames [lindex $attrspec 0]
                    lappend varnames [lindex $attrspec 1]
                } else {
                    tailcall DeclError ATTR_VAR_SPEC $attrspec
                }
            }
            set idattrs [list]
            foreach identifier [relvar identifiers $relvar] {
                ::struct::set add idattrs $identifier
            }
            set idupdates [::struct::set intersect $idattrs $attrnames]
            if {![::struct::set empty $idupdates]} {
                tailcall DeclError ID_UPDATE [join $idupdates {, }]
            }
            uplevel 1 [list ral relation assign [deRef $instref] {*}$attrspecs]
            uplevel 1 $body
            set extcmd [list relation extend $insts exttuple]
            set heading [relation heading [relvar set $relvar]]
            foreach attr $attrnames var $varnames {
                if {[uplevel 1 [list info exists $var]]} {
                    upvar 1 $var varvalue
                    lappend extcmd $attr [dict get $heading $attr] \{$varvalue\}
                }
            }
            relvar updateper $relvar [eval $extcmd]
        
            return
        }
        proc readAttribute {ref args} {
            # We insist upon a singular reference for reading attributes.  Multiple
            # references can be handled by dereferences and using TclRAL "relation"
            # commands.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            return [expr {[llength $args] == 0 ? {} :\
                [relation extract [deRef $ref {*}$args] {*}$args]}] ; # <1>
        }
        proc assignAttribute {ref args} {
            # We must insist upon a singular references, since assigning to scalar
            # variables from a relation value doesn't make a lot of sense.
            if {![isRefSingular $ref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $ref]
            }
        
            uplevel 1 [list ral relation assign [deRef $ref] {*}$args] ; # <1>
            return
        }
        proc delete {args} {
            foreach instref $args {
                lassign $instref relvar insts
                relvar minus $relvar [deRef $instref]
        
                SplitRelvarName $relvar domain class
                set instrelvar ${domain}::${class}__STATEINST
                if {[relvar exists $instrelvar]} {
                    relvar minus $instrelvar [relation semijoin $insts\
                        [relvar set $instrelvar]]
                }
            }
        
            return
        }
        proc signal {dstset event args} {
            set srcref [SelfInstRef]
            if {![::rosea::Dispatch::MapPolymorphicEvent ::rosea::Dispatch::SignalEvent\
                    $srcref $dstset $event $args]} {
                ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args
            }
            return
        }
        proc delaysignal {time dstset event args} {
            if {!([string is integer -strict $time] && $time >= 0)} {
                tailcall DeclError INVALID_TIME $time
            }
            set srcref [SelfInstRef]
            if {![::rosea::Dispatch::MapPolymorphicEvent\
                    [list ::rosea::Dispatch::SignalDelayedEvent $time]\
                    $srcref $dstset $event $args]} {
                ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args
            }
            return
        }
        proc canceldelayed {srcref dstset event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            forAllRefs dstref $dstset {
                ::rosea::Dispatch::CancelDelayedSignal $srcref $event $dstref
            }
            return
        }
        proc delayremaining {srcref dstref event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
            if {![isRefSingular $dstref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $dstref]
            }
            tailcall ::rosea::Dispatch::SignalTimeRemaining $srcref $event $dstref
        }
        proc instop {instref op args} {
            tailcall [lindex $instref 0]::Instance $instref $op {*}$args
        }
    }
    namespace eval RelCmds {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        proc linkSimple {rname instref1 instref2} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set reflink [relvar restrictone ${domain1}::__Arch_RefLink Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs} ; # <1>
            if {$class1 eq $referringClass && $class2 eq $referencedClass} {
                set fromrelvar $relvar1
                set frominsts $inst1
                set torelvar $relvar2
                set toinst $inst2
            } elseif {$class2 eq $referringClass && $class1 eq $referencedClass} {
                set fromrelvar $relvar2
                set frominsts $inst2
                set torelvar $relvar1
                set toinst $inst1
            } else {
                tailcall DeclError NON_PARTICIPANTS $relvar1 $relvar2 $rname\
                    $referringClass $referencedClass
            }
            if {[relation cardinality $toinst] != 1} {
                tailcall MUST_BE_SINGULAR $torelvar [relation cardinality $toinst]
            }
            set refedvalue [relation semijoin $toinst [relvar set $torelvar]]
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] { # <1>
                    tuple update $fromtup {*}$tovalues ; # <2>
                }
            }
        
            return
        }
        proc linkAssoc {rname instref1 instref2 args} {
            lassign $instref1 relvar1 inst1
            SplitRelvarName $relvar1 domain1 class1
            
            lassign $instref2 relvar2 inst2
            SplitRelvarName $relvar2 domain2 class2
            
            if {$domain1 ne $domain2} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${domain1}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            set ref1 [relation restrictwith $references {$Participant eq $class1}]
            if {[relation isempty $ref1]} {
                tailcall DeclError NOT_IN_ASSOCIATION $class1 $rname
            }
            if {[relation cardinality $ref1] > 1} {
                set ref2 [relation restrictwith $ref1 {$Role eq "target"}]
                set ref1 [relation minus $ref1 $ref2] ; # <1>
            } else {
                set ref2 [relation restrictwith $references {$Participant eq $class2}]
                if {[relation isempty $ref2]} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class2 $rname
                }
            }
            
            set rattr1 [relation extract $ref1 ReferringAttrs]
            set rattr2 [relation extract $ref2 ReferringAttrs]
            set values1 [relation semijoin $inst1 [relvar set $relvar1]]
            set values2 [relation semijoin $inst2 [relvar set $relvar2]]
            set assoctuples [list]
            relation foreach v1 $values1 { # <1>
                set refto1 [pipe {
                    relation extend $rattr1 rfa RefValue string {
                        [relation extract $v1 [tuple extract $rfa ReferencedAttribute]]
                    } |
                    relation dict ~ ReferringAttribute RefValue
                }]
                relation foreach v2 $values2 {
                    set refto2 [pipe {
                        relation extend $rattr2 rfa RefValue string {
                            [relation extract $v2\
                                [tuple extract $rfa ReferencedAttribute]]
                        } |
                        relation dict ~ ReferringAttribute RefValue
                    }]
            
                    lappend assoctuples [dict merge $args $refto1 $refto2] ; # <2>
                }
            }
            set ref [ToRef ${domain1}::$assocClass\
                    [relvar insert ${domain1}::$assocClass {*}$assoctuples]]
                CreateInInitialStateFromRef $domain1 $assocClass $ref ; # <1>
            return $ref
        }
        proc referenceAssoc {rname assocref instref {dir {}}} {
            if {![isRefSingular $assocref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $assocref]
            }
            lassign $assocref assocrelvar associnst
            SplitRelvarName $assocrelvar assocdomain assocclass
            
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref instrelvar inst
            SplitRelvarName $instrelvar instdomain instclass
            
            if {$assocdomain ne $instdomain} {
                tailcall DeclError NO_CROSS_DOMAIN $domain1 $domain2
            }
            set assocref [relvar restrictone ${instdomain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            
            relation assign $assocref\
                {AssocClass assocClass}\
                {References references}
            
            if {$assocClass ne $assocclass} {
                tailcall DeclError NOT_IN_ASSOCIATION $assocclass $rname
            }
            set ref [relation restrictwith $references {$Participant eq $instclass}]
            set refcard [relation cardinality $ref]
            if {$refcard == 2} {
                switch -exact -- $dir {
                    forward {
                        set role target
                    }
                    backward {
                        set role source
                    }
                    default {
                        tailcall DeclError DIRECTION_REQUIRED $dir
                    }
                }
                set ref [relation restrictwith $ref {$Role eq $role}]
            } elseif {$refcard == 0} {
                tailcall DeclError NOT_IN_ASSOCIATION $instclass $rname
            }
            set referringAttrs [relation extract $ref ReferringAttrs]
            
            set refedvalue [relation semijoin $inst [relvar set $instrelvar]]
            
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {
                    [relation extract $refedvalue\
                        [tuple extract $rfa ReferencedAttribute]]} |
                relation dict ~ ReferringAttribute RefValue
            }]
            relvar updateone $assocrelvar assoctup [tuple get [relation tuple $associnst]] {
                tuple update $assoctup {*}$tovalues
            }
        }
        proc unlinkSimple {rname instref} {
            lassign $instref relvar inst
            SplitRelvarName $relvar domain class
        
            set reflink [relvar restrictone ${domain}::__Arch_RefLink\
                    Relationship $rname]
            if {[relation isempty $reflink]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $reflink\
                {ReferringClass referringClass}\
                {ReferencedClass referencedClass}\
                {ReferringAttrs referringAttrs}
        
            if {$class eq $referringClass} {
                set fromrelvar $relvar
                set frominsts $inst
            } elseif {$class eq $referencedClass} {
                lassign [::rosea::InstCmds::findRelated $instref ~$rname]\
                    fromrelvar frominsts
            } else {
                tailcall DeclError NOT_IN_ASSOCIATION $relvar $rname
            }
        
            set tovalues [pipe {
                relation extend $referringAttrs rfa RefValue string {{}} |
                relation dict ~ ReferringAttribute RefValue
            }]
        
            relation foreach frominst $frominsts {
                relvar updateone $fromrelvar fromtup\
                        [tuple get [relation tuple $frominst]] {
                    tuple update $fromtup {*}$tovalues
                }
            }
        
            return
        }
        proc unlinkAssoc {rname instref} {
            lassign $instref relvar insts
            SplitRelvarName $relvar domain class
        
            set assocref [relvar restrictone ${domain}::__Arch_AssocRef\
                    Relationship $rname]
            if {[relation isempty $assocref]} {
                tailcall DeclError UNKNOWN_RELATIONSHIP $rname
            }
            relation assign $assocref\
                {Relationship relationship}\
                {AssocClass associator}\
                {References references}
        
            # If we are given instances to the associator class, then there is no
            # more work to do.
            if {$class ne $associator} {
                # Otherwise, we have to find the associator class instances ourselves.
                set part [relation restrictwith $references {$Participant eq $class}]
                set partcard [relation cardinality $part]
                if {$partcard == 0} {
                    tailcall DeclError NOT_IN_ASSOCIATION $class $rname
                } elseif {$partcard > 1} {
                    tailcall DeclError AMBIGUOUS_UNLINK $rname $relvar ; # <1>
                } else {
                    # Find associative class instances.  We have to determine the
                    # direction of the relationship traversal.
                    set navdir [expr {[relation extract $part Role] eq "source" ?\
                        "$relationship" : "~$relationship"}]
                    set instref [::rosea::InstCmds::findRelated $instref\
                        [list $navdir [namespace tail $associator]]]
                    lassign $instref relvar insts
                    SplitRelvarName $relvar domain class
                }
            }
        
            # We are going to delete tuples from the relvar that holds the class
            # instances.
            set delrelvars [list ${domain}::$class]
            # If the associative class also has a state model, then we need to also
            # delete the state instance tuples.
            if {[relvar exists ${domain}::${class}__STATEINST]} {
                lappend delrelvars ${domain}::${class}__STATEINST
            }
        
            # Now, we iterate across the associative class instances and delete all the
            # tuples in class relvar and, if necessary, the state instances.
            relation foreach inst $insts {
                set idattrs [tuple get [relation tuple $inst]]
                foreach rv $delrelvars {
                    relvar deleteone $rv {*}$idattrs
                }
            }
            return $instref
        }
        proc migrate {rname instref subclass args} {
            if {![isRefSingular $instref]} {
                tailcall DeclError SINGLE_REF_REQUIRED [refMultiplicity $instref]
            }
            lassign $instref relvar inst
            SplitRelvarName $relvar domns class
        
            set link [relvar restrictone ${domns}::__Arch_AssociationLink Name $rname\
                    SrcClass $class]
            if {[relation isempty $link]} {
                tailcall DeclError NO_SUBCLASS $rname $relvar
            }
        
            # Traverse the relationship to the superclass. We need to get the values of
            # the referenced attributes to use in creating the new subclass instance.
            set superinst [pipe {
                relvar set ${domns}::[relation extract $link DstClass] |
                relation semijoin $inst ~ -using [relation extract $link Attrs]
            }]
        
            set sublink [relvar restrictone ${domns}::__Arch_SubLink\
                    Relationship $rname SubClass $subclass]
            if {[relation isempty $sublink]} {
                tailcall DeclError NO_SUBCLASS $rname $subclass
            }
        
            # Using the same relation extend strategy, we compute a dictionary of the
            # attribute names / values as they must appear in the subclass we are about
            # to create.
            set refedvalues [pipe {
                relation extract $sublink ReferringAttrs |
                relation extend ~ rval Value string {
                    [relation extract $superinst\
                        [tuple extract $rval ReferencedAttribute]]
                } |
                relation dict ~ ReferringAttribute Value
            }]
        
            # We use the class commands to delete the old subclass instance and create
            # the new one. This will make sure that if the subclass has a state model
            # that the initial state is set correctly.
            # N.B. this is _not_ done in a relvar transaction. The transaction
            # boundaries should be set by the current thread of control or domain
            # operation.
            ::rosea::InstCmds::delete $instref
            return [::rosea::ClassCmds::create ${domns}::$subclass\
                    {*}[dict merge $args $refedvalues]]
        }
        proc signalAssigner {rname event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
        
            set dstref [pipe {
                relvar set $assignrelvar |
                relation project ~ {*}[lindex [relvar identifiers $assignrelvar] 0] |
                list $rname ~
            }]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args
        
            return
        }
        proc signalMultiAssigner {rname idvalues event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [lindex [relvar identifiers $assignrelvar] 0]
            # We will insist that the idvalues contain the necessary identifying
            # attributes.
            if {![struct::set equal [dict keys $idvalues] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
            }
            set assigninsts [relvar set $assignrelvar]
            set assignrefs [relation project $assigninsts {*}$idattrs]
        
            # We need to find the tuple in "assignrefs" that matches the attributes and
            # values in "idvalues". We will do this by creating a relation value from
            # the idvalues list and semijoining that to "assignrefs". If we come up
            # non-empty, then we have found our multi-assigner instance.
            set heading [relation heading $assignrefs]
            set dstinst [pipe {
                tuple create $heading $idvalues |
                tuple relation ~ |
                relation semijoin ~ $assignrefs
            }]
            if {[relation isempty $dstinst]} {
                tailcall DeclError UNKNOWN_ASSIGNER $idvalues $rname
            }
        
            set dstref [list $rname $dstinst]
            ::rosea::Dispatch::SignalEvent [SelfInstRef] $dstref $event $args ; # <1>
        
            return
        }
        proc createMultiAssigner {rname args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [lindex [relvar identifiers $assignrelvar] 0]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            CreateInInitialState $domain $relationship $args
        }
    }
    namespace eval Dispatch {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        variable toc_queue [list]
        variable event_queue [list]
        pipe {
            relvar restrictone ${domain}::__Arch_Transition\
                Class $class State $currstate Event $event |
            relation extract ~ NewState
        } transitionQuery
        relvar create DelayedSignal {
            RefId           int
            SrcInstRef      list
            Event           string
            DstInstRef      list
            TimerId         string
            Expire          bignum
        } RefId {SrcInstRef Event DstInstRef} TimerId
        variable DelayedSignalId 0
        pipe {
            relvar set ${domain}::__Arch_PartitionDst |
            relation restrictwith ~ {$SrcClass eq $dstclass} |
            relation group ~ DstLinks DstClass Attrs
        } polymapQuery
        proc SignalEvent {srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            set callback [namespace code DispatchEvent]
            set eventInfo [dict create\
                type ordinary\
                src $srcref\
                event $event\
                params $arglist\
            ]
            if {[isRefEqual $srcref [nilInstRef]]} {
                variable toc_queue
                forAllRefs dstref $dstset {
                    # Queue the thread of control events.
                    dict set eventInfo dst $dstref
                    lappend toc_queue $eventInfo
                    ::after 0 $callback
                }
            } else {
                variable event_queue
                forAllRefs dstref $dstset {
                    dict set eventInfo dst $dstref
                    if {[isRefEqual $srcref $dstref]} { # <1>
                        for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
                            set cmpevent [lindex $event_queue $eqindex]
                            if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
                                break
                            }
                        }
                        set event_queue [linsert [K $event_queue [set event_queue {}]]\
                                $eqindex $eventInfo] ; # <1>
                    } else {
                        # Non-self directed events are always simply appended to the
                        # event queue.
                        lappend event_queue $eventInfo
                    }
                    ::after 0 $callback
                }
            }
        }
        proc DispatchEvent {} {
            variable event_queue
            variable toc_queue
            
            if {[llength $event_queue] != 0} {
                set eventInfo [lindex $event_queue 0]
                set event_queue [lrange [K $event_queue [set event_queue {}]] 1 end] ; # <1>
            } elseif {[llength $toc_queue] != 0} {
                set eventInfo [lindex $toc_queue 0]
                set toc_queue [lrange [K $toc_queue [set toc_queue {}]] 1 end]
                relvar transaction begin ; # <2>
            } else {
                return
            }
            if {[dict get $eventInfo type] eq "creation"} {
                try {
                    set dstref [::rosea::ClassCmds::createin\
                            [dict get $eventInfo dstClass] @\
                            {*}[dict get $eventInfo dstAttrs]] ; # <1>
                } on error {result} {
                    catch {
                        if {[llength $event_queue] == 0} {
                            relvar transaction end
                        }
                    }
                    tailcall DeclError ASYNC_CREATION_FAILED [dict get $eventInfo dstClass]\
                        [dict get $eventInfo dstAttrs] $result
                }
                dict set eventInfo dst $dstref ; # <2>
                ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
                    [dict get $eventInfo event] $dstref [dict get $eventInfo params]
            }
            set dstref [dict get $eventInfo dst]
            lassign $dstref relvar ref
            SplitRelvarName $relvar domain class
            
            set instrelvar ${domain}::${class}__STATEINST
            set state [relation semijoin $ref [relvar set $instrelvar]]
            if {[relation isempty $state]} {
                tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
            }
            set currstate [relation extract $state __State]
            set event [dict get $eventInfo event]
            variable transitionQuery
            set newState [eval $transitionQuery]
            
            ::rosea::Trace::TraceTransition [dict get $eventInfo src]\
                $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
            try {
                if {$newState eq "CH"} {
                    TransitionError [dict get $eventInfo src] $event $dstref $currstate
                } elseif {$newState ne "IG"} {
                    set idattrs [tuple get [relation tuple $ref]]
                    relvar updateone $instrelvar is $idattrs {
                        tuple update $is __State $newState
                    }
                    try {
                        ${relvar}::__Activity::$newState $dstref\
                                {*}[dict get $eventInfo params] ; # <1>
                    } on error {result opts} {
                        return -options $opts $result
                    } finally {
                        set term [relvar restrictone ${domain}::__Arch_TerminalState\
                                Class $class State $newState]
                        if {[relation isnotempty $term]} {
                            relvar deleteone $relvar {*}$idattrs
                            relvar deleteone $instrelvar {*}$idattrs
                        }
                    }
                }
            } on error {result opts} {
                catch {
                    if {[llength $event_queue] == 0} {
                        relvar transaction end
                    }
                } ; # <1>
                return -options $opts $result
            }
            
            if {[llength $event_queue] == 0} {
                relvar transaction end
            }
            return
        }
        proc TransitionError {src event dst currstate} {
            tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
        }
        proc FindDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            return [relation restrictwith $DelayedSignal {
                    [isRefEqual $SrcInstRef $srcref] && $Event eq $event &&\
                    [isRefEqual $DstInstRef $dstref]}]
        }
        proc DeleteDelayedSignal {srcref event dstref} {
            relvar delete DelayedSignal dsig {
                [isRefEqual [tuple extract $dsig SrcInstRef] $srcref] &&\
                [tuple extract $dsig Event] eq $event &&\
                [isRefEqual [tuple extract $dsig DstInstRef] $dstref]
            }
        }
        proc SignalDelayedEvent {time srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            variable DelayedSignalId
            set eventInfo [dict create\
                id [incr DelayedSignalId]\
                type ordinary\
                src $srcref\
                event $event\
                params $arglist\
            ]
            forAllRefs dstref $dstset {
                dict set eventInfo dst $dstref
                DeleteDelayedSignal $srcref $event $dstref ; # <1>
                relvar insert DelayedSignal [list\
                    RefId       $DelayedSignalId\
                    SrcInstRef  $srcref\
                    Event       $event\
                    DstInstRef  $dstref\
                    TimerId     [::after $time [list\
                                ::rosea::Dispatch::DispatchDelayedEvent $eventInfo]]\
                    Expire      [expr {entier([clock milliseconds]) + entier($time)}]\
                ]
            }
            return
        }
        proc DispatchDelayedEvent {eventInfo} {
            relvar deleteone DelayedSignal RefId [dict get $eventInfo id]
            variable toc_queue
            lappend toc_queue $eventInfo
            tailcall DispatchEvent
        }
        proc CancelDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            set sig [FindDelayedSignal $srcref $event $dstref]
            if {[relation isnotempty $sig]} {
                ::after cancel [relation extract $sig TimerId]
                DeleteDelayedSignal $srcref $event $dstref
            } else {
                # Search the toc_queue to see if the signal delay has already expired
                # and the event is awaiting dispatch.
                variable toc_queue
                for {set i 0} {$i < [llength $toc_queue]} {incr i} {
                    set eventInfo [lindex $toc_queue $i]
                    dict update eventInfo src evtsrc dst evtdst event evtevent {
                        if {[isRefEqual $evtsrc $srcref] &&\
                                [isRefEqual $evtdst $dstref] &&\
                                $evtevent eq $event} {
                            set toc_queue [lreplace\
                                    [K $toc_queue [set toc_queue {}]] $i $i]
                            break
                        }
                    }
                }
            }
        }
        proc SignalTimeRemaining {srcref event dstref} {
            set sig [FindDelayedSignal $srcref $event $dstref]
            return [expr {[relation isempty $sig] ? 0 :\
                max([relation extract $sig Expire] - [clock milliseconds], 0)}] ; # <1>
        }
        proc MapPolymorphicEvent {frwdcmd srcref dstrefs event arglist} {
            lassign $dstrefs dstrelvar dstinsts
            SplitRelvarName $dstrelvar domain dstclass
            set polyevent [relvar restrictone ${domain}::__Arch_PolymorphicEvent\
                Class $dstclass Event $event]
            if {[relation isempty $polyevent]} {
                return false
            }
            variable polymapQuery
            set partitions [eval $polymapQuery]
            relation foreach inst $dstinsts {
                relation foreach partition $partitions {
                    relation assign $partition
                    relation foreach dstlink $DstLinks {
                        relation assign $dstlink
                        set related [relation semijoin $inst\
                            [relvar set ${domain}::$DstClass] -using $Attrs]
                        if {[relation isnotempty $related]} {
                            set dstreference [ToRef ${domain}::${DstClass} $related]
                            set target [ToRef $dstrelvar $inst]
                            ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\
                                    $arglist
                            if {![MapPolymorphicEvent $frwdcmd $srcref $dstreference $event $arglist]} {
                                {*}$frwdcmd $srcref $dstreference $event $arglist ; # <1>
                            }
                            break
                        }
                    }
                }
            }
        
            return true
        }
    }
    namespace eval Config {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [namespace parent]::Helpers
        variable evalLambda {{body} {
            upvar #0 ::rosea::Config::errcount errcount ; # <1>
            upvar #0 ::rosea::Config::configlineno configlineno
            set lineno $configlineno
            set command {}
            foreach line [split $body \n] { # <2>
                append command $line \n
                incr lineno ; # <3>
                if {[info complete $command]} {
                    try {
                        eval $command
                    } on error {result} {
                        log::error "line $configlineno: \"$result\""
                        incr errcount
                    }
                    set command {} ; # <4>
                    set configlineno $lineno
                }
            }
            return $errcount
        }}
        relvar create Domain {
            Name        string
            Location    string
        } Name
        relvar create DomainElement {
            Domain  string
            Element string
        } {Domain Element}
        relvar association R1\
            DomainElement Domain *\
            Domain Name 1
        relvar create Class {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create Relationship {
            Domain  string
            Name    string
        } {Domain Name}
        relvar create DomainOperation {
            Domain      string
            Name        string
            Parameters  list
            Body        string
        } {Domain Name}
        relvar partition R2 DomainElement {Domain Element}\
            Class {Domain Name}\
            Relationship {Domain Name}\
            DomainOperation {Domain Name}
        relvar create Attribute {
            Domain  string
            Class   string
            Name    string
            Type    string
        } {Domain Class Name}
        relvar association R3\
            Attribute {Domain Class} +\
            Class {Domain Name} 1
        relvar create Identifier {
            Domain  string
            Class   string
            Number  int
        } {Domain Class Number}
        relvar association R4\
            Identifier {Domain Class} +\
            Class {Domain Name} 1
        relvar create IdentifyingAttribute {
            Domain      string
            Class       string
            Attribute   string
            Number      int
        } {Domain Class Attribute Number}
        relvar correlation R5 IdentifyingAttribute\
            {Domain Class Number} + Identifier {Domain Class Number}\
            {Domain Class Attribute} * Attribute {Domain Class Name}
        relvar create DefaultValue {
            Domain      string
            Class       string
            Attribute   string
        } {Domain Class Attribute}
        relvar association R6\
            DefaultValue {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create UserSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            Value       string
        } {Domain Class Attribute}
        relvar create SystemSuppliedValue {
            Domain      string
            Class       string
            Attribute   string
            StartValue  int
        } {Domain Class Attribute}
        relvar create GeneratedValue {
            Domain      string
            Class       string
            Attribute   string
            Cmd         string
        } {Domain Class Attribute}
        relvar partition R18 DefaultValue {Domain Class Attribute}\
            UserSuppliedValue {Domain Class Attribute}\
            SystemSuppliedValue {Domain Class Attribute}\
            GeneratedValue {Domain Class Attribute}
        relvar create ValueCheck {
            Domain      string
            Class       string
            Attribute   string
            Expression  string
        } {Domain Class Attribute}
        relvar association R17\
            ValueCheck {Domain Class Attribute} ?\
            Attribute {Domain Class Name} 1
        relvar create AttributeReference {
            Domain              string
            ReferringClass      string
            ReferringAttribute  string
            ReferringRole       string
            ReferencedClass     string
            ReferencedAttribute string
            ReferencedRole      string
            ReferencedIdNumber  int
            Relationship        string
        } {Domain ReferringClass ReferringAttribute ReferringRole\
            ReferencedClass ReferencedAttribute ReferencedRole ReferencedIdNumber\
            Relationship}
        relvar association R13\
            AttributeReference {Domain ReferringClass ReferringAttribute} *\
            Attribute {Domain Class Name} 1
        relvar create ReferencedIdAttribute {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Attribute       string
            Number          int
        } {Domain Class Relationship Role Attribute Number}
        relvar create Operation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar association R8\
            Operation {Domain Class} * Class {Domain Name} 1
        
        relvar create InstanceOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar create ClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R7 Operation {Domain Class Name}\
            InstanceOperation {Domain Class Name}\
            ClassOperation {Domain Class Name}
        
        relvar create UserInstanceOperation {
            Domain      string
            Class       string
            Name        string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemInstanceOperation {
            Domain      string
            Class       string
            Name        string
        } {Domain Class Name}
        
        relvar partition R9 InstanceOperation {Domain Class Name}\
            UserInstanceOperation {Domain Class Name}\
            SystemInstanceOperation {Domain Class Name}
        
        relvar create UserClassOperation {
            Domain  string
            Class   string
            Name    string
            Parameters  string
            Body        string
        } {Domain Class Name}
        
        relvar create SystemClassOperation {
            Domain  string
            Class   string
            Name    string
        } {Domain Class Name}
        
        relvar partition R10 ClassOperation {Domain Class Name}\
            UserClassOperation {Domain Class Name}\
            SystemClassOperation {Domain Class Name}
        
        relvar create SuppliedOperation {
            Name                string
            Command             string
            RequiresStateModel  boolean
        } Name
        
        relvar create SuppliedClassOperation {
            Name    string
        } Name
        
        relvar create SuppliedInstanceOperation {
            Name    string
        } Name
        
        relvar partition R14 SuppliedOperation Name\
            SuppliedClassOperation Name\
            SuppliedInstanceOperation Name
        
        relvar association R15\
            SystemClassOperation Name *\
            SuppliedClassOperation Name 1
        
        relvar association R16\
            SystemInstanceOperation Name *\
            SuppliedInstanceOperation Name 1
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findAll
                Command             ::rosea::ClassCmds::findAll
                RequiresStateModel  false
            } {
                Name                findById
                Command             ::rosea::ClassCmds::findById
                RequiresStateModel  false
            } {
                Name                findWhere
                Command             ::rosea::ClassCmds::findWhere
                RequiresStateModel  false
            } {
                Name                create
                Command             ::rosea::ClassCmds::create
                RequiresStateModel  false
            } {
                Name                createin
                Command             ::rosea::ClassCmds::createin
                RequiresStateModel  true
            } {
                Name                createasync
                Command             ::rosea::ClassCmds::createasync
                RequiresStateModel  true
            } {
                Name                update
                Command             ::rosea::ClassCmds::update
                RequiresStateModel  false
            }
        
            relvar insert SuppliedClassOperation {
                Name    findAll
            } {
                Name    findById
            } {
                Name    findWhere
            } {
                Name    create
            } {
                Name    createin
            } {
                Name    createasync
            } {
                Name    update
            }
        }
        relvar eval {
            relvar insert SuppliedOperation {
                Name                findRelated
                Command             ::rosea::InstCmds::findRelated
                RequiresStateModel  false
            } {
                Name                findUnrelated
                Command             ::rosea::InstCmds::findById
                RequiresStateModel  false
            } {
                Name                findRelatedWhere
                Command             ::rosea::InstCmds::findRelatedWhere
                RequiresStateModel  false
            } {
                Name                findUnrelatedWhere
                Command             ::rosea::InstCmds::findUnrelatedWhere
                RequiresStateModel  false
            } {
                Name                updateAttribute
                Command             ::rosea::InstCmds::updateAttribute
                RequiresStateModel  false
            } {
                Name                withAttribute
                Command             ::rosea::InstCmds::withAttribute
                RequiresStateModel  false
            } {
                Name                readAttribute
                Command             ::rosea::InstCmds::readAttribute
                RequiresStateModel  false
            } {
                Name                assignAttribute
                Command             ::rosea::InstCmds::assignAttribute
                RequiresStateModel  false
            } {
                Name                delete
                Command             ::rosea::InstCmds::delete
                RequiresStateModel  false
            } {
                Name                signal
                Command             ::rosea::InstCmds::signal
                RequiresStateModel  true
            } {
                Name                delaysignal
                Command             ::rosea::InstCmds::delaysignal
                RequiresStateModel  true
            } {
                Name                canceldelayed
                Command             ::rosea::InstCmds::canceldelayed
                RequiresStateModel  true
            } {
                Name                delayremaining
                Command             ::rosea::InstCmds::delayremaining
                RequiresStateModel  true
            } {
                Name                instop
                Command             ::rosea::InstCmds::instop
                RequiresStateModel  false
            } {
                Name                deRef
                Command             ::rosea::InstCmds::deRef
                RequiresStateModel  false
            } {
                Name                isEmptyRef
                Command             ::rosea::InstCmds::isEmptyRef
                RequiresStateModel  false
            } {
                Name                isNotEmptyRef
                Command             ::rosea::InstCmds::isNotEmptyRef
                RequiresStateModel  false
            } {
                Name                refMultiplicity
                Command             ::rosea::InstCmds::refMultiplicity
                RequiresStateModel  false
            } {
                Name                isRefSingular
                Command             ::rosea::InstCmds::isRefSingular
                RequiresStateModel  false
            } {
                Name                limitRef
                Command             ::rosea::InstCmds::limitRef
                RequiresStateModel  false
            } {
                Name                isRefEqual
                Command             ::rosea::InstCmds::isRefEqual
                RequiresStateModel  false
            } {
                Name                forAllRefs
                Command             ::rosea::InstCmds::forAllRefs
                RequiresStateModel  false
            }
        
            relvar insert SuppliedInstanceOperation {
                Name    findRelated
            } {
                Name    findUnrelated
            } {
                Name    findRelatedWhere
            } {
                Name    findUnrelatedWhere
            } {
                Name    updateAttribute
            } {
                Name    withAttribute
            } {
                Name    readAttribute
            } {
                Name    assignAttribute
            } {
                Name    delete
            } {
                Name    signal
            } {
                Name    delaysignal
            } {
                Name    canceldelayed
            } {
                Name    delayremaining
            } {
                Name    instop
            } {
                Name    deRef
            } {
                Name    isEmptyRef
            } {
                Name    isNotEmptyRef
            } {
                Name    refMultiplicity
            } {
                Name    isRefSingular
            } {
                Name    limitRef
            } {
                Name    isRefEqual
            } {
                Name    forAllRefs
            }
        }
        relvar create Association {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create Generalization {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R30 Relationship {Domain Name}\
            Association {Domain Name}\
            Generalization {Domain Name}
        relvar create SimpleAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar create ClassBasedAssociation {
            Domain      string
            Name        string
        } {Domain Name}
        relvar partition R31 Association {Domain Name}\
            SimpleAssociation {Domain Name}\
            ClassBasedAssociation {Domain Name}
        relvar create SimpleReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R32\
            SimpleReferringClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SimpleReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
        } {Domain Class Relationship Role}
        relvar association R33\
            SimpleReferencedClass {Domain Relationship} 1\
            SimpleAssociation {Domain Name} 1
        relvar create SourceClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R34\
            SourceClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create TargetClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
            Conditionality  boolean
            Multiplicity    boolean
        } {Domain Class Relationship Role}
        relvar association R35\
            TargetClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create AssociatorClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R42\
            AssociatorClass {Domain Relationship} 1\
            ClassBasedAssociation {Domain Name} 1
        relvar create Superclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R36\
            Superclass {Domain Relationship} 1\
            Generalization {Domain Name} 1
        relvar create Subclass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar association R37\
            Subclass {Domain Relationship} +\
            Generalization {Domain Name} 1
        relvar create ReferringClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R38 ReferringClass {Domain Class Relationship Role}\
            SimpleReferringClass {Domain Class Relationship Role}\
            AssociatorClass {Domain Class Relationship Role}\
            Subclass {Domain Class Relationship Role}
        relvar create ReferencedClass {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R39 ReferencedClass {Domain Class Relationship Role}\
            SimpleReferencedClass {Domain Class Relationship Role}\
            SourceClass {Domain Class Relationship Role}\
            TargetClass {Domain Class Relationship Role}\
            Superclass {Domain Class Relationship Role}
        relvar create ClassRole {
            Domain          string
            Class           string
            Relationship    string
            Role            string
        } {Domain Class Relationship Role}
        relvar partition R40 ClassRole {Domain Class Relationship Role}\
            ReferringClass {Domain Class Relationship Role}\
            ReferencedClass {Domain Class Relationship Role}
        relvar correlation R41 ClassRole\
            {Domain Relationship} + Relationship {Domain Name}\
            {Domain Class} * Class {Domain Name}
        relvar correlation R11 ReferencedIdAttribute\
            {Domain Class Relationship Role} +\
                ReferencedClass {Domain Class Relationship Role}\
            {Domain Class Attribute Number} *\
                IdentifyingAttribute {Domain Class Attribute Number}
        relvar correlation R12 AttributeReference\
            {Domain ReferringClass Relationship ReferringRole} +\
                ReferringClass {Domain Class Relationship Role}\
            {Domain ReferencedClass Relationship ReferencedRole ReferencedAttribute\
                    ReferencedIdNumber} +\
                ReferencedIdAttribute {Domain Class Relationship Role Attribute Number}
        relvar create Config_AssocSpec {
            Spec                string
            NeedsAssociator     boolean
            ReflexiveAllowed    boolean
            ReferringCond       boolean
            ReferringMult       boolean
            ReferencedCond      boolean
            ReferencedMult      boolean
        } Spec
        
        relvar insert Config_AssocSpec {
            Spec 1--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..1--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 0..*--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec 1..*--0..1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 0..*--0..1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec 1..*--1..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 0..*--1..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec 1..*--0..* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec 0..*--0..* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec ?--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult false
                ReferencedCond false ReferencedMult false
        } {
            Spec ?--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult false
                ReferencedCond true ReferencedMult false
        } {
            Spec +--1 NeedsAssociator false ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec *--1 NeedsAssociator false ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult false
        } {
            Spec +--? NeedsAssociator false ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec *--? NeedsAssociator false ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult false
        } {
            Spec +--+ NeedsAssociator true ReflexiveAllowed true
                ReferringCond false ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec *--+ NeedsAssociator true ReflexiveAllowed false
                ReferringCond true ReferringMult true
                ReferencedCond false ReferencedMult true
        } {
            Spec +--* NeedsAssociator true ReflexiveAllowed false
                ReferringCond false ReferringMult true
                ReferencedCond true ReferencedMult true
        } {
            Spec *--* NeedsAssociator true ReflexiveAllowed true
                ReferringCond true ReferringMult true
                ReferencedCond true ReferencedMult true
        }
        relvar create Config_ClassAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_NonReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            TargetClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexiveAssoc {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
        } {Domain Relationship AssocClass SourceClass}
        relvar create Config_ReflexivePath {
            Domain              string
            Relationship        string
            AssocClass          string
            SourceClass         string
            SourceAttr          string
            TargetAttr          string
        } {Domain Relationship AssocClass SourceClass SourceAttr}
        relvar partition Config1\
            Config_ClassAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_NonReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}\
            Config_ReflexiveAssoc\
                {Domain Relationship AssocClass SourceClass}
        relvar association Config2\
            Config_ReflexivePath {Domain Relationship AssocClass SourceClass} +\
            Config_ReflexiveAssoc {Domain Relationship AssocClass SourceClass} 1
        pipe {
            relvar set ::rosea::Config::AttributeReference |
            relation project ~ Domain ReferencedClass Relationship ReferencedRole\
                    ReferencedAttribute ReferencedIdNumber |
            relation rename ~ ReferencedClass Class ReferencedRole Role\
                    ReferencedAttribute Attribute ReferencedIdNumber Number |
            relvar union ::rosea::Config::ReferencedIdAttribute
        } refIdQuery
        relvar create StateModel {
            Domain          string
            Model           string
            InitialState    string
            DefaultTrans    string
        } {Domain Model}
        
        relvar create InstanceStateModel {
            Domain          string
            Class           string
        } {Domain Class}
        
        relvar association R51\
            InstanceStateModel {Domain Class} ?\
            Class {Domain Name} 1
        
        relvar create AssignerStateModel {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar association R52\
            AssignerStateModel {Domain Relationship} ?\
            Association {Domain Name} 1
        
        relvar partition R50 StateModel {Domain Model}\
            InstanceStateModel {Domain Class}\
            AssignerStateModel {Domain Relationship}
        
        relvar create SingleAssigner {
            Domain          string
            Relationship    string
        } {Domain Relationship}
        
        relvar create MultipleAssigner {
            Domain          string
            Relationship    string
            Class           string
            Number          int
        } {Domain Relationship}
        
        relvar partition R53 AssignerStateModel {Domain Relationship}\
            SingleAssigner {Domain Relationship}\
            MultipleAssigner {Domain Relationship}
        
        relvar association R54\
            MultipleAssigner {Domain Class Number} ?\
            Identifier {Domain Class Number} 1
        
        relvar create State {
            Domain          string
            Model           string
            Name            string
            Parameters      string
            Action          string
            IsFinal         boolean
        } {Domain Model Name}
        
        relvar association R55\
            State {Domain Model} +\
            StateModel {Domain Model} 1
        
        relvar association R58\
            StateModel {Domain Model InitialState} ?\
            State {Domain Model Name} 1
        
        relvar create TransitionRule {
            Name    string
        } Name
        
        relvar insert TransitionRule {Name IG} {Name CH}
        
        relvar association R59\
            StateModel DefaultTrans *\
            TransitionRule Name 1
        
        relvar create CreationState {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar create StatePlace {
            Domain          string
            Model           string
            Name            string
        } {Domain Model Name}
        
        relvar partition R57 StatePlace {Domain Model Name}\
            State {Domain Model Name}\
            CreationState {Domain Model Name}
        relvar create Event {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create DeferredEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create EffectiveEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R80 Event {Domain Model Event}\
            DeferredEvent {Domain Model Event}\
            EffectiveEvent {Domain Model Event}
        
        relvar create DeferralPath {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event Relationship Role}
        
        relvar correlation R86 DeferralPath\
            {Domain Model Event} + DeferredEvent {Domain Model Event}\
            {Domain Model Relationship Role} * Superclass\
                {Domain Class Relationship Role}
        
        relvar create PolymorphicEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar create InheritedEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R81 DeferredEvent {Domain Model Event}\
            PolymorphicEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar create MappedEvent {
            Domain      string
            Model       string
            Event       string
            ParentModel string
        } {Domain Model Event}
        
        relvar association R84\
            MappedEvent {Domain ParentModel Event} *\
            DeferredEvent {Domain Model Event} 1
        
        relvar create LocalEvent {
            Domain  string
            Model   string
            Event   string
        } {Domain Model Event}
        
        relvar partition R82 EffectiveEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            LocalEvent {Domain Model Event}
        
        relvar create NonLocalEvent {
            Domain          string
            Model           string
            Event           string
            Relationship    string
            Role            string
        } {Domain Model Event}
        
        relvar partition R83 NonLocalEvent {Domain Model Event}\
            MappedEvent {Domain Model Event}\
            InheritedEvent {Domain Model Event}
        
        relvar association R85\
            NonLocalEvent {Domain Model Relationship Role} *\
            Subclass {Domain Class Relationship Role} 1
        
        relvar association R87\
            EffectiveEvent {Domain Model} +\
            StateModel {Domain Model} 1
        relvar create TransitionPlace {
            Domain  string
            Model   string
            State   string
            Event   string
        } {Domain Model State Event}
        
        relvar correlation R70 TransitionPlace\
            {Domain Model State} * StatePlace {Domain Model Name}\
            {Domain Model Event} * EffectiveEvent {Domain Model Event}
        
        relvar create StateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            NewState    string
        } {Domain Model State Event}
        
        relvar create NonStateTransition {
            Domain      string
            Model       string
            State       string
            Event       string
            TransRule   string
        } {Domain Model State Event}
        
        relvar partition R71 TransitionPlace {Domain Model State Event}\
            StateTransition {Domain Model State Event}\
            NonStateTransition {Domain Model State Event}
        
        relvar association R72\
            StateTransition {Domain Model NewState} *\
            State {Domain Model Name} 1
        
        relvar association R73\
            NonStateTransition TransRule *\
            TransitionRule Name 1
        relvar create Config_DataError {
            Relationship        string
            RefClass            string
            RefType             string
            Format              string
        } {Relationship RefClass RefType}
        relvar insert Config_DataError {
            Relationship        R3
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no attributes}
        } {
            Relationship        R4
            RefClass            Class
            RefType             notrefed
            Format              {in domain, \"$Domain\", class, \"$Name\",\
                                has no identifiers}
        } {
            Relationship        R11
            RefClass            ReferencedClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", for relationship,\
                                \"$Relationship\", no class has defined a reference\
                                to class, \"$Class\"}
        } {
            Relationship        R11
            RefClass            ReferencedIdAttribute
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references attribute,\
                                \"$Attribute\", in class, \"$Class\", which is\
                                not an identifying attribute, does not exist\
                                or \"$Relationship\" does not exist}
        } {
            Relationship        R12
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                refers to, \"$ReferencedAttribute\", in class,\
                                \"$ReferencedClass\", but the class, attribute or\
                                relationship does not exist}
        } {
            Relationship        R12
            RefClass            ReferringClass
            RefType             notrefed
            Format              {in domain, \"$Domain\", in class, \"$Class\",\
                                makes a reference along relationship,\
                                \"$Relationship\", but $Class does not pariticipate\
                                in $Relationship}
        } {
            Relationship        R13
            RefClass            AttributeReference
            RefType             refnone
            Format              {in domain, \"$Domain\", the attribute,\
                                \"$ReferringAttribute\", in class, \"$ReferringClass\",\
                                does not exist, but is used as a referential attribute}
        } {
            Relationship        R41
            RefClass            ClassRole
            RefType             refnone
            Format              {in domain, \"$Domain\", relationship,\
                                \"$Relationship\", references class, \"$Class\",\
                                which does not exist}
        } {
            Relationship        R52
            RefClass            AssignerStateModel
            RefType             refnone
            Format              {in domain, \"$Domain\", an assigner state model is\
                                defined on relationship, \"$Relationship\", which is\
                                not an association type relationship}
        } {
            Relationship        R70
            RefClass            TransitionPlace
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains a transition for event,\
                                \"$Event\", but $Event was a polymorphic event\
                                consumed by a superclass of $Model}
        } {
            Relationship        R72
            RefClass            StateTransition
            RefType             refnone
            Format              {in domain, \"$Domain\", the state model for,\
                                \"$Model\", contains the transition,\
                                \"$State - $Event -> $NewState\",\
                                but state \"$NewState\" does not exist}
        } {
            Relationship        R81
            RefClass            DeferredEvent
            RefType             multrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is both an inherited\
                                polymorphic event and a locally defined one}
        } {
            Relationship        R86
            RefClass            DeferredEvent
            RefType             notrefed
            Format              {in domain, \"$Domain\", in the state model for,\
                                \"$Model\", event, \"$Event\", is defined as\
                                polymorphic but \"$Model\" is not a superclass\
                                of a generalization}
        } {
            Relationship        R87
            RefClass            EffectiveEvent
            RefType             refnone
            Format              {in domain, \"$Domain\", event, \"$Event\" has been\
                                inherited, but no state model exists for, \"$Model\"}
        }
        namespace export ConfigEvaluate
        
        proc ConfigEvaluate {ns body} {
            variable evalLambda
            tailcall ::apply [concat $evalLambda [list $ns]] $body ; # <1>
        }
        proc domain {name body} {
            namespace upvar DomainDef DomainName DomainName ; # <1>
            set DomainName $name
        
            relvar insert ::rosea::Config::Domain [list Name $name Location {}]
            try {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME domain
                }
        
                relvar eval { # <2>
                    ConfigEvaluate [namespace current]::DomainDef $body
        
                    # At this point we have the definition of the domain and enough
                    # information to tie together the referential attributes and
                    # the association definitions.
                    variable Config_NonReflexiveAssoc
                    
                    relation foreach nra $Config_NonReflexiveAssoc {
                        relation assign $nra
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferencedClass] eq $SourceClass
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable Config_ReflexivePath
                    
                    relation foreach rp $Config_ReflexivePath {
                        relation assign $rp
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass
                        } {tuple update $ar ReferringRole associator}
                    
                        relvar update ::rosea::Config::AttributeReference ar {
                            [tuple extract $ar Domain] eq $Domain &&
                            [tuple extract $ar Relationship] eq $Relationship &&
                            [tuple extract $ar ReferringClass] eq $AssocClass &&
                            [tuple extract $ar ReferringAttribute] eq $SourceAttr
                        } {tuple update $ar ReferencedRole source}
                    }
                    variable refIdQuery
                    
                    eval $refIdQuery
        
                    # We must also compute how polymorphic events are inherited
                    # down generalization hierarchies.
                    # Create Deferral Path instances
                    
                    variable PolymorphicEvent
                    variable DeferredEvent
                    variable Superclass
                    variable Subclass
                    variable DeferralPath
                    
                    set dpaths [pipe {
                        relation restrictwith $PolymorphicEvent {$Domain eq $name} |
                        relation semijoin ~ $DeferredEvent |
                        relation join ~ $Superclass -using {Domain Domain Model Class}
                    }]
                    relvar insert ::rosea::Config::DeferralPath {*}[relation body $dpaths]
                    set supers [relation semiminus $Subclass $Superclass\
                        -using {Domain Domain Class Class}]
                    
                    relation foreach super $supers {
                        PropagatePolyEvents $super
                    }
                }
            } on error {result} {
                # puts $::errorInfo
                ::rosea::Config::HandleConfigError $result
            }
        }
        proc HandleConfigError {result} {
            set lines [split [string trimright $result] \n]
            set nlines [llength $lines]
            set lineno 0
            upvar #0 ::rosea::Config::errcount errcount
            while {$lineno < $nlines} {
                set line [lindex $lines $lineno]
                incr lineno
                if {[regexp {^for[^:]+([^(]+)\(.+\), in relvar (.+)$} $line\
                        match rnum refclass]} {
                    set rnum [namespace tail $rnum]
                    set refclass [namespace tail $refclass]
                
                    # Now iterate over the "tuple" lines that follow the constraint message.
                    while {$lineno < $nlines} {
                        set tupline [lindex $lines $lineno]
                        if {[regexp {^tuple {(.+)} (.+)$} $tupline match tuple phrase]} {
                            incr lineno
                            incr errcount
                            if {[string match {is not referenced*} $phrase]} {
                                set reftype notrefed
                            } elseif {[string match {references no*} $phrase]} {
                                set reftype refnone
                            } elseif {[string match {*to by multiple*} $phrase]} {
                                set reftype multrefed
                            } elseif {[string match {is not referred to*} $phrase]} {
                                set reftype notrefto
                            } else {
                                log::error "unknown constraint phrasing, \"$phrase\""
                                continue
                            }
                            set cde [relvar restrictone Config_DataError Relationship $rnum RefClass\
                                    $refclass RefType $reftype]
                            if {[relation isnotempty $cde]} {
                                dict with tuple {
                                    log::error [subst -nocommands [relation extract $cde Format]]
                                }
                            } else {
                                log::error "$line\n$tupline"
                            }
                        } else {
                            break
                        }
                    }
                } else {
                    log::error "unknown configuration error, \"$result\""
                }
            }
        
            return
        }
        namespace eval DomainDef {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace import ::rosea::Config::ConfigEvaluate
            namespace import ::rosea::Helpers::DeclError
            proc class {name body} {
                namespace upvar [namespace current] DomainName DomainName ; # <1>
                namespace upvar ClassDef ClassName ClassName
                set ClassName $name
            
                if {![regexp {\A[[:alnum:]].*} $name]} {
                    tailcall DeclError BAD_CLASS_NAME $name
                }
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                } ; # <2>
                relvar insert ::rosea::Config::Class [list\
                    Domain  $DomainName\
                    Name    $name\
                ]
                set instops [pipe {
                    relvar set ::rosea::Config::SuppliedInstanceOperation |
                    relation extend ~ ioptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemInstanceOperation $instops
                relvar union ::rosea::Config::InstanceOperation $instops
                relvar union ::rosea::Config::Operation $instops
                set classops [pipe {
                    relvar set ::rosea::Config::SuppliedClassOperation |
                    relation extend ~ coptuple\
                        Domain string {[set DomainName]}\
                        Class string {[set ClassName]}
                }]
                relvar union ::rosea::Config::SystemClassOperation $classops
                relvar union ::rosea::Config::ClassOperation $classops
                relvar union ::rosea::Config::Operation $classops
            
                ConfigEvaluate [namespace current]::ClassDef $body
            }
            proc association {name source spec target args} {
                if {[llength $args] % 2 != 0} {
                    tailcall DeclError ARG_FORMAT $args
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME association
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                # Obtain references to the domain and class context.
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
            
                set associator {}
                set path {}
                
                foreach {option value} $args {
                    switch -exact -- $option {
                        -associator {
                            set associator $value
                        }
                        -path {
                            set path $value
                            if {[llength $path] % 2 != 0} {
                                tailcall DeclError ARG_FORMAT $path
                            }
                        }
                        default {
                            tailcall DeclError UNKNOWN_OPTION association $option
                        }
                    }
                }
                set cas [relvar restrictone ::rosea::Config::Config_AssocSpec Spec $spec]
                if {[relation isempty $cas]} {
                    tailcall DeclError BAD_RELATIONSHIP_SPEC $spec
                }
                set needsassoc [relation extract $cas NeedsAssociator]
                if {$needsassoc && $associator eq {}} {
                    tailcall DeclError NEED_ASSOCIATOR $spec
                }
                if {$source eq $target} {
                    if {![relation extract $cas ReflexiveAllowed]} {
                        tailcall DeclError REFLEXIVE_NOT_ALLOWED $spec
                    }
                    if {$needsassoc && $path eq {}} {
                        tailcall DeclError NEED_REFLEXIVE_PATH $name $source $spec $target
                    }
                }
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                # Many relvars have tuples with the same heading, so we construct it
                # once here.
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
            
                # Populate the data for a Relationship and Association since that
                # is what this command defines.
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Association $reltuple
            
                # Populate the type of association we are dealing with.
                if {$associator eq {}} {
                    relvar insert ::rosea::Config::SimpleAssociation $reltuple
                    relvar insert ::rosea::Config::SimpleReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::SimpleReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                } else {
                    relvar insert ::rosea::Config::Config_ClassAssoc [list\
                        Domain              $DomainName\
                        Relationship        $name\
                        AssocClass          $associator\
                        SourceClass         $source\
                    ]
                    if {[llength $path] == 0} {
                        relvar insert ::rosea::Config::Config_NonReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                            TargetClass         $target\
                        ]
                    } else {
                        relvar insert ::rosea::Config::Config_ReflexiveAssoc [list\
                            Domain              $DomainName\
                            Relationship        $name\
                            AssocClass          $associator\
                            SourceClass         $source\
                        ]
                        foreach {sourceattr targetattr} $path {
                            relvar insert ::rosea::Config::Config_ReflexivePath [list\
                                Domain              $DomainName\
                                Relationship        $name\
                                AssocClass          $associator\
                                SourceClass         $source\
                                SourceAttr          $sourceattr\
                                TargetAttr          $targetattr\
                            ]
                        }
                    }
                    
                    relvar insert ::rosea::Config::ClassBasedAssociation $reltuple
                    relvar insert ::rosea::Config::SourceClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                        Conditionality  [relation extract $cas ReferringCond]\
                        Multiplicity    [relation extract $cas ReferringMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $source\
                        Relationship    $name\
                        Role            source\
                    ]
                    relvar insert ::rosea::Config::TargetClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                        Conditionality  [relation extract $cas ReferencedCond]\
                        Multiplicity    [relation extract $cas ReferencedMult]\
                    ]
                    relvar insert ::rosea::Config::ReferencedClass [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $target\
                        Relationship    $name\
                        Role            target\
                    ]
                    relvar insert ::rosea::Config::AssociatorClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ReferringClass [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                    relvar insert ::rosea::Config::ClassRole [list\
                        Domain          $DomainName\
                        Class           $associator\
                        Relationship    $name\
                        Role            associator\
                    ]
                }
            }
            proc generalization {name super args} {
                if {[llength $args] < 2} {
                    tailcall DeclError TOO_FEW_SUBCLASSES [llength $args]
                }
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME generalization
                }
                if {[string index $name 0] eq "~"} {
                    tailcall DeclError TILDE_NAME $name
                }
            
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain  $DomainName\
                        Element $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
            
                set reltuple [list\
                    Domain  $DomainName\
                    Name $name\
                ]
                relvar insert ::rosea::Config::Relationship $reltuple
                relvar insert ::rosea::Config::Generalization $reltuple
            
                set supertuple [list\
                    Domain          $DomainName\
                    Class           $super\
                    Relationship    $name\
                    Role            target\
                ]
                relvar insert ::rosea::Config::Superclass $supertuple
                relvar insert ::rosea::Config::ReferencedClass $supertuple
                relvar insert ::rosea::Config::ClassRole $supertuple
            
                set subtuple [dict create\
                    Domain          $DomainName\
                    Relationship    $name\
                    Role            source\
                ]
                foreach sub $args {
                    dict set subtuple Class $sub
                    relvar insert ::rosea::Config::Subclass $subtuple
                    relvar insert ::rosea::Config::ReferringClass $subtuple
                    relvar insert ::rosea::Config::ClassRole $subtuple
                }
            }
            proc assigner {rname body} {
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                namespace upvar AssignerDef\
                    RelationshipName RelationshipName\
                    multiClass multiClass\
                    multiIdNum multiIdNum\
                    InitialState InitialState\
                    DefaultTrans DefaultTrans
            
                set RelationshipName $rname
                set multiClass {}
                set multiIdNum 1
                set InitialState {}
                set DefaultTrans {}
            
                try {
                    ConfigEvaluate [namespace current]::AssignerDef $body
            
                    if {$DefaultTrans eq {}} {
                        set DefaultTrans CH
                    }
                    relvar insert ::rosea::Config::StateModel [list\
                        Domain          $DomainName\
                        Model           $rname\
                        InitialState    $InitialState\
                        DefaultTrans    $DefaultTrans\
                    ]
                    set assigntuple [list\
                        Domain          $DomainName\
                        Relationship    $rname\
                    ]
                    relvar insert ::rosea::Config::AssignerStateModel $assigntuple
                    if {$multiClass eq {}} {
                        relvar insert ::rosea::Config::SingleAssigner $assigntuple
                    } else {
                        lappend assigntuple Class $multiClass Number $multiIdNum
                        relvar insert ::rosea::Config::MultipleAssigner $assigntuple
                    }
                } on error {result opts} {
                    log::error $result
                    upvar #0 ::rosea::Config::errcount errcount
                    incr errcount
                }
            }
            proc operation {name params body} {
                if {$name eq {}} {
                    tailcall DeclError EMPTY_NAME operation
                }
                namespace upvar ::rosea::Config::DomainDef DomainName DomainName
            
                try {
                    relvar insert ::rosea::Config::DomainElement [list\
                        Domain      $DomainName\
                        Element     $name\
                    ]
                } trap {RAL relvar insert DUPLICATE_TUPLE} {result opts} {
                    tailcall DeclError DUP_ELEMENT_NAME $name
                }
                relvar insert ::rosea::Config::DomainOperation [list\
                    Domain      $DomainName\
                    Name        $name\
                    Parameters  $params\
                    Body        $body\
                ]
            }
        
            namespace eval ClassDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc attribute {name type args} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME attribute
                    }
                    if {[string range $name 0 1] eq "__"} {
                        tailcall DeclError RESERVED_NAME $name
                    }
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    relvar insert ::rosea::Config::Attribute [list\
                        Domain  $DomainName\
                        Class   $ClassName\
                        Name    $name\
                        Type    $type\
                    ]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -default {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::UserSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Value       $value\
                                ]
                            }
                            -system {
                                if {$type ne "int"} {
                                    tailcall DeclError INT_TYPE_REQUIRED $type
                                }
                                if {![string is integer -strict $value]} {
                                    tailcall DeclError INT_VALUE_REQUIRED $value
                                }
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::SystemSuppliedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    StartValue  $value\
                                ]
                            }
                            -generate {
                                relvar insert ::rosea::Config::DefaultValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                ]
                                relvar insert ::rosea::Config::GeneratedValue [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Cmd         $value\
                                ]
                            }
                            -id {
                                relvar uinsert ::rosea::Config::Identifier [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Number      $value\
                                ] ; # <1>
                                relvar insert ::rosea::Config::IdentifyingAttribute [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Number      $value\
                                ]
                            }
                            -check {
                                relvar insert ::rosea::Config::ValueCheck [list\
                                    Domain      $DomainName\
                                    Class       $ClassName\
                                    Attribute   $name\
                                    Expression  $value\
                                ]
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION attribute $option
                            }
                        }
                    }
                }
                proc reference {relname rclass args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set refnum 1
                    set linkopts [list]
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -refid {
                                set refnum $value
                            }
                            -link {
                                if {[llength $value] < 1 || [llength $value] > 2} {
                                    tailcall DeclError ARG_FORMAT $value
                                }
                                lappend linkopts $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION reference $option
                            }
                        }
                    }
                
                    # We defer processing the link options until the end so as not
                    # to impose an order on the -refid option.
                    foreach linkopt $linkopts {
                        lassign $linkopt referring referenced
                        if {$referenced eq {}} {
                            set referenced $referring
                        }
                        relvar insert ::rosea::Config::AttributeReference [list\
                            Domain              $DomainName\
                            ReferringClass      $ClassName\
                            ReferringAttribute  $referring\
                            ReferringRole       source\
                            ReferencedClass     $rclass\
                            ReferencedAttribute $referenced\
                            ReferencedRole      target\
                            ReferencedIdNumber  $refnum\
                            Relationship        $relname
                        ] ; # <1>
                    }
                }
                proc classop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "class operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::ClassOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserClassOperation $optuple
                }
                proc instop {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME "instance operation"
                    } elseif {[string first :: $name] != -1} {
                        tailcall DeclError NS_QUALIFIERS $name
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    set sysop [relvar restrictone ::rosea::Config::Operation\
                        Domain $DomainName Class $ClassName Name $name]
                    if {[relation isnotempty $sysop]} {
                        tailcall DeclError DUP_OP_NAME $name
                    }
                
                    set optuple [list Domain $DomainName Class $ClassName Name $name]
                    relvar insert ::rosea::Config::Operation $optuple
                    relvar insert ::rosea::Config::InstanceOperation $optuple
                
                    lappend optuple Parameters $params Body $body
                    relvar insert ::rosea::Config::UserInstanceOperation $optuple
                }
                proc statemodel {body} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    variable ClassName
                
                    namespace upvar StateModelDef\
                        InitialState InitialState\
                        DefaultTrans DefaultTrans\
                        Terminals Terminals
                
                    set InitialState {}
                    set DefaultTrans {}
                    set Terminals [list]
                
                    try {
                        ConfigEvaluate [namespace current]::StateModelDef $body
                
                        if {$DefaultTrans eq {}} {
                            set DefaultTrans CH
                        }
                        relvar insert ::rosea::Config::StateModel [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            InitialState    $InitialState\
                            DefaultTrans    $DefaultTrans\
                        ]
                        relvar insert ::rosea::Config::InstanceStateModel [list\
                            Domain          $DomainName\
                            Class           $ClassName\
                        ]
                
                        foreach terminal $Terminals {
                            relvar updateone ::rosea::Config::State stup [list\
                                    Domain $DomainName Model $ClassName Name $terminal] {
                                tuple update $stup IsFinal true
                            }
                        }
                    } on error {result opts} {
                        log::error $result
                        upvar #0 ::rosea::Config::errcount errcount
                        incr errcount
                    }
                }
                proc polymorphic {args} {
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                
                    foreach polyevent $args {
                        set eventtuple [list\
                            Domain $DomainName\
                            Model $ClassName\
                            Event $polyevent\
                        ]
                        relvar insert ::rosea::Config::PolymorphicEvent $eventtuple
                        relvar insert ::rosea::Config::DeferredEvent $eventtuple
                        relvar insert ::rosea::Config::Event $eventtuple
                    }
                    return
                }
            
                namespace eval StateModelDef {
                    logger::initNamespace [namespace current]
                
                    namespace import\
                        ::ral::relation\
                        ::ral::tuple\
                        ::ral::relformat\
                        ::ralutil::pipe
                    namespace import ::ral::relvar
                    namespace import ::rosea::Config::ConfigEvaluate
                    namespace import ::rosea::Helpers::DeclError
                
                    proc state {name params body} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME state
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name state
                        }
                    
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        variable InitialState
                    
                        if {$InitialState eq {}} {
                            set InitialState $name
                        }
                    
                        relvar insert ::rosea::Config::State [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                            Parameters      $params\
                            Action          $body\
                            IsFinal         false\
                        ]
                        relvar insert ::rosea::Config::StatePlace [list\
                            Domain          $DomainName\
                            Model           $ClassName\
                            Name            $name\
                        ]
                        return
                    }
                    proc transition {source - event -> target} {
                        if {$event eq {}} {
                            tailcall DeclError EMPTY_NAME event
                        }
                        if {$source in {CH IG}} {
                            tailcall DeclError PSEUDO_STATE $source "transition source state"
                        }
                        namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                        namespace upvar ::rosea::Config::DomainDef::ClassDef ClassName ClassName
                    
                        if {$source eq "@"} {
                            if {$target in {CH IG}} {
                                tailcall DeclError BAD_CREATION_TARGET $target
                            }
                            set cstuple [list\
                                Domain          $DomainName\
                                Model           $ClassName\
                                Name            @\
                            ]
                            relvar uinsert ::rosea::Config::CreationState $cstuple
                            relvar uinsert ::rosea::Config::StatePlace $cstuple
                        }
                    
                        set eventtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            Event   $event\
                        ]
                        relvar uinsert ::rosea::Config::Event $eventtuple ; # <1>
                        relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                        relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                    
                        set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                            Name $target]
                        set transtuple [list\
                            Domain  $DomainName\
                            Model   $ClassName\
                            State   $source\
                            Event   $event\
                        ]
                        relvar insert ::rosea::Config::TransitionPlace $transtuple
                    
                        if {[relation isnotempty $tranrule]} {
                            lappend transtuple TransRule $target
                            set tpsubtype NonStateTransition
                        } else {
                            lappend transtuple NewState $target
                            set tpsubtype StateTransition
                        }
                        relvar insert ::rosea::Config::$tpsubtype $transtuple
                        return
                    }
                    proc initialstate {name} {
                        if {$name eq {}} {
                            tailcall DeclError EMPTY_NAME initialstate
                        }
                        if {$name in {@ CH IG}} {
                            tailcall DeclError PSEUDO_STATE $name initialstate
                        }
                        variable InitialState $name
                        return
                    }
                    proc defaulttrans {name} {
                        if {$name ni {CH IG}} {
                            tailcall DeclError EXPECTED_PSEUDO_STATE $name
                        }
                        variable DefaultTrans $name
                        return
                    }
                    proc terminal {args} {
                        variable Terminals
                        ::struct::set add Terminals $args
                        return
                    }
                }
            }
            namespace eval AssignerDef {
                logger::initNamespace [namespace current]
            
                namespace import\
                    ::ral::relation\
                    ::ral::tuple\
                    ::ral::relformat\
                    ::ralutil::pipe
                namespace import ::ral::relvar
                namespace import ::rosea::Config::ConfigEvaluate
                namespace import ::rosea::Helpers::DeclError
            
                proc state {name params body} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME state
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name state
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    variable InitialState
                
                    if {$InitialState eq {}} {
                        set InitialState $name
                    }
                
                    relvar insert ::rosea::Config::State [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                        Parameters      $params\
                        Action          $body\
                        IsFinal         false\
                    ]
                    relvar insert ::rosea::Config::StatePlace [list\
                        Domain          $DomainName\
                        Model           $RelationshipName\
                        Name            $name\
                    ]
                    return
                }
                proc transition {source - event -> target} {
                    if {$event eq {}} {
                        tailcall DeclError EMPTY_NAME event
                    }
                    if {$source in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name "transition source state"
                    }
                
                    namespace upvar ::rosea::Config::DomainDef DomainName DomainName
                    namespace upvar ::rosea::Config::DomainDef::AssignerDef\
                        RelationshipName RelationshipName
                
                    set eventtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        Event   $event\
                    ]
                    relvar uinsert ::rosea::Config::Event $eventtuple
                    relvar uinsert ::rosea::Config::EffectiveEvent $eventtuple
                    relvar uinsert ::rosea::Config::LocalEvent $eventtuple
                
                    set tranrule [relvar restrictone ::rosea::Config::TransitionRule\
                        Name $target]
                    set transtuple [list\
                        Domain  $DomainName\
                        Model   $RelationshipName\
                        State   $source\
                        Event   $event\
                    ]
                    relvar insert ::rosea::Config::TransitionPlace $transtuple
                
                    if {[relation isnotempty $tranrule]} {
                        lappend transtuple TransRule $target
                        set tpsubtype NonStateTransition
                    } else {
                        lappend transtuple NewState $target
                        set tpsubtype StateTransition
                    }
                    relvar insert ::rosea::Config::$tpsubtype $transtuple
                    return
                }
                proc initialstate {name} {
                    if {$name eq {}} {
                        tailcall DeclError EMPTY_NAME initialstate
                    }
                    if {$name in {CH IG}} {
                        tailcall DeclError PSEUDO_STATE $name initialstate
                    }
                    variable InitialState $name
                    return
                }
                proc defaulttrans {name} {
                    if {$name ni {CH IG}} {
                        tailcall DeclError EXPECTED_PSEUDO_STATE $name
                    }
                    variable DefaultTrans $name
                    return
                }
                proc identifyby {name args} {
                    if {[llength $args] % 2 != 0} {
                        tailcall DeclError ARG_FORMAT $args
                    }
                
                    variable multiClass $name
                
                    foreach {option value} $args {
                        switch -exact -- $option {
                            -id {
                                variable multiIdNum $value
                            }
                            default {
                                tailcall DeclError UNKNOWN_OPTION identifyby $option
                            }
                        }
                    }
                
                    return
                }
            }
        }
    }
    namespace eval Populate {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Config::ConfigEvaluate
        namespace import ::rosea::Helpers::DeclError
        proc domain {name body} {
            set domain [relvar restrictone ::rosea::Config::Domain Name $name]
            if {[relation isempty $domain]} {
                tailcall DeclError UNKNOWN_DOMAIN $domain
            }
        
            namespace upvar DomainPop DomainName DomainName DomainLoc DomainLoc
            relation assign $domain {Name DomainName} {Location DomainLoc}
        
            try {
                relvar eval {
                    ConfigEvaluate [namespace current]::DomainPop $body
                }
            } on error {result opts} {
                log::error $result
                upvar #0 ::rosea::Config::errcount errcount
                incr errcount
            }
        }
        namespace eval DomainPop {
            logger::initNamespace [namespace current]
        
            namespace import\
                ::ral::relation\
                ::ral::tuple\
                ::ral::relformat\
                ::ralutil::pipe
            namespace import ::ral::relvar
            namespace path ::rosea::Helpers
            proc class {class heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                set body [list]
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.
                    set tuple [list]
                    foreach attr $heading value $values {
                        # Check if we are skipping a value to use a default.  We must also
                        # allow some way to specify the value as "-".
                        if {$value eq "-"} {
                            continue
                        } elseif {$value eq "\\-"} {
                            set value -
                        }
                        lappend tuple $attr $value
                    }
                    # Accumulate the tuples as a list to form the body that will be
                    # inserted into the relvar.
                    lappend body $tuple
                }
            
                # Insert the body into the relvar.
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::$class
                set insts [relvar insert $relvar {*}$body]
            
                # Now we have to deal with any state model that might be present.  We have
                # to set up the initial state properly if such a thing exists for this
                # class.
                set idattrs [lindex [relvar identifiers $relvar] 0]
                relation foreach inst $insts {
                    CreateInInitialState $domns $class [pipe {
                        relation project $inst {*}$idattrs |
                        relation tuple ~ |
                        tuple get ~
                    }]
                }
            
                return [relation body $insts]
            }
            proc assigner {rname heading args} {
                # Determine if we have one big list or a bunch of values.
                set popvalues [expr {[llength $args] == 1 ? [lindex $args 0] : $args}]
                set headlen [llength $heading]
                if {[llength $popvalues] % $headlen != 0} {
                    tailcall DeclError ARG_MISMATCH $headlen [llength $popvalues]
                }
            
                namespace upvar [namespace current]\
                    DomainName DomainName\
                    DomainLoc DomainLoc
                set domns ${DomainLoc}::${DomainName}
                set relvar ${domns}::${rname}__STATEINST
                set idattrs [lindex [relvar identifiers $relvar] 0]
                if {![struct::set equal $heading $idattrs]} {
                    tailcall DeclError NO_IDENTIFIER $heading $idattrs
                }
            
                # Iterate over the attribute values taking them in chunks that are the same
                # size as the heading.
                for {set vindex 0} {$vindex < [llength $popvalues]} {incr vindex $headlen} {
                    set values [lrange $popvalues $vindex [expr {$vindex + $headlen - 1}]]
                    # Create a tuple as a list of attribute name / value pairs.  We assume
                    # the values are in the same order as the heading -- that is the point.
                    set tuple [list]
                    foreach attr $heading value $values {
                        lappend tuple $attr $value
                    }
                    CreateInInitialState $domns $rname $tuple
                }
            
                return
            }
        }
    }
    namespace eval Info {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace import ::rosea::Helpers::DeclError
        proc domain {arglist} {
            set arglist [lassign $arglist subcmd domainname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            switch -exact -- $subcmd {
                classes {
                    return [pipe {
                        relvar set ::rosea::Config::Class |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                relationships {
                    return [pipe {
                        relvar set ::rosea::Config::Relationship |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation list ~ Name
                    }]
                }
                operations {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::DomainOperation |
                        relation semijoin $dominst ~ -using {Name Domain} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc FormatOpsInfo {ops} {
            set result [list]
            relation foreach op $ops {
                relation assign $op
                lappend result $Name $Parameters $Body
            }
            return $result
        }
        proc class {arglist} {
            set arglist [lassign $arglist subcmd domainname classname]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                attributes {
                    return [pipe {
                        relvar set ::rosea::Config::Attribute |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation dict ~ Name Type
                    }]
                }
                classops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserClassOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                instops {
                    return [FormatOpsInfo [pipe {
                        relvar set ::rosea::Config::UserInstanceOperation |
                        relation semijoin $classinst ~ -using {Domain Domain Name Class} |
                        relation project ~ Name Parameters Body
                    }]]
                }
                default {
                    tailcall DeclError UNKNOWN_INFO_CMD $subcmd
                }
            }
        }
        proc statemodel {arglist} {
            set arglist [lassign $arglist subcmd domainname classname statename]
            set dominst [relvar restrictone ::rosea::Config::Domain Name $domainname]
            if {[relation isempty $dominst]} {
                tailcall DeclError UNKNOWN_DOMAIN $domainname
            }
            set domns [string cat [relation extract $dominst Location] :: $domainname]
        
            set classinst [pipe {
                relvar set ::rosea::Config::Class |
                relation semijoin $dominst ~ -using {Name Domain} |
                relation restrictwith ~ {$Name eq $classname}
            }]
            if {[relation isempty $classinst]} {
                tailcall DeclError UNKNOWN_CLASS $classname $domainname
            }
        
            switch -exact -- $subcmd {
                states {
                    set states [pipe {
                        relvar set ::rosea::Config::State |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation project ~ Name Parameters Action
                    }]
                    set result [list]
                    relation foreach state $states {
                        relation assign $state
                        lappend result $Name $Parameters $Action
                    }
                    return $result
                }
                events {
                    return [pipe {
                        relvar set ::rosea::Config::EffectiveEvent |
                        relation restrictwith ~\
                            {$Domain eq $domainname && $Model eq $classname} |
                        relation list ~ Event
                    }]
                }
                transitions {
                    return [pipe {
                        relvar set ${domns}::__Arch_Transition |
                        relation restrictwith ~ {$Class eq $classname} |
                        relation eliminate ~ Class |
                        relation group ~ Transition Event NewState |
                        relation extend ~ trtup TranCol dict {
                            [relation dict [tuple extract $trtup Transition] Event NewState]} |
                        relation dict ~ State TranCol
                    }] ; # <1>
                }
                activityproc {
                    return ${domns}::${classname}::__Activity::${statename}
                }
            }
        }
    }
    namespace eval Trace {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
            ::ralutil::pipe
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        relvar create Trace {
            Trace_Id    int
            Timestamp   bignum
            Source      list
            Event       string
            Target      list
            Params      list
        } Trace_Id
        
        relvar create Creation {
            Trace_Id    int
        } Trace_Id
        
        relvar create Polymorphic {
            Trace_Id    int
            SubInst     string
            Linkage     string
        } Trace_Id
        
        relvar create Transition {
            Trace_Id    int
            CurrState   string
            NewState    string
        } Trace_Id
        
        relvar partition R1 Trace Trace_Id\
            Creation Trace_Id\
            Polymorphic Trace_Id\
            Transition Trace_Id
        variable targetCmpFunc [lambda {instrefs target} {
            lassign $target trelvar tinst
            foreach instref $instrefs {
                lassign $instref crelvar cinst
                if {$trelvar eq $crelvar && [ral relation is $tinst subsetof $cinst]} {
                    return true
                }
            }
            return false
        }]
        variable traceState off
        variable traceNumber 0
        variable traceLogState off
        variable traceLogLevel info
        variable traceLogCmd [::logger::init rosea]
        proc QueryClassTraces {classes} {
            variable Trace
            return [relation restrictwith $Trace {
                [lindex $Target 0] in $classes ||\
                    [namespace tail [lindex $Target 0]] in $classes
            }] ; # <1>
        }
        proc QueryTargetTraces {targets} {
            variable Trace
            variable targetCmpFunc
            return [relation restrictwith $Trace {[{*}$targetCmpFunc $targets $Target]}]
        }
        proc TraceCreation {source event target params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Creation [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TracePolymorphic {source event target sub link params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Polymorphic [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        SubInst     $sub\
                        Linkage     $link\
                    ]
                }
                LogTrace $trace
            }
        }
        proc TraceTransition {source event target curr new params} {
            variable traceState
            if {$traceState} {
                relvar eval {
                    set trace [NewTrace $source $event $target $params]
                    relvar insert Transition [list\
                        Trace_Id    [relation extract $trace Trace_Id]\
                        CurrState   $curr\
                        NewState    $new\
                    ]
                }
                LogTrace $trace
            }
        }
        proc NewTrace {src event target params} {
            variable traceNumber
            return [relvar insert Trace [list\
                Trace_Id    [incr traceNumber]\
                Timestamp   [clock microseconds]\
                Source      $src\
                Event       $event\
                Target      $target\
                Params      $params\
            ]]
        }
        proc LogTrace {trace} {
            variable traceLogState
            if {$traceLogState} {
                set rec [FormatTraceRec [lindex [TracesToRecords $trace] 0]] ; # <1>
        
                variable traceLogCmd
                variable traceLogLevel
                ${traceLogCmd}::${traceLogLevel} $rec
            }
        }
        proc TracesToRecords {traces} {
            foreach rvname {Creation Polymorphic Transition} { # <1>
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            set result [list]
            relation foreach trace $traces -ascending Trace_Id { # <2>
                relation assign $trace
                set labeled [dict create\
                    id      $Trace_Id\
                    time    $Timestamp\
                    source  $Source\
                    event   $Event\
                    target  $Target\
                    params  $Params\
                    class   [lindex $Target 0]\
                ] ; # <3>
                if {[relation isnotempty $Transition]} { # <4>
                    relation assign $Transition
                    dict set labeled type transition
                    dict set labeled current $CurrState
                    dict set labeled new $NewState
                } elseif {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic
                    dict set labeled type polymorphic
                    dict set labeled sub $SubInst
                    dict set labeled link $Linkage
                } elseif {[relation isnotempty $Creation]} {
                    dict set labeled type creation
                }
        
                lappend result $labeled
            }
            return $result
        }
        proc DecodeAllTraces {} {
            variable Trace
            tailcall TracesToRecords $Trace
        }
        proc DecodeClassTraces {args} {
            return [TracesToRecords [QueryClassTraces $args]]
        }
        proc DecodeTargetTraces {args} {
            tailcall TracesToRecords [QueryTargetTraces $args]
        }
        proc FormatTraceRec {rec} {
            dict with rec {
                switch -exact -- $type {
                    transition {
                        append result\
                            "Transition: "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $current -> $new"
                    }
                    polymorphic {
                        append result\
                            "Polymorphic : "\
                            [FormatTransition $source $event $params $target]\
                            " ==> $link -> [FormatInstRef $sub]"
                    }
                    creation {
                        append result\
                            "Creation: "\
                            "[FormatInstRef $source] - "\
                            "[FormatEvent $event $params] -> $class\
                            " ==> [FormatInstRef $target]"
                    }
                    default {
                        DeclError BAD_TRACETYPE $type
                    }
                }
            }
            return $result
        }
        proc FormatTransition {source event params target} {
            return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
                [FormatInstRef $target]"
        }
        proc FormatEvent {event params} {
            return [string cat\
                "$event"\
                [expr {[llength $params] != 0 ? " \([join $params {, }]\)" : {}}]\
            ]
        }
        proc FormatInstRef {instref} {
            lassign $instref relvar inst
            if {$relvar eq {}} {
                return {()}
            } else {
                return "$relvar \([tuple get [relation tuple $inst]]\)"
            }
        }
        proc FormatTimestamp {time} {
            set sec [clock format [expr {$time / 1000000}] -format %T] ; # <1>
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %s.%03ld.%03ld $sec $msec $usec]
        }
        proc FormatTimeAsSec {time} {
            set sec [expr {$time / 1000000}]
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        
            return [format %3ld.%03ld.%03ld $sec $msec $usec]
        }
        proc DiagTraces {traces args} {
            set result {}
            append result "seqdiag \{\n"
            append result "    activation = none;\n"
            foreach {option value} $args {
                append result "    $option = $value;\n"
            }
        
            foreach rvname {Creation Polymorphic Transition} {
                set traces [::ralutil::rvajoin $traces [relvar set $rvname] $rvname]
            }
        
            relation foreach trace $traces -ascending Trace_Id {
                relation assign $trace
                if {[isEmptyRef $Source]} {
                    set Source EXTERNAL
                } else {
                    set Source [namespace tail [lindex $Source 0]]
                }
                set Target [namespace tail [lindex $Target 0]]
                set evtlabel [FormatEvent $Event $Params]
                if {[relation isnotempty $Polymorphic]} {
                    relation assign $Polymorphic Linkage
                    append evtlabel " <<Polymorphic $Linkage>>"
                } elseif {[relation isnotempty $Creation]} {
                    append evtlabel " <<Creation>>"
                }
                append result "    $Source ->> $Target \[label=\"$evtlabel\"\];\n"
            }
        
            append result "\}\n"
        
            return $result
        }
        proc DiagAllTraces {filename args} {
            set chan [open $filename w]
            variable Trace
            try {
                chan puts $chan [DiagTraces $Trace {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagClassTraces {filename classes args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryClassTraces $classes] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
        proc DiagTargetTraces {filename targets args} {
            set chan [open $filename w]
            try {
                chan puts $chan [DiagTraces [QueryTargetTraces $targets] {*}$args]
            } finally {
                chan close $chan
            }
            return
        }
    }

    namespace path ::rosea::Helpers
    namespace import ::rosea::Config::ConfigEvaluate
}

package provide rosea $::rosea::version
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Changes to rosea/doc/rosea.html.

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
....
1150
1151
1152
1153
1154
1155
1156



1157
1158
1159
1160
1161










1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
....
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
....
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
....
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
....
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
....
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
<!-- Generated from file 'rosea.man' by tcllib/doctools with format 'html'
   -->
<!-- Copyright &amp;copy; 2014-2020 by G. Andrew Mangogna
   -->
<!-- rosea.n
   -->
<body><div class="doctools">
<h1 class="doctools_title">rosea(n) 1.9.2 rosea &quot;XUML Data and Execution Architecture&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>rosea - Relation Oriented Software Execution Architecture</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
................................................................................
</li>
<li class="doctools_section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">rosea <span class="opt">?1.9.2?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li>Package Commands</li>
<li><a href="#1"><b class="cmd">::rosea configure</b> <i class="arg">script</i></a></li>
<li><a href="#2"><b class="cmd">::rosea configureFromChan</b> <i class="arg">channel</i></a></li>
<li><a href="#3"><b class="cmd">::rosea configureFromFile</b> <i class="arg">filename</i></a></li>
<li><a href="#4"><b class="cmd">::rosea generate</b> <span class="opt">?<i class="arg">pattern</i>?</span> <span class="opt">?<i class="arg">nsqual</i>?</span></a></li>
................................................................................
<li><a href="#56"><i class="arg">relationship</i> <b class="cmd">link</b> <i class="arg">instref1</i> <i class="arg">instref2</i> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></li>
<li><a href="#57"><i class="arg">relationship</i> <b class="cmd">reference</b> <i class="arg">assocref</i> <i class="arg">instref</i></a></li>
<li><a href="#58"><i class="arg">relationship</i> <b class="cmd">unlink</b> <i class="arg">instref</i></a></li>
<li><a href="#59"><i class="arg">relationship</i> <b class="cmd">migrate</b> <i class="arg">instref</i> <i class="arg">subclass</i> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></li>
<li><a href="#60"><i class="arg">relationship</i> <b class="cmd">signal</b> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#61"><i class="arg">relationship</i> <b class="cmd">signal</b> <i class="arg">idvalues</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#62"><i class="arg">relationship</i> <b class="cmd">create</b> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></li>

<li>Instance Commands</li>
<li><a href="#63"><b class="cmd">deRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></li>
<li><a href="#64"><b class="cmd">nilInstRef</b></a></li>
<li><a href="#65"><b class="cmd">isEmptyRef</b> <i class="arg">instref</i></a></li>
<li><a href="#66"><b class="cmd">isNotEmptyRef</b> <i class="arg">instref</i></a></li>
<li><a href="#67"><b class="cmd">refMultiplicity</b> <i class="arg">instref</i></a></li>
<li><a href="#68"><b class="cmd">isRefSingular</b> <i class="arg">instref</i></a></li>
<li><a href="#69"><b class="cmd">limitRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">count</i>?</span></a></li>
<li><a href="#70"><b class="cmd">isRefEqual</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#71"><b class="cmd">refUnion</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#72"><b class="cmd">refIntersect</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#73"><b class="cmd">refMinus</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#74"><b class="cmd">forAllRefs</b> <i class="arg">varname</i> <i class="arg">instref</i> <i class="arg">script</i></a></li>
<li><a href="#75"><b class="cmd">findRelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></li>
<li><a href="#76"><b class="cmd">findUnrelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></li>
<li><a href="#77"><b class="cmd">findRelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></li>
<li><a href="#78"><b class="cmd">findUnrelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></li>
<li><a href="#79"><b class="cmd">idInstance</b> <i class="arg">asgnref</i></a></li>
<li><a href="#80"><b class="cmd">updateAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 value1 ...</i>?</span></a></li>
<li><a href="#81"><b class="cmd">withAttribute</b> <i class="arg">instref</i> <i class="arg">attrvarpair1</i> <span class="opt">?<i class="arg">attrvarpair2 attrvarpair3 ...</i>?</span> <i class="arg">body</i></a></li>
<li><a href="#82"><b class="cmd">readAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></li>
<li><a href="#83"><b class="cmd">assignAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attrvarpair1 attrvarpair2 ...</i>?</span></a></li>
<li><a href="#84"><b class="cmd">delete</b> <i class="arg"><span class="opt">?instref ...?</span></i></a></li>
<li><a href="#85"><b class="cmd">signal</b> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#86"><b class="cmd">delaysignal</b> <i class="arg">time</i> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#87"><b class="cmd">canceldelayed</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></li>
<li><a href="#88"><b class="cmd">delayremaining</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></li>
<li><a href="#89"><b class="cmd">instop</b> <i class="arg">instref</i> <i class="arg">operation</i> <span class="opt">?<i class="arg">arg1 arg2 ...</i>?</span></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>This manpage describes the <b class="package">rosea</b> package.
<b class="package">Rosea</b> is a data and execution architecture for translating
XUML models using Tcl as the implementation language.</p>
................................................................................
<dt><a name="61"><i class="arg">relationship</i> <b class="cmd">signal</b> <i class="arg">idvalues</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></dt>
<dd><p>For associations that have a multiple assigner state model,
the <b class="cmd">signal</b> command is used to signal <i class="arg">event</i> to the assigner
state machine identified by <i class="arg">idvalues</i>.
The <i class="arg">idvalues</i> argument is a dictionary whose keys are the attributes
names of the assigner identifier and whose corresponding values
match those of some assigner for <i class="arg">relationship</i>.



Any optional event parameters are given by the <i class="arg">paramN</i> arguments.</p></dd>
<dt><a name="62"><i class="arg">relationship</i> <b class="cmd">create</b> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></dt>
<dd><p>For associations that have a multiple assigner state model,
the <b class="cmd">create</b> command creates an instance of the assigner
that is identified by the <i class="arg">attrN</i> / <i class="arg">valueN</i> names and values.</p></dd>










</dl>
</div>
<div id="subsection8" class="doctools_subsection"><h3><a name="subsection8">Instance Commands</a></h3>
<p>The commands below define operations on class instances.
They are intended to be invoked as part of state activities and operations
to access the data model and signal events.
The context in which a state activity runs is such that these
commands will resolve using unqualified command names.</p>
<dl class="doctools_definitions">
<dt><a name="63"><b class="cmd">deRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">deRef</b> command returns a relation value containing the
class instances referred to by <i class="arg">instref</i>.
If no <i class="arg">attrN</i> arguments are given,
then the heading of the returned relation value contains all the
class attributes.
Otherwise, supplying <i class="arg">attr</i> names will result in the returned
relation value having only the given attributes plus a set of
identifying attributes.</p></dd>
<dt><a name="64"><b class="cmd">nilInstRef</b></a></dt>
<dd><p>The <b class="cmd">nilInstRef</b> command returns an instance reference that does
not refer to any instance.
Note that the nil instance reference is different from an empty
instance reference.
The later refers to no instances of some particular class.
The nil instance reference refers to no instances of no class
and is not equal to any instance reference other than itself.
This command has very limited utility such as when it is necessary
to cancel a delayed event that was signaled outside of a state activity.
In that case,
the nil instance reference is considered the source
of the event.</p></dd>
<dt><a name="65"><b class="cmd">isEmptyRef</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">isEmptyRef</b> command returns true if <i class="arg">instref</i> refers to
no instances and false otherwise.</p></dd>
<dt><a name="66"><b class="cmd">isNotEmptyRef</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">isNotEmptyRef</b> command returns true if <i class="arg">instref</i> refers to
any instances and false otherwise.</p></dd>
<dt><a name="67"><b class="cmd">refMultiplicity</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">refMultiplicity</b> command returns the number of instances referenced
by <i class="arg">instref</i>.</p></dd>
<dt><a name="68"><b class="cmd">isRefSingular</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">isRefSingular</b> command returns true if <i class="arg">instref</i> refers to
exactly one instance and false otherwise.</p></dd>
<dt><a name="69"><b class="cmd">limitRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">count</i>?</span></a></dt>
<dd><p>The <b class="cmd">limitRef</b> command returns a new instance reference that
refers to at most <i class="arg">count</i> instances.
If the <i class="arg">count</i> argument is missing, then the returned instance reference
refers to at most one instance.</p></dd>
<dt><a name="70"><b class="cmd">isRefEqual</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">isRefEqual</b> command returns true if <i class="arg">instref1</i> and <i class="arg">instref2</i>
both refers to the same instances and false otherwise.</p></dd>
<dt><a name="71"><b class="cmd">refUnion</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">refUnion</b> command computes the set union of the two instance
references given as arguments.</p></dd>
<dt><a name="72"><b class="cmd">refIntersect</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">refIntersect</b> command computes the set intersection of the two instance
references given as arguments.</p></dd>
<dt><a name="73"><b class="cmd">refMinus</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">refMinus</b> command computes the set differenct of <i class="arg">instref1</i>
minus <i class="arg">instref2</i>.</p></dd>
<dt><a name="74"><b class="cmd">forAllRefs</b> <i class="arg">varname</i> <i class="arg">instref</i> <i class="arg">script</i></a></dt>
<dd><p>The <b class="cmd">forAllRefs</b> command iterates across all the instances referred
to by <i class="arg">instref</i>.
It assigns a singular instance reference into <i class="arg">varname</i> and then
executes <i class="arg">script</i>.</p></dd>
<dt><a name="75"><b class="cmd">findRelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">findRelated</b> command traverses a relationship chain starting
at <i class="arg">instref</i> finding all the instances of those classes which
are the target of the traversal along the path given by the
<i class="arg">relationshipN</i> arguments.
Each <i class="arg">relationshipN</i> argument is treated as a one or two element list.
If a single element, then it is the name of a relationship (<em>e.g.</em> R27)
that is to be traversed in the forward direction or the
................................................................................
<p>The return value of <b class="cmd">findRelated</b> is an instance reference to
a set of instances for the class that is the ultimate destination of
the relationship chain.</p>
<pre class="doctools_example">
set inst [findRelated $self R1 {~R2 Sub} ~R3]
</pre>
</dd>
<dt><a name="76"><b class="cmd">findUnrelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">findUnrelated</b> command traverses a relationship chain starting
at <i class="arg">instref</i> finding all the instances of those classes that are <em>not</em>
related which are the target of the traversal along the path given by the
<i class="arg">relationshipN</i> arguments.
The <i class="arg">relationshipN</i> arguments are specified in the same manner
as for the <b class="cmd">findRelated</b> command.</p>
<p>The return value of <b class="cmd">findUnrelated</b> is an instance reference to
a set of instances that are <em>not</em> related to the
instances referenced by <i class="arg">instref</i> along the relationship navigation chain.</p></dd>
<dt><a name="77"><b class="cmd">findRelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></dt>
<dd><p>The <b class="cmd">findRelatedWhere</b> command traverses a relationship chain given by
<i class="arg">rchain</i> starting at <i class="arg">instref</i> finding all the instances of
those classes which are the target of the traversal along the path.
The result of the traversal is further filtered by returning a reference
only to those instances where <i class="arg">expression</i> evaluates to true.
The <i class="arg">rchain</i> argument is a list of relationship traversals as
described for the <b class="cmd">findRelated</b> command.
................................................................................
<p>The return value of <b class="cmd">findRelatedWhere</b> is an instance reference to
a set of instances for the class that is the ultimate destination of
the relationship chain and for which <i class="arg">expression</i> evaluates to true.</p>
<pre class="doctools_example">
set wv [findRelatedWhere $self ~R3 {$ValveID eq &quot;Drain&quot;}]
</pre>
</dd>
<dt><a name="78"><b class="cmd">findUnrelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></dt>
<dd><p>The <b class="cmd">findUnrelatedWhere</b> command operates the same as the
<b class="cmd">findRelatedWhere</b> command except that it returns a reference to
those instances that are <em>not</em> related to the instances
referenced by <i class="arg">instref</i>.</p></dd>
<dt><a name="79"><b class="cmd">idInstance</b> <i class="arg">asgnref</i></a></dt>
<dd><p>]
For associations that have a multiple assigner state model,
the <b class="cmd">idInstance</b> command finds the instance of the partitioning
class whose identifying attribute values match those of the
assigner instance.</p></dd>
<dt><a name="80"><b class="cmd">updateAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 value1 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">updateAttribute</b> command updates the <i class="arg">attrN</i> attributes
to the corresponding <i class="arg">valueN</i> value for all the class instances referenced
by <i class="arg">instref</i>.</p>
<p>The return value of <b class="cmd">updateAttribute</b> is the empty string.</p>
<pre class="doctools_example">
set wc [WashingCycle findById CycleType Normal]
updateAttribute $wc SpinDuration 20 SpinSpeed high
</pre>
</dd>
<dt><a name="81"><b class="cmd">withAttribute</b> <i class="arg">instref</i> <i class="arg">attrvarpair1</i> <span class="opt">?<i class="arg">attrvarpair2 attrvarpair3 ...</i>?</span> <i class="arg">body</i></a></dt>
<dd><p>The <b class="cmd">withAttribute</b> command assigns the values of the
attributes referenced by <i class="arg">instref</i> and given by
<i class="arg">attrvarpairN</i> arguments into the corresponding Tcl variables and
evaluates <i class="arg">body</i>.
The <i class="arg">instref</i> must refer to only a single instance.
After <i class="arg">body</i> executes,
the values of the assigned attributes are updated back into the class.
................................................................................
then that attribute is not updated after <i class="arg">body</i> completes.</p>
<pre class="doctools_example">
withAttribute $self Count {
    incr Count
}
</pre>
</dd>
<dt><a name="82"><b class="cmd">readAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">readAttribute</b> command returns the values of zero or more
attributes of the instance referenced by <i class="arg">instref</i>.
The <i class="arg">instref</i> reference must be singular.
If no <i class="arg">attrN</i> arguments are given,
the return value is the empty string.
If only one attribute argument is given,
then a simple scalar value is returned.
................................................................................
The order of the returned list corresponds to the order of
the <i class="arg">attrN</i> arguments.</p>
<pre class="doctools_example">
set wc [WashingCycle findById CycleType Normal]
set duration [readAttribute $wc SpinDuration]
</pre>
</dd>
<dt><a name="83"><b class="cmd">assignAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attrvarpair1 attrvarpair2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">assignAttribute</b> command assigns the values of the instance
referenced by <i class="arg">instref</i> into Tcl variables.
The <i class="arg">instref</i> reference must be singular.
If no <i class="arg">attrvarpairN</i> arguments are given,
then all the attributes of the instance are assigned to Tcl variables
whose names are the same as the attribute names.
If any <i class="arg">attrvarpairN</i> arguments are present,
................................................................................
set wc [WashingCycle findById CycleType Normal]
assignAttribute $wc {SpinDuration spin} {WashWaterTemp wwtemp}
if {$wwtemp &gt; 100} {
    puts &quot;we're in hot water&quot;
}
</pre>
</dd>
<dt><a name="84"><b class="cmd">delete</b> <i class="arg"><span class="opt">?instref ...?</span></i></a></dt>
<dd><p>The <b class="cmd">delete</b> command deletes all the class instances referenced by
the <i class="arg">instrefN</i> arguments.</p></dd>
<dt><a name="85"><b class="cmd">signal</b> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">signal</b> command sends the event named, <i class="arg">event</i>,
to all the class instances referenced by <i class="arg">instref</i>.
If any optional <i class="arg">paramN</i> parameters are supplied they are send as
parameters of the event.
It is a corollary of the rules of Moore type state machines that
any event that causes a transition into a state must supply any
parametric event data defined by the signature of the state activity.
Failing to do so will result in a runtime error when the event is dispatched.</p>
<pre class="doctools_example">
set wm [WashingMachine findById MachineId 27]
signal $wm Start
</pre>
</dd>
<dt><a name="86"><b class="cmd">delaysignal</b> <i class="arg">time</i> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">delaysignal</b> command sends the event named, <i class="arg">event</i>,
to all the class instances referenced by <i class="arg">instref</i>
at least <i class="arg">time</i> milliseconds in the future..
If any optional <i class="arg">paramN</i> parameters are supplied they are send as
parameters of the event.</p>
<pre class="doctools_example">
set wm [WashingMachine findById MachineId 27]
delaysignal 100 $wm Start
</pre>
</dd>
<dt><a name="87"><b class="cmd">canceldelayed</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></dt>
<dd><p>The <b class="cmd">canceldelayed</b> command cancels the outstanding <i class="arg">event</i>
between the instance referred to by <i class="arg">srcref</i> and all the instances
referred to by <i class="arg">dstref</i>.
If there are not outstanding <i class="arg">event</i> events between the referenced
instanced,
then no action is taken and no error is generated.</p></dd>
<dt><a name="88"><b class="cmd">delayremaining</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></dt>
<dd><p>The <b class="cmd">delayremaining</b> command returns the number of milliseconds
until <i class="arg">event</i> is signaled from <i class="arg">srcref</i> to <i class="arg">dstref</i>.
The returned value will be zero if the <i class="arg">event</i> does not exist
or has already been signaled.</p></dd>
<dt><a name="89"><b class="cmd">instop</b> <i class="arg">instref</i> <i class="arg">operation</i> <span class="opt">?<i class="arg">arg1 arg2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">instop</b> command invokes an instance based operation,
<i class="arg">operation</i>, on the class instance referenced by <i class="arg">instref</i>.
The options <i class="arg">argN</i> arguments are passed to the operation.</p></dd>
</dl>
</div>
</div>
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2014-2020 by G. Andrew Mangogna</p>
</div>
</div></body></html>







|







 







|







 







>

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







 







>
>
>




|
>
>
>
>
>
>
>
>
>
>









|








|












|


|


|


|


|




|


|


|


|


|




|







 







|









|







 







|




|





|









|







 







|







 







|







 







|


|













|










|






|




|










94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
....
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
....
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
....
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
....
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
....
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
....
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
<!-- Generated from file 'rosea.man' by tcllib/doctools with format 'html'
   -->
<!-- Copyright &amp;copy; 2014-2020 by G. Andrew Mangogna
   -->
<!-- rosea.n
   -->
<body><div class="doctools">
<h1 class="doctools_title">rosea(n) 1.10 rosea &quot;XUML Data and Execution Architecture&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>rosea - Relation Oriented Software Execution Architecture</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
................................................................................
</li>
<li class="doctools_section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">rosea <span class="opt">?1.10?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li>Package Commands</li>
<li><a href="#1"><b class="cmd">::rosea configure</b> <i class="arg">script</i></a></li>
<li><a href="#2"><b class="cmd">::rosea configureFromChan</b> <i class="arg">channel</i></a></li>
<li><a href="#3"><b class="cmd">::rosea configureFromFile</b> <i class="arg">filename</i></a></li>
<li><a href="#4"><b class="cmd">::rosea generate</b> <span class="opt">?<i class="arg">pattern</i>?</span> <span class="opt">?<i class="arg">nsqual</i>?</span></a></li>
................................................................................
<li><a href="#56"><i class="arg">relationship</i> <b class="cmd">link</b> <i class="arg">instref1</i> <i class="arg">instref2</i> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></li>
<li><a href="#57"><i class="arg">relationship</i> <b class="cmd">reference</b> <i class="arg">assocref</i> <i class="arg">instref</i></a></li>
<li><a href="#58"><i class="arg">relationship</i> <b class="cmd">unlink</b> <i class="arg">instref</i></a></li>
<li><a href="#59"><i class="arg">relationship</i> <b class="cmd">migrate</b> <i class="arg">instref</i> <i class="arg">subclass</i> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></li>
<li><a href="#60"><i class="arg">relationship</i> <b class="cmd">signal</b> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#61"><i class="arg">relationship</i> <b class="cmd">signal</b> <i class="arg">idvalues</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#62"><i class="arg">relationship</i> <b class="cmd">create</b> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></li>
<li><a href="#63"><i class="arg">relationship</i> <b class="cmd">delete</b> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></li>
<li>Instance Commands</li>
<li><a href="#64"><b class="cmd">deRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></li>
<li><a href="#65"><b class="cmd">nilInstRef</b></a></li>
<li><a href="#66"><b class="cmd">isEmptyRef</b> <i class="arg">instref</i></a></li>
<li><a href="#67"><b class="cmd">isNotEmptyRef</b> <i class="arg">instref</i></a></li>
<li><a href="#68"><b class="cmd">refMultiplicity</b> <i class="arg">instref</i></a></li>
<li><a href="#69"><b class="cmd">isRefSingular</b> <i class="arg">instref</i></a></li>
<li><a href="#70"><b class="cmd">limitRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">count</i>?</span></a></li>
<li><a href="#71"><b class="cmd">isRefEqual</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#72"><b class="cmd">refUnion</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#73"><b class="cmd">refIntersect</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#74"><b class="cmd">refMinus</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></li>
<li><a href="#75"><b class="cmd">forAllRefs</b> <i class="arg">varname</i> <i class="arg">instref</i> <i class="arg">script</i></a></li>
<li><a href="#76"><b class="cmd">findRelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></li>
<li><a href="#77"><b class="cmd">findUnrelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></li>
<li><a href="#78"><b class="cmd">findRelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></li>
<li><a href="#79"><b class="cmd">findUnrelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></li>
<li><a href="#80"><b class="cmd">idInstance</b> <i class="arg">asgnref</i></a></li>
<li><a href="#81"><b class="cmd">updateAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 value1 ...</i>?</span></a></li>
<li><a href="#82"><b class="cmd">withAttribute</b> <i class="arg">instref</i> <i class="arg">attrvarpair1</i> <span class="opt">?<i class="arg">attrvarpair2 attrvarpair3 ...</i>?</span> <i class="arg">body</i></a></li>
<li><a href="#83"><b class="cmd">readAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></li>
<li><a href="#84"><b class="cmd">assignAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attrvarpair1 attrvarpair2 ...</i>?</span></a></li>
<li><a href="#85"><b class="cmd">delete</b> <i class="arg"><span class="opt">?instref ...?</span></i></a></li>
<li><a href="#86"><b class="cmd">signal</b> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#87"><b class="cmd">delaysignal</b> <i class="arg">time</i> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></li>
<li><a href="#88"><b class="cmd">canceldelayed</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></li>
<li><a href="#89"><b class="cmd">delayremaining</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></li>
<li><a href="#90"><b class="cmd">instop</b> <i class="arg">instref</i> <i class="arg">operation</i> <span class="opt">?<i class="arg">arg1 arg2 ...</i>?</span></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>This manpage describes the <b class="package">rosea</b> package.
<b class="package">Rosea</b> is a data and execution architecture for translating
XUML models using Tcl as the implementation language.</p>
................................................................................
<dt><a name="61"><i class="arg">relationship</i> <b class="cmd">signal</b> <i class="arg">idvalues</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></dt>
<dd><p>For associations that have a multiple assigner state model,
the <b class="cmd">signal</b> command is used to signal <i class="arg">event</i> to the assigner
state machine identified by <i class="arg">idvalues</i>.
The <i class="arg">idvalues</i> argument is a dictionary whose keys are the attributes
names of the assigner identifier and whose corresponding values
match those of some assigner for <i class="arg">relationship</i>.
The attribute names will be the same as the attribute names of the
identifier implied by the <b class="method">identifyby</b> command which is used
to mark an assigner as a multi-assigner.
Any optional event parameters are given by the <i class="arg">paramN</i> arguments.</p></dd>
<dt><a name="62"><i class="arg">relationship</i> <b class="cmd">create</b> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></dt>
<dd><p>For associations that have a multiple assigner state model,
the <b class="cmd">create</b> command creates an instance of the assigner
that is identified by the <i class="arg">attrN</i> / <i class="arg">valueN</i> names and values.
The attribute names will be the same as the attribute names of the
identifier implied by the <b class="method">identifyby</b> command which is used
to mark an assigner as a multi-assigner.</p></dd>
<dt><a name="63"><i class="arg">relationship</i> <b class="cmd">delete</b> <span class="opt">?<i class="arg">attr1 value1 attr2 value2 ...</i>?</span></a></dt>
<dd><p>For associations that have a multiple assigner state model,
the <b class="cmd">delete</b> command deletes an instance of the assigner
that is identified by the <i class="arg">attrN</i> / <i class="arg">valueN</i> names and values.
The attribute names will be the same as the attribute names of the
identifier implied by the <b class="method">identifyby</b> command which is used
to mark an assigner as a multi-assigner.</p></dd>
</dl>
</div>
<div id="subsection8" class="doctools_subsection"><h3><a name="subsection8">Instance Commands</a></h3>
<p>The commands below define operations on class instances.
They are intended to be invoked as part of state activities and operations
to access the data model and signal events.
The context in which a state activity runs is such that these
commands will resolve using unqualified command names.</p>
<dl class="doctools_definitions">
<dt><a name="64"><b class="cmd">deRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">deRef</b> command returns a relation value containing the
class instances referred to by <i class="arg">instref</i>.
If no <i class="arg">attrN</i> arguments are given,
then the heading of the returned relation value contains all the
class attributes.
Otherwise, supplying <i class="arg">attr</i> names will result in the returned
relation value having only the given attributes plus a set of
identifying attributes.</p></dd>
<dt><a name="65"><b class="cmd">nilInstRef</b></a></dt>
<dd><p>The <b class="cmd">nilInstRef</b> command returns an instance reference that does
not refer to any instance.
Note that the nil instance reference is different from an empty
instance reference.
The later refers to no instances of some particular class.
The nil instance reference refers to no instances of no class
and is not equal to any instance reference other than itself.
This command has very limited utility such as when it is necessary
to cancel a delayed event that was signaled outside of a state activity.
In that case,
the nil instance reference is considered the source
of the event.</p></dd>
<dt><a name="66"><b class="cmd">isEmptyRef</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">isEmptyRef</b> command returns true if <i class="arg">instref</i> refers to
no instances and false otherwise.</p></dd>
<dt><a name="67"><b class="cmd">isNotEmptyRef</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">isNotEmptyRef</b> command returns true if <i class="arg">instref</i> refers to
any instances and false otherwise.</p></dd>
<dt><a name="68"><b class="cmd">refMultiplicity</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">refMultiplicity</b> command returns the number of instances referenced
by <i class="arg">instref</i>.</p></dd>
<dt><a name="69"><b class="cmd">isRefSingular</b> <i class="arg">instref</i></a></dt>
<dd><p>The <b class="cmd">isRefSingular</b> command returns true if <i class="arg">instref</i> refers to
exactly one instance and false otherwise.</p></dd>
<dt><a name="70"><b class="cmd">limitRef</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">count</i>?</span></a></dt>
<dd><p>The <b class="cmd">limitRef</b> command returns a new instance reference that
refers to at most <i class="arg">count</i> instances.
If the <i class="arg">count</i> argument is missing, then the returned instance reference
refers to at most one instance.</p></dd>
<dt><a name="71"><b class="cmd">isRefEqual</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">isRefEqual</b> command returns true if <i class="arg">instref1</i> and <i class="arg">instref2</i>
both refers to the same instances and false otherwise.</p></dd>
<dt><a name="72"><b class="cmd">refUnion</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">refUnion</b> command computes the set union of the two instance
references given as arguments.</p></dd>
<dt><a name="73"><b class="cmd">refIntersect</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">refIntersect</b> command computes the set intersection of the two instance
references given as arguments.</p></dd>
<dt><a name="74"><b class="cmd">refMinus</b> <i class="arg">instref1</i> <i class="arg">instref2</i></a></dt>
<dd><p>The <b class="cmd">refMinus</b> command computes the set differenct of <i class="arg">instref1</i>
minus <i class="arg">instref2</i>.</p></dd>
<dt><a name="75"><b class="cmd">forAllRefs</b> <i class="arg">varname</i> <i class="arg">instref</i> <i class="arg">script</i></a></dt>
<dd><p>The <b class="cmd">forAllRefs</b> command iterates across all the instances referred
to by <i class="arg">instref</i>.
It assigns a singular instance reference into <i class="arg">varname</i> and then
executes <i class="arg">script</i>.</p></dd>
<dt><a name="76"><b class="cmd">findRelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">findRelated</b> command traverses a relationship chain starting
at <i class="arg">instref</i> finding all the instances of those classes which
are the target of the traversal along the path given by the
<i class="arg">relationshipN</i> arguments.
Each <i class="arg">relationshipN</i> argument is treated as a one or two element list.
If a single element, then it is the name of a relationship (<em>e.g.</em> R27)
that is to be traversed in the forward direction or the
................................................................................
<p>The return value of <b class="cmd">findRelated</b> is an instance reference to
a set of instances for the class that is the ultimate destination of
the relationship chain.</p>
<pre class="doctools_example">
set inst [findRelated $self R1 {~R2 Sub} ~R3]
</pre>
</dd>
<dt><a name="77"><b class="cmd">findUnrelated</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">relationship1 relationship2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">findUnrelated</b> command traverses a relationship chain starting
at <i class="arg">instref</i> finding all the instances of those classes that are <em>not</em>
related which are the target of the traversal along the path given by the
<i class="arg">relationshipN</i> arguments.
The <i class="arg">relationshipN</i> arguments are specified in the same manner
as for the <b class="cmd">findRelated</b> command.</p>
<p>The return value of <b class="cmd">findUnrelated</b> is an instance reference to
a set of instances that are <em>not</em> related to the
instances referenced by <i class="arg">instref</i> along the relationship navigation chain.</p></dd>
<dt><a name="78"><b class="cmd">findRelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></dt>
<dd><p>The <b class="cmd">findRelatedWhere</b> command traverses a relationship chain given by
<i class="arg">rchain</i> starting at <i class="arg">instref</i> finding all the instances of
those classes which are the target of the traversal along the path.
The result of the traversal is further filtered by returning a reference
only to those instances where <i class="arg">expression</i> evaluates to true.
The <i class="arg">rchain</i> argument is a list of relationship traversals as
described for the <b class="cmd">findRelated</b> command.
................................................................................
<p>The return value of <b class="cmd">findRelatedWhere</b> is an instance reference to
a set of instances for the class that is the ultimate destination of
the relationship chain and for which <i class="arg">expression</i> evaluates to true.</p>
<pre class="doctools_example">
set wv [findRelatedWhere $self ~R3 {$ValveID eq &quot;Drain&quot;}]
</pre>
</dd>
<dt><a name="79"><b class="cmd">findUnrelatedWhere</b> <i class="arg">instref</i> <i class="arg">rchain</i> <i class="arg">expression</i></a></dt>
<dd><p>The <b class="cmd">findUnrelatedWhere</b> command operates the same as the
<b class="cmd">findRelatedWhere</b> command except that it returns a reference to
those instances that are <em>not</em> related to the instances
referenced by <i class="arg">instref</i>.</p></dd>
<dt><a name="80"><b class="cmd">idInstance</b> <i class="arg">asgnref</i></a></dt>
<dd><p>]
For associations that have a multiple assigner state model,
the <b class="cmd">idInstance</b> command finds the instance of the partitioning
class whose identifying attribute values match those of the
assigner instance.</p></dd>
<dt><a name="81"><b class="cmd">updateAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 value1 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">updateAttribute</b> command updates the <i class="arg">attrN</i> attributes
to the corresponding <i class="arg">valueN</i> value for all the class instances referenced
by <i class="arg">instref</i>.</p>
<p>The return value of <b class="cmd">updateAttribute</b> is the empty string.</p>
<pre class="doctools_example">
set wc [WashingCycle findById CycleType Normal]
updateAttribute $wc SpinDuration 20 SpinSpeed high
</pre>
</dd>
<dt><a name="82"><b class="cmd">withAttribute</b> <i class="arg">instref</i> <i class="arg">attrvarpair1</i> <span class="opt">?<i class="arg">attrvarpair2 attrvarpair3 ...</i>?</span> <i class="arg">body</i></a></dt>
<dd><p>The <b class="cmd">withAttribute</b> command assigns the values of the
attributes referenced by <i class="arg">instref</i> and given by
<i class="arg">attrvarpairN</i> arguments into the corresponding Tcl variables and
evaluates <i class="arg">body</i>.
The <i class="arg">instref</i> must refer to only a single instance.
After <i class="arg">body</i> executes,
the values of the assigned attributes are updated back into the class.
................................................................................
then that attribute is not updated after <i class="arg">body</i> completes.</p>
<pre class="doctools_example">
withAttribute $self Count {
    incr Count
}
</pre>
</dd>
<dt><a name="83"><b class="cmd">readAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attr1 attr2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">readAttribute</b> command returns the values of zero or more
attributes of the instance referenced by <i class="arg">instref</i>.
The <i class="arg">instref</i> reference must be singular.
If no <i class="arg">attrN</i> arguments are given,
the return value is the empty string.
If only one attribute argument is given,
then a simple scalar value is returned.
................................................................................
The order of the returned list corresponds to the order of
the <i class="arg">attrN</i> arguments.</p>
<pre class="doctools_example">
set wc [WashingCycle findById CycleType Normal]
set duration [readAttribute $wc SpinDuration]
</pre>
</dd>
<dt><a name="84"><b class="cmd">assignAttribute</b> <i class="arg">instref</i> <span class="opt">?<i class="arg">attrvarpair1 attrvarpair2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">assignAttribute</b> command assigns the values of the instance
referenced by <i class="arg">instref</i> into Tcl variables.
The <i class="arg">instref</i> reference must be singular.
If no <i class="arg">attrvarpairN</i> arguments are given,
then all the attributes of the instance are assigned to Tcl variables
whose names are the same as the attribute names.
If any <i class="arg">attrvarpairN</i> arguments are present,
................................................................................
set wc [WashingCycle findById CycleType Normal]
assignAttribute $wc {SpinDuration spin} {WashWaterTemp wwtemp}
if {$wwtemp &gt; 100} {
    puts &quot;we're in hot water&quot;
}
</pre>
</dd>
<dt><a name="85"><b class="cmd">delete</b> <i class="arg"><span class="opt">?instref ...?</span></i></a></dt>
<dd><p>The <b class="cmd">delete</b> command deletes all the class instances referenced by
the <i class="arg">instrefN</i> arguments.</p></dd>
<dt><a name="86"><b class="cmd">signal</b> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">signal</b> command sends the event named, <i class="arg">event</i>,
to all the class instances referenced by <i class="arg">instref</i>.
If any optional <i class="arg">paramN</i> parameters are supplied they are send as
parameters of the event.
It is a corollary of the rules of Moore type state machines that
any event that causes a transition into a state must supply any
parametric event data defined by the signature of the state activity.
Failing to do so will result in a runtime error when the event is dispatched.</p>
<pre class="doctools_example">
set wm [WashingMachine findById MachineId 27]
signal $wm Start
</pre>
</dd>
<dt><a name="87"><b class="cmd">delaysignal</b> <i class="arg">time</i> <i class="arg">instref</i> <i class="arg">event</i> <span class="opt">?<i class="arg">param1 param2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">delaysignal</b> command sends the event named, <i class="arg">event</i>,
to all the class instances referenced by <i class="arg">instref</i>
at least <i class="arg">time</i> milliseconds in the future..
If any optional <i class="arg">paramN</i> parameters are supplied they are send as
parameters of the event.</p>
<pre class="doctools_example">
set wm [WashingMachine findById MachineId 27]
delaysignal 100 $wm Start
</pre>
</dd>
<dt><a name="88"><b class="cmd">canceldelayed</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></dt>
<dd><p>The <b class="cmd">canceldelayed</b> command cancels the outstanding <i class="arg">event</i>
between the instance referred to by <i class="arg">srcref</i> and all the instances
referred to by <i class="arg">dstref</i>.
If there are not outstanding <i class="arg">event</i> events between the referenced
instanced,
then no action is taken and no error is generated.</p></dd>
<dt><a name="89"><b class="cmd">delayremaining</b> <i class="arg">srcref</i> <i class="arg">dstref</i> <i class="arg">event</i></a></dt>
<dd><p>The <b class="cmd">delayremaining</b> command returns the number of milliseconds
until <i class="arg">event</i> is signaled from <i class="arg">srcref</i> to <i class="arg">dstref</i>.
The returned value will be zero if the <i class="arg">event</i> does not exist
or has already been signaled.</p></dd>
<dt><a name="90"><b class="cmd">instop</b> <i class="arg">instref</i> <i class="arg">operation</i> <span class="opt">?<i class="arg">arg1 arg2 ...</i>?</span></a></dt>
<dd><p>The <b class="cmd">instop</b> command invokes an instance based operation,
<i class="arg">operation</i>, on the class instance referenced by <i class="arg">instref</i>.
The options <i class="arg">argN</i> arguments are passed to the operation.</p></dd>
</dl>
</div>
</div>
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2014-2020 by G. Andrew Mangogna</p>
</div>
</div></body></html>

Changes to rosea/doc/rosea.pdf.

cannot compute difference between binary files

Changes to rosea/src/Makefile.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

vpath %.pdf $(DOCDIR)
vpath %.html $(DOCDIR)
vpath %.test $(TESTDIR)
vpath %.uxf $(IMAGEDIR)

PROGNAME = rosea
VERSION=1.9.2

DOCSRC 	=\
	$(PROGNAME).aweb\
	$(NULL)

DIAGRAMS =\
	assoc-link.uxf\
................................................................................
	mkmodule $(PROGNAME) $(VERSION) -script $^
	mv $(PROGNAME)-$(VERSION).tm $(MODULEDIR)

$(PKGDIR)/package-$(PROGNAME)-$(VERSION)-tcl.tm : $(TCLSRC) teapot.txt
	teapot-pkg generate --output $(PKGDIR) .

runtests : tests
	cd $(TESTDIR) ; tclsh $(TESTS) -verbose bet -level info

runexample : example
	tclsh runwm.tcl | tee wmctrl-trace.txt

wmctrl-trace.txt $(IMAGEDIR)/wmctrl-seqdiag.diag : runwm.tcl wmctrl.tcl $(TCLSRC)
	tclsh runwm.tcl | tee wmctrl-trace.txt








|







 







|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

vpath %.pdf $(DOCDIR)
vpath %.html $(DOCDIR)
vpath %.test $(TESTDIR)
vpath %.uxf $(IMAGEDIR)

PROGNAME = rosea
VERSION=1.10

DOCSRC 	=\
	$(PROGNAME).aweb\
	$(NULL)

DIAGRAMS =\
	assoc-link.uxf\
................................................................................
	mkmodule $(PROGNAME) $(VERSION) -script $^
	mv $(PROGNAME)-$(VERSION).tm $(MODULEDIR)

$(PKGDIR)/package-$(PROGNAME)-$(VERSION)-tcl.tm : $(TCLSRC) teapot.txt
	teapot-pkg generate --output $(PKGDIR) .

runtests : tests
	cd $(TESTDIR) ; tclsh $(TESTS) -verbose bet -level debug

runexample : example
	tclsh runwm.tcl | tee wmctrl-trace.txt

wmctrl-trace.txt $(IMAGEDIR)/wmctrl-seqdiag.diag : runwm.tcl wmctrl.tcl $(TCLSRC)
	tclsh runwm.tcl | tee wmctrl-trace.txt

Changes to rosea/src/bibliography.txt.



1
2
3
4
5
6
7
8
9
10
11
12
13





14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37


[bibliography]
Bibliography
------------
[bibliography]
.Books
- [[[mb-xuml]]] Stephen J. Mellor and Marc J. Balcer,
    'Executable UML: a foundation for model-driven architecture',
    Addison-Wesley (2002), ISBN 0-201-74804-5.
- [[[rs-xuml]]] Chris Raistrick, Paul Francis, John Wright, Colin Carter and
    Ian Wilkie,
    'Model Driven Architecture with Executable UML',
    Cambridge University Press (2004),
    ISBN 0-521-53771-1.





- [[[ls-build]]], Leon Starr,
    'How to Build Shlaer-Mellor Object Models',
    Yourdon Press (1996),
    ISBN 0-13-207663-2.
- [[[sm-data]]] Sally Shlaer and Stephen J. Mellor,
    'Object Oriented Systems Analysis: Modeling the World in Data',
    Prentice-Hall (1988),
    ISBN 0-13-629023-X.
- [[[sm-states]]]
    Sally Shlaer and Stephen J. Mellor,
    'Object Oriented Systems Analysis: Modeling the World in States',
    Prentice-Hall (1992),
    ISBN 0-13-629940-7.

[bibliography]
.Articles
- [[[ls-articulate]]] Leon Starr,
    'How to Build Articulate UML Class Models',
    2008,
    http://www.modelint.com/how-to-build-articulate-uml-class-models/
- [[[ls-time]]] Leon Starr,
    'Time and Synchronization in Executable UML',
    2008,
    http://www.modelint.com/time-and-synchronization-in-executable-uml/
>
>

|
<










>
>
>
>
>










|













1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// vim:set syntax=asciidoc:

[bibliography]
== Bibliography

[bibliography]
.Books
- [[[mb-xuml]]] Stephen J. Mellor and Marc J. Balcer,
    'Executable UML: a foundation for model-driven architecture',
    Addison-Wesley (2002), ISBN 0-201-74804-5.
- [[[rs-xuml]]] Chris Raistrick, Paul Francis, John Wright, Colin Carter and
    Ian Wilkie,
    'Model Driven Architecture with Executable UML',
    Cambridge University Press (2004),
    ISBN 0-521-53771-1.
- [[[mtoc]]]
    Leon Starr, Andrew Mangogna and Stephen Mellor,
    'Models to Code: With No Mysterious Gaps',
    Apress (2017),
    ISBN 978-1-4842-2216-4
- [[[ls-build]]], Leon Starr,
    'How to Build Shlaer-Mellor Object Models',
    Yourdon Press (1996),
    ISBN 0-13-207663-2.
- [[[sm-data]]] Sally Shlaer and Stephen J. Mellor,
    'Object Oriented Systems Analysis: Modeling the World in Data',
    Prentice-Hall (1988),
    ISBN 0-13-629023-X.
- [[[sm-states]]]
    Sally Shlaer and Stephen J. Mellor,
    'Object Lifecycles: Modeling the World in States',
    Prentice-Hall (1992),
    ISBN 0-13-629940-7.

[bibliography]
.Articles
- [[[ls-articulate]]] Leon Starr,
    'How to Build Articulate UML Class Models',
    2008,
    http://www.modelint.com/how-to-build-articulate-uml-class-models/
- [[[ls-time]]] Leon Starr,
    'Time and Synchronization in Executable UML',
    2008,
    http://www.modelint.com/time-and-synchronization-in-executable-uml/

Changes to rosea/src/docinfo.xml.

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<authorgroup>
  <author>
    <firstname>Andrew</firstname>
    <surname>Mangogna</surname>
  </author>
</authorgroup>
<copyright>
  <year>2014-2015</year>
  <holder>
      G. Andrew Mangogna
  </holder>
</copyright>
<legalnotice>
  <title>
      Legal Notices and Information
  </title>
  <para>
This software is copyrighted 2014-2015 by G. Andrew Mangogna.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files.
  </para>
  <para>
The author hereby grants permission to use, copy, modify, distribute,
and license this software and its documentation for any purpose, provided
that existing copyright notices are retained in all copies and that this







|









|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<authorgroup>
  <author>
    <firstname>Andrew</firstname>
    <surname>Mangogna</surname>
  </author>
</authorgroup>
<copyright>
  <year>2014-2020</year>
  <holder>
      G. Andrew Mangogna
  </holder>
</copyright>
<legalnotice>
  <title>
      Legal Notices and Information
  </title>
  <para>
This software is copyrighted 2014-2020 by G. Andrew Mangogna.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files.
  </para>
  <para>
The author hereby grants permission to use, copy, modify, distribute,
and license this software and its documentation for any purpose, provided
that existing copyright notices are retained in all copies and that this

Changes to rosea/src/images/arch-class-diagram.uxf.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

151
152
153

154
155
156











































157
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="13.3">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>500</x>
      <y>240</y>
      <w>70</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

State
--
Class {I}
State (I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>610</x>
      <y>70</y>
      <w>90</w>
      <h>90</h>
    </coordinates>
    <panel_attributes>style=autoresize

Transition
--
Class {I,R1}
State (I,R1}
Event {I,R1}
NewState</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>540</x>
      <y>220</y>
      <w>260</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..n
m2=1..n
R1
reacts to&gt;
&lt;affects
</panel_attributes>
    <additional_attributes>30;50;240;50</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>630</x>
      <y>130</y>
      <w>50</w>
      <h>160</h>
    </coordinates>
    <panel_attributes>lt=&lt;-</panel_attributes>
    <additional_attributes>30;140;30;30</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>150</x>
      <y>240</y>
      <w>90</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

InitialState
--
Class {I,R2}
State (R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>210</x>
      <y>220</y>
      <w>310</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..1
m2=1
R6
is a starting state&gt;
&lt;starts at
</panel_attributes>
    <additional_attributes>30;50;290;50</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>710</x>
      <y>410</y>
      <w>120</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

PolymorphicEvent
--
Class {I,R2}
Event (I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>780</x>
      <y>240</y>
      <w>70</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Event
--
Class {I}
Event (I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>480</x>
      <y>450</y>
      <w>100</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

TerminalState
--
Class {I,R2}
State (R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>520</x>
      <y>290</y>
      <w>150</w>
      <h>180</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1

m2=0..*
is an ending state ^
R7

ends at v</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;160.0</additional_attributes>
  </element>











































</diagram>

|






|
|


>









|

|
|


>









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|

|
|


>







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





|


>











|
|


>











|
|


>










|
|
|



>

<
<
>
|
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38




























39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

















55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="14.3.0">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>500</x>
      <y>240</y>
      <w>60</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
State
--
Class {I}
State (I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>620</x>
      <y>70</y>
      <w>80</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Transition
--
Class {I,R1}
State (I,R1}
Event {I,R1}
NewState</panel_attributes>
    <additional_attributes/>
  </element>
  <element>




























    <id>UMLClass</id>
    <coordinates>
      <x>160</x>
      <y>240</y>
      <w>80</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
InitialState
--
Class {I,R2}
State (R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>

















    <id>UMLClass</id>
    <coordinates>
      <x>710</x>
      <y>410</y>
      <w>120</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
PolymorphicEvent
--
Class {I,R2}
Event (I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>780</x>
      <y>240</y>
      <w>60</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Event
--
Class {I}
Event (I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>480</x>
      <y>450</y>
      <w>90</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
TerminalState
--
Class {I,R2}
State (R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>520</x>
      <y>300</y>
      <w>130</w>
      <h>170</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=is an ending state
m2=0..*


r2=ends at
R7</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;150.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>650</x>
      <y>160</y>
      <w>30</w>
      <h>130</h>
    </coordinates>
    <panel_attributes>lt=.</panel_attributes>
    <additional_attributes>10.0;110.0;10.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>230</x>
      <y>250</y>
      <w>290</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..1
r1=starts at
m2=1
r2=is a starting\nstate
R6</panel_attributes>
    <additional_attributes>10.0;30.0;270.0;30.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>550</x>
      <y>250</y>
      <w>250</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..1
r1=affects
m2=1
r2=reacts to
R1</panel_attributes>
    <additional_attributes>10.0;20.0;230.0;20.0</additional_attributes>
  </element>
</diagram>

Changes to rosea/src/images/assoc-link.uxf.

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.2">
  <zoom_level>10</zoom_level>
  <element>
    <type>com.umlet.element.Class</type>
    <coordinates>
      <x>460</x>
      <y>210</y>
      <w>100</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>X


--
RefAttr {R1}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.umlet.element.Class</type>
    <coordinates>
      <x>690</x>
      <y>210</y>
      <w>70</w>
      <h>40</h>
    </coordinates>
    <panel_attributes>Y

--</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.umlet.element.Relation</type>
    <coordinates>
      <x>530</x>
      <y>180</y>
      <w>180</w>
      <h>94</h>
    </coordinates>
    <panel_attributes>
direction&gt;
R1</panel_attributes>
    <additional_attributes>160;50;30;50</additional_attributes>
  </element>
</diagram>

|


|

|
|
|


|
>
>





|

|
|

|

|
>




|

|
|
|
|

|
|

|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="14.3.0">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>500</x>
      <y>350</y>
      <w>80</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
X
--
RefAttr {R1}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>740</x>
      <y>350</y>
      <w>70</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>bg=yellow
Y
--</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>570</x>
      <y>360</y>
      <w>190</w>
      <h>40</h>
    </coordinates>
    <panel_attributes>lt=-
direction &gt;
R1</panel_attributes>
    <additional_attributes>10.0;20.0;170.0;20.0</additional_attributes>
  </element>
</diagram>

Changes to rosea/src/images/assoc-ref-links.uxf.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="13.3">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>260</x>
      <y>180</y>
      <w>110</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize

AssocRef
--
Relationship {I}
AssocClass
References</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>590</x>
      <y>250</y>
      <w>140</w>
      <h>40</h>
    </coordinates>
    <panel_attributes>halign=left
style=autoresize

ReferringAttribute
ReferencedAttribute</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>430</x>
      <y>220</y>
      <w>100</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>halign=left
style=autoresize

Participant
Role
ReferringAttrs</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>340</x>
      <y>220</y>
      <w>110</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes>
    <additional_attributes>30;30;90;30</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>500</x>
      <y>240</y>
      <w>110</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes>
    <additional_attributes>30;30;90;30</additional_attributes>
  </element>
</diagram>

|




|

|



>










|

|
|



>







|

|




>






|

|
|
|
|

|
|


|

|
|
|
|

|
|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="14.3.0">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>270</x>
      <y>180</y>
      <w>100</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
AssocRef
--
Relationship {I}
AssocClass
References</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>600</x>
      <y>250</y>
      <w>130</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>halign=left
style=autoresize
bg=yellow
ReferringAttribute
ReferencedAttribute</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>440</x>
      <y>220</y>
      <w>90</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>halign=left
style=autoresize
bg=yellow
Participant
Role
ReferringAttrs</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>360</x>
      <y>240</y>
      <w>100</w>
      <h>30</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;&lt;&lt;&lt;-</panel_attributes>
    <additional_attributes>10.0;10.0;80.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>520</x>
      <y>260</y>
      <w>100</w>
      <h>30</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;&lt;&lt;&lt;-</panel_attributes>
    <additional_attributes>10.0;10.0;80.0;10.0</additional_attributes>
  </element>
</diagram>

Changes to rosea/src/images/config-classes.uxf.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58



59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151


152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

259
260

261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444

















































































































































445
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="13.3">
  <zoom_level>8</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>168</x>
      <y>152</y>
      <w>80</w>
      <h>48</h>
    </coordinates>
    <panel_attributes>style=autoresize

lt=.
Class
--
Domain {I,R2}
Name {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>552</x>
      <y>440</y>
      <w>80</w>
      <h>72</h>
    </coordinates>
    <panel_attributes>style=autoresize

Attribute
--
Domain {I,R3}
Class {I,R3}
Name {I}
Type</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>128</x>
      <y>176</y>
      <w>440</w>
      <h>332</h>
    </coordinates>
    <panel_attributes>lt=-
m1=  1
m2=1..*
R3
is characterized by&gt;
&lt;defines the properties of</panel_attributes>
    <additional_attributes>88;24;88;288;424;288</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>544</x>
      <y>136</y>
      <w>80</w>



      <h>64</h>
    </coordinates>
    <panel_attributes>style=autoresize

Identifier
--
Domain {I,R4}
Class {I,R4}
Number {I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>224</x>
      <y>128</y>
      <w>336</w>
      <h>84</h>
    </coordinates>
    <panel_attributes>lt=-
m1=  1
m2=1..*
R4
has unique instances determined by&gt;
&lt;uniquely identifies instances of</panel_attributes>
    <additional_attributes>24;40;320;40</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>536</x>
      <y>176</y>
      <w>104</w>
      <h>280</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*
m2=1..*
R5
consists of&gt;
&lt;is part of</panel_attributes>
    <additional_attributes>56;24;56;264</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>672</x>
      <y>200</y>
      <w>104</w>
      <h>72</h>

    </coordinates>
    <panel_attributes>style=autoresize

Identifying Attribute
--
Domain {I,R5}
Class {I,R5}
Attribute {I,R5}
Number {I,R5}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>568</x>
      <y>216</y>
      <w>120</w>
      <h>40</h>
    </coordinates>
    <panel_attributes>lt=&lt;-</panel_attributes>
    <additional_attributes>24;24;104;24</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Note</type>
    <coordinates>
      <x>408</x>
      <y>16</y>
      <w>208</w>
      <h>96</h>
    </coordinates>
    <panel_attributes>Note..
Identifiers are further constrained
to be minimal identifiers.
The set of attributes that form
an identifier may not be a subset
of those for a different identifier
of the same class.</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>544</x>
      <y>624</y>
      <w>88</w>


      <h>64</h>
    </coordinates>
    <panel_attributes>style=autoresize

Default Value
--
Domain {I,R6}
Class {I,R6}
Attribute {I,R6}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>808</x>
      <y>416</y>
      <w>152</w>
      <h>128</h>
    </coordinates>
    <panel_attributes>style=autoresize

Attribute Reference
--
Domain {I,R12,R13}
ReferringClass {I,R12,R13}
ReferringAttribute {I,R13}
ReferringRole {I,R12}
ReferencedClass {I,R12}
................................................................................
ReferencedAttribute {I,R12}
ReferenceRole {I,R12}
ReferencedIdNumber {I,R12}
Relationship {I,R13}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>984</x>
      <y>376</y>
      <w>132</w>
      <h>192</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..*
m2=1..*
R12
is referenced by&gt;
&lt;refers to</panel_attributes>
    <additional_attributes>72;24;72;176</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>1000</x>
      <y>552</y>
      <w>112</w>
      <h>72</h>
    </coordinates>
    <panel_attributes>style=autoresize

lt=.
Referring Class
--
Domain {I,R40}
Class {I,R40}
Relationship {I,R40}
Role {I,R40}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>1128</x>
      <y>200</y>
      <w>112</w>
      <h>72</h>
    </coordinates>
    <panel_attributes>style=autoresize

lt=.
Referenced Class
--
Domain {I,R40}
Class {I,R40}
Relationship {I,R40}
Role {I,R40}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>752</x>
      <y>200</y>
      <w>392</w>
      <h>84</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..*
m2=0..*
R11
identifies&gt;
&lt;is identified by</panel_attributes>
    <additional_attributes>24;40;376;40</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>992</x>
      <y>304</y>
      <w>120</w>
      <h>96</h>

    </coordinates>
    <panel_attributes>style=autoresize

Referenced Id Attribute
--
Domain {I,R11}
Class {I,R11}
Relationship {I,R11}
Role {I,R11}
Attribute {I,R11}
Number {I,R11}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>1032</x>
      <y>216</y>
      <w>40</w>
      <h>104</h>
    </coordinates>
    <panel_attributes>lt=&lt;-</panel_attributes>
    <additional_attributes>24;24;24;88</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>936</x>
      <y>440</y>
      <w>136</w>
      <h>40</h>
    </coordinates>
    <panel_attributes>lt=&lt;-</panel_attributes>
    <additional_attributes>120;24;24;24</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>608</x>
      <y>440</y>
      <w>216</w>
      <h>84</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
m2=0..*
R13
has a role of&gt;
&lt;is a role for</panel_attributes>
    <additional_attributes>24;40;200;40</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>280</x>
      <y>560</y>
      <w>96</w>
      <h>72</h>
    </coordinates>
    <panel_attributes>style=autoresize

Value Check
--
Domain {I,R17}
Class {I,R17}
Attribute {I,R17}
Expression</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>312</x>
      <y>480</y>
      <w>256</w>
      <h>96</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1

m2=0..*
R17
validates the value of &gt;
&lt; has its value validated by</panel_attributes>
    <additional_attributes>300.0;20.0;10.0;20.0;10.0;100.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>584</x>
      <y>504</y>
      <w>176</w>
      <h>136</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1

m2=0..*
has missing value supplied by v
R6
supplies missing value for ^</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;150.0</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>392</x>
      <y>752</y>
      <w>104</w>
      <h>72</h>
    </coordinates>
    <panel_attributes>style=autoresize

User Supplied Value
--
Domain {I,R18}
Class {I,R18}
Attribute {I,R18}
Value</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>528</x>
      <y>752</y>
      <w>120</w>
      <h>72</h>
    </coordinates>
    <panel_attributes>style=autoresize

System Supplied Value
--
Domain {I,R18}
Class {I,R18}
Attribute {I,R18}
StartValue</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>680</x>
      <y>752</y>
      <w>96</w>
      <h>72</h>
    </coordinates>
    <panel_attributes>style=autoresize

Generated Value
--
Domain {I,R18}
Class {I,R18}
Attribute {I,R18}
Cmd</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>432</x>
      <y>704</y>
      <w>304</w>
      <h>64</h>
    </coordinates>
    <panel_attributes>lt=-
</panel_attributes>
    <additional_attributes>10.0;60.0;10.0;20.0;360.0;20.0;360.0;60.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>576</x>
      <y>680</y>
      <w>40</w>
      <h>56</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R18</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>576</x>
      <y>712</y>
      <w>24</w>
      <h>56</h>
    </coordinates>
    <panel_attributes>lt=-
</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
  </element>

















































































































































</diagram>

|




|
|
|
|


>










|
|
|
|


>









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


<
<
<
>
>
>



>








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|
|

<
>


>









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


<
<
|
>
>



>










|
|
|
|


>







 







|

|
|
|
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

>












|
|
|
|


>










<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|
|

<
>


>











|

|
|
|
<
<
<
<
<
<
<
<
<
<
<
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

>











|
|





>

<
|
|
|




|
|
|
|



>

|
<
|
|




|
|

|


>











|
|
|
|


>











|
|
|
|


>











|
|










|
|










|
|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
















40
41



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
































57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74




























75
76


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
















122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
















153
154
155
156
157

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177











178
179



























180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="14.3.0">
  <zoom_level>8</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>112</x>
      <y>232</y>
      <w>72</w>
      <h>56</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
lt=.
Class
--
Domain {I,R2}
Name {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>496</x>
      <y>528</y>
      <w>72</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Attribute
--
Domain {I,R3}
Class {I,R3}
Name {I}
Type</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
















    <id>UMLClass</id>
    <coordinates>



      <x>488</x>
      <y>224</y>
      <w>72</w>
      <h>64</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Identifier
--
Domain {I,R4}
Class {I,R4}
Number {I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
































    <id>UMLClass</id>
    <coordinates>
      <x>616</x>
      <y>288</y>
      <w>104</w>

      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Identifying Attribute
--
Domain {I,R5}
Class {I,R5}
Attribute {I,R5}
Number {I,R5}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>




























    <id>UMLClass</id>
    <coordinates>


      <x>488</x>
      <y>712</y>
      <w>80</w>
      <h>64</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Default Value
--
Domain {I,R6}
Class {I,R6}
Attribute {I,R6}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>752</x>
      <y>504</y>
      <w>144</w>
      <h>136</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Attribute Reference
--
Domain {I,R12,R13}
ReferringClass {I,R12,R13}
ReferringAttribute {I,R13}
ReferringRole {I,R12}
ReferencedClass {I,R12}
................................................................................
ReferencedAttribute {I,R12}
ReferenceRole {I,R12}
ReferencedIdNumber {I,R12}
Relationship {I,R13}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>944</x>
      <y>640</y>
      <w>104</w>
      <h>80</h>
    </coordinates>
















    <panel_attributes>style=autoresize
bg=yellow
lt=.
Referring Class
--
Domain {I,R40}
Class {I,R40}
Relationship {I,R40}
Role {I,R40}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>1072</x>
      <y>288</y>
      <w>104</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
lt=.
Referenced Class
--
Domain {I,R40}
Class {I,R40}
Relationship {I,R40}
Role {I,R40}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
















    <id>UMLClass</id>
    <coordinates>
      <x>936</x>
      <y>392</y>
      <w>120</w>

      <h>104</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Referenced Id Attribute
--
Domain {I,R11}
Class {I,R11}
Relationship {I,R11}
Role {I,R11}
Attribute {I,R11}
Number {I,R11}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>224</x>
      <y>648</y>
      <w>88</w>











      <h>80</h>
    </coordinates>



























    <panel_attributes>style=autoresize
bg=yellow
Value Check
--
Domain {I,R17}
Class {I,R17}
Attribute {I,R17}
Expression</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>256</x>
      <y>568</y>
      <w>256</w>
      <h>96</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=validates the\nvalue of
m2=0..*

r2=has its value\nvalidated by
R17</panel_attributes>
    <additional_attributes>300.0;30.0;10.0;30.0;10.0;100.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>528</x>
      <y>600</y>
      <w>160</w>
      <h>128</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=supplies missing value for
m2=0..*
r2=has missing value supplied by

R6</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;140.0</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>336</x>
      <y>840</y>
      <w>104</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
User Supplied Value
--
Domain {I,R18}
Class {I,R18}
Attribute {I,R18}
Value</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>472</x>
      <y>840</y>
      <w>112</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
System Supplied Value
--
Domain {I,R18}
Class {I,R18}
Attribute {I,R18}
StartValue</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>624</x>
      <y>840</y>
      <w>88</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Generated Value
--
Domain {I,R18}
Class {I,R18}
Attribute {I,R18}
Cmd</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>376</x>
      <y>792</y>
      <w>304</w>
      <h>64</h>
    </coordinates>
    <panel_attributes>lt=-
</panel_attributes>
    <additional_attributes>10.0;60.0;10.0;20.0;360.0;20.0;360.0;60.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>520</x>
      <y>768</y>
      <w>40</w>
      <h>56</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R18</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>520</x>
      <y>800</y>
      <w>24</w>
      <h>56</h>
    </coordinates>
    <panel_attributes>lt=-
</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;50.0</additional_attributes>
  </element>
  <element>
    <id>UMLNote</id>
    <coordinates>
      <x>376</x>
      <y>104</y>
      <w>168</w>
      <h>88</h>
    </coordinates>
    <panel_attributes>style=autoresize
Identifiers are further constrained
to be minimal identifiers.
The set of attributes that form
an identifier may not be a subset
of those for a different identifier
of the same class.</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>520</x>
      <y>320</y>
      <w>112</w>
      <h>24</h>
    </coordinates>
    <panel_attributes>lt=.</panel_attributes>
    <additional_attributes>10.0;10.0;120.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>888</x>
      <y>536</y>
      <w>128</w>
      <h>24</h>
    </coordinates>
    <panel_attributes>lt=.</panel_attributes>
    <additional_attributes>10.0;10.0;140.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>984</x>
      <y>320</y>
      <w>24</w>
      <h>88</h>
    </coordinates>
    <panel_attributes>lt=.</panel_attributes>
    <additional_attributes>10.0;90.0;10.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>136</x>
      <y>280</y>
      <w>376</w>
      <h>296</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=defines the\nproperties of
m2=1..*
r2=is characterized by</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;340.0;450.0;340.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>560</x>
      <y>552</y>
      <w>208</w>
      <h>40</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=is a role for
m2=0..*
r2=has a role of
R13</panel_attributes>
    <additional_attributes>10.0;20.0;240.0;20.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>992</x>
      <y>488</y>
      <w>96</w>
      <h>168</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..*
r1=refers to
m2=1..*
r2=is referenced by
R12</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;190.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>520</x>
      <y>280</y>
      <w>72</w>
      <h>264</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*
r1=is part of
m2=1..*
r2=consists of
R5</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;310.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>176</x>
      <y>240</y>
      <w>328</w>
      <h>48</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=uniquely identifies\ninstances of
m2=1..*
r2=has unique instances\ndetermined by
R4</panel_attributes>
    <additional_attributes>10.0;30.0;390.0;30.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>712</x>
      <y>312</y>
      <w>376</w>
      <h>40</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..*
r1=is identified by
m2=0..*
r2=identifies
R4</panel_attributes>
    <additional_attributes>10.0;20.0;450.0;20.0</additional_attributes>
  </element>
</diagram>

Changes to rosea/src/images/config-domain.uxf.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
...
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
...
333
334
335
336
337
338
339

340
341
342
343
344
345
346
...
347
348
349
350
351
352
353

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370

371
372
373

374
375
376
377
378
379
380












381
382
383
384
385

386
387
388












389
390
391












































392
393

394
395
396
397
398
399
400
401

402
403
404
405

406
407
408
409

410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425
426
427
428


429












430
431






































432
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="13.3">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>60</x>
      <y>20</y>
      <w>70</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Domain
--
Name {I}
Location</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>430</x>
      <y>20</y>
      <w>110</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Domain Element
--
Domain {I,R1}
Element {I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>100</x>
      <y>0</y>
      <w>350</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
m2=0..*
R1
models entities using&gt;
&lt;is a entity of</panel_attributes>
    <additional_attributes>30;50;330;50</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>450</x>
      <y>190</y>
      <w>100</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Relationship
--
Domain {I,R2}
Name {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>620</x>
      <y>190</y>
      <w>100</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Class
--
Domain {I,R2}
Name {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>300</x>
      <y>130</y>
      <w>400</w>
      <h>80</h>
    </coordinates>
    <panel_attributes/>
    <additional_attributes>30;60;30;30;380;30;380;60</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>460</x>
      <y>50</y>
      <w>72</w>
      <h>130</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R2</panel_attributes>
    <additional_attributes>40;30;40;110</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>260</x>
      <y>190</y>
      <w>120</w>
      <h>90</h>
    </coordinates>
    <panel_attributes>style=autoresize

DomainOperation
--
Domain {I,R2}
Name {I,R2}
Parameters
Body</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>470</x>
      <y>130</y>
      <w>50</w>
      <h>80</h>
    </coordinates>
    <panel_attributes/>
    <additional_attributes>30;30;30;60</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>620</x>
      <y>380</y>
      <w>100</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize

Operation
--
Domain {I,R8}
Class {I,R8}
Name {I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>380</x>
      <y>560</y>
      <w>130</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize

Instance Operation
--
Domain {I,R7}
Class {I,R7}
Name {I,R7}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>840</x>
      <y>560</y>
      <w>110</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize

Class Operation
--
Domain {I,R7}
Class {I,R7}
Name {I,R7}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>240</x>
      <y>740</y>
      <w>160</w>
      <h>120</h>
    </coordinates>
    <panel_attributes>style=autoresize

User Instance Operation
--
Domain {I,R9}
Class {I,R9}
Name {I,R9}
Parameters
Body
</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>460</x>
      <y>740</y>
      <w>180</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize

System Instance Operation
--
Domain {I,R9}
Class {I,R9}
Name {I,R9,R16}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>920</x>
      <y>740</y>
      <w>140</w>
      <h>110</h>
    </coordinates>
    <panel_attributes>style=autoresize

User Class Operation
--
Domain {I,R10}
Class {I,R10}
Name {I,R10}
Parameters
Body</panel_attributes>
................................................................................
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>720</x>
      <y>740</y>
      <w>160</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize

System Class Operation
--
Domain {I,R10}
Class {I,R10}
Name {I,R10,R15}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>420</x>
      <y>500</y>
      <w>500</w>
      <h>80</h>
    </coordinates>
    <panel_attributes/>
    <additional_attributes>30;60;30;30;480;30;480;60</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>290</x>
      <y>680</y>
      <w>290</w>
      <h>80</h>
    </coordinates>
    <panel_attributes/>
    <additional_attributes>30;60;30;30;270;30;270;60</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>770</x>
      <y>680</y>
      <w>250</w>
      <h>80</h>
    </coordinates>
    <panel_attributes/>
    <additional_attributes>30;60;30;30;230;30;230;60</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>640</x>
      <y>430</y>
      <w>72</w>
      <h>120</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R7</panel_attributes>
    <additional_attributes>40;30;40;100</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>400</x>
      <y>610</y>
      <w>72</w>
      <h>120</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R9</panel_attributes>
    <additional_attributes>40;30;40;100</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>860</x>
      <y>610</y>
      <w>70</w>
      <h>120</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R10</panel_attributes>
    <additional_attributes>40;30;40;100</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>460</x>
      <y>960</y>
      <w>180</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize

Supplied Instance Operation
--
Name {I,R14}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
................................................................................
    <coordinates>
      <x>710</x>
      <y>960</y>
      <w>160</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize

Supplied Class Operation
--
Name {I,R14}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
................................................................................
    <coordinates>
      <x>610</x>
      <y>1100</y>
      <w>130</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize

Supplied Operation
--
Name {I}
Command
RequiresStateModel</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>530</x>
      <y>980</y>
      <w>300</w>
      <h>90</h>
    </coordinates>
    <panel_attributes/>
    <additional_attributes>30;30;30;70;280;70;280;30</additional_attributes>

  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>

    <coordinates>
      <x>650</x>
      <y>1020</y>
      <w>70</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-












R14</panel_attributes>
    <additional_attributes>40;80;40;30</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>

    <coordinates>
      <x>700</x>
      <y>790</y>












      <w>208</w>
      <h>190</h>
    </coordinates>












































    <panel_attributes>lt=-
m1=  1

m2=    0..*
R15
is defined by&gt;
&lt;gives the command for</panel_attributes>
    <additional_attributes>110;170;110;30</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>

    <coordinates>
      <x>450</x>
      <y>790</y>
      <w>208</w>

      <h>190</h>
    </coordinates>
    <panel_attributes>lt=-
m1=  1

m2=    0..*
R16
is defined by&gt;
&lt;gives the command for</panel_attributes>
    <additional_attributes>110;170;110;30</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>

    <coordinates>
      <x>600</x>
      <y>220</y>
      <w>156</w>
      <h>180</h>
    </coordinates>
    <panel_attributes>lt=-
m1=  1
m2=    0..n
R8
operates over&gt;


&lt;is the basis for</panel_attributes>












    <additional_attributes>80;30;80;160</additional_attributes>
  </element>






































</diagram>

|







|


>









|


|


>







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




|
|


>











|
|


>







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





|


>









<
<
<
<
<
<
<
<
<
<
<




|



>












|



>












|



>












|
|


>






<
|







|



>












|



>







 







|



>








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<








>







 







>







 







>








|

|
|
|
|

|
|
>


<
>

|
|
|



>
>
>
>
>
>
>
>
>
>
>
>
|
|


<
>

|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
>
|
<
|
|
|


<
>

|
|
<
>
|


|
>
|
<
|
|
|


<
>

|
|
|
|


|
<
<
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
















37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68























69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86











87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209





































































210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

360
361
362
363
364

365
366
367
368

369
370
371
372
373
374
375

376
377
378
379
380

381
382
383
384
385
386
387
388
389


390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="14.3.0">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>60</x>
      <y>20</y>
      <w>70</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Domain
--
Name {I}
Location</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>440</x>
      <y>20</y>
      <w>110</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Domain Element
--
Domain {I,R1}
Element {I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
















    <id>UMLClass</id>
    <coordinates>
      <x>450</x>
      <y>190</y>
      <w>90</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Relationship
--
Domain {I,R2}
Name {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>620</x>
      <y>190</y>
      <w>90</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Class
--
Domain {I,R2}
Name {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>























    <id>UMLClass</id>
    <coordinates>
      <x>260</x>
      <y>190</y>
      <w>120</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
DomainOperation
--
Domain {I,R2}
Name {I,R2}
Parameters
Body</panel_attributes>
    <additional_attributes/>
  </element>
  <element>











    <id>UMLClass</id>
    <coordinates>
      <x>620</x>
      <y>380</y>
      <w>90</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Operation
--
Domain {I,R8}
Class {I,R8}
Name {I}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>380</x>
      <y>560</y>
      <w>120</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Instance Operation
--
Domain {I,R7}
Class {I,R7}
Name {I,R7}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>840</x>
      <y>560</y>
      <w>100</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Class Operation
--
Domain {I,R7}
Class {I,R7}
Name {I,R7}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>240</x>
      <y>740</y>
      <w>150</w>
      <h>110</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
User Instance Operation
--
Domain {I,R9}
Class {I,R9}
Name {I,R9}
Parameters

Body</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>460</x>
      <y>740</y>
      <w>170</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
System Instance Operation
--
Domain {I,R9}
Class {I,R9}
Name {I,R9,R16}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>920</x>
      <y>740</y>
      <w>130</w>
      <h>110</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
User Class Operation
--
Domain {I,R10}
Class {I,R10}
Name {I,R10}
Parameters
Body</panel_attributes>
................................................................................
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>720</x>
      <y>740</y>
      <w>150</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
System Class Operation
--
Domain {I,R10}
Class {I,R10}
Name {I,R10,R15}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>





































































    <id>UMLClass</id>
    <coordinates>
      <x>460</x>
      <y>960</y>
      <w>180</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Supplied Instance Operation
--
Name {I,R14}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
................................................................................
    <coordinates>
      <x>710</x>
      <y>960</y>
      <w>160</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Supplied Class Operation
--
Name {I,R14}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
................................................................................
    <coordinates>
      <x>610</x>
      <y>1100</y>
      <w>130</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Supplied Operation
--
Name {I}
Command
RequiresStateModel</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>670</x>
      <y>1040</y>
      <w>50</w>
      <h>80</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R14</panel_attributes>
    <additional_attributes>10.0;60.0;10.0;10.0</additional_attributes>
  </element>
  <element>

    <id>Relation</id>
    <coordinates>
      <x>890</x>
      <y>630</y>
      <w>50</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R10</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;80.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>420</x>
      <y>630</y>
      <w>40</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R9</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;80.0</additional_attributes>
  </element>
  <element>

    <id>Relation</id>
    <coordinates>
      <x>660</x>
      <y>450</y>
      <w>40</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R7</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;80.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>300</x>
      <y>700</y>
      <w>270</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-</panel_attributes>
    <additional_attributes>10.0;40.0;10.0;10.0;250.0;10.0;250.0;40.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>780</x>
      <y>700</y>
      <w>220</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-</panel_attributes>
    <additional_attributes>10.0;40.0;10.0;10.0;200.0;10.0;200.0;40.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>550</x>
      <y>1000</y>
      <w>270</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>lt=-</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;50.0;250.0;50.0;250.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>430</x>
      <y>520</y>
      <w>470</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-</panel_attributes>
    <additional_attributes>10.0;40.0;10.0;10.0;450.0;10.0;450.0;40.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>540</x>
      <y>810</y>
      <w>100</w>
      <h>170</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*
r1=gives the\ncommand for
m2=1

r2=is defined by
R16</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;150.0</additional_attributes>
  </element>
  <element>

    <id>Relation</id>
    <coordinates>
      <x>780</x>
      <y>810</y>

      <w>100</w>
      <h>170</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*
r1=gives the\ncommand for
m2=1

r2=is defined by
R15</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;150.0</additional_attributes>
  </element>
  <element>

    <id>Relation</id>
    <coordinates>
      <x>650</x>
      <y>250</y>
      <w>110</w>
      <h>150</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*


r1=operates over
m2=1
r2=is the basis for
R8</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;130.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>480</x>
      <y>80</y>
      <w>40</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=&lt;&lt;-
R2</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;80.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>310</x>
      <y>150</y>
      <w>370</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-</panel_attributes>
    <additional_attributes>10.0;40.0;10.0;10.0;350.0;10.0;350.0;40.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>480</x>
      <y>150</y>
      <w>30</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;40.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>120</x>
      <y>30</y>
      <w>340</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*
r1=models entities\nusing
m2=1
r2=is an entity of
R1</panel_attributes>
    <additional_attributes>320.0;30.0;10.0;30.0</additional_attributes>
  </element>
</diagram>

Changes to rosea/src/images/wmc-class-diagram.uxf.

1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131

132
133
134
135
136














































137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

185
186
187

188
189
190
191
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="13.3">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>410</x>
      <y>190</y>
      <w>150</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Washing Machine (WM)
--
Machine ID {I}
Cycle Type {R4}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>430</x>
      <y>370</y>
      <w>120</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize

Clothes Tub (CT)
--
Machine ID {I,R1}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>420</x>
      <y>530</y>
      <w>120</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Motor (MTR)
--
Motor ID {I}
Machine ID {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>820</x>
      <y>140</y>
      <w>140</w>
      <h>150</h>
    </coordinates>
    <panel_attributes>style=autoresize

Washing Cycle (WC)
--
Cycle Type {I}
Wash Water Temp
Rinse Water Temp
Wash Duration
Rinse Duration
Spin Duration
Agitation Speed
Spin Speed</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>530</x>
      <y>170</y>
      <w>310</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*
m2=1
operates according to&gt;
R4
&lt;prescribes the operation of</panel_attributes>
    <additional_attributes>30;50;290;50</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>80</x>
      <y>360</y>
      <w>120</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize

Water Valve (WV)
--
Valve ID {I}
Machine ID {I,R3}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>
    <coordinates>
      <x>170</x>
      <y>350</y>
      <w>280</w>
      <h>100</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..*
m2=1
controls water flow for&gt;
R3
&lt;controls wash water via</panel_attributes>
    <additional_attributes>30;50;260;50</additional_attributes>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>810</x>
      <y>370</y>
      <w>170</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize

Water Level Sensor (WLS)
--
Machine ID {I,R5}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <type>com.baselet.element.old.element.Relation</type>

    <coordinates>
      <x>520</x>
      <y>350</y>
      <w>310</w>
      <h>100</h>














































    </coordinates>
    <panel_attributes>lt=-
m1=1

m2=1
monitors water level with&gt;
R5
&lt;is the water level monitor for</panel_attributes>
    <additional_attributes>30;50;290;50</additional_attributes>
  </element>
  <element>
    <type>com.baselet.element.old.element.Note</type>
    <coordinates>
      <x>720</x>
      <y>520</y>
      <w>230</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>Washing Machine Control Domain
Class Diagram
Version 1.0.5</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>470</x>
      <y>410</y>
      <w>100</w>
      <h>140</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1

m2=1..*
is used by ^
R2
uses v</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;120.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>470</x>
      <y>240</y>
      <w>150</w>
      <h>150</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1

m2=1
holds clothes for ^
R1

washes clothes in v</panel_attributes>
    <additional_attributes>10.0;10.0;10.0;130.0</additional_attributes>
  </element>
</diagram>

|







|


>











|



>










|
|


>











|
|


>













<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




|
|


>







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




|



>






<
>

|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>

|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|






|



|
>
|
|
<
|
|




|
|
|
|


|
>

<
<
>
|
|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
















74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
















90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162














163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193


194
195
196
197
198
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="14.3.0">
  <zoom_level>10</zoom_level>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>410</x>
      <y>190</y>
      <w>150</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Washing Machine (WM)
--
Machine ID {I}
Cycle Type {R4}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>430</x>
      <y>370</y>
      <w>110</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Clothes Tub (CT)
--
Machine ID {I,R1}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>420</x>
      <y>530</y>
      <w>110</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Motor (MTR)
--
Motor ID {I}
Machine ID {I,R2}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>UMLClass</id>
    <coordinates>
      <x>820</x>
      <y>140</y>
      <w>130</w>
      <h>160</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Washing Cycle (WC)
--
Cycle Type {I}
Wash Water Temp
Rinse Water Temp
Wash Duration
Rinse Duration
Spin Duration
Agitation Speed
Spin Speed</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
















    <id>UMLClass</id>
    <coordinates>
      <x>80</x>
      <y>360</y>
      <w>110</w>
      <h>70</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Water Valve (WV)
--
Valve ID {I}
Machine ID {I,R3}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
















    <id>UMLClass</id>
    <coordinates>
      <x>810</x>
      <y>370</y>
      <w>160</w>
      <h>50</h>
    </coordinates>
    <panel_attributes>style=autoresize
bg=yellow
Water Level Sensor (WLS)
--
Machine ID {I,R5}</panel_attributes>
    <additional_attributes/>
  </element>
  <element>

    <id>UMLNote</id>
    <coordinates>
      <x>720</x>
      <y>540</y>
      <w>210</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>style=autoresize
Washing Machine Control Domain
Class Diagram
Version 1.0.6</panel_attributes>
    <additional_attributes/>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>550</x>
      <y>200</y>
      <w>290</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-
m1=0..*
r1=prescribes the\noperation of
r2=operates\naccording to
m2=1
R4</panel_attributes>
    <additional_attributes>10.0;30.0;270.0;30.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>470</x>
      <y>250</y>
      <w>130</w>
      <h>140</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=washes clothes in
m2=1
r2=holds clothes for
R1</panel_attributes>
    <additional_attributes>10.0;120.0;10.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>530</x>
      <y>370</y>
      <w>300</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1
r1=is the water\nlevel monitor for
m2=1
r2=monitors water\nlevel with














R5</panel_attributes>
    <additional_attributes>10.0;30.0;280.0;30.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>470</x>
      <y>410</y>
      <w>80</w>
      <h>140</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..*
r1=uses
m2=1
r2=is used by

R2</panel_attributes>
    <additional_attributes>10.0;120.0;10.0;10.0</additional_attributes>
  </element>
  <element>
    <id>Relation</id>
    <coordinates>
      <x>180</x>
      <y>370</y>
      <w>270</w>
      <h>60</h>
    </coordinates>
    <panel_attributes>lt=-
m1=1..*
r1=controls wash\nwater via
m2=1


r2=controls water\nflow for
R3</panel_attributes>
    <additional_attributes>10.0;30.0;250.0;30.0</additional_attributes>
  </element>
</diagram>

Changes to rosea/src/rosea-docinfo.xml.

288
289
290
291
292
293
294
















295
        that the events cascade down a hierarchy disguises the origin
        of the event.
        If the original source of the event was outside of a state machine
        context, it would appear that the event originated from within a
        state machine and fail to start the required data transaction.
    </revremark>
  </revision>
















</revhistory>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
        that the events cascade down a hierarchy disguises the origin
        of the event.
        If the original source of the event was outside of a state machine
        context, it would appear that the event originated from within a
        state machine and fail to start the required data transaction.
    </revremark>
  </revision>
  <revision>
    <revnumber>1.10</revnumber>
    <date>May 12, 2020</date>
    <authorinitials>GAM</authorinitials>
    <revremark>
        Reworked the way polymorphic events are dispatched.
        Previously, the mapping of polymorphic events to ordinary events
        happened before being placed on the event queue.
        Now the mapping happens during event dispatch and transitioning.
        This give a clearer picture of what is happening.
        Also, improved the formatting of trace messages, particularly
        the parameters to events and the identifiers of the instances
        involved in a transition.
        Added a relationship command to delete multi-assigner instances.
    </revremark>
  </revision>
</revhistory>

Changes to rosea/src/rosea.aweb.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
....
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
....
4248
4249
4250
4251
4252
4253
4254
4255
4256

4257
4258
4259
4260
4261
4262
4263
....
4266
4267
4268
4269
4270
4271
4272



4273
4274
4275
4276
4277
4278
4279
....
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
....
4332
4333
4334
4335
4336
4337
4338





















4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350



4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361



4362
4363
4364
4365
4366
4367
4368
....
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386























































4387
4388
4389
4390
4391
4392
4393
....
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
....
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
....
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
....
6724
6725
6726
6727
6728
6729
6730
6731
6732




6733
6734
6735






















6736
6737
6738
6739
6740
6741
6742
....
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
....
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
....
6858
6859
6860
6861
6862
6863
6864

6865
6866
6867

6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895

6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980

6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032

7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
....
7573
7574
7575
7576
7577
7578
7579






















7580
































































































































































































































































































7581
7582
7583
7584
7585
7586
7587
....
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658


7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703

7704
7705
7706
7707
7708

7709
7710


7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
....
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765







7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794

7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814

7815
7816
7817
7818
7819

7820
7821
7822


7823
7824
7825

7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846

7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873







7874
7875
7876
7877
7878
7879
7880
.....
16033
16034
16035
16036
16037
16038
16039


16040
16041
16042
16043
16044
16045
16046
.....
17614
17615
17616
17617
17618
17619
17620


17621
17622


17623
17624
17625
17626
17627
17628
17629
.....
17815
17816
17817
17818
17819
17820
17821



















































17822
17823
17824
17825
17826
17827
17828
.....
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304










21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346



















21347
21348
21349
21350
21351
21352
21353
.....
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
.....
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
.....
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
.....
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
relationships and supports set-at-a-time operations on domain class instances.
Processing is transactional and constraint violations result in
rolling back the changes to a known good state.

== Introduction [[introduction,Introduction]]

This document is about a Tcl package named, +rosea+.
+Rosea+ is a data and execution domain that is intended as the
target for translating
http://en.wikipedia.com/wiki/Executable_UML[Executable UML]
(XUML) models using Tcl as the implementation language.

//////////
----
<<manual description>>=
................................................................................
of documents like this while retaining the ability to produce the
source code files needed by the Tcl interpreter.

=== How To Read This Document

This document contains a lot of material.
It contains the complete source code, test cases and a runnable example.
Reading the document from beginning to end in order would be an
exceptional undertaking.
Skipping around is encouraged.
For example,
you may wish to skip over the test cases although they do provide
interesting examples in the small of how `rosea` constructs are used.

For those readers wishing a quick look at what `rosea` provides,
................................................................................
    # the new attributes to have the old attribute names.
    set newvalues [relation update [rosea::InstCmds::deRef $ref Temp Volume]\
            newtuple {1} {
        tuple update $newtuple\
            Temp [expr {[tuple extract $newtuple Temp] + 10}]\
            Volume [expr {[tuple extract $newtuple Volume] * 2.0}]
    }]
    log::debug [relformat $newvalues newvalues]
    set ref [rosea::ClassCmds::update [namespace current]::foo::c1 $newvalues]
    # Extract one of the instances and make sure the attribute values
    # were properly updated.
    pipe {
        rosea::InstCmds::deRef $ref |
        relation restrictwith ~ {$Temp < 200} |
        relation extract ~ Temp Volume
................................................................................

+event+::
    The name of an event to be signaled to the assigner associated
    with _relationship_.
+idvalues+::
    A dictionary keyed by attribute names whose values identify
    an instance of the multiple assigner associated with _relationship_.
    The attribute names must be the same as those given when the
    multiple assigner was defined.

+paramN+::
    Optional event parameters are passed as additional arguments.
*****

///////
----
<<manual architecture relationship commands>>=
................................................................................

For associations that have a multiple assigner state model,
the [cmd signal] command is used to signal [arg event] to the assigner
state machine identified by [arg idvalues].
The [arg idvalues] argument is a dictionary whose keys are the attributes
names of the assigner identifier and whose corresponding values
match those of some assigner for [arg relationship].



Any optional event parameters are given by the [arg paramN] arguments.
----
///////

[float]
===== Implementation

................................................................................
<<relationship commands>>=
proc signalMultiAssigner {rname idvalues event args} {
    SplitRelvarName $rname domain relationship
    set assignrelvar ${domain}::${relationship}__STATEINST
    if {![relvar exists $assignrelvar]} {
        tailcall DeclError NO_ASSIGNER $rname
    }
    set idattrs [lindex [relvar identifiers $assignrelvar] 0]
    # We will insist that the idvalues contain the necessary identifying
    # attributes.
    if {![struct::set equal [dict keys $idvalues] $idattrs]} {
        tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
    }
    set assigninsts [relvar set $assignrelvar]
    set assignrefs [relation project $assigninsts {*}$idattrs]
................................................................................
(((error code,UNKNOWN_ASSIGNER)))
[source,tcl]
----
<<error code formats>>=
NO_IDENTIFIER       {bad identifying attributes, expected "%s", got "%s"}
UNKNOWN_ASSIGNER    {unknown assigner instance, "%s", for relationship, "%s"}
----






















==== Creating a Multi-Assigner

Since associations can have multi-assigners,
we must provide a means to create instances of the assigners.

*****
_relationship_ +create+ _?attr1 value1 attr2 value2 ...?_

+attrN valueN+::
    Attribute name / value pairs that form the identifier for an
    instance of the multi-assigner associated with _relationship_.



*****

///////
----
<<manual architecture relationship commands>>=
[call [arg relationship] [cmd create]\
    [opt [arg "attr1 value1 attr2 value2 ..."]]]

For associations that have a multiple assigner state model,
the [cmd create] command creates an instance of the assigner
that is identified by the [arg attrN] / [arg valueN] names and values.



----
///////

[float]
===== Implementation
(((rosea,RelCmds,createMultiAssigner)))
[source,tcl]
................................................................................
        tailcall DeclError ARG_FORMAT $args
    }
    SplitRelvarName $rname domain relationship
    set assignrelvar ${domain}::${relationship}__STATEINST
    if {![relvar exists $assignrelvar]} {
        tailcall DeclError NO_ASSIGNER $rname
    }
    set idattrs [lindex [relvar identifiers $assignrelvar] 0]
    if {![struct::set equal [dict keys $args] $idattrs]} {
        tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
    }
    CreateInInitialState $domain $relationship $args
}
----
























































=== Instance Commands

In this section we discuss the +rosea+ commands that operate on instance
references.
These commands form the foundation of operations that state activities
use to access the underlying execution architecture.
................................................................................
===== Implementation [[signal-command]]
(((rosea,InstCmds,signal)))
[source,tcl]
----
<<instance commands>>=
proc signal {dstset event args} {
    set srcref [SelfInstRef]
    if {![::rosea::Dispatch::MapPolymorphicEvent ::rosea::Dispatch::SignalEvent\
            $srcref $dstset $event $args]} {
        ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args
    }
    return
}
----

==== Signaling Delayed Events

The XUML modeling semantics supply the concept of a delayed event
................................................................................
----
<<instance commands>>=
proc delaysignal {time dstset event args} {
    if {!([string is integer -strict $time] && $time >= 0)} {
        tailcall DeclError INVALID_TIME $time
    }
    set srcref [SelfInstRef]
    if {![::rosea::Dispatch::MapPolymorphicEvent\
            [list ::rosea::Dispatch::SignalDelayedEvent $time]\
            $srcref $dstset $event $args]} {
        ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args
    }
    return
}
----

(((error code,INVALID_TIME)))
[source,tcl]
----
................................................................................
----
<<dispatch commands>>=
proc SignalEvent {srcref dstset event arglist} {
    <<SignalEvent: validate event>>

    set callback [namespace code DispatchEvent]
    set eventInfo [dict create\
        type ordinary\
        src $srcref\
        event $event\
        params $arglist\
    ]
    if {[isRefEqual $srcref [nilInstRef]]} {
        variable toc_queue
        forAllRefs dstref $dstset {
................................................................................
sure that the class instances accept the event.

[source,tcl]
----
<<SignalEvent: validate event>>=
lassign $dstset relvar insts
SplitRelvarName $relvar domain class
if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
        Class $class Event $event]]} {




    tailcall DeclError UNKNOWN_EVENT $event $class
}
----























Finding the proper place for a self directed event requires inserting
the event at the front of the event queue.
However,
there is a minor complication.
If there is already a self directed event on the event queue,
we don't want to place the new one directly on the front.
................................................................................
for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
    set cmpevent [lindex $event_queue $eqindex]
    if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
        break
    }
}
set event_queue [linsert [K $event_queue [set event_queue {}]]\
        $eqindex $eventInfo] ; # <1>
----
<1> This code uses the K combinator trick. This is an optimization
that exploits a particular design characteristic of Tcl.
The net effect is to prevent the sharing of the +event_queue+ value
and save the copy that would otherwise have to be made when the list value is
modified by the list insertion command.
See http://wiki.tcl.tk/1923[the Tcl wiki] for a complete discussion.
................................................................................

(((rosea,Dispatch,DispatchEvent)))
[source,tcl]
----
<<dispatch commands>>=
proc DispatchEvent {} {
    <<DispatchEvent: select event>>
    <<DispatchEvent: handle creation events>>
    <<DispatchEvent: get current state>>
    <<DispatchEvent: determine new state>>
    <<DispatchEvent: execute state action>>
    return
}
----

Events are removed from the +event_queue+ list first.
This queue holds the events generated on the currently running
thread of control and it is always our goal to run the current thread
................................................................................

[source,tcl]
----
<<DispatchEvent: select event>>=
variable event_queue
variable toc_queue


if {[llength $event_queue] != 0} {
    set eventInfo [lindex $event_queue 0]
    set event_queue [lrange [K $event_queue [set event_queue {}]] 1 end] ; # <1>

} elseif {[llength $toc_queue] != 0} {
    set eventInfo [lindex $toc_queue 0]
    set toc_queue [lrange [K $toc_queue [set toc_queue {}]] 1 end]
    relvar transaction begin ; # <2>
} else {
    return
}
----
<1> Note the use of the `K` trick here and below.
<2> Each time we start a new thread of control, we begin a transaction.

The event dictionary has a `type` key that determines if the event
is just an ordinary event or is a creation event.
For a creation event we must actually create an class instance before we
dispatch the event to it.

[source,tcl]
----
<<DispatchEvent: handle creation events>>=
if {[dict get $eventInfo type] eq "creation"} {
    try {
        set dstref [::rosea::ClassCmds::createin\
                [dict get $eventInfo dstClass] @\
                {*}[dict get $eventInfo dstAttrs]] ; # <1>
    } on error {result} {
        catch {
            if {[llength $event_queue] == 0} {
                relvar transaction end

            }
        }
        tailcall DeclError ASYNC_CREATION_FAILED [dict get $eventInfo dstClass]\
            [dict get $eventInfo dstAttrs] $result
    }
    dict set eventInfo dst $dstref ; # <2>
    ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
        [dict get $eventInfo event] $dstref [dict get $eventInfo params]
}
----
<1> Here is where the new instance is created in the pseudo-initial, `@`,
state.
<2> Note that we are just setting the `dst` dictionary key so that now
all the members are in place to look just like an ordinary event.
The rest of the code simply ignores the dictionary members that it is not
concerned with.

(((error code,ASYNC_CREATION_FAILED)))
[source,tcl]
----
<<error code formats>>=
ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
    with attributes, "%s", failed: %s}
----

Each class that has a state model also has an additional relvar that is used to
hold the value of the current state for the instances of the class.
That relvar is named, `<class>__STATEINST`, where +<class>+ is replaced
by the class name.
The heading of the current state relvar consists of the attributes of the first
identifier of the class plus an attribute named, `__State`, which holds the
current state.
So obtaining the current state means that we +semijoin+ the instance reference
to the value of the `<class>__STATEINST` relvar.

[source,tcl]
----
<<DispatchEvent: get current state>>=
set dstref [dict get $eventInfo dst]
lassign $dstref relvar ref
SplitRelvarName $relvar domain class

set instrelvar ${domain}::${class}__STATEINST
set state [relation semijoin $ref [relvar set $instrelvar]]
if {[relation isempty $state]} {
    tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
}
set currstate [relation extract $state __State]
----

(((error code,EVENT_IN_FLIGHT)))
[source,tcl]
----
<<error code formats>>=
EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
----

It is possible for an event to be signaled to an instance that
has been deleted before the event is actually delivered.
This is known as the _event in flight_ error and is one of the few
run-time errors that is diagnosed by +rosea+.
This is considered an analysis error detected at run time.
Correct analysis models must insure that no events are in flight to
an instance before deleting it.
In general, deletion protocols within a domain model can be quite
complicated as the model is responsible for all the compensatory
operations needed to make the instance population consistent with
the relationship constraints.

To obtain the new state,
we query the *Transition* relvar that was shown above.
When the *Transition* relvar value is set up,
it is the Cartesian product of the states and events for the class.
So it can be considered the complete transition matrix and the
query below will always find a tuple with the new state.

[source,tcl]
----
<<dispatch data>>=
pipe {
    relvar restrictone ${domain}::__Arch_Transition\
        Class $class State $currstate Event $event |
    relation extract ~ NewState
} transitionQuery
----


Combining the event name and the current state we perform the
query to find the new state.

[source,tcl]
----
<<DispatchEvent: determine new state>>=
set event [dict get $eventInfo event]
variable transitionQuery
set newState [eval $transitionQuery]

::rosea::Trace::TraceTransition [dict get $eventInfo src]\
    $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
----
<1> Note that we trace the transition _before_ we take any action on it.
It is a simpler control path.
We will have much more to say about state machine tracing.

Finally, we get to the heart of the event dispatch code.
There are three cases to consider:

* The event causes a CH (Can't Happen) transition and that is considered
a serious error.
* The event causes an IG (Ignore) transition and we do nothing.
* We transition to the new state and execute the state activity.

In the end,
we must decide if the thread of control has ended and if so then
the transaction is also ended.

[source,tcl]
----
<<DispatchEvent: execute state action>>=
try {
    if {$newState eq "CH"} {
        <<DispatchEvent: handle transition error>>
    } elseif {$newState ne "IG"} {
        <<DispatchEvent: transition to new state>>
    }
} on error {result opts} {
    catch {
        if {[llength $event_queue] == 0} {
            relvar transaction end
        }
    } ; # <1>
    return -options $opts $result
}

if {[llength $event_queue] == 0} {
    relvar transaction end
}
----

<1> If there is an error executing a state activity, we may still need
to end the thread of control (and hence the `relvar transaction`).
In general,
the transaction will fail since the state activity did not complete.
We don't want the transaction failure to throw another error
which would mask the reason the state activity failed in the first place.

The *CH* (can't happen) transition deserves special consideration.
You can think of a *CH* transition as an analogy to the +assert+ macro
in ordinary ``C'' code.
Triggering a *CH* transition is a serious error that should never
happen in production code.
If it does, usually there is no clear way to proceed and how to
handle such situations is very application dependent.
Often the only recourse is to exit or reset to some saved checkpoint.
However during development and testing,
the *CH* transition can uncover a wealth of analysis errors and
misunderstandings.
Consequently,
it is very useful to have some control over what happens should
a *CH* transition occur.
We delegate the error handling for *CH* transitions to
the +TransitionError+ footnote:[The fully qualified name is
+::rosea::Dispatch::TransitionError+]
procedure.

[source,tcl]
----
<<DispatchEvent: handle transition error>>=
TransitionError [dict get $eventInfo src] $event $dstref $currstate
----

We supply a default implementation of +TransitionError+ which simply
throws an error.
Application can redefine this procedure to gain control over the error
handling.

(((rosea,Dispatch,TransitionError)))
[source,tcl]
----
<<dispatch commands>>=
proc TransitionError {src event dst currstate} {
    tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
}
----

(((error code,CANT_HAPPEN_EVENT)))
[source,tcl]
----
<<error code formats>>=
CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}
----

When transitioning to the new state,
we update the value of the current state of the instance to be the newly
determined state value.
The identifiers of the `<class>__STATEINST` relvar are just the
attributes of the instance reference for the instance.
Note that the current state is updated to the new state _before_ the
state activity is executed.
Some architectures wait until after the state activity is executed.
Which is better or correct is hard to determine and in practice does
not matter since state activities are strongly discouraged from having knowledge
of their own state.

[source,tcl]
----
<<DispatchEvent: transition to new state>>=
set idattrs [tuple get [relation tuple $ref]]
relvar updateone $instrelvar is $idattrs {
    tuple update $is __State $newState
}
----

At last we execute the state activity.
State activities are ordinary Tcl procedures named the same as the state and
placed in the `__Activity` namespace that is a child of the
namespace associated to the class.
The instance reference of the event target is passed as the
value of the +self+ parameter and any other parameters carried along
with the event are also given to the activity procedure.
Here is the explicit reason that the parameters carried with the
event must match the arguments that the state activity expects
or Tcl will throw an error.

[source,tcl]
----
<<DispatchEvent: transition to new state>>=
try {
    ${relvar}::__Activity::$newState $dstref\
            {*}[dict get $eventInfo params] ; # <1>
} on error {result opts} {
    return -options $opts $result
} finally {
    set term [relvar restrictone ${domain}::__Arch_TerminalState\
            Class $class State $newState]
    if {[relation isnotempty $term]} {
        relvar deleteone $relvar {*}$idattrs
        relvar deleteone $instrelvar {*}$idattrs
    }
}
----
<1> This command invocation has a lot of variable substitution.
Each state activity is actually a procedure.
Those procedures are placed in the `__Activity` child namespace
of the class so that there is no naming conflict.
The value of +dstref+ becomes +self+ in the state activity.
Finally, we expand out the list of event parameters to be
any additional arguments to the state activity procedure.

After executing the state activity,
we look to see if new state is a terminal state.
If the state was marked as terminal when the state model was defined,
the the system automatically deletes the class instance.
Of course, we must also delete the tuple that records the current state.

[float]
===== Testing

[source,tcl]
----
<<dispatch command tests>>=
test DispatchEvent-1.0 {
................................................................................
    set src [rosea::Helpers::nilInstRef]
    set remain [rosea::InstCmds::delayremaining $src $ref e1]
    rosea::InstCmds::canceldelayed $src $ref e1
    expr {$remain <= 100 && $remain >= 95}
} -result {1}
----























==== Dispatching Polymorphic Events

































































































































































































































































































We now consider the job of dispatching polymorphic events.
Polymorphic events are events directed at the superclass of a generalization
that are mapped at run time to an event in the subclass to which the
superclass instance is currently related.
This is the only type of polymorphism that XUML execution rules
supportfootnote:[In particular note there are no polymorphic operations
................................................................................
the subclass instances form a disjoint union.].
In this case,
the state model must respond to the union of the events
from all the generalization for which the class is a subclass.
Note that some care might have to be taken to insure that the polymorphic
event names of the multiple hierarchies are distinct.

==== MapPolymorphicEvent

The +MapPolymorphicEvent+ procedure is called by the instance commands
that deal with signaling events to determine if the event
is indeed polymorphic.
It is,
then the the event is recursively signaled to the currently related
subclass instance.
Otherwise,
+MapPolymorphicEvent+ returns an indication that the event is not
polymorphic and the instance signaling commands can then perform
the operation of signaling an ordinary event.
Ultimately,
execution sequencing is only accomplished by delivering ordinary events.
Event polymorphism is a convenience and optimization that prevents
state activities from performing event mapping themselves.



[float]
===== Implementation

One consideration for the implementation of the +MapPolymorphicEvent+
procedure is that we want to use this procedure to handle both
immediate and delayed events.
The function of mapping the event is the same.
The only difference is how the mapped event is handled.
So we will pass in a forwarding command prefix as an argument.
Once the work is accomplished to determine which subclass instance
is to be signaled,
the forwarding command will determine if it is a delayed or immediate event.

(((rosea,Dispatch,MapPolymorphicEvent)))
[source,tcl]
----
<<dispatch commands>>=
proc MapPolymorphicEvent {frwdcmd srcref dstrefs event arglist} {
    <<MapPolymorphicEvent: check if event is polymorphic>>
    <<MapPolymorphicEvent: find subclasses>>
    <<MapPolymorphicEvent: map event>>

    return true
}
----

We use the *PolymorphicEvent* relvar to determine if is the event
is polymorphic.
If the event is not found here,
then we just return and the event will be signaled as an ordinary event.

[source,tcl]
----
<<arch relvar definitions>>=
ral relvar create __Arch_PolymorphicEvent {
    Class           string
    Event           string
} {Class Event}
----

[source,tcl]
----
<<MapPolymorphicEvent: check if event is polymorphic>>=
lassign $dstrefs dstrelvar dstinsts

SplitRelvarName $dstrelvar domain dstclass
set polyevent [relvar restrictone ${domain}::__Arch_PolymorphicEvent\
    Class $dstclass Event $event]
if {[relation isempty $polyevent]} {
    return false

}
----



If we indeed have a polymorphic event,
we need to determine the generalization hierarchies that are affected.
We do that with a query.

[source,tcl]
----
<<MapPolymorphicEvent: find subclasses>>=
variable polymapQuery
set partitions [eval $polymapQuery]
----

[[polymapQuery,polymorphic event query]]
The essential query for dispatching a polymorphic event is to find the set of
hierarchies originating at the source relvar.

[source,tcl]
----
<<dispatch data>>=
................................................................................
exactly one subclass from among all the subclasses in the generalization and
it is to that subclass instance that the event will be forwarded.

The heading of the result of this query will be:

[width="50%",options="header",title="Heading of Polymorphic Event Mapping Query Result"]
|=========================
    |Name       |SrcClass   2+^h|DstLinks
    |string     |string     2+^|Relation
1.2+|       1.2+|             h|DstClass     h|Attrs
                               |string        |list
|=========================

Note that the *DstLinks* attribute is relation valued.footnote:[That is what
the +group+ operation does.]








The polymorphic event mapping operation consists of three nested iterations.
The outside loop iterates over the target superclass instances
since we may be signaling several instances in the same call.
The next iteration is over all the hierarchies that originate from
the superclass.
Typically, this is only one, but it can be several for a compound
generalization.
Finally, we iterate over all the subclass links.

[source,tcl]
----
<<MapPolymorphicEvent: map event>>=
relation foreach inst $dstinsts {
    relation foreach partition $partitions {
        relation assign $partition
        relation foreach dstlink $DstLinks {
            relation assign $dstlink
            <<MapPolymorphicEvent: signal subclass>>
        }
    }
}
----

We must traverse the generalization relationship to find the one subclass that
is actually linked and forward the event on to that one.
Note that we are semijoining to each subclass in the generalization until
one is found.
This is different from navigating the relationship in the context
of the +findRelated+ command.

There we determined whether the superclass instance is related to a specific
subclass instance.
Here we are searching for the subclass instance to which the superclass
instance is related.
Once we know which is the related subclass instance we can formulate an
instance reference to it and trace the polymorphic event dispatch.
We _forward_ the event to the subclass instance by recursively signaling
the event.
Once forwarding has happened, we can stop looking any further since
we _know_ that there is exactly one subclass instance linked to any given
superclass instance because the partition constraint guarantees that.

[source,tcl]
----
<<MapPolymorphicEvent: signal subclass>>=
set related [relation semijoin $inst\
    [relvar set ${domain}::$DstClass] -using $Attrs]
if {[relation isnotempty $related]} {
    set dstreference [ToRef ${domain}::${DstClass} $related]
    set target [ToRef $dstrelvar $inst]

    ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\
            $arglist
    if {![MapPolymorphicEvent $frwdcmd $srcref $dstreference $event $arglist]} {
        {*}$frwdcmd $srcref $dstreference $event $arglist ; # <1>
    }

    break
}
----


<1> The forward command prefix will either be +SignalEvent+ or
+SignalDelayedEvent <time>+ depending whether we arrived
here via the +signal+ instance command or the +delaysignal+ instance command.


[float]
===== Testing

[source,tcl]
----
<<test utility procs>>=
proc addPolymorphic {domain args} {
    relvar insert [namespace current]::${domain}::__Arch_PolymorphicEvent\
            $args
}

proc polysignal {srcref dstref event paramlist} {
    puts -nonewline [info level 0]
}
----

[source,tcl]
----
<<dispatch command tests>>=
test MapPolymorphicEvent-1.0 {

    Map a polymorphic event
} -setup {
    setupDomain bar
    addClass bar S {S1 int S2 string} S1
    addClass bar X {X1 int X2 string} X1
    addClass bar Y {Y1 int Y2 string} Y1

    addAssocLink bar {Name R1 SrcClass X}\
        {Name R1 SrcClass X DstClass S Attrs {X1 S1} PrevSrcClass {}}
    addAssocLink bar {Name R1 SrcClass Y}\
        {Name R1 SrcClass Y DstClass S Attrs {Y1 S1} PrevSrcClass {}}
    relvar eval {
        addParitionLink bar {Name ~R1 SrcClass S}
        addPartitionDst bar {Name ~R1 SrcClass S DstClass X Attrs {S1 X1}}
        addPartitionDst bar {Name ~R1 SrcClass S DstClass Y Attrs {S1 Y1}}
    }

    addPolymorphic bar Class S Event e1
    set ref [rosea::ClassCmds::create [namespace current]::bar::S S1 5 S2 baz]
    rosea::ClassCmds::create [namespace current]::bar::X X1 5 X2 bar
} -cleanup {
    cleanupDomain bar
} -body {
    rosea::Dispatch::MapPolymorphicEvent [namespace current]::polysignal\
        {} $ref e1 {}
} -result {true} -output {::rosea::test::polysignal {} {::rosea::test::bar::X {{X1 int} {{X1 5}}}} e1 {}}
----








=== Helper Commands

In this section we present a set of commands that factor common processing
used in a number of areas.
These commands are placed in a separate namespace
which is imported into most of the other package namespaces.
................................................................................
        set assigner [relation semijoin $reference $MultipleAssigner\
            -using {Domain Domain Relationship Relationship}]
        if {[relation isnotempty $assigner]} {
            dict set ensemblemap signal [list\
                ::rosea::RelCmds::signalMultiAssigner $rpath]
            dict set ensemblemap create [list\
                ::rosea::RelCmds::createMultiAssigner $rpath]


        }
    }
    # Create the relationship ensemble command.
    namespace ensemble create -command $rpath -map $ensemblemap
}
----

................................................................................
    relvar eval {
        set aref [::grocer::Fruit create Name apple Color red]
        ::grocer::SeededFruit create Name apple
        ::grocer::RedFruit create Name apple
    }

    set ::rosea::test::states [list]


    rosea tunnel $aref signal grow
    vwait ::rosea::test::states



    testConditions\
        {"SeededFruit" in $::rosea::test::states}\
        {"RedFruit" in $::rosea::test::states}
} -result {1}
----

................................................................................
    ::foo::R1 signal {Name Shoes} e1
    set timer [after 1000 set ::done TIMEOUT]
    vwait ::done
    after cancel $timer
    set ::done
} -result {1}
----




















































== Initial Instance Population

[[initial-instance-population]]
The third important step in translating an XUML domain is to establish
an initial population for the instances in a domain.
If you consider the evolution of the domain over time,
................................................................................
                    [FormatTransition $source $event $params $target]\
                    " ==> $link -> [FormatInstRef $sub]"
            }
            creation {
                append result\
                    "Creation: "\
                    "[FormatInstRef $source] - "\
                    "[FormatEvent $event $params] -> $class\
                    " ==> [FormatInstRef $target]"
            }
            default {
                DeclError BAD_TRACETYPE $type
            }
        }
    }
    return $result
}
----











(((rosea,Trace,FormatTransition)))
[source,tcl]
----
<<trace commands>>=
proc FormatTransition {source event params target} {
    return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
        [FormatInstRef $target]"
}
----

(((rosea,Trace,FormatEvent)))
[source,tcl]
----
<<trace commands>>=
proc FormatEvent {event params} {
    return [string cat\
        "$event"\
        [expr {[llength $params] != 0 ? " \([join $params {, }]\)" : {}}]\
    ]
}
----

(((rosea,Trace,FormatInstRef)))
[source,tcl]
----
<<trace commands>>=
proc FormatInstRef {instref} {
    lassign $instref relvar inst
    if {$relvar eq {}} {
        return {()}
    } else {
        return "$relvar \([tuple get [relation tuple $inst]]\)"
    }
}
----

(((error code,BAD_TRACETYPE)))
[source,tcl]
----
<<error code formats>>=
BAD_TRACETYPE   {unknown trace type, "%s"}



















----

==== Format Time Stamp

(((proc,Trace,FormatTimeStamp)))
[source,tcl]
----
................................................................................

[source,tcl]
----
<<copyright info>>=
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2015 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
................................................................................

proc ::K {x y} {set x}

namespace eval ::rosea {
    <<rosea exports>>
    namespace ensemble create

    variable version 1.9.2

    logger::initNamespace [namespace current]

    <<tclral imports>>
    namespace import ::ral::relvar
    <<rosea data>>
    <<rosea commands>>
................................................................................
=== Package Index

We also provide a root chunk to extract a package index file.

[source,tcl]
----
<<pkgIndex.tcl>>=
package ifneeded rosea 1.9.2 [list source [file join $dir rosea.tcl]]
----

=== Unit Tests

[source,tcl]
----
<<rosea.test>>=
................................................................................
----

=== Reference Documentation

[source,tcl]
----
<<rosea.man>>=
[manpage_begin rosea n 1.9.2]
[comment {
<<copyright info>>
}]
[moddesc "XUML Data and Execution Architecture"]
[titledesc "Relation Oriented Software Execution Architecture"]
[copyright "2014-2020 by G. Andrew Mangogna"]
[require rosea [opt 1.9.2]]
[description]
<<manual description>>
[section "Package Commands"]
The commands in this section are part of the ensemble command [cmd ::rosea].
Their use is to configure, generate and populate domains
and to control state machine tracing during run time.
[list_begin definitions]







|







 







|







 







|







 







|
|
>







 







>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>
>
>











>
>
>







 







|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
|
<







 







<
<
<
|
<







 







|







 







|
|
>
>
>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|
<
<
<







 







>
|
<
|
>
|
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
<
|
<
<
|
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
<
<







>
|






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
>
>




<
<
<
<
<
<
<
<
<
<
|



<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
>
|
<
>
>
|
<
<
<
<
<

<
<
<
<








 







|
|

|





>
>
>
>
>
>
>
|
<
<
|







|
<
|
|
|
|
|
<










>
|





|







|





>

<
|
<
|
>
|
<
<
>
>
|
|
|
>
|
<
|
|
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
>
>
>
>
>
>







 







>
>







 







>
>


>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|










>
>
>
>
>
>
>
>
>
>











<
<
<
<
<
<
<
<
<
<
<
<






|
<
<
|
<



|


|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







 







|







 







|






|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
....
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
....
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
....
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
....
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
....
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
....
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
....
6255
6256
6257
6258
6259
6260
6261


6262

6263
6264
6265
6266
6267
6268
6269
....
6322
6323
6324
6325
6326
6327
6328



6329

6330
6331
6332
6333
6334
6335
6336
....
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
....
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
....
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
....
6940
6941
6942
6943
6944
6945
6946
6947



6948
6949
6950
6951
6952
6953
6954
....
6960
6961
6962
6963
6964
6965
6966
6967
6968

6969
6970
6971

6972
6973
















6974

6975

6976


6977
6978
6979














































































6980





6981
6982






































6983





6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998













































































































6999
7000
7001
7002
7003
7004
7005
....
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
....
7796
7797
7798
7799
7800
7801
7802


7803













7804
7805
7806
7807
7808
7809










7810
7811
7812
7813



7814























7815
7816




7817
7818

7819
7820
7821





7822




7823
7824
7825
7826
7827
7828
7829
7830
....
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874


7875
7876
7877
7878
7879
7880
7881
7882
7883

7884
7885
7886
7887
7888

7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921

7922

7923
7924
7925


7926
7927
7928
7929
7930
7931
7932

7933
7934

7935















7936
7937


























7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
.....
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
.....
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
.....
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
.....
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453












21454
21455
21456
21457
21458
21459
21460


21461

21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
.....
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
.....
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
.....
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
.....
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
relationships and supports set-at-a-time operations on domain class instances.
Processing is transactional and constraint violations result in
rolling back the changes to a known good state.

== Introduction [[introduction,Introduction]]

This document is about a Tcl package named, +rosea+.
+Rosea+ is a model execution domain that is intended as the
target for translating
http://en.wikipedia.com/wiki/Executable_UML[Executable UML]
(XUML) models using Tcl as the implementation language.

//////////
----
<<manual description>>=
................................................................................
of documents like this while retaining the ability to produce the
source code files needed by the Tcl interpreter.

=== How To Read This Document

This document contains a lot of material.
It contains the complete source code, test cases and a runnable example.
Reading the document in order from beginning to end would be an
exceptional undertaking.
Skipping around is encouraged.
For example,
you may wish to skip over the test cases although they do provide
interesting examples in the small of how `rosea` constructs are used.

For those readers wishing a quick look at what `rosea` provides,
................................................................................
    # the new attributes to have the old attribute names.
    set newvalues [relation update [rosea::InstCmds::deRef $ref Temp Volume]\
            newtuple {1} {
        tuple update $newtuple\
            Temp [expr {[tuple extract $newtuple Temp] + 10}]\
            Volume [expr {[tuple extract $newtuple Volume] * 2.0}]
    }]
    log::debug "\n[relformat $newvalues newvalues]"
    set ref [rosea::ClassCmds::update [namespace current]::foo::c1 $newvalues]
    # Extract one of the instances and make sure the attribute values
    # were properly updated.
    pipe {
        rosea::InstCmds::deRef $ref |
        relation restrictwith ~ {$Temp < 200} |
        relation extract ~ Temp Volume
................................................................................

+event+::
    The name of an event to be signaled to the assigner associated
    with _relationship_.
+idvalues+::
    A dictionary keyed by attribute names whose values identify
    an instance of the multiple assigner associated with _relationship_.
    The attribute names will be the same as the attribute names of the
    identifier implied by the `identifyby` command which is used
    to mark an assigner as a multi-assigner.
+paramN+::
    Optional event parameters are passed as additional arguments.
*****

///////
----
<<manual architecture relationship commands>>=
................................................................................

For associations that have a multiple assigner state model,
the [cmd signal] command is used to signal [arg event] to the assigner
state machine identified by [arg idvalues].
The [arg idvalues] argument is a dictionary whose keys are the attributes
names of the assigner identifier and whose corresponding values
match those of some assigner for [arg relationship].
The attribute names will be the same as the attribute names of the
identifier implied by the [method identifyby] command which is used
to mark an assigner as a multi-assigner.
Any optional event parameters are given by the [arg paramN] arguments.
----
///////

[float]
===== Implementation

................................................................................
<<relationship commands>>=
proc signalMultiAssigner {rname idvalues event args} {
    SplitRelvarName $rname domain relationship
    set assignrelvar ${domain}::${relationship}__STATEINST
    if {![relvar exists $assignrelvar]} {
        tailcall DeclError NO_ASSIGNER $rname
    }
    set idattrs [MultiAssignerIDAttrs $domain $relationship]
    # We will insist that the idvalues contain the necessary identifying
    # attributes.
    if {![struct::set equal [dict keys $idvalues] $idattrs]} {
        tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
    }
    set assigninsts [relvar set $assignrelvar]
    set assignrefs [relation project $assigninsts {*}$idattrs]
................................................................................
(((error code,UNKNOWN_ASSIGNER)))
[source,tcl]
----
<<error code formats>>=
NO_IDENTIFIER       {bad identifying attributes, expected "%s", got "%s"}
UNKNOWN_ASSIGNER    {unknown assigner instance, "%s", for relationship, "%s"}
----

A helper command determines the proper set of attribute names that
match those of the identifying class and have the correct ID number.

(((rosea,Helpers,SelfInstRef)))
[source,tcl]
----
<<helper commands>>=
proc MultiAssignerIDAttrs {domain relationship} {
    if {[string range $domain 0 1] eq "::"} {
        set domain [string range $domain 2 end]
    }
    return [pipe {
        relvar restrictone ::rosea::Config::MultipleAssigner\
            Domain $domain Relationship $relationship |
        relation semijoin ~ $::rosea::Config::Identifier\
            $::rosea::Config::IdentifyingAttribute |
        relation list ~ Attribute
    }]
}
----

==== Creating a Multi-Assigner

Since associations can have multi-assigners,
we must provide a means to create instances of the assigners.

*****
_relationship_ +create+ _?attr1 value1 attr2 value2 ...?_

+attrN valueN+::
    Attribute name / value pairs that form the identifier for an
    instance of the multi-assigner associated with _relationship_.
    The attribute names will be the same as the attribute names of the
    identifier implied by the `identifyby` command which is used
    to mark an assigner as a multi-assigner.
*****

///////
----
<<manual architecture relationship commands>>=
[call [arg relationship] [cmd create]\
    [opt [arg "attr1 value1 attr2 value2 ..."]]]

For associations that have a multiple assigner state model,
the [cmd create] command creates an instance of the assigner
that is identified by the [arg attrN] / [arg valueN] names and values.
The attribute names will be the same as the attribute names of the
identifier implied by the [method identifyby] command which is used
to mark an assigner as a multi-assigner.
----
///////

[float]
===== Implementation
(((rosea,RelCmds,createMultiAssigner)))
[source,tcl]
................................................................................
        tailcall DeclError ARG_FORMAT $args
    }
    SplitRelvarName $rname domain relationship
    set assignrelvar ${domain}::${relationship}__STATEINST
    if {![relvar exists $assignrelvar]} {
        tailcall DeclError NO_ASSIGNER $rname
    }
    set idattrs [MultiAssignerIDAttrs $domain $relationship]
    if {![struct::set equal [dict keys $args] $idattrs]} {
        tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
    }
    CreateInInitialState $domain $relationship $args
}
----

==== Deleting a Multi-Assigner

Since multi-assigners can be dynamically created,
we must provide a means to delete instances of the assigners.

*****
_relationship_ +delete+ _?attr1 value1 attr2 value2 ...?_

+attrN valueN+::
    Attribute name / value pairs that form the identifier for an
    instance of the multi-assigner associated with _relationship_.
    The attribute names will be the same as the attribute names of the
    identifier implied by the `identifyby` command which is used
    to mark an assigner as a multi-assigner.
*****

///////
----
<<manual architecture relationship commands>>=
[call [arg relationship] [cmd delete]\
    [opt [arg "attr1 value1 attr2 value2 ..."]]]

For associations that have a multiple assigner state model,
the [cmd delete] command deletes an instance of the assigner
that is identified by the [arg attrN] / [arg valueN] names and values.
The attribute names will be the same as the attribute names of the
identifier implied by the [method identifyby] command which is used
to mark an assigner as a multi-assigner.
----
///////

[float]
===== Implementation
(((rosea,RelCmds,createMultiAssigner)))
[source,tcl]
----
<<relationship commands>>=
proc deleteMultiAssigner {rname args} {
    if {[llength $args] % 2 != 0} {
        tailcall DeclError ARG_FORMAT $args
    }
    SplitRelvarName $rname domain relationship
    set assignrelvar ${domain}::${relationship}__STATEINST
    if {![relvar exists $assignrelvar]} {
        tailcall DeclError NO_ASSIGNER $rname
    }
    set idattrs [MultiAssignerIDAttrs $domain $relationship]
    if {![struct::set equal [dict keys $args] $idattrs]} {
        tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
    }
    relvar deleteone $assignrelvar {*}$args
    return
}
----

=== Instance Commands

In this section we discuss the +rosea+ commands that operate on instance
references.
These commands form the foundation of operations that state activities
use to access the underlying execution architecture.
................................................................................
===== Implementation [[signal-command]]
(((rosea,InstCmds,signal)))
[source,tcl]
----
<<instance commands>>=
proc signal {dstset event args} {
    set srcref [SelfInstRef]


    ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args

    return
}
----

==== Signaling Delayed Events

The XUML modeling semantics supply the concept of a delayed event
................................................................................
----
<<instance commands>>=
proc delaysignal {time dstset event args} {
    if {!([string is integer -strict $time] && $time >= 0)} {
        tailcall DeclError INVALID_TIME $time
    }
    set srcref [SelfInstRef]



    ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args

    return
}
----

(((error code,INVALID_TIME)))
[source,tcl]
----
................................................................................
----
<<dispatch commands>>=
proc SignalEvent {srcref dstset event arglist} {
    <<SignalEvent: validate event>>

    set callback [namespace code DispatchEvent]
    set eventInfo [dict create\
        type $eventType\
        src $srcref\
        event $event\
        params $arglist\
    ]
    if {[isRefEqual $srcref [nilInstRef]]} {
        variable toc_queue
        forAllRefs dstref $dstset {
................................................................................
sure that the class instances accept the event.

[source,tcl]
----
<<SignalEvent: validate event>>=
lassign $dstset relvar insts
SplitRelvarName $relvar domain class
if {[relation isnotempty [relvar restrictone ${domain}::__Arch_Event\
    Class $class Event $event]]} {
    set eventType ordinary
} elseif {[IsPolymorphicEvent $domain $class $event]} {
    set eventType polymorphic
} else {
    tailcall DeclError UNKNOWN_EVENT $event $class
}
----

We use the *PolymorphicEvent* relvar to determine if is the event
is polymorphic.

[source,tcl]
----
<<arch relvar definitions>>=
ral relvar create __Arch_PolymorphicEvent {
    Class           string
    Event           string
} {Class Event}
----

[source,tcl]
----
<<SignalEvent: validate event>>=
<<dispatch commands>>=
proc IsPolymorphicEvent {domain class event} {
    return [relation isnotempty [relvar restrictone\
        ${domain}::__Arch_PolymorphicEvent Class $class Event $event]]
}
----

Finding the proper place for a self directed event requires inserting
the event at the front of the event queue.
However,
there is a minor complication.
If there is already a self directed event on the event queue,
we don't want to place the new one directly on the front.
................................................................................
for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
    set cmpevent [lindex $event_queue $eqindex]
    if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
        break
    }
}
set event_queue [linsert [K $event_queue [set event_queue {}]]\
    $eqindex $eventInfo] ; # <1>
----
<1> This code uses the K combinator trick. This is an optimization
that exploits a particular design characteristic of Tcl.
The net effect is to prevent the sharing of the +event_queue+ value
and save the copy that would otherwise have to be made when the list value is
modified by the list insertion command.
See http://wiki.tcl.tk/1923[the Tcl wiki] for a complete discussion.
................................................................................

(((rosea,Dispatch,DispatchEvent)))
[source,tcl]
----
<<dispatch commands>>=
proc DispatchEvent {} {
    <<DispatchEvent: select event>>
    <<DispatchEvent: handle event types>>



    return
}
----

Events are removed from the +event_queue+ list first.
This queue holds the events generated on the currently running
thread of control and it is always our goal to run the current thread
................................................................................

[source,tcl]
----
<<DispatchEvent: select event>>=
variable event_queue
variable toc_queue

try {
    if {[llength $event_queue] != 0} {

        set event_queue [lassign $event_queue eventInfo]
        TransitionEvent $eventInfo
    } elseif {[llength $toc_queue] != 0} {

        set toc_queue [lassign $toc_queue eventInfo]
        relvar transaction begin ;                              # <1>
















        try {

            TransitionEvent $eventInfo

        } on error {result opts} {


            catch {relvar transaction end} ;                    # <2>
            return -level 0 -options $opts $result
        }














































































    } else {





        return
    }






































} on error {result opts} {





    return -options $opts $result
}

if {[llength $event_queue] == 0} {
    relvar transaction end
}
----
<1> Each time we start a new thread of control, we begin a transaction.
<2> If there is an error in the transition, we need
to end the thread of control (and hence the `relvar transaction`).
In general,
the transaction will fail since the state activity did not complete.
We don't want the transaction failure to throw another error
which would mask the reason the state activity failed in the first place.














































































































[float]
===== Testing

[source,tcl]
----
<<dispatch command tests>>=
test DispatchEvent-1.0 {
................................................................................
    set src [rosea::Helpers::nilInstRef]
    set remain [rosea::InstCmds::delayremaining $src $ref e1]
    rosea::InstCmds::canceldelayed $src $ref e1
    expr {$remain <= 100 && $remain >= 95}
} -result {1}
----

=== Event Transition

In this section we present the implementation of transitioning events.
When an event is directed at an instance,
we must compute any transition the event causes.

==== TransitionEvent

The event dictionary has a `type` key that determines if the event
is an ordinary event, a polymorphic event, or is a creation event.

[source,tcl]
----
<<dispatch commands>>=
proc TransitionEvent {eventInfo} {
    switch -exact -- [dict get $eventInfo type] {
        ordinary {
            TransitionOrdinaryEvent $eventInfo
        }
        creation {
            TransitionCreationEvent $eventInfo
        }
        polymorphic {
            TransitionPolymorphicEvent $eventInfo
        }
        default {
            tailcall DeclError UNKNOWN_EVENT_TYPE [dict get $eventInfo type]
        }
    }
}
----

(((error code,UNKNOWN_EVENT_TYPE)))
[source,tcl]
----
<<error code formats>>=
UNKNOWN_EVENT_TYPE     {unknown event type, \"%s\"}
----

==== TransitionOrdinaryEvent

Events immediately dispatched from the event queue are termed
_ordinary_ events to distinguish them from events such as _creation_
events or _polymorphic_ events which have further semantics associated
with them.

(((rosea,Dispatch,TransitionOrdinaryEvent)))
[source,tcl]
----
<<dispatch commands>>=
proc TransitionOrdinaryEvent {eventInfo} {
    variable event_queue
    <<TransitionOrdinaryEvent: get current state>>
    <<TransitionOrdinaryEvent: determine new state>>
    <<TransitionOrdinaryEvent: execute state action>>
    return
}
----

Each class that has a state model also has an additional relvar that is used to
hold the value of the current state for the instances of the class.
That relvar is named, `<class>__STATEINST`, where +<class>+ is replaced
by the class name.
The heading of the current state relvar consists of the attributes of the first
identifier of the class plus an attribute named, `__State`, which holds the
current state.
So obtaining the current state means that we +semijoin+ the instance reference
to the value of the `<class>__STATEINST` relvar.

[source,tcl]
----
<<TransitionOrdinaryEvent: get current state>>=
set dstref [dict get $eventInfo dst]
lassign $dstref relvar ref
SplitRelvarName $relvar domain class

set instrelvar ${domain}::${class}__STATEINST
set state [relation semijoin $ref [relvar set $instrelvar]]
if {[relation isempty $state]} {
    tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
}
set currstate [relation extract $state __State]
----

(((error code,EVENT_IN_FLIGHT)))
[source,tcl]
----
<<error code formats>>=
EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
----

It is possible for an event to be signaled to an instance that
has been deleted before the event is actually delivered.
This is known as the _event in flight_ error and is one of the few
run-time errors that is diagnosed by +rosea+.
This is considered an analysis error detected at run time.
Correct analysis models must insure that no events are in flight to
an instance before deleting it.
In general, deletion protocols within a domain model can be quite
complicated as the model is responsible for all the compensatory
operations needed to make the instance population consistent with
the relationship constraints.

To obtain the new state,
we query the *Transition* relvar that was shown above.
When the *Transition* relvar value is set up,
it is the Cartesian product of the states and events for the class.
So it can be considered the complete transition matrix and the
query below will always find a tuple with the new state.

[source,tcl]
----
<<dispatch data>>=
pipe {
relvar restrictone ${domain}::__Arch_Transition\
    Class $class State $currstate Event $event |
    relation extract ~ NewState
} transitionQuery
----

Combining the event name and the current state we perform the
query to find the new state.

[source,tcl]
----
<<TransitionOrdinaryEvent: determine new state>>=
set event [dict get $eventInfo event]
variable transitionQuery
set newState [eval $transitionQuery]

::rosea::Trace::TraceTransition [dict get $eventInfo src]\
    $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
----
<1> Note that we trace the transition _before_ we take any action on it.
It is a simpler control path.
We will have much more to say about state machine tracing.

Finally, we get to the heart of the event dispatch code.
There are three cases to consider:

* The event causes a CH (Can't Happen) transition and that is considered
a serious error.
* The event causes an IG (Ignore) transition and we do nothing.
* We transition to the new state and execute the state activity.

In the end,
we must decide if the thread of control has ended and if so then
the transaction is also ended.

[source,tcl]
----
<<TransitionOrdinaryEvent: execute state action>>=
if {$newState eq "CH"} {
    <<TransitionOrdinaryEvent: handle transition error>>
} elseif {$newState ne "IG"} {
    <<TransitionOrdinaryEvent: transition to new state>>
}
----

The *CH* (can't happen) transition deserves special consideration.
You can think of a *CH* transition as an analogy to the +assert+ macro
in ordinary ``C'' code.
Triggering a *CH* transition is a serious error that should never
happen in production code.
If it does, usually there is no clear way to proceed and how to
handle such situations is very application dependent.
Often the only recourse is to exit or reset to some saved checkpoint.
However during development and testing,
the *CH* transition can uncover a wealth of analysis errors and
misunderstandings.
Consequently,
it is very useful to have some control over what happens should
a *CH* transition occur.
We delegate the error handling for *CH* transitions to
the +TransitionError+ footnote:[The fully qualified name is
+::rosea::Dispatch::TransitionError+]
procedure.

[source,tcl]
----
<<TransitionOrdinaryEvent: handle transition error>>=
TransitionError [dict get $eventInfo src] $event $dstref $currstate
----

We supply a default implementation of +TransitionError+ which simply
throws an error.
Application can redefine this procedure to gain control over the error
handling.

(((rosea,Dispatch,TransitionError)))
[source,tcl]
----
<<dispatch commands>>=
proc TransitionError {src event dst currstate} {
    tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
}
----

(((error code,CANT_HAPPEN_EVENT)))
[source,tcl]
----
<<error code formats>>=
CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}
----

When transitioning to the new state,
we update the value of the current state of the instance to be the newly
determined state value.
The identifiers of the `<class>__STATEINST` relvar are just the
attributes of the instance reference for the instance.
Note that the current state is updated to the new state _before_ the
state activity is executed.
Some architectures wait until after the state activity is executed.
Which is better or correct is hard to determine and in practice does
not matter since state activities are strongly discouraged from having knowledge
of their own state.

[source,tcl]
----
<<TransitionOrdinaryEvent: transition to new state>>=
set idattrs [tuple get [relation tuple $ref]]
relvar updateone $instrelvar is $idattrs {
    tuple update $is __State $newState
}
----

At last we execute the state activity.
State activities are ordinary Tcl procedures named the same as the state and
placed in the `__Activity` namespace that is a child of the
namespace associated to the class.
The instance reference of the event target is passed as the
value of the +self+ parameter and any other parameters carried along
with the event are also given to the activity procedure.
Here is the explicit reason that the parameters carried with the
event must match the arguments that the state activity expects
or Tcl will throw an error.

[source,tcl]
----
<<TransitionOrdinaryEvent: transition to new state>>=
try {
    ${relvar}::__Activity::$newState $dstref\
            {*}[dict get $eventInfo params] ; # <1>
} on error {result opts} {
    chan puts stderr $::errorInfo
    return -options $opts $result
} finally {
    set term [relvar restrictone ${domain}::__Arch_TerminalState\
            Class $class State $newState]
    if {[relation isnotempty $term]} {
        relvar deleteone $relvar {*}$idattrs
        relvar deleteone $instrelvar {*}$idattrs
    }
}
----
<1> This command invocation has a lot of variable substitution.
Each state activity is actually a procedure.
Those procedures are placed in the `__Activity` child namespace
of the class so that there is no naming conflict.
The value of +dstref+ becomes +self+ in the state activity.
Finally, we expand out the list of event parameters to be
any additional arguments to the state activity procedure.

After executing the state activity,
we look to see if new state is a terminal state.
If the state was marked as terminal when the state model was defined,
the the system automatically deletes the class instance.
Of course, we must also delete the tuple that records the current state.

==== TransitionCreationEvent

For a creation event we must actually create an class instance before we
cause the event transition.

[source,tcl]
----
<<dispatch commands>>=
proc TransitionCreationEvent {eventInfo} {
    try {
        set dstref [::rosea::ClassCmds::createin\
                [dict get $eventInfo dstClass] @\
                {*}[dict get $eventInfo dstAttrs]] ; # <1>
    } on error {result opts} {
        tailcall DeclError ASYNC_CREATION_FAILED\
                [dict get $eventInfo dstClass]\
                [dict get $eventInfo dstAttrs] $result
        return -options $opts $result
    }
    ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
        [dict get $eventInfo event] $dstref [dict get $eventInfo params]
    dict set eventInfo type ordinary
    dict set eventInfo dst $dstref ; # <2>
    TransitionOrdinaryEvent $eventInfo
}
----
<1> Here is where the new instance is created in the pseudo-initial, `@`,
state.
<2> Note that we are just setting the `dst` dictionary key so that now
all the members are in place to look just like an ordinary event.
The rest of the code simply ignores the dictionary members that it is not
concerned with.

(((error code,ASYNC_CREATION_FAILED)))
[source,tcl]
----
<<error code formats>>=
ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
with attributes, "%s", failed: %s}
----

==== TransitionPolymorphicEvent

We now consider the job of dispatching polymorphic events.
Polymorphic events are events directed at the superclass of a generalization
that are mapped at run time to an event in the subclass to which the
superclass instance is currently related.
This is the only type of polymorphism that XUML execution rules
supportfootnote:[In particular note there are no polymorphic operations
................................................................................
the subclass instances form a disjoint union.].
In this case,
the state model must respond to the union of the events
from all the generalization for which the class is a subclass.
Note that some care might have to be taken to insure that the polymorphic
event names of the multiple hierarchies are distinct.



The +TransitionPolymorphicEvent+ procedure is called during event dispatch













to map polymorphic events to local ordinary events in the
subclasses of a generalization hierarchy.

[float]
===== Implementation











(((rosea,Dispatch,TransitionPolymorphicEvent)))
[source,tcl]
----
<<dispatch commands>>=



proc TransitionPolymorphicEvent {eventInfo} {























    lassign [dict get $eventInfo dst] dstrelvar inst
    SplitRelvarName $dstrelvar domain dstclass




    set event [dict get $eventInfo event]


    <<TransitionPolymorphicEvent: find subclasses>>
    <<TransitionPolymorphicEvent: map event>>
}





----





[[polymapQuery,polymorphic event query]]
The essential query for dispatching a polymorphic event is to find the set of
hierarchies originating at the source relvar.

[source,tcl]
----
<<dispatch data>>=
................................................................................
exactly one subclass from among all the subclasses in the generalization and
it is to that subclass instance that the event will be forwarded.

The heading of the result of this query will be:

[width="50%",options="header",title="Heading of Polymorphic Event Mapping Query Result"]
|=========================
|Name       |SrcClass   2+^h|DstLinks
|string     |string     2+^|Relation
1.2+|       1.2+|             h|DstClass     h|Attrs
                           |string        |list
|=========================

Note that the *DstLinks* attribute is relation valued.footnote:[That is what
the +group+ operation does.]

[source,tcl]
----
<<TransitionPolymorphicEvent: find subclasses>>=
variable polymapQuery
set partitions [eval $polymapQuery]
----

The polymorphic event mapping operation consists of two nested iterations.


The outside iteration is over all the hierarchies that originate from
the superclass.
Typically, this is only one, but it can be several for a compound
generalization.
Finally, we iterate over all the subclass links.

[source,tcl]
----
<<TransitionPolymorphicEvent: map event>>=

relation foreach partition $partitions {
    relation assign $partition
    relation foreach dstlink $DstLinks {
        relation assign $dstlink
        <<TransitionPolymorphicEvent: signal subclass>>

    }
}
----

We must traverse the generalization relationship to find the one subclass that
is actually linked and forward the event on to that one.
Note that we are semijoining to each subclass in the generalization until
one is found.
This is different from navigating the relationship in the context
of the +findRelated+ command.
In that case,
we determined whether the superclass instance is related to a specific
subclass instance.
Here we are searching for the subclass instance to which the superclass
instance is related.
Once we know which is the related subclass instance we can formulate an
instance reference to it and trace the polymorphic event dispatch.
We _forward_ the event to the subclass instance by recursively transitioning
the event.
Once forwarding has happened, we can stop looking any further since
we _know_ that there is exactly one subclass instance linked to any given
superclass instance because the partition constraint guarantees that.

[source,tcl]
----
<<TransitionPolymorphicEvent: signal subclass>>=
set related [relation semijoin $inst\
    [relvar set ${domain}::$DstClass] -using $Attrs]
if {[relation isnotempty $related]} {
    set dstreference [ToRef ${domain}::${DstClass} $related]
    set target [ToRef $dstrelvar $inst]
    set srcref [dict get $eventInfo src]
    ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\

            [dict get $eventInfo params]


    set mappedInfo $eventInfo ;                                 # <1>
    dict set mappedInfo src $target


    dict set mappedInfo dst $dstreference
    if {[IsPolymorphicEvent $domain $DstClass $event]} {
        TransitionPolymorphicEvent $mappedInfo
    } else {
        dict set eventInfo type ordinary
        TransitionOrdinaryEvent $mappedInfo
    }

    break
}

----















<1> The event information we hand down the hierarchy is modified to
reflect the polymorphic mapping.


























Note that we modify a copy of the event information, since in the case of
a compound generalization, we need to preserve the original event information
for another generalization hierachy that originates from the same
superclass.
This is the case where one event to a superclass causes multiple events
to be transitioned when the superclass has multiple hierarchies extending
from it.

=== Helper Commands

In this section we present a set of commands that factor common processing
used in a number of areas.
These commands are placed in a separate namespace
which is imported into most of the other package namespaces.
................................................................................
        set assigner [relation semijoin $reference $MultipleAssigner\
            -using {Domain Domain Relationship Relationship}]
        if {[relation isnotempty $assigner]} {
            dict set ensemblemap signal [list\
                ::rosea::RelCmds::signalMultiAssigner $rpath]
            dict set ensemblemap create [list\
                ::rosea::RelCmds::createMultiAssigner $rpath]
            dict set ensemblemap delete [list\
                ::rosea::RelCmds::deleteMultiAssigner $rpath]
        }
    }
    # Create the relationship ensemble command.
    namespace ensemble create -command $rpath -map $ensemblemap
}
----

................................................................................
    relvar eval {
        set aref [::grocer::Fruit create Name apple Color red]
        ::grocer::SeededFruit create Name apple
        ::grocer::RedFruit create Name apple
    }

    set ::rosea::test::states [list]
    rosea trace control clear
    rosea trace control on
    rosea tunnel $aref signal grow
    vwait ::rosea::test::states
    rosea trace control off
    puts [rosea trace format [rosea trace decode all]]

    testConditions\
        {"SeededFruit" in $::rosea::test::states}\
        {"RedFruit" in $::rosea::test::states}
} -result {1}
----

................................................................................
    ::foo::R1 signal {Name Shoes} e1
    set timer [after 1000 set ::done TIMEOUT]
    vwait ::done
    after cancel $timer
    set ::done
} -result {1}
----

[source,tcl]
----
<<generate command tests>>=
test generate-6.2 {
    delete a multi assigner
} -setup {
    rosea configure {
        domain foo {
            class Customer {
                attribute Name string -id 1
            }
            class Clerk {
                attribute Name string -id 1
                attribute Customer string
                attribute Department string
                reference R1 Customer -link {Customer Name}
                reference R2 Department -link {Department Name}
            }
            class Department {
                attribute Name string -id 1
            }
            association R1 Clerk 0..1--0..1 Customer
            association R2 Clerk 1..*--1 Department
            assigner R1 {
                identifyby Department
                state s1 {a b} {
                    puts $a $b
                }
                transition s1 - e1 -> s2

                state s2 {} {
                    puts "in s2"
                        set ::done 1
                }
                transition s2 - e1 -> s1
            }
        }
    }
    rosea generate
} -cleanup {
    cleanupConfigData
    removeDomain ::foo
} -body {
    ::foo::R1 create Name Shoes
    ::foo::R1 delete Name Shoes
    ::foo::R1 signal {Name Shoes} e1
} -result\
    {unknown assigner instance, "Name Shoes", for relationship, "::foo::R1"}\
    -returnCodes error
----

== Initial Instance Population

[[initial-instance-population]]
The third important step in translating an XUML domain is to establish
an initial population for the instances in a domain.
If you consider the evolution of the domain over time,
................................................................................
                    [FormatTransition $source $event $params $target]\
                    " ==> $link -> [FormatInstRef $sub]"
            }
            creation {
                append result\
                    "Creation: "\
                    "[FormatInstRef $source] - "\
                    "[FormatEvent $event $params] -> $class"\
                    " ==> [FormatInstRef $target]"
            }
            default {
                DeclError BAD_TRACETYPE $type
            }
        }
    }
    return $result
}
----

(((error code,BAD_TRACETYPE)))
[source,tcl]
----
<<error code formats>>=
BAD_TRACETYPE   {unknown trace type, "%s"}
----

A number of formatting commands can be factored out to operate on the
pieces of a trace record.

(((rosea,Trace,FormatTransition)))
[source,tcl]
----
<<trace commands>>=
proc FormatTransition {source event params target} {
    return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
        [FormatInstRef $target]"
}
----













(((rosea,Trace,FormatInstRef)))
[source,tcl]
----
<<trace commands>>=
proc FormatInstRef {instref} {
    lassign $instref relvar inst
    return [expr {$relvar eq {} ? "()" :


            "$relvar\([FormatNVPairs [tuple get [relation tuple $inst]]]\)"}]

}
----

(((rosea,Trace,FormatEvent)))
[source,tcl]
----
<<trace commands>>=
proc FormatEvent {event params} {
    set result $event

    if {[llength $params] != 0} {
        append result "\([join $params {, }]\)"
    }
    return $result
}
----

(((rosea,Trace,FormatEvent)))
[source,tcl]
----
<<trace commands>>=
proc FormatNVPairs {pairs} {
    return [pipe {
        lmap {attr val} $pairs {string cat $attr ": " $val} |
        join ~ {, }
    }]
}
----

==== Format Time Stamp

(((proc,Trace,FormatTimeStamp)))
[source,tcl]
----
................................................................................

[source,tcl]
----
<<copyright info>>=
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2020 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
................................................................................

proc ::K {x y} {set x}

namespace eval ::rosea {
    <<rosea exports>>
    namespace ensemble create

    variable version 1.10

    logger::initNamespace [namespace current]

    <<tclral imports>>
    namespace import ::ral::relvar
    <<rosea data>>
    <<rosea commands>>
................................................................................
=== Package Index

We also provide a root chunk to extract a package index file.

[source,tcl]
----
<<pkgIndex.tcl>>=
package ifneeded rosea 1.10 [list source [file join $dir rosea.tcl]]
----

=== Unit Tests

[source,tcl]
----
<<rosea.test>>=
................................................................................
----

=== Reference Documentation

[source,tcl]
----
<<rosea.man>>=
[manpage_begin rosea n 1.10]
[comment {
<<copyright info>>
}]
[moddesc "XUML Data and Execution Architecture"]
[titledesc "Relation Oriented Software Execution Architecture"]
[copyright "2014-2020 by G. Andrew Mangogna"]
[require rosea [opt 1.10]]
[description]
<<manual description>>
[section "Package Commands"]
The commands in this section are part of the ensemble command [cmd ::rosea].
Their use is to configure, generate and populate domains
and to control state machine tracing during run time.
[list_begin definitions]

Changes to rosea/src/rosea.tcl.

1
2
3
4
5
6
7
8
9
10
11
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
734
735
736
737
738
739
740


741
742
743
744
745
746
747
....
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324


1325
1326
1327
1328
1329
1330
1331
....
1397
1398
1399
1400
1401
1402
1403












1404
1405
1406
1407
1408
1409
1410
....
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
....
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
....
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
















2431
2432
2433
2434
2435
2436
2437
....
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459





2460
2461
2462
2463
2464
2465
2466
2467
2468
2469




2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
....
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509




2510
2511
2512
2513

2514
2515
2516


2517
2518
2519

2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577


2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
....
2669
2670
2671
2672
2673
2674
2675
2676


















2677
2678



























2679
2680

2681





2682
2683

























2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695

2696
2697
2698
2699

2700









2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
....
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253





5254
5255
5256
5257
5258
5259
5260
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2015 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
................................................................................
    
    namespace export tunnel
    
    namespace export trace
    
    namespace ensemble create

    variable version 1.9.2

    logger::initNamespace [namespace current]

    namespace import\
        ::ral::relation\
        ::ral::tuple\
        ::ral::relformat\
................................................................................
                    set assigner [relation semijoin $reference $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]


                    }
                }
                # Create the relationship ensemble command.
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            set cassocs [relation semijoin $rships $Association\
                    $ClassBasedAssociation]
................................................................................
            WITH_ATTR_USAGE {wrong arguments, should be,\
                    "withAttribute attrvarpair1 ?attrvarpair2 ...? body"}
            ATTR_VAR_SPEC   {attribute / variable argument must be a one or two element\
                    list, got "%s"}
            INVALID_TIME    {invalid time value, "%s"}
            SINGLE_OR_EMPTY_REF_REQUIRED {single valued or nil reference required, %d found}
            SINGLE_REF_REQUIRED     {single valued reference required, %d found}
            ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
                with attributes, "%s", failed: %s}
            EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
            CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}


            CONFIG_ERRORS     {encountered %d configuration script errors}
            EMPTY_NAME      {the empty string is not a valid name for a %s}
            BAD_CLASS_NAME      {class names must be begin with an alphanumeric\
                                character, got: "%s"}
            DUP_ELEMENT_NAME    {a class, relationship or domain operation named, "%s",\
                                already exists}
            RESERVED_NAME {names beginning with two underscore characters are reserved,\
................................................................................
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstanceFromRef $domns $class\
                    [relation extract $initstate State] $ref
            }
            return












        }
        proc SelfInstRef {{level 2}} {
            set foundRef false
            set ref [nilInstRef]
        
            for {set ns [uplevel $level namespace current]} {$ns ne "::"}\
                    {set ns [uplevel [incr level] namespace current]} {
................................................................................
                }
            }
        
            return
        }
        proc signal {dstset event args} {
            set srcref [SelfInstRef]
            if {![::rosea::Dispatch::MapPolymorphicEvent ::rosea::Dispatch::SignalEvent\
                    $srcref $dstset $event $args]} {
                ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args
            }
            return
        }
        proc delaysignal {time dstset event args} {
            if {!([string is integer -strict $time] && $time >= 0)} {
                tailcall DeclError INVALID_TIME $time
            }
            set srcref [SelfInstRef]
            if {![::rosea::Dispatch::MapPolymorphicEvent\
                    [list ::rosea::Dispatch::SignalDelayedEvent $time]\
                    $srcref $dstset $event $args]} {
                ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args
            }
            return
        }
        proc canceldelayed {srcref dstset event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
................................................................................
        }
        proc signalMultiAssigner {rname idvalues event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [lindex [relvar identifiers $assignrelvar] 0]
            # We will insist that the idvalues contain the necessary identifying
            # attributes.
            if {![struct::set equal [dict keys $idvalues] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
            }
            set assigninsts [relvar set $assignrelvar]
            set assignrefs [relation project $assigninsts {*}$idattrs]
................................................................................
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [lindex [relvar identifiers $assignrelvar] 0]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            CreateInInitialState $domain $relationship $args
















        }
    }
    namespace eval Dispatch {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
................................................................................
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        variable toc_queue [list]
        variable event_queue [list]
        pipe {
            relvar restrictone ${domain}::__Arch_Transition\
                Class $class State $currstate Event $event |
            relation extract ~ NewState
        } transitionQuery
        relvar create DelayedSignal {
            RefId           int
            SrcInstRef      list
            Event           string
            DstInstRef      list
            TimerId         string
            Expire          bignum
        } RefId {SrcInstRef Event DstInstRef} TimerId
        variable DelayedSignalId 0





        pipe {
            relvar set ${domain}::__Arch_PartitionDst |
            relation restrictwith ~ {$SrcClass eq $dstclass} |
            relation group ~ DstLinks DstClass Attrs
        } polymapQuery
        proc SignalEvent {srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isempty [relvar restrictone ${domain}::__Arch_Event\
                    Class $class Event $event]]} {




                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            set callback [namespace code DispatchEvent]
            set eventInfo [dict create\
                type ordinary\
                src $srcref\
                event $event\
                params $arglist\
            ]
            if {[isRefEqual $srcref [nilInstRef]]} {
                variable toc_queue
                forAllRefs dstref $dstset {
................................................................................
                        for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
                            set cmpevent [lindex $event_queue $eqindex]
                            if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
                                break
                            }
                        }
                        set event_queue [linsert [K $event_queue [set event_queue {}]]\
                                $eqindex $eventInfo] ; # <1>
                    } else {
                        # Non-self directed events are always simply appended to the
                        # event queue.
                        lappend event_queue $eventInfo
                    }
                    ::after 0 $callback
                }
            }
        }




        proc DispatchEvent {} {
            variable event_queue
            variable toc_queue
            

            if {[llength $event_queue] != 0} {
                set eventInfo [lindex $event_queue 0]
                set event_queue [lrange [K $event_queue [set event_queue {}]] 1 end] ; # <1>


            } elseif {[llength $toc_queue] != 0} {
                set eventInfo [lindex $toc_queue 0]
                set toc_queue [lrange [K $toc_queue [set toc_queue {}]] 1 end]

                relvar transaction begin ; # <2>
            } else {
                return
            }
            if {[dict get $eventInfo type] eq "creation"} {
                try {
                    set dstref [::rosea::ClassCmds::createin\
                            [dict get $eventInfo dstClass] @\
                            {*}[dict get $eventInfo dstAttrs]] ; # <1>
                } on error {result} {
                    catch {
                        if {[llength $event_queue] == 0} {
                            relvar transaction end
                        }
                    }
                    tailcall DeclError ASYNC_CREATION_FAILED [dict get $eventInfo dstClass]\
                        [dict get $eventInfo dstAttrs] $result
                }
                dict set eventInfo dst $dstref ; # <2>
                ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
                    [dict get $eventInfo event] $dstref [dict get $eventInfo params]
            }
            set dstref [dict get $eventInfo dst]
            lassign $dstref relvar ref
            SplitRelvarName $relvar domain class
            
            set instrelvar ${domain}::${class}__STATEINST
            set state [relation semijoin $ref [relvar set $instrelvar]]
            if {[relation isempty $state]} {
                tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
            }
            set currstate [relation extract $state __State]
            set event [dict get $eventInfo event]
            variable transitionQuery
            set newState [eval $transitionQuery]
            
            ::rosea::Trace::TraceTransition [dict get $eventInfo src]\
                $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
            try {
                if {$newState eq "CH"} {
                    TransitionError [dict get $eventInfo src] $event $dstref $currstate
                } elseif {$newState ne "IG"} {
                    set idattrs [tuple get [relation tuple $ref]]
                    relvar updateone $instrelvar is $idattrs {
                        tuple update $is __State $newState
                    }
                    try {
                        ${relvar}::__Activity::$newState $dstref\
                                {*}[dict get $eventInfo params] ; # <1>
                    } on error {result opts} {
                        return -options $opts $result
                    } finally {
                        set term [relvar restrictone ${domain}::__Arch_TerminalState\
                                Class $class State $newState]
                        if {[relation isnotempty $term]} {
                            relvar deleteone $relvar {*}$idattrs
                            relvar deleteone $instrelvar {*}$idattrs
                        }


                    }
                }
            } on error {result opts} {
                catch {
                    if {[llength $event_queue] == 0} {
                        relvar transaction end
                    }
                } ; # <1>
                return -options $opts $result
            }
            
            if {[llength $event_queue] == 0} {
                relvar transaction end
            }
            return
        }
        proc TransitionError {src event dst currstate} {
            tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
        }
        proc FindDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            return [relation restrictwith $DelayedSignal {
                    [isRefEqual $SrcInstRef $srcref] && $Event eq $event &&\
                    [isRefEqual $DstInstRef $dstref]}]
        }
        proc DeleteDelayedSignal {srcref event dstref} {
................................................................................
            }
        }
        proc SignalTimeRemaining {srcref event dstref} {
            set sig [FindDelayedSignal $srcref $event $dstref]
            return [expr {[relation isempty $sig] ? 0 :\
                max([relation extract $sig Expire] - [clock milliseconds], 0)}] ; # <1>
        }
        proc MapPolymorphicEvent {frwdcmd srcref dstrefs event arglist} {


















            lassign $dstrefs dstrelvar dstinsts
            SplitRelvarName $dstrelvar domain dstclass



























            set polyevent [relvar restrictone ${domain}::__Arch_PolymorphicEvent\
                Class $dstclass Event $event]

            if {[relation isempty $polyevent]} {





                return false
            }

























            variable polymapQuery
            set partitions [eval $polymapQuery]
            relation foreach inst $dstinsts {
                relation foreach partition $partitions {
                    relation assign $partition
                    relation foreach dstlink $DstLinks {
                        relation assign $dstlink
                        set related [relation semijoin $inst\
                            [relvar set ${domain}::$DstClass] -using $Attrs]
                        if {[relation isnotempty $related]} {
                            set dstreference [ToRef ${domain}::${DstClass} $related]
                            set target [ToRef $dstrelvar $inst]

                            ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\
                                    $arglist
                            if {![MapPolymorphicEvent $frwdcmd $srcref $dstreference $event $arglist]} {
                                {*}$frwdcmd $srcref $dstreference $event $arglist ; # <1>

                            }









                            break
                        }
                    }
                }
            }
        
            return true
        }
    }
    namespace eval Config {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
................................................................................
                            [FormatTransition $source $event $params $target]\
                            " ==> $link -> [FormatInstRef $sub]"
                    }
                    creation {
                        append result\
                            "Creation: "\
                            "[FormatInstRef $source] - "\
                            "[FormatEvent $event $params] -> $class\
                            " ==> [FormatInstRef $target]"
                    }
                    default {
                        DeclError BAD_TRACETYPE $type
                    }
                }
            }
            return $result
        }
        proc FormatTransition {source event params target} {
            return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
                [FormatInstRef $target]"
        }
        proc FormatEvent {event params} {
            return [string cat\
                "$event"\
                [expr {[llength $params] != 0 ? " \([join $params {, }]\)" : {}}]\
            ]
        }
        proc FormatInstRef {instref} {
            lassign $instref relvar inst
            if {$relvar eq {}} {
                return {()}
            } else {
                return "$relvar \([tuple get [relation tuple $inst]]\)"
            }





        }
        proc FormatTimestamp {time} {
            set sec [clock format [expr {$time / 1000000}] -format %T] ; # <1>
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        



|







 







|







 







>
>







 







|
<


>
>







 







>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
|
<







<
<
<
|
<







 







|







 







|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<









>
>
>
>
>








|
|
>
>
>
>





|







 







|









>
>
>
>




>
|
<
<
>
>
|
<
<
>
|
<
<
<
<
|
<
|
<
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
|
>
>
|
<

<
<
<
<
<








<
<
<







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
<
>
|
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
|
|
|
|
|
|
|
|
|
>
|
<
<
<
>
|
>
>
>
>
>
>
>
>
>
|
|
|
|
<
<
<







 







|













|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
....
1316
1317
1318
1319
1320
1321
1322
1323

1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
....
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
....
2007
2008
2009
2010
2011
2012
2013


2014

2015
2016
2017
2018
2019
2020
2021



2022

2023
2024
2025
2026
2027
2028
2029
....
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
....
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
....
2463
2464
2465
2466
2467
2468
2469





2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
....
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547


2548
2549
2550


2551
2552




2553

2554

2555


2556





































2557






2558
2559
2560
2561

2562





2563
2564
2565
2566
2567
2568
2569
2570



2571
2572
2573
2574
2575
2576
2577
....
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698

2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734

2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745



2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760



2761
2762
2763
2764
2765
2766
2767
....
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2020 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
................................................................................
    
    namespace export tunnel
    
    namespace export trace
    
    namespace ensemble create

    variable version 1.10

    logger::initNamespace [namespace current]

    namespace import\
        ::ral::relation\
        ::ral::tuple\
        ::ral::relformat\
................................................................................
                    set assigner [relation semijoin $reference $MultipleAssigner\
                        -using {Domain Domain Relationship Relationship}]
                    if {[relation isnotempty $assigner]} {
                        dict set ensemblemap signal [list\
                            ::rosea::RelCmds::signalMultiAssigner $rpath]
                        dict set ensemblemap create [list\
                            ::rosea::RelCmds::createMultiAssigner $rpath]
                        dict set ensemblemap delete [list\
                            ::rosea::RelCmds::deleteMultiAssigner $rpath]
                    }
                }
                # Create the relationship ensemble command.
                namespace ensemble create -command $rpath -map $ensemblemap
            }
            set cassocs [relation semijoin $rships $Association\
                    $ClassBasedAssociation]
................................................................................
            WITH_ATTR_USAGE {wrong arguments, should be,\
                    "withAttribute attrvarpair1 ?attrvarpair2 ...? body"}
            ATTR_VAR_SPEC   {attribute / variable argument must be a one or two element\
                    list, got "%s"}
            INVALID_TIME    {invalid time value, "%s"}
            SINGLE_OR_EMPTY_REF_REQUIRED {single valued or nil reference required, %d found}
            SINGLE_REF_REQUIRED     {single valued reference required, %d found}
            UNKNOWN_EVENT_TYPE     {unknown event type, \"%s\"}

            EVENT_IN_FLIGHT     {event, "%s", sent to "%s", which does not exist}
            CANT_HAPPEN_EVENT   {can't happen transition, %s - %s -> %s ==> %s -> CH}
            ASYNC_CREATION_FAILED     {asynchronous creation of an instance of class, "%s",\
            with attributes, "%s", failed: %s}
            CONFIG_ERRORS     {encountered %d configuration script errors}
            EMPTY_NAME      {the empty string is not a valid name for a %s}
            BAD_CLASS_NAME      {class names must be begin with an alphanumeric\
                                character, got: "%s"}
            DUP_ELEMENT_NAME    {a class, relationship or domain operation named, "%s",\
                                already exists}
            RESERVED_NAME {names beginning with two underscore characters are reserved,\
................................................................................
            set initstate [relvar restrictone ${domns}::__Arch_InitialState\
                Class $class]
            if {[relation isnotempty $initstate]} {
                CreateStateInstanceFromRef $domns $class\
                    [relation extract $initstate State] $ref
            }
            return
        }
        proc MultiAssignerIDAttrs {domain relationship} {
            if {[string range $domain 0 1] eq "::"} {
                set domain [string range $domain 2 end]
            }
            return [pipe {
                relvar restrictone ::rosea::Config::MultipleAssigner\
                    Domain $domain Relationship $relationship |
                relation semijoin ~ $::rosea::Config::Identifier\
                    $::rosea::Config::IdentifyingAttribute |
                relation list ~ Attribute
            }]
        }
        proc SelfInstRef {{level 2}} {
            set foundRef false
            set ref [nilInstRef]
        
            for {set ns [uplevel $level namespace current]} {$ns ne "::"}\
                    {set ns [uplevel [incr level] namespace current]} {
................................................................................
                }
            }
        
            return
        }
        proc signal {dstset event args} {
            set srcref [SelfInstRef]


            ::rosea::Dispatch::SignalEvent $srcref $dstset $event $args

            return
        }
        proc delaysignal {time dstset event args} {
            if {!([string is integer -strict $time] && $time >= 0)} {
                tailcall DeclError INVALID_TIME $time
            }
            set srcref [SelfInstRef]



            ::rosea::Dispatch::SignalDelayedEvent $time $srcref $dstset $event $args

            return
        }
        proc canceldelayed {srcref dstset event} {
            set srcmult [refMultiplicity $srcref]
            if {$srcmult > 1} {
                tailcall DeclError SINGLE_OR_EMPTY_REF_REQUIRED $srcmult
            }
................................................................................
        }
        proc signalMultiAssigner {rname idvalues event args} {
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            # We will insist that the idvalues contain the necessary identifying
            # attributes.
            if {![struct::set equal [dict keys $idvalues] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $idvalues] $idattrs
            }
            set assigninsts [relvar set $assignrelvar]
            set assignrefs [relation project $assigninsts {*}$idattrs]
................................................................................
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            CreateInInitialState $domain $relationship $args
        }
        proc deleteMultiAssigner {rname args} {
            if {[llength $args] % 2 != 0} {
                tailcall DeclError ARG_FORMAT $args
            }
            SplitRelvarName $rname domain relationship
            set assignrelvar ${domain}::${relationship}__STATEINST
            if {![relvar exists $assignrelvar]} {
                tailcall DeclError NO_ASSIGNER $rname
            }
            set idattrs [MultiAssignerIDAttrs $domain $relationship]
            if {![struct::set equal [dict keys $args] $idattrs]} {
                tailcall DeclError NO_IDENTIFIER [dict keys $args] $idattrs
            }
            relvar deleteone $assignrelvar {*}$args
            return
        }
    }
    namespace eval Dispatch {
        namespace import\
            ::ral::relation\
            ::ral::tuple\
            ::ral::relformat\
................................................................................
        namespace import ::ral::relvar
        namespace path [list\
            [namespace parent]::Helpers\
            [namespace parent]::InstCmds\
        ]
        variable toc_queue [list]
        variable event_queue [list]





        relvar create DelayedSignal {
            RefId           int
            SrcInstRef      list
            Event           string
            DstInstRef      list
            TimerId         string
            Expire          bignum
        } RefId {SrcInstRef Event DstInstRef} TimerId
        variable DelayedSignalId 0
        pipe {
        relvar restrictone ${domain}::__Arch_Transition\
            Class $class State $currstate Event $event |
            relation extract ~ NewState
        } transitionQuery
        pipe {
            relvar set ${domain}::__Arch_PartitionDst |
            relation restrictwith ~ {$SrcClass eq $dstclass} |
            relation group ~ DstLinks DstClass Attrs
        } polymapQuery
        proc SignalEvent {srcref dstset event arglist} {
            lassign $dstset relvar insts
            SplitRelvarName $relvar domain class
            if {[relation isnotempty [relvar restrictone ${domain}::__Arch_Event\
                Class $class Event $event]]} {
                set eventType ordinary
            } elseif {[IsPolymorphicEvent $domain $class $event]} {
                set eventType polymorphic
            } else {
                tailcall DeclError UNKNOWN_EVENT $event $class
            }
        
            set callback [namespace code DispatchEvent]
            set eventInfo [dict create\
                type $eventType\
                src $srcref\
                event $event\
                params $arglist\
            ]
            if {[isRefEqual $srcref [nilInstRef]]} {
                variable toc_queue
                forAllRefs dstref $dstset {
................................................................................
                        for {set eqindex 0} {$eqindex < [llength $event_queue]} {incr eqindex} {
                            set cmpevent [lindex $event_queue $eqindex]
                            if {![isRefEqual [dict get $cmpevent src] [dict get $cmpevent dst]]} {
                                break
                            }
                        }
                        set event_queue [linsert [K $event_queue [set event_queue {}]]\
                            $eqindex $eventInfo] ; # <1>
                    } else {
                        # Non-self directed events are always simply appended to the
                        # event queue.
                        lappend event_queue $eventInfo
                    }
                    ::after 0 $callback
                }
            }
        }
        proc IsPolymorphicEvent {domain class event} {
            return [relation isnotempty [relvar restrictone\
                ${domain}::__Arch_PolymorphicEvent Class $class Event $event]]
        }
        proc DispatchEvent {} {
            variable event_queue
            variable toc_queue
            
            try {
                if {[llength $event_queue] != 0} {


                    set event_queue [lassign $event_queue eventInfo]
                    TransitionEvent $eventInfo
                } elseif {[llength $toc_queue] != 0} {


                    set toc_queue [lassign $toc_queue eventInfo]
                    relvar transaction begin ;                              # <1>




                    try {

                        TransitionEvent $eventInfo

                    } on error {result opts} {


                        catch {relvar transaction end} ;                    # <2>





































                        return -level 0 -options $opts $result






                    }
                } else {
                    return
                }

            } on error {result opts} {





                return -options $opts $result
            }
            
            if {[llength $event_queue] == 0} {
                relvar transaction end
            }
            return
        }



        proc FindDelayedSignal {srcref event dstref} {
            variable DelayedSignal
            return [relation restrictwith $DelayedSignal {
                    [isRefEqual $SrcInstRef $srcref] && $Event eq $event &&\
                    [isRefEqual $DstInstRef $dstref]}]
        }
        proc DeleteDelayedSignal {srcref event dstref} {
................................................................................
            }
        }
        proc SignalTimeRemaining {srcref event dstref} {
            set sig [FindDelayedSignal $srcref $event $dstref]
            return [expr {[relation isempty $sig] ? 0 :\
                max([relation extract $sig Expire] - [clock milliseconds], 0)}] ; # <1>
        }
        proc TransitionEvent {eventInfo} {
            switch -exact -- [dict get $eventInfo type] {
                ordinary {
                    TransitionOrdinaryEvent $eventInfo
                }
                creation {
                    TransitionCreationEvent $eventInfo
                }
                polymorphic {
                    TransitionPolymorphicEvent $eventInfo
                }
                default {
                    tailcall DeclError UNKNOWN_EVENT_TYPE [dict get $eventInfo type]
                }
            }
        }
        proc TransitionOrdinaryEvent {eventInfo} {
            variable event_queue
            set dstref [dict get $eventInfo dst]
            lassign $dstref relvar ref
            SplitRelvarName $relvar domain class
            
            set instrelvar ${domain}::${class}__STATEINST
            set state [relation semijoin $ref [relvar set $instrelvar]]
            if {[relation isempty $state]} {
                tailcall DeclError EVENT_IN_FLIGHT [dict get $eventInfo event] $ref
            }
            set currstate [relation extract $state __State]
            set event [dict get $eventInfo event]
            variable transitionQuery
            set newState [eval $transitionQuery]
            
            ::rosea::Trace::TraceTransition [dict get $eventInfo src]\
                $event $dstref $currstate $newState [dict get $eventInfo params] ; # <1>
            if {$newState eq "CH"} {
                TransitionError [dict get $eventInfo src] $event $dstref $currstate
            } elseif {$newState ne "IG"} {
                set idattrs [tuple get [relation tuple $ref]]
                relvar updateone $instrelvar is $idattrs {
                    tuple update $is __State $newState
                }
                try {
                    ${relvar}::__Activity::$newState $dstref\
                            {*}[dict get $eventInfo params] ; # <1>
                } on error {result opts} {
                    chan puts stderr $::errorInfo
                    return -options $opts $result
                } finally {
                    set term [relvar restrictone ${domain}::__Arch_TerminalState\

                            Class $class State $newState]
                    if {[relation isnotempty $term]} {
                        relvar deleteone $relvar {*}$idattrs
                        relvar deleteone $instrelvar {*}$idattrs
                    }
                }
            }
            return
        }
        proc TransitionError {src event dst currstate} {
            tailcall DeclError CANT_HAPPEN_EVENT $src $event $dst $currstate
        }
        proc TransitionCreationEvent {eventInfo} {
            try {
                set dstref [::rosea::ClassCmds::createin\
                        [dict get $eventInfo dstClass] @\
                        {*}[dict get $eventInfo dstAttrs]] ; # <1>
            } on error {result opts} {
                tailcall DeclError ASYNC_CREATION_FAILED\
                        [dict get $eventInfo dstClass]\
                        [dict get $eventInfo dstAttrs] $result
                return -options $opts $result
            }
            ::rosea::Trace::TraceCreation [dict get $eventInfo src]\
                [dict get $eventInfo event] $dstref [dict get $eventInfo params]
            dict set eventInfo type ordinary
            dict set eventInfo dst $dstref ; # <2>
            TransitionOrdinaryEvent $eventInfo
        }
        proc TransitionPolymorphicEvent {eventInfo} {
            lassign [dict get $eventInfo dst] dstrelvar inst
            SplitRelvarName $dstrelvar domain dstclass
            set event [dict get $eventInfo event]
        
            variable polymapQuery
            set partitions [eval $polymapQuery]

            relation foreach partition $partitions {
                relation assign $partition
                relation foreach dstlink $DstLinks {
                    relation assign $dstlink
                    set related [relation semijoin $inst\
                        [relvar set ${domain}::$DstClass] -using $Attrs]
                    if {[relation isnotempty $related]} {
                        set dstreference [ToRef ${domain}::${DstClass} $related]
                        set target [ToRef $dstrelvar $inst]
                        set srcref [dict get $eventInfo src]
                        ::rosea::Trace::TracePolymorphic $srcref $event $target $dstreference $Name\



                                [dict get $eventInfo params]
                    
                        set mappedInfo $eventInfo ;                                 # <1>
                        dict set mappedInfo src $target
                        dict set mappedInfo dst $dstreference
                        if {[IsPolymorphicEvent $domain $DstClass $event]} {
                            TransitionPolymorphicEvent $mappedInfo
                        } else {
                            dict set eventInfo type ordinary
                            TransitionOrdinaryEvent $mappedInfo
                        }
                        break
                    }
                }
            }



        }
    }
    namespace eval Config {
        logger::initNamespace [namespace current]
    
        namespace import\
            ::ral::relation\
................................................................................
                            [FormatTransition $source $event $params $target]\
                            " ==> $link -> [FormatInstRef $sub]"
                    }
                    creation {
                        append result\
                            "Creation: "\
                            "[FormatInstRef $source] - "\
                            "[FormatEvent $event $params] -> $class"\
                            " ==> [FormatInstRef $target]"
                    }
                    default {
                        DeclError BAD_TRACETYPE $type
                    }
                }
            }
            return $result
        }
        proc FormatTransition {source event params target} {
            return "[FormatInstRef $source] - [FormatEvent $event $params] ->\
                [FormatInstRef $target]"
        }
        proc FormatInstRef {instref} {
            lassign $instref relvar inst
            return [expr {$relvar eq {} ? "()" :
                    "$relvar\([FormatNVPairs [tuple get [relation tuple $inst]]]\)"}]
        }
        proc FormatEvent {event params} {
            set result $event
        
            if {[llength $params] != 0} {
                append result "\([join $params {, }]\)"
            }
            return $result
        }
        proc FormatNVPairs {pairs} {
            return [pipe {
                lmap {attr val} $pairs {string cat $attr ": " $val} |
                join ~ {, }
            }]
        }
        proc FormatTimestamp {time} {
            set sec [clock format [expr {$time / 1000000}] -format %T] ; # <1>
            set time [expr {$time % 1000000}]
            set msec [expr {$time / 1000}]
            set usec [expr {$time % 1000}]
        

Changes to rosea/src/teapot.txt.

1
2
3
4
5
6
7
8
Package rosea 1.9.2
Meta description Rosea is a data and execution architecture for
Meta description translating XUML models using Tcl as the implementation
Meta description language.
Meta entrysource rosea.tcl
Meta included    rosea.tcl
Meta platform    tcl
Meta require     {Tcl 8.6}
|







1
2
3
4
5
6
7
8
Package rosea 1.10
Meta description Rosea is a data and execution architecture for
Meta description translating XUML models using Tcl as the implementation
Meta description language.
Meta entrysource rosea.tcl
Meta included    rosea.tcl
Meta platform    tcl
Meta require     {Tcl 8.6}

Changes to rosea/tests/rosea.test.

1
2
3
4
5
6
7
8
9
10
11
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
...
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
....
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
....
3561
3562
3563
3564
3565
3566
3567


3568
3569


3570
3571
3572
3573
3574
3575
3576
....
3654
3655
3656
3657
3658
3659
3660














































3661
3662
3663
3664
3665
3666
3667
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2015 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
................................................................................
                $linkattrs
    }
    
    proc addPartitionDst {domain dstattrs} {
        relvar insert [namespace current]::${domain}::__Arch_PartitionDst\
            $dstattrs
    }
    proc addPolymorphic {domain args} {
        relvar insert [namespace current]::${domain}::__Arch_PolymorphicEvent\
                $args
    }
    
    proc polysignal {srcref dstref event paramlist} {
        puts -nonewline [info level 0]
    }
    proc cleanupConfigData {} {
        set preserved {
            ::rosea::Config::TransitionRule
            ::rosea::Config::SuppliedOperation
            ::rosea::Config::SuppliedInstanceOperation
            ::rosea::Config::SuppliedClassOperation
            ::rosea::Config::Config_AssocSpec
................................................................................
        # the new attributes to have the old attribute names.
        set newvalues [relation update [rosea::InstCmds::deRef $ref Temp Volume]\
                newtuple {1} {
            tuple update $newtuple\
                Temp [expr {[tuple extract $newtuple Temp] + 10}]\
                Volume [expr {[tuple extract $newtuple Volume] * 2.0}]
        }]
        log::debug [relformat $newvalues newvalues]
        set ref [rosea::ClassCmds::update [namespace current]::foo::c1 $newvalues]
        # Extract one of the instances and make sure the attribute values
        # were properly updated.
        pipe {
            rosea::InstCmds::deRef $ref |
            relation restrictwith ~ {$Temp < 200} |
            relation extract ~ Temp Volume
................................................................................
    } -body {
        rosea::InstCmds::delaysignal 100 $ref e1
        set src [rosea::Helpers::nilInstRef]
        set remain [rosea::InstCmds::delayremaining $src $ref e1]
        rosea::InstCmds::canceldelayed $src $ref e1
        expr {$remain <= 100 && $remain >= 95}
    } -result {1}
    test MapPolymorphicEvent-1.0 {
        Map a polymorphic event
    } -setup {
        setupDomain bar
        addClass bar S {S1 int S2 string} S1
        addClass bar X {X1 int X2 string} X1
        addClass bar Y {Y1 int Y2 string} Y1
    
        addAssocLink bar {Name R1 SrcClass X}\
            {Name R1 SrcClass X DstClass S Attrs {X1 S1} PrevSrcClass {}}
        addAssocLink bar {Name R1 SrcClass Y}\
            {Name R1 SrcClass Y DstClass S Attrs {Y1 S1} PrevSrcClass {}}
        relvar eval {
            addParitionLink bar {Name ~R1 SrcClass S}
            addPartitionDst bar {Name ~R1 SrcClass S DstClass X Attrs {S1 X1}}
            addPartitionDst bar {Name ~R1 SrcClass S DstClass Y Attrs {S1 Y1}}
        }
    
        addPolymorphic bar Class S Event e1
        set ref [rosea::ClassCmds::create [namespace current]::bar::S S1 5 S2 baz]
        rosea::ClassCmds::create [namespace current]::bar::X X1 5 X2 bar
    } -cleanup {
        cleanupDomain bar
    } -body {
        rosea::Dispatch::MapPolymorphicEvent [namespace current]::polysignal\
            {} $ref e1 {}
    } -result {true} -output {::rosea::test::polysignal {} {::rosea::test::bar::X {{X1 int} {{X1 5}}}} e1 {}}
    test configure-1.0 {
        Define domain
    } -setup {
    } -cleanup {
        cleanupConfigData
    } -body {
        rosea configure {
................................................................................
        relvar eval {
            set aref [::grocer::Fruit create Name apple Color red]
            ::grocer::SeededFruit create Name apple
            ::grocer::RedFruit create Name apple
        }
    
        set ::rosea::test::states [list]


        rosea tunnel $aref signal grow
        vwait ::rosea::test::states


    
        testConditions\
            {"SeededFruit" in $::rosea::test::states}\
            {"RedFruit" in $::rosea::test::states}
    } -result {1}
    test generate-6.0 {
        signal an assigner
................................................................................
        ::foo::R1 create Name Shoes
        ::foo::R1 signal {Name Shoes} e1
        set timer [after 1000 set ::done TIMEOUT]
        vwait ::done
        after cancel $timer
        set ::done
    } -result {1}














































    test populate-1.0 {
        Populate a domain
    } -setup {
        rosea configure {
            domain meta {
                class C1 {
                    attribute Id string -id 1



|







 







<
<
<
<
<
<
<
<







 







|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>


>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
...
257
258
259
260
261
262
263








264
265
266
267
268
269
270
...
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
....
1365
1366
1367
1368
1369
1370
1371



























1372
1373
1374
1375
1376
1377
1378
....
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
....
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
# DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED FROM A LITERATE PROGRAM SOURCE FILE.
#
# This software is copyrighted 2014-2020 by G. Andrew Mangogna.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
# 
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
................................................................................
                $linkattrs
    }
    
    proc addPartitionDst {domain dstattrs} {
        relvar insert [namespace current]::${domain}::__Arch_PartitionDst\
            $dstattrs
    }








    proc cleanupConfigData {} {
        set preserved {
            ::rosea::Config::TransitionRule
            ::rosea::Config::SuppliedOperation
            ::rosea::Config::SuppliedInstanceOperation
            ::rosea::Config::SuppliedClassOperation
            ::rosea::Config::Config_AssocSpec
................................................................................
        # the new attributes to have the old attribute names.
        set newvalues [relation update [rosea::InstCmds::deRef $ref Temp Volume]\
                newtuple {1} {
            tuple update $newtuple\
                Temp [expr {[tuple extract $newtuple Temp] + 10}]\
                Volume [expr {[tuple extract $newtuple Volume] * 2.0}]
        }]
        log::debug "\n[relformat $newvalues newvalues]"
        set ref [rosea::ClassCmds::update [namespace current]::foo::c1 $newvalues]
        # Extract one of the instances and make sure the attribute values
        # were properly updated.
        pipe {
            rosea::InstCmds::deRef $ref |
            relation restrictwith ~ {$Temp < 200} |
            relation extract ~ Temp Volume
................................................................................
    } -body {
        rosea::InstCmds::delaysignal 100 $ref e1
        set src [rosea::Helpers::nilInstRef]
        set remain [rosea::InstCmds::delayremaining $src $ref e1]
        rosea::InstCmds::canceldelayed $src $ref e1
        expr {$remain <= 100 && $remain >= 95}
    } -result {1}



























    test configure-1.0 {
        Define domain
    } -setup {
    } -cleanup {
        cleanupConfigData
    } -body {
        rosea configure {
................................................................................
        relvar eval {
            set aref [::grocer::Fruit create Name apple Color red]
            ::grocer::SeededFruit create Name apple
            ::grocer::RedFruit create Name apple
        }
    
        set ::rosea::test::states [list]
        rosea trace control clear
        rosea trace control on
        rosea tunnel $aref signal grow
        vwait ::rosea::test::states
        rosea trace control off
        puts [rosea trace format [rosea trace decode all]]
    
        testConditions\
            {"SeededFruit" in $::rosea::test::states}\
            {"RedFruit" in $::rosea::test::states}
    } -result {1}
    test generate-6.0 {
        signal an assigner
................................................................................
        ::foo::R1 create Name Shoes
        ::foo::R1 signal {Name Shoes} e1
        set timer [after 1000 set ::done TIMEOUT]
        vwait ::done
        after cancel $timer
        set ::done
    } -result {1}
    test generate-6.2 {
        delete a multi assigner
    } -setup {
        rosea configure {
            domain foo {
                class Customer {
                    attribute Name string -id 1
                }
                class Clerk {
                    attribute Name string -id 1
                    attribute Customer string
                    attribute Department string
                    reference R1 Customer -link {Customer Name}
                    reference R2 Department -link {Department Name}
                }
                class Department {
                    attribute Name string -id 1
                }
                association R1 Clerk 0..1--0..1 Customer
                association R2 Clerk 1..*--1 Department
                assigner R1 {
                    identifyby Department
                    state s1 {a b} {
                        puts $a $b
                    }
                    transition s1 - e1 -> s2
    
                    state s2 {} {
                        puts "in s2"
                            set ::done 1
                    }
                    transition s2 - e1 -> s1
                }
            }
        }
        rosea generate
    } -cleanup {
        cleanupConfigData
        removeDomain ::foo
    } -body {
        ::foo::R1 create Name Shoes
        ::foo::R1 delete Name Shoes
        ::foo::R1 signal {Name Shoes} e1
    } -result\
        {unknown assigner instance, "Name Shoes", for relationship, "::foo::R1"}\
        -returnCodes error
    test populate-1.0 {
        Populate a domain
    } -setup {
        rosea configure {
            domain meta {
                class C1 {
                    attribute Id string -id 1