QPALM develop
Proximal Augmented Lagrangian method for Quadratic Programs
Loading...
Searching...
No Matches
examples/fortran/qpalm_fortran_demo.f90
1! THIS VERSION: 25/04/2022 AT 13:45 GMT
2! Nick Gould (nick.gould@stfc.ac.uk)
3
4PROGRAM qpalm_fortran_example
5
7
8 ! set problem dimensions
9
10 INTEGER ( KIND = integer_kind ), PARAMETER :: n = 2
11 INTEGER ( KIND = integer_kind ), PARAMETER :: m = 3
12 INTEGER ( KIND = integer_kind ), PARAMETER :: hne = 2
13 INTEGER ( KIND = integer_kind ), PARAMETER :: ane = 4
14
15 ! set problem and solution arrays
16
17 INTEGER ( KIND = integer_kind ), DIMENSION( hne ) :: hrow
18 INTEGER ( KIND = integer_kind ), DIMENSION( n + 1 ) :: hptr
19 REAL ( KIND = real_kind ), DIMENSION( hne ) :: hval
20 REAL ( KIND = real_kind ), DIMENSION( n ) :: g
21 REAL ( KIND = real_kind ) :: f
22 INTEGER ( KIND = integer_kind ), DIMENSION( ane ) :: arow
23 INTEGER ( KIND = integer_kind ), DIMENSION( n + 1 ) :: aptr
24 REAL ( KIND = real_kind ), DIMENSION( ane ) :: aval
25 REAL ( KIND = real_kind ), DIMENSION( m ) :: cl, cu
26 REAL ( KIND = real_kind ), DIMENSION( n ) :: x
27 REAL ( KIND = real_kind ), DIMENSION( m ) :: y
28 TYPE ( QPALM_settings ) :: settings
29 TYPE ( QPALM_info ) :: info
30
31 ! set problem data (NB 1-based integer index arrays)
32
33 hptr = (/ 1, 2, 3 /) ; hrow = (/ 1, 2 /)
34 hval = (/ 1.0_real_kind, 1.5_real_kind /)
35 g = (/ 8.4018771715_real_kind, 3.9438292682_real_kind /) ; f = 0.0_real_kind
36 aptr = (/ 1, 3, 5 /) ; arow = (/ 1, 3, 2, 3 /)
37 aval = (/ 1.0_real_kind, 1.0_real_kind, 1.0_real_kind, 1.0_real_kind /)
38 cl = (/ - 2.0_real_kind, - 2.0_real_kind, - 2.0_real_kind /)
39 cu = (/ 2.0_real_kind, 2.0_real_kind, 2.0_real_kind /)
40
41 ! assign non-default settings prior to solution
42
43 settings%verbose = 0
44
45 ! solve the problem
46
47 CALL qpalm_fortran( n, m, hne, hptr, hrow, hval, g, f, &
48 ane, aptr, arow, aval, cl, cu, settings, x, y, info )
49
50 ! report the solution
51
52 IF ( info%status_val == 1 ) THEN
53 WRITE( 6, "( ' problem solved in ', I0, ' iterations, objective value =', &
54 & ES18.10 )" ) info%iter, info%objective
55 WRITE( 6, "( ' X =', ( 5ES13.5 ) )" ) x
56 ELSE
57 WRITE( 6, "( ' error return with status = ', I0 )" ) info%status_val
58 END IF
59
60END PROGRAM qpalm_fortran_example
Invoke the QPALM solver.
Fortran interface to the C package QPALM, with the aim to minimize the objective function.
integer, parameter real_kind