private SwingBackgroundTask < List < String > > createTask ( final Collection < String > cities ) { final TravellingSalesmanStrategy strategy = strategyPanel . getStrategy ( ) ; return new SwingBackgroundTask < List < String > > ( ) { private long elapsedTime = 0 ; @ Override protected List < String > performTask ( ) { long startTime = System . currentTimeMillis ( ) ; List < String > result = strategy . calculateShortestRoute ( cities , executionPanel ) ; elapsedTime = System . currentTimeMillis ( ) - startTime ; return result ; } @ Override protected void postProcessing ( List < String > result ) { executionPanel . appendOutput ( createResultString ( strategy . getDescription ( ) , result , evaluator . getFitness ( result , null ) , elapsedTime ) ) ; setEnabled ( true ) ; } } ; }
Helper method to create a background task for running the travelling salesman algorithm .