[37] | 1 | function sys = pretty(F) |
---|
| 2 | % PRETTY Pretty print an SET object |
---|
| 3 | % PRETTY(F) tries to print the SET F in a format that |
---|
| 4 | % resembles type-set mathematics. |
---|
| 5 | % |
---|
| 6 | % Requires the Symbolic Math Toolbox |
---|
| 7 | |
---|
| 8 | % Author Johan Löfberg |
---|
| 9 | % $Id: pretty.m,v 1.3 2005/02/04 10:10:27 johanl Exp $ |
---|
| 10 | |
---|
| 11 | error('Pretty is obsolte and no longer supported') |
---|
| 12 | |
---|
| 13 | nlmi = size(F.clauses,2); |
---|
| 14 | |
---|
| 15 | spaces = [' ']; |
---|
| 16 | if (nlmi == 0) & (neq == 0) |
---|
| 17 | disp('empty LMI') |
---|
| 18 | return |
---|
| 19 | end |
---|
| 20 | |
---|
| 21 | lmiinfo{1} = 'Matrix inequality'; |
---|
| 22 | lmiinfo{2} = 'Element-wise inequality'; |
---|
| 23 | lmiinfo{3} = 'Equality constraint'; |
---|
| 24 | lmiinfo{4} = 'Second order cone constraint'; |
---|
| 25 | |
---|
| 26 | % Needed for formating |
---|
| 27 | infolen = max(cellfun('length',lmiinfo)); |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | % Check if there are any handles, sizes of strings |
---|
| 31 | max_ns = 0; |
---|
| 32 | max_nh = 0; |
---|
| 33 | for i = 1:nlmi |
---|
| 34 | max_ns = max(max_ns,length(F.clauses{i}.symbolic)); |
---|
| 35 | max_nh = max(max_nh,length(F.clauses{i}.handle)); |
---|
| 36 | end |
---|
| 37 | |
---|
| 38 | ns = min(40,max_ns); |
---|
| 39 | nh = min(40,max_nh); |
---|
| 40 | nt = infolen+3; |
---|
| 41 | nh = 40; |
---|
| 42 | |
---|
| 43 | if nlmi>0 |
---|
| 44 | nn = ceil(log10(nlmi+1)+1); |
---|
| 45 | disp('*************************'); |
---|
| 46 | disp('Inequality constraints'); |
---|
| 47 | disp('*************************'); |
---|
| 48 | for i = 1:nlmi |
---|
| 49 | type = lmiinfo{F.clauses{i}.type}; |
---|
| 50 | handle = truncstring(F.clauses{i}.handle,nh); |
---|
| 51 | number = strjust(fillstring(['#' num2str(i)],nn),'right'); |
---|
| 52 | if isempty(handle) |
---|
| 53 | infostr = sprintf('%s %s',number,type); |
---|
| 54 | else |
---|
| 55 | infostr = sprintf('%s %s (%s)',number,type,handle); |
---|
| 56 | end |
---|
| 57 | disp(infostr); |
---|
| 58 | prettyhack(F.clauses{i}.symbolic); |
---|
| 59 | disp(' ' ); |
---|
| 60 | end |
---|
| 61 | disp(' '); |
---|
| 62 | else |
---|
| 63 | disp('*************************'); |
---|
| 64 | disp('No inequality constraints'); |
---|
| 65 | disp('*************************'); |
---|
| 66 | end |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | function x= truncstring(x,n) |
---|
| 70 | if length(x) > n |
---|
| 71 | x = [x(1:n-3) '...']; |
---|
| 72 | end |
---|
| 73 | |
---|
| 74 | function x = fillstring(x,n) |
---|
| 75 | x = [x blanks(n-length(x))]; |
---|
| 76 | |
---|
| 77 | % Works for some type of problems |
---|
| 78 | function prettyhack(F) |
---|
| 79 | |
---|
| 80 | % Some hacks to make it work |
---|
| 81 | Y = F; |
---|
| 82 | F = strrep(F,'''','^T'); |
---|
| 83 | F = strrep(F,'diag','Diag'); |
---|
| 84 | F = strrep(F,'min','Min'); |
---|
| 85 | F = strrep(F,'max','Max'); |
---|
| 86 | |
---|
| 87 | try |
---|
| 88 | TypeofConstraint = 0; |
---|
| 89 | delimiters = {'.<','.>','<.','>.','<','>','=',''}; |
---|
| 90 | delindex = 0;indtodel = []; |
---|
| 91 | while isempty(indtodel) & (delindex<=7) |
---|
| 92 | delindex = delindex+1; |
---|
| 93 | indtodel = findstr(F,delimiters{delindex}); |
---|
| 94 | end |
---|
| 95 | switch delindex |
---|
| 96 | case 5 %< |
---|
| 97 | TypeofConstraint = 1; |
---|
| 98 | ind_start = indtodel-1; |
---|
| 99 | ind_end = indtodel+1; |
---|
| 100 | REVERSE = 1; |
---|
| 101 | dell = '<'; |
---|
| 102 | case 6 %> |
---|
| 103 | TypeofConstraint = 1; |
---|
| 104 | ind_start = indtodel-1; |
---|
| 105 | ind_end = indtodel+1; |
---|
| 106 | REVERSE = 0; |
---|
| 107 | dell = '>'; |
---|
| 108 | case 1 %.< |
---|
| 109 | TypeofConstraint = 2; |
---|
| 110 | ind_start = indtodel-1; |
---|
| 111 | ind_end = indtodel+2; |
---|
| 112 | REVERSE = 1; |
---|
| 113 | dell = '<'; |
---|
| 114 | case 2 %.> |
---|
| 115 | TypeofConstraint = 2; |
---|
| 116 | ind_start = indtodel-1; |
---|
| 117 | ind_end = indtodel+2; |
---|
| 118 | REVERSE = 0; |
---|
| 119 | dell = '>'; |
---|
| 120 | case 7%= |
---|
| 121 | TypeofConstraint = 3; |
---|
| 122 | ind_start = indtodel-1; |
---|
| 123 | ind_end = indtodel+1; |
---|
| 124 | REVERSE = 0; |
---|
| 125 | dell = '='; |
---|
| 126 | case {3,4} |
---|
| 127 | error('Incorrect argument. Perhaps you mean .> or .<'); |
---|
| 128 | otherwise |
---|
| 129 | error('Incorrect argument. Could not find <=>.>.<') |
---|
| 130 | end |
---|
| 131 | |
---|
| 132 | LeftHand = char(sym(F(1:ind_start))); |
---|
| 133 | RightHand = char(sym(F(ind_end:end))); |
---|
| 134 | |
---|
| 135 | maplemex('interface(prettyprint=true);'); |
---|
| 136 | disp(' ') |
---|
| 137 | r = maplemex(['print(' LeftHand ' ' dell ' ' RightHand ');']); |
---|
| 138 | if ~isempty(r) |
---|
| 139 | disp(' ') |
---|
| 140 | disp([strjust(fillstring(Y,79),'center') ' (cannot be displayed in Maple)']) |
---|
| 141 | end |
---|
| 142 | catch |
---|
| 143 | disp(' '); |
---|
| 144 | disp([strjust(fillstring(Y,79),'center') ' (cannot be displayed in Maple)']) |
---|
| 145 | end |
---|
| 146 | maplemex('interface(prettyprint=false);'); |
---|
| 147 | |
---|