r47 - in branches/3.2: exports rules scripts simulators
Author: bpoussin Date: 2008-08-12 13:10:38 +0000 (Tue, 12 Aug 2008) New Revision: 47 Modified: branches/3.2/exports/CapturesNombre.java branches/3.2/exports/CapturesPoids.java branches/3.2/exports/RejetsPoids.java branches/3.2/rules/GraviteCPUE.java branches/3.2/scripts/GravityModel.java branches/3.2/scripts/ResultName.java branches/3.2/scripts/SiMatrix.java branches/3.2/simulators/DefaultSimulator.java Log: Ajout du calcul en cell pour affiner les calculs (repercussion sur les rules, exports, ... Modified: branches/3.2/exports/CapturesNombre.java =================================================================== --- branches/3.2/exports/CapturesNombre.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/exports/CapturesNombre.java 2008-08-12 13:10:38 UTC (rev 47) @@ -37,7 +37,7 @@ static private Log log = LogFactory.getLog(CapturesNombre.class); protected String [] necessaryResult = { - ResultName.MATRIX_CATCH_PER_STRATEGY_MET + ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP }; public String[] getNecessaryResult() { @@ -61,7 +61,8 @@ for (Population pop : simulation.getParameter().getPopulations()) { for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) { - MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_CATCH_PER_STRATEGY_MET); + MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, + ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP); if (mat != null) { // can be null if simulation is stopped before last year simulation mat = mat.sumOverDim(0); //sum on strategy for (MatrixIterator i=mat.iterator(); i.hasNext();) { Modified: branches/3.2/exports/CapturesPoids.java =================================================================== --- branches/3.2/exports/CapturesPoids.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/exports/CapturesPoids.java 2008-08-12 13:10:38 UTC (rev 47) @@ -37,7 +37,7 @@ static private Log log = LogFactory.getLog(CapturesPoids.class); protected String [] necessaryResult = { - ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP }; public String[] getNecessaryResult() { @@ -61,7 +61,8 @@ for (Population pop : simulation.getParameter().getPopulations()) { for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) { - MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET); + MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); if (mat != null) { // can be null if simulation is stopped before last year simulation mat = mat.sumOverDim(0); //sum on strategy for (MatrixIterator i=mat.iterator(); i.hasNext();) { Modified: branches/3.2/exports/RejetsPoids.java =================================================================== --- branches/3.2/exports/RejetsPoids.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/exports/RejetsPoids.java 2008-08-12 13:10:38 UTC (rev 47) @@ -37,7 +37,8 @@ static private Log log = LogFactory.getLog(RejetsPoids.class); protected String [] necessaryResult = { - ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET + ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP + }; public String[] getNecessaryResult() { @@ -61,7 +62,7 @@ for (Population pop : simulation.getParameter().getPopulations()) { for (Date date = new Date(0); !date.after(lastDate); date = date.next() ) { - MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET); + MatrixND mat = simulation.getResultStorage().getMatrix(date, pop, ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP); if (mat != null) { // can be null if simulation is stopped before last year simulation mat = mat.sumOverDim(0); //sum on strategy for (MatrixIterator i=mat.iterator(); i.hasNext();) { Modified: branches/3.2/rules/GraviteCPUE.java =================================================================== --- branches/3.2/rules/GraviteCPUE.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/rules/GraviteCPUE.java 2008-08-12 13:10:38 UTC (rev 47) @@ -57,7 +57,7 @@ // example: // ResultName.MATRIX_BIOMASS, // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, - ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET, + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP, ResultName.MATRIX_EFFORT_PER_STRATEGY_MET, }; @@ -186,7 +186,7 @@ MatrixND temp = resultmanager.getMatrix( date.previousYear(), pop, - ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET); + ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); // on somme sur les zones temp=temp.sumOverDim(3); // on somme sur les groupes Modified: branches/3.2/scripts/GravityModel.java =================================================================== --- branches/3.2/scripts/GravityModel.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/scripts/GravityModel.java 2008-08-12 13:10:38 UTC (rev 47) @@ -572,7 +572,7 @@ double price = group.getPrice(); Collection<Zone> zones = pop.getPopulationZone(); for(Zone zone : zones){ - double catchWeight = getCatchWeightPerStrMet(str, metier, group, zone, date); + double catchWeight = getCatchWeightPerStrMetPerZonePop(str, metier, group, zone, date); double discardsWeight = getDiscardsWeightPerStrMet(str, metier, group, zone, date); // FIXME demander/verifier que ce le bon calcule result += price * (catchWeight - discardsWeight); @@ -589,8 +589,8 @@ * @param date * @return */ - private double getCatchWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) { - MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET); + private double getCatchWeightPerStrMetPerZonePop(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) { + MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); double result = 0; if(mat != null){ result = mat.getValue(str, metier, group, zone); @@ -607,7 +607,7 @@ * @return */ private double getDiscardsWeightPerStrMet(Strategy str, Metier metier, PopulationGroup group, Zone zone, Date date) { - MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET); + MatrixND mat = resultManager.getMatrix(date, group.getPopulation(), ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP); double result = 0; if(mat != null){ result = mat.getValue(str, metier, group, zone); @@ -1249,7 +1249,7 @@ for(PopulationGroup group : groups){ double price = group.getPrice(); for(Zone zone : zones){ - double catchValue = getCatchWeightPerStrMet(str, metier, group, zone, date); + double catchValue = getCatchWeightPerStrMetPerZonePop(str, metier, group, zone, date); double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date); result += price * (catchValue - discards); } @@ -1294,7 +1294,7 @@ Collection<Zone> zones = pop.getPopulationZone(); for(PopulationGroup group : groups){ for(Zone zone : zones){ - double catchValue = getCatchWeightPerStrMet(str, metier, group, zone, date); + double catchValue = getCatchWeightPerStrMetPerZonePop(str, metier, group, zone, date); double discards = getDiscardsWeightPerStrMet(str, metier, group, zone, date); result += catchValue - discards; } Modified: branches/3.2/scripts/ResultName.java =================================================================== --- branches/3.2/scripts/ResultName.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/scripts/ResultName.java 2008-08-12 13:10:38 UTC (rev 47) @@ -52,7 +52,7 @@ */ public class ResultName { @Doc(value = "do the doc of Result matrixDiscardsWeightPerStrMet") - static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET = n_("matrixDiscardsWeightPerStrMet"); + static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP = n_("matrixDiscardsWeightPerStrMet"); @Doc(value = "do the doc of Result matrixDiscardsPerStrMet") static final public String MATRIX_DISCARDS_PER_STR_MET = n_("matrixDiscardsPerStrMet"); @@ -65,14 +65,14 @@ static final public String MATRIX_STD_TRAVEL_EFFORT_PER_STRATEGY_MET = n_("matrixStdTravelEffortPerStrategyMet"); @Doc(value = "do the doc of Result matrixEffortPerZonePop") static final public String MATRIX_EFFORT_PER_ZONE_POP = n_("matrixEffortPerZonePop"); - @Doc(value = "do the doc of Result matrixCatchRatePerStrategyMet") - static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET = n_("matrixCatchRatePerStrategyMet"); - @Doc(value = "do the doc of Result matrixCatchPerStrategyMet") - static final public String MATRIX_CATCH_PER_STRATEGY_MET = n_("matrixCatchPerStrategyMet"); - @Doc(value = "do the doc of Result matrixFishingMortality") - static final public String MATRIX_FISHING_MORTALITY = n_("matrixFishingMortality"); - @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMet") - static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET = n_("matrixCatchWeightPerStrategyMet"); + @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZoneMet") + static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchPerStrategyMetPerZoneMet"); + @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZonePop") + static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchPerStrategyMetPerZonePop"); + @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZoneMet") + static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchWeightPerStrategyMetPerZoneMet"); + @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZonePop") + static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchWeightPerStrategyMetPerZonePop"); @Doc(value = "do the doc of Result matrixAbundance") static final public String MATRIX_ABUNDANCE = n_("matrixAbundance"); @Doc(value = "do the doc of Result matrixBiomass") Modified: branches/3.2/scripts/SiMatrix.java =================================================================== --- branches/3.2/scripts/SiMatrix.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/scripts/SiMatrix.java 2008-08-12 13:10:38 UTC (rev 47) @@ -67,6 +67,7 @@ import fr.ifremer.isisfish.simulator.SimulationContext; import fr.ifremer.isisfish.types.Date; import fr.ifremer.isisfish.types.Month; +import java.util.Set; /** * @author poussin @@ -240,6 +241,94 @@ // /////////////////////////////////////////////////////////////////////////// + public MatrixND matrixCatchWeightPerStrategyMetPerZoneMet(Date date, Population pop, MatrixND matrixCatchPerStrategyMetPerZoneMet) throws TopiaException, IsisFishException { + List<PopulationGroup> groups = pop.getPopulationGroup(); + + MatrixND result = matrixCatchPerStrategyMetPerZoneMet.copy(); + result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET); + + for (PopulationGroup group : groups) { + MatrixND sub = result.getSubMatrix(2, group, 1); + double meanWeight = group.getMeanWeight(); + sub.mults(meanWeight); + } + + return result; + } + + public MatrixND matrixCatchPerStrategyMetPerZoneMet(MatrixND N, Population pop, Date date) throws TopiaException, IsisFishException { + + MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(date, pop); + MatrixND matrixCatchRatePerStrategyMetPerCell = matrixCatchRatePerStrategyMetPerCell(pop, date, matrixFishingMortalityPerCell); + MatrixND matrixCatchPerStrategyMetPerCell = matrixCatchPerStrategyMetPerCell(N, pop, date, matrixCatchRatePerStrategyMetPerCell); + + List<Strategy> strategies = getStrategies(date); + List<Metier> metiers = getMetiers(date); + List<PopulationGroup> groups = matrixCatchPerStrategyMetPerCell.getSemantics(2); + List<Zone> zones = getZones(date); + + MatrixND result = MatrixFactory.getInstance().create( + ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET, + new List[]{strategies, metiers, groups, zones}, + new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")}); + + // matrice temporaire ou les zones pops sont sommees + MatrixND tmp = matrixCatchPerStrategyMetPerCell.sumOverDim(3); + tmp = tmp.reduce(3); + + for (int s = 0; s < strategies.size(); s++) { + Strategy str = strategies.get(s); + for(int g = 0; g<groups.size(); g++) { + PopulationGroup group = groups.get(g); + for (int m = 0; m < metiers.size(); m++) { + Metier metier = metiers.get(m); + MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(date.getMonth()); + Collection<Zone> zoneMet = infoMet.getZone(); + for (Zone z : zoneMet) { + double value = 0; + List<Cell> cells = z.getCell(); + for (int c = 0; c < cells.size(); c++) { + Cell cell = cells.get(c); + value += tmp.getValue(str, metier, group, cell); + result.setValue(str, metier, group, z, value); + } + } + } + } + } + + return result; + } + + public MatrixND matrixCatchPerStrategyMetPerZonePop(MatrixND N, Population pop, Date date) throws TopiaException, IsisFishException { + MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(date, pop); + MatrixND matrixCatchRatePerStrategyMetPerCell = matrixCatchRatePerStrategyMetPerCell(pop, date, matrixFishingMortalityPerCell); + MatrixND matrixCatchPerStrategyMetPerCell = matrixCatchPerStrategyMetPerCell(N, pop, date, matrixCatchRatePerStrategyMetPerCell); + + // on somme sur les cellules + MatrixND result = matrixCatchPerStrategyMetPerCell.sumOverDim(4); + result = result.reduce(4); + result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP); + + return result; + } + + public MatrixND matrixCatchWeightPerStrategyMetPerZonePop(Date date, + Population pop, MatrixND matrixCatchPerStrategyMetPerZonePop) throws TopiaException, IsisFishException { + List<PopulationGroup> groups = pop.getPopulationGroup(); + + MatrixND result = matrixCatchPerStrategyMetPerZonePop.copy(); + result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP); + + for (PopulationGroup group : groups) { + MatrixND sub = result.getSubMatrix(2, group, 1); + double meanWeight = group.getMeanWeight(); + sub.mults(meanWeight); + } + + return result; + } + /** * Matrice des captures en nombre * dim [ Strategy x Metier x Classe x zonePop ] @@ -251,21 +340,21 @@ * @throws TopiaException * @throws IsisFishException */ - public MatrixND matrixCatchPerStrategyMet(MatrixND N, Population pop, - Date date, MatrixND matrixCatchRatePerStrategyMet) throws TopiaException, IsisFishException { + private MatrixND matrixCatchPerStrategyMetPerCell(MatrixND N, Population pop, + Date date, MatrixND matrixCatchRatePerStrategyMetPerCell) throws TopiaException, IsisFishException { List<PopulationGroup> groups = pop.getPopulationGroup(); List<Zone> zones = pop.getPopulationZone(); // on le passe en argument ce qui evite de le calculer 2 fois // MatrixND matrixCatchRatePerStrategyMet = matrixCatchRatePerStrategyMet(pop, date); - MatrixND result = matrixCatchRatePerStrategyMet.copy(); - result.setName(ResultName.MATRIX_CATCH_PER_STRATEGY_MET); + MatrixND result = matrixCatchRatePerStrategyMetPerCell.copy(); + result.setName("matrixCatchPerStrategyMetPerCell"); for(PopulationGroup group : groups) { MatrixND sub = result.getSubMatrix(2, group, 1); for(Zone zone : zones){ MatrixND subsub = sub.getSubMatrix(3, zone, 1); - double val = N.getValue(group, zone); + double val = N.getValue(group, zone) / (double)zone.sizeCell(); subsub.mults(val); } } @@ -282,16 +371,17 @@ * @throws TopiaException * @throws IsisFishException */ - public MatrixND matrixCatchRatePerStrategyMet(Population pop, Date date, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException { + private MatrixND matrixCatchRatePerStrategyMetPerCell(Population pop, Date date, MatrixND matrixFishingMortalityPerCell) throws TopiaException, IsisFishException { List<Strategy> strategies = getStrategies(date); List<Metier> metiers = getMetiers(date); List<PopulationGroup> groups = pop.getPopulationGroup(); List<Zone> zones = pop.getPopulationZone(); + List<Cell> cells = getCells(zones); MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_CATCH_RATE_PER_STRATEGY_MET, - new List[]{strategies, metiers, groups, zones}, - new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")}); + "matrixCatchRatePerStrategyMetPerCell", + new List[]{strategies, metiers, groups, zones, cells}, + new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones"), n_("Cells")}); // for (int s=0; s < strategies.size(); s++) { // Strategy str = strategies.get(s); @@ -313,26 +403,38 @@ // if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + pop + ")");} // } else { // Optimisation Hilaire - for (int s=0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - metiers = getMetiers(str, date); - for (int m=0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - for (int z=0; z < zones.size(); z++) { - Zone zone = zones.get(z); - double effort = effortPerZonePop(str,metier,date,zone); - if (effort > 0){ - for (int g=0; g < groups.size(); g++) { + + MatrixND matrixFishingMortalityPerCellSumOverGroup = matrixFishingMortalityPerCell.sumOverDim(2); + matrixFishingMortalityPerCellSumOverGroup = matrixFishingMortalityPerCellSumOverGroup.reduce(2); + + for (int s = 0; s < strategies.size(); s++) { + Strategy str = strategies.get(s); + metiers = getMetiers(str, date); + for (int m = 0; m < metiers.size(); m++) { + Metier metier = metiers.get(m); + for (int z = 0; z < zones.size(); z++) { + Zone zone = zones.get(z); + List<Cell> cellZones = zone.getCell(); + for (int c = 0; c < cellZones.size(); c++) { + Cell cell = cellZones.get(c); + double effort = matrixFishingMortalityPerCellSumOverGroup.getValue( + str, metier, zone, cell); + if (effort > 0) { + for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); - double value = catchRatePerStrategyMet(str, metier, date, group, zone, matrixFishingMortality); - result.setValue(str, metier, group, zone, value); + double value = catchRatePerStrategyMetPerCell( + str, metier, date, group, zone, cell, + matrixFishingMortalityPerCell); + result.setValue(new Object[]{str, metier, group, + zone, cell}, value); } } } } } + } // } - + // for (Strategy str : strategies) { // List<Metier> metierStr = getMetiers(str, date); // for (Metier metier : metierStr) { @@ -380,25 +482,31 @@ // } // Optimisation Hilaire - private double catchRatePerStrategyMet(Strategy str, Metier metier, Date date, PopulationGroup group, Zone zone, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException { -// double totalFishingMortality = matrixFishingMortality.sumAll(); - double totalFishingMortality = totalFishingMortality(date, matrixFishingMortality).getValue(group, zone); + private double catchRatePerStrategyMetPerCell(Strategy str, Metier metier, + Date date, PopulationGroup group, Zone zone, Cell cell, + MatrixND matrixFishingMortalityPerCell) throws TopiaException, IsisFishException { + double totalFishingMortality = totalFishingMortalityPerCell(date, + matrixFishingMortalityPerCell).getValue(group, zone); + if(totalFishingMortality == 0){ if(log.isDebugEnabled()) {log.debug("pas de totalFishingMortality pour (" + group + ", " + zone +")");} return 0; } - double fishingMortality = matrixFishingMortality.getValue(str, metier, group, zone); - double totalCatchRate = totalCatchRate(date, group, zone, totalFishingMortality); + double fishingMortalityPerCell = matrixFishingMortalityPerCell.getValue( + new Object[]{str, metier, group, zone, cell}); + double totalCatchRatePerCell = + totalCatchRatePerCell(date, group, zone, totalFishingMortality); if(log.isDebugEnabled()) { log.debug( " totalFishingMortality=" + totalFishingMortality + - " fishingMortality=" + fishingMortality + - " totalCatchRate=" + totalCatchRate); + " fishingMortality=" + fishingMortalityPerCell + + " totalCatchRate=" + totalCatchRatePerCell); } - double result = fishingMortality / totalFishingMortality * totalCatchRate; + double result = + fishingMortalityPerCell / totalFishingMortality * totalCatchRatePerCell; return result; } @@ -412,8 +520,8 @@ * @return * @throws TopiaException */ - private double totalCatchRate(Date date, PopulationGroup group, - Zone zone, double totalFishingMortality) throws TopiaException { + private double totalCatchRatePerCell(Date date, PopulationGroup group, + Zone zone, double totalFishingMortalityPerCell) throws TopiaException { double M = group.getNaturalDeathRate(zone) / Month.NUMBER_OF_MONTH; if(M == 0){ // normalement il devrait y avoir de la mortalite naturelle @@ -421,7 +529,7 @@ log.warn("Pas de mortalit� naturelle pour: " + group); } } - double F = totalFishingMortality; + double F = totalFishingMortalityPerCell; double result = 0; if( M != 0 || F != 0){ @@ -440,16 +548,18 @@ * @param zone * @return */ - private MatrixND totalFishingMortality(Date date, MatrixND matrixFishingMortality) { - MatrixND result = matrixFishingMortality.sumOverDim(0); + private MatrixND totalFishingMortalityPerCell(Date date, MatrixND matrixFishingMortalityPerCell) { + MatrixND result = matrixFishingMortalityPerCell.sumOverDim(0); result = result.sumOverDim(1); result = result.reduceDims(0, 1); return result; } + + // Nouvelle implantation suite a demande Steph et Sigrid: 20080208 (NouvellesEquationsfev2008ParCelluleAvecAlgo.odt) /** * Matrice fishing mortality - * dim [ Strategy x Metier x Classe x zonePop ] + * dim [ Strategy x Metier x Classe x zonePop x cellPop] * * @param pop * @param date @@ -457,64 +567,60 @@ * @throws TopiaException * @throws IsisFishException */ - public MatrixND matrixFishingMortality(Date date, Population pop) throws TopiaException, IsisFishException { + public MatrixND matrixFishingMortalityPerCell(Date date, Population pop) throws TopiaException, IsisFishException { List<Strategy> strategies = getStrategies(date); List<Metier> metiers = getMetiers(date); List<PopulationGroup> groups = pop.getPopulationGroup(); List<Zone> zones = pop.getPopulationZone(); + List<Cell> cells = getCells(zones); // default value in matrix is 0 MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_FISHING_MORTALITY, - new List[]{strategies, metiers, groups, zones}, - new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")}); + "matrixFishingMortalityPerCell", + new List[]{strategies, metiers, groups, zones, cells}, + new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones"), n_("Cells")}); Month month = date.getMonth(); PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month); -// org.codelutin.util.CallAnalyse.activate(); - for (int g=0; g < groups.size(); g++) { - PopulationGroup group = groups.get(g); - - // getCapturability is check matrix validity and create matrix if needed and get one value in -// org.codelutin.util.CallAnalyse.enter("debug infoPop.getCapturability"); - double capturability = infoPop.getCapturability(group); -// org.codelutin.util.CallAnalyse.exit("debug infoPop.getCapturability"); - if (capturability != 0) { // check 0, this prevent next call, for default value - - for (int m=0; m < metiers.size(); m++) { - Metier metier = metiers.get(m); - -// org.codelutin.util.CallAnalyse.enter("debug infoMet.getTargetFactor"); - MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month); - // getTargetFactor seem to be simple - double ciblage = infoMet.getTargetFactor(group); -// org.codelutin.util.CallAnalyse.exit("debug infoMet.getTargetFactor"); + for (int g = 0; g < groups.size(); g++) { + PopulationGroup group = groups.get(g); - if (ciblage != 0) { // check 0, this prevent next call, for default value - -// org.codelutin.util.CallAnalyse.enter("debug gear.getPopulationSelectivity"); - Gear gear = metier.getGear(); - Selectivity selectivity = gear.getPopulationSelectivity(pop); -// org.codelutin.util.CallAnalyse.exit("debug gear.getPopulationSelectivity"); - if (selectivity != null) { + // getCapturability is check matrix validity and create matrix + // if needed and get one value in + double capturability = infoPop.getCapturability(group); + if (capturability != 0) { // check 0, this prevent next call, for default value + for (int m = 0; m < metiers.size(); m++) { + Metier metier = metiers.get(m); - // getCoefficient is equation evaluation -// org.codelutin.util.CallAnalyse.enter("debug selectivity.getCoefficient"); - double coeff = selectivity.getCoefficient(pop, group, metier); -// org.codelutin.util.CallAnalyse.exit("debug selectivity.getCoefficient"); - if (coeff != 0) { // check 0, this prevent next call, for default value - - for (int s=0; s < strategies.size(); s++) { - Strategy str = strategies.get(s); - for (int z=0; z < zones.size(); z++) { - Zone zone = zones.get(z); - double effort = effortPerZonePop(str,metier,date,zone); - if (effort > 0){ // put value only if <> 0 - double value = coeff * capturability * ciblage * effort; -// org.codelutin.util.CallAnalyse.enter("debug result.setValue"); - result.setValue(str, metier, group, zone, value); -// org.codelutin.util.CallAnalyse.exit("debug result.setValue"); + MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month); + // getTargetFactor seem to be simple + double ciblage = infoMet.getTargetFactor(group); + + if (ciblage != 0) { // check 0, this prevent next call, for default value + + Gear gear = metier.getGear(); + Selectivity selectivity = gear.getPopulationSelectivity(pop); + if (selectivity != null) { + + // getCoefficient is equation evaluation + double coeff = selectivity.getCoefficient(pop, group, metier); + if (coeff != 0) { // check 0, this prevent next call, for default value + + for (int s = 0; s < strategies.size(); s++) { + Strategy str = strategies.get(s); + // l'effort d'une cellule du metier + double effort = effortPerStrategyPerCell(str, metier, date); + if (effort > 0) { // put value only if <> 0 + for (int z = 0; z < zones.size(); z++) { + Zone zone = zones.get(z); + Set<Cell> cellPops = new HashSet<Cell>(zone.getCell()); + for (Cell cellMet : infoMet.getCells()) { + if (cellPops.contains(cellMet)) { + double value = coeff * capturability * ciblage * effort; + result.setValue(new Object[]{str, metier, group, zone, cellMet}, value); + } + } } } } @@ -524,10 +630,79 @@ } } } -// System.out.println("****DEBUG matrixFishingMortality:" + org.codelutin.util.CallAnalyse.getThreadStatistics().toString()); return result; } + // Supprimee suite a demande Steph et Sigrid: 20080208 (NouvellesEquationsfev2008ParCelluleAvecAlgo.odt) +// /** +// * Matrice fishing mortality +// * dim [ Strategy x Metier x Classe x zonePop ] +// * +// * @param pop +// * @param date +// * @return +// * @throws TopiaException +// * @throws IsisFishException +// */ +// public MatrixND matrixFishingMortalityPerCell(Date date, Population pop) throws TopiaException, IsisFishException { +// List<Strategy> strategies = getStrategies(date); +// List<Metier> metiers = getMetiers(date); +// List<PopulationGroup> groups = pop.getPopulationGroup(); +// List<Zone> zones = pop.getPopulationZone(); +// +// // default value in matrix is 0 +// MatrixND result = MatrixFactory.getInstance().create( +// ResultName.MATRIX_FISHING_MORTALITY, +// new List[]{strategies, metiers, groups, zones}, +// new String[]{n_("Strategies"), n_("Metiers"), n_("Groups"), n_("Zones")}); +// +// Month month = date.getMonth(); +// PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month); +// +// for (int g=0; g < groups.size(); g++) { +// PopulationGroup group = groups.get(g); +// +// // getCapturability is check matrix validity and create matrix if needed and get one value in +// double capturability = infoPop.getCapturability(group); +// if (capturability != 0) { // check 0, this prevent next call, for default value +// +// for (int m=0; m < metiers.size(); m++) { +// Metier metier = metiers.get(m); +// +// MetierSeasonInfo infoMet = metier.getMetierSeasonInfo(month); +// // getTargetFactor seem to be simple +// double ciblage = infoMet.getTargetFactor(group); +// +// if (ciblage != 0) { // check 0, this prevent next call, for default value +// +// Gear gear = metier.getGear(); +// Selectivity selectivity = gear.getPopulationSelectivity(pop); +// if (selectivity != null) { +// +// // getCoefficient is equation evaluation +// double coeff = selectivity.getCoefficient(pop, group, metier); +// if (coeff != 0) { // check 0, this prevent next call, for default value +// +// for (int s=0; s < strategies.size(); s++) { +// Strategy str = strategies.get(s); +// for (int z=0; z < zones.size(); z++) { +// Zone zone = zones.get(z); +// double effort = effortPerZonePop(str,metier,date,zone); +// if (effort > 0){ // put value only if <> 0 +// double value = coeff * capturability * ciblage * effort; +// result.setValue(str, metier, group, zone, value); +// } +// } +// } +// } +// } +// } +// } +// } +// } +// return result; +// } + // ne prendre que les metiers pratiqu� semble une bonne idee, mais en fait non, car cela oblige l'ordre des boucles // et donc ne permet pas autant d'optimisation que souhait� // public MatrixND matrixFishingMortality2(Date date, Population pop) throws TopiaException, IsisFishException { @@ -670,33 +845,34 @@ // return result; // } - /** - * @param str - * @param metier - * @param date - * @param zone - * @return - */ - private double effortPerZonePop(Strategy str, Metier metier, Date date, Zone zonePop) { - Month month = date.getMonth(); - Collection<Zone> zoneMet = metier.getMetierSeasonInfo(month).getZone(); - double inter = nbCellInter(zoneMet, zonePop); + // Supprimee suite a demande Steph et Sigrid: 20080208 (NouvellesEquationsfev2008ParCelluleAvecAlgo.odt) +// /** +// * @param str +// * @param metier +// * @param date +// * @param zone +// * @return +// */ +// private double effortPerZonePop(Strategy str, Metier metier, Date date, Zone zonePop) { +// Month month = date.getMonth(); +// Collection<Zone> zoneMet = metier.getMetierSeasonInfo(month).getZone(); +// double inter = nbCellInter(zoneMet, zonePop); +// +// double effortPerStrategyPerCell = effortPerStrategyPerCell(str, metier, date); +// +// if(log.isDebugEnabled()) { +// log.debug( +// " strategy=" + str + +// " metier=" + metier + +// " inter=" + inter + +// " effortPerStrategyPerCell=" + effortPerStrategyPerCell +// ); +// } +// +// double result = effortPerStrategyPerCell * inter; +// return result; +// } - double effortPerStrategyPerCell = effortPerStrategyPerCell(str, metier, date); - - if(log.isDebugEnabled()) { - log.debug( - " strategy=" + str + - " metier=" + metier + - " inter=" + inter + - " effortPerStrategyPerCell=" + effortPerStrategyPerCell - ); - } - - double result = effortPerStrategyPerCell * inter; - return result; - } - /** * @param str * @param metier @@ -1001,35 +1177,54 @@ * @throws IsisFishException * @throws TopiaException */ - public MatrixND matrixAbundance(MatrixND N, Population pop, Date date, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException { + private MatrixND matrixAbundancePerCell(MatrixND N, Population pop, + Date date, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException { + List<PopulationGroup> groups = pop.getPopulationGroup(); List<Zone> zones = pop.getPopulationZone(); MatrixND result = MatrixFactory.getInstance().create( - ResultName.MATRIX_ABUNDANCE, + ResultName.MATRIX_ABUNDANCE + "_PER_CELL", new List[]{groups, zones}, - new String[]{n_("Groups"), n_("Zones")}); + new String[]{n_("Groups"), n_("Zones"), n_("Cells")}); for (int g=0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); for (int z=0; z < zones.size(); z++) { - Zone zone = zones.get(z); - double value = survivalRate(date, group, zone, matrixFishingMortality); - double n = N.getValue(g, z); - value *= n; - result.setValue(g, z, value); + Zone zone = zones.get(z); + List<Cell> cells = zone.getCell(); + for (int c=0; c<cells.size(); c++) { + Cell cell = cells.get(c); + double value = survivalRatePerCell(date, group, zone, cell, matrixFishingMortality); + double n = N.getValue(g, z) / zone.sizeCell(); + value *= n; + result.setValue(g, z, value); + } } } + + return result; + } + + /** + * @param N + * @param pop + * @param date + * @return + * @throws IsisFishException + * @throws TopiaException + */ + public MatrixND matrixAbundance(MatrixND N, Population pop, Date date) + throws TopiaException, IsisFishException { -// for(PopulationGroup group : groups){ -// for(Zone zone : zones){ -// double val = survivalRate(date, group, zone); -// val *= N.getValue(group, zone); -// result.setValue(group, zone, val); -// } -// } + MatrixND matrixFishingMortalityPerCell = matrixFishingMortalityPerCell(date, pop); - return result; + MatrixND result = matrixAbundancePerCell(N, pop, date, matrixFishingMortalityPerCell); + result = result.sumOverDim(2); + result = result.reduce(2); + result.setName(ResultName.MATRIX_ABUNDANCE); + + return result; } /** @@ -1040,8 +1235,11 @@ * @throws IsisFishException * @throws TopiaException */ - private double survivalRate(Date date, PopulationGroup group, Zone zone, MatrixND matrixFishingMortality) throws TopiaException, IsisFishException { - double F = totalFishingMortality(date, matrixFishingMortality).getValue(group, zone); //totalFishingMortality(date, group, zone); // rem perf: totalFishingMortality a deja ete calcul� + private double survivalRatePerCell(Date date, PopulationGroup group, Zone zone, + Cell cell, MatrixND matrixFishingMortalityPerCell) throws TopiaException, IsisFishException { + + double F = totalFishingMortalityPerCell(date, matrixFishingMortalityPerCell) + .getValue(group, zone, cell); //totalFishingMortality(date, group, zone); // rem perf: totalFishingMortality a deja ete calcul� double M = group.getNaturalDeathRate(zone)/(double)Month.NUMBER_OF_MONTH; double result = (double)Math.exp(-(F+M)); @@ -1138,38 +1336,40 @@ // /////////////////////////////////////////////////////////////////////////// - /** - * @param pop - * @param date - * @return - */ - public MatrixND matrixCatchWeightPerStrategyMet(Population pop, - Date date, MatrixND matrixCatchPerStrategyMet) { - List<PopulationGroup> groups = pop.getPopulationGroup(); +// /** +// * @param pop +// * @param date +// * @return +// */ +// public MatrixND matrixCatchWeightPerStrategyMet(Population pop, +// Date date, MatrixND matrixCatchPerStrategyMet) { +// List<PopulationGroup> groups = pop.getPopulationGroup(); +// +// MatrixND result = matrixCatchPerStrategyMet.copy(); +// result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET); +// +// for(PopulationGroup group : groups){ +// MatrixND sub = result.getSubMatrix(2, group, 1); +// double meanWeight = group.getMeanWeight(); +// sub.mults(meanWeight); +// } +// +// return result; +// } - MatrixND result = matrixCatchPerStrategyMet.copy(); - result.setName(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET); - - for(PopulationGroup group : groups){ - MatrixND sub = result.getSubMatrix(2, group, 1); - double meanWeight = group.getMeanWeight(); - sub.mults(meanWeight); - } - - return result; - } - /** + * + * * @param pop * @param date * @return */ - public MatrixND matrixDiscardWeightPerStrategyMet(Population pop, - Date date, MatrixND matrixDiscardPerStrategyMet) { + public MatrixND matrixDiscardWeightPerStrategyMetPerZonePop(Population pop, + Date date, MatrixND matrixDiscardPerStrategyMetPerZonePop) { List<PopulationGroup> groups = pop.getPopulationGroup(); - MatrixND result = matrixDiscardPerStrategyMet.copy(); - result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET); + MatrixND result = matrixDiscardPerStrategyMetPerZonePop.copy(); + result.setName(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP); for(PopulationGroup group : groups){ MatrixND sub = result.getSubMatrix(2, group, 1); Modified: branches/3.2/simulators/DefaultSimulator.java =================================================================== --- branches/3.2/simulators/DefaultSimulator.java 2008-08-12 08:13:26 UTC (rev 46) +++ branches/3.2/simulators/DefaultSimulator.java 2008-08-12 13:10:38 UTC (rev 47) @@ -1,6 +1,6 @@ /* *##% * Copyright (C) 2006 - * Ifremer, Code Lutin, C�dric Pineau, Benjamin Poussin + * Ifremer, Code Lutin, C?dric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,7 +20,7 @@ /* * * DefaultSimulator.java * - * Created: 21 ao�t 2006 10:57:46 + * Created: 21 ao?t 2006 10:57:46 * * @author poussin * @version $Revision: 1.19 $ @@ -98,7 +98,10 @@ MetierMonitor metierMonitor = context.getMetierMonitor(); RuleMonitor ruleMonitor = context.getRuleMonitor(); - for (Population pop : siMatrix.getPopulations(date)) { + List<Population> allpops = siMatrix.getPopulations(date); + populationMonitor.init(allpops); + + for (Population pop : allpops) { MatrixND N = param.getNumberOf(pop); N.setName(ResultName.MATRIX_ABUNDANCE); populationMonitor.setN(pop, N); @@ -281,8 +284,8 @@ } resManager.addResult(date, pop, discard); - if (resManager.isEnabled(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET)) { - MatrixND discardWeightPerStrategyMet = siMatrix.matrixDiscardWeightPerStrategyMet(pop, date, discard); + if (resManager.isEnabled(ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP)) { + MatrixND discardWeightPerStrategyMet = siMatrix.matrixDiscardWeightPerStrategyMetPerZonePop(pop, date, discard); resManager.addResult(date, pop, discardWeightPerStrategyMet); } @@ -404,24 +407,43 @@ // compute fishing matrix only if there are one or more strategy if (siMatrix.getStrategies(date).size() > 0) { // compute some Matrix and add result - MatrixND matrixFishingMortality = siMatrix.matrixFishingMortality(date, pop); - resManager.addResult(date, pop, matrixFishingMortality); - abundance = siMatrix.matrixAbundance(N, pop, date, matrixFishingMortality); + // n'existe plus suite a l'implantation de calculs en cell +// MatrixND matrixFishingMortality = siMatrix.matrixFishingMortality(date, pop); +// resManager.addResult(date, pop, matrixFishingMortality); + + abundance = siMatrix.matrixAbundance(N, pop, date); + // n'existe plus suite a l'implantation de calculs en cell // this matrix is necessary for matrixCatchPerStrategyMet - MatrixND catchRatePerStrategyMet = siMatrix.matrixCatchRatePerStrategyMet(pop, date, matrixFishingMortality); - resManager.addResult(date, pop, catchRatePerStrategyMet); +// MatrixND catchRatePerStrategyMet = siMatrix.matrixCatchRatePerStrategyMet(pop, date, matrixFishingMortality); +// resManager.addResult(date, pop, catchRatePerStrategyMet); // this matrix is necessary for PopulationMonitor.holdCatch (reused in rule) - MatrixND catchPerStrategyMet = siMatrix.matrixCatchPerStrategyMet(N, pop, date, catchRatePerStrategyMet); - popMon.holdCatch(pop, catchPerStrategyMet); - resManager.addResult(date, pop, catchPerStrategyMet); + MatrixND catchPerStrategyMetPerZonePop = + siMatrix.matrixCatchPerStrategyMetPerZonePop(N, pop, date); + popMon.holdCatch(pop, catchPerStrategyMetPerZonePop); + resManager.addResult(date, pop, catchPerStrategyMetPerZonePop); - if (resManager.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET)) { - MatrixND catchWeightPerStrategyMet = siMatrix.matrixCatchWeightPerStrategyMet(pop, date, catchPerStrategyMet); + if (resManager.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP)) { + MatrixND catchWeightPerStrategyMet = + siMatrix.matrixCatchWeightPerStrategyMetPerZonePop(date, pop, + catchPerStrategyMetPerZonePop); resManager.addResult(date, pop, catchWeightPerStrategyMet); } + + MatrixND catchPerStrategyMetPerZoneMet = + siMatrix.matrixCatchPerStrategyMetPerZoneMet(N, pop, date); + resManager.addResult(date, pop, catchPerStrategyMetPerZoneMet); + + if (resManager.isEnabled(ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET)) { + MatrixND catchWeightPerStrategyMet = + siMatrix.matrixCatchWeightPerStrategyMetPerZoneMet(date, pop, + catchPerStrategyMetPerZoneMet); + resManager.addResult(date, pop, catchWeightPerStrategyMet); + } + + } log.debug("abundance: " + abundance);
participants (1)
-
bpoussin@users.labs.libre-entreprise.org