Package dissemination
Class DisseminationEngine
- java.lang.Object
-
- dissemination.DisseminationEngine
-
public class DisseminationEngine extends java.lang.ObjectResponsible for adding dissemination information to States.
-
-
Constructor Summary
Constructors Constructor Description DisseminationEngine(java.util.List<State> states)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<State>calculateDissemination()Attaches dissemination information to the states that have been passed in the contstructor.private booleanexchange(UserStatePair pair)Performs data exchange between two users.java.util.List<TrainState>findEligibleAgents(java.util.List<UserState> states)Given a list of UserStates, the method finds agents that are eligible for data transfer.java.util.List<UserStatePair>pairAgents(TrainState train)Given a train of users, this method finds pairs of users who have and those who do not have the data.private voidpersistDataTransfer(State exchangeState, UserState receiverState)Marks given user as a data carrier in every state where the user appears.voidsetStates(java.util.List<State> states)Set states for the dissemination engine.
-
-
-
Field Detail
-
RANDOM
private static final java.util.Random RANDOM
-
states
private java.util.List<State> states
-
-
Constructor Detail
-
DisseminationEngine
public DisseminationEngine(java.util.List<State> states)
-
-
Method Detail
-
calculateDissemination
public java.util.List<State> calculateDissemination()
Attaches dissemination information to the states that have been passed in the contstructor. For each state, it checks eligible agents, pairs the agents and exchanges information between them.- Returns:
- The modified state array.
-
findEligibleAgents
public java.util.List<TrainState> findEligibleAgents(java.util.List<UserState> states)
Given a list of UserStates, the method finds agents that are eligible for data transfer.Eligible means, that they are currently on the very end of their current leg and have not yet exchanged data.
- Parameters:
states- The list of UserStates to check- Returns:
- A list of TrainStates which represent users travelling together in the same train - and eligible for transfer.
-
pairAgents
public java.util.List<UserStatePair> pairAgents(TrainState train)
Given a train of users, this method finds pairs of users who have and those who do not have the data.- Parameters:
train- The TrainState of users.- Returns:
- A list of UserStatePairs.
-
exchange
private boolean exchange(UserStatePair pair)
Performs data exchange between two users.Exchange is performed with a given probability and may fail. It will also fail, if the sender has no data to share or the receiver already has this data.
- Parameters:
pair- Pair of users, one of which is a data sender, another one is a receiver- Returns:
- True if the data exchange succeeded, false otherwise
-
persistDataTransfer
private void persistDataTransfer(State exchangeState, UserState receiverState)
Marks given user as a data carrier in every state where the user appears.- Parameters:
receiverState- Data receiverexchangeState- State when the data exchange happens
-
setStates
public void setStates(java.util.List<State> states)
Set states for the dissemination engine.- Parameters:
states- The states to work on.
-
-