Revision 182:593e57d264a4

View differences:

src/main/java/cz/agents/dimaptools/search/HeuristicOpenList.java
16 16
    private final HeuristicInterface requestHeuristic;
17 17
    
18 18
    private final boolean usePreferred;
19
//    private boolean choosePreferred = false;
19
    private final boolean recomputeHeuristiconReceive;
20 20
    
21 21
    private int openPriority = 0;
22 22
    private int preOpenPriority = 0;
23 23
    
24
    public HeuristicOpenList(String label,boolean usePreferred, HeuristicInterface heuristic) {
25
    	this(label,usePreferred,heuristic,heuristic);
24
    public HeuristicOpenList(String label,boolean usePreferred, HeuristicInterface heuristic, boolean recomputeHeuristiconReceive) {
25
    	this(label,usePreferred,heuristic,heuristic, recomputeHeuristiconReceive);
26 26
    }
27 27
    
28
	public HeuristicOpenList(String label,boolean usePreferred, HeuristicInterface heuristic, HeuristicInterface requestHeuristic) {
28
	public HeuristicOpenList(String label,boolean usePreferred, HeuristicInterface heuristic, HeuristicInterface requestHeuristic, boolean recomputeHeuristiconReceive) {
29 29
		super();
30 30
		this.label = label;
31 31
		this.heuristic = heuristic;
32 32
		this.requestHeuristic = requestHeuristic;
33 33
		this.usePreferred = usePreferred;
34
		this.recomputeHeuristiconReceive = recomputeHeuristiconReceive;
34 35
		
35 36
		open = new PriorityBlockingQueue<SearchState>();
36 37
		preOpen = new PriorityBlockingQueue<SearchState>();
......
46 47
		return usePreferred;
47 48
	}
48 49
	
50
	public boolean recomputeHeuristicOnReceive(){
51
		return recomputeHeuristiconReceive;
52
	}
53
	
49 54
	public SearchState pollOpen(){
50 55
		
51 56
			if(usePreferred){
src/main/java/cz/agents/dimaptools/search/MultiheuristicDistributedBestFirstSearch.java
47 47

  
48 48
    }
49 49

  
50
    protected void addReceivedState(StateMessage sm, String sender){
51
        SearchState newState = new SearchState(problem.initState.getDomain(),sm,sender);
52
        for(HeuristicOpenList open : openLists){
53
            open.add(newState,sm.isPreferred());
54
        }
55
    }
56

  
57

  
50
    
58 51
    private boolean allListsEmpty(){
59 52
        for(HeuristicOpenList open : openLists){
60 53
            if(!open.isEmpty()){
......
63 56
        }
64 57
        return true;
65 58
    }
59
    
60
    protected void addReceivedState(final StateMessage sm, String sender){
61
    	final SearchState newState = new SearchState(problem.initState.getDomain(),sm,sender);
62
    	
63
    	if(recomputeHeuristicOnReceive){ //should be probably done for projected heuristics
64
    		for(final HeuristicOpenList open : openLists){
65
                open.getHeuristic(newState, new HeuristicComputedCallback() {
66
    				
67
    				@Override
68
    				public void heuristicComputed(HeuristicResult result) {
69
    					open.add(newState,sm.isPreferred());
70
    				}
71
    			});
72
            }
73
    	}else{
74
    		for(HeuristicOpenList open : openLists){
75
                open.add(newState,sm.isPreferred());
76
            }
77
    	}
78
    }
66 79

  
67 80
    @Override
68 81
    protected void readConfiguration(ConfigurationInterface config){
69 82

  
70 83
        if(config.containsKey("heuristic") && !config.containsKey("requestHeuristic")){
71 84
            boolean usePreferred = config.containsKey("preferred") ? (Boolean)config.getObject("preferred") : false;
72
            openLists.add(new HeuristicOpenList("heuristic",usePreferred, (HeuristicInterface) config.getObject("heuristic")));
85
            openLists.add(new HeuristicOpenList("heuristic",usePreferred, (HeuristicInterface) config.getObject("heuristic"),config.getBoolean("recomputeHeuristicOnReceive", false)));
73 86
            return;
74 87
        }
75 88

  
76 89
        if(config.containsKey("heuristic") && config.containsKey("requestHeuristic")){
77 90
            boolean usePreferred = config.containsKey("preferred") ? (Boolean)config.getObject("preferred") : false;
78
            openLists.add(new HeuristicOpenList("heuristic",usePreferred, (HeuristicInterface) config.getObject("heuristic"), (HeuristicInterface) config.getObject("requestHeuristic")));
91
            openLists.add(new HeuristicOpenList("heuristic",usePreferred, (HeuristicInterface) config.getObject("heuristic"), (HeuristicInterface) config.getObject("requestHeuristic"),config.getBoolean("recomputeHeuristicOnReceive", false)));
79 92
            return;
80 93
        }
81 94

  
82 95
        for(String key : config.getKeyList()){
83
            if(!key.equals("preferred") && !key.equals("openSelectionStrategy")){
96
            if(!key.equals("preferred") && !key.equals("openSelectionStrategy") && !key.equals("recomputeHeuristicOnReceive")){
84 97
                openLists.add((HeuristicOpenList)config.getObject(key));
85 98
            }
86 99
        }
87 100
        
88 101
        strategy = OpenSelectionStrategy.valueOf(config.getString("openSelectionStrategy", OpenSelectionStrategy.ALTERNATE.name()));
89 102
        
90
        recomputeHeuristicOnReceive = config.getBoolean("recomputeHeuristicOnReceive", false);
91 103

  
92 104
    }
93 105

  
src/main/java/cz/agents/dimaptools/search/SearchState.java
75 75
        parentAction = new ParentAction(sender);
76 76
        parentActionOwner = sender;
77 77
        wasReachedByPublicAction = false;
78
        createdByPreferred = msg.isPreferred();
78 79

  
79 80
        // cost
80 81
        this.g = msg.getG();
src/test/java/cz/agents/dimaptools/multiheuristic/TestFFHeuristicM.java
27 27
	public void runSearch(DIMAPWorldInterface world){
28 28
		MultiheuristicDistributedBestFirstSearch search = new MultiheuristicDistributedBestFirstSearch(world);
29 29

  
30
		HeuristicOpenList hFF = new HeuristicOpenList("hFF",true,new RelaxationHeuristic(world.getProblem(),new FFEvaluator(world.getProblem())));
30
		HeuristicOpenList hFF = new HeuristicOpenList("hFF",true,new RelaxationHeuristic(world.getProblem(),new FFEvaluator(world.getProblem())),false);
31 31

  
32 32
		search.plan(new MapConfiguration("hFF",hFF), searchCallback);
33 33
	}
src/test/java/cz/agents/dimaptools/multiheuristic/TestFFrdFFHeuristicM.java
30 30
    public void runSearch(DIMAPWorldInterface world){
31 31
        MultiheuristicDistributedBestFirstSearch search = new MultiheuristicDistributedBestFirstSearch(world);
32 32

  
33
        HeuristicOpenList hFF = new HeuristicOpenList("hFF",true,new RelaxationHeuristic(world.getProblem(), new FFEvaluator(world.getProblem())));
33
        HeuristicOpenList hFF = new HeuristicOpenList("hFF",true,new RelaxationHeuristic(world.getProblem(), new FFEvaluator(world.getProblem())),false);
34 34

  
35
        new HeuristicOpenList("hAdd",false,new RelaxationHeuristic(world.getProblem(),new AddEvaluator(world.getProblem(),false)));
35
        new HeuristicOpenList("hAdd",false,new RelaxationHeuristic(world.getProblem(),new AddEvaluator(world.getProblem(),false)),false);
36 36
//		HeuristicOpenList hAdd = new HeuristicOpenList("hAdd",false,new RelaxationHeuristic(world.getProblem(),new AddEvaluator(world.getProblem(),false)));
37 37

  
38 38
        RecursiveDistributedRelaxationRequestHeuristic req = new RecursiveDistributedRelaxationRequestHeuristic(world, new FFEvaluator(world.getProblem()));
39 39
        RecursiveDistributedRelaxationReplyHeuristic rep = new RecursiveDistributedRelaxationReplyHeuristic(world, new FFEvaluator(world.getProblem()),req.getRequestProtocol());
40 40
        req.setReplyProtocol(rep.getReplyProtocol());
41 41

  
42
        HeuristicOpenList hrdFF = new HeuristicOpenList("hrdFF",true,req,rep);
42
        HeuristicOpenList hrdFF = new HeuristicOpenList("hrdFF",true,req,rep,false);
43 43

  
44 44
//		search.plan(new MapConfiguration("hFF",hFF,"hAdd",hAdd), searchCallback);
45 45

  
src/test/java/cz/agents/dimaptools/multiheuristic/TestFFrdFFHeuristicMPrefference.java
31 31
    public void runSearch(DIMAPWorldInterface world){
32 32
        MultiheuristicDistributedBestFirstSearch search = new MultiheuristicDistributedBestFirstSearch(world);
33 33

  
34
        HeuristicOpenList hFF = new HeuristicOpenList("hFF",true,new RelaxationHeuristic(world.getProblem(), new FFEvaluator(world.getProblem())));
34
        HeuristicOpenList hFF = new HeuristicOpenList("hFF",true,new RelaxationHeuristic(world.getProblem(), new FFEvaluator(world.getProblem())),false);
35 35

  
36
        new HeuristicOpenList("hAdd",false,new RelaxationHeuristic(world.getProblem(),new AddEvaluator(world.getProblem(),false)));
36
        new HeuristicOpenList("hAdd",false,new RelaxationHeuristic(world.getProblem(),new AddEvaluator(world.getProblem(),false)),false);
37 37
//		HeuristicOpenList hAdd = new HeuristicOpenList("hAdd",false,new RelaxationHeuristic(world.getProblem(),new AddEvaluator(world.getProblem(),false)));
38 38

  
39 39
        RecursiveDistributedRelaxationRequestHeuristic req = new RecursiveDistributedRelaxationRequestHeuristic(world, new FFEvaluator(world.getProblem()));
40 40
        RecursiveDistributedRelaxationReplyHeuristic rep = new RecursiveDistributedRelaxationReplyHeuristic(world, new FFEvaluator(world.getProblem()),req.getRequestProtocol());
41 41
        req.setReplyProtocol(rep.getReplyProtocol());
42 42

  
43
        HeuristicOpenList hrdFF = new HeuristicOpenList("hrdFF",true,req,rep);
43
        HeuristicOpenList hrdFF = new HeuristicOpenList("hrdFF",true,req,rep,false);
44 44

  
45 45
//		search.plan(new MapConfiguration("hFF",hFF,"hAdd",hAdd), searchCallback);
46 46

  

Also available in: Unified diff