Download Heuristic Algorithms for NP
Transcript
94
API Manual
E.5
New GUI Problems
Given that one has created a new NPCProblem for the model, one can incorporate
it in the GUI as follows.
For each NPCProblem one has to make a new class which inherits GUIProblem.
The generic parameter of this class must take the NPCProblem class, which we
want to represent.
Secondly it must have two constructors. The first is for user defined instances
and must take no arguments. The second constructor is for transformed instances and must take the instance, a reference to the GUIProblem it was transformed from and the Method, which should be used for detransformation.
Inheriting GUIProblem requires one to implement the method consoleInput(String),
which is for handling the commands issued from the GUI console.
To control how an instance is visualized, one has to override the method paint(Graphics)
as one usually would.
Continuing with the previous example one would get the following code:
1
public class GUIWHCycl e extends GUIProblem < WeightedHa m il t o nC y cl e <
XPoint > >{
2
3
4
public G U I W H a m i l t o n C y c l e () {
super ( G U I W H a m i l t o n C y c l e . class , W e i g h t e d H a m i l t o n C y c l e . class )
;
}
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public G U I W H a m i l t o n C y c l e ( WeightedHa m i lt o nC y c le < XPoint > w ,
GUIProble m parent , Method dt ) {
super ( G U I W H a m i l t o n C y c l e . class , w , parent , dt ) ;
}
public boolean c o n s o l e I n p u t ( String command ) {
// parse and obey command
// return false if it was a invalid command
}
public void paint ( Graphics g ) {
super . paint ( g ) ; problem . draw ( g ) ;
}
public String toString () { return " W H a m i l t o n C y c l e " ;}
}