Revision 118:d907fbf639a3

View differences:

src/main/java/cz/agents/dimaptools/search/HeuristicOpenList.java
18 18
    private final boolean usePreferred;
19 19
//    private boolean choosePreferred = false;
20 20
    
21
    private int openPriority = 0;
22
    private int preOpenPriority = 0;
23
    private boolean polledPreferred = false;
24
    
21 25
    public HeuristicOpenList(String label,boolean usePreferred, HeuristicInterface heuristic) {
22 26
    	this(label,usePreferred,heuristic,heuristic);
23 27
    }
......
47 51
		
48 52
		
49 53
			
50
//			choosePreferred = !choosePreferred;
51
//			if(usePreferred && choosePreferred && !preOpen.isEmpty()){
52
//				return preOpen.poll(1, TimeUnit.DAYS);
53
//			}else if (!open.isEmpty()){
54
//				return open.poll(1, TimeUnit.DAYS);
55
//			}else if(!preOpen.isEmpty()){
56
//				return preOpen.poll(1, TimeUnit.DAYS);
57
//			}
58
//			return null;
59
			
60 54
			if(usePreferred){
61 55
				if(preOpen.isEmpty())return open.poll();
62 56
				if(open.isEmpty())return preOpen.poll();
63 57
				
64
				SearchState preS = preOpen.peek();
65
				SearchState s = open.peek();
66
				
67
				if(preS.getHeuristic() <= s.getHeuristic()){
58
				if(preOpenPriority >= openPriority){
59
					polledPreferred = true;
60
					--preOpenPriority;
68 61
					return preOpen.poll();
69 62
				}else{
63
					polledPreferred = false;
64
					--openPriority;
70 65
					return open.poll();
71 66
				}
72 67
				
73
//				choosePreferred = !choosePreferred;
74
//				if(choosePreferred){
75
//					return preOpen.poll();
76
//				}else{
77
//					return open.poll();
78
//				}
79 68
				
80 69
			}else{
81 70
				return open.poll();
......
86 75
		
87 76
	}
88 77
	
78
	public boolean polledPreferred() {
79
		return polledPreferred;
80
	}
81
	
82
	public void boost(boolean boostPreferred) {
83
		if(boostPreferred){
84
			preOpenPriority += 1000;  
85
//			System.out.println("boost preferred: " + preOpenPriority + ", normal: " + openPriority);
86
		}else{
87
			openPriority += 1000; 
88
//			System.out.println("boost normal: " + openPriority + ", preferred: " + preOpenPriority);
89
		}
90
	}
91
	
89 92
	public void add(SearchState state, boolean helpful){
90 93
		open.add(state);
91 94
		if(helpful)preOpen.add(state);
......
136 139
		}
137 140
	}
138 141

  
142
	
143

  
144
	
145

  
139 146
}
src/main/java/cz/agents/dimaptools/search/MultiheuristicDistributedAStar.java
4 4
import gnu.trove.TIntObjectHashMap;
5 5

  
6 6
import java.util.ArrayList;
7
import java.util.Arrays;
8 7
import java.util.LinkedList;
9 8
import java.util.List;
10 9

  
......
187 186
                        }
188 187
                    }
189 188
		        	
190
		        	
189
		        	final boolean stateIsPreferred = openLists.get(currentOpenList).polledPreferred();
190
					
191 191
		        	for(final HeuristicOpenList open : openLists){
192 192
		        		
193 193
//		        		LOGGER.info(comm.getAddress() + "("+open.label+") get heuristic of state " + state.hashCode()); 
......
205 205
		                    		LOGGER.info(comm.getAddress() + " LARGE_HEURISTIC");
206 206
		                    		return;
207 207
		                    	}
208
		                    	
209
		                    	if(result.getValue() < SearchState.getBestHeuristicSoFar()){
210
		                    		//System.out.println("found best state: " + result.getValue() + "("+stateIsPreferred+")");
211
		                    		open.boost(stateIsPreferred);
212
		                    	}
213
		                    	
208 214
		                        state.setHeuristics(result.getValue());
209 215
	
210 216
		                        if (state.wasReachedByPublicAction()) {
......
268 274
	 * @param plan
269 275
	 */
270 276
	private void reconstructPlan(SearchState state, List<String> plan){
271
//		System.out.println(comm.getAddress() + " reconstruct " + state.hashCode() + " - " + plan);
277
//		//System.out.println(comm.getAddress() + " reconstruct " + state.hashCode() + " - " + plan);
272 278
		SearchState lastState = state.reconstructPlan(plan);
273 279
        if(lastState.getParentActionOwner() == null){
274 280
        	LOGGER.info(comm.getAddress() + " plan found " + state.hashCode() + " - " + plan);
src/main/java/cz/agents/dimaptools/search/SearchState.java
182 182
	public String getParentActionOwner() {
183 183
		return parentActionOwner;
184 184
	}
185
	
186
	public static int getBestHeuristicSoFar(){
187
		return minH;
188
	}
185 189

  
186 190
}

Also available in: Unified diff