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

Created by sophie on 22.02.17. More...

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

Public Member Functions

 CEnvironment (final int p_size, final String p_fileName)
 constructor More...
 
void addAgentCoordinated (final CGroup p_group, final CVotingAgent p_votingAgent)
 add agent to group (for coordinated grouping) More...
 
void addAgentRandom (final CGroup p_randomGroup, final CVotingAgent p_votingAgent)
 add agent to group (for random grouping) More...
 
ILiteral detectGroup (final CChairAgent p_chairAgent)
 detect group of chair agent More...
 
final void initialset (final CVotingAgent p_votingAgent)
 initialize groups More...
 
ILiteral literal (final CVotingAgent p_votingAgent)
 returns literal representation of existing groups More...
 
CGroup openNewGroupCoordinated (final CVotingAgent p_votingAgent)
 open new group (for coordinated grouping) More...
 
CGroup openNewGroupRandom (final CVotingAgent p_votingAgent)
 open new group (for random grouping) More...
 
void reopen (final CGroup p_group)
 open group for further elections unless the capacity is reached. More...
 

Private Member Functions

void wakeUpAgent ()
 

Private Attributes

final List< CVotingAgentm_agentList
 
int m_currentIndex
 
final String m_fileName
 
boolean m_firstActivated
 
final List< CGroupm_groups
 

Detailed Description

Environment class

Definition at line 41 of file CEnvironment.java.

Constructor & Destructor Documentation

org.lightvoting.simulation.environment.CEnvironment.CEnvironment ( final int  p_size,
final String  p_fileName 
)
Parameters
p_sizenumber of agents
p_fileNameHDF5 file

Definition at line 58 of file CEnvironment.java.

References org.lightvoting.simulation.environment.CEnvironment.m_agentList, org.lightvoting.simulation.environment.CEnvironment.m_fileName, and org.lightvoting.simulation.environment.CEnvironment.m_groups.

59  {
60  m_fileName = p_fileName;
61  m_groups = Collections.synchronizedList( new LinkedList<>() );
62  m_agentList = new LinkedList<>();
63  }

Member Function Documentation

void org.lightvoting.simulation.environment.CEnvironment.addAgentCoordinated ( final CGroup  p_group,
final CVotingAgent  p_votingAgent 
)
Parameters
p_groupgroup to join
p_votingAgentjoining agent

Definition at line 145 of file CEnvironment.java.

146  {
147  p_group.addCoordinated( p_votingAgent );
148  this.wakeUpAgent();
149  }
void org.lightvoting.simulation.environment.CEnvironment.addAgentRandom ( final CGroup  p_randomGroup,
final CVotingAgent  p_votingAgent 
)
Parameters
p_randomGrouprandom group to join
p_votingAgentjoining agent

Definition at line 131 of file CEnvironment.java.

132  {
133  p_randomGroup.addRandom( p_votingAgent );
134  this.wakeUpAgent();
135  }
ILiteral org.lightvoting.simulation.environment.CEnvironment.detectGroup ( final CChairAgent  p_chairAgent)
Parameters
p_chairAgentchair agent
Returns
literal representation of group if chair is assigned to a group

Definition at line 156 of file CEnvironment.java.

References org.lightvoting.simulation.environment.CEnvironment.m_groups.

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

157  {
158  for ( final CGroup l_group : m_groups )
159  {
160  if ( !( ( l_group.literal( p_chairAgent ) ) == null ) )
161  return l_group.literal( p_chairAgent );
162  }
163  return null;
164  }

+ Here is the caller graph for this function:

final void org.lightvoting.simulation.environment.CEnvironment.initialset ( final CVotingAgent  p_votingAgent)
Parameters
p_votingAgentagent

Definition at line 71 of file CEnvironment.java.

References org.lightvoting.simulation.environment.CEnvironment.m_firstActivated.

72  {
73  m_agentList.add( p_votingAgent );
74 
75  if ( !m_firstActivated )
76  {
77 
78  final CVotingAgent l_firstAgent = m_agentList.get( 0 );
79 
80  l_firstAgent.sleep( 0 );
81  l_firstAgent.getChair().sleep( 0 );
82  m_firstActivated = true;
83  }
84  }
ILiteral org.lightvoting.simulation.environment.CEnvironment.literal ( final CVotingAgent  p_votingAgent)
Parameters
p_votingAgentvoting agent
Returns
literal with references to existing groups

Definition at line 91 of file CEnvironment.java.

References org.lightvoting.simulation.environment.CEnvironment.m_groups.

Referenced by org.lightvoting.simulation.agent.CVotingAgent.perceiveEnv().

92  {
93  return CLiteral.from( "groups", CRawTerm.from( m_groups ) );
94  }

+ Here is the caller graph for this function:

CGroup org.lightvoting.simulation.environment.CEnvironment.openNewGroupCoordinated ( final CVotingAgent  p_votingAgent)
Parameters
p_votingAgentvoting agent opening group
Returns
new group

Definition at line 116 of file CEnvironment.java.

117  {
118  final CGroup l_group = new CGroup( p_votingAgent, "COORDINATED" );
119  m_groups.add( l_group );
120  System.out.println( "Created Group " + l_group );
121 
122  return l_group;
123  }
CGroup org.lightvoting.simulation.environment.CEnvironment.openNewGroupRandom ( final CVotingAgent  p_votingAgent)
Parameters
p_votingAgentvoting agent opening group
Returns
new group

Definition at line 101 of file CEnvironment.java.

102  {
103  final CGroup l_group = new CGroup( p_votingAgent, "RANDOM" );
104  m_groups.add( l_group );
105  System.out.println( "Created Group " + l_group );
106  this.wakeUpAgent();
107 
108  return l_group;
109  }
void org.lightvoting.simulation.environment.CEnvironment.reopen ( final CGroup  p_group)

Also, wake up the next agent

Parameters
p_groupgroup to be reopened

Definition at line 173 of file CEnvironment.java.

174  {
175  p_group.reopen();
176  this.wakeUpAgent();
177  }
void org.lightvoting.simulation.environment.CEnvironment.wakeUpAgent ( )
private

Definition at line 179 of file CEnvironment.java.

References org.lightvoting.simulation.environment.CEnvironment.m_currentIndex.

180  {
181  m_currentIndex++;
182  final CVotingAgent l_wakingAgent = m_agentList.get( m_currentIndex );
183  l_wakingAgent.sleep( 0 );
184  l_wakingAgent.getChair().sleep( 0 );
185  System.out.println( "Waking up agent " + l_wakingAgent.name() );
186  }

Member Data Documentation

final List<CVotingAgent> org.lightvoting.simulation.environment.CEnvironment.m_agentList
private
int org.lightvoting.simulation.environment.CEnvironment.m_currentIndex
private
final String org.lightvoting.simulation.environment.CEnvironment.m_fileName
private
boolean org.lightvoting.simulation.environment.CEnvironment.m_firstActivated
private