C     =================================================================
C     File: alabbma.f
C     =================================================================

C     =================================================================
C     Module: Main program
C     =================================================================

C     Last update of any of the component of this module: 
C
C     September 13, 2006.

C     ******************************************************************
C     ******************************************************************

      program alabbma

      implicit none

C     PARAMETERS
      include "dim.f"

C     LOCAL SCALARS
      logical checkder
      integer inform,annz,iprint,m,maxoutit,ml,meq,n,ncomp,outiter,
     +        totnnodes
      double precision epsgap,epsfeas,epsopt,f,nalpsupn,snorm
      real time

C     LOCAL ARRAYS
      integer alin(annzmax),acol(annzmax),wi1(nmax),wi2(mlmax)
      logical equatn(mmax),linear(mmax),linvar(nmax)
      double precision aval(annzmax),b(mlmax),l(nmax),lambda(mmax),
     +        H(nmax,nmax),rho(mmax),u(nmax),wd1(mmax),wd2(mmax),
     +        wd3(nmax),wd4(mmax),wd5(mmax),wd6(nmax),wd7(nmax),
     +        wd8(nmax),wd9(nmax),wd10(nmax),wd11(nmax),wd12(nmax),
     +        x(nmax)

C     INITIALIZE INTERVAL ANALYSIS TOOL
      call simini()

C     SET UP PROBLEM DATA
      call inip(n,x,l,u,m,lambda,rho,equatn,linear,ml,meq,alin,acol,
     +aval,annz,b)

C     Set linvar(i) = .true. if x(i) appears just linearly in the 
C     objective function as well as appears just in linear constraints
C     (that will not be penalized). Otherwise, it sets linvar(i) = .false.
      call setlv(n,linvar)

C     SET SOME SOLVER ARGUMENTS
      call param(checkder,epsgap,epsfeas,epsopt,maxoutit,iprint,ncomp)

C     CALL OPTIMIZATION SOLVER
      call solver(n,x,l,u,m,lambda,rho,equatn,linear,linvar,ml,meq,alin,
     +acol,aval,annz,b,checkder,epsgap,epsfeas,epsopt,maxoutit,iprint,
     +ncomp,f,snorm,nalpsupn,nmax,H,outiter,totnnodes,time,inform,wi1,
     +wi2,wd1,wd2,wd3,wd4,wd5,wd6,wd7,wd8,wd9,wd10,wd11,wd12)

C     WRITE ADDITIONAL OUTPUT INFORMATION CODED BY THE USER
      call endp(n,x,l,u,m,lambda,rho,equatn,linear)

      stop

      end

C     ******************************************************************
C     ******************************************************************

      subroutine param(checkder,epsgap,epsfeas,epsopt,maxoutit,iprint,
     +ncomp)

      implicit none

C     SCALAR ARGUMENTS
      logical checkder
      integer iprint,maxoutit,ncomp
      double precision epsfeas,epsgap,epsopt
 
      checkder = .false.

      epsgap  = 1.0d-04
      epsfeas = 1.0d-04
      epsopt  = 1.0d-04

      maxoutit = 50

      iprint = 1
      ncomp  = 5

      end

C     ******************************************************************
C     ******************************************************************

      double precision function drand(ix)

C     This is the random number generator of Schrage:
C
C     L. Schrage, A more portable Fortran random number generator, ACM
C     Transactions on Mathematical Software 5 (1979), 132-138.

      double precision ix

      double precision a,p,b15,b16,xhi,xalo,leftlo,fhi,k
      data a/16807.d0/,b15/32768.d0/,b16/65536.d0/,p/2147483647.d0/

      xhi= ix/b16
      xhi= xhi - dmod(xhi,1.d0)
      xalo= (ix-xhi*b16)*a
      leftlo= xalo/b16
      leftlo= leftlo - dmod(leftlo,1.d0)
      fhi= xhi*a + leftlo
      k= fhi/b15
      k= k - dmod(k,1.d0)
      ix= (((xalo-leftlo*b16)-p)+(fhi-k*b15)*b16)+k
      if (ix.lt.0) ix= ix + p
      drand= ix*4.656612875d-10

      return

      end

