54 #ifndef _GAMS_ELECTIONS_ELECTION_BASE_H_
55 #define _GAMS_ELECTIONS_ELECTION_BASE_H_
61 #include "madara/knowledge/KnowledgeBase.h"
62 #include "madara/knowledge/containers/Map.h"
76 typedef std::map <std::string,
92 const std::string & agent_prefix =
"",
93 madara::knowledge::KnowledgeBase * knowledge = 0);
105 virtual bool has_voted(
const std::string & agent_prefix);
138 madara::knowledge::KnowledgeBase * knowledge);
163 void vote(
const std::string & candidate,
int votes = 1);
171 virtual void vote(
const std::string & agent,
172 const std::string & candidate,
int votes = 1);
231 madara::knowledge::containers::Map
votes_;
236 #include "ElectionBase.inl"
Copyright (c) 2016 Carnegie Mellon University.
Copyright(c) 2016 Carnegie Mellon University.
Base class for an election.
virtual void set_knowledge_base(madara::knowledge::KnowledgeBase *knowledge)
Sets the knowledge base.
int round_
the election round in a multi-round election
madara::knowledge::KnowledgeBase * knowledge_
The knowledge base to use as a data plane.
void vote(const std::string &candidate, int votes=1)
Votes in the election.
int get_round(void) const
Retrieves the round number, usually in a multi-round election.
virtual void set_election_prefix(const std::string &prefix)
Sets the prefix for the election in the knowledge base.
madara::knowledge::containers::Map votes_
convenience class for bids
virtual void vote(const std::string &agent, const std::string &candidate, int votes=1)
Bids in the election.
virtual ~ElectionBase()
Constructor.
virtual void sync(void)
Syncs the election information from the knowledge base.
virtual bool has_voted(const std::string &agent_prefix)
Checks if the agent has voted in this round.
virtual void advance_round(void)
Proceeds to the next election round in a multi-round election.
virtual void get_votes(groups::GroupBase *group, CandidateVotes &results)
Gets the votes cast in the election by a specific group of agents.
virtual CandidateList get_leaders(int num_leaders=1)=0
Returns the leaders of the election in order of popularity or whatever conditions constitute winning ...
virtual void reset_round(void)
Resets the round.
virtual void get_votes(CandidateVotes &results)
Gets the votes cast in the election.
std::string election_prefix_
the prefix for the election
const std::string & get_agent_prefix(void) const
Gets the prefix for the current agent.
void reset_votes_pointer(void)
calls a reset on the votes_ location in the knowledge base using election_prefix_ + "....
ElectionBase(const std::string &election_prefix="", const std::string &agent_prefix="", madara::knowledge::KnowledgeBase *knowledge=0)
Constructor.
const std::string & get_election_prefix(void) const
Gets the prefix for the election in the knowledge base.
virtual void set_agent_prefix(const std::string &prefix)
Sets the prefix for the current bidding agent.
std::string agent_prefix_
self prefix of the agent
Base class for a group of agents.
std::vector< std::string > CandidateList
list of candidates
std::map< std::string, madara::knowledge::KnowledgeRecord::Integer > CandidateVotes
candidate vote tally
Contains all GAMS-related tools, classes and code.