Download Heuristic Algorithms for NP
Transcript
E.6 GUI Transformations
E.6
95
GUI Transformations
Making the transformations available in the GUI requires a method for each
transformation. The method must take no arguments and the prefix has to be
”guitransform“.
Before a transformation method had to return a NPCProblem instance, now it
has to return its GUIProblem instance instead.
The way it is done with the previous example is shown below:
1
2
3
4
5
6
7
8
9
10
11
public class G U I W H a m i l t o n C y c l e extends GUIProblem <
WeightedHa m i lt o nC y c le >{
...
public G U I T r a v e l i n g S a l e s m a n g u i t r a n s f o r m T r a v e l i n g S a l e s m a n () {
TravelingSa l es ma n < XPoint > ts = problem . t r a n s f o r m T o T S () ;
Method df = g e t D e t r a n s f o r m a t i o n ( " d e t r a n s f o r m T S " ) ;
return new G U I T r a v e l i n g S a l e s m a n ( ts , this , df ) ;
}
...
}
E.7
GUI Update
In order to display and make the new NPC problems available in GUI on has to
give the topframe the classes as argument. Furthermore one has to inform the
frame how to place the different classes. An example of this is done below.
1
2
3
4
5
6
7
8
9
10
ArrayList < ClassPoint <? extends GUIProblem > > p ;
p = new ArrayList < ClassPoint <? extends GUIProblem > >() ;
// Problems to be shown and used
p . add ( new ClassPoint ( GUIWHCycle . class , 350 , 150) ) ;
p . add ( new ClassPoint ( G U I T r a v e l i n g S a l e s m a n . class , 250 , 200) ) ;
p . add ( new ClassPoint ( G U I H a m i l t o n P a t h . class , 400 , 200) ) ;
...
new M o u n t O l y m p u s ( p ) ;