[gee-svn] SF.net SVN: gabel: [143] trunk/gee/src/java/edu/indiana/psych/gee
Status: Alpha
Brought to you by:
alllee
|
From: <al...@us...> - 2006-03-05 05:17:18
|
Revision: 143 Author: alllee Date: 2006-03-04 21:17:09 -0800 (Sat, 04 Mar 2006) ViewCVS: http://svn.sourceforge.net/gabel/?rev=143&view=rev Log Message: ----------- mapping ForagerAgentConfiguration and more properties from ForagerExperimentParameters. Modified Paths: -------------- trunk/gee/src/java/edu/indiana/psych/gee/ConsentForm.java trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java trunk/gee/src/java/edu/indiana/psych/gee/event/EventChannel.java trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerAgentConfiguration.java trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperiment.java trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java Modified: trunk/gee/src/java/edu/indiana/psych/gee/ConsentForm.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/ConsentForm.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/ConsentForm.java 2006-03-05 05:17:09 UTC (rev 143) @@ -7,7 +7,9 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; -import javax.persistence.*; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; /** * $Id$ Modified: trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java 2006-03-05 05:17:09 UTC (rev 143) @@ -3,9 +3,6 @@ import java.net.InetSocketAddress; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import edu.indiana.psych.gee.time.Duration; /** Modified: trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java 2006-03-05 05:17:09 UTC (rev 143) @@ -34,21 +34,20 @@ implements ExperimentConfiguration<T> { private final static String DEFAULT_SERVER_ADDRESS = "groups.psych.indiana.edu"; - + + // persistent fields private long id = -1; - private String description; private String experimentName; private String clientJarName; private String clientMainClass; private ConsentForm consentForm; - - private T currentParameters; - private InetSocketAddress serverAddress; private int serverPort; private String serverName; private boolean triggeredExperiment; + // transient fields + private InetSocketAddress serverAddress; public ExperimentConfigurationEntity(String serverName, int port) { setServerName(serverName); Modified: trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java 2006-03-05 05:17:09 UTC (rev 143) @@ -1,12 +1,7 @@ package edu.indiana.psych.gee; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; import javax.persistence.Table; -import javax.persistence.*; /** * $Id: Exp$ @@ -17,8 +12,15 @@ * @version $Revision: $ */ +@Entity +@Table(name="experiment_parameters") public abstract class ExperimentParametersEntity<T extends ExperimentConfiguration> implements ExperimentRoundParameters { + private long id = -1; + + + + } Modified: trunk/gee/src/java/edu/indiana/psych/gee/event/EventChannel.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/event/EventChannel.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/event/EventChannel.java 2006-03-05 05:17:09 UTC (rev 143) @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -137,21 +136,21 @@ * @see mud.engine.EventGenerator */ private static class EventDispatcher { - /** - * Map<EventHandler, EventConstraint > - */ - private final Map eventListeners; + private final Map<EventHandler, EventConstraint> eventListeners; /** * Create a new EventDispatcher. */ protected EventDispatcher() { - eventListeners = new HashMap(); + eventListeners = new HashMap<EventHandler, EventConstraint>(); } /** - * This method allows EventGenerators to add an EventHandler and EventConstraint. - * This should be used within the EventGenerator's subscribe() method. + * Associates a constraint with a given handler; whenever an Event passes + * through the EventChannel the constraint is applied to the event. If + * successful, the Event is passed to the EventHandler, otherwise it's + * skipped. Currently only supports 1-1 mappings between constraints + * and handlers. * * @param handler EventHandler to subscribe. * @param constraint EventConstraint to filter with. @@ -174,23 +173,26 @@ /** * Fires the given event to all interested EventHandlers. This method * provides a way for Events to be sent to all EventHandlers subscribed - * for them. This method should be used in an EventGenerator whenever an - * event needs to be fired. + * for them. * * @param event The event to fire. */ protected synchronized void dispatch(final Event event) { + for (Map.Entry<EventHandler, EventConstraint> entry : eventListeners.entrySet()) { + if (entry.getValue().accepts(event)) { + entry.getKey().handle(event); + } + } + /* for (Iterator handlers = eventListeners.keySet().iterator(); handlers.hasNext(); ) { final EventHandler handler = (EventHandler) handlers.next(); - final EventConstraint constraint = getConstraintFor(handler); + final EventConstraint constraint = eventListeners.get(handler); if ( constraint.accepts(event) ) { handler.handle(event); } } + */ } - private EventConstraint getConstraintFor(EventHandler handler) { - return (EventConstraint) eventListeners.get(handler); - } } } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerAgentConfiguration.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerAgentConfiguration.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerAgentConfiguration.java 2006-03-05 05:17:09 UTC (rev 143) @@ -3,6 +3,8 @@ import java.util.Properties; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.Proxy; @@ -15,30 +17,36 @@ public class ForagerAgentConfiguration implements AgentConfiguration { private static final long serialVersionUID = -6259298886681245586L; - - private final ForagerConfiguration foragerConfiguration; - - /** - * @param configuration - */ - ForagerAgentConfiguration(ForagerConfiguration configuration) { - foragerConfiguration = configuration; + + private long id = -1; + + private int foodReward = 200; + private int expectedFoodReward = 500; + private int luceK = 100; + private int movementPenalty = 2; + private float movementRate = 0.5f; + private Properties properties; + + @Id @GeneratedValue + public long getId() { + return id; } + + public void setId(long id) { + this.id = id; + } - - Properties properties; - public int getFoodReward() { - return 200; + return foodReward; } public int getExpectedFoodReward() { - return 500; + return expectedFoodReward; } public int getLuceK() { - return 100; + return luceK; } public int getMovementPenalty() { - return 2; + return movementPenalty; } public Properties getProperties() { @@ -46,6 +54,26 @@ } public float getMovementRate() { - return 0.5f; + return movementRate; } + + public void setExpectedFoodReward(int expectedFoodReward) { + this.expectedFoodReward = expectedFoodReward; + } + + public void setFoodReward(int foodReward) { + this.foodReward = foodReward; + } + + public void setLuceK(int luceK) { + this.luceK = luceK; + } + + public void setMovementPenalty(int movementPenalty) { + this.movementPenalty = movementPenalty; + } + + public void setMovementRate(float movementRate) { + this.movementRate = movementRate; + } } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java 2006-03-05 05:17:09 UTC (rev 143) @@ -16,13 +16,12 @@ import edu.indiana.psych.gee.ExperimentConfiguration; import edu.indiana.psych.gee.ExperimentConfigurationEntity; -import edu.indiana.psych.gee.forager.client.ForagerApplet; import edu.indiana.psych.gee.time.Duration; /** * $Id$ * - * Configuration for the forager experiment. + * Persistent configuration for the forager experiment. * * * @author <a href='al...@cs...'>Allen Lee</a> @@ -52,9 +51,6 @@ return ForagerApplet.class.getName(); } - public String getExperimentName() { - return "forager"; - } public String getDescription() { return "The Forager experiment explores how participants allocate themselves in a world with scarce resources."; } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperiment.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperiment.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperiment.java 2006-03-05 05:17:09 UTC (rev 143) @@ -11,7 +11,6 @@ import java.util.SortedSet; import edu.indiana.psych.gee.AbstractExperiment; -import edu.indiana.psych.gee.ConsentForm; import edu.indiana.psych.gee.Identifier; import edu.indiana.psych.gee.agent.Agent; import edu.indiana.psych.gee.event.AbortExperimentRequest; @@ -185,7 +184,7 @@ */ private void addAgents(ForagerExperimentParameters configuration) { int numberOfParticipants = currentParticipantHeadings.size(); - int minimumParticipants = configuration.getMinimumParticipants(); + int minimumParticipants = configuration.getMinimumParticipantsForNoBots(); getLogger().debug(String.format("Need [%d] participants - have [%d]", minimumParticipants, numberOfParticipants)); if (numberOfParticipants < minimumParticipants) { @@ -237,11 +236,7 @@ } enum ForagerState implements State { WAITING, ROUND_IN_PROGRESS } - - private void foo() { - timeToNextRound = delayBetweenRounds.plus(currentRoundDuration.getDelta()).start(); - } - + private class ForagerStateMachine implements StateMachine { private ForagerState state; Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java 2006-03-05 04:55:19 UTC (rev 142) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java 2006-03-05 05:17:09 UTC (rev 143) @@ -6,6 +6,8 @@ import java.util.Properties; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @@ -13,7 +15,6 @@ import org.hibernate.annotations.Proxy; -import edu.indiana.psych.gee.ExperimentParametersEntity; import edu.indiana.psych.gee.ExperimentRoundParameters; import edu.indiana.psych.gee.time.Duration; @@ -28,6 +29,14 @@ private String name; private int foodSpoilDuration; private double foodRate; + private int minimumParticipantsForNoBots; + private int participantsRequiredForSave; + private int numberOfBots; + private int boardWidth; + private int boardHeight; + private int minimumSeparation; + private int maximumSeparation; + private String specialInstructions; private long id = -1; @@ -55,49 +64,43 @@ } - public int getMinimumParticipants() { - // FIXME: replace with configuration value. - return 5; + public int getMinimumParticipantsForNoBots() { + return minimumParticipantsForNoBots; } public int getNumberOfBots() { - return 5; + return numberOfBots; } public int getMinimumSeparation() { - // FIXME: use actual configuration parameters. - return 5; + return minimumSeparation; } public int getMaximumSeparation() { - // FIXME: use actual configuration parameters. - return 25; + return maximumSeparation; } public String getSpecialInstructions() { - // TODO Auto-generated method stub - return "Very special instructions"; + return specialInstructions; } @Transient public Properties getProperties() { - // TODO Auto-generated method stub return new Properties(); } @Transient public Dimension getBoardSize() { // TODO Auto-generated method stub - return new Dimension(600, 600); + return new Dimension(getBoardWidth(), getBoardHeight()); } public boolean shouldPersist(int numberOfParticipants) { - return (numberOfParticipants >= getNumberOfParticipantsRequiredForSave()); + return (numberOfParticipants >= getParticipantsRequiredForSave()); } - private int getNumberOfParticipantsRequiredForSave() { - // FIXME: remove stub default value. - return 5; + public int getParticipantsRequiredForSave() { + return participantsRequiredForSave; } @Transient @@ -145,8 +148,54 @@ this.foodRate = foodRate; } + @ManyToOne(targetEntity=ForagerAgentConfiguration.class) + @JoinColumn(name="agent_configuration_id") public ForagerAgentConfiguration getAgentConfiguration() { return agentConfiguration; } + + public int getBoardHeight() { + return boardHeight; + } + + public void setBoardHeight(int boardHeight) { + this.boardHeight = boardHeight; + } + + public int getBoardWidth() { + return boardWidth; + } + + public void setBoardWidth(int boardWidth) { + this.boardWidth = boardWidth; + } + + public void setAgentConfiguration(ForagerAgentConfiguration agentConfiguration) { + this.agentConfiguration = agentConfiguration; + } + + public void setMaximumSeparation(int maximumSeparation) { + this.maximumSeparation = maximumSeparation; + } + + public void setMinimumParticipantsForNoBots(int minimumParticipantsForNoBots) { + this.minimumParticipantsForNoBots = minimumParticipantsForNoBots; + } + + public void setMinimumSeparation(int minimumSeparation) { + this.minimumSeparation = minimumSeparation; + } + + public void setNumberOfBots(int numberOfBots) { + this.numberOfBots = numberOfBots; + } + + public void setSpecialInstructions(String specialInstructions) { + this.specialInstructions = specialInstructions; + } + + public void setParticipantsRequiredForSave(int participantsRequiredForSave) { + this.participantsRequiredForSave = participantsRequiredForSave; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |