Sep 2015 Collections of Cars - Gnorion/BizVR GitHub Wiki
Solutions
Collections of CarsGiven an arbitrary number of collections of cars, find the set of cars that is common to all collections (based on make and model):
Also:
Identify cars that do not exist in any other collection Solve for two collections first, then if possible generalize your solution to handle any number of collections Optional: For each collection of cars eliminate all but the most expensive instance of each make and model (assume an attribute for price)
Introduction
The way the data is organized can have a significant impact on how you model the rules. Two solutions are presented based on different data models. Part I uses an N:N association data model and that leads to a very simple rule model. Part II uses a “flat” record oriented data model and converts the flat data into structured data (using 1:N associations).
Part I Association Model
The Vocabulary
Let’s assume that the same car type (make and model) can be a member of one or more groups. So make and model are not duplicated but are referenced by (or associated with) the groups they belong to. This is how several of the other solutions interpreted it. This can be modeled as a many-to-many association In part II I’ll discuss an alternative way to model this that does allow make and model to be repeated as they are in the sample data (possibly with different pricing). This becomes clearer if you add the vehicle VIN to the model.
The Rule Sheet
Normally you’d divide up a problem into a number of rule sheets to make it easier for humans to understand the logic, but for this example we’ll do it all in one rule sheet to save space. Here’s the natural language view of the decision table. It expresses how a human might describe the problem and its solution. It’s written from the point of view of an individual car type. Its automatically applied to all car types or groups as appropriate. And here is one possible implementation: