es.ants.felixgm.trmsim_wsn.trm.powertrust
Class PowerTrust_Sensor

java.lang.Object
  extended by es.ants.felixgm.trmsim_wsn.network.Sensor
      extended by es.ants.felixgm.trmsim_wsn.trm.powertrust.PowerTrust_Sensor
All Implemented Interfaces:
java.lang.Comparable<PowerTrust_Sensor>, java.lang.Runnable

public class PowerTrust_Sensor
extends Sensor
implements java.lang.Comparable<PowerTrust_Sensor>

This class models a Sensor implementing PowerTrust

Since:
0.3
Version:
0.3
Author:
Félix Gómez Mármol, Gregorio Martínez Pérez

Field Summary
protected static int _numSensors
          Number of sensors composing the network this sensor belongs to
protected  double globalReputationScore
          Score v_i
protected  boolean isPowerNode
          Indicates if this sensor is a power node (true) or not (false)
protected  double[] mostRecentFeedbackScoreVector
          Vector s_i
protected  double[] normalizedLocalTrustVector
          Vector r_i
protected  java.util.Collection<Transaction> transactions
          Collection of Transactions this sensor has had
 
Fields inherited from class es.ants.felixgm.trmsim_wsn.network.Sensor
_maxDistance, activeState, collusion, dynamic, id, idCount, links, numRequests, numRequestsThreshold, numRequestsTimer, outcome, requiredService, runningSimulation, servicesGoodness, sleepTimer, sleepTimerAux, transmittedDistance, trmmodelWSN, xPosition, yPosition
 
Constructor Summary
PowerTrust_Sensor()
          This constructor creates a new Sensor implementing PowerTrust
PowerTrust_Sensor(int id, double x, double y)
          This constructor creates a new Sensor implementing PowerTrust
 
Method Summary
 void addNewTransaction(PowerTrust_Sensor client, PowerTrust_Sensor server, Outcome outcome)
          This method adds a new Transaction to the collection of transactions of this sensor
 int compareTo(PowerTrust_Sensor comparedSensor)
          This method compares two PowerTrust sensors according to their global reputation scores
 double computeGlobalReputation()
          This method computes the global retupation of this node according to algorithm 3 of PowerTrust, i.e., v_i = (1-alpha)*sum(v_j*r_{ji})+alpha/m if this sensor is a power node and v_i = (1-alpha)*sum(v_j*r_{ji}), otherwise
 double get_globalReputationScore()
          Returns the current global reputation score v_i^t
 Outcome get_outcome()
          This method returns the last outcome of a performed transaction and, additionally, dynamically selects the new set of m power nodes
 double getNormalizedLocalTrustScore(PowerTrust_Sensor server)
          This method computes the normalized local trust score r_{ij}\in[0,1]
static int getNumSensors()
          Returns the number of sensors composing the network this sensor belongs to
 boolean isPowerNode()
          Indicates if this sensor is a power node (true) or not (false)
 void reset()
          This method resets a Sensor to its initial state
static void setNumSensors(int numSensors)
          Sets the number of sensors composing the network this sensor belongs to
 void setPowerNode(boolean isPowerNode)
          Sets this senor as a power node or not
 
Methods inherited from class es.ants.felixgm.trmsim_wsn.network.Sensor
addLink, addService, addTransmittedDistance, cancelAllTimers, distance, distanceInHops, equals, findSensors, get_goodness, get_numServices, get_requiredService, get_services, get_transmittedDistance, get_TRModel_WSN, getNeighbors, getService, getX, getY, id, isActive, isNeighbor, isRunningSimulation, offersService, offersService, removeAllNeighbors, removeLink, removeService, resetId, run, serve, set_goodness, set_requiredService, set_TRModel_WSN, setActiveState, setCollusion, setDynamic, setMaxDistance, setRunningSimulation, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_numSensors

protected static int _numSensors
Number of sensors composing the network this sensor belongs to


globalReputationScore

protected double globalReputationScore
Score v_i


normalizedLocalTrustVector

protected double[] normalizedLocalTrustVector
Vector r_i


mostRecentFeedbackScoreVector

protected double[] mostRecentFeedbackScoreVector
Vector s_i


transactions

protected java.util.Collection<Transaction> transactions
Collection of Transactions this sensor has had


isPowerNode

protected boolean isPowerNode
Indicates if this sensor is a power node (true) or not (false)

Constructor Detail

PowerTrust_Sensor

public PowerTrust_Sensor()
This constructor creates a new Sensor implementing PowerTrust


PowerTrust_Sensor

public PowerTrust_Sensor(int id,
                         double x,
                         double y)
This constructor creates a new Sensor implementing PowerTrust

Parameters:
id - Identifier of the new sensor
x - X coordinate of the new sensor
y - Y coordinate of the new sensor
Method Detail

reset

public void reset()
Description copied from class: Sensor
This method resets a Sensor to its initial state

Specified by:
reset in class Sensor

getNormalizedLocalTrustScore

public double getNormalizedLocalTrustScore(PowerTrust_Sensor server)
This method computes the normalized local trust score r_{ij}\in[0,1]

Parameters:
server - Server j
Returns:
r_{ij}

computeGlobalReputation

public double computeGlobalReputation()
This method computes the global retupation of this node according to algorithm 3 of PowerTrust, i.e., v_i = (1-alpha)*sum(v_j*r_{ji})+alpha/m if this sensor is a power node and v_i = (1-alpha)*sum(v_j*r_{ji}), otherwise

Returns:
The global reputation of this node after computing it

addNewTransaction

public void addNewTransaction(PowerTrust_Sensor client,
                              PowerTrust_Sensor server,
                              Outcome outcome)
This method adds a new Transaction to the collection of transactions of this sensor

Parameters:
client - The client who requested the service
server - The server who provided the service
outcome - Outcome of the trnsaction to be added

get_outcome

public Outcome get_outcome()
This method returns the last outcome of a performed transaction and, additionally, dynamically selects the new set of m power nodes

Overrides:
get_outcome in class Sensor
Returns:
The last outcome of a performed transaction

compareTo

public int compareTo(PowerTrust_Sensor comparedSensor)
This method compares two PowerTrust sensors according to their global reputation scores

Specified by:
compareTo in interface java.lang.Comparable<PowerTrust_Sensor>
Parameters:
comparedSensor - Sensor to be compared with this sensor
Returns:
1, 0 or -1 if this sensor's global reputation is greater than, equal to, or less than comparedSensor's global reputation

setNumSensors

public static void setNumSensors(int numSensors)
Sets the number of sensors composing the network this sensor belongs to

Parameters:
numSensors - The number of sensors composing the network this sensor belongs to

setPowerNode

public void setPowerNode(boolean isPowerNode)
Sets this senor as a power node or not

Parameters:
isPowerNode - true if this sensor is to be a power node, false otherwise

isPowerNode

public boolean isPowerNode()
Indicates if this sensor is a power node (true) or not (false)

Returns:
true if this sensor is a power node, false otherwise

getNumSensors

public static int getNumSensors()
Returns the number of sensors composing the network this sensor belongs to

Returns:
The number of sensors composing the network this sensor belongs to

get_globalReputationScore

public double get_globalReputationScore()
Returns the current global reputation score v_i^t

Returns:
The current global reputation score v_i^t