/* ** scenario01.txt - restriction scenario(set max consecutive up and down days). ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Get the status whether or not path S is restricted. ** ** Format: status=scenario01(S,maxupdays,maxdowndays); ** ** Input: S vector, a path to be determined whether or not it is used ** ** maxupdays scalar, maximum consecutive upward(rising) days ** ** maxdowndays scalar, maximum consecutive downward(falling) days ** ** ** Output: status scalar, 1 if restricted, 0 otherwise ** */ proc scenario01(S,maxupdays,maxdowndays); local n,delta,signs,i,count,result; n=rows(S); delta=S[2:n]-S[1:n-1]; /* looking upward */ signs=(delta.>0); result=zeros(n-1,1); count=0; i=1; do while i<=n-1; if signs[i]==0; count=0; result[i]=count; else; count=count+1; result[i]=count; endif; i=i+1; endo; if maxc(result)>maxupdays; retp(1); endif; /* looking downward */ signs=(delta.<0); result=zeros(n-1,1); count=0; i=1; do while i<=n-1; if signs[i]==0; count=0; result[i]=count; else; count=count+1; result[i]=count; endif; i=i+1; endo; if maxc(result)>maxdowndays; retp(1); endif; retp(0); endp;