GAMS  1.2.2
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 
206  void reset_votes_pointer (void);
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.
Copyright (c) 2016 Carnegie Mellon University.
std::map< std::string, madara::knowledge::KnowledgeRecord::Integer > CandidateVotes
candidate vote tally
Definition: ElectionBase.h:77
madara::knowledge::KnowledgeBase * knowledge_
The knowledge base to use as a data plane.
Definition: ElectionBase.h:211
madara::knowledge::containers::Map votes_
convenience class for bids
Definition: ElectionBase.h:231
std::string election_prefix_
the prefix for the election
Definition: ElectionBase.h:216
Contains all GAMS-related tools, classes and code.
std::vector< std::string > CandidateList
list of candidates
Definition: ElectionBase.h:73
Base class for a group of agents.
Definition: GroupBase.h:90
int round_
the election round in a multi-round election
Definition: ElectionBase.h:226
#define GAMS_EXPORT
Definition: GamsExport.h:20
std::string agent_prefix_
self prefix of the agent
Definition: ElectionBase.h:221
Base class for an election.
Definition: ElectionBase.h:82