This is an old version of the class. Please see the 2017 version instead.
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:
- The constraint solver must support constraints expressed on any
property of an object, including position properties (X, Y, etc.), color
slots, line-thickness, etc.
- 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.
- 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.
- 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.
- 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.
- You can use any of the constraint solving algorithms discussed in class,
or make up your own. Recommended choices as constraint solvers are:
- Hudson's lazy constraint solver, discussed in class. (This is probably the easiest choice.)
- The
Amulet constraint solver, which supports pointer variables.
- Bjorn N. Freeman-Benson and Alan Borning's
multi-way constraint solver.
- Brad Vander Zanden's sophisticated
multi-way constraint solver.
- 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:
- Creating nodes as some shape, such as a rectangle.
- Creating an edge
that connects two nodes. For example, you might press down on one node, drag
and release on another node, and an edge will be created between the two
nodes. It must be possible to have multiple edges into and out of a node.
-
It should not be possible to make an edge from a node to itself, or
to make a new edge between two nodes that are already connected. This will
test the extensibility of your create-new-objects behavior objects.
- Moving a node should move all the connected edges.
- Trying to
move an edge should be a no-op (edges cannot be independently moved).
- If you
implement deleting, then deleting a node should delete all the connected
edges.
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