[virtualcommons-svn] commit/foraging: alllee: merging default branch back into stable
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2012-03-19 23:54:09
|
1 new commit in foraging: https://bitbucket.org/virtualcommons/foraging/changeset/78057caab3b6/ changeset: 78057caab3b6 branch: stable user: alllee date: 2012-03-20 00:54:01 summary: merging default branch back into stable affected #: 32 files diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java --- a/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java +++ b/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java @@ -18,7 +18,7 @@ import edu.asu.commons.foraging.model.ForagingDataModel; import edu.asu.commons.foraging.model.GroupDataModel; import edu.asu.commons.foraging.model.Resource; -import edu.asu.commons.foraging.rules.iu.ForagingStrategy; +import edu.asu.commons.foraging.rules.Strategy; import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; /** @@ -46,7 +46,7 @@ // these are the subjects that have sanctioned us. private Map<Identifier, Duration> sanctioners = new HashMap<Identifier, Duration>(); - private List<ForagingStrategy> selectedRules = new ArrayList<ForagingStrategy>(); + private List<Strategy> selectedStrategies = new ArrayList<Strategy>(); private ForagingClient client; private volatile boolean explicitCollectionMode = false; @@ -271,13 +271,18 @@ return explicitCollectionMode; } - // FIXME: deprecate and remove these later - public void setSelectedRules(List<ForagingStrategy> selectedRules) { - this.selectedRules = selectedRules; + public void setSelectedStrategies(List<Strategy> selectedStrategies) { + this.selectedStrategies = selectedStrategies; + getRoundConfiguration().setSelectedRules(selectedStrategies); } - public List<ForagingStrategy> getSelectedRules() { - return selectedRules; + public List<Strategy> getSelectedStrategies() { + return selectedStrategies; + } + + @Deprecated + public List<Strategy> getSelectedRules() { + return selectedStrategies; } public Point3D getPoint3D(Identifier id) { diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/client/ForagingClient.java --- a/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java +++ b/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java @@ -2,6 +2,7 @@ import java.awt.BorderLayout; import java.awt.Color; +import java.util.Arrays; import java.util.LinkedList; import javax.swing.JFrame; @@ -33,7 +34,7 @@ import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.RuleSelectedUpdateEvent; import edu.asu.commons.foraging.event.RuleVoteRequest; -import edu.asu.commons.foraging.event.ShowImposedStrategyRequest; +import edu.asu.commons.foraging.event.SetImposedStrategyEvent; import edu.asu.commons.foraging.event.ShowSurveyInstructionsRequest; import edu.asu.commons.foraging.event.ShowTrustGameRequest; import edu.asu.commons.foraging.event.ShowVoteScreenRequest; @@ -162,9 +163,9 @@ getGameWindow().showTrustGame(); } }); - addEventProcessor(new EventTypeProcessor<ShowImposedStrategyRequest>(ShowImposedStrategyRequest.class) { - @Override public void handle(ShowImposedStrategyRequest request) { - getGameWindow2D().showImposedStrategy(request.getStrategy()); + addEventProcessor(new EventTypeProcessor<SetImposedStrategyEvent>(SetImposedStrategyEvent.class) { + @Override public void handle(SetImposedStrategyEvent event) { + dataModel.setSelectedStrategies(Arrays.asList(event.getStrategy())); } }); addEventProcessor(new EventTypeProcessor<ShowVotingInstructionsRequest>(ShowVotingInstructionsRequest.class) { @@ -175,7 +176,7 @@ addEventProcessor(new EventTypeProcessor<RuleSelectedUpdateEvent>(RuleSelectedUpdateEvent.class) { @Override public void handle(RuleSelectedUpdateEvent event) { - dataModel.setSelectedRules(event.getSelectedStrategies()); + dataModel.setSelectedStrategies(event.getSelectedStrategies()); getGameWindow2D().showVotingResults(event.getSelectedStrategies(), event.getVotingResults()); } }); @@ -448,8 +449,10 @@ } public void sendRuleVoteRequest(ForagingStrategy selectedRule) { - transmit(new RuleVoteRequest(getId(), selectedRule)); - getGameWindow2D().ruleVoteSubmitted(); + if (selectedRule != null) { + transmit(new RuleVoteRequest(getId(), selectedRule)); + } + getGameWindow2D().strategyNominationSubmitted(); } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java --- a/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java +++ b/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java @@ -43,7 +43,7 @@ * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev: 534 $ */ -public class RoundConfiguration extends ExperimentRoundParameters.Base<ServerConfiguration> { +public class RoundConfiguration extends ExperimentRoundParameters.Base<ServerConfiguration, RoundConfiguration> { private static final long serialVersionUID = 8575239803733029326L; @@ -58,7 +58,7 @@ private static final double DEFAULT_TOKEN_MOVEMENT_PROBABILITY = 0.2d; private static final double DEFAULT_TOKEN_BIRTH_PROBABILITY = 0.01d; - private List<ForagingStrategy> selectedRules; + private List<Strategy> selectedRules; public double getTrustGamePayoffIncrement() { return getDoubleProperty("trust-game-payoff", 0.25d); @@ -553,19 +553,19 @@ public boolean isVotingEnabled() { return getBooleanProperty("voting-enabled"); } + + public boolean isImposedStrategyEnabled() { + return getBooleanProperty("imposed-strategy-enabled"); + } public String getVotingInstructions() { - return getProperty("voting-instructions"); + return render(getProperty("voting-instructions")); } public String getInitialVotingInstructions() { return createStringTemplate(getProperty("initial-voting-instructions")).render(); } - public List<ForagingStrategy> getForagingRules() { - return Arrays.asList(ForagingStrategy.values()); - - } public boolean isVotingAndRegulationEnabled() { return getBooleanProperty("voting-and-regulation-enabled", false); } @@ -722,22 +722,25 @@ } public String getSubmittedVoteInstructions() { - return getProperty("submitted-vote-instructions", "<h1>Submitted</h1><hr><p>Your nomination has been recorded. The final results of the nomination will be shown once all the nominations in your group have been received.</p>"); + return render(getProperty("submitted-vote-instructions")); } - public String generateVotingResults(List<ForagingStrategy> selectedRules, Map<ForagingStrategy, Integer> nominations) { + public String generateVotingResults(List<Strategy> selectedRules, Map<Strategy, Integer> nominations) { List<ForagingStrategyNomination> sortedNominations = new ArrayList<ForagingStrategyNomination>(); - for (Map.Entry<ForagingStrategy, Integer> entry: new TreeMap<ForagingStrategy, Integer>(nominations).entrySet()) { - ForagingStrategy strategy = entry.getKey(); + for (Map.Entry<Strategy, Integer> entry: new TreeMap<Strategy, Integer>(nominations).entrySet()) { + Strategy strategy = entry.getKey(); sortedNominations.add(new ForagingStrategyNomination(strategy, entry.getValue(), strategy.equals(selectedRules.get(0)))); } setSelectedRules(selectedRules); ST template = createStringTemplate(getVotingResultsTemplate()); template.add("nominations", sortedNominations); template.add("tiebreaker", selectedRules.size() > 1); - template.add("selectedRules", selectedRules); return template.render(); } + + public List<ForagingStrategy> getForagingStrategies() { + return Arrays.asList(ForagingStrategy.values()); + } public String getVotingResultsTemplate() { return getProperty("voting-results", getParentConfiguration().getVotingResults()); @@ -772,11 +775,11 @@ return template.render(); } - public List<ForagingStrategy> getSelectedRules() { + public List<Strategy> getSelectedRules() { return selectedRules; } - public void setSelectedRules(List<ForagingStrategy> selectedRules) { + public void setSelectedRules(List<Strategy> selectedRules) { this.selectedRules = selectedRules; } @@ -847,10 +850,4 @@ return getProperty("survey-confirmation-message", "Please make sure you have completed the survey before continuing. Have you completed the survey?"); } - - public String getImposedStrategyInstructions(Strategy strategy) { - ST st = createStringTemplate(getProperty("imposed-strategy-instructions")); - st.add("strategy", strategy); - return st.render(); - } } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/conf/ServerConfiguration.java --- a/src/main/java/edu/asu/commons/foraging/conf/ServerConfiguration.java +++ b/src/main/java/edu/asu/commons/foraging/conf/ServerConfiguration.java @@ -24,7 +24,7 @@ * @see * @version $Revision$ */ -public class ServerConfiguration extends ExperimentConfiguration.Base<RoundConfiguration> { +public class ServerConfiguration extends ExperimentConfiguration.Base<ServerConfiguration, RoundConfiguration> { private static final long serialVersionUID = -1737412253553943902L; diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/data/AllDataProcessor.java --- a/src/main/java/edu/asu/commons/foraging/data/AllDataProcessor.java +++ b/src/main/java/edu/asu/commons/foraging/data/AllDataProcessor.java @@ -17,6 +17,8 @@ import edu.asu.commons.foraging.event.QuizResponseEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; import edu.asu.commons.foraging.event.ResourcesAddedEvent; +import edu.asu.commons.foraging.event.RuleSelectedUpdateEvent; +import edu.asu.commons.foraging.event.RuleVoteRequest; import edu.asu.commons.foraging.event.TokenCollectedEvent; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.GroupDataModel; @@ -141,6 +143,17 @@ String line = String.format("%s, %s", savedRoundData.toSecondString(event), request.toString()); writer.println(line); } + else if (event instanceof RuleVoteRequest) { + RuleVoteRequest request = (RuleVoteRequest) event; + String line = String.format("%s, %s, %s, Strategy Nomination", savedRoundData.toSecondString(event), request.getId(), request.getRule()); + writer.println(line); + } + else if (event instanceof RuleSelectedUpdateEvent) { + RuleSelectedUpdateEvent update = (RuleSelectedUpdateEvent) event; + String line = String.format("%s, %s, \"%s\", \"%s\", Rule selected", + savedRoundData.toSecondString(event), update.getGroup(), update.getSelectedStrategies(), update.getVotingResults()); + writer.println(line); + } else { writer.println(String.format("%s, %s", savedRoundData.toSecondString(event), event.toString())); } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/event/RuleSelectedUpdateEvent.java --- a/src/main/java/edu/asu/commons/foraging/event/RuleSelectedUpdateEvent.java +++ b/src/main/java/edu/asu/commons/foraging/event/RuleSelectedUpdateEvent.java @@ -5,7 +5,8 @@ import java.util.Map; import edu.asu.commons.event.AbstractPersistableEvent; -import edu.asu.commons.foraging.rules.iu.ForagingStrategy; +import edu.asu.commons.foraging.model.GroupDataModel; +import edu.asu.commons.foraging.rules.Strategy; import edu.asu.commons.net.Identifier; /** @@ -21,26 +22,35 @@ public class RuleSelectedUpdateEvent extends AbstractPersistableEvent { private static final long serialVersionUID = 4360213814026474451L; - private final List<ForagingStrategy> selectedStrategies; - private final Map<ForagingStrategy, Integer> votingResults; + private final List<Strategy> selectedStrategies; + private final Map<Strategy, Integer> votingResults; + private final GroupDataModel group; - public RuleSelectedUpdateEvent(Identifier id, List<ForagingStrategy> selectedStrategies, Map<ForagingStrategy, Integer> votingResults) { + public RuleSelectedUpdateEvent(Identifier id, GroupDataModel group, List<Strategy> selectedStrategies, Map<Strategy, Integer> votingResults) { super(id, String.format("Strategies (first is tiebreaker): %s, All nominations: %s", selectedStrategies, votingResults)); this.selectedStrategies = selectedStrategies; this.votingResults = votingResults; + this.group = group; } - public ForagingStrategy getSelectedRule() { + public Strategy getSelectedRule() { return selectedStrategies.get(0); } - public List<ForagingStrategy> getSelectedStrategies() { + public List<Strategy> getSelectedStrategies() { return selectedStrategies; } - public Map<ForagingStrategy, Integer> getVotingResults() { + public Map<Strategy, Integer> getVotingResults() { return votingResults; } + /** + * @return the group + */ + public GroupDataModel getGroup() { + return group; + } + } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/event/SetImposedStrategyEvent.java --- /dev/null +++ b/src/main/java/edu/asu/commons/foraging/event/SetImposedStrategyEvent.java @@ -0,0 +1,22 @@ +package edu.asu.commons.foraging.event; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.rules.Strategy; +import edu.asu.commons.net.Identifier; + +public class SetImposedStrategyEvent extends AbstractEvent { + + private static final long serialVersionUID = -6046837892041909032L; + + private Strategy strategy; + + public SetImposedStrategyEvent(Identifier id, Strategy strategy) { + super(id); + this.strategy = strategy; + } + + public Strategy getStrategy() { + return strategy; + } + +} diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/event/ShowImposedStrategyRequest.java --- a/src/main/java/edu/asu/commons/foraging/event/ShowImposedStrategyRequest.java +++ /dev/null @@ -1,26 +0,0 @@ -package edu.asu.commons.foraging.event; - -import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.rules.Strategy; -import edu.asu.commons.net.Identifier; - -public class ShowImposedStrategyRequest extends AbstractEvent { - - private static final long serialVersionUID = -6046837892041909032L; - - private Strategy strategy; - - public ShowImposedStrategyRequest(Identifier id) { - super(id); - } - - public ShowImposedStrategyRequest(Identifier id, Strategy strategy) { - super(id); - this.strategy = strategy; - } - - public Strategy getStrategy() { - return strategy; - } - -} diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java --- a/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java +++ b/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java @@ -25,7 +25,6 @@ import edu.asu.commons.foraging.event.FacilitatorUpdateEvent; import edu.asu.commons.foraging.event.ImposeStrategyEvent; import edu.asu.commons.foraging.event.QuizCompletedEvent; -import edu.asu.commons.foraging.event.ShowImposedStrategyRequest; import edu.asu.commons.foraging.event.ShowSurveyInstructionsRequest; import edu.asu.commons.foraging.event.ShowTrustGameRequest; import edu.asu.commons.foraging.event.ShowVoteScreenRequest; @@ -184,7 +183,7 @@ * Send a request to set the configuration object */ public void sendSetConfigRequest() { - transmit(new ConfigurationEvent<ServerConfiguration>(getId(), getServerConfiguration())); + transmit(new ConfigurationEvent<ServerConfiguration, RoundConfiguration>(getId(), getServerConfiguration())); } public FacilitatorWindow getFacilitatorWindow() { @@ -240,12 +239,4 @@ return imposedStrategyDistribution; } - public void sendShowImposedStrategy() { - if (imposedStrategyDistribution == null || imposedStrategyDistribution.isEmpty()) { - facilitatorWindow.addMessage("No imposed strategies selected, please select a strategy first."); - return; - } - transmit(new ShowImposedStrategyRequest(getId())); - } - } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java --- a/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java +++ b/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java @@ -82,9 +82,9 @@ private JMenuItem showVotingInstructionsMenuItem; private JMenuItem showVoteScreenMenuItem; private JMenuItem showSurveyInstructionsMenuItem; - private JMenuItem showExitInstructionsMenuItem; - private JMenuItem imposeStrategyMenuItem; - + private JMenuItem showExitInstructionsMenuItem; + private JMenuItem imposeStrategyMenuItem; + private HtmlEditorPane messageEditorPane; private StringBuilder instructionsBuilder; @@ -94,7 +94,7 @@ private ClipboardService clipboardService; private Map<Strategy, Integer> imposedStrategies = new HashMap<Strategy, Integer>(); - + public FacilitatorWindow(Dimension dimension, Facilitator facilitator) { this.facilitator = facilitator; initGuiComponents(); @@ -113,7 +113,7 @@ * This method gets called after the end of each round */ public void displayInstructions() { - + } /* @@ -131,7 +131,6 @@ // Round menu JMenu menu = new JMenu("Round"); menu.setMnemonic(KeyEvent.VK_R); - showInstructionsMenuItem = new JMenuItem("Show Instructions"); showInstructionsMenuItem.setMnemonic(KeyEvent.VK_I); @@ -143,7 +142,7 @@ } }); menu.add(showInstructionsMenuItem); - + startRoundMenuItem = new JMenuItem("Start"); startRoundMenuItem.setMnemonic(KeyEvent.VK_T); startRoundMenuItem.setEnabled(false); @@ -170,7 +169,7 @@ facilitator.sendShowExitInstructionsRequest(); } }); - + startChatMenuItem = new JMenuItem("Start chat"); startChatMenuItem.setEnabled(true); startChatMenuItem.addActionListener(new ActionListener() { @@ -188,10 +187,8 @@ }); menu.add(showTrustGameMenuItem); - - menuBar.add(menu); - + // voting menu menu = new JMenu("Voting"); @@ -206,38 +203,34 @@ } }); imposeStrategyMenuItem = createMenuItem(menu, "Add imposed strategy", new ActionListener() { - public void actionPerformed(ActionEvent e) { - ForagingStrategy selection = (ForagingStrategy) JOptionPane.showInputDialog(FacilitatorWindow.this, "Select the strategy to impose:\n", - "Impose Strategy", - JOptionPane.QUESTION_MESSAGE, - null, - ForagingStrategy.values(), - ForagingStrategy.NONE - ); - Integer distribution = imposedStrategies.get(selection); - if (distribution == null) { - distribution = Integer.valueOf(0); - } - imposedStrategies.put(selection, Integer.valueOf(distribution + 1)); - addMessage("Current strategy distribution: " + imposedStrategies); - } + public void actionPerformed(ActionEvent e) { + ForagingStrategy selection = (ForagingStrategy) JOptionPane.showInputDialog(FacilitatorWindow.this, "Select the strategy to impose:\n", + "Impose Strategy", + JOptionPane.QUESTION_MESSAGE, + null, + ForagingStrategy.values(), + ForagingStrategy.NONE + ); + if (selection == null) + return; + Integer distribution = imposedStrategies.get(selection); + if (distribution == null) { + distribution = Integer.valueOf(0); + } + imposedStrategies.put(selection, Integer.valueOf(distribution + 1)); + addMessage("Current strategy distribution: " + imposedStrategies); + } }); createMenuItem(menu, "Clear imposed strategies", new ActionListener() { - public void actionPerformed(ActionEvent e) { - - imposedStrategies.clear(); - } + public void actionPerformed(ActionEvent e) { + imposedStrategies.clear(); + addMessage("Cleared strategy distribution: " + imposedStrategies); + } }); - createMenuItem(menu, "Send imposed strategy", new ActionListener() { - public void actionPerformed(ActionEvent e) { - facilitator.sendImposeStrategyEvent(imposedStrategies); - } - }); - - createMenuItem(menu, "Show imposed strategy", new ActionListener() { - public void actionPerformed(ActionEvent e) { - facilitator.sendShowImposedStrategy(); - } + createMenuItem(menu, "Send imposed strategy distribution", new ActionListener() { + public void actionPerformed(ActionEvent e) { + facilitator.sendImposeStrategyEvent(imposedStrategies); + } }); menuBar.add(menu); @@ -395,16 +388,16 @@ } public void addMessage(final String message) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - try { - messageEditorPane.getDocument().insertString(0, "-----\n" + message + "\n", null); - messageEditorPane.setCaretPosition(0); - } catch (BadLocationException exception) { - exception.printStackTrace(); - } - } - }); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + messageEditorPane.getDocument().insertString(0, "-----\n" + message + "\n", null); + messageEditorPane.setCaretPosition(0); + } catch (BadLocationException exception) { + exception.printStackTrace(); + } + } + }); } public void quizCompleted(QuizCompletedEvent event) { @@ -469,10 +462,10 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (String.class.equals(flavor.getRepresentationClass())) { return html; - } + } else if (Reader.class.equals(flavor.getRepresentationClass())) { return new StringReader(html); - } + } else if (InputStream.class.equals(flavor.getRepresentationClass())) { return new ByteArrayInputStream(html.getBytes()); } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java --- a/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java +++ b/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java @@ -79,7 +79,7 @@ private ArrayList<RegulationData> submittedRegulations = new ArrayList<RegulationData>(); - private ArrayList<ForagingStrategy> selectedRules; + private ArrayList<Strategy> selectedRules; public GroupDataModel(ServerDataModel serverDataModel) { this(serverDataModel, nextGroupId++); @@ -766,9 +766,20 @@ public EventChannel getEventChannel() { return serverDataModel.getEventChannel(); } + + public Map<Strategy, Integer> generateVotingResults() { + return generateVotingResults(getRoundConfiguration().isImposedStrategyEnabled()); + } - public Map<ForagingStrategy, Integer> generateVotingResults() { - Map<ForagingStrategy, Integer> tallyMap = new HashMap<ForagingStrategy, Integer>(); + public Map<Strategy, Integer> generateVotingResults(boolean imposedStrategyEnabled) { + Map<Strategy, Integer> tallyMap = new HashMap<Strategy, Integer>(); + selectedRules = new ArrayList<Strategy>(); + if (imposedStrategyEnabled) { + // short circuits to use the imposed strategy + tallyMap.put(getImposedStrategy(), 1); + selectedRules.add(getImposedStrategy()); + return tallyMap; + } for (ClientData client: clients.values()) { ForagingStrategy rule = client.getVotedRule(); Integer count = tallyMap.get(rule); @@ -777,9 +788,9 @@ } tallyMap.put(rule, count + 1); } - selectedRules = new ArrayList<ForagingStrategy>(); + Integer maxSeenValue = 0; - for (Map.Entry<ForagingStrategy, Integer> entry : tallyMap.entrySet()) { + for (Map.Entry<Strategy, Integer> entry : tallyMap.entrySet()) { Integer currentValue = entry.getValue(); // getLogger().info("rule : " + entry.getKey() + " has a vote value of " + currentValue); @@ -801,12 +812,12 @@ return tallyMap; } - public List<ForagingStrategy> getSelectedRules() { + public List<Strategy> getSelectedRules() { return selectedRules; } - public ForagingStrategy getSelectedRule() { + public Strategy getSelectedRule() { return selectedRules.get(0); } @@ -820,7 +831,7 @@ } public void setImposedStrategy(Strategy imposedStrategy) { - this.imposedStrategy = imposedStrategy; + this.imposedStrategy = imposedStrategy; } } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/model/ServerDataModel.java --- a/src/main/java/edu/asu/commons/foraging/model/ServerDataModel.java +++ b/src/main/java/edu/asu/commons/foraging/model/ServerDataModel.java @@ -63,6 +63,8 @@ // Maps client Identifiers to the GroupDataModel that the client belongs to private final Map<Identifier, GroupDataModel> clientsToGroups = new HashMap<Identifier, GroupDataModel>(); + private Map<Strategy, Integer> imposedStrategyDistribution; + public ServerDataModel() { super(EventTypeChannel.getInstance()); } @@ -463,24 +465,41 @@ } + public List<GroupDataModel> allocateImposedStrategyDistribution(Map<Strategy, Integer> imposedStrategyDistribution) { - List<GroupDataModel> groups = getOrderedGroups(); - int numberOfGroups = groups.size(); - Collections.shuffle(groups); - Iterator<GroupDataModel> groupIterator = groups.iterator(); - int numberOfStrategies = 0; - for (Map.Entry<Strategy, Integer> entry : imposedStrategyDistribution.entrySet()) { - Strategy strategy = entry.getKey(); - int occurrences = entry.getValue(); - if (numberOfStrategies > numberOfGroups) { - throw new IllegalArgumentException("Invalid number of strategies : " + numberOfStrategies + " for " + numberOfGroups + " groups."); - } - for (int i = 0; i < occurrences; i++) { - GroupDataModel group = groupIterator.next(); - group.setImposedStrategy(strategy); - numberOfStrategies++; - } - } - return groups; + if (imposedStrategyDistribution == null || imposedStrategyDistribution.isEmpty()) { + throw new IllegalArgumentException("No strategy distribution defined. Please create a strategy distribution and try again."); + } + List<GroupDataModel> groups = getOrderedGroups(); + int numberOfGroups = groups.size(); + Collections.shuffle(groups); + Iterator<GroupDataModel> groupIterator = groups.iterator(); + int numberOfStrategies = 0; + for (Map.Entry<Strategy, Integer> entry : imposedStrategyDistribution.entrySet()) { + Strategy strategy = entry.getKey(); + int occurrences = entry.getValue(); + if (numberOfStrategies > numberOfGroups) { + throw new IllegalArgumentException("Invalid number of strategies : " + numberOfStrategies + " for " + numberOfGroups + " groups."); + } + for (int i = 0; i < occurrences; i++) { + GroupDataModel group = groupIterator.next(); + group.setImposedStrategy(strategy); + numberOfStrategies++; + } + } + return groups; } + + public List<GroupDataModel> allocateImposedStrategyDistribution() { + return allocateImposedStrategyDistribution(imposedStrategyDistribution); + } + + public void setImposedStrategyDistribution(Map<Strategy, Integer> strategyDistribution) { + this.imposedStrategyDistribution = strategyDistribution; + } + + public Map<Strategy, Integer> getImposedStrategyDistribution() { + return imposedStrategyDistribution; + } + } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/rules/iu/ForagingStrategyNomination.java --- a/src/main/java/edu/asu/commons/foraging/rules/iu/ForagingStrategyNomination.java +++ b/src/main/java/edu/asu/commons/foraging/rules/iu/ForagingStrategyNomination.java @@ -1,16 +1,18 @@ package edu.asu.commons.foraging.rules.iu; +import edu.asu.commons.foraging.rules.Strategy; + public class ForagingStrategyNomination { - private final ForagingStrategy strategy; + private final Strategy strategy; private final Integer nominations; private final boolean selected; - public ForagingStrategyNomination(ForagingStrategy strategy, Integer nominations, boolean selected) { + public ForagingStrategyNomination(Strategy strategy, Integer nominations, boolean selected) { this.strategy = strategy; this.nominations = nominations; this.selected = selected; } - public ForagingStrategy getStrategy() { + public Strategy getStrategy() { return strategy; } public Integer getNominations() { diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/server/ForagingServer.java --- a/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java +++ b/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java @@ -13,6 +13,7 @@ import java.util.ListIterator; import java.util.Map; import java.util.Set; +import java.util.logging.Level; import edu.asu.commons.event.BeginRoundRequest; import edu.asu.commons.event.ChatEvent; @@ -61,7 +62,8 @@ import edu.asu.commons.foraging.event.RuleSelectedUpdateEvent; import edu.asu.commons.foraging.event.RuleVoteRequest; import edu.asu.commons.foraging.event.SanctionAppliedEvent; -import edu.asu.commons.foraging.event.ShowImposedStrategyRequest; +import edu.asu.commons.foraging.event.SetImposedStrategyEvent; +import edu.asu.commons.foraging.event.ShowVoteScreenRequest; import edu.asu.commons.foraging.event.SurveyIdSubmissionRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.event.TrustGameResultsFacilitatorEvent; @@ -76,7 +78,7 @@ import edu.asu.commons.foraging.model.ResourceDispenser; import edu.asu.commons.foraging.model.ServerDataModel; import edu.asu.commons.foraging.model.TrustGameResult; -import edu.asu.commons.foraging.rules.iu.ForagingStrategy; +import edu.asu.commons.foraging.rules.Strategy; import edu.asu.commons.foraging.ui.Circle; import edu.asu.commons.net.Dispatcher; import edu.asu.commons.net.Identifier; @@ -102,8 +104,6 @@ public final static int SYNCHRONIZATION_FREQUENCY = 60; public final static int SERVER_SLEEP_INTERVAL = 75; - private Identifier facilitatorId; - // FIXME: investigate using java.util.concurrent constructs instead, e.g., CountDownLatch / CyclicBarrier private final Object roundSignal = new Object(); private final Object quizSignal = new Object(); @@ -253,7 +253,7 @@ clients.put(identifier, new ClientData(identifier)); } // send welcome instructions and experiment configuration - transmit(new SetConfigurationEvent<RoundConfiguration>(identifier, getCurrentRoundConfiguration())); + transmit(new SetConfigurationEvent<ServerConfiguration, RoundConfiguration>(identifier, getCurrentRoundConfiguration())); } }); addEventProcessor(new EventTypeProcessor<DisconnectionRequest>(DisconnectionRequest.class) { @@ -261,7 +261,12 @@ public void handle(DisconnectionRequest event) { synchronized (clients) { Identifier id = event.getId(); - getLogger().warning("Disconnecting client, removing " + id + " from clients " + clients.keySet()); + if (id.equals(getFacilitatorId())) { + getLogger().log(Level.SEVERE, "Disconnecting facilitator.", event.getException()); + } + else { + sendFacilitatorMessage("Received DisconnectionRequest, removing " + id + " from clients " + clients.keySet(), event.getException()); + } clients.remove(id); serverDataModel.removeClient(id); } @@ -281,7 +286,7 @@ public void handle(FacilitatorCensoredChatRequest request) { if (getCurrentRoundConfiguration().isCensoredChat()) { sendFacilitatorMessage("needs approval: " + request); - request.setId(facilitatorId); + request.setId(getFacilitatorId()); transmit(request); } else { @@ -306,7 +311,7 @@ public void handle(final QuizResponseEvent event) { sendFacilitatorMessage("Received quiz response: " + event); numberOfSubmittedQuizzes++; - transmit(new QuizCompletedEvent(facilitatorId, event)); + transmit(new QuizCompletedEvent(getFacilitatorId(), event)); ClientData clientData = clients.get(event.getId()); clientData.addCorrectQuizAnswers(event.getNumberOfCorrectAnswers()); if (numberOfSubmittedQuizzes >= clients.size()) { @@ -333,7 +338,7 @@ transmit(updateEvent); } // update the facilitator - transmit(new FacilitatorSanctionUpdateEvent(facilitatorId, serverDataModel)); + transmit(new FacilitatorSanctionUpdateEvent(getFacilitatorId(), serverDataModel)); Utils.notify(facilitatorSignal); numberOfCompletedSanctions = 0; } @@ -369,7 +374,6 @@ }); addEventProcessor(new EventTypeProcessor<RuleVoteRequest>(RuleVoteRequest.class) { int votesReceived = 0; - @Override public void handle(RuleVoteRequest request) { sendFacilitatorMessage("Received vote rule request: " + request); @@ -377,19 +381,7 @@ client.setVotedRule(request.getRule()); votesReceived++; if (votesReceived >= clients.size()) { - // calculate votes - for (GroupDataModel group : serverDataModel.getGroups()) { - Map<ForagingStrategy, Integer> votingResults = group.generateVotingResults(); - List<ForagingStrategy> selectedRules = group.getSelectedRules(); - for (Identifier id : group.getClientIdentifiers()) { - sendFacilitatorMessage(String.format( - "%s selected [%s] from all rules (%s)", - group, selectedRules, votingResults)); - - transmit(new RuleSelectedUpdateEvent(id, selectedRules, votingResults)); - } - store(new RuleSelectedUpdateEvent(facilitatorId, selectedRules, votingResults)); - } + processNominations(); } } }); @@ -412,6 +404,24 @@ }); } + + private void processNominations() { + boolean imposedStrategyEnabled = getCurrentRoundConfiguration().isImposedStrategyEnabled(); + for (GroupDataModel group : serverDataModel.getGroups()) { + // calculate votes + Map<Strategy, Integer> votingResults = group.generateVotingResults(imposedStrategyEnabled); + List<Strategy> selectedRules = group.getSelectedRules(); + sendFacilitatorMessage(String.format( + "%s selected [%s] from all rules %s (imposed? %s)", + group, selectedRules, votingResults, imposedStrategyEnabled)); + if (! imposedStrategyEnabled) { + for (Identifier id : group.getClientIdentifiers()) { + transmit(new RuleSelectedUpdateEvent(id, group, selectedRules, votingResults)); + } + } + store(new RuleSelectedUpdateEvent(getFacilitatorId(), group, selectedRules, votingResults)); + } + } @Deprecated @SuppressWarnings("unused") @@ -575,8 +585,9 @@ // facilitator handlers addEventProcessor(new EventTypeProcessor<FacilitatorRegistrationRequest>(FacilitatorRegistrationRequest.class) { public void handle(FacilitatorRegistrationRequest event) { - // remap the facilitator ID and remove from the clients list. - facilitatorId = event.getId(); + Identifier facilitatorId = event.getId(); + getLogger().info("Registering facilitator: " + facilitatorId); + setFacilitatorId(event.getId()); synchronized (clients) { clients.remove(facilitatorId); } @@ -585,46 +596,28 @@ addEventProcessor(new EventTypeProcessor<ImposeStrategyEvent>(ImposeStrategyEvent.class) { @Override public void handle(ImposeStrategyEvent event) { - if (! event.getId().equals(facilitatorId)) { + if (! event.getId().equals(getFacilitatorId())) { sendFacilitatorMessage("Ignoring request to impose strategy " + event); return; } + serverDataModel.setImposedStrategyDistribution(event.getStrategyDistribution()); + sendFacilitatorMessage("Setting imposed strategy distribution to " + event.getStrategyDistribution()); persister.store(event); - try { - List<GroupDataModel> groups = serverDataModel.allocateImposedStrategyDistribution(event.getStrategyDistribution()); - StringBuilder builder = new StringBuilder(); - for (GroupDataModel group: groups) { - builder.append('[').append(group).append(':').append(group.getImposedStrategy()).append(']'); - } - sendFacilitatorMessage("Server has imposed strategies for all groups: " + builder); - - } - catch (IllegalArgumentException exception) { - sendFacilitatorMessage("Couldn't allocate strategy distribution: " + event, exception); - } - } - }); - addEventProcessor(new EventTypeProcessor<ShowImposedStrategyRequest>(ShowImposedStrategyRequest.class) { - @Override - public void handle(ShowImposedStrategyRequest request) { - if (! request.getId().equals(facilitatorId)) { - sendFacilitatorMessage("Ignoring request to show imposed strategies from: " + request.getId()); - return; - } - for (Identifier id: clients.keySet()) { - transmit(new ShowImposedStrategyRequest(id, serverDataModel.getGroup(id).getImposedStrategy())); - } - sendFacilitatorMessage("Notified all groups of imposed strategy."); } }); addEventProcessor(new EventTypeProcessor<ShowRequest>(ShowRequest.class, true) { @Override public void handle(ShowRequest request) { // validity checks: request from facilitator? - if (! request.getId().equals(facilitatorId)) { + if (! request.getId().equals(getFacilitatorId())) { sendFacilitatorMessage("Ignoring show request from non facilitator id: " + request.getId()); return; } + // FIXME: bah, more special casing. figure out a better way + // to determine when to send the imposed strategy.. + if (request instanceof ShowVoteScreenRequest && getCurrentRoundConfiguration().isImposedStrategyEnabled()) { + sendImposedStrategy(); + } // if this is a ShowExitInstructionsRequest, is this the last round at least? if (request instanceof ShowExitInstructionsRequest && ! getCurrentRoundConfiguration().isLastRound()) { sendFacilitatorMessage("Ignoring request to show exit instructions, we are not at the last round yet."); @@ -637,7 +630,7 @@ }); addEventProcessor(new EventTypeProcessor<BeginRoundRequest>(BeginRoundRequest.class) { public void handle(BeginRoundRequest event) { - if (event.getId().equals(facilitatorId)) { + if (event.getId().equals(getFacilitatorId())) { if (isReadyToStartRound()) { getLogger().info("Begin round request from facilitator - starting round."); experimentStarted = true; @@ -657,7 +650,7 @@ }); addEventProcessor(new EventTypeProcessor<EndRoundRequest>(EndRoundRequest.class) { public void handle(EndRoundRequest request) { - if (request.getId().equals(facilitatorId)) { + if (request.getId().equals(getFacilitatorId())) { // set current round duration to expire? currentRoundDuration.stop(); } @@ -691,7 +684,7 @@ clientData.setTrustGamePlayerOneAmountToKeep(request.getPlayerOneAmountToKeep()); clientData.setTrustGamePlayerTwoAmountsToKeep(request.getPlayerTwoAmountsToKeep()); persister.store(request); - transmit(new TrustGameSubmissionEvent(facilitatorId, request)); + transmit(new TrustGameSubmissionEvent(getFacilitatorId(), request)); numberOfSubmissions++; sendFacilitatorMessage(String.format("Received trust game submission %s (%d total)", request, numberOfSubmissions)); } @@ -762,7 +755,7 @@ transmit(new ShowExitInstructionsRequest(data.getId(), data.getGroupDataModel())); } } - transmitAndStore(new TrustGameResultsFacilitatorEvent(facilitatorId, serverDataModel, allTrustGameResults)); + transmitAndStore(new TrustGameResultsFacilitatorEvent(getFacilitatorId(), serverDataModel, allTrustGameResults)); Utils.notify(facilitatorSignal); } @@ -855,7 +848,7 @@ // while waiting for connections we must defer group initialization till all clients // are connected (which is unknown, we allow clients to connect until the experiment has started) setupRound(); - sendFacilitatorMessage("Ready to show instructions and the start next round."); + sendFacilitatorMessage("Ready to show instructions and start the next round."); if (getCurrentRoundConfiguration().isQuizEnabled()) { getLogger().info("Waiting for all quizzes to be submitted."); Utils.waitOn(quizSignal); @@ -870,6 +863,23 @@ break; } } + + private void sendImposedStrategy() { + try { + List<GroupDataModel> groups = serverDataModel.allocateImposedStrategyDistribution(); + StringBuilder builder = new StringBuilder(); + for (GroupDataModel group: groups) { + builder.append('[').append(group).append(':').append(group.getImposedStrategy()).append(']'); + for (Identifier id: group.getClientIdentifiers()) { + transmit(new SetImposedStrategyEvent(id, group.getImposedStrategy())); + } + } + sendFacilitatorMessage("Server has imposed strategies for all groups: " + builder); + } + catch (IllegalArgumentException exception) { + sendFacilitatorMessage("Couldn't allocate strategy distribution: " + serverDataModel.getImposedStrategyDistribution(), exception); + } + } private void setupRound() { persister.initialize(getCurrentRoundConfiguration()); @@ -912,9 +922,9 @@ getLogger().info("Advancing to round # " + getConfiguration().getCurrentRoundNumber()); // send the next round configuration to each client for (Identifier id : clients.keySet()) { - transmit(new SetConfigurationEvent<RoundConfiguration>(id, nextRoundConfiguration)); + transmit(new SetConfigurationEvent<ServerConfiguration, RoundConfiguration>(id, nextRoundConfiguration)); } - transmit(new SetConfigurationEvent<RoundConfiguration>(facilitatorId, nextRoundConfiguration)); + transmit(new SetConfigurationEvent<ServerConfiguration, RoundConfiguration>(getFacilitatorId(), nextRoundConfiguration)); } private void processRound() { @@ -978,7 +988,7 @@ } // FIXME: refine this, send basic info to the facilitator (how many resources left, etc.) if (shouldUpdateFacilitator()) { - transmit(new FacilitatorUpdateEvent(facilitatorId, serverDataModel, currentRoundDuration.getTimeLeft())); + transmit(new FacilitatorUpdateEvent(getFacilitatorId(), serverDataModel, currentRoundDuration.getTimeLeft())); } } @@ -990,7 +1000,7 @@ private boolean shouldSynchronize(ClientData data) { long startCount = secondTick.getStartCount(); int assignedNumber = data.getAssignedNumber(); - return (startCount < 2) || ((startCount % SYNCHRONIZATION_FREQUENCY) == (assignedNumber * 10)); + return (startCount == 0) || ((startCount % SYNCHRONIZATION_FREQUENCY) == (assignedNumber * 10)); } private void sendEndRoundEvents() { @@ -998,7 +1008,7 @@ // 1. avg number of tokens collected in this round for the group // 2. total number of tokens collected by this client // 3. number of tokens collected by this client in this round. - transmit(new FacilitatorEndRoundEvent(facilitatorId, serverDataModel)); + transmit(new FacilitatorEndRoundEvent(getFacilitatorId(), serverDataModel)); boolean lastRound = getConfiguration().isLastRound(); for (Map.Entry<Identifier, ClientData> clientDataEntry : clients.entrySet()) { Identifier id = clientDataEntry.getKey(); @@ -1077,7 +1087,7 @@ getLogger().info("monitor rotation interval: " + monitorRotationInterval); } currentRoundDuration.start(); - transmit(new FacilitatorUpdateEvent(facilitatorId, serverDataModel, currentRoundDuration.getTimeLeft())); + transmit(new FacilitatorUpdateEvent(getFacilitatorId(), serverDataModel, currentRoundDuration.getTimeLeft())); secondTick.start(); serverState = ServerState.ROUND_IN_PROGRESS; } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java --- a/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java +++ b/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java @@ -57,7 +57,6 @@ import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.Direction; import edu.asu.commons.foraging.rules.Strategy; -import edu.asu.commons.foraging.rules.iu.ForagingStrategy; import edu.asu.commons.net.Identifier; import edu.asu.commons.ui.HtmlEditorPane; import edu.asu.commons.ui.UserInterfaceUtils; @@ -741,22 +740,27 @@ } public void showVotingScreen() { - if (votingPanel == null) { - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingInstructionsEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); - votingInstructionsScrollPane = new JScrollPane(votingInstructionsEditorPane); - votingInstructionsEditorPane.setText(client.getCurrentRoundConfiguration().getVotingInstructions()); - votingPanel.add(votingInstructionsScrollPane); - votingForm = new VotingForm(client); - votingPanel.add(votingForm); - votingPanel.setName(VotingForm.NAME); - add(votingPanel); - } - showPanel(VotingForm.NAME); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (votingPanel == null) { + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingInstructionsEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); + votingInstructionsScrollPane = new JScrollPane(votingInstructionsEditorPane); + RoundConfiguration configuration = client.getCurrentRoundConfiguration(); + votingInstructionsEditorPane.setText(configuration.getVotingInstructions()); + votingPanel.add(votingInstructionsScrollPane); + votingForm = new VotingForm(client); + votingPanel.add(votingForm); + votingPanel.setName(VotingForm.NAME); + add(votingPanel); + } + showPanel(VotingForm.NAME); + } + }); } - public void showVotingResults(final List<ForagingStrategy> selectedRules, final Map<ForagingStrategy, Integer> votingResults) { + public void showVotingResults(final List<Strategy> selectedRules, final Map<Strategy, Integer> votingResults) { SwingUtilities.invokeLater(new Runnable() { public void run() { votingPanel.removeAll(); @@ -882,18 +886,10 @@ showInstructionsPanel(); } - public void ruleVoteSubmitted() { - setInstructions(dataModel.getRoundConfiguration().getSubmittedVoteInstructions()); + public void strategyNominationSubmitted() { + RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); + setInstructions(roundConfiguration.getSubmittedVoteInstructions()); showInstructionsPanel(); } - public void showImposedStrategy(final Strategy strategy) { - SwingUtilities.invokeLater(new Runnable() { - @Override public void run() { - setInstructions(dataModel.getRoundConfiguration().getImposedStrategyInstructions(strategy)); - } - }); - } - - } diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/java/edu/asu/commons/foraging/ui/VotingForm.java --- a/src/main/java/edu/asu/commons/foraging/ui/VotingForm.java +++ b/src/main/java/edu/asu/commons/foraging/ui/VotingForm.java @@ -32,15 +32,21 @@ import javax.swing.WindowConstants; import edu.asu.commons.foraging.client.ForagingClient; +import edu.asu.commons.foraging.rules.Strategy; import edu.asu.commons.foraging.rules.iu.ForagingStrategy; import edu.asu.commons.ui.UserInterfaceUtils; /** * $Id$ + * + * Interface nominate a given ForagingStrategy + * * @author Allen Lee */ public class VotingForm extends JPanel { + private static final int DEFAULT_STRATEGY_GAP_SIZE = 80; + private static final long serialVersionUID = 3871660663519284024L; public final static String NAME = "Strategy voting form"; @@ -48,18 +54,18 @@ private ForagingClient client; public VotingForm(ForagingClient client) { - this(client, new HashMap<ForagingStrategy, Integer>()); + this(client, new HashMap<Strategy, Integer>()); } - public VotingForm(ForagingClient client, Map<ForagingStrategy, Integer> votingResults) { + public VotingForm(ForagingClient client, Map<Strategy, Integer> votingResults) { this.client = client; initComponents(); initForm(votingResults); setName(NAME); } - private void initForm(Map<ForagingStrategy, Integer> votingResults) { - ForagingStrategy[] rules = ForagingStrategy.values(); + private void initForm(Map<Strategy, Integer> votingResults) { + ForagingStrategy[] strategies = ForagingStrategy.values(); JPanel panel = new JPanel(); GroupLayout groupLayout = new GroupLayout(panel); panel.setLayout(groupLayout); @@ -73,7 +79,11 @@ horizontalGroup.addGroup(horizontalButtonParallelGroup); GroupLayout.SequentialGroup verticalGroup = groupLayout.createSequentialGroup(); - String rightColumnHeader = votingResults.isEmpty() ? "Select" : "Nominations"; + boolean imposedStrategyEnabled = (client != null) && client.getCurrentRoundConfiguration().isImposedStrategyEnabled(); + // XXX: this is certainly what Rawlins was warning against + String rightColumnHeader = votingResults.isEmpty() + ? (imposedStrategyEnabled) ? "" : "Select" + : "Nominations"; JLabel rightHeaderLabel = new JLabel(rightColumnHeader); rightHeaderLabel.setFont(UserInterfaceUtils.DEFAULT_BOLD_FONT); horizontalButtonParallelGroup.addComponent(rightHeaderLabel); @@ -83,27 +93,31 @@ horizontalLabelParallelGroup.addComponent(strategyHeaderLabel); verticalGroup.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(strategyHeaderLabel).addGap(20).addComponent(rightHeaderLabel)); - Dimension labelDimension = new Dimension(800, 100); - for (ForagingStrategy rule: rules) { - JLabel ruleLabel = new JLabel("<html>" + rule.getDescription() + "</html>"); + Dimension labelDimension = new Dimension(1000, 100); + + for (ForagingStrategy strategy: strategies) { + JLabel ruleLabel = new JLabel("<html>" + strategy.getDescription() + "</html>"); ruleLabel.setFont(UserInterfaceUtils.DEFAULT_PLAIN_FONT); ruleLabel.setMaximumSize(labelDimension); horizontalLabelParallelGroup.addComponent(ruleLabel); JComponent component = null; - if (votingResults.isEmpty()) { + if (imposedStrategyEnabled) { + component = new JLabel(""); + } + else if (votingResults.isEmpty()) { JRadioButton radioButton = new JRadioButton(); - radioButton.setActionCommand(rule.name()); + radioButton.setActionCommand(strategy.name()); buttonGroup.add(radioButton); component = radioButton; - horizontalButtonParallelGroup.addComponent(radioButton); - verticalGroup.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(ruleLabel).addComponent(radioButton)); +// horizontalButtonParallelGroup.addComponent(radioButton); +// verticalGroup.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(ruleLabel).addComponent(radioButton)); } else { - Integer numberOfVotes = votingResults.get(rule); + Integer numberOfVotes = votingResults.get(strategy); component = new JLabel(String.valueOf(numberOfVotes == null ? 0 : numberOfVotes)); } horizontalButtonParallelGroup.addComponent(component); - verticalGroup.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(ruleLabel).addComponent(component)); + verticalGroup.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(ruleLabel).addGap(DEFAULT_STRATEGY_GAP_SIZE).addComponent(component)); } if (votingResults.isEmpty()) { JButton submitButton = getSubmitButton(); @@ -121,6 +135,10 @@ JButton submitButton = new JButton("Submit"); submitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + if (client.getCurrentRoundConfiguration().isImposedStrategyEnabled()) { + client.sendRuleVoteRequest(null); + return; + } ButtonModel model = buttonGroup.getSelection(); if (model == null) { JOptionPane.showMessageDialog(VotingForm.this, "Please select a strategy."); diff -r bbb67c1354864fb3543f0b66a02482908d18d028 -r 78057caab3b65da359093d97d27c9c9b2fcdbe99 src/main/resources/configuration/iu/2011/imposed-punish/round0.xml --- /dev/null +++ b/src/main/resources/configuration/iu/2011/imposed-punish/round0.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="resource-width">13</entry> +<entry key="resource-depth">13</entry> +<entry key="practice-round">true</entry> +<entry key="private-property">true</entry> +<entry key="duration">240</entry> + +<entry key="quiz">true</entry> +<entry key="q1">C</entry> +<entry key="q2">B</entry> + +<entry key='instructions'> +<![CDATA[ +<h2>Practice Round Instructions</h2> +<hr> +<p> + Once everyone has finished the quiz, we will start a practice round of the token + task. +</p> +<p> + During the practice round, you will have {duration} to practice with the + experimental environment. The decisions you make in this round will NOT + influence your earnings. At the beginning of the practice round + {initialDistri... [truncated message content] |