@@ -19,47 +19,44 @@ depMess <- paste("The old behavior for hin >= 0 has been deprecated. Please",
19
19
" restate the inequality to be <=0. The ability to use the old" ,
20
20
" behavior will be removed in a future release." )
21
21
22
- # # Functions for SLSQP
22
+ # Taken from example
23
23
x0.hs100 <- c(1 , 2 , 0 , 4 , 0 , 1 , 1 )
24
- fn.hs100 <- function (x ) {
25
- (x [1L ] - 10 ) ^ 2 + 5 * (x [2L ] - 12 ) ^ 2 + x [3L ] ^ 4 + 3 * (x [4L ] - 11 ) ^ 2 +
26
- 10 * x [5L ] ^ 6 + 7 * x [6L ] ^ 2 + x [7L ] ^ 4 - 4 * x [6L ] * x [7L ] -
27
- 10 * x [6L ] - 8 * x [7L ]
24
+ fn.hs100 <- function (x ) {(x [1 ] - 10 ) ^ 2 + 5 * (x [2 ] - 12 ) ^ 2 + x [3 ] ^ 4 +
25
+ 3 * (x [4 ] - 11 ) ^ 2 + 10 * x [5 ] ^ 6 + 7 * x [6 ] ^ 2 +
26
+ x [7 ] ^ 4 - 4 * x [6 ] * x [7 ] - 10 * x [6 ] - 8 * x [7 ]}
27
+
28
+ hin.hs100 <- function (x ) {c(
29
+ 2 * x [1 ] ^ 2 + 3 * x [2 ] ^ 4 + x [3 ] + 4 * x [4 ] ^ 2 + 5 * x [5 ] - 127 ,
30
+ 7 * x [1 ] + 3 * x [2 ] + 10 * x [3 ] ^ 2 + x [4 ] - x [5 ] - 282 ,
31
+ 23 * x [1 ] + x [2 ] ^ 2 + 6 * x [6 ] ^ 2 - 8 * x [7 ] - 196 ,
32
+ 4 * x [1 ] ^ 2 + x [2 ] ^ 2 - 3 * x [1 ] * x [2 ] + 2 * x [3 ] ^ 2 + 5 * x [6 ] -
33
+ 11 * x [7 ])
28
34
}
29
35
30
36
gr.hs100 <- function (x ) {
31
- c(2 * x [1L ] - 20 ,
32
- 10 * x [2L ] - 120 ,
33
- 4 * x [3L ] ^ 3 ,
34
- 6 * x [4L ] - 66 ,
35
- 60 * x [5L ] ^ 5 ,
36
- 14 * x [6L ] - 4 * x [7L ] - 10 ,
37
- 4 * x [7L ] ^ 3 - 4 * x [6L ] - 8 )
38
- }
39
-
40
- gr <- function (x ) nl.grad(x , fn.hs100 )
41
-
42
- hin.hs100 <- function (x ) {
43
- h <- double(4L )
44
- h [1L ] <- 127 - 2 * x [1L ] ^ 2 - 3 * x [2L ] ^ 4 - x [3L ] - 4 * x [4L ] ^ 2 - 5 *
45
- x [5L ]
46
- h [2L ] <- 282 - 7 * x [1L ] - 3 * x [2L ] - 10 * x [3L ] ^ 2 - x [4L ] + x [5L ]
47
- h [3L ] <- 196 - 23 * x [1L ] - x [2L ] ^ 2 - 6 * x [6L ] ^ 2 + 8 * x [7L ]
48
- h [4L ] <- - 4 * x [1L ] ^ 2 - x [2L ] ^ 2 + 3 * x [1L ] * x [2L ] - 2 * x [3L ] ^ 2 -
49
- 5 * x [6L ] + 11 * x [7L ]
50
- return (h )
37
+ c( 2 * x [1 ] - 20 ,
38
+ 10 * x [2 ] - 120 ,
39
+ 4 * x [3 ] ^ 3 ,
40
+ 6 * x [4 ] - 66 ,
41
+ 60 * x [5 ] ^ 5 ,
42
+ 14 * x [6 ] - 4 * x [7 ] - 10 ,
43
+ 4 * x [7 ] ^ 3 - 4 * x [6 ] - 8 )
51
44
}
52
45
53
46
hinjac.hs100 <- function (x ) {
54
- matrix (c(4 * x [1L ], 12 * x [2L ] ^ 3 , 1 , 8 * x [4L ], 5 , 0 , 0 , 7 , 3 , 20 * x [3L ],
55
- 1 , - 1 , 0 , 0 , 23 , 2 * x [2L ], 0 , 0 , 0 , 12 * x [6L ], - 8 ,
56
- 8 * x [1L ] - 3 * x [2L ], 2 * x [2L ] - 3 * x [1L ], 4 * x [3L ], 0 , 0 , 5 ,
57
- - 11 ), 4L , 7L , byrow = TRUE )
47
+ matrix (c(4 * x [1 ], 12 * x [2 ] ^ 3 , 1 , 8 * x [4 ], 5 , 0 , 0 ,
48
+ 7 , 3 , 20 * x [3 ], 1 , - 1 , 0 , 0 ,
49
+ 23 , 2 * x [2 ], 0 , 0 , 0 , 12 * x [6 ], - 8 ,
50
+ 8 * x [1 ] - 3 * x [2 ], 2 * x [2 ] - 3 * x [1 ], 4 * x [3 ], 0 , 0 , 5 , - 11 ),
51
+ nrow = 4 , byrow = TRUE )
58
52
}
59
53
60
- hin2.hs100 <- function (x ) - hin.hs100(x ) # Needed for nloptr call
61
- hinjac2.hs100 <- function (x ) - hinjac.hs100(x ) # Needed for nloptr call
62
- hinjac2b.hs100 <- function (x ) nl.jacobian(x , hin2.hs100 )# Needed for nloptr call
54
+ hin2.hs100 <- function (x ) - hin.hs100(x ) # Needed to test old behavior
55
+ hinjac2.hs100 <- function (x ) - hinjac.hs100(x ) # Needed to test old behavior
56
+
57
+ gr.hs100.computed <- function (x ) nl.grad(x , fn.hs100 )
58
+ hinjac.hs100.computed <- function (x ) nl.jacobian(x , hin.hs100 )
59
+ hinjac2.hs100.computed <- function (x ) nl.jacobian(x , hin2.hs100 )
63
60
64
61
# Test printout if nl.info passed. The word "Call:" should be in output if
65
62
# passed and not if not passed.
@@ -69,13 +66,14 @@ expect_stdout(slsqp(x0.hs100, fn = fn.hs100, nl.info = TRUE),
69
66
expect_silent(slsqp(x0.hs100 , fn = fn.hs100 ))
70
67
71
68
# No passed gradient or Inequality Jacobians
72
- slsqpTest <- suppressMessages(slsqp(x0.hs100 , fn.hs100 , hin = hin.hs100 ))
69
+ slsqpTest <- slsqp(x0.hs100 , fn.hs100 , hin = hin.hs100 ,
70
+ deprecatedBehavior = FALSE )
73
71
74
72
slsqpControl <- nloptr(x0 = x0.hs100 ,
75
73
eval_f = fn.hs100 ,
76
- eval_grad_f = gr ,
77
- eval_g_ineq = hin2 .hs100 ,
78
- eval_jac_g_ineq = hinjac2b .hs100 ,
74
+ eval_grad_f = gr.hs100.computed ,
75
+ eval_g_ineq = hin .hs100 ,
76
+ eval_jac_g_ineq = hinjac .hs100.computed ,
79
77
opts = list (algorithm = " NLOPT_LD_SLSQP" ,
80
78
xtol_rel = 1e-6 , maxeval = 1000L ))
81
79
@@ -86,15 +84,15 @@ expect_identical(slsqpTest$convergence, slsqpControl$status)
86
84
expect_identical(slsqpTest $ message , slsqpControl $ message )
87
85
88
86
# Passed gradient or Inequality Jacobians
89
- slsqpTest <- suppressMessages( slsqp(x0.hs100 , fn = fn.hs100 , gr = gr.hs100 ,
90
- hin = hin .hs100 , hinjac = hinjac.hs100 ) )
87
+ slsqpTest <- slsqp(x0.hs100 , fn = fn.hs100 , gr = gr.hs100 , hin = hin .hs100 ,
88
+ hinjac = hinjac .hs100 , deprecatedBehavior = FALSE )
91
89
92
90
# Going to be reused below in new behavior test.
93
91
slsqpControlhinjac <- nloptr(x0 = x0.hs100 ,
94
92
eval_f = fn.hs100 ,
95
93
eval_grad_f = gr.hs100 ,
96
- eval_g_ineq = hin2 .hs100 ,
97
- eval_jac_g_ineq = hinjac2 .hs100 ,
94
+ eval_g_ineq = hin .hs100 ,
95
+ eval_jac_g_ineq = hinjac .hs100 ,
98
96
opts = list (algorithm = " NLOPT_LD_SLSQP" ,
99
97
xtol_rel = 1e-6 , maxeval = 1000L ))
100
98
@@ -105,13 +103,14 @@ expect_identical(slsqpTest$convergence, slsqpControlhinjac$status)
105
103
expect_identical(slsqpTest $ message , slsqpControlhinjac $ message )
106
104
107
105
# Not passing equality Jacobian
108
- slsqpTest <- suppressMessages(slsqp(x0.hs100 , fn = fn.hs100 , heq = hin.hs100 ))
106
+ slsqpTest <- slsqp(x0.hs100 , fn = fn.hs100 , heq = hin.hs100 ,
107
+ deprecatedBehavior = FALSE )
109
108
110
109
slsqpControl <- nloptr(x0 = x0.hs100 ,
111
110
eval_f = fn.hs100 ,
112
- eval_grad_f = gr.hs100 ,
113
- eval_g_eq = hin2 .hs100 ,
114
- eval_jac_g_eq = hinjac2b .hs100 ,
111
+ eval_grad_f = gr.hs100.computed ,
112
+ eval_g_eq = hin .hs100 ,
113
+ eval_jac_g_eq = hinjac .hs100.computed ,
115
114
opts = list (algorithm = " NLOPT_LD_SLSQP" ,
116
115
xtol_rel = 1e-6 , maxeval = 1000L ))
117
116
@@ -122,14 +121,14 @@ expect_identical(slsqpTest$convergence, slsqpControl$status)
122
121
expect_identical(slsqpTest $ message , slsqpControl $ message )
123
122
124
123
# Passing equality Jacobian
125
- slsqpTest <- suppressMessages( slsqp(x0.hs100 , fn = fn.hs100 , heq = hin.hs100 ,
126
- heqjac = hinjac.hs100 ) )
124
+ slsqpTest <- slsqp(x0.hs100 , fn = fn.hs100 , gr = gr .hs100 , heq = hin.hs100 ,
125
+ heqjac = hinjac.hs100 , deprecatedBehavior = FALSE )
127
126
128
127
slsqpControl <- nloptr(x0 = x0.hs100 ,
129
128
eval_f = fn.hs100 ,
130
129
eval_grad_f = gr.hs100 ,
131
- eval_g_eq = hin2 .hs100 ,
132
- eval_jac_g_eq = hinjac2 .hs100 ,
130
+ eval_g_eq = hin .hs100 ,
131
+ eval_jac_g_eq = hinjac .hs100 ,
133
132
opts = list (algorithm = " NLOPT_LD_SLSQP" ,
134
133
xtol_rel = 1e-6 , maxeval = 1000L ))
135
134
@@ -139,17 +138,12 @@ expect_identical(slsqpTest$iter, slsqpControl$iterations)
139
138
expect_identical(slsqpTest $ convergence , slsqpControl $ status )
140
139
expect_identical(slsqpTest $ message , slsqpControl $ message )
141
140
142
- # Test deprecated behavor message; remove when old behavior made defucnt.
143
- expect_message (slsqp(x0.hs100 , fn = fn.hs100 , hin = hin .hs100 ), depMess )
141
+ # Test deprecated message
142
+ expect_warning (slsqp(x0.hs100 , fn = fn.hs100 , hin = hin2 .hs100 ), depMess )
144
143
145
- # Test new behavior. Adjust tests above when old behavior made defucnt.
146
- hinx <- function (x ) - hin.hs100(x )
147
- hinjacx <- function (x ) - hinjac.hs100(x )
148
- expect_silent(slsqp(x0.hs100 , fn = fn.hs100 , hin = hinx , hinjac = hinjacx ,
149
- deprecatedBehavior = FALSE ))
150
-
151
- slsqpTest <- slsqp(x0.hs100 , fn = fn.hs100 , hin = hinx , hinjac = hinjacx ,
152
- deprecatedBehavior = FALSE )
144
+ # Test deprecated behavior Adjust tests above when old behavior made defunct.
145
+ slsqpTest <- suppressWarnings(slsqp(x0.hs100 , fn = fn.hs100 , gr = gr.hs100 ,
146
+ hin = hin2.hs100 , hinjac = hinjac2.hs100 ))
153
147
154
148
expect_identical(slsqpTest $ par , slsqpControlhinjac $ solution )
155
149
expect_identical(slsqpTest $ value , slsqpControlhinjac $ objective )
0 commit comments