Revision 180:52b404b5bbde

View differences:

src/main/java/cz/agents/dimaptools/search/HeuristicOpenList.java
20 20
    
21 21
    private int openPriority = 0;
22 22
    private int preOpenPriority = 0;
23
    private boolean polledPreferred = false;
24 23
    
25 24
    public HeuristicOpenList(String label,boolean usePreferred, HeuristicInterface heuristic) {
26 25
    	this(label,usePreferred,heuristic,heuristic);
......
49 48
	
50 49
	public SearchState pollOpen(){
51 50
		
52
		
53
			
54 51
			if(usePreferred){
55
				if(preOpen.isEmpty())return open.poll();
56
				if(open.isEmpty())return preOpen.poll();
57 52
				
58
				if(preOpenPriority >= openPriority){
59
					polledPreferred = true;
60
					--preOpenPriority;
61
					return preOpen.poll();
62
				}else{
63
					polledPreferred = false;
53
				if(preOpen.isEmpty()){
64 54
					--openPriority;
65 55
					return open.poll();
66 56
				}
67 57
				
58
				if(open.isEmpty()){
59
					--preOpenPriority;
60
					return preOpen.poll();
61
				}
62

  
63
				if(preOpenPriority >= openPriority){
64
					--preOpenPriority;
65
					return preOpen.poll();
66
				}else{
67
					--openPriority;
68
					return open.poll();
69
				}
68 70
				
69 71
			}else{
70 72
				return open.poll();
71 73
			}
72 74
			
73
			
74
			
75
		
76 75
	}
77 76
	
78
	/*
79
	 * TODO: this does not make sense! if a state is preferred must be determined by which 
80
	 * operator it was created, no form which queue it was pulled 
81
	 * - in normal queue are both preferred and normal states. The way it is implemented, once
82
	 * a queue is polled, it will most probably be always polled (until its empty)
83
	 */
84
	public boolean polledPreferred() {
85
		return polledPreferred;
86
	}
87 77
	
88 78
	public void boost(boolean boostPreferred) {
89 79
		
......
94 84
			openPriority += 1000; 
95 85
//			System.out.println("boost normal: " + openPriority + ", preferred: " + preOpenPriority);
96 86
		}
97
		System.out.println("boost "+label+"("+boostPreferred+"), preferred: " + preOpenPriority + ", normal: " + openPriority);
87
//		System.out.println("boost "+label+"("+boostPreferred+"), preferred: " + preOpenPriority + ", normal: " + openPriority);
98 88
	}
99 89
	
100 90
	public void add(SearchState state, boolean helpful){
src/main/java/cz/agents/dimaptools/search/MultiheuristicDistributedBestFirstSearch.java
156 156

  
157 157

  
158 158

  
159
                    final boolean stateIsPreferred = openLists.get(currentOpenList).polledPreferred();
159
                    final boolean stateIsPreferred = state.wasCreatedByPreferredAction();
160 160
                    
161 161
                    int bestOpenPriority = 0;
162 162
                    
src/test/java/cz/agents/dimaptools/multiheuristic/TestFFrdFFHeuristicMPrefference.java
22 22
//		testProblem("logistics-a2");
23 23
//		testProblem("logistics-a4");
24 24
//		testProblem("deconfliction-a4");
25
		testProblem("rovers-a4");
25
//		testProblem("rovers-a4");
26 26
//		testProblem("sokoban-a1");
27 27
//		testProblem("sokoban-a2");
28 28
    }

Also available in: Unified diff