GAMS  1.4.0
ElectionBase.h
Go to the documentation of this file.
1 
54 #ifndef _GAMS_ELECTIONS_ELECTION_BASE_H_
55 #define _GAMS_ELECTIONS_ELECTION_BASE_H_
56 
57 #include <vector>
58 #include <string>
59 #include <map>
60 
61 #include "madara/knowledge/KnowledgeBase.h"
62 #include "madara/knowledge/containers/Map.h"
63 
64 #include "ElectionTypesEnum.h"
65 #include "gams/groups/GroupBase.h"
66 #include "gams/GamsExport.h"
67 
68 namespace gams
69 {
70  namespace elections
71  {
73  typedef std::vector<std::string> CandidateList;
74 
76  typedef std::map <std::string,
77  madara::knowledge::KnowledgeRecord::Integer> CandidateVotes;
78 
83  {
84  public:
91  ElectionBase(const std::string & election_prefix = "",
92  const std::string & agent_prefix = "",
93  madara::knowledge::KnowledgeBase * knowledge = 0);
94 
98  virtual ~ElectionBase();
99 
105  virtual bool has_voted(const std::string & agent_prefix);
106 
111  virtual void get_votes(CandidateVotes & results);
112 
118  virtual void get_votes(
119  groups::GroupBase * group, CandidateVotes & results);
120 
125  virtual void set_agent_prefix(const std::string & prefix);
126 
131  virtual void set_election_prefix(const std::string & prefix);
132 
137  virtual void set_knowledge_base(
138  madara::knowledge::KnowledgeBase * knowledge);
139 
143  virtual void sync(void);
144 
149  const std::string & get_agent_prefix(void) const;
150 
155  const std::string & get_election_prefix(void) const;
156 
163  void vote(const std::string & candidate, int votes = 1);
164 
171  virtual void vote(const std::string & agent,
172  const std::string & candidate, int votes = 1);
173 
180  virtual CandidateList get_leaders(int num_leaders = 1) = 0;
181 
186  virtual void advance_round(void);
187 
192  int get_round(void) const;
193 
198  virtual void reset_round(void);
199 
200  protected:
201 
207 
211  mutable madara::knowledge::KnowledgeBase * knowledge_;
212 
216  std::string election_prefix_;
217 
221  std::string agent_prefix_;
222 
226  int round_;
227 
231  madara::knowledge::containers::Map votes_;
232  };
233  }
234 }
235 
236 #include "ElectionBase.inl"
237 
238 #endif // _GAMS_ELECTIONS_ELECTION_BASE_H_
Copyright (c) 2016 Carnegie Mellon University.
#define GAMS_EXPORT
Definition: GamsExport.h:20
Copyright(c) 2016 Carnegie Mellon University.
Base class for an election.
Definition: ElectionBase.h:83
virtual void set_knowledge_base(madara::knowledge::KnowledgeBase *knowledge)
Sets the knowledge base.
int round_
the election round in a multi-round election
Definition: ElectionBase.h:226
madara::knowledge::KnowledgeBase * knowledge_
The knowledge base to use as a data plane.
Definition: ElectionBase.h:211
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
Definition: ElectionBase.h:231
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
Definition: ElectionBase.h:216
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
Definition: ElectionBase.h:221
Base class for a group of agents.
Definition: GroupBase.h:91
std::vector< std::string > CandidateList
list of candidates
Definition: ElectionBase.h:73
std::map< std::string, madara::knowledge::KnowledgeRecord::Integer > CandidateVotes
candidate vote tally
Definition: ElectionBase.h:77
Contains all GAMS-related tools, classes and code.