Class Simulation<U extends java.io.Serializable,I extends java.io.Serializable,P>
java.lang.Object
es.uam.eps.ir.relison.diffusion.simulation.Simulation<U,I,P>
- Type Parameters:
U- type of the users.I- type of the information pieces.P- type of the parameter values.
public class Simulation<U extends java.io.Serializable,I extends java.io.Serializable,P>
extends java.lang.Object
Class that stores the evolution of a simulation over time. It just stores the
pieces that are read by the different users in the network.
-
Field Summary
Fields Modifier and Type Field Description private Data<U,I,P>dataData.private intinitialNumberInitial iteration number.private java.util.List<Iteration<U,I,P>>iterationsList of iterations.private intnumIterationsTotal number of iterations in the simulation. -
Constructor Summary
Constructors Constructor Description Simulation(Data<U,I,P> data)Constructor.Simulation(Data<U,I,P> data, int initialNumber)Constructor. -
Method Summary
Modifier and Type Method Description booleanaddIteration(Iteration<U,I,P> iteration)Adds an iteration.Data<U,I,P>getData()Obtains the data for the simulation.SimulationState<U,I,P>getFinalState(UpdateMechanism upd)Finds a final state of the simulation.intgetInitialNumber()Number of the first iteration.Iteration<U,I,P>getIteration(int number)Gets an individual iteration in the simulation.intgetNumIterations()Obtains the current number of iterations in the simulation.private voidupdateDiscarded(Iteration<U,I,P> iteration, java.util.Map<U,java.util.Map<I,java.lang.Long>> propagated, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> discarded, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> received)Updates the values for discarded pieces of information.private voidupdatePropagated(Iteration<U,I,P> iteration, java.util.Map<U,java.util.Map<I,java.lang.Long>> propagated, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> discarded, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> received)Updates the values for propagated pieces of information.private voidupdateReceived(Iteration<U,I,P> iteration, java.util.Map<U,java.util.Map<I,java.lang.Long>> propagated, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> discarded, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> received, UpdateMechanism upd)Updates the values for received pieces of information.
-
Field Details
-
numIterations
private int numIterationsTotal number of iterations in the simulation. -
iterations
private final java.util.List<Iteration<U extends java.io.Serializable,I extends java.io.Serializable,P>> iterationsList of iterations. -
data
Data. -
initialNumber
private final int initialNumberInitial iteration number.
-
-
Constructor Details
-
Simulation
Constructor.- Parameters:
data- the real data.initialNumber- initial iteration number.
-
Simulation
Constructor.- Parameters:
data- the real data
-
-
Method Details
-
addIteration
Adds an iteration. The iteration must have the correct iteration number (initial + number of iterations).- Parameters:
iteration- the iteration to add.- Returns:
- true if the iteration is correctly added, false if it is not.
-
getIteration
Gets an individual iteration in the simulation.- Parameters:
number- the number of the iteration.- Returns:
- the iteration if it exists, null if it does not.
-
getNumIterations
public int getNumIterations()Obtains the current number of iterations in the simulation.- Returns:
- the current number of iterations in the simulation.
-
getData
Obtains the data for the simulation.- Returns:
- the data for the simulation.
-
getInitialNumber
public int getInitialNumber()Number of the first iteration.- Returns:
- the number of the first iteration.
-
getFinalState
Finds a final state of the simulation.- Parameters:
upd- update mechanism.- Returns:
- the final state of the simulation.
-
updatePropagated
private void updatePropagated(Iteration<U,I,P> iteration, java.util.Map<U,java.util.Map<I,java.lang.Long>> propagated, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> discarded, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> received)Updates the values for propagated pieces of information.- Parameters:
iteration- the current iteration.propagated- the set of propagated pieces.discarded- the set of discarded pieces.received- the set of received pieces.
-
updateDiscarded
private void updateDiscarded(Iteration<U,I,P> iteration, java.util.Map<U,java.util.Map<I,java.lang.Long>> propagated, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> discarded, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> received)Updates the values for discarded pieces of information.- Parameters:
iteration- the current iteration.propagated- the set of propagated pieces.discarded- the set of discarded pieces.received- the set of received pieces.
-
updateReceived
private void updateReceived(Iteration<U,I,P> iteration, java.util.Map<U,java.util.Map<I,java.lang.Long>> propagated, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> discarded, java.util.Map<U,java.util.Map<I,Tuple2oo<java.util.Set<U>,java.lang.Long>>> received, UpdateMechanism upd)Updates the values for received pieces of information.- Parameters:
iteration- the current iteration.propagated- the set of propagated pieces.discarded- the set of discarded pieces.received- the set of received pieces.upd- the update mechanism.
-