FRODO Version 2.19.1
An open-source framework for Distributed Constraint Optimization (DCOP)
Loading...
Searching...
No Matches
frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable > Class Template Reference

Protocol to elect a variable. More...

Inheritance diagram for frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >:

Public Member Functions

 VariableElection (DCOPProblemInterface<?, ?> problem, ScoringHeuristic< S > heuristic, int nbrSteps)
 Constructor.
 VariableElection (DCOPProblemInterface<?, ?> problem, Element parameters) throws Exception
 Constructor from XML descriptions.
Collection< MessageTypegetMsgTypes ()
 Listens to messages of types LeaderElectionMaxID.START_MSG_TYPE and LeaderElectionMaxID.LE_MSG_TYPE.
void notifyIn (Message msg)
 The actual algorithm.
void setQueue (Queue queue)
void sendMessageToSelf (Message msg)
 Method called by the LeaderElectionMaxID listeners to send their outputs.
Public Member Functions inherited from frodo2.communication.Queue
 Queue (boolean measureMsgs)
 Constructor.
 Queue (boolean measureMsgs, boolean init)
 Constructor.
void toBeClosedUponKill (QueueInputPipeInterface input)
 Reminds the queue to close the given pipe when it is killed.
void removeInputPipe (QueueInputPipeInterface input)
 Removes the given input pipe from the list of input pipes.
void addOutputPipe (Object recipient, QueueOutputPipeInterface output)
 Adds an output pipe to this queue.
QueueOutputPipeInterface getOutputPipe (Object recipient)
 Returns the output pipe corresponding to the given recipient.
void removeOutputPipe (Object recipient)
 Removes the output pipe corresponding to the given recipient.
QueueIOPipe addOutputQueue (Object recipient, Queue queue)
 Adds a new output pipe to the provided queue.
void addIncomingMessagePolicy (IncomingMsgPolicyInterface< MessageType > policy)
 Adds a listener to be notified of new incoming messages.
void addIncomingMessagePolicy (Collection< MessageType > msgTypes, IncomingMsgPolicyInterface< MessageType > policy)
 Adds a listener to be notified of new incoming messages.
void addIncomingMessagePolicy (MessageType type, IncomingMsgPolicyInterface< MessageType > policy)
 Adds a listener to be notified of new incoming messages of type type.
void addOutgoingMessagePolicy (OutgoingMsgPolicyInterface< MessageType > policy)
 Adds a listener to be notified of new outgoing messages.
void addOutgoingMessagePolicy (Collection< MessageType > msgTypes, OutgoingMsgPolicyInterface< MessageType > policy)
 Adds a listener to be notified of new outgoing messages.
void addOutgoingMessagePolicy (MessageType type, OutgoingMsgPolicyInterface< MessageType > policy)
 Adds a listener to be notified of new outgoing messages of type type.
void addToInbox (MessageWrapper msg)
 Adds the input message to this queue's inbox.
void sendMessage (Object to, Message msg)
 Sends a message to a specified recipient.
void sendMessage (Object to, MessageWrapper msgWrap)
 Send a message that has already been wrapped.
void end ()
 Kills the queue, making it unusable.
void run ()
 Continuously processes all messages in the inbox.
void deleteIncomingMessagePolicy (IncomingMsgPolicyInterface< MessageType > policy)
 Completely removes the input policy from all lists of listeners.
void deleteStatsReporters ()
 Delete all StatsReporters.
void deleteOutgoingMessagePolicy (OutgoingMsgPolicyInterface< MessageType > policy)
 Completely removes the outgoing message policy from all lists of listeners.
void cleanQueue ()
 Removes all messages from the inbox.
void setProblem (ProblemInterface<?, ?> problem)
 Sets the problem that is queried for NCCCs.
void updateNCCCs (long msgNCCCs)
 Updates the queue's NCCC counter to the input count if the input is greater.
long getCurrentTime ()
int getInboxSize ()
MessageWrapper getCurrentMessageWrapper ()
HashMap< MessageType, Integer > getMsgNbrs ()
HashMap< Object, Integer > getMsgNbrsSent ()
HashMap< MessageType, Long > getMsgSizes ()
HashMap< Object, Long > getMsgSizesSent ()
HashMap< MessageType, Long > getMaxMsgSizes ()
void resetStats ()
 Resets the metrics statistics.
void resetMsgSizeMonitor ()
 Closes the MsgSizeMonitor and creates a new one.
Public Member Functions inherited from frodo2.communication.IncomingMsgPolicyInterface< T >
default void notifyIn (Message msg, Object toAgent)
 Notifies the listener of an incoming message.

Static Public Attributes

static MessageType START_MSG_TYPE = AgentInterface.START_AGENT
 The type of the message telling the module to start.
static MessageType FINISH_MSG_TYPE = AgentInterface.AGENT_FINISHED
 The type of the message telling the agent finished.

Protected Member Functions

 VariableElection (DCOPProblemInterface<?, ?> problem)
 Incomplete constructor to be used by overriding classes.
LeaderElectionMaxID< S > newListener (String var, S score, Collection< String > neighbors)
 Instantiates a new LeaderElectionMaxID.
Protected Member Functions inherited from frodo2.communication.Queue
 Queue ()
 Empty constructor that does absolutely nothing.
void notifyInListeners (Message msg, Object toAgent)
 Notifies the incoming message listeners of a message.
boolean notifyOutListeners (Object fromAgent, Message msg, Collection<? extends Object > toAgents)
 Notifies the outgoing message listeners of a message.
void recordStats (Object to, Message msg)
 Records statistics about the input message.

Protected Attributes

int nbrSteps
 The number of steps the protocol should run before it terminates.
ScoringHeuristic< S > heuristic
 The heuristic.
Protected Attributes inherited from frodo2.communication.Queue
Set< QueueInputPipeInterfaceinputs
 List of input pipes.
HashMap< Object, QueueOutputPipeInterfaceoutputs
 Map associating an output pipe to each destination ID.
MsgSizeMonitor monitor
 A monitor used to measure the sizes of the messages.
HashMap< MessageType, ArrayList< IncomingMsgPolicyInterface< MessageType > > > inPolicies
 A list of listeners notified of incoming objects.
HashMap< MessageType, ArrayList< OutgoingMsgPolicyInterface< MessageType > > > outPolicies
 A list of listeners notified of outgoing messages.
ProblemInterface<?, ?> problem
 The problem used to obtain the current NCCC count.
final boolean measureMsgs
 Whether to measure the number of messages and the total amount of information sent.
HashMap< MessageType, Integer > msgNbrs
 For each message type, the number of messages sent of that type.
HashMap< MessageType, Long > msgSizes
 For each message type, the total amount of information sent in messages of that type, in bytes.
HashMap< MessageType, Long > maxMsgSizes
 For each message type, the size (in bytes) of the largest message of that type.
MessageWrapper msgWrap
 The last wrapped message to have been received.

Package Functions

public< R extends Object > void sendMessageToMulti (Collection< R > recipients, Message msg)
 Method called by the LeaderElectionMaxID listeners in order to send a message to specified variables.
Package Functions inherited from frodo2.communication.Queue
public< T extends Object > void sendMessageToMulti (Collection< T > recipients, Message msg)
 Sends a message to all specified recipients.

Private Member Functions

void init ()
 Parses the problem.
void reset ()
 Resets all problem-dependent fields (except the problem itself).

Private Attributes

Queue queue
 The queue on which it should call sendMessage().
DCOPProblemInterface<?, ?> problem
 The problem.
boolean started = false
 Whether the execution of the algorithm has started.
Map< String, ArrayList< LeaderElectionMaxID< S > > > neighborhoods
 For each variable (internal or external), the list of internal variables connected to it.
Map< String, String > owners = new HashMap<String, String> ()
 For each known variable, the name of the agent that owns it.
Collection< LeaderElectionMaxID< S > > listeners
 The LeaderElectionMaxID listeners corresponding to this agent's variables.

Additional Inherited Members

Static Public Member Functions inherited from frodo2.communication.Queue
static String networkToDOT (Queue[] queues)
 Generates a String representation in DOT format of a network of queues.

Detailed Description

Protocol to elect a variable.

Contrary to LeaderElectionMaxID, this protocol elects a variable rather than an agent. The advantage is that it works when agents' subproblems have disconnected components. The implementation actually uses LeaderElectionMaxID, by treating each variable as an agent.

Author
Thomas Leaute
Parameters
<S>the type used for the variables' scores
Note
S must properly override equals(Object) and hashCode().

Constructor & Destructor Documentation

◆ VariableElection() [1/3]

frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.VariableElection ( DCOPProblemInterface<?, ?> problem,
ScoringHeuristic< S > heuristic,
int nbrSteps )

Constructor.

Parameters
problemthe problem
heuristicthe heuristic
nbrStepsnumber of steps the protocol should run before it terminates
Warning
nbrSteps must be an upper bound on the diameter of the largest component in the constraint graph for the algorithm to work properly.

References heuristic, nbrSteps, and problem.

Referenced by VariableElection().

◆ VariableElection() [2/3]

frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.VariableElection ( DCOPProblemInterface<?, ?> problem,
Element parameters ) throws Exception

Constructor from XML descriptions.

Parameters
problemdescription of the problem
parametersdescription of the parameters of this protocol
Exceptions
Exceptionif an error occurs
Warning
nbrSteps must be an upper bound on the total number of variables for the algorithm to work properly.

References problem, and VariableElection().

Here is the call graph for this function:

◆ VariableElection() [3/3]

frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.VariableElection ( DCOPProblemInterface<?, ?> problem)
protected

Incomplete constructor to be used by overriding classes.

Parameters
problemthe agent's problem

References problem.

Member Function Documentation

◆ getMsgTypes()

◆ init()

void frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.init ( )
private

◆ newListener()

LeaderElectionMaxID< S > frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.newListener ( String var,
S score,
Collection< String > neighbors )
protected

Instantiates a new LeaderElectionMaxID.

Parameters
varthe variable
scorethe score
neighborsthe variable's neighbors
Returns
a new LeaderElectionMaxID

References nbrSteps.

Referenced by init().

◆ notifyIn()

void frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.notifyIn ( Message msg)

The actual algorithm.

Listens to messages sent by LeaderElectionMaxID listeners, and notifies this agent's own LeaderElectionMaxID listeners.

Parameters
msgthe message that was just received

Implements frodo2.communication.IncomingMsgPolicyInterface< T >.

References frodo2.communication.MessageType.equals(), FINISH_MSG_TYPE, init(), notifyIn(), and START_MSG_TYPE.

Referenced by notifyIn().

Here is the call graph for this function:

◆ reset()

void frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.reset ( )
private

Resets all problem-dependent fields (except the problem itself).

◆ sendMessageToMulti()

public< R extends Object > void frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.sendMessageToMulti ( Collection< R > recipients,
Message msg )
package

Method called by the LeaderElectionMaxID listeners in order to send a message to specified variables.

If multiple variables are owned by the same agent, the message is only sent once to that agent.

See also
Queue#sendMessageToMulti(Collection, Message)

References owners, and queue.

◆ sendMessageToSelf()

void frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.sendMessageToSelf ( Message msg)

Method called by the LeaderElectionMaxID listeners to send their outputs.

See also
Queue.sendMessageToSelf(Message)

Reimplemented from frodo2.communication.Queue.

References queue.

◆ setQueue()

void frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.setQueue ( Queue queue)
See also
IncomingMsgPolicyInterface.setQueue(Queue)

Implements frodo2.communication.MessageListener< T >.

References frodo2.communication.Queue.Queue(), queue, and setQueue().

Referenced by setQueue().

Here is the call graph for this function:

Member Data Documentation

◆ FINISH_MSG_TYPE

MessageType frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.FINISH_MSG_TYPE = AgentInterface.AGENT_FINISHED
static

The type of the message telling the agent finished.

Referenced by getMsgTypes(), and notifyIn().

◆ heuristic

ScoringHeuristic<S> frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.heuristic
protected

The heuristic.

Referenced by init(), and VariableElection().

◆ listeners

Collection< LeaderElectionMaxID<S> > frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.listeners
private

The LeaderElectionMaxID listeners corresponding to this agent's variables.

Referenced by init().

◆ nbrSteps

int frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.nbrSteps
protected

The number of steps the protocol should run before it terminates.

Referenced by newListener(), and VariableElection().

◆ neighborhoods

Map< String, ArrayList< LeaderElectionMaxID<S> > > frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.neighborhoods
private
Initial value:
=
new HashMap < String, ArrayList< LeaderElectionMaxID<S> > > ()

For each variable (internal or external), the list of internal variables connected to it.

Referenced by init().

◆ owners

Map<String, String> frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.owners = new HashMap<String, String> ()
private

For each known variable, the name of the agent that owns it.

Referenced by sendMessageToMulti().

◆ problem

DCOPProblemInterface<?, ?> frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.problem
private

The problem.

Referenced by init(), VariableElection(), VariableElection(), and VariableElection().

◆ queue

Queue frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.queue
private

The queue on which it should call sendMessage().

Referenced by sendMessageToMulti(), sendMessageToSelf(), and setQueue().

◆ START_MSG_TYPE

MessageType frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.START_MSG_TYPE = AgentInterface.START_AGENT
static

The type of the message telling the module to start.

Referenced by getMsgTypes(), and notifyIn().

◆ started

boolean frodo2.algorithms.varOrdering.election.VariableElection< S extends Comparable< S > &Serializable >.started = false
private

Whether the execution of the algorithm has started.


The documentation for this class was generated from the following file: