Optimizing Multiset Metagrammars. Formal Definitions