This manual presents a visualization tool, called VisualCHR, which supports the development of constraint solvers written in the high-level language Constraint Handling Rules (CHR). VisualCHR can be used to debug and to improve the efficency of constraint solvers. It can also be used to understand the details of constraint propagation methods and the interaction of different constraints implemented by means of CHR. Thus, it is suitable for users at different levels of expertise.
Alternatively, VisualCHR can import a graph that reflects an external inference engine's process, provided that this engine can produce a trace, a protocol of its computation steps in a defined format. Regardless whether a graph is internally produced or imported, VisualCHR offers a rich functionality to display, inspect, rearrange, and manipulate it interactively, including means to influence the granularity with which it is displayed and to compactify what is not in the user's current focus of interest.
The VisualCHR program can be started as an applet or application.
The graphical surface elements were implemented by means of Swing components. The classes of these components are in the Java archive swingall.jar, which one can download from the internet pages of the program. This archive should be in the class path of the browser. How this is to be managed is described in the manual of the browser. Alternatively, the Swing classes can also be loaded together with the applet. But note that the archive is about 2,5 MB, which can take 10 minutes or more to download on a slow modem. A third possibility to start the applet in the browser is using the Java plugin. By means of this plugin, one achieves the best performance and the Swing classes are usually installed together with the plugin.
Figure 2.1 shows an error that can occur during loading the applet due to the use of HTTP proxies. In that case, press Yes to try loading the applet again. Otherwise close down the browser and start it again. If the error persists, switch off the HTTP proxie with the browser.
If the VisualCHR program is to be executed as an application to debug one's own JCHR constraint solvers, a Java runtime environment from version 1.1 must be installed on the local computer. Moreover, one needs to install the Swing classes, which are in the Java archive swingall.jar, the classes of the JCHR evaluator in the archive evaluator.jar, and of course the program archive VisualCHR.jar. All these archives and the program to be debugged must be inserted into the class path CLASSPATH of the Java virtual machine (VM).
#!/bin/sh
if [ -z $JAVA_HOME ] ; then
JAVA_HOME=/usr/lib/java
fi
if [ -z $SWING_HOME ] ; then
SWING_HOME=/usr/lib/swing
fi
if [ -z $JCHR_HOME ] ; then
JCHR_HOME=/home/proj/chr/jchr
fi
if [ -z $VCHR_HOME ] ; then
VCHR_HOME=/home/proj/chr/vchr
fi
JAVA_CLASSES=$JAVA_HOME/lib/classes.zip
SWING_CLASSES=$SWING_HOME/swingall.jar
VJCHR_CLASSES=$JCHR_HOME/evaluator.jar:$VCHR_HOME/VisualCHR.jar
SOLVER_CLASSES=.
if [ $@ ] ; then
SOLVER_CLASSES=$@
fi
CLASSPATH=$JAVA_CLASSES:$SWING_CLASSES:$VJCHR_CLASSES:$SOLVER_CLASSES
PARMS= \
\" \
-SKIP_SLEEP 250 \
-COLOR_SCHEME system \
\"
$JAVA_HOME/bin/java -classpath $CLASSPATH visualchr.VisualCHR $PARMS
The program is started by the commandline `java visualchr.VisualCHR'. If the class path CLASSPATH was not updated, one also can do it by means of the Java commandline parameter -classpath. Details can be found in the Java documentation. For VisualCHR there are two commandline parameters, -SKIP_SLEEP n and -COLOR_SCHEME {visualchr | system}. The parameter n indicates the number of the milliseconds which elapse in the case of the Skip step between two evaluation steps. The number should be large enough, so that enough time for the drawing of the graph remains. 250 ms are default. The parameter for -COLOR_SCHEME specifies the color scheme of the user interface, either visualchr for the VisualCHR own color scheme or the default value system for system colors.
Figure 2.2 shows a start script for UNIX systems to help with starting the application. As a commandline parameter for the script, one can specify the path of the JCHR solver to be debugged. Default is the current directory.
If VisualCHR was started successfully, the start screen shown in Figure 2.3 appears.
All graphical elements, i.e. buttons, lists, legends, containing interactive explainations, so called ToolTips. These appear one second after the mouse pointer was moved onto such an element and disappear after about five seconds.
With the applet, only the given example constraint solvers can be debugged. For debugging one's own constraint solvers, VisualCHR has to be executed as application. To load a solver one clicks on Open Solver.
If the applet was used, the dialog box Solver Selection Frame appears as in Figure 2.4. Hide Open closes the dialog box.
From the shortlist Solver Selection one can select an example solver by clicking on it. In the field Solver Description a short description of the selected solver will appear. The selected solver can be loaded by clicking on Load or a double click in the shortlist. The Load button changes to Show Source. A click on this button or onto the selected solver in the shortlist will show the source code of the solver in readonly mode (cf. Figure 2.5).
If the VisualCHR program was started as application, then for loading a solver the dialog shown in Figure 2.6 appears. Take care only to open the *Handler.class files from the JCHR compiler. The path of the solver must be in the class path CLASSPATH. Otherwise the error message of Figure 2.7 appears. The source code of the solver will not be shown.
When clicking the button Show Graph in the main window (cf. Figure 2.3), the Graph Frame (Figure 3.1) appears. The control and the legend bar can be pulled out of the windows to allow for more space for the graph.
The constraint graph grows only downwards. The meaning of its nodes are explained in Figure 3.2.
|
User defined constraints those are in the constraint store. |
|
User defined constraints those were removed from the constraint store. |
|
Predefined constraints. |
|
Constraints those in the store visualization together with the rule led to the new state. |
|
Rule names. |
The graph layout can be changed by the user. Pressing the left mouse button allows for moving a node. The edges will follow. When the window size is changed, clicking on Layout Graph in the menu Modify will recompute the layout.
The control bar contains a selection menu for goals. In the applet version, this list is predefined. In the application version, a goal can be entered manually. Take care of typos. The goal is started by pressing the ENTER key or by clicking Call Goal. Clear Graph aborts the current evaluation and clears the graphical display.
After starting the goal, the goal constraints are inserted into the constraint store, and thus into the graph, too. Next carries out the next evaluation step if evaluation is not yet completed. Skip skips over the step by step evaluation and completely executes the selected goal. After clicking the Skip button, this is transformed into Pause. If it is clicked, the automatic evaluation stops and the button is transformed again into Skip. In order to restart the selected goal one has to click on Call Goal. The functionality of these buttons is also available in the menu Build under similar menu items.
The following figures involves the leq example solver. Figure 3.3 shows the visualisation of constraint goals. Another view of the evaluation is the constraint store view, which is discussed in the next section.
Every large node in the graph stands for an individual constraint. These nodes are called constraint nodes. The small nodes represent the rules and include their names. They are called rule nodes. A mouse click toggles between the display of the rule name and the display of the actual code of the rule.
A rule node connects the constraint nodes which are involved in the application of a CHR rule: The constraints to which the rule is applied lead to the rule, and from the rule there are edges to the constraints that are added by the rule. If a constraint was removed by the rule, the connecting edge is blue. If predefined equality constraints were employed for firing a rule, the edge is gray.
In the leq example, the first row shows the goal constraints leq(X, Y), leq(Z, X) and leq(Y, Z) inserted into the constraint store. In the first step the rule transitivity was applied to the constraints leq(X, Y) and leq(Y, Z) and therefore the new constraint leq(X, Z) has been generated. The two constraints leq(X, Y) and leq(Y, Z) remain in the constraint store. In the second step the rule transitivity was applied, this time to the constraints leq(X, Y) and leq(Z, X), which remain in the store, too. The new constraint leq(Z, Y) is added.
In Figure 3.4 the third step shows the application of the rule antisymmetry applied to the constraints leq(Z, X) and leq(X, Z). These two user defined constraints are eliminated by the rule application from the constraint store. The new predefined constraint Z = X is added.
In the next evaluation step the rule antisymmetry is applied to the two constraints leq(X, Y) and leq(Y, Z). These two constraints are removed by the rule application and the predefined constraint X = Y is inserted.
Figure 3.5 show the state at the last evaluation step. The rule reflexivity is applied to the constraint leq(Z, Y). This constraint is removed and the predefined constraint true is inserted. The application of this rule is possible here since Z = Y holds due to Z = X and X = Y.
All user defined constraints are now marked as removed and only the predefined constraints Z = X, X = Y and true remain. No more rule is now applicable and evaluation terminates. The solution is Z = X and X = Y.
The menu Modify can be used to change to the constraint store view (Figure 3.6). The entire contents of the constraint store after each evaluation step is represented as an individual node. Since all constraints present at one time are shown in own large node, the graph is just a chain of constraint stores and rule applications. Constraints to which a rule was applied are shown in color Fired. Variable bindings are shown in the same color as the predefined equality constraint.
If one clicks with the right mouse button onto a store node, a popup menu appears. If Hide This Store is selected, the clicked node is collapsed to a small hexagon. Hide Recursive Backward or Hide Recursive Forward also collapses all previous or subsequent store nodes, respectively.
If one clicks with the right mouse button onto a collapsed node, another popup menu appears (see Figure 3.6). Un Hide This will unhide all the collapsed store nodes. Un Hide First or Un Hide Last only unhide the first or last hidden node, respectively. Hide Recursive Backward and Hide Recursive Forward work as before. With Hide Previous or Hide Next the previous or next node of the clicked node can be hidden. Manual layout changes go while hiding and again produce lost from nodes, since the size of the nodes changes so strongly, that superpositions would originate inwill be lost while (un)hiding constraints.
Select Constraint Display Options for hiding constraint nodes in the menu Modify. Figure 3.7 shows the resulting dialog box. Two lists are in it, one for user defined, the other for predefined constraints. Constraints are grouped by classes. For example, leq(X, Y) and leq(Y, Z) are of the same class leq.
Only constraints belonging to one class are shown. In order to select all classes one clicks on Select All. For removing all selections, one clicks on Clear Selection. The changes in the graph are made with Apply.
One can also click with the right mouse button directly onto constraint nodes in the graph to hide them. A popup menu will apear with the possibilities to Hide This Constraint or to Hide All Constraints of the same class as the clicked constraint.
Analogous to hiding constraint nodes, rule nodes can be hidden as well. Rules, like constraint nodes, can be hidden in both the constraint goal and the constraint store view. When a rule is hidden, also all the constraints it produced are hidden.
The menu Modify contains the item Rule Display Options. When it is selected, a dialog box as in Figure 3.8 will appear. Only rules will be shown, whose names have been selected in the list Rule Names. The dialog box works analogous to the Constraint Display Options dialog box.
If one clicks with the right mouse button onto a rule node in the graph, a popup menu appears. Options are Hide This Rule and Hide All Rules.
By clicking Show Rules in the main window (Figure 2.3) a window called Rules Frame is opened (Figure 3.9). All rules belonging to the current JCHR constraint solver will be displayed together with their names. Note that the display does not show the actual source code, but rather a normalized version of it as produced by the JCHR compiler.