Revision 120:e9dc1e18cd90

View differences:

src/main/java/cz/agents/dimaptools/domain/Problem.java
2 2

  
3 3
import gnu.trove.TIntObjectHashMap;
4 4

  
5
import java.util.HashSet;
5 6
import java.util.Set;
6 7

  
7 8

  
......
12 13
    public final SuperState goalSuperState;
13 14
    private final Set<Action> myActions;
14 15
    private final Set<Action> allActions;
16
    private final Set<Action> projectedActions;
15 17
    private final Set<Action> publicActions;
16 18

  
17 19
    private final TIntObjectHashMap allActionMap = new TIntObjectHashMap();
......
26 28
		this.myActions = myActions;
27 29
		this.allActions = allActions;
28 30
		this.publicActions = publicActions;
31
		
32
		projectedActions = new HashSet<Action>(allActions);
33
		projectedActions.removeAll(myActions);
29 34

  
30 35
		for(Action a : allActions){
31 36
			allActionMap.put(a.hashCode(), a);
......
49 54
	public Set<Action> getAllActions() {
50 55
		return allActions;
51 56
	}
57
	
58
	/**
59
	 * Get projections of all public actions owned by other agents.
60
	 * @return
61
	 */
62
	public Set<Action> getProjectedActions() {
63
		return projectedActions;
64
	}
52 65

  
53 66
	/**
54 67
	 * Get all public actions and projections
src/main/java/cz/agents/dimaptools/protocol/DistributedSearchProtocol.java
51 51
	
52 52
	
53 53
	
54
	public void sendStateMessage(StateMessage msg){
54
	public void sendStateMessage(StateMessage msg, String receiver){
55 55
		if(LOGGER.isDebugEnabled())LOGGER.debug(communicator.getAddress() + " send state " + msg);
56 56
		Message message = communicator.createMessage(encoder.encodeStateMessage(msg));
57
        message.addReceiver(CommunicationChannelBroadcast.BROADCAST_ADDRESS);
57
        message.addReceiver(receiver);
58 58
        communicator.sendMessage(message);
59 59
	}
60 60
	
src/main/java/cz/agents/dimaptools/search/DistributedAStar.java
14 14

  
15 15
import cz.agents.alite.communication.CommunicationPerformer;
16 16
import cz.agents.alite.communication.Communicator;
17
import cz.agents.alite.communication.channel.CommunicationChannelBroadcast;
17 18
import cz.agents.alite.configurator.ConfigurationInterface;
18 19
import cz.agents.dimaptools.DIMAPWorldInterface;
19 20
import cz.agents.dimaptools.domain.Action;
......
77 78
			
78 79
			@Override
79 80
			public void receiveStateMessage(StateMessage sm, String sender) {
80
				if (!sender.equals(comm.getAddress())) { //TODO get rid of this expensive and stupid check!
81
				if (!closed.contains(sm.getHash())) { 
81 82

  
82 83
					if(LOGGER.isDebugEnabled())LOGGER.debug(comm.getAddress() + " receive state " + Arrays.toString(sm.getValues()));
83 84

  
......
264 265
		DataAccumulator.getAccumulator().searchMessages ++;
265 266
		DataAccumulator.getAccumulator().totalBytes += msg.getBytes();
266 267

  
267
        protocol.sendStateMessage(msg);
268
		
269
//		protocol.sendStateMessage(msg,CommunicationChannelBroadcast.BROADCAST_ADDRESS);
270
		
271
		//send only to relevant agents
272
		Set<String> sentTo = new HashSet<String>();
273
		for(Action a : problem.getProjectedActions()){
274
			if(!sentTo.contains(a.getOwner()) && a.isApplicableIn(state)){
275
				protocol.sendStateMessage(msg,a.getOwner());
276
				sentTo.add(a.getOwner());
277
			}
278
		}
268 279
    }
269 280

  
270 281
	private Set<SearchState> expand(SearchState state) {
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.HashSet;
7 8
import java.util.LinkedList;
8 9
import java.util.List;
10
import java.util.Set;
9 11

  
10 12
import org.apache.log4j.Logger;
11 13

  
......
69 71
			
70 72
			@Override
71 73
			public void receiveStateMessage(StateMessage sm, String sender) {
72
				if (!sender.equals(comm.getAddress())) { //TODO get rid of this expensive and stupid check!
73

  
74
				if (!closed.contains(sm.getHash())) { 
74 75
//					LOGGER.info(comm.getAddress() + " receive state " + Arrays.toString(sm.getValues()));
75

  
76
					SearchState newState = new SearchState(problem.initState.getDomain(),sm,sender);
76 77
	            	for(HeuristicOpenList open : openLists){
77
	            		SearchState newState = new SearchState(problem.initState.getDomain(),sm,sender); 
78 78
	            		open.add(newState,sm.isPreferred());
79 79
	            	}
80 80
	            }
......
306 306
		DataAccumulator.getAccumulator().searchMessages ++;
307 307
		DataAccumulator.getAccumulator().totalBytes += msg.getBytes();
308 308

  
309
        protocol.sendStateMessage(msg);
309
		//send only to relevant agents
310
		Set<String> sentTo = new HashSet<String>();
311
		for(Action a : problem.getProjectedActions()){
312
			if(!sentTo.contains(a.getOwner()) && a.isApplicableIn(state)){
313
				protocol.sendStateMessage(msg,a.getOwner());
314
				sentTo.add(a.getOwner());
315
			}
316
		}
310 317
    }
311 318

  
312 319
	
src/main/java/cz/agents/dimaptools/search/ParentAction.java
12 12
	
13 13

  
14 14
	public ParentAction(SearchAction action) {
15
		super();
16 15
		this.parentState = action.getParentState();
17 16
		this.label = action.getLabel();
18 17
		this.owner = action.getOwner();
19 18
	}
19
	
20
	
21
	public ParentAction(String owner) {
22
		super();
23
		this.parentState = null;
24
		this.label = null;
25
		this.owner = owner;
26
	}
20 27

  
21 28

  
22 29

  
src/main/java/cz/agents/dimaptools/search/ParentState.java
17 17
	}
18 18

  
19 19
	public ParentState reconstructPlan(List<String> plan) {
20
		if (parentAction == null) {
20
		if (parentAction == null || parentAction.parentState == null) {
21 21
            return this;
22 22
        } else {
23 23
            return parentAction.reconstructPlan(plan);
src/main/java/cz/agents/dimaptools/search/SearchState.java
80 80
    public SearchState(Domain domain, StateMessage msg, String sender) {
81 81
        super(domain,msg.getValues());
82 82

  
83
        parentAction = null;
83
        parentAction = new ParentAction(sender);
84 84
        parentActionOwner = sender;
85 85
        wasReachedByPublicAction = false;
86 86

  

Also available in: Unified diff