Skip to content

Commit

Permalink
remove AlgorithmFactories and some associate classes
Browse files Browse the repository at this point in the history
the YAML-related code is still icky, but we have now fully moved to
Java service-loader infrastructure!
  • Loading branch information
nicolaspayette committed Jun 5, 2024
1 parent 72c009c commit 52a1cbf
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 678 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
/*
* POSEIDON, an agent-based model of fisheries
* Copyright (C) 2017 CoHESyS Lab [email protected]
* POSEIDON: an agent-based model of fisheries
* Copyright (c) 2017-2024 CoHESyS Lab [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package uk.ac.ox.oxfish.model.regs.factory;
Expand All @@ -27,16 +25,12 @@
import uk.ac.ox.poseidon.common.core.parameters.FixedDoubleParameter;

/**
* Creates a single mono-quota object and shares it every time it is called. If you modify the quota parameter here, it will
* affect all the quotas that were created before as well
* Created by carrknight on 6/14/15.
* Creates a single mono-quota object and shares it every time it is called. If you modify the quota
* parameter here, it will affect all the quotas that were created before as well Created by
* carrknight on 6/14/15.
*/
public class TACMonoFactory implements AlgorithmFactory<MonoQuotaRegulation> {
/**
* This provides a static singleton instance that will be used when building the list of constructors in the
* {@link uk.ac.ox.oxfish.utility.AlgorithmFactories} class, so all the TACs are forced to remain connected.
*/
private static final TACMonoFactory instance = new TACMonoFactory();

/**
* for each model there is only one quota object being shared
*/
Expand All @@ -49,10 +43,6 @@ public class TACMonoFactory implements AlgorithmFactory<MonoQuotaRegulation> {
*/
private DoubleParameter quota = new FixedDoubleParameter(500000);

public static TACMonoFactory getInstance() {
return instance;
}

/**
* Creates a TAC and optionally the whole structure that keeps track of opportunity costs
*
Expand All @@ -63,27 +53,25 @@ public static TACMonoFactory getInstance() {
@SuppressWarnings("unchecked")
public MonoQuotaRegulation apply(final FishState state) {


final Double yearlyQuota = quota.applyAsDouble(state.random);
final MonoQuotaRegulation quotaRegulation =
modelQuota.presentKey(
state.getUniqueID(),
() -> new MonoQuotaRegulation(yearlyQuota)
);

//if it has not been consumed (probably because the model still has to start) then:
// if it has not been consumed (probably because the model still has to start) then:
if (quotaRegulation.getQuotaRemaining(0) > 0 &&
Math.abs(quotaRegulation.getQuotaRemaining(0) - quotaRegulation.getYearlyQuota()) < .1)
quotaRegulation.setQuotaRemaining(0, yearlyQuota);

//set yearly quota (notice that this will affect everyone)
// set yearly quota (notice that this will affect everyone)
quotaRegulation.setYearlyQuota(yearlyQuota);

//don't let quota remaining be above yearly quota though
// don't let quota remaining be above yearly quota though
if (quotaRegulation.getQuotaRemaining(0) > quotaRegulation.getYearlyQuota())
quotaRegulation.setQuotaRemaining(0, yearlyQuota);


return quotaRegulation;

}
Expand All @@ -92,11 +80,9 @@ public DoubleParameter getQuota() {
return quota;
}


public void setQuota(final DoubleParameter quota) {
this.quota = quota;
}


}

Loading

0 comments on commit 52a1cbf

Please sign in to comment.