icfp-solver/src/main/java/ru/bosony/solvers/AbstractSolver.java
author indvdum (gotoindvdum[at]gmail[dot]com)
Mon, 16 Jul 2012 15:20:48 +0400
branchCleverSearch
changeset 46 4197f736166a
parent 42 2bd032a701a7
child 50 9530f55e9639
permissions -rw-r--r--
Add history of searching
     1 package ru.bosony.solvers;
     2 
     3 import java.util.HashMap;
     4 import java.util.Map;
     5 
     6 import ru.bosony.model.mine.Mine;
     7 
     8 /**
     9  * @author indvdum (gotoindvdum[at]gmail[dot]com) <br>
    10  *         16.07.2012 4:30:47
    11  * 
    12  */
    13 public abstract class AbstractSolver {
    14 
    15 	protected Mine					mine			= null;
    16 	protected SolverListener		listener		= null;
    17 	protected Map<String, Integer>	routesWithScore	= new HashMap<String, Integer>();
    18 	protected long					attemptsCount	= 0;
    19 
    20 	public AbstractSolver(Mine mine, SolverListener listener) {
    21 		this.mine = mine;
    22 		this.listener = listener;
    23 	}
    24 
    25 	protected void addNewRoute(String route, int score) {
    26 		if (!routesWithScore.containsKey(route) && score > getMaxFoundScore()) {
    27 			routesWithScore.put(route, score);
    28 			listener.foundNextRoute(route);
    29 		}
    30 	}
    31 
    32 	protected int getMaxFoundScore() {
    33 		int maxScore = 0;
    34 		for (int foundScore : routesWithScore.values()) {
    35 			if (foundScore > maxScore)
    36 				maxScore = foundScore;
    37 		}
    38 		return maxScore;
    39 	}
    40 
    41 	public abstract void solve();
    42 }