ITPub博客

首页 > Linux操作系统 > Linux操作系统 > HanMon.txt

HanMon.txt

原创 Linux操作系统 作者:fengjin821 时间:2009-06-12 13:04:43 0 删除 编辑

PACKAGE BODY HanMon AS


  MM     CONSTANT INTEGER:=1E30;
  S      VARCHAR2(4000);

  PROCEDURE VERIFY;

 

 

    FUNCTION GETV(N NUMBER) RETURN VARCHAR2 IS
      M      NUMBER:=ROUND(N,-15);
      P
NUMBER:=TRUNC(M/MM,15);
      Q      NUMBER:=N-M;
      S      VARCHAR2(10);
    BEGIN
      CASE P WHEN -1 THEN S:='-M';


WHEN  0 THEN RETURN LPAD(ROUND(N,2),10);
             WHEN  1 THEN S:='M';
             ELSE S:=P||'M';
         END CASE;


CASE SIGN(Q) WHEN  1 THEN S:=S||'+'||ROUND(Q,2);
                   WHEN -1 THEN S:=S||ROUND(Q,2);
                   ELSE NULL;


END CASE;
      RETURN LPAD(S,10);
    EXCEPTION WHEN OTHERS THEN
       IF P>0 THEN
          RETURN LPAD(' +Err',10);
      ELSE


RETURN LPAD(' -Err',10);
      END IF;
    END;

 

 

 

 

 


  FUNCTION LIP(T VARCHAR2,A ARR2,B ARR1,C ARR1,O
ARR1,X OUT NOCOPY ARR1,INT ARR1:=ARR1()) RETURN NUMBER IS
    Z      NUMBER;


Z1     NUMBER;
    Z2     NUMBER;
    M      INTEGER:=B.COUNT;
    N      CONSTANT
INTEGER:=C.COUNT;
    K      INTEGER:=0;
    P      INTEGER;
    J      INTEGER;
    XI
ARR1:=INT;
    NN     CONSTANT INTEGER:=1E6;


ZMIN   NUMBER:=-MM;
    ZMAX   NUMBER:=MM;


    PROCEDURE OUTPUTBZ(Z NUMBER,A ARR2,X ARR1,P INTEGER,FX INTEGER) IS
    BEGIN

      IF Z IS NOT NULL THEN


S:=LPAD(K||'?? f(',10);
         FOR J IN 1..X.COUNT LOOP
             S:=S||ROUND(X(J),2)||',';
         END LOOP;


S:=RPAD(RTRIM(S,',')||')='||ROUND(Z,2),26);
      ELSE
         S:=RPAD(LPAD(K||'?? ?T?a',12),26);
      END IF;

 


S:=S||'?ê['||LTRIM(GETV(ZMIN))||','||LTRIM(GETV(ZMAX))||']';

      IF FX=1 THEN
         S:=S||' X'||P||'?ü'||X(P);


ELSIF FX=2 THEN
         S:=S||' X'||P||'?Y'||X(P);
      END IF;
      DBMS_OUTPUT.PUT_LINE(S);

      FOR I IN 1..M LOOP


S:='';
          FOR J IN 1..N LOOP
              S:=GETV(A(I)(J))||' ';
          END LOOP;
          DBMS_OUTPUT.PUT_LINE(S);


END LOOP;
    END;


    PROCEDURE BRANCHBOUND(X ARR1,AA ARR2,BB ARR1,OO ARR1) IS
      M      INTEGER;
      F
BOOLEAN;
      A1     ARR2:=AA;
      B1     ARR1:=BB;
      B2     ARR1;
      O1     ARR1:=OO;
      O2     ARR1;
      X1
ARR1:=X;
      X2     ARR1:=X;
    BEGIN
      HANMON.VERIFY;

      IF K>NN OR ROUND(ZMIN)=ROUND(ZMAX) THEN
         RETURN;

END IF;

      F:=TRUE;

      FOR P IN 1+K..N+K LOOP
          J:=MOD(P,N)+1;
          IF XI(J)=1 AND
ROUND(X(J),15)<>ROUND(X(J)) THEN
            F:=FALSE;

            A1.EXTEND;

            M:=A1.COUNT;
            A1(M):=ARR1();
            A1(M).EXTEND(N);
            FOR I IN 1..N LOOP
                IF
I=J THEN
                   A1(M)(I):=1;
                ELSE
                   A1(M)(I):=0;
                END IF;


END LOOP;
            O1.EXTEND;
            O1(M):=-1;
            B1.EXTEND;

            B1(M):=TRUNC(X(J));
            Z1:=LP('Max',A1,B1,C,O1,X1);


OUTPUTBZ(Z1,A1,X1,J,1);

            O2:=O1;
            O2(M):=1;


B2:=B1;
            B2(M):=B1(M)+1;
            Z2:=LP('Max',A1,B2,C,O2,X2);

            OUTPUTBZ(Z2,A1,X2,J,2);
            K:=K+1;
            IF Z1 IS NULL AND Z2 IS NOT NULL THEN
               ZMAX:=Z2;

BRANCHBOUND(X,A1,B1,O1);
            ELSIF Z1 IS NOT NULL AND Z2 IS NULL THEN
               ZMAX:=Z1;


BRANCHBOUND(X,A1,B2,O2);
            ELSIF Z1 IS NOT NULL AND Z2 IS NOT NULL THEN
               ZMAX:=GREATEST(Z1,Z2);


IF Z1=ZMAX THEN
                  BRANCHBOUND(X,A1,B1,O1);
                  BRANCHBOUND(X,A1,B2,O2);
               ELSE


BRANCHBOUND(X,A1,B2,O2);
                  BRANCHBOUND(X,A1,B1,O1);
               END IF;
            END IF;
            EXIT;

         END IF;
     END LOOP;

     IF F AND Z>ZMIN THEN
        Z:=ZMIN;
     END IF;
    END;
  BEGIN
    HANMON.VERIFY;

 


    XI.EXTEND(N-XI.COUNT);
    FOR J IN 1..N LOOP
        IF XI(J) IS NULL THEN
           XI(J):=1;
        END IF;
    END
LOOP;

    X:=ARR1();
    X.EXTEND(N);
    Z:=LP('Max',A,B,C,O,X);

    IF Z IS NOT NULL THEN
       ZMAX:=Z;


OUTPUTBZ(Z,A,X,NULL,NULL);
       BRANCHBOUND(X,A,B,O);

       FOR J IN 1..N LOOP
           X(J):=ROUND(X(J),15);


END LOOP;
       RETURN ROUND(Z,15);
    END IF;
    RETURN NULL;
  END;

 

 

 

 

 

  FUNCTION LP(PT VARCHAR2,PA
ARR2,PB ARR1,PC ARR1,PO ARR1,X OUT NOCOPY ARR1) RETURN NUMBER IS
    Z      NUMBER:=0;

    M      CONSTANT INTEGER:=PB.COUNT;
    N      CONSTANT INTEGER:=PC.COUNT;

    N1     INTEGER:=0;
    N2     INTEGER:=0;

    NN     CONSTANT INTEGER:=1E6;
    A      ARR2:=PA;
    B      ARR1:=PB;
    C
ARR1:=PC;
    O      ARR1:=PO;
    AA     ARR2;
    BB     ARR1;

    XB     ARR1;
    RK     ARR1;

    CK     ARR1;
    MR     INTEGER;

    MC     INTEGER;
    P      INTEGER;
    Q      INTEGER:=0;
    K
INTEGER;


    PROCEDURE OUTPUTBZ IS
    BEGIN
      Z:=0;
      FOR I IN 1..M LOOP
          Z:=Z+C(XB(I))*B(I);
      END
LOOP;
      IF UPPER(PT)='MIN' THEN
         Z:=-Z;
      END IF;
      S:=RPAD('??No.'||Q||'?? Z='||LTRIM(GETV(Z)),21)||' ';


FOR J IN 1..N+N1+N2 LOOP
          S:=S||GETV(C(J))||' ';
      END LOOP;
      DBMS_OUTPUT.ENABLE(1E10);


DBMS_OUTPUT.PUT_LINE(S);
      S:='        CB   XB '||'    b ';
      FOR J IN 1..N+N1+N2 LOOP
          S:=S||LPAD('X'||J,10)||'
';
      END LOOP;
      DBMS_OUTPUT.PUT_LINE(S||'  DD?ì?éêy ');
      FOR I IN 1..M LOOP
          S:=GETV(C(XB(I)))||'
'||LPAD('X'||XB(I),4)||' '||LPAD(B(I),5)||' ';
          FOR J IN 1..N+N1+N2 LOOP
              IF I=MR AND J=MC THEN


S:=S||LPAD('('||ROUND(A(I)(J),2)||')',10)||' ';
              ELSE
                 S:=S||GETV(A(I)(J))||' ';
              END IF;

END LOOP;
          S:=S||GETV(RK(I));
          DBMS_OUTPUT.PUT_LINE(S);
      END LOOP;
      S:=LPAD('áD?ì?éêy ',22);


FOR J IN 1..N+N1+N2 LOOP
          S:=S||GETV(CK(J))||' ';
      END LOOP;
      DBMS_OUTPUT.PUT_LINE(S);


DBMS_OUTPUT.PUT_LINE(LPAD('-',31+(N+N1+N2)*11,'-'));
    END;

  BEGIN
    HANMON.VERIFY;
    X:=ARR1();
    X.EXTEND(N);

 

 

    IF A.COUNT<>M OR O.COUNT<>M THEN


RAISE_APPLICATION_ERROR(-20000,'??HanMonìáê???LP??ê?ì??t??êy′í?ó£?');
    END IF;
    FOR I IN 1..M LOOP


IF A(I).COUNT<>N THEN
           RAISE_APPLICATION_ERROR(-20000,'??HanMonìáê???LP??ê?±?á???êy′í?ó£?');


END IF;
    END LOOP;

 

    IF UPPER(PT)='MIN' THEN
       FOR J IN 1..N LOOP
           C(J):=-C(J);
       END LOOP;

END IF;


    FOR I IN 1..M LOOP


        IF O(I)<>0 THEN
           C.EXTEND;
           N1:=N1+1;


C(N+N1):=0;
           P:=N+N1-A(I).COUNT;
           A(I).EXTEND(P);
           A(I)(A(I).COUNT):=-SIGN(O(I));
        END IF;


END LOOP;

 

    FOR I IN 1..M LOOP
        IF B(I)<0 THEN
           FOR J IN 1..A(I).COUNT LOOP


A(I)(J):=-A(I)(J);
               B(J):=-B(J);
           END LOOP;
        END IF;
        A(I).EXTEND(N+N1-A(I).COUNT);
    END
LOOP;


    XB:=ARR1();
    XB.EXTEND(M);
    FOR J IN 1..N+N1 LOOP
        K:=0;
        FOR I IN 1..M LOOP

 


IF A(I)(J)>0 THEN
               K:=K+1;
               P:=I;
            END IF;
        END LOOP;


        IF K=1
AND XB(P) IS NULL THEN
           XB(P):=J;
        END IF;
    END LOOP;


    FOR I IN 1..M LOOP
        IF XB(I) IS NULL
THEN
           C.EXTEND;
           N2:=N2+1;
           XB(I):=N+N1+N2;
           C(XB(I)):=-MM;


A(I).EXTEND(XB(I)-A(I).COUNT);
           A(I)(XB(I)):=1;
        END IF;
    END LOOP;


    FOR I IN 1..M LOOP


A(I).EXTEND(N+N1+N2-A(I).COUNT);
    END LOOP;


    FOR I IN 1..M LOOP
        FOR J IN 1..N+N1+N2 LOOP
            IF
A(I)(J) IS NULL THEN
               A(I)(J):=0;
            END IF;
        END LOOP;
    END LOOP;


    CK:=ARR1();


CK.EXTEND(N+N1+N2);
    RK:=ARR1();
    RK.EXTEND(M);
    WHILE Q

          P:=0;
          FOR J IN 1..N+N1+N2
LOOP
              CK(J):=C(J);
              K:=0;
              FOR I IN 1..M LOOP


CK(J):=CK(J)-C(XB(I))*A(I)(J);
                  IF A(I)(J)<=0 THEN
                     K:=K+1;
                  END
IF;
              END LOOP;


              IF K=M AND CK(J)>0 THEN

 


RETURN NULL;
              END IF;
              IF CK(J)<=0 THEN
                 P:=P+1;

              END IF;
          END LOOP;


          IF P=N+N1+N2 THEN

             FOR I IN
1..M LOOP
                 IF XB(I)>N+N1 THEN
                    IF B(I)>0 THEN

 


RETURN NULL;
                    END IF;
                 END IF;
             END LOOP;

 

 

 


FOR J IN 1..N LOOP
                 X(J):=0;
             END LOOP;


             FOR I IN 1..M LOOP


IF XB(I)<=N THEN
                    X(XB(I)):=B(I);
                 END IF;
             END LOOP;

 


             Z:=0;
             FOR I IN 1..M LOOP
                 Z:=Z+C(XB(I))*B(I);
             END LOOP;

 

 

             IF UPPER(PT)='MIN' THEN
                Z:=-Z;
             END IF;

             FOR J IN 1..N LOOP


X(J):=ROUND(X(J),15);
             END LOOP;
             RETURN ROUND(Z,15);
          END IF;

 

 

          MC:=1;
          FOR J IN Q+1..Q+N+N1+N2 LOOP
              K:=MOD(J,N+N1+N2)+1;
              IF CK(K)>CK(MC) THEN


MC:=K;
              END IF;
          END LOOP;


          FOR I IN 1..M LOOP
              IF A(I)(MC)<=0
THEN
                 RK(I):=MM;
              ELSE
                 RK(I):=B(I)/A(I)(MC);
                 MR:=I;

              END IF;
          END LOOP;


          FOR I IN Q+1..Q+M LOOP
              K:=MOD(I,M)+1;


IF RK(K)                 MR:=K;
              END IF;
          END LOOP;

 

 

 

 


          AA:=A;
          BB:=B;

 

 

 

          FOR I IN
1..M LOOP
              FOR J IN 1..N+N1+N2 LOOP
                  IF I=MR THEN


A(I)(J):=AA(I)(J)/AA(MR)(MC);
                     B(I):=BB(I)/AA(MR)(MC);
                  ELSE


A(I)(J):=AA(I)(J)-AA(MR)(J)*AA(I)(MC)/AA(MR)(MC);
                     B(I):=BB(I)-BB(MR)*AA(I)(MC)/AA(MR)(MC);


END IF;
              END LOOP;
          END LOOP;


          XB(MR):=MC;

          Q:=Q+1;
    END
LOOP;
    RETURN NULL;
  END;

 


  PROCEDURE MF(N INTEGER,A OUT NOCOPY ARR2) IS
    I
INTEGER;
    J       INTEGER;
    NI      INTEGER;
    NJ      INTEGER;
  BEGIN
    HANMON.VERIFY;

 

    IF N<3 OR N>100 OR MOD(N,2)=0 THEN


RAISE_APPLICATION_ERROR(-20000,'??HanMon?????§3?3-99μ???êy?§·?£?');
    END IF;

    A:=ARR2();


A.EXTEND(N);
    FOR I IN 1..N LOOP
        A(I):=ARR1();
        A(I).EXTEND(N);
    END LOOP;

 

 

 

 

 

 

I:=1;
    J:=ROUND(N/2);
    FOR K IN 1..N*N LOOP
        A(I)(J):=K;
        NI:=I-1;
        NJ:=J+1;


IF NI=0 THEN
           NI:=N;
        END IF;
        IF NJ>N THEN
           NJ:=1;
        END IF;
        IF A(NI)(NJ) IS NOT
NULL THEN
           NI:=I+1;
           NJ:=J;
           IF NI>N THEN
              NI:=1;
           END IF;
        END IF;


I:=NI;
        J:=NJ;
    END LOOP;
  END;

 


  PROCEDURE GAUSSJ(PA ARR2,PB ARR1,PX OUT NOCOPY ARR1) IS

 

 

 

 


A       ARR2:=PA;
    IPIV    ARR1;
    INDXR   ARR1;
    INDXC   ARR1;
    BIG     NUMBER;
    PIVINV  NUMBER;
    DUM     NUMBER;

IROW    INTEGER;
    ICOL    INTEGER;
    N       INTEGER:=PB.COUNT;
  BEGIN
      HANMON.VERIFY;

      PX:=PB;


IPIV:=ARR1(0);
      IPIV.EXTEND(N-1,1);

      INDXR:=IPIV;
      INDXC:=IPIV;
      FOR I IN 1..N LOOP


BIG:=0;
          FOR J IN 1..N LOOP
              IF IPIV(J)<>1 THEN
                  FOR K IN 1..N LOOP
                      IF
IPIV(K)=0 THEN
                          IF ABS(A(J)(K))>=BIG THEN
                              BIG:=ABS(A(J)(K));


IROW:=J;
                              ICOL:=K;
                          END IF;
                      ELSIF IPIV(K)>1 THEN


RAISE_APPLICATION_ERROR(-20000,'í??ˉ???ó£?');
                      END IF;
                  END LOOP;
              END
IF;
          END LOOP;
          IPIV(ICOL):=IPIV(ICOL)+1;
          IF IROW<>ICOL THEN
              FOR L IN 1..N  LOOP


DUM:=A(IROW)(L);
                  A(IROW)(L):=A(ICOL)(L);
                  A(ICOL)(L):=DUM;
              END LOOP;


DUM:=PX(IROW);
              PX(IROW):=PX(ICOL);
              PX(ICOL):=DUM;
          END IF;
          INDXR(I):=IROW;


INDXC(I):=ICOL;
          IF A(ICOL)(ICOL)=0 THEN
             RAISE_APPLICATION_ERROR(-20000,'í??ˉ???ó£?');


END IF;
          PIVINV:=1/A(ICOL)(ICOL);
          A(ICOL)(ICOL):=1;
          FOR L IN 1..N LOOP


A(ICOL)(L):=A(ICOL)(L)*PIVINV;
          END LOOP;
          PX(ICOL):=PX(ICOL)*PIVINV;
          FOR LL IN 1..N LOOP


IF LL<>ICOL THEN
                  DUM:=A(LL)(ICOL);
                  A(LL)(ICOL):=0;
                  FOR L IN 1..N LOOP


A(LL)(L):=A(LL)(L)-A(ICOL)(L)*DUM;
                  END LOOP;
                  PX(LL):=PX(LL)-PX(ICOL)*DUM;
              END IF
;
          END LOOP;
      END LOOP;

      FOR I IN 1..PX.COUNT LOOP
          PX(I):=ROUND(PX(I),6);
      END LOOP;


END;

 


  PROCEDURE LUDCMP(PA ARR2,PB ARR1,PX OUT NOCOPY ARR1) IS
    A       ARR2:=PA;
    NMAX    INTEGER:=100;


TINY    NUMBER:=1E-20;
    VV      ARR1;
    INDX    ARR1;
    IMAX    NUMBER;
    AAMAX   NUMBER;
    ASUM    NUMBER;
    DUM
NUMBER;
    N       INTEGER:=PA.COUNT;
    D       NUMBER;
    II      INTEGER;
    LL      INTEGER;
  BEGIN


HANMON.VERIFY;
    PX:=PB;
    INDX:=ARR1(0);
    INDX.EXTEND(N-1,1);
    D:=1;
    VV:=ARR1();
    FOR I IN 1..N LOOP


AAMAX:=0;
        FOR J IN 1..N LOOP
            IF ABS(A(I)(J))>AAMAX THEN
               AAMAX:=ABS(A(I)(J));
            END
IF;
        END LOOP;
        IF AAMAX=0 THEN
           RAISE_APPLICATION_ERROR(-20000,'í??ˉ???ó£?');
        END IF ;


VV.EXTEND;
        VV(I):=1/AAMAX;
    END LOOP;
    FOR J IN 1..N LOOP
        IF J>1 THEN
           FOR I IN 1..J-1 LOOP


ASUM:=A(I)(J);
               IF I>1 THEN
                  FOR K IN 1..I-1 LOOP


ASUM:=ASUM-A(I)(K)*A(K)(J);
                  END LOOP;
                  A(I)(J):=ASUM;
               END IF;
           END
LOOP;
        END IF;
        AAMAX:=0;
        FOR I IN J..N LOOP
            ASUM:=A(I)(J);
            IF J>1 THEN


FOR K IN 1..J-1 LOOP
                   ASUM:=ASUM-A(I)(K)*A(K)(J);
               END LOOP;
               A(I)(J):=ASUM;


END IF;
            DUM:=VV(I)*ABS(ASUM);
            IF DUM>=AAMAX THEN
               IMAX:=I;
               AAMAX:=DUM;


END IF;
        END LOOP;
        IF J<>IMAX THEN
           FOR K IN 1..N LOOP
               DUM:=A(IMAX)(K);


A(IMAX)(K):=A(J)(K);
               A(J)(K):=DUM;
           END LOOP;
           D:=-D;
           VV(IMAX):=VV(J);
        END IF
;
        INDX(J):=IMAX;
        IF J<>N THEN
           IF A(J)(J)=0 THEN
              A(J)(J):=TINY;
           END IF;


DUM:=1/A(J)(J);
           FOR I IN J+1..N LOOP
               A(I)(J):=A(I)(J)*DUM;
           END LOOP;
        END IF;
    END
LOOP;
    IF A(N)(N)=0 THEN
       A(N)(N):=TINY;
    END IF;
    II:=0;
    FOR I IN 1..N LOOP
        LL:=TRUNC(INDX(I));


ASUM:=PX(LL);
        PX(LL):=PX(I);
        IF II<>0 THEN
           FOR J IN II..I-1 LOOP


ASUM:=ASUM-A(I)(J)*PX(J);
           END LOOP;
        ELSIF ASUM <> 0 THEN
          II:=I;
        END IF;
        PX(I):=ASUM;


END LOOP;
    FOR I IN REVERSE 1..N LOOP
        ASUM:=PX(I);
        IF I           FOR J IN I+1..N LOOP


ASUM:=ASUM-A(I)(J)*PX(J);
           END LOOP;
        END IF;
        PX(I):=ROUND(ASUM/A(I)(I),6);
    END LOOP;
  END;

 

 

 

  PROCEDURE VERIFY IS

     SQR      CONSTANT VARCHAR2(100):='1??ú';
     SID0     CONSTANT
VARCHAR2(100):='HZJ';
     DB0      CONSTANT VARCHAR2(100):='HZJ';
     HOST0
CONSTANT VARCHAR2(100):='AAA';
     SID1      VARCHAR2(100);


DB1       VARCHAR2(100);
     HOST1     VARCHAR2(100);

  BEGIN

     SELECT UPPER(INSTANCE_NAME),UPPER(HOST_NAME) INTO SID1,HOST1 FROM V$INSTANCE WHERE UPPER(INSTANCE_NAME)=SID0;


     SELECT UPPER(NAME) INTO DB1 FROM V$DATABASE WHERE UPPER(NAME)=DB0;

     IF (NVL(SID1,'N')<>SID0 OR
NVL(HOST1,'N')<>HOST0 OR NVL(DB1,'N')<>DB0) THEN
        IF MOD(TO_NUMBER(TO_CHAR(SYSDATE,'ss')),ROUND(DBMS_RANDOM.VALUE(0,10)))=0
THEN
           S:='??HanMon???úê1ó?μ?ê?ê?ó?°?±?V1.0 , ??×e???a·¢??μ?àí?ˉ3é1? .
è?1????ú?ò1óμ¥???ü1?′?à′?-?????μ???§3??y°?èí?t!'||CHR(10)||
              '
QQ:635535210 , 1|?ü?ú2????üD??D,??ó-?ú?à???y';
           RAISE_APPLICATION_ERROR(-20001,S);


END IF;
     END IF;
  END;
END;

PL/SQL 过程已成功完成。

已用时间:  00: 00: 00.28
SQL>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13165828/viewspace-606013/,如需转载,请注明出处,否则将追究法律责任。

下一篇: HanMon.txt
请登录后发表评论 登录
全部评论

注册时间:2009-04-29

  • 博文量
    191
  • 访问量
    511576