GAMS  1.4.0
gams::elections::ElectionBase Class Referenceabstract

Base class for an election. More...

#include <ElectionBase.h>

Inheritance diagram for gams::elections::ElectionBase:
gams::elections::ElectionCumulative gams::elections::ElectionPlurality

Public Member Functions

 ElectionBase (const std::string &election_prefix="", const std::string &agent_prefix="", madara::knowledge::KnowledgeBase *knowledge=0)
 Constructor. More...
 
virtual ~ElectionBase ()
 Constructor. More...
 
virtual void advance_round (void)
 Proceeds to the next election round in a multi-round election. More...
 
const std::string & get_agent_prefix (void) const
 Gets the prefix for the current agent. More...
 
const std::string & get_election_prefix (void) const
 Gets the prefix for the election in the knowledge base. More...
 
virtual CandidateList get_leaders (int num_leaders=1)=0
 Returns the leaders of the election in order of popularity or whatever conditions constitute winning the election. More...
 
int get_round (void) const
 Retrieves the round number, usually in a multi-round election. More...
 
virtual void get_votes (CandidateVotes &results)
 Gets the votes cast in the election. More...
 
virtual void get_votes (groups::GroupBase *group, CandidateVotes &results)
 Gets the votes cast in the election by a specific group of agents. More...
 
virtual bool has_voted (const std::string &agent_prefix)
 Checks if the agent has voted in this round. More...
 
virtual void reset_round (void)
 Resets the round. More...
 
virtual void set_agent_prefix (const std::string &prefix)
 Sets the prefix for the current bidding agent. More...
 
virtual void set_election_prefix (const std::string &prefix)
 Sets the prefix for the election in the knowledge base. More...
 
virtual void set_knowledge_base (madara::knowledge::KnowledgeBase *knowledge)
 Sets the knowledge base. More...
 
virtual void sync (void)
 Syncs the election information from the knowledge base. More...
 
virtual void vote (const std::string &agent, const std::string &candidate, int votes=1)
 Bids in the election. More...
 
void vote (const std::string &candidate, int votes=1)
 Votes in the election. More...
 

Protected Member Functions

void reset_votes_pointer (void)
 calls a reset on the votes_ location in the knowledge base using election_prefix_ + "." + round_. More...
 

Protected Attributes

std::string agent_prefix_
 self prefix of the agent More...
 
std::string election_prefix_
 the prefix for the election More...
 
madara::knowledge::KnowledgeBase * knowledge_
 The knowledge base to use as a data plane. More...
 
int round_
 the election round in a multi-round election More...
 
madara::knowledge::containers::Map votes_
 convenience class for bids More...
 

Detailed Description

Base class for an election.

Definition at line 82 of file ElectionBase.h.

Constructor & Destructor Documentation

◆ ElectionBase()

gams::elections::ElectionBase::ElectionBase ( const std::string &  election_prefix = "",
const std::string &  agent_prefix = "",
madara::knowledge::KnowledgeBase *  knowledge = 0 
)

Constructor.

Parameters
election_prefixthe name of the election(e.g. election.leader)
agent_prefixthe name of this bidder(e.g. agent.0)
knowledgethe knowledge base to use for syncing

◆ ~ElectionBase()

virtual gams::elections::ElectionBase::~ElectionBase ( )
virtual

Constructor.

Member Function Documentation

◆ advance_round()

virtual void gams::elections::ElectionBase::advance_round ( void  )
virtual

Proceeds to the next election round in a multi-round election.

◆ get_agent_prefix()

const std::string& gams::elections::ElectionBase::get_agent_prefix ( void  ) const

Gets the prefix for the current agent.

Returns
the name of this bidding agent(e.g. agent.0)

◆ get_election_prefix()

const std::string& gams::elections::ElectionBase::get_election_prefix ( void  ) const

Gets the prefix for the election in the knowledge base.

Returns
the name of the election(e.g. election.protectors)

◆ get_leaders()

virtual CandidateList gams::elections::ElectionBase::get_leaders ( int  num_leaders = 1)
pure virtual

Returns the leaders of the election in order of popularity or whatever conditions constitute winning the election.

Parameters
num_leadersmaximum leaders to return
Returns
the leaders of the election up to num_leaders

Implemented in gams::elections::ElectionPlurality, and gams::elections::ElectionCumulative.

◆ get_round()

int gams::elections::ElectionBase::get_round ( void  ) const

Retrieves the round number, usually in a multi-round election.

Returns
the agent prefix of the leader of the election

◆ get_votes() [1/2]

virtual void gams::elections::ElectionBase::get_votes ( CandidateVotes results)
virtual

Gets the votes cast in the election.

Parameters
resultsthe results of the vote

◆ get_votes() [2/2]

virtual void gams::elections::ElectionBase::get_votes ( groups::GroupBase group,
CandidateVotes results 
)
virtual

Gets the votes cast in the election by a specific group of agents.

Parameters
groupthe group that is of interest
resultsthe results of the vote

◆ has_voted()

virtual bool gams::elections::ElectionBase::has_voted ( const std::string &  agent_prefix)
virtual

Checks if the agent has voted in this round.

Parameters
agent_prefixthe participating agent's prefix(e.g. agent.0)
Returns
true if the agent is a member of the election

◆ reset_round()

virtual void gams::elections::ElectionBase::reset_round ( void  )
virtual

Resets the round.

Returns
the agent prefix of the leader of the election

◆ reset_votes_pointer()

void gams::elections::ElectionBase::reset_votes_pointer ( void  )
protected

calls a reset on the votes_ location in the knowledge base using election_prefix_ + "." + round_.

◆ set_agent_prefix()

virtual void gams::elections::ElectionBase::set_agent_prefix ( const std::string &  prefix)
virtual

Sets the prefix for the current bidding agent.

Parameters
prefixthe name of the agent(e.g. agent.0)

◆ set_election_prefix()

virtual void gams::elections::ElectionBase::set_election_prefix ( const std::string &  prefix)
virtual

Sets the prefix for the election in the knowledge base.

Parameters
prefixthe name of the election(e.g. election.protectors)

◆ set_knowledge_base()

virtual void gams::elections::ElectionBase::set_knowledge_base ( madara::knowledge::KnowledgeBase *  knowledge)
virtual

Sets the knowledge base.

Parameters
knowledgethe knowledge base to use for syncing

◆ sync()

virtual void gams::elections::ElectionBase::sync ( void  )
virtual

Syncs the election information from the knowledge base.

◆ vote() [1/2]

virtual void gams::elections::ElectionBase::vote ( const std::string &  agent,
const std::string &  candidate,
int  votes = 1 
)
virtual

Bids in the election.

Parameters
agentthe agent prefix who is bidding
candidatethe candidate receiving votes
votesthe number of votes cast

◆ vote() [2/2]

void gams::elections::ElectionBase::vote ( const std::string &  candidate,
int  votes = 1 
)

Votes in the election.

Uses the agent prefix that has been set in this Election as the voter id.

Parameters
candidatethe candidate receiving votes
votesthe number of votes cast

Member Data Documentation

◆ agent_prefix_

std::string gams::elections::ElectionBase::agent_prefix_
protected

self prefix of the agent

Definition at line 221 of file ElectionBase.h.

◆ election_prefix_

std::string gams::elections::ElectionBase::election_prefix_
protected

the prefix for the election

Definition at line 216 of file ElectionBase.h.

◆ knowledge_

madara::knowledge::KnowledgeBase* gams::elections::ElectionBase::knowledge_
mutableprotected

The knowledge base to use as a data plane.

Definition at line 211 of file ElectionBase.h.

◆ round_

int gams::elections::ElectionBase::round_
protected

the election round in a multi-round election

Definition at line 226 of file ElectionBase.h.

◆ votes_

madara::knowledge::containers::Map gams::elections::ElectionBase::votes_
protected

convenience class for bids

Definition at line 231 of file ElectionBase.h.


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