@@ -1497,6 +1497,28 @@ function test_nonlinear_variable_real_nodes()
14971497 return
14981498end
14991499
1500+ function test_nonlinear_variable_complex_nodes ()
1501+ x = MOI. VariableIndex (1 )
1502+ object = Dict {String,Any} (
1503+ " type" => " ScalarNonlinearFunction" ,
1504+ " root" => MOF. Dict {String,Any} (
1505+ " type" => " ^" ,
1506+ " args" => Any[
1507+ Dict {String,Any} (" type" => " node" , " index" => 1 ),
1508+ Dict {String,Any} (" type" => " node" , " index" => 2 ),
1509+ ],
1510+ ),
1511+ " node_list" => Any[
1512+ Dict {String,Any} (" type" => " variable" , " name" => " x" ),
1513+ Dict {String,Any} (" type" => " complex" , " real" => 2.0 , " imag" => 3.0 ),
1514+ ],
1515+ )
1516+ f = MOI. ScalarNonlinearFunction (:^ , Any[x, 2.0 + 3im ])
1517+ @test MOF. function_to_moi (object, Dict (" x" => x)) ≈ f
1518+ return
1519+ end
1520+
1521+
15001522function test_mof_scalaraffinefunction ()
15011523 x = MOI. VariableIndex (1 )
15021524 f = 1.0 * x + 2.0
@@ -1535,6 +1557,40 @@ function test_mof_scalarquadraticfunction()
15351557 return
15361558end
15371559
1560+ function test_nonlinear_expression_not_call ()
1561+ model = MOF. Model ()
1562+ x = MOI. add_variable (model)
1563+ expr = :($ x[1 ])
1564+ con = MOI. add_constraint (model, MOF. Nonlinear (expr), MOI. EqualTo (1.0 ))
1565+ io = IOBuffer ()
1566+ @test_throws (
1567+ ErrorException (
1568+ " Expected an expression that was a function. Got $expr " ,
1569+ ),
1570+ write (io, model),
1571+ )
1572+ return
1573+ end
1574+
1575+ function test_write_NLPBlock_no_objective ()
1576+ model = MOF. Model ()
1577+ x = MOI. add_variables (model, 4 )
1578+ for (index, variable) in enumerate (x)
1579+ MOI. set (model, MOI. VariableName (), variable, " var_$(index) " )
1580+ end
1581+ MOI. add_constraints (model, x, Ref (MOI. Interval (1.0 , 5.0 )))
1582+ block = HS071 (x)
1583+ new_block =
1584+ MOI. NLPBlockData (block. constraint_bounds, block. evaluator, false )
1585+ MOI. set (model, MOI. NLPBlock (), new_block)
1586+ io = IOBuffer ()
1587+ write (io, model)
1588+ seekstart (io)
1589+ contents = read (io, String)
1590+ @test occursin (""" "objective":{"sense":"feasibility"}""" , contents)
1591+ return
1592+ end
1593+
15381594end
15391595
15401596TestMOF. runtests ()
0 commit comments