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

JUnit test for the class VariableElection. More...

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

Public Member Functions

 VariableElectionTest (boolean useTCP, boolean useXML, Class< ? extends ScoringHeuristic<?> > heuristic, Class< ? extends ScoringHeuristic<?> > tiebreaking)
 Constructor that instantiates a test only for the input method.
void testRandom () throws IOException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
 Tests the variable election protocol on a random graph.
Collection< MessageTypegetMsgTypes ()
void notifyIn (Message msg)
 Keeps track of the output of the leader election protocol sent by each variable.
void setQueue (Queue queue)
 Does nothing in this case.
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 Member Functions

static TestSuite suite ()

Protected Member Functions

void setUp ()
void tearDown () throws Exception
 Ends all queues.
void checkOutputs (Class<?> heuristic, Map< String, S > allUniqueIDs)
 Checks that the outputs of the module are consistent with the correct outputs for the given heuristic.
void initiateParamAndListener (XCSPparser< AddableInteger, AddableReal > parser, Class< ? extends ScoringHeuristic<?> > heuristic, Class< ? extends ScoringHeuristic<?> > tiebreaking, int diameter) throws NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
 Initiate the parameter and the listener by reflection.
VariableElection<?> getNewInstance (Constructor<?> constr, Object[] args) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException

Protected Attributes

Map< String, MessageLEoutput< S > > outputs
 For each variable, the output of VariableElection.
int remainingOutputs
 Current number of variables that have not yet sent their output of the leader election protocol.
final ReentrantLock finished_lock = new ReentrantLock ()
 Used to make the test thread wait.
final Condition finished = finished_lock.newCondition()
 Used to wake up the test thread when all agents have finished.
Map< String, Queuequeues
 List of queues, indexed by agent name.
RandGraphFactory.Graph graph
 Random graph used to generate a constraint graph.
Map< String, QueueOutputPipeInterfacepipes
 One output pipe used to send messages to each queue, indexed by the queue's agent name.
boolean useTCP
 true whether TCP pipes should be used instead of QueueIOPipes

Private Attributes

final int maxNbrVars = 12
 Maximum number of variables in the random graph.
final int maxNbrEdges = 30
 Maximum number of edges in the random graph.
final int maxNbrAgents = 4
 Maximum number of agents.
boolean useXML
 Whether we should use the VariableElection constructor that takes in XML elements.
Class< ? extends ScoringHeuristic<?> > heuristic
 The ScoringHeuristic.
Class< ? extends ScoringHeuristic<?> > tiebreaking
 The tie-breaking heuristic.

Detailed Description

JUnit test for the class VariableElection.

Author
Thomas Leaute
Parameters
<S>type used for scores
Bug
Even if all unit tests pass, sometimes a SocketException is thrown. This is because, as soon as a variable receives a MaxIDmsg with an ID higher than its own, it already knows that it is not the leader, and already sends an output message saying it is not the leader. But then it must keep processing MessageMaxIDs until the protocol finishes. Since VariableElectionTest only listens to output messages, it sometimes starts closing queues while MessageMaxIDs are still in the process of being delivered. Solution to fix this: make VariableElectionTest also listen to MessageMaxIDs, and properly compute how many of these messages it must wait for before it can close the queues.

Constructor & Destructor Documentation

◆ VariableElectionTest()

frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.VariableElectionTest ( boolean useTCP,
boolean useXML,
Class< ? extends ScoringHeuristic<?> > heuristic,
Class< ? extends ScoringHeuristic<?> > tiebreaking )

Constructor that instantiates a test only for the input method.

Parameters
useTCPtrue whether TCP pipes should be used instead of QueueIOPipes
useXMLWhether we should use the VariableElection constructor that takes in XML elements
heuristicThe ScoringHeuristic
tiebreakingThe tie-breaking heuristic

References heuristic, tiebreaking, useTCP, and useXML.

Referenced by suite().

Member Function Documentation

◆ checkOutputs()

void frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.checkOutputs ( Class<?> heuristic,
Map< String, S > allUniqueIDs )
protected

◆ getMsgTypes()

◆ getNewInstance()

VariableElection<?> frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.getNewInstance ( Constructor<?> constr,
Object[] args ) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
protected
Parameters
constra constructor of VariableElection type
argsthe argument that will fit in public constructor of VariableElection: a ProblemInterface and a JDOM Element
Returns
a new Instance of VariableElection
Exceptions
InvocationTargetExceptionthrown if the VariableElection constructor throws an exception
IllegalAccessExceptionthrown if the VariableElection class does not have a public constructor that takes in a ProblemInterface and a JDOM Element
InstantiationExceptionwould be thrown if VariableElection were abstract
IllegalArgumentExceptionif the VariableElection constructor does not take the proper arguments

◆ initiateParamAndListener()

void frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.initiateParamAndListener ( XCSPparser< AddableInteger, AddableReal > parser,
Class< ? extends ScoringHeuristic<?> > heuristic,
Class< ? extends ScoringHeuristic<?> > tiebreaking,
int diameter ) throws NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException
protected

Initiate the parameter and the listener by reflection.

Parameters
parserthe problem
heuristica ScoringHeuristic
tiebreakingthe tie-breaking ScoringHeuristic
diameterthe diameter of the problem
Exceptions
NoSuchMethodExceptionthrown if the VariableElection class does not have a public constructor that takes in a ProblemInterface and a JDOM Element
InvocationTargetExceptionthrown if the VariableElection constructor throws an exception
IllegalAccessExceptionthrown if the VariableElection class does not have a public constructor that takes in a ProblemInterface and a JDOM Element
InstantiationExceptionwould be thrown if VariableElection were abstract
IllegalArgumentExceptionif the VariableElection constructor does not take the proper arguments

References frodo2.communication.Queue.addIncomingMessagePolicy(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getSubProblem(), heuristic, queues, frodo2.communication.Queue.setProblem(), and tiebreaking.

Referenced by testRandom().

Here is the call graph for this function:

◆ notifyIn()

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

Keeps track of the output of the leader election protocol sent by each variable.

See also
IncomingMsgPolicyInterface.notifyIn(Message)

Implements frodo2.communication.IncomingMsgPolicyInterface< T >.

References frodo2.communication.MessageType.equals(), notifyIn(), and frodo2.algorithms.varOrdering.election.LeaderElectionMaxID< T extends Comparable< T > &Serializable >.OUTPUT_MSG_TYPE.

Referenced by notifyIn().

Here is the call graph for this function:

◆ setQueue()

void frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.setQueue ( Queue queue)

Does nothing in this case.

Parameters
queuethe queue

Implements frodo2.communication.MessageListener< T >.

◆ setUp()

void frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.setUp ( )
protected
See also
junit.framework.TestCase#setUp()

References frodo2.algorithms.RandGraphFactory.getRandGraph(), graph, maxNbrAgents, maxNbrEdges, and maxNbrVars.

Here is the call graph for this function:

◆ suite()

TestSuite frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.suite ( )
static
Returns
the test suite for this test

References VariableElectionTest().

Referenced by frodo2.algorithms.varOrdering.election.tests.AllTestsElection.suite().

Here is the call graph for this function:

◆ tearDown()

void frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.tearDown ( ) throws Exception
protected

Ends all queues.

See also
junit.framework.TestCase#tearDown()

References graph, outputs, pipes, and queues.

◆ testRandom()

void frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.testRandom ( ) throws IOException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException

Tests the variable election protocol on a random graph.

Exceptions
IOExceptionthrown if the method fails to create pipes
NoSuchMethodExceptionthrown if the VariableElection class does not have a public constructor that takes in a ProblemInterface and a JDOM Element
InvocationTargetExceptionthrown if the VariableElection constructor throws an exception
IllegalAccessExceptionthrown if the VariableElection class does not have a public constructor that takes in a ProblemInterface and a JDOM Element
InstantiationExceptionwould be thrown if VariableElection were abstract
IllegalArgumentExceptionif the VariableElection constructor does not take the proper arguments

References frodo2.communication.Queue.addIncomingMessagePolicy(), checkOutputs(), frodo2.algorithms.test.AllTests.createQueueNetwork(), frodo2.algorithms.test.AllTests.generateProblem(), frodo2.solutionSpaces.ProblemInterface< V extends Addable< V >, U extends Addable< U > >.getAgents(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getDomain(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getDomainSize(), frodo2.solutionSpaces.ProblemInterface< V extends Addable< V >, U extends Addable< U > >.getDomClass(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getProbabilitySpacePerRandVar(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getRandVars(), frodo2.algorithms.heuristics.ScoringHeuristic< S extends Comparable< S > &Serializable >.getScores(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getSolutionSpaces(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getSubProblem(), frodo2.solutionSpaces.ProblemInterface< V extends Addable< V >, U extends Addable< U > >.getUtilClass(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getVariables(), frodo2.solutionSpaces.DCOPProblemInterface< V extends Addable< V >, U extends Addable< U > >.getVarScopes(), graph, heuristic, initiateParamAndListener(), outputs, frodo2.algorithms.XCSPparser< V extends Addable< V >, U extends Addable< U > >.parse(), pipes, queues, frodo2.communication.Queue.setProblem(), frodo2.algorithms.XCSPparser< V extends Addable< V >, U extends Addable< U > >.setUtilClass(), frodo2.algorithms.AgentInterface< V extends Addable< V > >.START_AGENT, testRandom(), useTCP, and useXML.

Referenced by testRandom().

Here is the call graph for this function:

Member Data Documentation

◆ finished

final Condition frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.finished = finished_lock.newCondition()
protected

Used to wake up the test thread when all agents have finished.

◆ finished_lock

final ReentrantLock frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.finished_lock = new ReentrantLock ()
protected

Used to make the test thread wait.

◆ graph

RandGraphFactory.Graph frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.graph
protected

Random graph used to generate a constraint graph.

Referenced by checkOutputs(), setUp(), tearDown(), and testRandom().

◆ heuristic

Class< ? extends ScoringHeuristic<?> > frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.heuristic
private

◆ maxNbrAgents

final int frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.maxNbrAgents = 4
private

Maximum number of agents.

Referenced by setUp().

◆ maxNbrEdges

final int frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.maxNbrEdges = 30
private

Maximum number of edges in the random graph.

Referenced by setUp().

◆ maxNbrVars

final int frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.maxNbrVars = 12
private

Maximum number of variables in the random graph.

Note
Must be at least 2.

Referenced by setUp().

◆ outputs

Map< String, MessageLEoutput<S> > frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.outputs
protected

For each variable, the output of VariableElection.

Referenced by checkOutputs(), tearDown(), and testRandom().

◆ pipes

Map<String, QueueOutputPipeInterface> frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.pipes
protected

One output pipe used to send messages to each queue, indexed by the queue's agent name.

Referenced by tearDown(), and testRandom().

◆ queues

Map<String, Queue> frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.queues
protected

List of queues, indexed by agent name.

Referenced by initiateParamAndListener(), tearDown(), and testRandom().

◆ remainingOutputs

int frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.remainingOutputs
protected

Current number of variables that have not yet sent their output of the leader election protocol.

◆ tiebreaking

Class< ? extends ScoringHeuristic<?> > frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.tiebreaking
private

The tie-breaking heuristic.

Referenced by initiateParamAndListener(), and VariableElectionTest().

◆ useTCP

boolean frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.useTCP
protected

true whether TCP pipes should be used instead of QueueIOPipes

Referenced by testRandom(), and VariableElectionTest().

◆ useXML

boolean frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.useXML
private

Whether we should use the VariableElection constructor that takes in XML elements.

Referenced by testRandom(), and VariableElectionTest().


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