Assigned: Wednesday, February 12, 2020,
Due: Monday, March 2, 2020 at 1:30pm.

The goal of this assignment is to add a constraint solver to your retained object model. This will allow arbitrary constraints to be added to the objects, to keep them connected.

Requirements include:

  1. The constraint solver must support constraints expressed on any property of an object, including position properties (X, Y, etc.), color slots, line-thickness, the text string for text objects, etc.
  2. The programmers must be able to write their own constraints -- it is not sufficient for you just to provide a pre-selected set of constraints. So arbitrary code in the constraints must be allowed.
  3. New classes must be able to add new properties which have constraints in and on them. For example, I should be able to create a new class ValueRect as a subclass of OutlineRect that has a new integer property called "value", and then have a constraint on the value slot that computes a new value based on some other properties, and also to have the color of the ValueRect depend on the value with a constraint.
  4. To express your constraints, you can use any mechanism you want. You can use methods, classes, or even an embedded interpretive language. Try to make it easy for programmers to write the constraints.
  5. When a constraint recalculates a property of an object that will affect its appearance, then that object should eventually be redrawn with the new values. This means that you need to make sure values are propogated appropriately through the constraint network.
  6. You can use any of the constraint solving algorithms discussed in class, or make up your own. Recommended choices as constraint solvers are:
    1. Hudson's lazy constraint solver, discussed in class. (This is probably the easiest choice.)
    2. The Amulet constraint solver, which supports pointer variables and dynamically determining the dependency graphs.
    3. Bjorn N. Freeman-Benson and Alan Borning's multi-way constraint solver.
    4. Brad Vander Zanden's sophisticated multi-way constraint solver.
  7. For objects with multiple ways to set the properties, such as lines where you can set the left or the X1, if you implement a one-way constraint system (like A or B above), then you can specify which property can be constrained (e.g., X1, but not left) and say that when there is a constraint, the other property cannot be set. That is, if there is a constraint on the left property of a line that depends on X1 and X2, then setting the left of that line is either a no-op or an error. If you implement a multi-way constraint system (e.g., C or D), then clearly setting any property should appropriately update the others.

Note that these requirements give you much more freedom than homeworks 1 or 2, so you should start early enough to explore which design works best.

Readme file

Please include a readme file in .doc, .txt or .pdf format (note: not .md format) that explains how your constraint system works and how to use it. This document must describe:

I anticipate that this will only take a few pages, so it shouldn't be a big time sink.

Example and Test Programs

In order to give you a head-start, I created modified versions of the top-level classes from Homework2 in both Java and JavaScript, to show one way you might allow there to be constraints on every property of the objects. For example, the code shows that the x value can be a number or else a constraint that calculates a number. In both Java and JavaScript, this can be invisible to code that accesses the x value whether or not there is a constraint there. Since you can provide the constraints in many ways, consider these files just examples, not binding on how you should design or implement your constraints (unlike homework 2).

In the zip file, you will find a test program -- please get the program TestHomework3.java or TestHomework3.js to work, and add in tests to show off all the neat features of your constraint solver. This will also help you document your API for setting up constraints. I will also augment the file with additional tests of my own, so make it clear how to do that.


Back to Homework Overview
Back to 05-830 main page