*     *************************************************************************

      subroutine inset0( nipst, nip,  naibs,  iss, optmal,
     +                   elvar, elptr,  varin, ptrel, xst,
     +                   ftstem, pr, bep, fr, to, ba, nba,
     +                   info, iflag )

*     *************************************************************************

*     Purpose :
*     ---------

*     When OPTMAL  =  0 : It is the first time that the partition
*                         of the variables into independent sets
*                         is done. The superbasic set is not empty.
*                         The routine builds the independent sets.

*                 < > 0 : The routine dejoins the big old independent
*                         sets when, at least some superbasic arc from
*                         the old independent set has just been activated.

*     Parameters :
*     ------------

*     nipst   ( log )

*       input  : .true.  if the user whishes to use the concept
*                        of independent superbasic sets in order
*                        to exploit the parrallelism in both the
*                        constraints and the cost function structure.
*                .false. if no decomposition is achieved.
*       output : unmodified.

*     nip     ( int )

*       input  : the number of independent sets before the
*                routine is called.
*       output : the number of independent sets after the
*                the routine is called.

*     naibs   ( int )

*       input  : vector containing the number of superbasic
*                variables in each independent set.
*       output : this vector is updated following the new partition.

*     iss     ( int )

*       input  : vector containing for each variable, the indice
*                of the independent set in which it is included.
*                It is equal to zero when the variable does not
*                belongs to any independent set.
*       output : this vector is updated following the new partition.

*     optmal  ( int )

*       input  : =  0, when it is the first time that the partition
*                      of the variables into independent sets is done
*                <> 0, when we want to dejoin the big old independent
*                      sets, when at least some superbasic arc from
*                      the old independent set has just been activated.
*       output : unmodified.

*     elvar   ( int )

*       input  : array containing the indices of the variables in
*                the first element, followed by those in the second
*                element, etc.
*       output : unmodified.

*     elptr   ( int )

*       input  : array whose kth value is the position of the first
*                variable of element k, in the list ELVAR.
*       output : unmodified.

*     varin   ( int )

*       input  : meaningless.
*       output : array containing the indices of the element including
*                the first variable, followed by those including the
*                second variable, etc.

*     ptrel   ( int )

*       input  : meaningless.
*       output : array whose kth value is the position of the first
*                element including variable k, in the list VARIN.

*     xst     ( int )

*       input  : vector containing the status of the variables.
*       output : this vector is updated following the new partition.

*     ftstem  ( int )

*       input  : vector containing for each superbasic variable,
*                the length from its origine node to the stem
*                node, and the length of its flow augmenting path.
*       output : unmodified.

*     pr      ( int )

*       input  : the predecessor vector.
*       output : unmodified.

*     bep     ( int )

*       input  : array used as workspace.
*       output : meaningless.

*     fr      ( int )

*       input  : vector containing the origine nodes of the arcs.
*       output : unmodified.

*     to      ( int )

*       input  : vector containing the end nodes of the arcs.
*       output : unmodified.

*     ba      ( int )

*       input  : vector containing the indices of the basic
*                variables.
*       output : unmodified.

*     nba     ( int )

*       input  : the number of basic variables.
*       output : unmodified.

*     info    ( int )

*       input  : meaningless.
*       output : when IFLAG = 11, it contains the number of independent
*                sets created.
*                Otherwise, it is meaningless.

*     iflag   ( int )

*       input  : should be equal to zero when the routine is called.
*       output : = 11, if the maximum number of independent sets
*                      is reached.
*                Otherwise, it remains unmodified.

*     Routines used :
*     ---------------

*     Invpss, isetvl, snxdja, gxdej,
*     snxdej, gxsu, gxdeja, sxdeja, analys.

*     Programming :
*     -------------

*     D. Tuyttens

*     =========================================================================

*     Routine parameters

      integer  nip,  naibs(*), iss(*),  optmal,  elvar(*), elptr(*),
     +         varin(*), ptrel(*), xst(*), ftstem(*), pr(*), bep(*),
     +         fr(*), to(*),  ba(*), nba,  info, iflag
      logical  nipst

*     Internal variables

      integer  i, ip, k, s
      logical  deja, gxsu, gxdej, gxdeja

*     Common specifications

      integer           arcs, nodes, elem
      common / prbdim / arcs, nodes, elem

*     Parameters definition

      integer  maxins, maxip
      parameter(  maxins = 100 , maxip = 60  )

*
*     We build the inverse partially separable structure.
*
      call invpss( elvar, elptr, varin, ptrel )
*
*     We test if it is the first time that the partition
*     of the variables into independent sets is done.
*
      if( optmal.eq.0 ) then
*
*       It is the first time that the partition of the
*       variables into independent sets is done. We
*       initialize the vectors NAIBS and ISS.
*
        call isetvl( maxins, naibs, 1, 0 )
        call isetvl( arcs, iss, 1, 0 )
        nip = 1
*
      else
*
*       We set the status of the variables such that
*       it corresponds to the status of variables that
*       do not belong to one independent set that needs
*       to be dejoined.
*
        do 20 i = 1 , arcs
          call snxdja(xst(i))
 20     continue
        deja = .false.
*
*       We loop on the independent sets, and we detect
*       which of the sets are candidate to be dejoined.
*
        do 30 ip = 1 , nip
*
*         Is independent set IP candidate to be dejoined ?
*
          if( gxdej(xst(ip)) ) then
*
*           Independent set IP is candidate to be dejoined.
*
            s = naibs(ip)
            call snxdej(xst(ip))
*
*           We check the number of superbasic variables in the
*           independent set that is candidate to be de-joined.
*
            if( s.gt.maxip ) then
*
*             Independent set IP will be dejoined.
*
              deja = .true.
              naibs(ip) = 0
              do 40 k = 1 , arcs
                if( iss(k).eq.ip ) then
                  iss(k) = 0
*
*                 The status of the superbasic variable K
*                 is modified such that it corresponds to
*                 a status of a variable that belongs to
*                 on independent set that needs to be dejoined.
*
                  if( gxsu(xst(k)) ) call sxdeja(xst(k))
                endif
 40           continue
            endif
          endif
*
*         Next independent set.
*
 30     continue
*
*       If no independent set needs to be dejoined,
*       then nothing is to do.
*
        if( .not.deja ) return
      endif
*
*     Following the value of OPTMAL, we create or we
*     update the independent sets.
*
      do 50 k = 1 , arcs
        if( (optmal.eq.0 .and. gxsu(xst(k))) .or.
     +      (optmal.ne.0 .and. gxdeja(xst(k))) ) then
*
*         We include the superbasic arc K in a new
*         independent set and we analyse all its
*         dependencies.
*
          call analys( k,  nip, nipst, iss,  naibs, ftstem,
     +                 pr, bep, elvar, elptr, varin, ptrel,
     +                 xst, fr, to,  ba, nba, iflag, info )
        endif
 50   continue
*
      return
      end