24 package org.lightvoting;
26 import com.google.common.collect.Sets;
31 import org.yaml.snakeyaml.Yaml;
33 import java.io.FileInputStream;
34 import java.io.FileNotFoundException;
35 import java.util.Collection;
36 import java.util.Iterator;
39 import java.util.stream.Collectors;
40 import java.util.stream.IntStream;
64 public static void main(
final String[] p_args )
throws Exception
76 final Set<CVotingAgent> l_agents;
77 final CVotingAgent.CVotingAgentGenerator l_votingagentgenerator;
80 final String l_name =
"results.h5";
81 CDataWriter.createHDF5( l_name );
82 CDataWriter.test( l_name );
86 final FileInputStream l_stream =
new FileInputStream( p_args[0] );
87 final FileInputStream l_chairstream =
new FileInputStream( p_args[1] );
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() );
97 System.out.println(
" Numbers of agents: " + l_agents.size() );
101 catch (
final Exception l_exception )
103 l_exception.printStackTrace();
104 throw new RuntimeException();
109 final Set<CVotingAgent> l_activeAgents = Sets.newConcurrentHashSet();
111 System.out.println(
" Numbers of active agents: " + l_activeAgents.size() );
113 System.out.println(
" Numbers of active agents: " + l_activeAgents.size() );
114 System.out.println(
" Will run " + p_args[3] +
" cycles." );
121 : Integer.parseInt( p_args[3] ) )
124 System.out.println(
"Global cycle: " + j );
125 l_agents.parallelStream().forEach( i ->
135 catch (
final Exception l_exception )
137 l_exception.printStackTrace();
138 throw new RuntimeException();
144 @SuppressWarnings(
"unchecked" )
145 private static
void readYaml() throws FileNotFoundException
147 final Yaml l_yaml =
new Yaml();
149 System.out.println( l_yaml.dump( l_yaml.load(
new FileInputStream(
"src/main/resources/org/lightvoting/configuration.yaml" ) ) ) );
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" ) );
154 for (
final String l_key : l_values.keySet() )
156 final Map<String, String> l_subValues = l_values.get( l_key );
157 System.out.println( l_key );
159 for (
final String l_subValueKey : l_subValues.keySet() )
161 System.out.println( String.format(
"\t%s = %s",
162 l_subValueKey, l_subValues.get( l_subValueKey ) ) );
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 ) );
175 private static void addAgents(
final Collection<CVotingAgent> p_activeAgents,
final int p_newAgNum,
final Iterator<CVotingAgent> p_agentIterator )
178 for (
int i = 0; i < p_newAgNum; i++ )
180 if ( p_agentIterator.hasNext() )
183 p_activeAgents.add( l_curAg );
184 System.out.println(
"added Agent " + l_curAg.name() );
185 p_agentIterator.remove();
Created by sophie on 22.02.17.
static void addAgents(final Collection< CVotingAgent > p_activeAgents, final int p_newAgNum, final Iterator< CVotingAgent > p_agentIterator)
static CEnvironment s_environment
static void main(final String[] p_args)
Main.
Main, providing runtime of LightVoting.
CMain()
Hidden constructor.
Created by sophie on 21.02.17.
Action to send messages for communication.
BDI agent with voting capabilities.