P2: Writing Constraints and Model-to-Model Transformations in Prolog

Due: Friday, Sept 13, 10pm

Install SWI prolog -- it is native to windows and linux, and may run on Macs.  If you create an empty.pl file and double-click it, SWI prolog should run yielding the window:

This assignment has 3 distinct parts, all of which are aimed at (1) increasing your knowledge of Prolog, (2) understanding the role Prolog can play in defining metamodel constraints and (c) Prolog's role in defining model transformations.


Part 1: Prolog Constraints

You know the schema for FSM which was presented in the previous assignment P1.  You are to enumerate in English and in Prolog each constraint that you feel is appropriate.  Evaluate your constraints on the following FSM databases:

You are to submit:


Part 2: More Constraints

In Lecture MDELite2, I presented a bipartite graph, where all such graphs satisfy two constraints.  That (a)  Unode and Vnode tables have disjoint sets of nodes and (b) that there are no cycles of odd length in such graphs.  Now writing Prolog constraints won't prove either theorem -- all they will show is that the example on which the constraints are applied are valid or not.    Remember it is easy to draw graphs, but they might not be bipartite (even though the metamodel class diagram and constraints say it is so).  Constraints verify that a model conforms to its metamodel.

Your assignment here is to write a Prolog constraint that tests for the absence of acyclicity of odd length.  (The goal of this assignment is for you to understand how Prolog works and this assignment will take you a good part of the way).  Use the following graph to evaluate your algorithm:

  Hint: in my solution, I found it useful to rewrite the theorem predicate in a different (but equivalent) way.  If you get stuck, I'll provide you hints.

You are to submit:


Part 3: M2M Transformations

You may recall that there are two different (but equivalent) schemas for the family database.  We used f1 (below) where father and mother information is stored with each member.  Alternatively, we could have stored father and mother information with each family, f2 (below).  The differences in schemas are shown in the below figure:

Your task is to write Prolog transformations that map an instance (database) of schema f1 to its corresponding instance (database) of schema f2.  You are to start with the Prolog file that I used to map a f1 database to a person database.  You should augment this file with rules that translate f1 family and member tables to f2 family and member tables.  (Hint: map table family to table family2 and table member to table member2, and use the aliasTable to print the right names.  Read the MDELite/Docs pages for further details).


You are to submit: