LightVoting
 All Classes Namespaces Files Functions Variables Pages
org.lightvoting.CMain Class Reference

Main, providing runtime of LightVoting. More...

+ Collaboration diagram for org.lightvoting.CMain:

Static Public Member Functions

static void main (final String[] p_args) throws Exception
 Main. More...
 

Private Member Functions

 CMain ()
 Hidden constructor. More...
 

Static Private Member Functions

static void addAgents (final Collection< CVotingAgent > p_activeAgents, final int p_newAgNum, final Iterator< CVotingAgent > p_agentIterator)
 
static void readYaml () throws FileNotFoundException
 

Static Private Attributes

static int s_altnum
 
static CEnvironment s_environment
 
static String s_grouping
 
static String s_protocol
 

Detailed Description

Definition at line 45 of file CMain.java.

Constructor & Destructor Documentation

org.lightvoting.CMain.CMain ( )
private

Definition at line 55 of file CMain.java.

56  {
57  }

Member Function Documentation

static void org.lightvoting.CMain.addAgents ( final Collection< CVotingAgent p_activeAgents,
final int  p_newAgNum,
final Iterator< CVotingAgent p_agentIterator 
)
staticprivate

Definition at line 175 of file CMain.java.

176  {
177 
178  for ( int i = 0; i < p_newAgNum; i++ )
179  {
180  if ( p_agentIterator.hasNext() )
181  {
182  final CVotingAgent l_curAg = p_agentIterator.next();
183  p_activeAgents.add( l_curAg );
184  System.out.println( "added Agent " + l_curAg.name() );
185  p_agentIterator.remove();
186 
187  }
188  }
189 
190  }
static void org.lightvoting.CMain.main ( final String[]  p_args) throws Exception
static
Parameters
p_argsPassed command line args: [ASL File] [Number of Agents] [Cycles]
Exceptions
ExceptionThrows exception, e.g. on reading ASL file

Definition at line 64 of file CMain.java.

References org.lightvoting.CMain.readYaml(), org.lightvoting.CMain.s_altnum, org.lightvoting.CMain.s_environment, org.lightvoting.CMain.s_grouping, and org.lightvoting.CMain.s_protocol.

65  {
66  // Example code taken from
67  // https://lightjason.github.io/tutorial/tutorial-agentspeak-in-fifteen-minutes/
68  //
69  // parameter of the command-line arguments:
70  // 1. ASL file
71  // 2. number of agents
72  // 3. number of iterations (if not set maximum)
73 
74  readYaml();
75 
76  final Set<CVotingAgent> l_agents;
77  final CVotingAgent.CVotingAgentGenerator l_votingagentgenerator;
78 
79  // final CDataWriter l_writer = new CDataWriter();
80  final String l_name = "results.h5";
81  CDataWriter.createHDF5( l_name );
82  CDataWriter.test( l_name );
83 
84  try
85  {
86  final FileInputStream l_stream = new FileInputStream( p_args[0] );
87  final FileInputStream l_chairstream = new FileInputStream( p_args[1] );
88 
89  s_environment = new CEnvironment( Integer.parseInt( p_args[2] ), l_name );
90 
91  l_votingagentgenerator = new CVotingAgent.CVotingAgentGenerator( new CSend(), l_stream, s_environment, s_altnum, s_grouping, l_name );
92  l_agents = l_votingagentgenerator
93  .generatemultiple( Integer.parseInt( p_args[2] ), new CChairAgent.CChairAgentGenerator( l_chairstream, s_environment, s_grouping, s_protocol, l_name ) )
94  .collect( Collectors.toSet() );
95 
96 
97  System.out.println( " Numbers of agents: " + l_agents.size() );
98 
99 
100  }
101  catch ( final Exception l_exception )
102  {
103  l_exception.printStackTrace();
104  throw new RuntimeException();
105  }
106 
107  // generate empty set of active agents
108 
109  final Set<CVotingAgent> l_activeAgents = Sets.newConcurrentHashSet();
110 
111  System.out.println( " Numbers of active agents: " + l_activeAgents.size() );
112 
113  System.out.println( " Numbers of active agents: " + l_activeAgents.size() );
114  System.out.println( " Will run " + p_args[3] + " cycles." );
115 
116  IntStream
117  // define cycle range, i.e. number of cycles to run sequentially
118  .range( 0,
119  p_args.length < 4
120  ? Integer.MAX_VALUE
121  : Integer.parseInt( p_args[3] ) )
122  .forEach( j ->
123  {
124  System.out.println( "Global cycle: " + j );
125  l_agents.parallelStream().forEach( i ->
126  {
127  try
128  {
129  // check if the conditions for triggering a new cycle are fulfilled in the environment
130  // call each agent, i.e. trigger a new agent cycle
131  i.call();
132  // i.getChair().sleep( 0 );
133  i.getChair().call();
134  }
135  catch ( final Exception l_exception )
136  {
137  l_exception.printStackTrace();
138  throw new RuntimeException();
139  }
140  } );
141  } );
142  }
static int s_altnum
Definition: CMain.java:48
static CEnvironment s_environment
Definition: CMain.java:47
static String s_protocol
Definition: CMain.java:50
static void readYaml()
Definition: CMain.java:145
static String s_grouping
Definition: CMain.java:49

+ Here is the call graph for this function:

static void org.lightvoting.CMain.readYaml ( ) throws FileNotFoundException
staticprivate

Definition at line 145 of file CMain.java.

References org.lightvoting.CMain.s_altnum, org.lightvoting.CMain.s_grouping, and org.lightvoting.CMain.s_protocol.

Referenced by org.lightvoting.CMain.main().

146  {
147  final Yaml l_yaml = new Yaml();
148 
149  System.out.println( l_yaml.dump( l_yaml.load( new FileInputStream( "src/main/resources/org/lightvoting/configuration.yaml" ) ) ) );
150 
151  final Map<String, Map<String, String>> l_values = (Map<String, Map<String, String>>) l_yaml
152  .load( new FileInputStream( "src/main/resources/org/lightvoting/configuration.yaml" ) );
153 
154  for ( final String l_key : l_values.keySet() )
155  {
156  final Map<String, String> l_subValues = l_values.get( l_key );
157  System.out.println( l_key );
158 
159  for ( final String l_subValueKey : l_subValues.keySet() )
160  {
161  System.out.println( String.format( "\t%s = %s",
162  l_subValueKey, l_subValues.get( l_subValueKey ) ) );
163 
164  // parse input
165  if ( "grouping".equals( l_subValueKey ) )
166  s_grouping = l_subValues.get( l_subValueKey );
167  if ( "protocol".equals( l_subValueKey ) )
168  s_protocol = l_subValues.get( l_subValueKey );
169  if ( "altnum".equals( l_subValueKey ) )
170  s_altnum = Integer.parseInt( l_subValues.get( l_subValueKey ) );
171  }
172  }
173  }
static int s_altnum
Definition: CMain.java:48
static String s_protocol
Definition: CMain.java:50
static String s_grouping
Definition: CMain.java:49

+ Here is the caller graph for this function:

Member Data Documentation

int org.lightvoting.CMain.s_altnum
staticprivate

Definition at line 48 of file CMain.java.

Referenced by org.lightvoting.CMain.main(), and org.lightvoting.CMain.readYaml().

CEnvironment org.lightvoting.CMain.s_environment
staticprivate

Definition at line 47 of file CMain.java.

Referenced by org.lightvoting.CMain.main().

String org.lightvoting.CMain.s_grouping
staticprivate

Definition at line 49 of file CMain.java.

Referenced by org.lightvoting.CMain.main(), and org.lightvoting.CMain.readYaml().

String org.lightvoting.CMain.s_protocol
staticprivate

Definition at line 50 of file CMain.java.

Referenced by org.lightvoting.CMain.main(), and org.lightvoting.CMain.readYaml().