This is an old version of the class. Please see the 2017 version instead.

05-830, User Interface Software, Spring, 2013

Homework 4: Implement a Constraint System for your Retained Object System

18% of grade. Thursday, Mar. 7, 2013 - Thursday, Mar. 28, 2013 extended to: Tuesday, Apr. 9, 2013

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, 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 be redrawn. One way to implement this is that when you invalidate any property on which drawing depends (position, color, line thickness, etc.) as a result of that slot containing a constraint that depends on some other value which changes, then put this property on a list. After the end of the constraint solving phase, then demand all the values on the list. If any value of an object changes, then mark that object for redrawing.
  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.
    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 X, if you implement a one-way constraint system (like A or B above), then you can specify which parameter can be constrained (e.g., X, but not left) and say that when there is a constraint, the other parameter cannot be set. That is, if there is a constraint on the X parameter of a line, 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.

Node-and-Edge Editor

For the last part of the assignment, you will use your GraphicalObjects, constraints, and behavior objects to create a simple node-and-edge drawing editor. You might modify your drawing editor from the previous assignment to create it. The new editor should have the following features, at a minimum:

The user interface is up to you. Most such editors use a tool palette to switch between creating nodes and edges, and being in moving mode. As with the editor in Homework 2, don't spend time on making any controls or widgets, since that will be the next homework.. If it isn't obvious how to use your editor, be sure to display Text objects that document it, preferably outside the drawing area.

In addition, I will be creating constraints of my own to test your designs, so be sure to provide some documentation or comments on how a programmer can create new constraints.

Test Program

Please get the program TestHomework4.java 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. Download and fix up the appropriate file:


Back to Homework Overview
Back to 05-830 main page