@@ -1820,21 +1820,20 @@ function test_nonlinear_with_scalar_quadratic_function_with_off_diag(
1820
1820
@requires _supports (config, MOI. optimize!)
1821
1821
F = MOI. ScalarNonlinearFunction
1822
1822
@requires MOI. supports_constraint (model, F, MOI. EqualTo{T})
1823
- for (a, b, status) in [
1824
- (1 , 2 , config. optimal_status),
1825
- (1 , 3 , config. infeasible_status),
1826
- (2 , 3 , config. optimal_status),
1827
- (2 , 4 , config. infeasible_status),
1828
- ]
1823
+ test_cases = [(1 , 2 , true ), (1 , 3 , false ), (2 , 3 , true ), (2 , 4 , false )]
1824
+ for (a, b, status) in test_cases
1829
1825
MOI. empty! (model)
1830
1826
x, _ = MOI. add_constrained_variable (model, MOI. EqualTo (T (2 )))
1827
+ MOI. set (model, MOI. VariablePrimalStart (), x, T (2 ))
1831
1828
y, _ = MOI. add_constrained_variable (model, MOI. EqualTo (T (3 )))
1829
+ MOI. set (model, MOI. VariablePrimalStart (), y, T (3 ))
1832
1830
g = T (a) * x * y
1833
1831
@test g isa MOI. ScalarQuadraticFunction{T}
1834
1832
f = MOI. ScalarNonlinearFunction (:sqrt , Any[g])
1835
1833
MOI. add_constraint (model, f, MOI. GreaterThan (T (b)))
1836
1834
MOI. optimize! (model)
1837
- @test MOI. get (model, MOI. TerminationStatus ()) == status
1835
+ term_status = MOI. get (model, MOI. TerminationStatus ())
1836
+ @test (term_status == config. optimal_status) == status
1838
1837
end
1839
1838
return
1840
1839
end
@@ -1866,15 +1865,20 @@ function test_nonlinear_constraint_log(
1866
1865
x = MOI. add_variable (model)
1867
1866
t = MOI. add_variable (model)
1868
1867
MOI. add_constraint (model, x, MOI. LessThan (T (2 )))
1868
+ MOI. set (model, MOI. VariablePrimalStart (), x, T (1 ))
1869
1869
MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
1870
1870
f = 1.0 * t
1871
+ # max t
1872
+ # x <= 2
1873
+ # log(x) >= t
1871
1874
MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
1872
1875
g = MOI. ScalarNonlinearFunction (
1873
1876
:- ,
1874
1877
Any[MOI. ScalarNonlinearFunction (:log , Any[x]), t],
1875
1878
)
1876
1879
c = MOI. add_constraint (model, g, MOI. GreaterThan (T (0 )))
1877
1880
MOI. optimize! (model)
1881
+ @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
1878
1882
x_val = MOI. get (model, MOI. VariablePrimal (), x)
1879
1883
t_val = MOI. get (model, MOI. VariablePrimal (), t)
1880
1884
@test ≈ (x_val, T (2 ), config)
@@ -1983,7 +1987,9 @@ function test_nonlinear_quadratic_1(
1983
1987
#
1984
1988
# -> x = y = 1/sqrt(2)
1985
1989
x = MOI. add_variable (model)
1990
+ MOI. set (model, MOI. VariablePrimalStart (), x, T (1 ))
1986
1991
y = MOI. add_variable (model)
1992
+ MOI. set (model, MOI. VariablePrimalStart (), y, T (1 ))
1987
1993
MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
1988
1994
f = T (1 ) * x + T (1 ) * y
1989
1995
MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
@@ -1993,6 +1999,7 @@ function test_nonlinear_quadratic_1(
1993
1999
g = MOI. ScalarNonlinearFunction (:sqrt , Any[f3])
1994
2000
c = MOI. add_constraint (model, g, MOI. LessThan (T (1 )))
1995
2001
MOI. optimize! (model)
2002
+ @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
1996
2003
@test ≈ (MOI. get (model, MOI. ObjectiveValue ()), 2 / sqrt (2 ), config)
1997
2004
@test ≈ (MOI. get (model, MOI. VariablePrimal (), x), 1 / sqrt (2 ), config)
1998
2005
@test ≈ (MOI. get (model, MOI. VariablePrimal (), y), 1 / sqrt (2 ), config)
@@ -2029,7 +2036,9 @@ function test_nonlinear_quadratic_2(
2029
2036
#
2030
2037
# -> x = y = 1/sqrt(2)
2031
2038
x = MOI. add_variable (model)
2039
+ MOI. set (model, MOI. VariablePrimalStart (), x, T (1 ))
2032
2040
y = MOI. add_variable (model)
2041
+ MOI. set (model, MOI. VariablePrimalStart (), y, T (1 ))
2033
2042
MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
2034
2043
f = T (1 ) * x + T (1 ) * y
2035
2044
MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
@@ -2039,6 +2048,7 @@ function test_nonlinear_quadratic_2(
2039
2048
g = MOI. ScalarNonlinearFunction (:sqrt , Any[f3])
2040
2049
c = MOI. add_constraint (model, g, MOI. LessThan (T (1 )))
2041
2050
MOI. optimize! (model)
2051
+ @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
2042
2052
@test ≈ (MOI. get (model, MOI. ObjectiveValue ()), 2 / sqrt (2 ), config)
2043
2053
@test ≈ (MOI. get (model, MOI. VariablePrimal (), x), 1 / sqrt (2 ), config)
2044
2054
@test ≈ (MOI. get (model, MOI. VariablePrimal (), y), 1 / sqrt (2 ), config)
@@ -2075,7 +2085,9 @@ function test_nonlinear_quadratic_3(
2075
2085
#
2076
2086
# -> x = y = 1/sqrt(2)
2077
2087
x = MOI. add_variable (model)
2088
+ MOI. set (model, MOI. VariablePrimalStart (), x, T (1 ))
2078
2089
y = MOI. add_variable (model)
2090
+ MOI. set (model, MOI. VariablePrimalStart (), y, T (1 ))
2079
2091
MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
2080
2092
f = T (1 ) * x + T (1 ) * y
2081
2093
MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
@@ -2085,6 +2097,7 @@ function test_nonlinear_quadratic_3(
2085
2097
g = MOI. ScalarNonlinearFunction (:sqrt , Any[f3])
2086
2098
c = MOI. add_constraint (model, g, MOI. LessThan (T (1 )))
2087
2099
MOI. optimize! (model)
2100
+ @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
2088
2101
@test ≈ (MOI. get (model, MOI. ObjectiveValue ()), 2 / sqrt (2 ), config)
2089
2102
@test ≈ (MOI. get (model, MOI. VariablePrimal (), x), 1 / sqrt (2 ), config)
2090
2103
@test ≈ (MOI. get (model, MOI. VariablePrimal (), y), 1 / sqrt (2 ), config)
@@ -2120,7 +2133,9 @@ function test_nonlinear_quadratic_4(
2120
2133
#
2121
2134
# -> x = y = 1/sqrt(2)
2122
2135
x = MOI. add_variable (model)
2136
+ MOI. set (model, MOI. VariablePrimalStart (), x, T (1 ))
2123
2137
y = MOI. add_variable (model)
2138
+ MOI. set (model, MOI. VariablePrimalStart (), y, T (1 ))
2124
2139
MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
2125
2140
f = T (1 ) * x + T (1 ) * y
2126
2141
MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
@@ -2130,6 +2145,7 @@ function test_nonlinear_quadratic_4(
2130
2145
g = MOI. ScalarNonlinearFunction (:sqrt , Any[f3])
2131
2146
c = MOI. add_constraint (model, g, MOI. LessThan (T (1 )))
2132
2147
MOI. optimize! (model)
2148
+ @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
2133
2149
@test ≈ (MOI. get (model, MOI. ObjectiveValue ()), 2 / sqrt (2 ), config)
2134
2150
@test ≈ (MOI. get (model, MOI. VariablePrimal (), x), 1 / sqrt (2 ), config)
2135
2151
@test ≈ (MOI. get (model, MOI. VariablePrimal (), y), 1 / sqrt (2 ), config)
0 commit comments