Skip to content

Commit 0ef594e

Browse files
committed
Switch from use of fprintf() to redirectable mp_printf().
1 parent 043b45d commit 0ef594e

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ Change history for MIPS
22
=======================
33

44

5+
since 1.5.2
6+
-----------
7+
8+
#### 7/23/26
9+
- Use `mp_printf()`, recently included in [MP-Test](4), in place of
10+
`fprintf()` everywhere to allow redirecting of console output.
11+
12+
513
Version 1.5.2 - *July 12, 2025*
614
-------------------------------
715

@@ -304,3 +312,4 @@ Version 1.0b1 - *Dec 24, 2009* (released with MATPOWER 4.0b1)
304312
[1]: https://travis-ci.org
305313
[2]: https://matpower.org/doc/mips/
306314
[3]: https://github.com/MATPOWER/mips/issues/4
315+
[4]: https://github.com/MATPOWER/mptest

lib/mips.m

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
% pp. 1185-1193. :doi:`10.1109/TPWRS.2007.901301`
220220

221221
% MIPS
222-
% Copyright (c) 2009-2024, Power Systems Engineering Research Center (PSERC)
222+
% Copyright (c) 2009-2026, Power Systems Engineering Research Center (PSERC)
223223
% by Ray Zimmerman, PSERC Cornell
224224
%
225225
% This file is part of MIPS.
@@ -482,20 +482,20 @@
482482
if opt.verbose
483483
if opt.step_control, s = '-sc'; else, s = ''; end
484484
v = mipsver('all');
485-
fprintf('MATPOWER Interior Point Solver -- MIPS%s, Version %s, %s\n (using %s linear solver)', ...
485+
mp_printf('MATPOWER Interior Point Solver -- MIPS%s, Version %s, %s\n (using %s linear solver)', ...
486486
s, v.Version, v.Date, ls);
487487
if opt.verbose > 1
488-
fprintf('\n it objective step size feascond gradcond compcond costcond ');
489-
fprintf('\n---- ------------ --------- ------------ ------------ ------------ ------------');
490-
fprintf('\n%3d %12.8g %10s %12g %12g %12g %12g', ...
488+
mp_printf('\n it objective step size feascond gradcond compcond costcond ');
489+
mp_printf('\n---- ------------ --------- ------------ ------------ ------------ ------------');
490+
mp_printf('\n%3d %12.8g %10s %12g %12g %12g %12g', ...
491491
i, f/opt.cost_mult, '', feascond, gradcond, compcond, costcond);
492492
end
493493
end
494494
if feascond < opt.feastol && gradcond < opt.gradtol && ...
495495
compcond < opt.comptol && costcond < opt.costtol
496496
converged = 1;
497497
if opt.verbose
498-
fprintf('\nConverged!\n');
498+
mp_printf('\nConverged!\n');
499499
end
500500
end
501501

@@ -508,7 +508,7 @@
508508
lambda = struct('eqnonlin', lam(1:neqnln), 'ineqnonlin', mu(1:niqnln));
509509
if nonlinear
510510
if isempty(hess_fcn)
511-
fprintf('mips: Hessian evaluation via finite differences not yet implemented.\n Please provide your own hessian evaluation function.');
511+
mp_printf('mips: Hessian evaluation via finite differences not yet implemented.\n Please provide your own hessian evaluation function.');
512512
end
513513
Lxx = hess_fcn(x, lambda, opt.cost_mult);
514514
else
@@ -527,15 +527,15 @@
527527
% ];
528528
% rc = 1/condest(AAA);
529529
% if rc < 1e-22
530-
% fprintf('my RCOND = %g\n', rc);
530+
% mp_printf('my RCOND = %g\n', rc);
531531
% n = size(AAA, 1);
532532
% AAA = AAA + 1e-3 * speye(n,n);
533533
% end
534534
% bbb = [-N; -g];
535535
% dxdlam = AAA \ bbb;
536536
if any(isnan(dxdlam)) || norm(dxdlam) > max_stepsize
537537
if opt.verbose
538-
fprintf('\nNumerically Failed\n');
538+
mp_printf('\nNumerically Failed\n');
539539
end
540540
eflag = -1;
541541
break;
@@ -598,7 +598,7 @@
598598
end
599599
L1 = f1 + lam' * g1 + mu' * (h1+z) - gamma * sum(log(z));
600600
if opt.verbose > 2
601-
fprintf('\n %3d %10g', -j, norm(dx1));
601+
mp_printf('\n %3d %10g', -j, norm(dx1));
602602
end
603603
rho = (L1 - L) / (Lx' * dx1 + 0.5 * dx1' * Lxx * dx1);
604604
if rho > rho_min && rho < rho_max
@@ -676,20 +676,20 @@
676676
end
677677

678678
if opt.verbose > 1
679-
fprintf('\n%3d %12.8g %10.5g %12g %12g %12g %12g', ...
679+
mp_printf('\n%3d %12.8g %10.5g %12g %12g %12g %12g', ...
680680
i, f/opt.cost_mult, norm(dx), feascond, gradcond, compcond, costcond);
681681
end
682682
if feascond < opt.feastol && gradcond < opt.gradtol && ...
683683
compcond < opt.comptol && costcond < opt.costtol
684684
converged = 1;
685685
if opt.verbose
686-
fprintf('\nConverged!\n');
686+
mp_printf('\nConverged!\n');
687687
end
688688
else
689689
if any(isnan(x)) || alphap < alpha_min || alphad < alpha_min || ...
690690
gamma < eps || gamma > 1/eps
691691
if opt.verbose
692-
fprintf('\nNumerically Failed\n');
692+
mp_printf('\nNumerically Failed\n');
693693
end
694694
eflag = -1;
695695
break;
@@ -703,7 +703,7 @@
703703

704704
if opt.verbose
705705
if ~converged
706-
fprintf('\nDid not converge in %d iterations.\n', i);
706+
mp_printf('\nDid not converge in %d iterations.\n', i);
707707
end
708708
end
709709

lib/mipsver.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616
% See also mpver.
1717

1818
% MIPS
19-
% Copyright (c) 2010-2025, Power Systems Engineering Research Center (PSERC)
19+
% Copyright (c) 2010-2026, Power Systems Engineering Research Center (PSERC)
2020
% by Ray Zimmerman, PSERC Cornell
2121
%
2222
% This file is part of MIPS.
2323
% Covered by the 3-clause BSD License (see LICENSE file for details).
2424
% See https://github.com/MATPOWER/mips for more info.
2525

2626
v = struct( 'Name', 'MIPS', ...
27-
'Version', '1.5.2', ...
27+
'Version', '1.5.2+', ...
2828
'Release', '', ...
29-
'Date', '12-Jul-2025' );
29+
'Date', '23-Jul-2026' );
3030
if nargout > 0
3131
if nargin > 0
3232
rv = v;
3333
else
3434
rv = v.Version;
3535
end
3636
else
37-
fprintf('%-22s Version %-9s %11s\n', v.Name, v.Version, v.Date);
37+
mp_printf('%-22s Version %-9s %11s\n', v.Name, v.Version, v.Date);
3838
end

0 commit comments

Comments
 (0)