Revision 110:471538c48893

View differences:

src/main/java/cz/agents/dimaptools/landmarks/LMCutHeuristic.java
2 2

  
3 3
import java.util.LinkedList;
4 4
import java.util.List;
5
import java.util.Map;
5 6

  
6 7
import org.apache.log4j.Logger;
7 8

  
......
70 71
	    List<UnaryOperator> cut = new LinkedList<UnaryOperator>();
71 72
	    LinkedList<Proposition> secondExplorationQueue = new LinkedList<Proposition>();
72 73
	    firstExploration(state);
74
	    printEQ(state);
73 75
	    // validate_h_max();  // too expensive to use even in regular debug mode
74 76
	    if (artificialGoal.cost == -1){
75 77
	        callback.heuristicComputed(new HeuristicResult(LARGE_HEURISTIC,null));
......
83 85
	        //cout << "total_cost = " << total_cost << "..." << endl;
84 86
//	        mark_goal_plateau(&artificial_goal);
85 87
	        
86
	        secondExploration(state, secondExplorationQueue, cut);
88
	        //secondExploration
89
	        findCut(state, secondExplorationQueue, cut);
87 90
	        
88 91
	        if(cut.isEmpty()){
89 92
	        	LOGGER.warn("Cut is empty!");
......
105 108
	        //cout << "{" << cut_cost << "}" << flush;
106 109
	        totalCost += cut_cost;
107 110

  
108
	        firstExplorationIncremental(cut);
111
	        //firstExplorationIncremental
112
	        recomputeHMax(cut);
113
	        printEQ(state);
109 114
	        // validate_h_max();  // too expensive to use even in regular debug mode
110 115
	        // TODO: Need better name for all explorations; e.g. this could
111 116
	        //       be "recompute_h_max"; second_exploration could be
......
150 155
				System.out.println("!");
151 156
			}
152 157

  
153
			if(p.cost < p.distance) continue;
158
//			if(p.cost < p.distance) continue;
154 159

  
155 160
//			if(artificialGoal.cost >= 0){
156 161
//				return;
......
170 175
		}
171 176
	}
172 177
	
173
	private void firstExplorationIncremental(List<UnaryOperator> cut) {
178
	private void printEQ(State state){
179
		String out = "--- Exploration Queue: ---";
180
		
181
		int cost = 0;
182
		boolean empty = false;
183
		
184
		while(!empty){
185
			empty = true;
186
			
187
			String O = "";
188
			for(UnaryOperator op : operators){
189
				if(op.cost == cost){
190
					empty = false;
191
					O = O + " [";
192
					for(Proposition p : op.precondition) O = O + "(" + p.var + "=" + p.val + ")";
193
					O = O + "-->(" + op.effect.var + "=" + op.effect.val + ")]:"+op.operatorsIndex+"("+op.cost+") " ;
194
				}
195
			}
196
			out += "\n" + O;
197
			
198
			String P = "";
199
			for(Map<Integer,Proposition> map : propositions.values()){
200
				for(Proposition p : map.values()){
201
					if(p.cost == cost){
202
						empty = false;
203
						P = P + " [" + p.var + "=" + p.val + "]:"+p.cost + " ";
204
					}
205
				}
206
			}
207
			if(cost == artificialGoal.cost){
208
				P = P + " [" + artificialGoal.var + "=" + artificialGoal.val + "]:"+artificialGoal.cost + " ";
209
			}
210
			out += "\n" + P;
211
			
212
			++cost;
213
			
214
			
215
		}
216
		
217
		out += "\n --- --- ---";
218
		LOGGER.info(out);
219
		
220
	}
221
	
222
	private void recomputeHMax(List<UnaryOperator> cut) {
174 223
		
175 224
		for (UnaryOperator op : cut) {
176 225
	        int cost = op.hMaxSupporterCost + op.cost;
......
184 233
		while(!explorationQueue.isEmpty()){
185 234
			Proposition p = explorationQueue.poll();
186 235

  
187
			if(p.cost < p.distance) continue;
236
//			if(p.cost < p.distance) continue;
188 237

  
189 238
			//trigger operators
190 239
			for(UnaryOperator op : p.preconditionOf){
......
212 261
	}
213 262
	
214 263

  
215
	private void secondExploration(State state,LinkedList<Proposition> secondExplorationQueue,List<UnaryOperator> cut) {
264
	private void findCut(State state,LinkedList<Proposition> secondExplorationQueue,List<UnaryOperator> cut) {
216 265
		for(UnaryOperator op : operators){
217 266
			if(op.precondition.size() == 0){
218 267
				secondExplorationQueue.push(op.effect);
src/main/java/cz/agents/dimaptools/relaxed/UnaryOperator.java
34 34

  
35 35
	public void updateHMaxSupporter() {
36 36
		for (Proposition p : precondition){
37
	        if (p.distance > hMaxSupporter.distance){
37
	        if (p.cost > hMaxSupporter.cost){
38 38
	        	hMaxSupporter = p;
39 39
	        }
40 40
		}
41
		hMaxSupporterCost = hMaxSupporter.distance;
41
		hMaxSupporterCost = hMaxSupporter.cost;
42 42
	}
43 43

  
44 44

  

Also available in: Unified diff