15 virtual void reset(uint time,
Model& model) {
19 virtual void operate(uint time,
Model& model) = 0;
21 virtual double control(
void)
const {
25 virtual void read(std::istream& stream) {
29 virtual void write(std::ostream& stream) = 0;
42 class Lagger :
public std::deque<double> {
61 auto lagged = front();
76 virtual void write(std::ostream& stream){
78 <<
"DoNothing"<<
"\t\t\t\t\t\t\t\t\t\t\n";
81 virtual void operate(uint time,
Model& model){
94 Array<Variable<Fixed>,
Year,Quarter,Region,Method> catches;
98 catches.read(
"parameters/input/catches.tsv",
true);
101 virtual void write(std::ostream& stream){
103 <<
"HistCatch"<<
"\t\t\t\t\t\t\t\t\t\t\n";
106 virtual void operate(uint time,
Model& model){
110 uint year = IOSKJ::year(time);
111 if(year>2014) year = 2014;
112 uint quarter = IOSKJ::quarter(time);
113 model.exploit = model.exploit_catch;
114 for(
auto region : regions){
115 for(
auto method : methods){
116 model.
catches(region,method) = catches(year,quarter,region,method);
142 virtual void read(std::istream& stream){
147 virtual void write(std::ostream& stream){
149 <<
"ConstCatch\t"<<tac<<
"\t\t\t\t\t\t\t\t\t\n";
152 virtual void operate(uint time, Model& model){
153 model.catches_set(tac/4.0);
175 virtual void write(std::ostream& stream){
177 <<
"ConstEffort\t"<<tae<<
"\t\t\t\t\t\t\t\t\t\n";
180 virtual void operate(uint time, Model& model){
181 model.effort_set(tae);
250 template<
class Mirror>
253 .data(frequency,
"frequency")
254 .data(precision,
"precision")
255 .data(thresh,
"thresh")
256 .data(closure,
"closure")
266 void read(std::istream& stream){
303 catches_last_ = (425000/4.0);
310 int year = IOSKJ::year(time);
311 int quarter = IOSKJ::quarter(time);
313 if(year_last_<0 or year-year_last_>=frequency) {
317 double etarg = model.
e_40;
322 bcurr *= imprecision.random();
323 b0 *= imprecision.random();
324 etarg *= imprecision.random();
326 double status = bcurr/b0;
330 if(status<closure) exprate = 0;
331 else if(status>=thresh) exprate = imax * etarg;
332 else exprate = imax/(thresh-
closure)*(status-closure) * etarg;
336 double catches = exprate * bcurr;
337 if (catches*4 > cmax) {
342 auto change = catches/catches_last_;
343 if (change>(1+dmax)) catches = catches_last_ * (1 + dmax);
344 else if (change<(1-dmax)) catches = catches_last_ * (1 - dmax);
348 catches_last_ = catches;
352 catches_now_ = lagger.
push_pop(catches_last_);
356 if (not std::isnan(catches_now_)) {
361 virtual double control(
void)
const {
375 double catches_last_ = NAN;
380 double catches_now_ = NAN;
420 template<
class Mirror>
423 .data(frequency,
"frequency")
424 .data(precision,
"precision")
425 .data(target,
"target")
426 .data(thresh,
"thresh")
431 void read(std::istream& stream){
440 void write(std::ostream& stream){
447 <<limit<<
"\t\t\t\t\t\n";
450 virtual void reset(uint time, Model& model){
454 virtual void operate(uint time, Model& model){
455 int year = IOSKJ::year(time);
456 int quarter = IOSKJ::quarter(time);
457 if(quarter==0 and (last_<0 or year-last_>=frequency)){
459 double b = model.biomass_status();
462 b *= imprecision.random();
466 else if(b>thresh) f =
target;
467 else f = target/(thresh-
limit)*(b-limit);
469 model.fishing_mortality_set(f);
496 double precision = 0.1;
517 template<
class Mirror>
520 .data(frequency,
"frequency")
521 .data(precision,
"precision")
522 .data(target,
"target")
523 .data(buffer,
"buffer")
524 .data(change_max,
"change_max")
528 void write(std::ostream& stream){
535 <<change_max<<
"\t\t\t\t\t\n";
538 virtual void reset(uint time, Model& model){
543 virtual void operate(uint time, Model& model){
544 int year = IOSKJ::year(time);
545 int quarter = IOSKJ::quarter(time);
546 if(quarter==0 and (last_<0 or year-last_>=frequency)){
548 double f = model.exploitation_rate_get();
551 f *= imprecision.random();
553 if(f<target-buffer or f>target+buffer){
555 double adjust = target/f;
556 if(adjust>(1+change_max)) adjust = 1+
change_max;
557 else if(adjust<1/(1+change_max)) adjust = 1/(1+
change_max);
560 model.effort_set(effort_);
589 double precision = 0.2;
614 double change_max = 0.3;
624 template<
class Mirror>
627 .data(precision,
"precision")
628 .data(responsiveness,
"responsiveness")
629 .data(multiplier,
"multiplier")
630 .data(threshold,
"threshold")
632 .data(change_max,
"change_max")
633 .data(maximum,
"maximum")
637 void read(std::istream& stream){
648 void write(std::ostream& stream){
652 <<responsiveness<<
"\t" 657 <<maximum<<
"\t\t\t\n";
660 virtual void reset(uint time, Model& model){
665 virtual void operate(uint time, Model& model){
666 int quarter = IOSKJ::quarter(time);
670 GeometricMean combined;
671 combined.append(model.cpue(WE,PS));
672 combined.append(model.cpue(MA,PL));
673 double cpue = combined;
676 cpue *= imprecision.random();
678 if(index_==-1) index_ = cpue;
682 if(index_<limit) rate = 0;
684 else rate = multiplier/(threshold-
limit)*(index_-limit);
686 double tac = std::min(rate*cpue,maximum);
689 double change = tac/last_;
691 if(change>max) change = max;
692 else if(change<1/max) change = 1/max;
697 model.catches_set(tac*1000/4);
766 for(
double imax=0.5; imax<=1.5; imax+=0.1){
769 proc.tag =
"ref*imax";
772 for(
double thresh=0.2; thresh<=1; thresh+=0.1){
774 proc.thresh = thresh;
775 proc.tag =
"ref*thresh";
778 for(
double closure=0; closure<=0.4; closure+=0.1){
780 proc.closure = closure;
781 proc.tag =
"ref*closure";
784 for(
double dmax=0.1; dmax<=1.0; dmax+=0.1){
787 proc.tag =
"ref*dmax";
792 for(
auto frequency : {3}){
793 for(
auto precision : {0.1}){
794 for(
auto imax : {0.9, 1.0, 1.1}){
795 for(
auto thresh : {0.3, 0.4, 0.5}){
796 for(
auto closure : {0.0, 0.1, 0.2}){
797 for(
auto cmax : {700000, 800000, 900000}){
800 proc.precision = precision;
801 proc.thresh = thresh;
802 proc.closure = closure;
814 for(
double catches=100; catches<=1000; catches+=100){
816 proc.
tac = catches*1000;
821 for(
double effort=50; effort<=600; effort+=10){
829 auto& proc = *
new BRule;
831 proc.precision = 0.2;
837 for(
int frequency : {2}){
838 for(
double precision : {0.2}){
839 for(
auto target : {0.2,0.25,0.3}){
840 for(
auto thresh : {0.4,0.5}){
841 for(
auto limit : {0.1,0.2}){
842 auto& proc = *
new BRule;
844 proc.precision = precision;
845 proc.target = target;
846 proc.thresh = thresh;
857 auto& proc = *
new FRange;
859 proc.precision = 0.1;
862 proc.change_max = 0.3;
865 for(
int frequency : {5,7}){
866 for(
double precision : {0.2}){
867 for(
auto target : {0.2,0.25,0.3}){
868 for(
auto buffer : {0.02,0.05}){
869 auto& proc = *
new FRange;
871 proc.precision = precision;
872 proc.target = target;
873 proc.buffer = buffer;
874 proc.change_max = 0.4;
883 auto& proc = *
new IRate;
885 proc.multiplier = 100000;
886 proc.threshold = 0.4;
888 proc.change_max = 0.3;
891 for(
double responsiveness : {0.5}){
892 for(
double multiplier : {100000,120000,140000}){
893 for(
auto threshold : {0.4, 0.5, 0.6}){
894 for(
auto limit : {0.1,0.2}){
895 auto& proc = *
new IRate;
897 proc.multiplier = multiplier;
898 proc.threshold = threshold;
900 proc.change_max = 0.4;
909 void reset(
int procedure, uint time,
Model& model){
910 operator[](procedure)->reset(time,model);
913 void operate(
int procedure, uint time,
Model& model){
914 operator[](procedure)->operate(time,model);
917 void read(
const std::string& path =
"procedures/input/procedures.tsv"){
918 std::ifstream file(path);
920 std::getline(file,line);
921 while(std::getline(file,line)){
922 std::istringstream stream(line);
925 if(clas==
"HistCatch"){
928 }
else if(clas==
"ConstCatch"){
932 }
else if(clas==
"BRule"){
933 auto proc =
new BRule;
936 }
else if(clas==
"IRate"){
937 auto proc =
new IRate;
941 throw std::runtime_error(
"Unknown procedure class: "+clas);
946 void write(
const std::string& path =
"procedures/output/procedures.tsv"){
947 std::ofstream file(path);
948 file<<
"procedure\tclass\tp1\tp2\tp3\tp4\tp5\tp6\tp7\tp8\tp9\tp10\n";
952 procedure->write(file);
double tac
Definition: procedures.hpp:137
virtual void reset(uint time, Model &model)
Definition: procedures.hpp:297
Array< double, Region > biomass_spawners
Definition: model.hpp:29
Definition: procedures.hpp:91
int lag
Definition: procedures.hpp:244
double dmax
Definition: procedures.hpp:224
Definition: procedures.hpp:73
Definition: procedures.hpp:162
double target
Definition: procedures.hpp:405
double push_pop(double current)
Definition: procedures.hpp:59
double responsiveness
Definition: procedures.hpp:594
Array< double, Region > biomass_spawners_unfished
Definition: model.hpp:37
virtual void operate(uint time, Model &model)
Definition: procedures.hpp:309
double precision
Definition: procedures.hpp:400
void read(std::istream &stream)
Definition: procedures.hpp:266
Definition: dimensions.hpp:22
Definition: procedures.hpp:195
double tae
Definition: procedures.hpp:170
void catches_set(double catches_, double error=0.2)
Definition: model.hpp:493
Definition: procedures.hpp:42
double buffer
Definition: procedures.hpp:506
void write(std::ostream &stream)
Definition: procedures.hpp:280
Definition: procedures.hpp:715
void reflect(Mirror &mirror)
Definition: procedures.hpp:251
Definition: procedures.hpp:583
int frequency
Definition: procedures.hpp:491
int frequency
Definition: procedures.hpp:204
double closure
Definition: procedures.hpp:234
Definition: procedures.hpp:389
void reflect(Mirror &mirror)
Definition: procedures.hpp:421
int frequency
Definition: procedures.hpp:395
Definition: procedures.hpp:128
double thresh
Definition: procedures.hpp:229
double limit
Definition: procedures.hpp:609
Definition: procedures.hpp:13
void set(int lag)
Definition: procedures.hpp:48
double e_40
Definition: model.hpp:367
double maximum
Definition: procedures.hpp:619
double cmax
Definition: procedures.hpp:219
void reflect(Mirror &mirror)
Definition: procedures.hpp:518
double threshold
Definition: procedures.hpp:604
Definition: procedures.hpp:485
double limit
Definition: procedures.hpp:415
double change_max
Definition: procedures.hpp:614
double target
Definition: procedures.hpp:501
Array< double, Region, Method > catches
Definition: model.hpp:313
double change_max
Definition: procedures.hpp:512
double multiplier
Definition: procedures.hpp:599
double imax
Definition: procedures.hpp:214
Definition: distributions.hpp:262
double precision
Definition: procedures.hpp:209
double thresh
Definition: procedures.hpp:410
std::string tag
Definition: procedures.hpp:239
void reflect(Mirror &mirror)
Definition: procedures.hpp:625