Revision 196:128b341d4924

View differences:

src/main/java/cz/agents/dimaptools/search/GlobalLocalDistributedBestFirstSearch.java
69 69
    protected volatile boolean run = true;
70 70
    protected volatile boolean search = true;
71 71

  
72
	protected int minH = Integer.MAX_VALUE;
72
	protected int minGH = Integer.MAX_VALUE;
73
	protected int minLH = Integer.MAX_VALUE;
73 74
	protected int maxG = 0;
74 75

  
75 76

  
......
149 150
    	final SearchState newState = new SearchState(problem.initState.getDomain(),sm,sender);
150 151
    	
151 152
    	if(sm.isGlobalH()){
153
    		LOGGER.info(comm.getAddress() + " global h state received!" );
154
    		openGlobal.add(new SearchState(problem.initState.getDomain(),sm,sender));
155
    	}else{
156
//    		LOGGER.info(comm.getAddress() + " local h state received!" );
152 157
    		if(recomputeHeuristicOnReceive){
153 158
    			localHeuristic.getHeuristic(newState, new HeuristicComputedCallback() {
154 159
    				
......
161 166
    		}else{
162 167
    			openLocal.add(newState);
163 168
    		}
164
    	}else{
165
    		openGlobal.add(new SearchState(problem.initState.getDomain(),sm,sender));
166 169
    	}
167 170
    		
168 171
    	
......
206 209
        		if(!openGlobal.isEmpty()){
207 210
        			state = openGlobal.poll();
208 211
        			
209
        			if(state.getHeuristic() < minH){
210
    	              	minH = state.getHeuristic();
211
    	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new minimal [" + state.getParentActionOwner() + "] /h/: " + minH);
212
        			if(state.getHeuristic() < minGH){
213
    	              	minGH = state.getHeuristic();
214
    	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new minimal global [" + state.getParentActionOwner() + "] /h/: " + minGH);
212 215
    	            }
213 216
    	            if(state.getG() > maxG){
214 217
    	               	maxG = state.getG();
......
231 234
                            }
232 235
                        }
233 236
                        
234
                        if(!requestGlobalHeuristic.hasWaitingLocalRequests()){
237
//                        if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": global search - open: " + openGlobal.size());
238
                        
239
                        if(search && !requestGlobalHeuristic.hasWaitingLocalRequests()){
235 240
        	            	requestGlobalHeuristic.getHeuristic(state, new HeuristicComputedCallback(){
236 241

  
237 242
                                @Override
238 243
                                public void heuristicComputed(HeuristicResult result) {
244
//                                	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": global heuristic computed: " + state.hashCode() + "("+result.getValue()+")");
245
                                	
239 246
                                    if(result.getValue() >= HeuristicInterface.LARGE_HEURISTIC){
240 247
                                        return;
241 248
                                    }
......
260 267
        			state = null;
261 268
        		}
262 269
        		
263
        		while(openGlobal.isEmpty() || requestGlobalHeuristic.hasWaitingLocalRequests()){
270
        		boolean local = false;
271
        		
272
        		while(search && (openGlobal.isEmpty() || requestGlobalHeuristic.hasWaitingLocalRequests())){
264 273
        			final SearchState localState;
265 274
        			
266
        			if(state != null){
275
        			
276
        			if(!local && state != null){
277
//        				if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": local state is state, closed: "+closed.contains(state.hashCode()));
267 278
        				localState = state;
268 279
        			}else{
280
        				if(openLocal.isEmpty()){
281
        					break;
282
        				}
269 283
        				localState = openLocal.poll();
270 284
        			}
271 285
        			
272
        			if (state != null && !closed.contains(localState.hashCode())) {
286
        			if (state != null && !(closed.contains(localState.hashCode()) && local)) {
273 287

  
274
                        closed.add(localState.hashCode());
288
//                        closed.add(localState.hashCode());
275 289
                        
290
        				if(state.getHeuristic() < minLH){
291
        	              	minLH = state.getHeuristic();
292
        	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new minimal local [" + state.getParentActionOwner() + "] /h/: " + minLH);
293
        	            }
276 294
                        if(state.getG() > maxG){
277 295
        	               	maxG = state.getG();
278
        	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new maximal [" + state.getParentActionOwner() + "] /g/: " + maxG);
296
        	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new local maximal [" + state.getParentActionOwner() + "] /g/: " + maxG);
279 297
        	            }
280 298

  
281 299
                        if (solutionFound(localState)){
......
289 307
                                search = false;
290 308
                            }
291 309
                        }
310
                        
311
//                        if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": local search - open: " + openLocal.size());
292 312
        			
293 313
		            	localHeuristic.getHeuristic(localState, new HeuristicComputedCallback(){
294 314
	
295 315
	                        @Override
296 316
	                        public void heuristicComputed(HeuristicResult result) {
317
//	                        	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": local heuristic computed: " + state.hashCode() + "("+result.getValue()+")");
318
	                        	
297 319
	                            if(result.getValue() >= HeuristicInterface.LARGE_HEURISTIC){
298 320
	                                return;
299 321
	                            }
......
301 323
	                            localState.setHeuristics(result.getValue());
302 324
	
303 325
	                            if (localState.wasReachedByPublicAction()) {
326
//	                            	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": send locally expanded state! ");
304 327
	                                sendState(localState,false);
305 328
	                            }
306 329
	
......
328 351

  
329 352
                    // let other threads run
330 353
                    Thread.yield();
354
                    
355
                    local = true;
331 356
	            }
332 357
        		
333 358
        		
src/main/java/cz/agents/dimaptools/search/MultiheuristicDistributedBestFirstSearch.java
57 57
        return true;
58 58
    }
59 59
    
60
    //TODO: the information about which heuristic from which open list was computed should be added, 
61
//    otherwise if received state had local heuristic computed, it would dominate the distributed heuristic
62
//    thats also probably why multiheuristic search converges so much towards projected heuristic
60 63
    protected void addReceivedState(final StateMessage sm, String sender){
61 64
    	final SearchState newState = new SearchState(problem.initState.getDomain(),sm,sender);
62 65
    	

Also available in: Unified diff