@@ -230,7 +230,7 @@ def test_terminal_constraints(sys_args):
230230 final_point = [opt .state_range_constraint (sys , [0 , 0 ], [0 , 0 ])]
231231
232232 # Create the optimal control problem
233- time = np .arange (0 , 5 , 1 )
233+ time = np .arange (0 , 3 , 1 )
234234 optctrl = opt .OptimalControlProblem (
235235 sys , time , cost , terminal_constraints = final_point )
236236
@@ -302,3 +302,25 @@ def test_terminal_constraints(sys_args):
302302 with pytest .warns (UserWarning , match = "unable to solve" ):
303303 res = optctrl .compute_trajectory (x0 , squeeze = True , return_x = True )
304304 assert not res .success
305+
306+ def test_optimal_logging (capsys ):
307+ """Test logging functions (mainly for code coverage)"""
308+ sys = ct .ss2io (ct .ss ([[1 , 1 ], [0 , 1 ]], [[1 ], [0.5 ]], np .eye (2 ), 0 , 1 ))
309+
310+ # Set up the optimal control problem
311+ cost = opt .quadratic_cost (sys , 1 , 1 )
312+ state_constraint = opt .state_range_constraint (
313+ sys , [- np .inf , - 10 ], [10 , np .inf ])
314+ input_constraint = opt .input_range_constraint (sys , - 100 , 100 )
315+ time = np .arange (0 , 3 , 1 )
316+ x0 = [- 1 , 1 ]
317+
318+ # Solve it, with logging turned on
319+ res = opt .solve_ocp (
320+ sys , time , x0 , cost , input_constraint , terminal_cost = cost ,
321+ terminal_constraints = state_constraint , log = True )
322+
323+ # Make sure the output has info available only with logging turned on
324+ captured = capsys .readouterr ()
325+ assert captured .out .find ("process time" ) != - 1
326+
0 commit comments