LightVoting
 All Classes Namespaces Files Functions Variables Pages
org.lightvoting.simulation.agent.CChairAgent Class Reference

Created by sophie on 21.02.17. More...

Inherits IBaseAgent< CChairAgent >.

+ Collaboration diagram for org.lightvoting.simulation.agent.CChairAgent:

Classes

class  CChairAgentGenerator
 Class CChairAgentGenerator. More...
 

Public Member Functions

 CChairAgent (final String p_name, final IAgentConfiguration< CChairAgent > p_configuration, final CEnvironment p_environment, final String p_grouping, final String p_protocol, final String p_fileName)
 constructor of the agent More...
 
final CChairAgent call () throws Exception
 
void checkConditions ()
 check conditions More...
 
void computeResult ()
 compute result of election More...
 
String name ()
 
void perceiveGroup ()
 perceive group More...
 
void removeVoter ()
 remove most dissatisfied voter More...
 
void startElection ()
 start election More...
 
void storeDiss (final String p_name, final Double p_diss, final Integer p_iteration)
 store dissatisfaction value More...
 
void storeVote (final String p_agentName, final BitVector p_vote)
 store vote More...
 

Private Member Functions

CGroup determineGroup ()
 
int getMaxIndex (final List< Double > p_dissValues)
 
BitVector toBV (final AtomicIntegerArray p_vote)
 

Private Attributes

List< CVotingAgentm_agents
 
List< BitVector > m_bitVotes
 
List< Double > m_dissList
 
double m_dissThreshold = 1.1
 
List< CVotingAgentm_dissVoters
 
final CEnvironment m_environment
 environment More...
 
final String m_fileName
 
String m_grouping
 grouping algorithm: "RANDOM" or "COORDINATED" More...
 
int m_iteration
 
boolean m_iterative
 
final String m_name
 name of chair More...
 
String m_protocol
 

Detailed Description

Definition at line 63 of file CChairAgent.java.

Constructor & Destructor Documentation

org.lightvoting.simulation.agent.CChairAgent.CChairAgent ( final String  p_name,
final IAgentConfiguration< CChairAgent p_configuration,
final CEnvironment  p_environment,
final String  p_grouping,
final String  p_protocol,
final String  p_fileName 
)
Parameters
p_configurationagent configuration of the agent generator
p_groupinggrouping algorithm
p_protocolvoting protocol
p_fileNameh5 file

Definition at line 101 of file CChairAgent.java.

References org.lightvoting.simulation.agent.CChairAgent.m_agents, org.lightvoting.simulation.agent.CChairAgent.m_bitVotes, org.lightvoting.simulation.agent.CChairAgent.m_dissList, org.lightvoting.simulation.agent.CChairAgent.m_dissVoters, org.lightvoting.simulation.agent.CChairAgent.m_environment, org.lightvoting.simulation.agent.CChairAgent.m_fileName, org.lightvoting.simulation.agent.CChairAgent.m_grouping, org.lightvoting.simulation.agent.CChairAgent.m_iteration, org.lightvoting.simulation.agent.CChairAgent.m_iterative, org.lightvoting.simulation.agent.CChairAgent.m_name, and org.lightvoting.simulation.agent.CChairAgent.m_protocol.

Referenced by org.lightvoting.simulation.agent.CChairAgent.CChairAgentGenerator.generatesingle().

105  {
106  super( p_configuration );
107  m_name = p_name;
108  m_environment = p_environment;
109  m_bitVotes = Collections.synchronizedList( new LinkedList<>() );
110  m_dissList = Collections.synchronizedList( new LinkedList<>() );
111  m_dissVoters = Collections.synchronizedList( new LinkedList<>() );
112  m_grouping = p_grouping;
113  m_protocol = p_protocol;
114  m_iteration = 0;
115  m_agents = Collections.synchronizedList( new LinkedList<>() );
116  m_iterative = false;
117  m_fileName = p_fileName;
118  }
String m_grouping
grouping algorithm: "RANDOM" or "COORDINATED"
final CEnvironment m_environment
environment

+ Here is the caller graph for this function:

Member Function Documentation

final CChairAgent org.lightvoting.simulation.agent.CChairAgent.call ( ) throws Exception

Definition at line 122 of file CChairAgent.java.

123  {
124  // run default cycle
125  return super.call();
126  }
void org.lightvoting.simulation.agent.CChairAgent.checkConditions ( )

add literal for group of chair agent if it exists

Definition at line 159 of file CChairAgent.java.

References org.lightvoting.simulation.agent.CChairAgent.m_iteration, org.lightvoting.simulation.agent.CChairAgent.m_iterative, and org.lightvoting.simulation.environment.CGroup.readyForElection().

160  {
161  final CGroup l_group = this.determineGroup();
162 
163  // if conditions for election are fulfilled, trigger goal start/criterion/fulfilled
164 
165  final ITrigger l_trigger;
166 
167  // if m_iterative is true, we have the case of iterative voting, i.e. we already have the votes
168  // we only need to repeat the computation of the result
169 
170  if ( m_iterative && ( l_group.readyForElection() && !( l_group.electionInProgress() ) ) )
171  {
172  m_iteration++;
173  this.computeResult();
174  return;
175  }
176 
177 
178  if ( l_group.readyForElection() && ( !( l_group.electionInProgress() ) ) )
179  {
180  l_group.startProgress();
181 
182  l_trigger = CTrigger.from(
183  ITrigger.EType.ADDGOAL,
184  CLiteral.from( "start/criterion/fulfilled" )
185  );
186 
187  this.trigger( l_trigger );
188  }
189  }

+ Here is the call graph for this function:

void org.lightvoting.simulation.agent.CChairAgent.computeResult ( )

Definition at line 260 of file CChairAgent.java.

References org.lightvoting.simulation.agent.CChairAgent.m_bitVotes, org.lightvoting.simulation.agent.CChairAgent.m_grouping, org.lightvoting.simulation.agent.CChairAgent.m_iteration, org.lightvoting.simulation.agent.CChairAgent.m_iterative, org.lightvoting.simulation.agent.CChairAgent.m_protocol, org.lightvoting.simulation.environment.CGroup.updateBasic(), and org.lightvoting.simulation.environment.CGroup.updateIterative().

261  {
262  final CGroup l_group = this.determineGroup();
263 
264  final CMinisumApproval l_minisumApproval = new CMinisumApproval();
265 
266  final List<String> l_alternatives = new LinkedList<>();
267 
268  for ( char l_char : "ABCDEF".toCharArray() )
269 
270  l_alternatives.add( String.valueOf( l_char ) );
271 
272  System.out.println( " Alternatives: " + l_alternatives );
273 
274  System.out.println( " Votes: " + m_bitVotes );
275 
276  final BitVector l_comResultBV = l_minisumApproval.applyRuleBV( l_alternatives, m_bitVotes, 3 );
277 
278  System.out.println( " Result of election as BV: " + l_comResultBV );
279 
280  // set inProgress and readyForElection to false in group
281  l_group.reset();
282 
283  if ( "BASIC".equals( m_protocol ) )
284  {
285  this.beliefbase().add( l_group.updateBasic( this, l_comResultBV ) );
286  }
287 
288 
289  // if grouping is coordinated, reopen group for further voters
290  if ( "COORDINATED".equals( m_grouping ) && !l_group.finale() && !m_iterative )
291  {
292  System.out.println( " reopening group " );
293  m_environment.reopen( l_group );
294  }
295 
296  // for the iterative case, you need to differentiate between the final election and intermediate elections.
297  if ( "ITERATIVE".equals( m_protocol ) && ( l_group.finale() ) || m_iterative )
298  {
299  System.out.println( " Update iterative " );
300 
301  this.beliefbase().add( l_group.updateIterative( this, l_comResultBV, m_iteration ) );
302  return;
303  }
304 
305 
306  if ( "ITERATIVE".equals( m_protocol ) && !l_group.finale() )
307  {
308  System.out.println( " Update basic " );
309  this.beliefbase().add( l_group.updateBasic( this, l_comResultBV ) );
310  }
311 
312  // TODO test all cases
313 
314  }
String m_grouping
grouping algorithm: "RANDOM" or "COORDINATED"

+ Here is the call graph for this function:

CGroup org.lightvoting.simulation.agent.CChairAgent.determineGroup ( )
private

Definition at line 193 of file CChairAgent.java.

194  {
195  final AtomicReference<CGroup> l_groupAtomic = new AtomicReference<>();
196  final Collection l_groups = this.beliefbase().beliefbase().literal( "group" );
197  l_groups.stream().forEach( i -> l_groupAtomic.set( ( (ILiteral) i ).values().findFirst().get().raw() ) );
198  return l_groupAtomic.get();
199  }
int org.lightvoting.simulation.agent.CChairAgent.getMaxIndex ( final List< Double >  p_dissValues)
private

Definition at line 392 of file CChairAgent.java.

393  {
394  int l_maxIndex = 0;
395  for ( int i = 0; i < p_dissValues.size(); i++ )
396  {
397  if ( p_dissValues.get( i ) > p_dissValues.get( l_maxIndex ) )
398  {
399  System.out.println( " changed max index to " + i + " diss: " + p_dissValues.get( i ) );
400  l_maxIndex = i;
401  }
402  }
403  return l_maxIndex;
404  }
String org.lightvoting.simulation.agent.CChairAgent.name ( )

Definition at line 130 of file CChairAgent.java.

References org.lightvoting.simulation.agent.CChairAgent.m_name.

131  {
132  return m_name;
133  }
void org.lightvoting.simulation.agent.CChairAgent.perceiveGroup ( )

add literal for group of chair agent if it exists

Definition at line 145 of file CChairAgent.java.

References org.lightvoting.simulation.environment.CEnvironment.detectGroup(), and org.lightvoting.simulation.agent.CChairAgent.m_environment.

146  {
147  if ( !( m_environment.detectGroup( this ) == null ) )
148  this.beliefbase().add( m_environment.detectGroup( this ) );
149  }
ILiteral detectGroup(final CChairAgent p_chairAgent)
detect group of chair agent
final CEnvironment m_environment
environment

+ Here is the call graph for this function:

void org.lightvoting.simulation.agent.CChairAgent.removeVoter ( )

Definition at line 357 of file CChairAgent.java.

References org.lightvoting.simulation.agent.CChairAgent.m_dissList, org.lightvoting.simulation.agent.CChairAgent.m_dissThreshold, org.lightvoting.simulation.agent.CChairAgent.m_iterative, and org.lightvoting.simulation.environment.CGroup.size().

358  {
359  final CGroup l_group = this.determineGroup();
360 
361  final int l_maxIndex = this.getMaxIndex( m_dissList );
362  final double l_max = m_dissList.get( l_maxIndex );
363  System.out.println( " max diss is " + l_max );
364 
365  if ( l_max > m_dissThreshold )
366  {
367  System.out.println( " Determining most dissatisfied voter " );
368  final CVotingAgent l_maxDissAg = m_dissVoters.get( l_maxIndex );
369  System.out.println( " Most dissatisfied voter is " + l_maxDissAg.name() );
370  // remove vote of most dissatisfied voter from list
371  m_bitVotes.remove( l_maxDissAg.getBitVote() );
372  m_dissVoters.remove( l_maxDissAg );
373  l_group.remove( l_maxDissAg );
374 
375  System.out.println( "Removing " + l_maxDissAg.name() );
376 
377  // remove diss Values for next iteration
378  m_dissList.clear();
379 
380  m_iterative = true;
381  l_group.makeReady();
382 
383  if ( l_group.size() == 0 )
384  System.out.println( " Voter list is empty, we are done " );
385 
386  return;
387  }
388 
389  System.out.println( " No dissatisfied voter left, we are done " );
390  }

+ Here is the call graph for this function:

void org.lightvoting.simulation.agent.CChairAgent.startElection ( )

Definition at line 208 of file CChairAgent.java.

209  {
210  final CGroup l_group = this.determineGroup();
211  l_group.triggerAgents( this );
212  }
void org.lightvoting.simulation.agent.CChairAgent.storeDiss ( final String  p_name,
final Double  p_diss,
final Integer  p_iteration 
)
Parameters
p_dissdissatisfaction value
p_iterationiteration number

Definition at line 325 of file CChairAgent.java.

References org.lightvoting.simulation.agent.CChairAgent.m_dissList.

326  {
327  final CGroup l_group = this.determineGroup();
328 
329  m_dissList.add( p_diss );
330  final CVotingAgent l_dissAg = l_group.determineAgent( p_name );
331  m_dissVoters.add( l_dissAg );
332 
333  System.out.println( "Storing diss " + p_diss );
334 
335  if ( m_dissList.size() == l_group.size() )
336  {
337  final ITrigger l_trigger = CTrigger.from(
338  ITrigger.EType.ADDGOAL,
339  CLiteral.from(
340  "all/dissValues/received",
341  CRawTerm.from( p_iteration )
342  )
343 
344  );
345 
346  this.trigger( l_trigger );
347 
348  System.out.println( p_iteration + " All voters submitted their dissatisfaction value" );
349  }
350  }
void org.lightvoting.simulation.agent.CChairAgent.storeVote ( final String  p_agentName,
final BitVector  p_vote 
)
Parameters
p_votevote

Definition at line 221 of file CChairAgent.java.

References org.lightvoting.simulation.agent.CChairAgent.m_bitVotes.

222  {
223  final CGroup l_group = this.determineGroup();
224 
225  m_agents.add( l_group.determineAgent( p_agentName ) );
226  m_bitVotes.add( p_vote );
227 
228  if ( m_bitVotes.size() == l_group.size() )
229  {
230 
231  final ITrigger l_trigger = CTrigger.from(
232  ITrigger.EType.ADDGOAL,
233  CLiteral.from(
234  "all/votes/received" )
235 
236  );
237 
238  System.out.println( " CChairAgent.java: all votes received " );
239 
240  this.trigger( l_trigger );
241  }
242  }
BitVector org.lightvoting.simulation.agent.CChairAgent.toBV ( final AtomicIntegerArray  p_vote)
private

Definition at line 244 of file CChairAgent.java.

245  {
246  final BitVector l_bitVector = new BitVector( p_vote.length() );
247  for ( int i = 0; i < p_vote.length(); i++ )
248  if ( p_vote.get( i ) == 1 )
249  l_bitVector.put( i, true );
250  return l_bitVector;
251  }

Member Data Documentation

List<CVotingAgent> org.lightvoting.simulation.agent.CChairAgent.m_agents
private
List<BitVector> org.lightvoting.simulation.agent.CChairAgent.m_bitVotes
private
List<Double> org.lightvoting.simulation.agent.CChairAgent.m_dissList
private
double org.lightvoting.simulation.agent.CChairAgent.m_dissThreshold = 1.1
private
List<CVotingAgent> org.lightvoting.simulation.agent.CChairAgent.m_dissVoters
private
final CEnvironment org.lightvoting.simulation.agent.CChairAgent.m_environment
private
final String org.lightvoting.simulation.agent.CChairAgent.m_fileName
private
String org.lightvoting.simulation.agent.CChairAgent.m_grouping
private
final String org.lightvoting.simulation.agent.CChairAgent.m_name
private
String org.lightvoting.simulation.agent.CChairAgent.m_protocol
private