/*******************************************************************************
 * Copyright (C) 2013  Stefan Schroeder
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 3.0 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package basics.algo;

import java.util.Collection;

import org.apache.log4j.Logger;

import basics.VehicleRoutingAlgorithm;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.algo.SearchStrategy.DiscoveredSolution;

public class TimeBreaker implements PrematureAlgorithmBreaker, AlgorithmStartsListener{

	private static Logger logger = Logger.getLogger(TimeBreaker.class);
	
	private double timeThreshold;
	
	private double startTime;
	
	public TimeBreaker(double time) {
		super();
		this.timeThreshold = time;
		logger.info("initialise " + this);
	}
	
	@Override
	public String toString() {
		return "[name=TimeBreaker][timeThreshold="+timeThreshold+"]";
	}

	@Override
	public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) {
		if((System.currentTimeMillis() - startTime)/1000.0 > timeThreshold) return true;
		return false;
	}
	
	@Override
	public void informAlgorithmStarts(VehicleRoutingProblem problem,VehicleRoutingAlgorithm algorithm,Collection<VehicleRoutingProblemSolution> solutions) {
		startTime = System.currentTimeMillis();
	}

}

@@ -1137,229 +1137,728 @@
 n;%0A%0A
-public class TimeBreaker implements PrematureAlgorithmBreaker, AlgorithmStartsListener%7B%0A%0A%09private static Logger logger = Logger.getLogger(TimeBreaker.class);%0A%09%0A%09private double timeThreshold;%0A%09%0A%09private double startTime;%0A%09
+/**%0A * Breaks algorithm prematurely based on specified time.%0A * %0A * %3Cp%3ENote, TimeBreaker must be registered as AlgorithmListener %3Cbr%3E%0A * %3Ccode%3Eagorithm.getAlgorithmListeners().addListener(this);%3C/code%3E%0A * %0A * @author stefan%0A *%0A */%0Apublic class TimeBreaker implements PrematureAlgorithmBreaker, AlgorithmStartsListener%7B%0A%0A%09private static Logger logger = Logger.getLogger(TimeBreaker.class);%0A%09%0A%09private double timeThreshold;%0A%09%0A%09private double startTime;%0A%09%0A%09/**%0A%09 * Constructs TimeBreaker that breaks algorithm prematurely based on specified time.%0A%09 * %0A%09 * %3Cp%3ENote, TimeBreaker must be registered as AlgorithmListener %3Cbr%3E%0A%09 * %3Ccode%3Eagorithm.getAlgorithmListeners().addListener(this);%3C/code%3E%0A%09 * %0A%09 * @author stefan%0A%09 *%0A%09 */
 %0A%09pu
@@ -1885,16 +1885,27 @@
 ble time
+_in_seconds
 ) %7B%0A%09%09su
@@ -1938,16 +1938,27 @@
 d = time
+_in_seconds
 ;%0A%09%09logg

change para-name in constructor to specify time