PKϐO
codemeta.json{"@context": "http://schema.org", "@type": "SoftwareSourceCode", "isPartOf": {"@type": "WebApplication", "applicationCategory": "Computational Modeling Software Repository", "operatingSystem": "Any", "name": "CoMSES Model Library", "url": "https://www.comses.net/codebases"}, "publisher": {"@id": "https://www.comses.net", "@type": "Organization", "name": "CoMSES Net", "url": "https://www.comses.net"}, "provider": {"@id": "https://www.comses.net", "@type": "Organization", "name": "CoMSES Net", "url": "https://www.comses.net"}, "name": "A Pastoral Stoking Strategy Model with Fodder Import and Loan Scenarios", "description": "This model was built to estimate the impacts of exogenous fodder input and credit loans services on livelihood, rangeland health and profits of pastoral production in a small holder pastoral household in the arid steppe rangeland of Inner Mongolia, China. The model simulated the long-term dynamic of herd size and structure, the forage demand and supply, the cash flow, and the situation of loan debt under three different stocking strategies: (1) No external fodder input, (2) fodders were only imported when natural disaster occurred, and (3) frequent import of external fodder, with different amount of available credit loans. Monte-Carlo method was used to address the influence of climate variability. ", "version": "1.0.0", "targetProduct": {"@type": "SoftwareApplication", "operatingSystem": "windows", "applicationCategory": "Computational Model", "downloadUrl": "https://www.comses.net/codebases/2c34b392-54ba-40ef-9a63-4f7d1f43c625/releases/1.0.0/download/", "releaseNotes": "To use this model you need to upload the code files in MatLab, define the parameters, and run the main program (the run_final document). More detailed instruction is provided in the description document. If you need to use it in other parts, you have to modify the code.", "softwareVersion": "1.0.0", "identifier": "https://www.comses.net/codebases/2c34b392-54ba-40ef-9a63-4f7d1f43c625/releases/1.0.0/", "sameAs": "https://www.comses.net/codebases/2c34b392-54ba-40ef-9a63-4f7d1f43c625/releases/1.0.0/"}, "programmingLanguage": [{"@type": "ComputerLanguage", "name": "MatLab"}], "author": [{"@type": "Person", "givenName": "", "familyName": "", "email": "yblee@ynu.edu.cn"}], "identifier": "https://www.comses.net/codebases/2c34b392-54ba-40ef-9a63-4f7d1f43c625/releases/1.0.0/", "dateCreated": "2019-12-24T17:26:17.774783+00:00", "dateModified": "2019-12-24T18:04:44.868496+00:00", "keywords": ["pastoral systems", "pastoralism", "dryland", "climate variability", "Monte-Carlo method", "loan", "exogenous fodder input", "debt", "forage"], "runtimePlatform": ["MatLab"], "url": "https://www.comses.net/codebases/2c34b392-54ba-40ef-9a63-4f7d1f43c625/releases/1.0.0/", "datePublished": "2019-12-24", "citation": ", (2019, December 24). \"A Pastoral Stoking Strategy Model with Fodder Import and Loan Scenarios\" (Version 1.0.0). _CoMSES Computational Model Library_. Retrieved from: https://www.comses.net/codebases/2c34b392-54ba-40ef-9a63-4f7d1f43c625/releases/1.0.0/", "copyrightYear": 2019, "license": "http://www.gnu.org/licenses/gpl-3.0.html", "referencePublication": "https://doi.org/10.1890/07-0992.1", "releaseNotes": "To use this model you need to upload the code files in MatLab, define the parameters, and run the main program (the run_final document). More detailed instruction is provided in the description document. If you need to use it in other parts, you have to modify the code."}PKzOiG55
data/Data.txtData
Data are contained in the description document.PKUOÕ!docs/Description of the model.txtA Pastoral Stoking Strategy Model with Fodder Import and Loan Scenarios v1.0.0
Yanbo Li (Institute of International Rivers and Eco-Scurity,Yunnan University,China; College of Environmental Sciences and Engineering, Peking University,China)
Wenjun Li (College of Environmental Sciences and Engineering, Peking University,China)
contact: Yanbo Li yblee@ynu.edu.cn
Description of the model
1.BASIC INFORMATION
The model runs on Matlab platform. The codes were divided into two files. The function file contains the functions that will be used in the program. The program file contains the programing codes to run the model. The program is divided into several subprograms to make it clearer to read. The run_final is the main program; it recalls the other subprograms during its process.
2.PARAMETERS
The parameters that need to be input into the model include:
(1)Parameters about the model
year, the temporal scale of modeling, year=50 in this model.
runs, times of repeat when using the Monte-Carlo methods, runs=1000 in this model.
(2)Pasture related parameters
PRTA, a vector with 1 rows and 3 columns that records the area of pastures, including area of warm season pasture, area of cold season pasture, area of warm season pasture that could be used in cold season, from the 1st column to the 3rd columns. PRTA= [426,461, 426] in this model. from the 1st column to the 3rd columns.
PRTFUE, a vector with 1 rows and 3 columns that records forage utilization rate, forage reserve rate, ratio of standing forage after reduction of those covered by snow from the 1st column to the 3rd columns. PRTFUE= [0.8, 0.603, 0.8] in our study.
(3)Herd related parameters
PRTL, a vector with 1 row and 4 columns that records mortality in warm season in normal years, mortality in cold season in normal years, birth-survival rate in normal years, sickness rate of sheep in normal years, from the 1st column to the 3rd columns. PRTL= [ 0.0015, 0.0015 ,0.05, 0.917] in our study.
(4)Market related parameters
PLSROCK, a vector with 1 row and 8 columns that records prices of sheep in autumn. It includes price of old and sick sheep, male lamb, female lamb, 2-years ewe, 6-years ewe, 5-year ewe, 4-years ewe, and 3-year ewe, respectively from the 1st column to the 8th columns. PLSROCK= [310,200,200,310,310,310,310,310] in our study.
PLSROCK2, a vector records the price of different category of sheep in summer. PLSROCKS= PLSROCK*0.5
PLSROCK3, restructure PLSROCK as the pattern price of male lamb, female lamb, 2-years ewe, 3-year ewe, 4-years ewe, 5-year ewe, 6-years ewe, and 7-year ewe. PLSROCK= [200,200,310,310,310,310,310,310] in our study.
COL, a vector with 1 row and 2 columns that records the annual living expenditures (CNY per year) and ceiling of annual savings (CNY). COL= [16875, 20000] in our study.
COP1, a vector with 1 row and 8 columns that records the costs of production except for forage costs. It includes labor cost (Yuan per person), costs of maintaince1 (Yuan per 1300 sheep), costs of maintaince2 (Yuan per sheep), Costs of energy (Yuan per sheep), Costs of vet (Yuan per sheep), interests of normal loan, depreciation 1(Yuan per year), depreciation 2(Yuan per sheep), and interests of high-interest-loan, respectively from the 1st column to the 8th columns.
COP1= [10000, 1000, 6.672, 2.206, 0.01, 3124, 4.226, 0.02] in our study.
DebtQuota, the highest amount of available normal loan. DebtQuota varied from 0 to 50000 Yuan in our study.
(5) Initialization
INITIAL, a vector with 1 row and 8 columns that records the initial saving, and herd number and structure to be inputted in the model. It includes savings, total number of sheep, number of male lamb, number of female lamb, number of 1-year ewe number of 6 year ewe. INITIAL=[20000,618, 140,140,40,56,50,60,71,60] in our study.
3.SEVERAL IMPORTANT VECTORS USED IN THE MODEL
STOCKDYN, a cell array with T row and 8 columns that records the dynamics of herd size and structure. It includes t, herd structure in warm season, herd structure in cold season, herd size at the beginning of warm season, herd size at the beginning of cold season, number of sheep sold in summer, herd structure died in winter, and herd structure at the end of cold season, from the 1st column to the 8th columns. Herd structure is stored in a vector with 1 row and 8 columns, including number of male lamb, female lamb, 2-years ewe, 3-year ewe, 4-years ewe, 5-year ewe, 6-years ewe, and 7-year ewe, from the 1st column to the 8th columns.
FORAGEDYN, a vector with 1 row and 8 columns that records the forage related dynamics. It includes t, forage production on warm season pasture, usable forage in warm season, gap of forage in warm season, remaining forage on warm season pasture, usable forage in cold season, de facto consumption of forage in cold season, de facto usable forage in cold season (reduced the forage covered by snow disaster), amount of imported forage in autumn, amount of imported forage in winter, hay left at the end of cold season, and grazing intensity on warm season pasture, from the 1st column to the 13rd columns.
MONEYDYN, a vector with 1 row and 11 columns that records cash flow related information. It includes ratio of number sheep sold due to lack of forage to the total number of sheep sold, income, costs in transhumance in warm season, total production costs without forage costs, forage costs in autumn, forage costs in winter, total production costs, living expenditures, cash for next year, value of herd, net income, and profits, from the 1st column to the 11th columns.
DEBAT, a vector with 1 row and 7 columns that records loan related information. It includes quarto of normal loan, the highest amount of available high-interest-loan, loan borrowed in warm season, loan borrowed in autumn, loan borrowed in winter, interests of normal loan, and interests of high-interests-loan, from the 1st column to the 7th columns.
4.PROCEDURES OF RUNNING THE MODEL
The following procedures are suggested.
(1) Upload the code files.
(2) Define the parameters motioned above.
(3) Run the climate_rand document to generate necessary climate parameters to apply the Monte-Carlo method.
(4) Run the main program ( the run_final document).
(5) Obtain the outputs. The outputs will be recorded in three cell arrays: OUTPUT_v1 (No external fodder input), OUTPUT_v2 (import fodders only imported when natural disaster occurred), and OUTPUT_v3 (frequent import of fodders). Each cell array contains four vectors: indictors to estimate the impacts of fodder input and credit loans ( in the first line of cells, including duration of pastoral production, frequency of overgrazing using grazing intensity of 0.5 as threshold, frequency of overgrazing using grazing intensity of 0.7 as threshold, and accumulated profits) ; detailed information of herd dynamics ( cells in line two), forage dynamic(cells in line three), cash flow(cells in line four) , and loans (cells in line five) in each run.
PKOocode/functions/ldeath_w.mfunction [ LS ] = ldeath_w( A,r )
% ldeath_w calculates the herd structure after mortality in warm season.
% input variables
% A, vector of herd structure before mortality.
% r, mortality
%Output variables
% LS, vector of herd structure after mortality.
nt=sum(A);
nd=round(nt*r);
L=find(A>0);%identify the colums with livestock
nc=length(L);%calculate the number of colums with livestock
n1=fix(nd/nc);
n2=nd-n1*nc;
LS=zeros(size(A));
LS(1,:)=A(1,:)-n1;
if n2>0
A3=randi([1,8],1,n2);
for i=1:n2;
j=A3(1,i);
LS(1,j)=LS(1,j)-1;
end
end
L2=find(LS<0);
l2=length(L2);
for i=1:l2;
j=L2(1,i);
LS(1,j)=0;
end
endPKOZ]code/functions/ssold3.mfunction [psbcc,inc2,STOCKC] = ssold3( A,P1,p2,c,fl,r)
% ssold3 calculates number and structure of sheep sold under the strategy of frequent import of fodder. Import of fodder is allowed. No additional restriction on herd size.
%%input variables
% A herd structure at end of cold season.
% P1vector of sheep price by category ( old and sick, male lamb, female lamb, 2-year-old ewe, 6-year-old ewe, 5-year-old ewe, 4-year-old ewe, 3-year-old ewe
% p2 price of fodder
% c, total expenditures except for fodder costs, including living expenditures, and production costs except for fodder costs.
% fl, current forage supply
% r, rate of sickness
% Output variables
% psbcc, number of sheep sold due to forage deficiency/ total number of sheep sold
% inc2, income for sheep sale
% STOCKC, herd structure after sell
% Yanbo Li 2013-10-31
[ ~,ILD,CN,~] = lhfs( A,r);
%% number of sheep to be sold based on expenditures
INCC=CN.*P1;
TINC=zeros(1,8);
TINC(1,1)=INCC(1,1);
for i=2:8
TINC(1,i)=TINC(1,i-1)+INCC(1,i);
end
GOI=TINC-c;% GOI gap of income
i=length(find(GOI<0));%to identify the last group of sheep to be sold.
SCN1=zeros(1,8);
if i>0
if i==8
SCN1(1,1:i)=CN(1,1:i);
else
SCN1(1,1:i)=CN(1,1:i);
SCN1(1,i+1)=ceil((0-GOI(1,i))/P1(1,i+1));
end
end
SCN1(1,1:2)= CN(1,1:2);%sale all old, sick and male lamb
nm=sum(SCN1);
save=sum(SCN1.*P1)-c;
STOCK=CN-SCN1;
%% identify the number of sheep to sell based on forage supply and demand
FDC=STOCK*2*205; %FDC forage demand by catagory. number of sheep could be supported by current forage supply. daily intake =2 kg/ day, duration of cold season = 205 days.
gof=sum(FDC)-fl-save/p2;
INCC2=STOCK.*P1;
SCN2=zeros(1,8);
if gof>0 %current income not enough to buy fodder, need to sell more sheep
i=3; %start to sale female lamb
while i<9
sale=ceil(gof*p2/(P1(1,i)+p2*2*205));
if sale>STOCK(1,i);
SCN2(1,i)=STOCK(1,i);
gof=gof-FDC(1,i)-INCC2(1,i)/gof;
i=i+1;
else
SCN2(1,i)=sale;
break
end
end
end
SCN=SCN1+SCN2;
%% decide off-take in each group
SHDH=zeros(1,8);
SHDH(1,1)=SCN(1,2);%number of male lamb sold.
SHDH(1,2)=SCN(1,3);%number of female lamb sold.
SHDH(1,3)=SCN(1,4);%number of 2-years old ewe sold.
SHDH(1,4)=SCN(1,8);%number of 3-years old ewe sold.
SHDH(1,5)=SCN(1,7);%number of 4-years old ewe sold.
SHDH(1,6)=SCN(1,6);%number of 5-years old ewe sold.
SHDH(1,7)=SCN(1,5);%number of 6-years old ewe sold.
SHD=ILD+SHDH;%final structure of sheep that will be sold.
STOCKC=A-SHD;
inc2=sum(SCN.*P1);
nos=sum(SCN);
psbcc=(nos-nm)/nos;
if any(STOCKC<0)
warning('error in off-take, number of sell surpasses number of sheep')
end
endPKOF&code/functions/ssold_summer.mfunction [STOCKC,inc,com,nos] = ssold_summer( A,P3,p4,save,gof)
% ssold_summer caculates livestock number and structure sold in summer for transhumance costs.
% input variables
% Aherd structure.
% P3vector of prices for each type of sheep( old and sick, male lamb, female lamb, 2-year-old ewe, 6-year-old ewe, 5-year-old ewe, 4-year-old ewe, 3-year-old ewe
% p4, costs of transhumance
% save, avaible money in summer
% gof, gap of forage in summer
% Output variables
% STOCKC, herd structure after transhumance
% inc, income from livestock sell in summer
% com, costs of movement
% nos, number of livestock sold.
% Yanbo Li 2013-11-25
[ ~,~,CN,~] = lhfs( A,0 );
if save>=gof*p4 %no need of selling if savings are enough to move livestock
com=gof*p4;
STOCKC=A;
inc=0;
nos=0;
else
gof=gof-save/p4;
INCC=CN.*P3;%possible income for each type of livestock
SCN=zeros(1,8);
i=1;
while i<9
sale=ceil(gof*p4/(P3(1,i)+p4*2*160));
if sale>CN(1,i);
SCN(1,i)=CN(1,i);
gof=gof-CN(1,i)*2*160-INCC(1,i)/p4;%
i=i+1;
else
SCN(1,i)=sale;
break
end
end
SHDH=zeros(1,8);
SHDH(1,1)=SCN(1,2);%number of male lamb sold.
SHDH(1,2)=SCN(1,3);%number of female lamb sold.
SHDH(1,3)=SCN(1,4);%number of 2-years old ewe sold.
SHDH(1,4)=SCN(1,8);%number of 3-years old ewe sold.
SHDH(1,5)=SCN(1,7);%number of 4-years old ewe sold.
SHDH(1,6)=SCN(1,6);%number of 5-years old ewe sold.
SHDH(1,7)=SCN(1,5);%number of 6-years old ewe sold.
SHDH(1,8)=SCN(1,1);%number of 7-years old ewe sold.
STOCKC=A-SHDH;
inc=sum(SCN.*P3);
com=inc+save;
nos=sum(SHDH);
end
endPKOzO
code/functions/ssold5.mfunction [psbcc,inc2,STOCKC] = ssold5( A,P1,p2,c,fl,prel,r)
% ssold5 calculates number and structure of sheep sold under the strategy of import fodder only in disaster years. Import of fodders is allowed in disaster years under the condition that the number of breeding ewe does not increase than in the previous year.
% Procedures: (1) sell old and sick sheep; (2) sell additional (potential) sheep according to demand for cash; (3) to meet the condition that the number of breeding ewe do not increase than in the previous year.(4) sell additional (potential ) sheep according to demand and supply of forage
%%input variables
% A herd structure at end of cold season.
% P1vector of sheep price by category ( old and sick, male lamb, female lamb, 2-year-old ewe, 6-year-old ewe, 5-year-old ewe, 4-year-old ewe, 3-year-old ewe
% p2 price of fodder
% c, total expenditures except for fodder costs, including living expenditures, and production costs except for fodder costs.
% fl, current forage supply
% prelherd size in the previous year
% r, rate of sickness
% Output variables
% psbcc, number of sheep sold due to forage deficiency/ total number of sheep sold
% inc2, income for sheep sale
% STOCKC, herd structure after sell
% Yanbo Li 2013-10-31
[ ~,ILD,CN,~] = lhfs( A,r);
%% number of sheep to be sold based on expenditures
INCC=CN.*P1;
TINC=zeros(1,8);
TINC(1,1)=INCC(1,1);
for i=2:8
TINC(1,i)=TINC(1,i-1)+INCC(1,i);
end
GOI=TINC-c;% GOI gap of income
i=length(find(GOI<0));%to identify the last group of sheep to be sold.
SCN1=zeros(1,8);
if i>0
if i==8
SCN1(1,1:i)=CN(1,1:i);
else
SCN1(1,1:i)=CN(1,1:i);
SCN1(1,i+1)=ceil((0-GOI(1,i))/P1(1,i+1));
end
end
SCN1(1,1:2)= CN(1,1:2);
nm=sum(SCN1);
save=sum(SCN1.*P1)-c;
STOCK=CN-SCN1;
ns=sum(STOCK);
%Import of fodders under the condition that the number of breeding ewe does not increase than in the previous year.
SCN2=zeros(1,8);
if ns>prel %current herd size surpassed number of breeding ewe in previous year, need to sell more sheep
nos=ns-prel;
i=3; %start from female lamb
while i<9
if STOCK(1,i)<=nos-sum(SCN2)
SCN2(1,i)=STOCK(1,i);
i=i+1;
else
SCN2(1,i)=nos-sum(SCN2);
break
end
end
STOCK=STOCK-SCN2;
end
%% identify the number of sheep to sell based on forage supply and demand
FDC=STOCK*2*205; %FDC forage demand by catagory. number of sheep could be supported by current forage supply. daily intake =2 kg/ day, duration of cold season = 205 days.
gof=sum(FDC)-fl-save/p2;
INCC2=STOCK.*P1;
SCN3=zeros(1,8);
if gof>0 %current income not enough to buy fodder, need to sell more sheep
i=3;
while i<9
sale=ceil(gof*p2/(P1(1,i)+p2*2*205));
if sale>STOCK(1,i);
SCN3(1,i)=STOCK(1,i);
gof=gof-FDC(1,i)-INCC2(1,i)/gof;
i=i+1;
else
SCN3(1,i)=sale;
break
end
end
end
SCN=SCN1+SCN2+SCN3;
%% decide off-take in each group
SHDH=zeros(1,8);
SHDH(1,1)=SCN(1,2);%number of male lamb sold.
SHDH(1,2)=SCN(1,3);%number of female lamb sold.
SHDH(1,3)=SCN(1,4);%number of 2-years old ewe sold.
SHDH(1,4)=SCN(1,8);%number of 3-years old ewe sold.
SHDH(1,5)=SCN(1,7);%number of 4-years old ewe sold.
SHDH(1,6)=SCN(1,6);%number of 5-years old ewe sold.
SHDH(1,7)=SCN(1,5);%number of 6-years old ewe sold.
SHD=ILD+SHDH;%final structure of sheep that will be sold.
STOCKC=A-SHD;
inc2=sum(SCN.*P1);
nos=sum(SCN);
psbcc=(nos-nm)/nos;
if any(STOCKC<0)
warning('error in off-take, number of sell surpasses number of sheep')
end
endPKOqy^.
.
code/functions/ssold1.mfunction [psbcc,inc,STOCKC] = ssold1( A,P1,c,fl,r )
% ssold1 caculates number and structure of sheep sold under the strategy of no import of fodder.
%%input variables
% A herd structure at end of cold season.
% P1vector of sheep price by category ( old and sick, male lamb, female lamb, 2-year-old ewe, 6-year-old ewe, 5-year-old ewe, 4-year-old ewe, 3-year-old ewe
% c, total expenditures except for fodder costs, including living expenditures, and production costs except for fodder costs.
% fl, current forage supply
% r, rate of sickness
% Output variables
% psbcc, number of sheep sold due to forage deficiency/ total number of sheep sold
% inc, income for sheep sale
% STOCKC, herd structure after sell
% Yanbo Li 2013-10-31
[~, ILD,CN,TN] = lhfs( A,r );
z=size(TN);
nt=sum(sum(A));%total nuber of livestok
np= fix(fl/2/205);% number of sheep could be supported by current forage supply. daily intake =2 kg/ day, duration of cold season = 205 days.
INCC=CN.*P1;%potential income from selling all sheep by category.
TINC=zeros(z);
TINC(1,1)=INCC(1,1);
for i=2:8
TINC(1,i)=TINC(1,i-1)+INCC(1,i);
end
GOI=TINC-c;% GOI gap of income
i=length(find(GOI<0));%to identify the last group of sheep to be sold.
SCN=zeros(z);
if i>0
if i==8
SCN(1,1:i)=CN(1,1:i);
else
SCN(1,1:i)=CN(1,1:i);
SCN(1,i+1)=ceil((0-GOI(1,i))/P1(1,i+1));
end
end
SCN(1,1:2)= CN(1,1:2);
nm=sum(SCN);% number of sheep sold based on consideration of cash flow
% identify the number of sheep to sell based on forage supply and demand
if np>=nt-nm %more forage supply than demand
nos=nm;
else %more forage demand than supply, need to sell more sheep according to foage gap.
nos=nt-np;
end
CN2=CN-SCN;
i=i+1;
while i<9
if CN2(1,i)<=nos-sum(sum(SCN))
SCN(1,i)=SCN(1,i)+CN2(1,i);
i=i+1;
else SCN(1,i)=SCN(1,i)+nos-sum(sum(SCN));
break
end
end
SHDH=zeros(1,8);
SHDH(1,1)=SCN(1,2);%number of male lamb sold.
SHDH(1,2)=SCN(1,3);%number of female lamb sold.
SHDH(1,3)=SCN(1,4);%number of 2-years old ewe sold.
SHDH(1,4)=SCN(1,8);%number of 3-years old ewe sold.
SHDH(1,5)=SCN(1,7);%number of 4-years old ewe sold.
SHDH(1,6)=SCN(1,6);%number of 5-years old ewe sold.
SHDH(1,7)=SCN(1,5);%number of 6-years old ewe sold.
end
SHD=ILD+SHDH;%final structure of sheep that will be sold.
STOCKC=A-SHD;
inc=sum(SCN.*P1);
psbcc=(nos-nm)/nos;
if any(STOCKC<0)
warning('error in off-take, number of sell surpasses number of sheep')
end
endPKO:<ddcode/functions/ltransform_sp.mfunction [ L ] = ltransform_sp(A,r1,r2)
% ltransform_sp tranform of herd structure in spring
Input variables
% A, herd structure at beginning of cold season
% r1, mortality in cold season
% r2, birth-and-survival rate
Output variables
L, herd structure at beginning of warm season
% % Yanbo 2013-10-26
if any(A>0)==0;
L=A;
else
LA= ldeath_w( A,r1 );
nbf=sum(LA(1,4:8));%number of breeding ewe
nb=round(0.5*nbf*r2);%female lamb and male lamb
LB=nb;
LG=circshift(LA,[0,1]);%each type of sheep grow by one year
L=LG;
L(1,1)=LB;
L(1,2)=LB;
end
end
PKO24code/functions/floan.mfunction [debatt,debatn,debath ] = floan( saving,cost,quota1)
%FLOAN caculates the type and amount of loans.
%input variables
% saving, savings before borrowing loan. The modeled household is in debt already in saving is negative.
% cost, costs to be met.
% quota1highest amount of available normal loan.
%output variables
%debatt, amount of loan borrowed.
%debatnamount of normal loan borrowed.
%debath, amount of high-interest loan borrowed.
%
if cost==0 %no loan needed if cost is zero.
debatt=0;debatn=0;debath=0;
else
if saving>=cost
debatt=0;
debatn=0;
debath=0;
else
if saving>=0 %without old loan.
debatt=cost-saving;
if debatt>quota1 % normal loan could not meet the needs.
debatn=quota1;
debath=debatt-quota1;
else
debatn=debatt;
debath=0;
end
else %with old loan.
debatt=cost;
if debatt-saving>quota1 %total amount of loan surpassed the amount of available normal loan.
debath=debatt-saving-quota1;
debatn=quota1;%
else
debatn=debatt;
debath=0;
end
end
end
end
end
PKOcode/functions/lhfs.mfunction [ H,ILD,CN,TN] = lhfs( A,r )
% LHFS Livestock health for sale) establishes a vector of healthy livestock lined according to the priority of sell.
% it not related to stocking strategy, i.e. every stocking strategy will follow these rules.
Input variables
% A, vector of herd structure
% r, rate of sickness
output variables
% H, vector of healthy livestock.
%ILDvector of old and sick livestock
%CN, a vector of healty livestock lined according to pripority of sale. 1old and sick,2male lamb,3female lamb42-year-old ewe56-year-old ewe; (6) 5-year-old ewe, (7) 4-year-old ewe; (8)3-year-old ewe
% TNaccumulated sum of number of livestock
% Yanbo 2013-10-25
%(1) generate a vector of healthy livestock.
H=ldeath_w(A,r);
ill=A-H;
ILD=ill;
ILD(1,8)=A(1,8);
%(2) reorganize the healty livestock according to pripority of sale.
CN=zeros(1,8);
CN(1,1)=H(1,8)+sum(ill);
CN(1,2)=H(1,1);%male lamb
CN(1,3)=H(1,2);%female lamb
CN(1,4)=H(1,3);%2-year-old ewe
CN(1,5)=H(1,7);%6-year-old ewe
CN(1,6)=H(1,6);%5-year-old ewe
CN(1,7)=H(1,5);%4-year-old ewe
CN(1,8)=H(1,4);%3-year-old ewe
%(3) accumulated sum of number of livestock
TN=zeros(1,8);
for i=1:8
TN(1,i)=sum(CN(1,1:i));
end
end
PKO;ppcode/program/run_v1.m%% No Import of Fodder Strategy (the NIF strategy)
initialize_v1
for t=2:year
PFORGE=PFORAGES(t,:);
workprocess_v1
if STOCKDYN{t,5}==0
break
end
end
%%recording the cash dynamic, forage dynamic and herd dynamic, and debt conditions.
MONEYDYN_v1=MONEYDYN;
FORAGEDYN_v1=FORAGEDYN;
STOCKDYN_v1=STOCKDYN;
DEBAT_v1=DEBAT;
%% Statistic of the focal indicators: duration of production, frequency of over-grazing, accumulated profits
RESULT_v1=zeros(1,4)
ECO=zeros(year,2);
ECO(:,1)=FORAGEDYN(1:t,13)-0.5;% grazing intensity on warm-season-pasture
ECO(:,2)=FORAGEDYN(1:t,13)-0.7;
RESULT_v1(1,1)=t;%duration of production before bankruptcy
RESULT_v1(1,2)=length(find(ECO(1:t,1)>0))/year;% frequency of over-grazing years
RESULT_v1(1,3)=length(find(ECO(1:t,2)>0))/year;
RESULT_v1(1,4)=sum(MONEYDYN(:,12))/10000;%accumulated profits (units: 10000 CNY)
PKO/KNcode/program/initialize_v3.m%% initialization under the Frequent Import of Fodder Strategy (the FIF strategy)
FORAGEDYN=zeros(year,13);%vector to record forage dynamic.
MONEYDYN=zeros(year,12);%vector to record cash flow.
MONEYDYN(:,8)=COL(1,1);% living expendituresassumed to be fix in this study
STOCKDYN=cell(year,8);
STOCKDYN{1,2}=INITIAL(1, 3:10) ;
DEBAT=zeros(year,7);
DEBAT(:,1)= DebtQuato;%highest amount of available normal loan,assumed to be fix in this study
t=1;
PFORGE=PFORAGES(t,:);
L=STOCKDYN {t,2};
%% forage supply on warm-season pasture
Fwt1=BP(t,1)*PRTA(1,1);
Fwt2=Fwt1*PRTFUE(1,1);
FORAGEDYN(t,2)=Fwt1;
FORAGEDYN(t,3)=Fwt2;
%%transhumance in warm season
intake=sum(sum(L))*2*160;% daily intake=2 kg/ per sheep, duration of warm season=160 days.
gof=intake-Fwt2;
saving=INITIAL(1,1);% available cash
if gof<=0
FORAGEDYN(t,4)=intake;
FORAGEDYN(t,5)=0;
FORAGEDYN(t,6)=(Fwt2-intake)/PRTA(1,1);
STOCKW=L;
STOCKDYN{t,6}=0;
inc=0;
com=0;
nos=0;
else
FORAGEDYN(t,4)=Fwt2;
FORAGEDYN(t,5)=gof;
FORAGEDYN(t,6)=0;
avm=DEBAT(t,1)+DEBAT(t,2)+saving;
[STOCKW,inc,com,nos] = ssold_summer(L,PLSTOCK2,PFORGE(1,3),avm,gof); %cash is not enough, need to sell livestock at low price
end
MONEYDYN(t,3)=com;
STOCKDYN{t,6}=nos;
[debatt,debatn,debath ]=floan(saving,com-inc,DEBAT(t,1));
DEBAT(t,3)=debatt;
DEBAT(t,7)=debath*2*COP1(1,8)+DEBAT(t,7);
DEBAT(t,6)=debatn*2*COP1(1,5)+DEBAT(t,6);%debt in summer will be paid in autumn, interests of 2 months.
FORAGEDYN(t,13)=(intake-FORAGEDYN(t,5))/Fwt1; %grazing intensity
%% estimation of available forage in cold season
fl1=FORAGEDYN(t,6)*PRTA(1,3)*PRTFUE(1,2);% residuals on warmseason pasture*reserve rate
fl2=BP(t,1)*PRTA(1,2)*PRTFUE(1,2)*PRTFUE(1,1); % primpary production on cold season pasture*reserve rate*ultilization rate
FORAGEDYN(t,7)=(fl1+fl2)*PRTFUE(1,3);
%%dynamic of herd size and structure in warm season
A =ldeath_w( STOCKW,PRTL(1,1) );
nol=sum(sum(L));
% Decision process on livestock selling in autumn
MONEYDYN(t,4)=(ceil(nol/1300)-1)*COP1(1,1)+(ceil(nol/1300))*COP1(1,2)+nol*(COP1(1,3)+COP1(1,4)+COP1(1,7))+COP1(1,6)+DEBAT(t,6)+DEBAT(t,7);
c=MONEYDYN(t,4)+MONEYDYN(t,8)+MONEYDYN(t,3)-inc- INITIAL(1,1)-DEBAT(t,1);%target of income= living expenditures+other production costs+costs of movement in summer-income from livestock in summer-savings
[pscc,inc2,STOCKC] = ssold3( A,PLSTOCK,PFORGE(1,1),c,FORAGEDYN(t,7),PRTL(1,3));%stocking decision under the FIF strategy
STOCKDYN {t,3}=STOCKC;
STOCKDYN {t,5}=sum(STOCKC);
MONEYDYN(t,1)=pscc;
%% forage import in autumn
FORAGEDYN(t,8)=sum(sum(STOCKC))*205*2;
if FORAGEDYN(t,8)>FORAGEDYN(t,7);
FORAGEDYN(t,10)=FORAGEDYN(t,8)-FORAGEDYN(t,7);
MONEYDYN(t,5)= FORAGEDYN(t,10)* PFORGE(1,1);
end
%%incomes and costs in autumn
MONEYDYN(t,2)=inc2+inc;
MONEYDYN(t,7)=MONEYDYN(t,3)+MONEYDYN(t,4)+MONEYDYN(t,5);
MONEYDYN(t,9)=MONEYDYN(t,2)-MONEYDYN(t,8)-MONEYDYN(t,7)+INITIAL(1,1);
saving=MONEYDYN(t,9);
if MONEYDYN(t,9)<0
DEBAT(t,4)=0-MONEYDYN(t,9);%debt in autumn
else
DEBAT(t,4)=0;
end
DEBAT(t+1,6)=DEBAT(t,4)*COP1(1,5)*12;%interests to be paid next year
%% forage-herd-cash flow dynamic in winter
FORAGEDYN(t,9)=FORAGEDYN(t,10)+fl1*(1-SND(t,3))+fl2*(1-SND(t,4));
gof=FORAGEDYN(t,8)-FORAGEDYN(t,9);
A=STOCKC;
STOCKDYN{t,7}=0;
if gof>0
avm=MONEYDYN(t,9)+ DEBAT(t,1)+ DEBAT(t,2);
if avm>0
avf= avm/PFORGE(1,2);
gof2=(gof-avf)/FORAGEDYN(t,8);
if gof2>0
LC = ldeath_w( A,gof2);
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=avf;
MONEYDYN(t,6)=avm;
else
FORAGEDYN(t,11)=gof;
MONEYDYN(t,6)= gof*PFORGE(1,2);
LC=STOCKDYN {t,3};
end
else
[ LC ] = ldeath_w( A,gof/FORAGEDYN(t,8));
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
end
FORAGEDYN(t,12)=0;
else
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
LC=STOCKDYN {t,3};
if FORAGEDYN(t,8)<=fl1*(1-SND(t,3))+fl2*(1-SND(t,4))
FORAGEDYN(t,12)=FORAGEDYN(t,10);
else
FORAGEDYN(t,12)=FORAGEDYN(t,9)-FORAGEDYN(t,8);
end
end
STOCKDYN {t,8}=LC;
[debatt,debatn,debath ]=floan(saving,MONEYDYN(t,6),DEBAT(t,1));
DEBAT(t,5)=debatt;
if t==year
DEBAT(1,6)=debatn*8*COP1(1,5)+DEBAT(1,6);
DEBAT(1,7)=debath*8*COP1(1,8)+DEBAT(1,7);
else
DEBAT(t+1,6)=debatn*8*COP1(1,5)+DEBAT(t+1,6);
DEBAT(t+1,7)=debath*8*COP1(1,8)+DEBAT(t+1,7);
end
%% final income and expenditures
MONEYDYN(t,7)=MONEYDYN(t,7)+MONEYDYN(t,6);
MONEYDYN(t,11)=MONEYDYN(t,2)-MONEYDYN(t,7);
MONEYDYN(t,9)=MONEYDYN(t,9)-MONEYDYN(t,6);
if MONEYDYN(t,9)>COL(1,2)
MONEYDYN(t,9)=COL(1,2);
end
LV0=L.*PLSTOCK3;%value of initial herd by group
LV0(1,1:2)=0;
%% herd dynamic between cold season and next warm season
[ L ] = ltransform_sp(LC,PRTL(1,2),PRTL(1,4));
if t0;%more forage demand than supply, livestock died proportionally to the gap of forage
deathrate=gof;
LC=ldeath_w( A,deathrate);%livestock survive to warm season
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
else
LC=STOCKDYN {t,3};
end
FORAGEDYN(t,11)=0;
FORAGEDYN(t,12)=0;%no forage left to the next year
MONEYDYN(t,6)=0;
STOCKDYN {t,8}=LC;
%% final income and expenditures
MONEYDYN(t,7)=MONEYDYN(t,3)+MONEYDYN(t,4);
MONEYDYN(t,11)=MONEYDYN(t,2)-MONEYDYN(t,7);%net income= total income-total costs
MONEYDYN(t,9)=MONEYDYN(t,11)-MONEYDYN(t,8)+INITIAL(1,1); %usable cash in next year=net income-living expenditures+savings from the previous year.
if MONEYDYN(t,9)<0
DEBAT(t,4)=0-MONEYDYN(t,9);
else
DEBAT(t,4)=0;
end
DEBAT(t+1,6)=DEBAT(t,4)*COP1(1,5)*12;
if MONEYDYN(t,9)>COL(1,2)
MONEYDYN(t,9)=COL(1,2);
end
LV0=L.*PLSTOCK3;%value of initial herd by group
LV0(1,1:2)=0;
%% herd dynamic between cold season and next warm season
[ L ] = ltransform_sp(LC,PRTL(1,2),PRTL(1,4));
STOCKDYN {t+1,2}=L;
STOCKDYN {t+1,4}=sum(sum(L));
% Profits
MONEYDYN(t,10)=sum(L.*PLSTOCK3);%value of herd at end of year
MONEYDYN(t,12)= MONEYDYN(t,11)+ MONEYDYN(t,10)-sum(LV0); % profits at end of year
PKOv%`Wcode/program/run_v2.m%% Import Fodder only in Disaster Years Strategy (the IFDY strategy)
initialize_v2
for t=2:year
PFORGE=PFORAGES(t,:);
workprocess_v2
if STOCKDYN{t,5}==0
break
end
end
MONEYDYN_v2=MONEYDYN;
FORAGEDYN_v2=FORAGEDYN;
STOCKDYN_v2=STOCKDYN;
DEBAT_v2=DEBAT;
%%recording the cash dynamic, forage dynamic and herd dynamic, and debt conditions.
RESULT_v2=zeros(1,4)
ECO=zeros(year,2);
ECO(:,1)=FORAGEDYN(1:t,13)-0.5;% grazing intensity on warm-season-pasture
ECO(:,2)=FORAGEDYN(1:t,13)-0.7;
RESULT_v2(1,1)=t;%duration of production before bankruptcy
RESULT_v2(1,2)=length(find(ECO(1:t,1)>0))/year;% frequency of over-grazing years
RESULT_v2(1,3)=length(find(ECO(1:t,2)>0))/year;
RESULT_v2(1,4)=sum(MONEYDYN(:,12))/10000;% accumulated profits (units: 10000 CNY)PKO
%code/program/workprocess_v3.m%%the Frequent Import of Fodder Strategy (the FIF strategy)
L=STOCKDYN {t,2};
%% forage supply on warm-season pasture
Fwt1=BP(t,1)*PRTA(1,1);
Fwt2=Fwt1*PRTFUE(1,1);
FORAGEDYN(t,2)=Fwt1;
FORAGEDYN(t,3)=Fwt2;
%%transhumance in warm season
intake=sum(sum(L))*2*160;
gof=intake-Fwt2;
saving=MONEYDYN(t-1,9);
if gof<=0
FORAGEDYN(t,4)=intake;
FORAGEDYN(t,5)=0;
FORAGEDYN(t,6)=(Fwt2-intake)/PRTA(1,1);
STOCKW=L;
STOCKDYN{t,6}=0;
inc=0;
com=0;
nos=0;
else
FORAGEDYN(t,4)=Fwt2;
FORAGEDYN(t,5)=gof;
FORAGEDYN(t,6)=0;
avm=DEBAT(t,1)+DEBAT(t,2)+saving;
[STOCKW,inc,com,nos] = ssold_summer(L,PLSTOCK2,PFORGE(1,3),avm,gof);
end
MONEYDYN(t,3)=com;
STOCKDYN{t,6}=nos;
[debatt,debatn,debath ]=floan(saving,com-inc,DEBAT(t,1));
DEBAT(t,3)=debatt;
DEBAT(t,7)=debath*2*COP1(1,8)+DEBAT(t,7);
DEBAT(t,6)=debatn*2*COP1(1,5)+DEBAT(t,6);
FORAGEDYN(t,13)=(intake-FORAGEDYN(t,5))/Fwt1;
%% estimation of available forage in cold season
fl1=FORAGEDYN(t,6)*PRTA(1,3)*PRTFUE(1,2);
fl2=BP(t,1)*PRTA(1,2)*PRTFUE(1,2)*PRTFUE(1,1);
FORAGEDYN(t,7)=(fl1+fl2)*PRTFUE(1,3);
%%dynamic of herd size and structure in warm season
A =ldeath_w( STOCKW,PRTL(1,1) );
nol=sum(sum(L));
% Decision process on livestock selling in autumn
MONEYDYN(t,4)=(ceil(nol/1300)-1)*COP1(1,1)+(ceil(nol/1300))*COP1(1,2)+nol*(COP1(1,3)+COP1(1,4)+COP1(1,7))+COP1(1,6)+DEBAT(t,6)+DEBAT(t,7);
c=MONEYDYN(t,4)+MONEYDYN(t,8)+MONEYDYN(t,3)-inc-MONEYDYN(t-1,9)-DEBAT(t,1);%target of income
[pscc,inc2,STOCKC] = ssold3( A,PLSTOCK,PFORGE(1,1),c,FORAGEDYN(t,7),PRTL(1,3));%stocking decision under the FIF strategy
STOCKDYN {t,3}=STOCKC;
STOCKDYN {t,5}=sum(STOCKC);
MONEYDYN(t,1)=pscc;
%% forage import in autumn
FORAGEDYN(t,8)=sum(sum(STOCKC))*205*2;
if FORAGEDYN(t,8)>FORAGEDYN(t,7);
FORAGEDYN(t,10)=FORAGEDYN(t,8)-FORAGEDYN(t,7);
MONEYDYN(t,5)= FORAGEDYN(t,10)* PFORGE(1,1);
end
%%incomes and costs in autumn
MONEYDYN(t,2)=inc2+inc;
MONEYDYN(t,7)=MONEYDYN(t,3)+MONEYDYN(t,4)+MONEYDYN(t,5);
MONEYDYN(t,9)=MONEYDYN(t,2)-MONEYDYN(t,8)-MONEYDYN(t,7)+MONEYDYN(t-1,9);
saving=MONEYDYN(t,9);
if MONEYDYN(t,9)<0
DEBAT(t,4)=0-MONEYDYN(t,9);
else
DEBAT(t,4)=0;
end
if t==year
DEBAT(1,6)=DEBAT(t,4)*COP1(1,5)*12+ DEBAT(1,6);%record the interests in the first year, otherwise it will be missed in anlysis
else
DEBAT(t+1,6)=DEBAT(t,4)*COP1(1,5)*12;
end
%% forage-herd-cash flow dynamic in winter
FORAGEDYN(t,9)=FORAGEDYN(t,10)+fl1*(1-SND(t,3))+fl2*(1-SND(t,4));
gof=FORAGEDYN(t,8)-FORAGEDYN(t,9);
A=STOCKC;
STOCKDYN{t,7}=0;
if gof>0
avm=MONEYDYN(t,9)+ DEBAT(t,1)+ DEBAT(t,2);
if avm>0
avf= avm/PFORGE(1,2);
gof2=(gof-avf)/FORAGEDYN(t,8);
if gof2>0
LC = ldeath_w( A,gof2);
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=avf;
MONEYDYN(t,6)=avm;
else
FORAGEDYN(t,11)=gof;
MONEYDYN(t,6)= gof*PFORGE(1,2);
LC=STOCKDYN {t,3};
end
else
[ LC ] = ldeath_w( A,gof/FORAGEDYN(t,8));
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
end
FORAGEDYN(t,12)=0;
else
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
LC=STOCKDYN {t,3};
if FORAGEDYN(t,8)<=fl1*(1-SND(t,3))+fl2*(1-SND(t,4))
FORAGEDYN(t,12)=FORAGEDYN(t,10);
else
FORAGEDYN(t,12)=FORAGEDYN(t,9)-FORAGEDYN(t,8);
end
end
STOCKDYN {t,8}=LC;
[debatt,debatn,debath ]=floan(saving,MONEYDYN(t,6),DEBAT(t,1));
DEBAT(t,5)=debatt;
if t==year
DEBAT(1,6)=debatn*8*COP1(1,5)+DEBAT(1,6);
DEBAT(1,7)=debath*8*COP1(1,8)+DEBAT(1,7);
else
DEBAT(t+1,6)=debatn*8*COP1(1,5)+DEBAT(t+1,6);
DEBAT(t+1,7)=debath*8*COP1(1,8)+DEBAT(t+1,7);
end
%% final income and expenditures
MONEYDYN(t,7)=MONEYDYN(t,7)+MONEYDYN(t,6);
MONEYDYN(t,11)=MONEYDYN(t,2)-MONEYDYN(t,7);
MONEYDYN(t,9)=MONEYDYN(t,9)-MONEYDYN(t,6);
if MONEYDYN(t,9)>COL(1,2)
MONEYDYN(t,9)=COL(1,2);
end
%% herd dynamic between cold season and next warm season
[ L ] = ltransform_sp(LC,PRTL(1,2),PRTL(1,4));
if tFORAGEDYN(t,7);
FORAGEDYN(t,10)=FORAGEDYN(t,8)-FORAGEDYN(t,7);
MONEYDYN(t,5)= FORAGEDYN(t,10)* PFORGE(1,1);
end
%% cash flow in autumn
MONEYDYN(t,2)=inc2+inc;
MONEYDYN(t,7)=MONEYDYN(t,3)+MONEYDYN(t,4)+MONEYDYN(t,5);
MONEYDYN(t,9)=MONEYDYN(t,2)-MONEYDYN(t,8)-MONEYDYN(t,7)+ INITIAL(1,1);
saving=MONEYDYN(t,9);
if MONEYDYN(t,9)<0
DEBAT(t,4)=0-MONEYDYN(t,9);%debt in autumn
else
DEBAT(t,4)=0;
end
DEBAT(t+1,6)=DEBAT(t,4)*COP1(1,5)*12;%interests to be paid next year
%%forage-herd-cash flow dynamic in winter
FORAGEDYN(t,9)=FORAGEDYN(t,10)+fl1*(1-SND(t,3))+fl2*(1-SND(t,4));
gof=FORAGEDYN(t,8)-FORAGEDYN(t,9);
A=STOCKC;
STOCKDYN{t,7}=0;
if gof>0
avm=MONEYDYN(t,9)+ DEBAT(t,1)+ DEBAT(t,2);
if avm>0
avf= avm/PFORGE(1,2);
gof2=(gof-avf)/FORAGEDYN(t,8);
if gof2>0
LC = ldeath_w( A,gof2);
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=avf;
MONEYDYN(t,6)=avm;
else
FORAGEDYN(t,11)=gof;
MONEYDYN(t,6)= gof*PFORGE(1,2);
LC=STOCKDYN {t,3};
end
else
[ LC ] = ldeath_w( A,gof/FORAGEDYN(t,8));
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
end
FORAGEDYN(t,12)=0;
else
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
LC=STOCKDYN {t,3};
if FORAGEDYN(t,8)<=fl1*(1-SND(t,3))+fl2*(1-SND(t,4))
FORAGEDYN(t,12)=FORAGEDYN(t,10);
else
FORAGEDYN(t,12)=FORAGEDYN(t,9)-FORAGEDYN(t,8);
end
end
STOCKDYN {t,8}=LC;
[debatt,debatn,debath ]=floan(saving,MONEYDYN(t,6),DEBAT(t,1));
DEBAT(t,5)=debatt;
if t==year
DEBAT(1,6)=debatn*8*COP1(1,5)+DEBAT(1,6);
DEBAT(1,7)=debath*8*COP1(1,8)+DEBAT(1,7);
else
DEBAT(t+1,6)=debatn*8*COP1(1,5)+DEBAT(t+1,6);
DEBAT(t+1,7)=debath*8*COP1(1,8)+DEBAT(t+1,7);
end
%% final income and expenditures
MONEYDYN(t,7)=MONEYDYN(t,7)+MONEYDYN(t,6);%final costs of production
MONEYDYN(t,11)=MONEYDYN(t,2)-MONEYDYN(t,7);
MONEYDYN(t,9)=MONEYDYN(t,9)-MONEYDYN(t,6);
if MONEYDYN(t,9)>COL(1,2)
MONEYDYN(t,9)=COL(1,2);
end
LV0=L.*PLSTOCK3;%value of initial herd by group
LV0(1,1:2)=0;
%% herd dynamic between cold season and next warm season
[ L ] = ltransform_sp(LC,PRTL(1,2),PRTL(1,4));
STOCKDYN {t+1,2}=L;
STOCKDYN {t+1,4}=sum(sum(L));
%%profits
MONEYDYN(t,10)=sum(L.*PLSTOCK3);%value of herd at end of year
MONEYDYN(t,12)= MONEYDYN(t,11)+ MONEYDYN(t,10)-sum(LV0);% profits at end of year
PKOo11code/program/climate_rand.m %% randomly generate n sets of climate serials with T years in each set. The climate serials have the same distribution pattern of annual rainfalls and frequency of snow disasters with our study area, Sonid Left Banner of Inner Mongolia, China. n= runs, T=year.
CLIMATE=cell(runs,4);
MRN=zeros(year,1);
snowy=round(year/3.5);%number of snow disasters. 3.5 is the frequency of snow disasters in our study area.
PFORAGES=zeros(year,3);
for i=1:runs
MRN(:,1)=191.4+51.63*randn(year,1);% generate the annual rainfall with same pattern of the study area ( mean =191.4mmstd=51.63mm
SND_seed=zeros(2,snowy);
a=randperm(year);
SND_seed(1,:)=a(1:snowy);%snow disaster year
SND_seed(2,:)=0.146+(0.292-0.146)*rand(1,snowy);%redution of available forage in cold season pasture when snow disaster occured(k).
SND=zeros(year,4);
for j=1:snowy %assign k to snow disaster years
k=SND_seed(1,j);
SND(k,3)=2*SND_seed(2,j);%k on warm season pasture. more serious reduction on summer pasture than on winter pasture because residuals on warm season pasture are shorter than on cold season pasture.
SND(k,4)=SND_seed(2,j);%k on cold season pasture.
end
%% price of forage
PFORAGES(:,1)=0.66+(MRN(:,1)-191.74)/112.7*0.2;%price in autunm. the formula is based on field survey in study area. unit: CNY/ kg
PFORAGES(:,3)=0.207+(MRN(:,1)-191.74)/112.7*0.0675;%price in summerthe formula is based on field survey in study area.unit: CNY/ sheep
for n=1:year
if PFORAGES(n,1)<0.45
PFORAGES(n,1)=0.45;
end
if PFORAGES(n,1)>0.90
PFORAGES(n,1)=0.90;
end
if PFORAGES(n,3)<0.14
PFORAGES(n,3)=0.14;
end
if PFORAGES(n,3)>0.28
PFORAGES(n,3)=0.28;
end
end
PFORAGES(:,2)=PFORAGES(:,1)*2;%forage price doubled in winter
CLIMATE{i,1}=MRN;
CLIMATE{i,2}=SND;
CLIMATE{i,3}=MRN(:,1)*0.24; %productivity of pasture based on rainfall use efficiency of study area (0.24g/m2?mmsource: Bai et al (2008).Ecology 89(8):2140-2153
CLIMATE{i,4}=PFORAGES;%price of forage in autumn andwinter, and cost of transhumance in summer per sheep.
end
PKORppcode/program/workprocess_v2.m%% the Import Fodder in Disaster Years Strategy (the IFDY strategy)
L=STOCKDYN {t,2};
%% forage supply on warm-season pasture
Fwt1=BP(t,1)*PRTA(1,1);
Fwt2=Fwt1*PRTFUE(1,1);
FORAGEDYN(t,2)=Fwt1;
FORAGEDYN(t,3)=Fwt2;
%% transhumance in warm season
intake=sum(sum(L))*2*160;
gof=intake-Fwt2;
saving=MONEYDYN(t-1,9);
if gof<=0
FORAGEDYN(t,4)=intake;
FORAGEDYN(t,5)=0;
FORAGEDYN(t,6)=(Fwt2-intake)/PRTA(1,1);
STOCKW=L;
STOCKDYN{t,6}=0;
inc=0;
com=0;
nos=0;
FORAGEDYN(t,13)=intake/Fwt1;
else
FORAGEDYN(t,4)=Fwt2;
FORAGEDYN(t,6)=0;
avm=DEBAT(t,1)+DEBAT(t,2)+saving;
[STOCKW,inc,com,nos] = ssold_summer(L,PLSTOCK2,PFORGE(1,3),avm,gof);
FORAGEDYN(t,5)=sum(STOCKW)*2*160- FORAGEDYN(t,3);
FORAGEDYN(t,13)=PRTFUE(1,1);
end
MONEYDYN(t,3)=com;
STOCKDYN{t,6}=nos;
[debatt,debatn,debath ]=floan(saving,com-inc,DEBAT(t,1));
DEBAT(t,3)=debatt;
DEBAT(t,7)=debath*2*COP1(1,8)+DEBAT(t,7);
DEBAT(t,6)=debatn*2*COP1(1,5)+DEBAT(t,6);
%% estimation of available forage in cold season
fl1=FORAGEDYN(t,6)*PRTA(1,3)*PRTFUE(1,2);
fl2=BP(t,1)*PRTA(1,2)*PRTFUE(1,2)*PRTFUE(1,1);
FORAGEDYN(t,7)=(fl1+fl2)*PRTFUE(1,3);
%% dynamic of herd size and structure in warm season
A =ldeath_w( STOCKW,PRTL(1,1) );
nol=sum(sum(L));
% Decision process on livestock selling in autumn
MONEYDYN(t,4)=(ceil(nol/1300)-1)*COP1(1,1)+(ceil(nol/1300))*COP1(1,2)+nol*(COP1(1,3)+COP1(1,4)+COP1(1,7))+COP1(1,6)+DEBAT(t,6)+DEBAT(t,7);
c=MONEYDYN(t,4)+MONEYDYN(t,8)+MONEYDYN(t,3)-inc-MONEYDYN(t-1,9)-DEBAT(t,1);%target of income= living expenditures+other production costs+costs of movement in summer-income-available loan from livestock in summer-savings
if BP(t,1)FORAGEDYN(t,7);
FORAGEDYN(t,10)=FORAGEDYN(t,8)-FORAGEDYN(t,7);
MONEYDYN(t,5)= FORAGEDYN(t,10)* PFORGE(1,1);
end
%% cash flow in autumn
MONEYDYN(t,2)=inc2+inc;
MONEYDYN(t,7)=MONEYDYN(t,3)+MONEYDYN(t,4)+MONEYDYN(t,5);
MONEYDYN(t,9)=MONEYDYN(t,2)-MONEYDYN(t,8)-MONEYDYN(t,7)+MONEYDYN(t-1,9);
saving=MONEYDYN(t,9);
if MONEYDYN(t,9)<0
DEBAT(t,4)=0-MONEYDYN(t,9);
else
DEBAT(t,4)=0;
end
if t==year
DEBAT(1,6)=DEBAT(t,4)*COP1(1,5)*12+DEBAT(1,6);%record the interests in the first year, otherwise it will be missed in anlysis
else
DEBAT(t+1,6)=DEBAT(t,4)*COP1(1,5)*12;
end
%%forage-herd-cash flow dynamic in winter
FORAGEDYN(t,9)=FORAGEDYN(t,10)+fl1*(1-SND(t,3))+fl2*(1-SND(t,4));
gof=FORAGEDYN(t,8)-FORAGEDYN(t,9);
A=STOCKC;
STOCKDYN{t,7}=0;
if gof>0
avm=MONEYDYN(t,9)+ DEBAT(t,1)+ DEBAT(t,2);
if avm>0
avf= avm/PFORGE(1,2);
gof2=(gof-avf)/FORAGEDYN(t,8);
if gof2>0
LC = ldeath_w( A,gof2);
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=avf;
MONEYDYN(t,6)=avm;
else
FORAGEDYN(t,11)=gof;
MONEYDYN(t,6)= gof*PFORGE(1,2);
LC=STOCKDYN {t,3};
end
else
[ LC ] = ldeath_w( A,gof/FORAGEDYN(t,8));
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
end
FORAGEDYN(t,12)=0;
else
FORAGEDYN(t,11)=0;
MONEYDYN(t,6)=0;
LC=STOCKDYN {t,3};
if FORAGEDYN(t,8)<=fl1*(1-SND(t,3))+fl2*(1-SND(t,4))
FORAGEDYN(t,12)=FORAGEDYN(t,10);
else
FORAGEDYN(t,12)=FORAGEDYN(t,9)-FORAGEDYN(t,8);
end
end
STOCKDYN {t,8}=LC;
[debatt,debatn,debath ]=floan(saving,MONEYDYN(t,6),DEBAT(t,1));
DEBAT(t,5)=debatt;
if t==year
DEBAT(1,6)=debatn*8*COP1(1,5)+DEBAT(1,6);
DEBAT(1,7)=debath*8*COP1(1,8)+DEBAT(1,7);
else
DEBAT(t+1,6)=debatn*8*COP1(1,5)+DEBAT(t+1,6);
DEBAT(t+1,7)=debath*8*COP1(1,8)+DEBAT(t+1,7);
end
%% final income and expenditures
MONEYDYN(t,7)=MONEYDYN(t,7)+MONEYDYN(t,6);
MONEYDYN(t,11)=MONEYDYN(t,2)-MONEYDYN(t,7);
MONEYDYN(t,9)=MONEYDYN(t,9)-MONEYDYN(t,6);
if MONEYDYN(t,9)>COL(1,2)
MONEYDYN(t,9)=COL(1,2);
end
%% herd dynamic between cold season and next warm season
[ L ] = ltransform_sp(LC,PRTL(1,2),PRTL(1,4));
if t0;
deathrate=gof;
LC=ldeath_w( A,deathrate);
STOCKDYN{t,7}=STOCKDYN{t,5}-sum(LC);
else
LC=STOCKDYN {t,3};
end
FORAGEDYN(t,11)=0;
FORAGEDYN(t,12)=0;
MONEYDYN(t,6)=0;
STOCKDYN {t,8}=LC;
%% final income and expenditures
MONEYDYN(t,7)=MONEYDYN(t,3)+MONEYDYN(t,4);
MONEYDYN(t,11)=MONEYDYN(t,2)-MONEYDYN(t,7);
MONEYDYN(t,9)=MONEYDYN(t,11)-MONEYDYN(t,8)+MONEYDYN(t-1,9);
if MONEYDYN(t,9)<0
DEBAT(t,4)=0-MONEYDYN(t,9);
else
DEBAT(t,4)=0;
end
if t==year %record the interests in the first year, otherwise it will be missed in anlysis
DEBAT(1,6)=DEBAT(t,4)*COP1(1,5)*12+DEBAT(1,6);
else
DEBAT(t+1,6)=DEBAT(t,4)*COP1(1,5)*12;
end
if MONEYDYN(t,9)>COL(1,2)
MONEYDYN(t,9)=COL(1,2);
end
%% herd dynamic between cold season and next warm season
[ L ] = ltransform_sp(LC,PRTL(1,2),PRTL(1,4));
if t0))/year;% frequency of over-grazing years
RESULT_v3(1,3)=length(find(ECO(1:t,2)>0))/year;
RESULT_v3(1,4)=sum(MONEYDYN(:,12))/10000;%accumulated profits (units: 10000 CNY)PKOffcode/program/run_final.m%the main program, simulate the herd dymanic, cash flow and forage dynamic under three stocking strategies with different degree of fodder input(No import of fodder, import fodder only in disaster years, and frequent import of fodder), and amount of available loan. Out put three focal indicators: duration of production, frequency of over-grazing, accumulated profits.
OUTPUT_v1=cell(runs,5);%FINAL_v1 recod the details in each run
OUTPUT_v2=cell(runs,5);
OUTPUT_v3=cell(runs,5);
OUTPUT_sum=cell(runs,1);
SER=zeros(runs,1);% ID
for n=1:runs
MRN=CLIMATE{n,1};% rainfall
SND=CLIMATE{n,2};% snow disaster year and reduction of avaiable foreage by snow disaster (k)
BP=CLIMATE{n,3}; %primary productivity of pasture
PFORAGES=CLIMATE{n,4}; %prices of forage
run_v1
run_v2
run_v3
OUTPUT_v1{n,1}=RESULT_v1;%the focal indicators under the NIF strategy
OUTPUT_v1{n,2}=STOCKDYN_v1;
OUTPUT_v1{n,3}=FORAGEDYN_v1;
OUTPUT_v1{n,4}=MONEYDYN_v1;
OUTPUT_v1{n,5}=DEBAT_v1;
OUTPUT_v2{n,1}=RESULT_v2;%the focal indicators under the IFDY strategy
OUTPUT_v2{n,2}=STOCKDYN_v2;
OUTPUT_v2{n,3}=FORAGEDYN_v2;
OUTPUT_v2{n,4}=MONEYDYN_v2;
OUTPUT_v2{n,5}=DEBAT_v2;
OUTPUT_v3{n,1}=RESULT_v3;%the focal indicators under the FIF strategy
OUTPUT_v3{n,2}=STOCKDYN_v3;
OUTPUT_v3{n,3}=FORAGEDYN_v3;
OUTPUT_v3{n,4}=MONEYDYN_v3;
OUTPUT_v3{n,5}=DEBAT_v3;
end
PKϐO
codemeta.jsonPKzOiG55
data/Data.txtPKUOÕ!Ddocs/Description of the model.txtPKOo*code/functions/ldeath_w.mPKOZ],code/functions/ssold3.mPKOF&8code/functions/ssold_summer.mPKOzO
?code/functions/ssold5.mPKOqy^.
.
Ncode/functions/ssold1.mPKO:<ddTYcode/functions/ltransform_sp.mPKO24[code/functions/floan.mPKO0acode/functions/lhfs.mPKO;pp[fcode/program/run_v1.mPKO/KNicode/program/initialize_v3.mPKOossHcode/program/initialize_v1.mPKOv%`Wcode/program/run_v2.mPKO
%9code/program/workprocess_v3.mPKOt,uumcode/program/initialize_v2.mPKOo11code/program/climate_rand.mPKORppcode/program/workprocess_v2.mPKOڇtj1code/program/workprocess_v1.mPKO}a)code/program/run_v3.mPKOff[code/program/run_final.mPK