LightVoting
 All Classes Namespaces Files Functions Variables Pages
org.lightvoting.simulation.environment.CGroup Class Reference

Created by sophie on 24.04.17. More...

+ Collaboration diagram for org.lightvoting.simulation.environment.CGroup:

Public Member Functions

 CGroup (final CVotingAgent p_votingAgent, final String p_grouping)
 constructor More...
 
void addCoordinated (final CVotingAgent p_votingAgent)
 add voting agent (for coordinated grouping) More...
 
void addRandom (final CVotingAgent p_votingAgent)
 add voting agent (for random grouping) More...
 
CVotingAgent determineAgent (final String p_agentName)
 determine agent for given name More...
 
boolean electionInProgress ()
 
boolean finale ()
 
ILiteral literal (final CVotingAgent p_votingAgent)
 returns literal representation for voting agent More...
 
ILiteral literal (final CChairAgent p_chairAgent)
 returns literal representation for chair agent, is null if the chair is not the chair of the group More...
 
void makeReady ()
 
boolean open ()
 
boolean readyForElection ()
 
void remove (final CVotingAgent p_votingAgent)
 
void reopen ()
 reopen group unless capacity is reached More...
 
void reset ()
 reset group More...
 
BitVector result ()
 return current result More...
 
int size ()
 return size More...
 
void startProgress ()
 
void triggerAgents (final CChairAgent p_chairAgent)
 trigger agents in group More...
 
ILiteral updateBasic (final CChairAgent p_chairAgent, final BitVector p_result)
 update group literal for chair agent ( for random grouping ) More...
 
ILiteral updateIterative (final CChairAgent p_chairAgent, final BitVector p_result, final int p_iteration)
 update group literal for chair agent ( for random grouping ) More...
 

Private Attributes

final List< CVotingAgentm_agentList
 
final int m_capacity = 3
 
final CChairAgent m_chair
 
boolean m_inProgress
 
boolean m_open
 
boolean m_readyForElection
 
BitVector m_result
 

Detailed Description

Definition at line 42 of file CGroup.java.

Constructor & Destructor Documentation

org.lightvoting.simulation.environment.CGroup.CGroup ( final CVotingAgent  p_votingAgent,
final String  p_grouping 
)
Parameters
p_votingAgentvoting agent creating the group
p_groupinggrouping algorithm

Definition at line 62 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_agentList, org.lightvoting.simulation.environment.CGroup.m_chair, org.lightvoting.simulation.environment.CGroup.m_inProgress, org.lightvoting.simulation.environment.CGroup.m_open, org.lightvoting.simulation.environment.CGroup.m_readyForElection, and org.lightvoting.simulation.environment.CGroup.m_result.

63  {
64  m_agentList = new LinkedList<>();
65  m_agentList.add( p_votingAgent );
66  m_chair = p_votingAgent.getChair();
67  m_open = true;
68  m_result = null;
69  if ( "RANDOM".equals( p_grouping ) )
70  m_readyForElection = false;
71  else
72  m_readyForElection = true;
73  m_inProgress = false;
74  }
final List< CVotingAgent > m_agentList
Definition: CGroup.java:44

Member Function Documentation

void org.lightvoting.simulation.environment.CGroup.addCoordinated ( final CVotingAgent  p_votingAgent)
Parameters
p_votingAgentjoining voting agent

Definition at line 131 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_open, and org.lightvoting.simulation.environment.CGroup.m_readyForElection.

132  {
133 
134  System.out.println( "Adding agent, old size is " + m_agentList.size() );
135  m_agentList.add( p_votingAgent );
136  m_open = false;
137  m_readyForElection = true;
138  }
void org.lightvoting.simulation.environment.CGroup.addRandom ( final CVotingAgent  p_votingAgent)
Parameters
p_votingAgentjoining voting agent

Definition at line 115 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_agentList, org.lightvoting.simulation.environment.CGroup.m_capacity, org.lightvoting.simulation.environment.CGroup.m_open, and org.lightvoting.simulation.environment.CGroup.m_readyForElection.

116  {
117  System.out.println( "Adding agent, old size is " + m_agentList.size() );
118  m_agentList.add( p_votingAgent );
119  if ( m_agentList.size() >= m_capacity )
120  {
121  m_open = false;
122  m_readyForElection = true;
123  }
124  }
final List< CVotingAgent > m_agentList
Definition: CGroup.java:44
CVotingAgent org.lightvoting.simulation.environment.CGroup.determineAgent ( final String  p_agentName)
Parameters
p_agentNamename
Returns
corresponding voting agent

Definition at line 286 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_agentList.

287  {
288  for ( int i = 0; i < m_agentList.size(); i++ )
289  if ( p_agentName.equals( m_agentList.get( i ).name() ) )
290  return m_agentList.get( i );
291  return null;
292  }
final List< CVotingAgent > m_agentList
Definition: CGroup.java:44
boolean org.lightvoting.simulation.environment.CGroup.electionInProgress ( )

Definition at line 150 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_inProgress.

151  {
152  return m_inProgress;
153  }
boolean org.lightvoting.simulation.environment.CGroup.finale ( )

Definition at line 271 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_capacity.

272  {
273  return m_agentList.size() >= m_capacity;
274  }
ILiteral org.lightvoting.simulation.environment.CGroup.literal ( final CVotingAgent  p_votingAgent)
Parameters
p_votingAgentvoting agent
Returns
literal with chair, status of group, curret voting result and info whether the group contains the agent

Definition at line 82 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_chair, and org.lightvoting.simulation.environment.CGroup.m_result.

83  {
84  return CLiteral.from( "group", CRawTerm.from( m_chair ), CRawTerm.from( this.open() ), CRawTerm.from( m_result ),
85  CRawTerm.from( m_agentList.contains( p_votingAgent ) ) );
86  }
ILiteral org.lightvoting.simulation.environment.CGroup.literal ( final CChairAgent  p_chairAgent)
Parameters
p_chairAgentchair agent
Returns
literal with group reference, agents in group, status of group, current voting result )

Definition at line 93 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_agentList, and org.lightvoting.simulation.environment.CGroup.m_chair.

94  {
95  final List<ITerm> l_terms = new LinkedList<>();
96 
97  for ( int i = 0; i < m_agentList.size(); i++ )
98  l_terms.add( CRawTerm.from( m_agentList.get( i ) ) );
99 
100 
101  if ( ( this.m_chair ).equals( p_chairAgent ) )
102  return CLiteral.from( "group", CRawTerm.from( this ) );
103  else return null;
104  }
final List< CVotingAgent > m_agentList
Definition: CGroup.java:44
void org.lightvoting.simulation.environment.CGroup.makeReady ( )
boolean org.lightvoting.simulation.environment.CGroup.open ( )

Definition at line 145 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_open.

146  {
147  return m_open;
148  }
boolean org.lightvoting.simulation.environment.CGroup.readyForElection ( )

Definition at line 106 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_readyForElection.

Referenced by org.lightvoting.simulation.agent.CChairAgent.checkConditions().

107  {
108  return m_readyForElection;
109  }

+ Here is the caller graph for this function:

void org.lightvoting.simulation.environment.CGroup.remove ( final CVotingAgent  p_votingAgent)

Definition at line 140 of file CGroup.java.

141  {
142  m_agentList.remove( p_votingAgent );
143  }
void org.lightvoting.simulation.environment.CGroup.reopen ( )
void org.lightvoting.simulation.environment.CGroup.reset ( )
BitVector org.lightvoting.simulation.environment.CGroup.result ( )
Returns
election result

Definition at line 265 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_result.

266  {
267  return m_result;
268  }
int org.lightvoting.simulation.environment.CGroup.size ( )
Returns
size of agent list

Definition at line 182 of file CGroup.java.

Referenced by org.lightvoting.simulation.agent.CChairAgent.removeVoter().

183  {
184  return m_agentList.size();
185  }

+ Here is the caller graph for this function:

void org.lightvoting.simulation.environment.CGroup.startProgress ( )

Definition at line 155 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_inProgress.

156  {
157  m_inProgress = true;
158  }
void org.lightvoting.simulation.environment.CGroup.triggerAgents ( final CChairAgent  p_chairAgent)
Parameters
p_chairAgentchair agent

Definition at line 164 of file CGroup.java.

165  {
166  m_agentList.forEach( i ->
167  i.trigger(
168  CTrigger.from(
169  ITrigger.EType.ADDGOAL,
170  CLiteral.from(
171  "submit/vote",
172  CRawTerm.from( p_chairAgent ) )
173  )
174  )
175  );
176  }
ILiteral org.lightvoting.simulation.environment.CGroup.updateBasic ( final CChairAgent  p_chairAgent,
final BitVector  p_result 
)
Parameters
p_chairAgentchair agent
p_resultelection result
Returns
group literal for chair agent

Definition at line 194 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_result.

Referenced by org.lightvoting.simulation.agent.CChairAgent.computeResult().

195  {
196  // send result of election to all agents in the group
197  m_agentList.stream().forEach( i ->
198  i.trigger( CTrigger.from(
199  ITrigger.EType.ADDGOAL,
200  CLiteral.from( "election/result",
201  CRawTerm.from( p_chairAgent ),
202  CRawTerm.from( p_result ) )
203  )
204  )
205  );
206 
207  m_result = p_result;
208  return this.literal( p_chairAgent );
209  }

+ Here is the caller graph for this function:

ILiteral org.lightvoting.simulation.environment.CGroup.updateIterative ( final CChairAgent  p_chairAgent,
final BitVector  p_result,
final int  p_iteration 
)
Parameters
p_chairAgentchair agent
p_resultelection result
p_iterationcurrent iteration
Returns
group literal for chair agent

Definition at line 219 of file CGroup.java.

References org.lightvoting.simulation.environment.CGroup.m_result.

Referenced by org.lightvoting.simulation.agent.CChairAgent.computeResult().

220  {
221  // send result of election to all agents in the group
222  m_agentList.stream().forEach( i ->
223  {
224  i.trigger( CTrigger.from(
225  ITrigger.EType.ADDGOAL,
226  CLiteral.from( "election/result",
227  CRawTerm.from( p_chairAgent ),
228  CRawTerm.from( p_result ),
229  CRawTerm.from( p_iteration ) )
230  )
231  );
232  System.out.println( "triggering agent " + i.name() );
233  } );
234 
235  m_result = p_result;
236  return this.literal( p_chairAgent );
237 
238  }

+ Here is the caller graph for this function:

Member Data Documentation

final int org.lightvoting.simulation.environment.CGroup.m_capacity = 3
private
final CChairAgent org.lightvoting.simulation.environment.CGroup.m_chair
private