r1900 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator
Author: chatellier Date: 2009-03-02 15:34:56 +0000 (Mon, 02 Mar 2009) New Revision: 1900 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java Log: Ajout de la methode "setDiscard". Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java 2009-03-02 14:22:38 UTC (rev 1899) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/PopulationMonitor.java 2009-03-02 15:34:56 UTC (rev 1900) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2006 + * Copyright (C) 2006 - 2009 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -17,18 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *##%*/ -/* * - * PopulationMonitor.java - * - * Created: 21 août 2006 15:41:18 - * - * @author poussin - * @version $Revision: 428 $ - * - * Last update: $Date: 2007-10-15 14:56:13 +0200 (lun, 15 oct 2007) $ - * by : $Author: bpoussin $ - */ - package fr.ifremer.isisfish.simulator; import java.util.ArrayList; @@ -51,7 +39,6 @@ import fr.ifremer.isisfish.types.Month; import java.util.Collections; - /** * Classe permettant le suivi des populations de la simulation. * <p> @@ -62,13 +49,16 @@ * Il serait bon que ce groupe deviennent un vrai groupe et que ce code specifique * puisse etre supprimer. * - * * @author poussin + * @version $Revision: 428 $ + * + * Last update: $Date: 2007-10-15 14:56:13 +0200 (lun, 15 oct 2007) $ + * by : $Author: bpoussin $ */ public class PopulationMonitor { - + /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(PopulationMonitor.class); + private static Log log = LogFactory.getLog(PopulationMonitor.class); /** La liste des pops monitorer par cette instance */ protected List<Population> pops = null; @@ -82,6 +72,7 @@ protected Map<Population, MatrixND> catchs = new HashMap<Population, MatrixND>(); /** catch per population, only last catch is remaining */ protected Map<Population, MatrixND> holdCatchs = new HashMap<Population, MatrixND>(); + protected double totalHoldCatch = 0; /** @@ -96,7 +87,8 @@ * @param pops */ public void init(List<Population> pops) { - this.pops = Collections.unmodifiableList(new ArrayList<Population>(pops)); + this.pops = Collections + .unmodifiableList(new ArrayList<Population>(pops)); for (Population pop : this.pops) { reproductions.put(pop, new HashMap<Date, MatrixND>()); discards.put(pop, new HashMap<Date, MatrixND>()); @@ -110,7 +102,7 @@ public List<Population> getPopulations() { return pops; } - + /** * Return current biomass for species * @param species @@ -118,14 +110,14 @@ */ public double getBiomass(Species species) { double result = 0; - + for (Population pop : species.getPopulation()) { result += getBiomass(pop); } return result; } - + /** * Return current biomass for population * @param pop @@ -133,20 +125,20 @@ */ public double getBiomass(Population pop) { double result = 0; - + MatrixND n = getN(pop); if (n != null) { n = n.sumOverDim(1); - for (MatrixIterator i=n.iterator(); i.next();){ - Object [] coord = i.getSemanticsCoordinates(); - PopulationGroup group = (PopulationGroup)coord[0]; + for (MatrixIterator i = n.iterator(); i.next();) { + Object[] coord = i.getSemanticsCoordinates(); + PopulationGroup group = (PopulationGroup) coord[0]; result += i.getValue() * group.getMeanWeight(); } } - + return result; } - + /** * Return current numbers for population * @param pop @@ -154,17 +146,17 @@ */ public MatrixND getN(Population pop) { MatrixND result = Ns.get(pop); - + if (result != null) { // change semantics with list from argument to ensure that // semantics don't used too old context result.setSemantics(0, pop.getPopulationGroup()); result.setSemantics(1, pop.getPopulationZone()); } - + return result; } - + public void setN(Population pop, MatrixND mat) { Ns.put(pop, mat); } @@ -175,9 +167,9 @@ public MatrixND getReproduction(Date date, Population pop) { return this.reproductions.get(pop).get(date); } - + /** - * @param reproduction The reproduction to set. + * @param repro The reproduction to set. */ public void setReproduction(Date date, Population pop, MatrixND repro) { reproductions.get(pop).put(date, repro); @@ -193,7 +185,7 @@ if (log.isTraceEnabled()) { log.trace("Matrix repro before mortality: " + reproduction); } - + for (MatrixIterator mi = reproduction.iterator(); mi.next();) { Object[] sems = mi.getSemanticsCoordinates(); Zone z = (Zone) sems[0]; @@ -201,7 +193,8 @@ if (log.isTraceEnabled()) { log.trace("NaturalDeath zone " + z + "=" + coeff); } - mi.setValue(mi.getValue() * Math.exp(-coeff / Month.NUMBER_OF_MONTH)); + mi.setValue(mi.getValue() + * Math.exp(-coeff / Month.NUMBER_OF_MONTH)); } if (log.isTraceEnabled()) { log.trace("Matrix repro after mortality: " + reproduction); @@ -223,17 +216,19 @@ MatrixND matEtalement = pop.getRecruitmentDistribution(); int etalement = matEtalement.getDim(0); - MatrixND result = MatrixFactory.getInstance().create( - new List[]{pop.getPopulationGroup(), pop.getPopulationZone()}); + MatrixND result = MatrixFactory.getInstance() + .create( + new List[] { pop.getPopulationGroup(), + pop.getPopulationZone() }); // pour chaque - for(int e=0; e<etalement; e++){ + for (int e = 0; e < etalement; e++) { // recuperation de la reproduction stucture en zone repro - Date d = new Date(date.getDate() - e - - pop.getMonthGapBetweenReproRecrutement()); - MatrixND repro = (MatrixND)reproductions.get(pop).get(d); + Date d = new Date(date.getDate() - e + - pop.getMonthGapBetweenReproRecrutement()); + MatrixND repro = (MatrixND) reproductions.get(pop).get(d); - if(repro != null){ // si une repro existe pour le mois + if (repro != null) { // si une repro existe pour le mois // on fait la correspondance entre les zones repro et // recrutement @@ -249,52 +244,55 @@ // on multiplie la repro par le coeff de recrutement double coeff = matEtalement.getValue(e); - + MatrixND matRepro = repro.copy(); matRepro = matRepro.mults(coeff); matRepro.setSemantics(0, zoneRepros); MatrixND mapping = pop.getMappingZoneReproZoneRecru(); - for(Zone zoneRepro : zoneRepros){ - MatrixND submapping = mapping.getSubMatrix(0, new Object[]{zoneRepro}); - for (MatrixIterator i=submapping.iterator(); i.hasNext();) { + for (Zone zoneRepro : zoneRepros) { + MatrixND submapping = mapping.getSubMatrix(0, + new Object[] { zoneRepro }); + for (MatrixIterator i = submapping.iterator(); i.hasNext();) { i.next(); Object[] sem = i.getSemanticsCoordinates(); - Zone zoneRecru = (Zone)sem[1]; + Zone zoneRecru = (Zone) sem[1]; double c = i.getValue(); - result.setValue(classe, zoneRecru, c*matRepro.getValue(zoneRepro) - +result.getValue(classe, zoneRecru)); - } + result.setValue(classe, zoneRecru, c + * matRepro.getValue(zoneRepro) + + result.getValue(classe, zoneRecru)); + } } } } - - if(pop.getSpecies().getAgeGroupType()){ + + if (pop.getSpecies().getAgeGroupType()) { // conversion et retour de la matrice en vecteur MatrixND N = pop.N2DToN1D(result); // on applique les migrations et le changement d'age sur le resultat // on suppose que la reproduction est toujours dans une seul saison - Date dateRepro = new Date(date.getDate() - - pop.getMonthGapBetweenReproRecrutement()); - + Date dateRepro = new Date(date.getDate() + - pop.getMonthGapBetweenReproRecrutement()); + // recherche les saisons des differents mois entre les deux dates List<PopulationSeasonInfo> infos = pop.getPopulationSeasonInfo(); List<PopulationSeasonInfo> usedSeasons = new ArrayList<PopulationSeasonInfo>(); - + while (date.after(dateRepro)) { dateRepro = dateRepro.next(); Month month = dateRepro.getMonth(); for (PopulationSeasonInfo info : infos) { if (month.equals(info.getFirstMonth())) { usedSeasons.add(info); - dateRepro = new Date(dateRepro.getDate() + info.getMonths().size() - 1); // -1 because, for have next() + dateRepro = new Date(dateRepro.getDate() + + info.getMonths().size() - 1); // -1 because, for have next() break; } } } - - for(PopulationSeasonInfo info : usedSeasons){ + + for (PopulationSeasonInfo info : usedSeasons) { Month month = info.getFirstMonth(); MatrixND CA = info.getGroupChangeMatrix(month); MatrixND MI = info.getMigrationMatrix(month, result); @@ -305,14 +303,14 @@ result = pop.split2D(N); } return result; - } + } /** * @param catchPerStrategyMet */ public void holdCatch(Population pop, MatrixND catchPerStrategyMet) { catchs.put(pop, catchPerStrategyMet); - + MatrixND holdCatch = holdCatchs.get(pop); if (holdCatch == null) { holdCatch = MatrixFactory.getInstance().create(catchPerStrategyMet); @@ -320,10 +318,10 @@ } else { holdCatch.add(catchPerStrategyMet); } - + // compute total - for(MatrixIterator i=catchPerStrategyMet.iterator(); i.next();){ - this.totalHoldCatch += i.getValue(); + for (MatrixIterator i = catchPerStrategyMet.iterator(); i.next();) { + this.totalHoldCatch += i.getValue(); } } @@ -336,7 +334,7 @@ MatrixND result = catchs.get(pop); return result; } - + /** * @param pop * @return @@ -345,7 +343,7 @@ MatrixND result = holdCatchs.get(pop); return result; } - + /** * @param pop * @return @@ -354,7 +352,7 @@ double result = totalHoldCatch; return result; } - + /** * raz capture cumulée de toutes les pops */ @@ -365,14 +363,35 @@ } /** - * @param date - * @param pop - * @return + * Get discard. + * + * @param date date to get discard + * @param pop population to get discard + * @return le discard */ public MatrixND getDiscard(Date date, Population pop) { MatrixND result = discards.get(pop).get(date); return result; } + + /** + * Set discard. + * + * Force discard at date for population. + * + * @param date date to set discard + * @param pop population to set discard + * @param discard le discard + */ + public void setDiscard(Date date, Population pop, MatrixND discard) { + Map<Date, MatrixND> oneDiscard = discards.get(pop); + synchronized (oneDiscard) { + // meme si discards.get(pop) != null + // replace toujours le précédent + MatrixND tmp = discard.copy(); + discards.get(pop).put(date, tmp); + } + } /** * FIXME: discards n'est jamais vider, on le conserve pour toutes les annees @@ -384,7 +403,7 @@ */ public void addDiscard(Date date, Population pop, MatrixND discard) { Map<Date, MatrixND> oneDiscard = discards.get(pop); - synchronized(oneDiscard) { + synchronized (oneDiscard) { MatrixND tmp = oneDiscard.get(date); if (tmp == null) { tmp = discard.copy(); @@ -394,6 +413,6 @@ } } } + + } - -
participants (1)
-
chatellier@users.labs.libre-entreprise.org