Revision 174:c7baf146bd0d

View differences:

src/main/java/cz/agents/dimaptools/search/SyncDistributedBestFirstSearch.java
35 35
 * @author stolba
36 36
 *
37 37
 */
38
public class SyncDistributedBestFirstSearch implements SearchInterface {
38
public class SyncDistributedBestFirstSearch implements SearchInterface, HeuristicComputedCallback {
39 39

  
40 40
    private static final Logger LOGGER = Logger.getLogger(SyncDistributedBestFirstSearch.class);
41 41

  
......
63 63
    protected volatile boolean search = true;
64 64

  
65 65
	private boolean heuristicComputed;
66
	private SearchState state;
66 67

  
67 68

  
68 69

  
......
146 147

  
147 148
        do {
148 149
            if(!open.isEmpty() && search) {
149
                final SearchState state = open.poll();
150
                state = open.poll();
150 151

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

  
......
178 179

  
179 180
                    heuristicComputed = false;
180 181
                    
181
                    heuristic.getHeuristic(state, new HeuristicComputedCallback(){
182

  
183
                        @Override
184
                        public void heuristicComputed(HeuristicResult result) {
185
//	                    	heurCount --;
186
//	                    	LOGGER.info(comm.getAddress() + " HEUR-- " + heurCount + ", open:" + open.size());
187

  
188
                            if(result.getValue() >= HeuristicInterface.LARGE_HEURISTIC){
189
                                LOGGER.info(comm.getAddress() + " LARGE_HEURISTIC"+ ", open:" + open.size() + ", state: "+state);
190
                                return;
191
                            }
192
                            state.setHeuristics(result.getValue());
193

  
194
                            if (state.wasReachedByPublicAction()) {
195
                                sendState(state);
196
                            }
197

  
198
                            DataAccumulator.getAccumulator().expandedStates++;
199

  
200
                            Set<SearchState> expandedStates = expand(state);
201
                            open.addAll(expandedStates);
202
                            
203
                            heuristicComputed = true;
204
                        }
205
                    });
182
                    heuristic.getHeuristic(state, this);
206 183

  
207 184
                }
208 185

  
......
241 218

  
242 219
        commPerformer.performClose();
243 220
    }
221
    
222
    @Override
223
	public void heuristicComputed(HeuristicResult result) {
224
    	if(result.getValue() >= HeuristicInterface.LARGE_HEURISTIC){
225
            LOGGER.info(comm.getAddress() + " LARGE_HEURISTIC"+ ", open:" + open.size() + ", state: "+state);
226
            return;
227
        }
228
        state.setHeuristics(result.getValue());
229

  
230
        if (state.wasReachedByPublicAction()) {
231
            sendState(state);
232
        }
233

  
234
        DataAccumulator.getAccumulator().expandedStates++;
235

  
236
        Set<SearchState> expandedStates = expand(state);
237
        open.addAll(expandedStates);
238
        
239
        heuristicComputed = true;
240
		
241
	}
244 242

  
245 243
    /**
246 244
     * Distributed reconstruction of the plan
......
340 338
        return false;
341 339
    }
342 340

  
341
	
342

  
343 343
}
src/test/java/cz/agents/dimaptools/synchronous/TestSynchronousDistributedAStar.java
17 17
//		testProblem("truck-crane-a2");
18 18
//		testProblem("logistics-a2");
19 19
//		testProblem("logistics-a4");
20
		testProblem("deconfliction-a4");
20
//		testProblem("deconfliction-a4");
21 21
//		testProblem("rovers-a4");
22 22
//		testProblem("sokoban-a1");
23 23
//		testProblem("sokoban-a2");

Also available in: Unified diff