[virtualcommons-svn] SF.net SVN: virtualcommons:[357] mentalmodels/trunk/src/main
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-11-12 22:22:26
|
Revision: 357 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=357&view=rev Author: seematalele Date: 2009-11-12 22:22:15 +0000 (Thu, 12 Nov 2009) Log Message: ----------- 1) DayByDayDecisionsService is working fine, tested all the calculation with 5 people on one bay. 2) Made changes in the schema in Student, added column named as money. To Do: 1) Implement the timer for DayByDayDecisions 2) Test with Kalin's GUI 3) Test strategy Execution using DayByDayDecisions.java Modified Paths: -------------- mentalmodels/trunk/src/main/db/init-mme.sql mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayOutput.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GroupLocation.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java Modified: mentalmodels/trunk/src/main/db/init-mme.sql =================================================================== --- mentalmodels/trunk/src/main/db/init-mme.sql 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/db/init-mme.sql 2009-11-12 22:22:15 UTC (rev 357) @@ -216,7 +216,6 @@ `id` bigint(20) NOT NULL AUTO_INCREMENT, `dayNumber` int(11) NOT NULL, `earnings` double DEFAULT NULL, - `money` double DEFAULT NULL, `location_id` bigint(20) NOT NULL, `student_id` bigint(20) NOT NULL, PRIMARY KEY (`id`), @@ -694,6 +693,7 @@ `gameCode` varchar(255) DEFAULT NULL, `gender` varchar(255) DEFAULT NULL, `major` varchar(255) DEFAULT NULL, + `money` double DEFAULT NULL, `semester` varchar(255) DEFAULT NULL, `student_no` int(11) DEFAULT NULL, `timestamp` datetime DEFAULT NULL, @@ -876,4 +876,4 @@ /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2009-10-30 22:37:53 +-- Dump completed on 2009-11-12 22:20:40 Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java 2009-11-12 22:22:15 UTC (rev 357) @@ -27,18 +27,15 @@ @ManyToOne @JoinColumn(nullable=false) private Location location; + + @ManyToOne + @JoinColumn(nullable=false) + private Student student; //earning will be in pound @Column private Double earnings; - @Column - private Double money; - - @ManyToOne - @JoinColumn(nullable=false) - private Student student; - /*@OneToMany(mappedBy = "dayByDayDecision") @CollectionOfElements(fetch = FetchType.EAGER) private List<DayByDayOtherStudentDecisions> dayByDayOtherStudentDecisions;*/ @@ -58,22 +55,7 @@ public Location getLocation() { return location; } - public void setEarnings(Double earnings) { - this.earnings = earnings; - } - - public Double getEarnings() { - return earnings; - } - public void setMoney(Double money) { - this.money = money; - } - - public Double getMoney() { - return money; - } - public void setStudent(Student student) { this.student = student; } @@ -90,6 +72,14 @@ return dayNumber; } + public void setEarnings(Double earnings) { + this.earnings = earnings; + } + + public Double getEarnings() { + return earnings; + } + /*public void setDayByDayOtherStudentDecisions( List<DayByDayOtherStudentDecisions> dayByDayOtherStudentDecisions) { this.dayByDayOtherStudentDecisions = dayByDayOtherStudentDecisions; Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayOutput.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayOutput.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayOutput.java 2009-11-12 22:22:15 UTC (rev 357) @@ -28,7 +28,7 @@ @Column(nullable=false) public Integer day; - @Column(nullable=false) + @Column(nullable=false,scale=2, precision=8) public Double earnings; public void setId(Long id) { Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GroupLocation.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GroupLocation.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GroupLocation.java 2009-11-12 22:22:15 UTC (rev 357) @@ -27,23 +27,23 @@ @JoinColumn(nullable=false) private Location location; - @Column(name="current_population", scale=2) + @Column(name="current_population") private Double currentPopulation; - @Column(name="fish_leaving", scale=2) + @Column(name="fish_leaving") private Double fishLeaving; - @Column(name="fish_return", scale=2) + @Column(name="fish_return") private Double fishReturned; @ManyToOne @JoinColumn(nullable=false) private Group group; - @Column(nullable=false,name="max_capacity", scale=2) + @Column(nullable=false,name="max_capacity") private Double maxCapacity; - @Column(nullable=false,name="initial_population", scale=2) + @Column(nullable=false,name="initial_population") private Double initialPopulation; public void setId(Long id) { Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java 2009-11-12 22:22:15 UTC (rev 357) @@ -26,7 +26,7 @@ /*@Column(nullable=false,name="max_capacity", scale=2) private Double maxCapacity;*/ - @Column(nullable=false,name="growth_rate", scale=2) + @Column(nullable=false,name="growth_rate") private Double growthRate; /*@Column(nullable=false,name="initial_population", scale=2) Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-11-12 22:22:15 UTC (rev 357) @@ -38,6 +38,11 @@ private String semester; + + + @Column + private Double money; + @ManyToOne @JoinColumn(nullable = false) private Game game; @@ -129,4 +134,12 @@ return gameCode; } + public void setMoney(Double money) { + this.money = money; + } + + public Double getMoney() { + return money; + } + } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-11-12 22:22:15 UTC (rev 357) @@ -82,17 +82,18 @@ private HibernateGroupLocationDao groupLocationDao; private HibernateGroupDao groupDao; private HibernateDayByDayOtherStudentDecisionsDao dayByDayOtherStudentDecisionsDao; + private double totalFishLeaving; static final String groupsWithinGame = "select distinct student.group from Student student where student.game =:current_game_id "; static final String studentDecisionsForGame = "SELECT d FROM DayByDayDecisions d, Student s where s.game =:game and s=d.student"; static final String getgroupLocation = "SELECT g FROM GroupLocation g where g.group =:group and g.location =:location"; - + public void setGameDao(HibernateGameDao gameDao) { this.gameDao = gameDao; } - + public void setLocationDao(HibernateLocationDao locationDao) { this.locationDao = locationDao; } @@ -159,146 +160,89 @@ public void allocateStudentForEachBay(Game game) { - List<DayByDayDecisions> studentDecisions = new ArrayList<DayByDayDecisions>(); - //studentDao.find(gameDao.find(game.getId()); - //studentDecisions = getDao(). Query query = getDao().getCurrentSession().createQuery(studentDecisionsForGame); query.setEntity("game", game); Iterator studentDecisionsIterator = query.list().iterator(); - - //getLogger().debug("student Decision Iterator is " + studentDecisionIterator.hasNext()); - while(studentDecisionsIterator.hasNext()) - { - studentDecisions.add((DayByDayDecisions)studentDecisionsIterator.next()); - // getLogger().info("decision is: " + decision.getId() + "location number: " + decision.getLocation().getLocationName()); - } - DayByDayDecisions studentDecision = new DayByDayDecisions(); + try{ + while(studentDecisionsIterator.hasNext()) + { + DayByDayDecisions decision = (DayByDayDecisions)studentDecisionsIterator.next(); + studentDecisions.add(decision); + getLogger().info("student decision is: " + decision.getId() + "location number: " + decision.getLocation().getLocationName()); + } - List<DayByDayDecisions> bay1Students = new ArrayList<DayByDayDecisions>(); + //find out different groups in the game + Query queryforGroups = studentDao.getCurrentSession().createQuery(groupsWithinGame); - // List<DayByDayDecisions> bay2Students = new ArrayList<DayByDayDecisions>(); - // List<DayByDayDecisions> bay3Students = new ArrayList<DayByDayDecisions>(); - // List<DayByDayDecisions> harborStudents = new ArrayList<DayByDayDecisions>(); + queryforGroups.setLong("current_game_id", game.getId()); + Iterator groups = queryforGroups.list().iterator(); + List<GroupLocation> groupLocations = new ArrayList<GroupLocation>(); + List<DayByDayDecisions> bay1Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> bay2Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> bay3Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> harborStudents = new ArrayList<DayByDayDecisions>(); + /** For every group find out the groupLocations objects. + * find out the student decisions for current group. + * Separate the students for each bay + * find out the population for every bay + */ - Map<Long,List<DayByDayDecisions>> bay1StudentMap = new HashMap<Long,List<DayByDayDecisions>>(); - Map<Long,List<DayByDayDecisions>> bay2StudentMap = new HashMap<Long,List<DayByDayDecisions>>(); - Map<Long,List<DayByDayDecisions>> bay3StudentMap = new HashMap<Long,List<DayByDayDecisions>>(); - Map<Long,List<DayByDayDecisions>> harborStudentMap = new HashMap<Long,List<DayByDayDecisions>>(); - - for(int i = 0; i < studentDecisions.size(); i++) - { - studentDecision = studentDecisions.get(i); - if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay1")) + getLogger().debug("number of groups in the game are: " + queryforGroups.list().size()); + while(groups.hasNext()) { - if(!bay1StudentMap.containsKey(studentDecision.getStudent().getGroup().getId() )) - { - //group = decision.getStudent().getGroup(); - List<DayByDayDecisions> decisions = new ArrayList<DayByDayDecisions>(); - decisions.add(studentDecision); - bay1StudentMap.put(studentDecision.getStudent().getGroup().getId(),decisions); - } - else - { - List<DayByDayDecisions> decisions = bay1StudentMap.get(studentDecision.getStudent().getGroup().getId()); - decisions.add(studentDecision); - } + Group currentGroup = (Group) groups.next(); + getLogger().debug("group id in executeStrategy is: " + currentGroup.getId()); - } - else if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay2")) - { - if(!bay2StudentMap.containsKey(studentDecision.getStudent().getGroup().getId() )) - { - //group = decision.getStudent().getGroup(); - List<DayByDayDecisions> decisions = new ArrayList<DayByDayDecisions>(); - decisions.add(studentDecision); - bay2StudentMap.put(studentDecision.getStudent().getGroup().getId(),decisions); - } - else - { - List<DayByDayDecisions> decisions = bay1StudentMap.get(studentDecision.getStudent().getGroup().getId()); - decisions.add(studentDecision); - } + groupLocations = groupLocationDao.findAllByProperty("group",currentGroup); + //getLogger().debug("grouplocation size is: " + groupLocations.size()); - } - else if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay3")) - { - if(!bay3StudentMap.containsKey(studentDecision.getStudent().getGroup().getId() )) + List<DayByDayDecisions> studentDecisionForCurrentGroup = new ArrayList<DayByDayDecisions>(); + for(DayByDayDecisions tempStudentDecision:studentDecisions) { - //group = decision.getStudent().getGroup(); - List<DayByDayDecisions> decisions = new ArrayList<DayByDayDecisions>(); - decisions.add(studentDecision); - bay3StudentMap.put(studentDecision.getStudent().getGroup().getId(),decisions); + if(tempStudentDecision.getStudent().getGroup().getId() == currentGroup.getId()) + { + //studentDecisionForCurrentGroup.add(tempStudentDecision); + if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay1")) + { + bay1Students.add(tempStudentDecision); + } + else if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay2")) + { + bay2Students.add(tempStudentDecision); + } + else if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay3")) + { + bay3Students.add(tempStudentDecision); + } + else if(tempStudentDecision.getLocation().getLocationName().equalsIgnoreCase("Harbor")) + { + harborStudents.add(tempStudentDecision); + } + + } + } - else - { - List<DayByDayDecisions> decisions = bay1StudentMap.get(studentDecision.getStudent().getGroup().getId()); - decisions.add(studentDecision); - } + calculateHarvest(bay1Students,"Bay1",currentGroup,game); + calculateHarvest(bay2Students,"Bay2",currentGroup,game); + calculateHarvest(bay3Students,"Bay3",currentGroup,game); + calculateNewPopulation(currentGroup); } - else if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Harbor")) - { - if(!harborStudentMap.containsKey(studentDecision.getStudent().getGroup().getId() )) - { - //group = decision.getStudent().getGroup(); - List<DayByDayDecisions> decisions = new ArrayList<DayByDayDecisions>(); - decisions.add(studentDecision); - harborStudentMap.put(studentDecision.getStudent().getGroup().getId(),decisions); - } - else - { - List<DayByDayDecisions> decisions = bay1StudentMap.get(studentDecision.getStudent().getGroup().getId()); - decisions.add(studentDecision); - } - } - } - /** - * Calculate the following in the order it is mention - * 1) The actual population of each bay after growth and fish leaving and assign the harvest to each agent. - * 2) Total fish leaving = leaving from bay1 + leaving from bay2 + leaving from bay3 - * 2) Receptivity for each bay - * 3) Total receptivity - * 4) Fish Return for each bay - * 5) New population at each bay - */ - - /*Iterator<Long> keys = bay1StudentMap.keySet().iterator(); - while(keys.hasNext()) + }catch(Exception e) { - Long groupId = keys.next(); - getLogger().info("key is: " + groupId + "values are : " ); - List<DayByDayDecisions> decisions = bay1StudentMap.get(groupId); - for(DayByDayDecisions decision:decisions) - { - getLogger().info("decision is: " + decision.getDayNumber() + "location number: " + decision.getLocation().getLocationName()); - } + e.printStackTrace(); + } - }*/ - - calculateHarvest(bay1StudentMap,"Bay1", game); - /**calculateHarvest(bay2StudentMap,"Bay2"); - calculateHarvest(bay3StudentMap,"Bay3"); - calculateHarvest(harborStudentMap,"Harbor"); **/ - - calculateTotalFishLeaving(game); - - /** calculateFishReturned(); - - calculateNewPopulation();**/ - } //FIXME: max_fish_capacity is hard coded to 5 but actually this value should get from game object - - - - public void calculateHarvest(Map<Long, List<DayByDayDecisions>> bay1StudentMap,String locationName, Game game) + public void calculateHarvest(List<DayByDayDecisions> bayStudents,String locationName, Group currentGroup, Game game) { // TODO Auto-generated method stub double maxFishCapacity = 0.0; @@ -308,117 +252,86 @@ double fishLeaving = 0.0; Long groupId; DayByDayOtherStudentDecisions otherStudents; - - maxFishCapacity = game.getGameConfig().getMaxFishHarvest(); - getLogger().debug("maxFishCapacity is : " + maxFishCapacity); - List<DayByDayDecisions> groupStudentDecisions = new ArrayList<DayByDayDecisions>(); - /*getLogger().debug("bay1StudentMap size is : " + bay1StudentMap.size() + "location name is : " + locationName); - Iterator<Long> keys1 = bay1StudentMap.keySet().iterator(); - while(keys1.hasNext()) - { - Long groupId1 = keys1.next(); - getLogger().info("key is: " + groupId1 + "values are : " ); - List<DayByDayDecisions> decisions = bay1StudentMap.get(groupId1); - for(DayByDayDecisions decision:decisions) - { - getLogger().info("decision is: " + decision.getDayNumber() + "location number: " + decision.getLocation().getLocationName()); - } - - }*/ + maxFishCapacity = game.getGameConfig().getMaxFishHarvest(); + getLogger().debug("location name is : " +locationName + "bay student size is: " + bayStudents.size()); try { - Iterator<Long> keys = bay1StudentMap.keySet().iterator(); - while(keys.hasNext()) - { - Location location = locationDao.findByProperty("locationName","Bay1"); - groupId = keys.next(); - getLogger().debug("group id is : " + groupId + "location id is: " + location.getId()); - groupStudentDecisions = bay1StudentMap.get(groupId); - Group group = groupDao.find(groupId); - GroupLocation groupLocation = new GroupLocation(); - /*groupLocation.setLocation(location); - groupLocation.setGroup(group); + Location location = locationDao.findByProperty("locationName",locationName); - - List<GroupLocation> groupLocations = groupLocationDao.findByExample(groupLocation);*/ - - Query query = groupLocationDao.getCurrentSession().createQuery(getgroupLocation); - query.setEntity("location", location); - query.setEntity("group", group); - Iterator i = query.list().iterator(); - while(i.hasNext()) - { - groupLocation = (GroupLocation)i.next(); - getLogger().debug("groupLocation id is: " + groupLocation.getId()); - } + Group group = groupDao.find(currentGroup.getId()); + GroupLocation groupLocation = new GroupLocation(); + Query query = groupLocationDao.getCurrentSession().createQuery(getgroupLocation); + query.setEntity("location", location); + query.setEntity("group", group); + Iterator i = query.list().iterator(); + while(i.hasNext()) + { + groupLocation = (GroupLocation)i.next(); + getLogger().debug("groupLocation id is: " + groupLocation.getId()); + } - /*if(groupLocations.size()== 1) - { - groupLocation = groupLocations.get(0); - } - else - { - //Error, should result only one result - }*/ + //get current population + actualPopulation = groupLocation.getCurrentPopulation(); - //get current population - actualPopulation = groupLocation.getCurrentPopulation(); + //1)Harvesting + //Find out the amount of fish per agent - //1)Harvesting - //Find out the amount of fish per agent + amountPerAgent = maxFishCapacity * groupLocation.getCurrentPopulation() / groupLocation.getMaxCapacity(); - amountPerAgent = maxFishCapacity * groupLocation.getCurrentPopulation() / groupLocation.getMaxCapacity(); + if((bayStudents.size() * amountPerAgent) > actualPopulation) + { + amountPerAgent = actualPopulation / bayStudents.size(); + getLogger().debug("In IF Loop assigning amount/agent: " + amountPerAgent); + } + //FIXME: allocate this amountPerAgent to each student - if((groupStudentDecisions.size() * amountPerAgent) > actualPopulation) - { - amountPerAgent = actualPopulation / groupStudentDecisions.size(); - } - //FIXME: allocate this amountPerAgent to each student + //calculate the current population after harvesting + actualPopulation = actualPopulation - bayStudents.size() * amountPerAgent; + getLogger().debug("groupStudentDecisions.size is : " + bayStudents.size()+ " fish population after assigning amount/agent: " + actualPopulation); - //calculate the current population after harvesting - actualPopulation = actualPopulation - groupStudentDecisions.size() * amountPerAgent; + //2)Growth + growth = actualPopulation * location.getGrowthRate(); + getLogger().info("Fish growth after harvest at " + locationName + " is: " + growth); - groupLocation.setCurrentPopulation(actualPopulation); + //3) Fish leaving location + fishLeaving = actualPopulation * growth / groupLocation.getMaxCapacity(); + getLogger().info("Fish leaving at " + locationName + " is: " + fishLeaving); - //2)Growth - growth = actualPopulation * location.getGrowthRate(); - getLogger().info("Fish growth at " + locationName + " is: " + growth); + groupLocation.setFishLeaving(fishLeaving); - //3) Fish leaving location - fishLeaving = actualPopulation * growth / groupLocation.getMaxCapacity(); - getLogger().info("Fish leaving at " + locationName + " is: " + fishLeaving); + //4) Population after diffusion + actualPopulation = actualPopulation + growth - fishLeaving; + getLogger().info("Fish population at " + locationName + " after diffusion is: " + actualPopulation); + groupLocation.setCurrentPopulation(actualPopulation); + groupLocationDao.save(groupLocation); - groupLocation.setFishLeaving(fishLeaving); - - //4) Population after diffusion - actualPopulation = actualPopulation + growth - fishLeaving; - getLogger().info("Fish population at " + locationName + " after diffusion is: " + actualPopulation); - groupLocationDao.save(groupLocation); + if(bayStudents.size()!= 0) + { List<DayByDayDecisions> tempStudentDecisions = new ArrayList<DayByDayDecisions>(); - tempStudentDecisions = groupStudentDecisions; - for(DayByDayDecisions dayByDayDecision : groupStudentDecisions) + tempStudentDecisions = bayStudents; + for(DayByDayDecisions dayByDayDecision : bayStudents) { //set earning + Student student = dayByDayDecision.getStudent(); dayByDayDecision.setEarnings(amountPerAgent); //set money + student.setMoney(game.getMoney() * amountPerAgent); + studentDao.save(student); - dayByDayDecision.setMoney(game.getMoney() * amountPerAgent); - //set other students //List<Student> otherStudents = new ArrayList<Student>(); - - + Long currentStudentId = dayByDayDecision.getStudent().getId(); getLogger().debug("For student id is: " + currentStudentId); - + for(DayByDayDecisions students:tempStudentDecisions) { getLogger().debug("temp student id is: " + students.getStudent().getId()); - + if(students.getStudent().getId() != currentStudentId) { getLogger().debug("other student id is: " + students.getStudent().getId()); @@ -426,15 +339,15 @@ otherStudents.setDayByDayDecision(dayByDayDecision); otherStudents.setOtherStudent(students.getStudent()); dayByDayOtherStudentDecisionsDao.save(otherStudents); - + } } //Group group = dayByDayDecisions.getStudent().getGroup(); getDao().save(dayByDayDecision); } - } + }catch(Exception e) { e.printStackTrace(); @@ -442,111 +355,90 @@ } - private void calculateTotalFishLeaving(Game game) { + private void calculateNewPopulation(Group group) { double totalFishLeaving = 0; - - Query query = studentDao.getCurrentSession().createQuery(groupsWithinGame); - - query.setLong("current_game_id", game.getId()); - Iterator groups = query.list().iterator(); - GroupLocation groupLocation = null; - while(groups.hasNext()) - { - Group group = (Group) groups.next(); - getLogger().debug("group id is: " + group.getId()); - groupLocation = groupLocationDao.findByProperty("group",group); - totalFishLeaving = totalFishLeaving + groupLocation.getFishLeaving(); - } - /*List<Student> students = studentDao.findAllByProperty("game", game); - List<Long> groups = null; - for(Student student:students) - { - if(groups == null) - { - groups = new ArrayList<Long>(); - groups.add(student.getGroup().getId()); - } - else if(!groups.contains(student.getGroup().getId())) - { - groups.add(student.getGroup().getId()); - } - }*/ - - setTotalFishLeaving(totalFishLeaving); - - } - - /**INFO: loss rate is 0 - according to the Dr Tobias' document, loss rate for the pilot experiment is 0 - but for single location it will be 1 */ - - private void calculateFishReturned() { - - /*double totalLoss = 0.0; + double totalLoss = 0.0; double lossRate = 0.0; double totalReturn = 0.0; double maxFishCapacity = 5.0; double totalReceptivity = 0.0; double receptivity = 0.0; + getLogger().debug("group id in calculate total fish leaving is: " + group.getId()); + List<GroupLocation> groupLocations = groupLocationDao.findAllByProperty("group",group); + getLogger().debug("grouplocation size is: " + groupLocations.size()); + for(GroupLocation groupLocation : groupLocations) + { + totalFishLeaving = totalFishLeaving + groupLocation.getFishLeaving(); + } + getLogger().debug("total fish leaving is : " + totalFishLeaving); + //setTotalFishLeaving(totalFishLeaving); + + /**INFO: loss rate is 0 - according to the Dr Tobias' document, loss rate for the pilot experiment is 0 + but for single location it will be 1 */ + /** + * Bay receptivity + * String: location name, Double: receptivity + */ Map<String,Double> bayReceptivity = new HashMap<String, Double>(); try { //calculate loss - totalLoss = getTotalFishLeaving() * lossRate; - totalReturn = getTotalFishLeaving() - totalLoss; + totalLoss = totalFishLeaving * lossRate; + totalReturn = totalFishLeaving - totalLoss; getLogger().info("Total Return is: " + totalReturn); //calculate the receptivity for each bay and total receptivity - for(Location location : locationService.getAllLocations()) + for(GroupLocation groupLocation : groupLocations) { - receptivity = 1 - location.getCurrentPopulation() / maxFishCapacity; - getLogger().info(location.getLocationName() + " receptivity is: " + receptivity); - bayReceptivity.put(location.getLocationName(), receptivity); - totalReceptivity = receptivity + totalReceptivity; + if(groupLocation.getLocation().getId()!=1) + { + getLogger().debug(groupLocation.getLocation().getLocationName() + "current population : " + groupLocation.getCurrentPopulation()); + receptivity = 1 - (groupLocation.getCurrentPopulation() /groupLocation.getMaxCapacity()); + getLogger().info(groupLocation.getLocation().getLocationName() + " receptivity is: " + receptivity); + bayReceptivity.put(groupLocation.getLocation().getLocationName(), receptivity); + totalReceptivity = receptivity + totalReceptivity; + } } getLogger().info("Total receptivity is: " + totalReceptivity); //calculte the returning for each bay - *//**FOR i = 1 TO 3 - IF receptivity_total = 0 - returning_i = 0 - ELSE - returning_i = receptivity_i \xD7 totalReturn \xD7 receptivity_i / receptivity_total - END FOR *//* + /**FOR i = 1 TO 3 + IF receptivity_total = 0 + returning_i = 0 + ELSE + returning_i = receptivity_i \xD7 totalReturn \xD7 receptivity_i / receptivity_total + END FOR */ receptivity = 0.0; - for(Location location : locationService.getAllLocations()) + for(GroupLocation groupLocation : groupLocations) { - if(totalReceptivity == 0) + if(groupLocation.getLocation().getId()!=1) { - location.setFishReturned(0.0); + if(totalReceptivity == 0) + { + groupLocation.setFishReturned(0.0); + } + else + { + receptivity = bayReceptivity.get(groupLocation.getLocation().getLocationName()); + groupLocation.setFishReturned(receptivity * totalReturn * receptivity / totalReceptivity); + getLogger().debug("Fish returned to " + groupLocation.getLocation().getLocationName() + "is " + groupLocation.getFishReturned()); + groupLocation.setCurrentPopulation(groupLocation.getCurrentPopulation() + groupLocation.getFishReturned()); + getLogger().debug("New population at " + groupLocation.getLocation().getLocationName() + " is: " + groupLocation.getCurrentPopulation()); + } } - else - { - receptivity = bayReceptivity.get(location.getLocationName()); - location.setFishReturned(receptivity * totalReturn * receptivity / totalReceptivity); - getLogger().debug("Fish returned to " + location.getLocationName() + "is " + location.getFishReturned()); - } + groupLocationDao.save(groupLocation); } }catch(Exception e) { e.printStackTrace(); - }*/ - } - - private void calculateNewPopulation() { - - /*for(Location location:locationService.getAllLocations()) - { - location.setCurrentPopulation(location.getCurrentPopulation() + location.getFishReturned()); - getLogger().debug("New population at " + location.getLocationName() + " is: " + location.getCurrentPopulation()); } - */ + } - } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-11-12 22:22:15 UTC (rev 357) @@ -150,7 +150,7 @@ { assignGroups(game); getLogger().debug("system has assigned groups. "); - pushBlock(game); + //pushBlock(game); flag = true; } else @@ -380,6 +380,9 @@ groupLocation.setInitialPopulation(initCapacity); groupLocation.setCurrentPopulation(initCapacity); getLogger().info("initiali population set is: " + initCapacity); + groupLocation.setFishLeaving(0.0); + groupLocation.setFishReturned(0.0); + groupLocationDao.save(groupLocation); getLogger().info("group location is created and id is: " + groupLocation.getId()); } @@ -393,6 +396,9 @@ groupLocation.setInitialPopulation(initCapacity); groupLocation.setCurrentPopulation(initCapacity); + groupLocation.setFishLeaving(0.0); + groupLocation.setFishReturned(0.0); + getLogger().info("initiali population set is: " + initCapacity); groupLocationDao.save(groupLocation); getLogger().info("group location is created and id is: " + groupLocation.getId()); @@ -408,6 +414,9 @@ groupLocation.setInitialPopulation(initCapacity); groupLocation.setCurrentPopulation(initCapacity); getLogger().info("initiali population set is: " + initCapacity); + groupLocation.setFishLeaving(0.0); + groupLocation.setFishReturned(0.0); + groupLocationDao.save(groupLocation); getLogger().info("group location is created and id is: " + groupLocation.getId()); } @@ -422,6 +431,9 @@ groupLocation.setInitialPopulation(initCapacity); groupLocation.setCurrentPopulation(initCapacity); getLogger().info("initiali population set is: " + initCapacity); + groupLocation.setFishLeaving(0.0); + groupLocation.setFishReturned(0.0); + groupLocationDao.save(groupLocation); getLogger().info("group location is created and id is: " + groupLocation.getId()); } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-11-12 22:22:15 UTC (rev 357) @@ -18,7 +18,7 @@ private boolean running; private RoundService roundService; private LocationService locationService; - private DayByDayDecisionsService dayBydayDecisionService; + private DayByDayDecisionsServiceSortingStudentBayWise dayBydayDecisionService; private StudentService studentService; private ModuleRoundConfig currentModuleRoundConfig; private Game game; @@ -115,11 +115,11 @@ this.locationService = locationService; } - public void setDayBydayDecisionService(DayByDayDecisionsService dayBydayDecisionService) { + public void setDayBydayDecisionService(DayByDayDecisionsServiceSortingStudentBayWise dayBydayDecisionService) { this.dayBydayDecisionService = dayBydayDecisionService; } - public DayByDayDecisionsService getDayBydayDecisionService() { + public DayByDayDecisionsServiceSortingStudentBayWise getDayBydayDecisionService() { return dayBydayDecisionService; } public void setStudentService(StudentService studentService) { Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java 2009-11-09 15:56:48 UTC (rev 356) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java 2009-11-12 22:22:15 UTC (rev 357) @@ -75,7 +75,7 @@ msg.setTimestamp(System.currentTimeMillis()); msg.setBody(block); AcknowledgeMessage ack = msgBroker.routeMessageToService(msg, null); - /*if(block!=null) + if(block!=null) { //int duration = block.getDuration(); @@ -97,8 +97,8 @@ { System.out.println("Game is Over..." + msg); } -*/ + /*AcknowledgeMessage ack = msgBroker.routeMessageToService(msg, null); logger.info("Ack received from client for message " + msg + "is : " + ack); */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |