Try out NAG Library functions

Explore NAG maths and stats routines with interactive demos
Function ID
E04MFF
Name
nagf_opt_lp_solve_old
Description
Linear programming
Keywords
LP, linear programming | active-set method
This example minimizes the function
-0.02x1-0.2x2-0.2x3-0.2x4-0.2x5+0.04x6+0.04x7  
subject to the bounds
-0.01x10.01-0.10x20.15-0.01x30.03-0.04x40.02-0.10x50.05-0.01x60.00-0.01x70.00  
and the general constraints
x1+x2+x3+x4+x5+x6+x7=-0.130.15x1+0.04x2+0.02x3+0.04x4+0.02x5+0.01x6+0.03x7-0.00490.03x1+0.05x2+0.08x3+0.02x4+0.06x5+0.01x6-0.006400.02x1+0.04x2+0.01x3+0.02x4+0.02x5-0.00370.02x1+0.03x2+0.01x5-0.0012-0.09920.70x1+0.75x2+0.80x3+0.75x4+0.80x5+0.97x6-0.0030.02x1+0.06x2+0.08x3+0.12x4+0.02x5+0.01x6+0.97x7-0.002  
The example data reflects that shown in the "Example" section of the routine documentation. You can change this here to try alternative inputs. The formatting will need to be kept as it is here, otherwise the program is likely to fail to run correctly.

Please note that incompatible data will however cause the example output to display an error message. These error messages are fully explained in the Routine document
    Program e04mffe

!     E04MFF Example Program Text

!     Mark 26 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: e04mff, e04mhf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: obj
      Integer                          :: i, ifail, iter, j, lda, liwork,      &
                                          lwork, n, nclin, sda
      Logical                          :: verbose_output
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:), ax(:), bl(:), bu(:),         &
                                          clamda(:), cvec(:), work(:), x(:)
      Integer, Allocatable             :: istate(:), iwork(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max
!     .. Executable Statements ..
      Write (nout,*) 'E04MFF Example Program Results'

!     Skip heading in data file

      Read (nin,*)
      Read (nin,*) n, nclin
      liwork = 2*n + 3

!     The minimum LWORK for an LP problem:

      If (0<nclin .And. nclin<n) Then
        lwork = 2*(nclin+1)**2 + 7*n + 5*nclin
      Else If (nclin>=n) Then
        lwork = 2*n**2 + 7*n + 5*nclin
      Else
        lwork = 7*n + 1
      End If

      lda = max(1,nclin)

      If (nclin>0) Then
        sda = n
      Else
        sda = 1
      End If

      Allocate (istate(n+nclin),iwork(liwork),a(lda,sda),bl(n+nclin),          &
        bu(n+nclin),cvec(n),x(n),ax(max(1,nclin)),clamda(n+nclin),work(lwork))

      Read (nin,*) cvec(1:n)
      Read (nin,*)(a(i,1:sda),i=1,nclin)
      Read (nin,*) bl(1:(n+nclin))
      Read (nin,*) bu(1:(n+nclin))
      Read (nin,*) x(1:n)

!     Set this to .True. to cause e04nqf to produce intermediate
!     progress output
      verbose_output = .False.

      If (.Not. verbose_output) Then
!       Turn off intermediate output from e04mff - it is on by default
        Call e04mhf('Nolist')
        Call e04mhf('Print Level = 0')
      End If

!     Solve the problem

      ifail = 0
      Call e04mff(n,nclin,a,lda,bl,bu,cvec,istate,x,iter,obj,ax,clamda,iwork,  &
        liwork,work,lwork,ifail)

      Select Case (ifail)
      Case (0:5,7:)
        Write (nout,*)
        Write (nout,99999)
        Do i = 1, n
          Write (nout,99998) i, istate(i), x(i), clamda(i)
        End Do

        If (nclin>0) Then
          Write (nout,*)
          Write (nout,99997)
          Do i = n + 1, n + nclin
            j = i - n
            Write (nout,99996) j, istate(i), ax(j), clamda(i)
          End Do

        End If

        Write (nout,*)
        Write (nout,99995) obj
      End Select

99999 Format (1X,'Varbl',3X,'Istate',4X,'Value',9X,'Lagr Mult')
99998 Format (1X,'V',2(1X,I3),4X,1P,E14.3,2X,1P,E12.3)
99997 Format (1X,'L Con',3X,'Istate',4X,'Value',9X,'Lagr Mult')
99996 Format (1X,'L',2(1X,I3),4X,1P,E14.3,2X,1P,E12.3)
99995 Format (1X,'Final objective value = ',1P,E15.3)
    End Program e04mffe
The NAG Library
The world’s largest collection of robust, documented, tested and maintained numerical algorithms.
Learn more here or contact us for purchasing information