Revision 195:c200a59cb6a9

View differences:

src/main/java/cz/agents/dimaptools/communication/message/StateMessage.java
14 14
	private final int h;
15 15
	private final int hash;
16 16
	private final boolean preferred;
17
	private final boolean globalH;
17 18

  
18 19

  
19 20
	/**
......
34 35
	 * @param preferred true if expanded by preferred operator
35 36
	 */
36 37
	public StateMessage(int[] values, int g, int h, boolean preferred) {
38
		this(values,g,h,false,preferred);
39
	}
40
	
41
	public StateMessage(int[] values, int g, int h, boolean globalH, boolean preferred) {
37 42
		this.values = values;
38 43
		this.g = g;
39 44
		this.h = h;
40 45
		this.preferred = preferred;
46
		this.globalH = globalH;
41 47

  
42 48
		hash = Arrays.hashCode(values);
43 49
	}
......
61 67
	public boolean isPreferred(){
62 68
		return preferred;
63 69
	}
70
	
71
	public boolean isGlobalH(){
72
		return globalH;
73
	}
64 74

  
65 75
	@Override
66 76
    public int hashCode() {
src/main/java/cz/agents/dimaptools/search/GlobalLocalDistributedBestFirstSearch.java
147 147
    protected void addReceivedState(final StateMessage sm, String sender){
148 148
    	
149 149
    	final SearchState newState = new SearchState(problem.initState.getDomain(),sm,sender);
150
    	
151
    	if(sm.isGlobalH()){
152
    		if(recomputeHeuristicOnReceive){
153
    			localHeuristic.getHeuristic(newState, new HeuristicComputedCallback() {
154
    				
155
    				@Override
156
    				public void heuristicComputed(HeuristicResult result) {
157
    					newState.setHeuristics(Math.max(result.getValue(), sm.getH()));
158
    					openLocal.add(newState);
159
    				}
160
    			});
161
    		}else{
162
    			openLocal.add(newState);
163
    		}
164
    	}else{
165
    		openGlobal.add(new SearchState(problem.initState.getDomain(),sm,sender));
166
    	}
150 167
    		
151
    	localHeuristic.getHeuristic(newState, new HeuristicComputedCallback() {
152
				
153
				@Override
154
				public void heuristicComputed(HeuristicResult result) {
155
					newState.setHeuristics(Math.max(result.getValue(), sm.getH()));
156
					openLocal.add(newState);
157
				}
158
		});
168
    	
159 169
    		
160
    	openGlobal.add(new SearchState(problem.initState.getDomain(),sm,sender));
170
    	
161 171
    	
162 172
    	
163 173
    }
......
233 243
                                    state.setHeuristics(result.getValue());
234 244

  
235 245
                                    if (state.wasReachedByPublicAction()) {
236
                                        sendState(state);
246
                                        sendState(state,true);
237 247
                                    }
238 248

  
239 249
                                    DataAccumulator.getAccumulator().expandedStates++;
......
262 272
        			if (state != null && !closed.contains(localState.hashCode())) {
263 273

  
264 274
                        closed.add(localState.hashCode());
275
                        
276
                        if(state.getG() > maxG){
277
        	               	maxG = state.getG();
278
        	               	if(LOGGER.isInfoEnabled())LOGGER.info(problem.agent + ": Reached new maximal [" + state.getParentActionOwner() + "] /g/: " + maxG);
279
        	            }
265 280

  
266 281
                        if (solutionFound(localState)){
267 282
                            if (localState.wasExpandedByMe(problem.agent)) {
......
286 301
	                            localState.setHeuristics(result.getValue());
287 302
	
288 303
	                            if (localState.wasReachedByPublicAction()) {
289
	                                sendState(localState);
304
	                                sendState(localState,false);
290 305
	                            }
291 306
	
292 307
	                            DataAccumulator.getAccumulator().expandedStates++;
......
390 405
     * Send reached state if reached by public action
391 406
     * @param state
392 407
     */
393
    public void sendState(final SearchState state){
408
    public void sendState(final SearchState state, boolean global){
394 409

  
395 410
        if(sentStates.containsKey(state.hashCode()))return;
396 411
        sentStates.put(state.hashCode(), state);
397 412

  
398
        StateMessage msg = new StateMessage(state.getValues(), state.getG(), state.getHeuristic());
413
        StateMessage msg = new StateMessage(state.getValues(), state.getG(), state.getHeuristic(),global,false);
399 414

  
400 415
        DataAccumulator.getAccumulator().searchMessages ++;
401 416
        DataAccumulator.getAccumulator().totalBytes += msg.getBytes();

Also available in: Unified diff