Revision 175:df20f493a3dc

View differences:

src/main/java/cz/agents/dimaptools/search/BestFirstSearch.java
35 35
    private final TIntHashSet closed = new TIntHashSet();
36 36

  
37 37
    private HeuristicInterface heuristic;
38
    
39
    private int maxG = 0;
40
    private int minH = Integer.MAX_VALUE;
38 41

  
39 42

  
40 43

  
......
72 75

  
73 76
            try {
74 77
                state = open.poll(1, TimeUnit.DAYS);
78
                
79
                
80
	            if(state.getHeuristic() < minH){
81
	              	minH = state.getHeuristic();
82
	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new minimal [" + state.getParentActionOwner() + "] /h/: " + minH);
83
	            }
84
	            if(state.getG() > maxG){
85
	               	maxG = state.getG();
86
	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new maximal [" + state.getParentActionOwner() + "] /g/: " + maxG);
87
	            }
88
                
75 89
            } catch (InterruptedException e) {
76 90
                planFoundCallback.planNotFound();
77 91
                LOGGER.fatal("Search timeout!", e);
......
101 115
                    @Override
102 116
                    public void heuristicComputed(HeuristicResult result) {
103 117
                        state.setHeuristics(result.getValue());
104

  
118
                        
105 119
                        Set<SearchState> expandedStates = expand(state);
106 120
                        open.addAll(expandedStates);
107 121
                    }
src/main/java/cz/agents/dimaptools/search/DistributedBestFirstSearch.java
62 62
    protected volatile boolean run = true;
63 63
    protected volatile boolean search = true;
64 64

  
65
	protected int minH = Integer.MAX_VALUE;
66
	protected int maxG = 0;
67

  
65 68

  
66 69

  
67 70

  
......
145 148
        do {
146 149
            if(!open.isEmpty() && search) {
147 150
                final SearchState state = open.poll();
151
                
152
                if(state.getHeuristic() < minH){
153
	              	minH = state.getHeuristic();
154
	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new minimal [" + state.getParentActionOwner() + "] /h/: " + minH);
155
	            }
156
	            if(state.getG() > maxG){
157
	               	maxG = state.getG();
158
	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new maximal [" + state.getParentActionOwner() + "] /g/: " + maxG);
159
	            }
148 160

  
149 161
                if (state != null && !closed.contains(state.hashCode())) {
150 162

  
src/main/java/cz/agents/dimaptools/search/MultiheuristicDistributedBestFirstSearch.java
96 96
                final SearchState state;
97 97

  
98 98
                state = openLists.get(currentOpenList).pollOpen();
99
                
100
                if(state.getHeuristic() < minH){
101
	              	minH = state.getHeuristic();
102
	               	if(LOGGER.isInfoEnabled())LOGGER.info("Reached new minimal [" + state.getParentActionOwner() + "] /h/: " + minH);
103
	            }
104
	            if(state.getG() > maxG){
105
	               	maxG = state.getG();
106
	               	if(LOGGER.isInfoEnabled())LOGGER.info("Reached new maximal [" + state.getParentActionOwner() + "] /g/: " + maxG);
107
	            }
99 108

  
100 109
                if (state != null && !closed.contains(state.hashCode())) {
101 110

  
......
154 163
                                    return;
155 164
                                }
156 165

  
157
                                if(result.getValue() < SearchState.getBestHeuristicSoFar()){
166
                                if(result.getValue() < minH){
158 167
                                    //System.out.println("found best state: " + result.getValue() + "("+stateIsPreferred+")");
159 168
                                    open.boost(stateIsPreferred);
160 169
                                }
src/main/java/cz/agents/dimaptools/search/SearchState.java
13 13

  
14 14
    private final static Logger LOGGER = Logger.getLogger(SearchState.class);
15 15

  
16
    private static int maxG = 0;
17
    private static int minH = Integer.MAX_VALUE;
18

  
19 16
    private final int g;
20 17
    private int h;
21 18
    private boolean createdByPreferred = false;
......
62 59
        // cost
63 60
        g = parentAction.parentState.g + searchAction.getPrice();
64 61

  
65
		if (g > maxG) {
66
			maxG = g;
67
			if(LOGGER.isInfoEnabled())LOGGER.info("Reached new maximal [" + searchAction.getOwner() + "] /g/: " + g);
68
		}
69

  
70 62
		//heuristic (lazy)
71 63
		h = parentAction.parentState.h;
72 64
    }
......
109 101
			System.out.println("!!!");
110 102
		}
111 103
       h = heuristicValue;
112
       if (h < minH) {
113
           minH = h;
114
           if(LOGGER.isInfoEnabled())LOGGER.info("Reached new minimal [" + this.getDomain().agent  + "] /h/: " + h + (createdByPreferred?" (P) ":""));//+ ", state:"+this);
115
       }
116 104
    }
117 105

  
118 106
    public boolean wasReachedByPublicAction() {
......
178 166
		return parentActionOwner;
179 167
	}
180 168
	
181
	public static int getBestHeuristicSoFar(){
182
		return minH;
183
	}
184

  
185

  
169
	
186 170
	public ParentState reconstructPlan(List<String> plan) {
187 171
		return parentAction.reconstructPlan(plan);
188 172
	}
src/main/java/cz/agents/dimaptools/search/SyncDistributedBestFirstSearch.java
65 65
	private boolean heuristicComputed;
66 66
	private SearchState state;
67 67

  
68
	protected int minH = Integer.MAX_VALUE;
69
	protected int maxG = 0;
70

  
68 71

  
69 72

  
70 73

  
......
148 151
        do {
149 152
            if(!open.isEmpty() && search) {
150 153
                state = open.poll();
154
                
155
                if(state.getHeuristic() < minH){
156
	              	minH = state.getHeuristic();
157
	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new minimal [" + state.getParentActionOwner() + "] /h/: " + minH);
158
	            }
159
	            if(state.getG() > maxG){
160
	               	maxG = state.getG();
161
	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new maximal [" + state.getParentActionOwner() + "] /g/: " + maxG);
162
	            }
151 163

  
152 164
                if (state != null && !closed.contains(state.hashCode())) {
153 165

  

Also available in: Unified diff