Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg1969 committed Apr 10, 2024
1 parent f65c1d1 commit 8b46dcb
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 84 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
uses: matlab-actions/run-command@v2
with:
command: install_sdpt3 -rebuild
- name: Run test
uses: matlab-actions/run-command@v2
with:
command: "install_sdpt3; sqlpdemo -noplot -nopause -exitiferror"
- name: Upload MATLAB MEX files
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -67,6 +71,15 @@ jobs:
which octave-cli.exe
octave-cli.exe --no-gui --eval "install_sdpt3 -rebuild"
if %errorlevel% neq 0 exit /b %errorlevel%
- name: Run test
if: matrix.os != 'windows-latest'
run: octave --eval "install_sdpt3; sqlpdemo -noplot -nopause -exitiferror"
- name: Run test
if: matrix.os == 'windows-latest'
shell: cmd
run: |
set PATH=C:\ProgramData\chocolatey\bin;%PATH%
octave-cli.exe --no-gui --eval "install_sdpt3; sqlpdemo -noplot -nopause -exitiferror"
- name: Upload Octave MEX files
uses: actions/upload-artifact@v4
with:
Expand Down
7 changes: 4 additions & 3 deletions Examples/graph.m → Examples/adjmat.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
%%******************************************************
%% graph: generate random adjacency matrix.
%% adjmat: generate random adjacency matrix.
%% renamed from "graph" by Michael Grant
%%
%% B = graph(n,prob);
%% B = adjmat(n,prob);
%%
%% see maxcut.m
%%
Expand All @@ -11,7 +12,7 @@
%% Last modified: 2 Feb 01
%%******************************************************

function B = graph(n,prob);
function B = adjmat(n,prob);

B = zeros(n,n);
if nargin <= 1; prob = 0.5; end;
Expand Down
47 changes: 35 additions & 12 deletions Solver/sqlpdemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@
%% Last Modified: 16 Sep 2004
%%*****************************************************************

function sqlpdemo
function sqlpdemo( varargin )

randn('seed',0); rand('seed',0); %#ok
feas = input('using feasible starting point? [yes = 1, no = 0] ');
if (feas)
fprintf('\n using feasible starting point\n\n');

if isempty(varargin)
feas = input('using feasible starting point? [yes = 1, no = 0] ');
if (feas)
fprintf('\n using feasible starting point\n\n');
else
fprintf('\n using infeasible starting point\n\n');
end
do_plot = true;
do_pause = true;
exit_if_error = false;
else
fprintf('\n using infeasible starting point\n\n');
feas = any( strcmp( varargin, '-feas') );
do_plot = ~any( strcmp( varargin, '-noplot') );
do_pause = ~any( strcmp( varargin, '-nopause') );
exit_if_error = ~any( strcmp( varargin, '-exitiferror' ) );
end
if do_pause;
pause(1);
end
pause(1);

ntrials = 1;
% iterm = zeros(2,6); infom = zeros(2,6); timem = zeros(2,6);
Expand All @@ -45,7 +58,7 @@
elseif (eg == 3);
disp('******** Max-cut *********');
N = 10;
B = graph(N);
B = adjmat(N);
[blk,At,C,b,X0,y0,Z0] = maxcut(B,feas);
text = 'Maxcut';
elseif (eg == 4);
Expand All @@ -57,7 +70,7 @@
elseif (eg == 5);
disp('**** Lovasz theta function ****')
N = 10;
B = graph(N);
B = adjmat(N);
[blk,At,C,b,X0,y0,Z0] = thetaproblem(B,feas);
text = 'Lovasz theta fn.';
elseif (eg == 6);
Expand Down Expand Up @@ -86,11 +99,21 @@
if (vers==1); legendtext{end+1} = 'HKM'; %#ok
elseif (vers==2); legendtext{end+1} = 'NT'; %#ok
end;
if exit_if_error,
if infoall.termcode ~= 0,
error('Unexpected solver fail');
end
end
end;
h = plotgap(Gap,Feas);
xlabel(text);
legend(h(h~=0),legendtext{:});
fprintf('\n**** press enter to continue ****\n'); pause
if do_plot
h = plotgap(Gap,Feas);
xlabel(text);
legend(h(h~=0),legendtext{:});
end
if do_pause
fprintf('\n**** press enter to continue ****\n');
pause
end
end
end
%%
Expand Down
141 changes: 72 additions & 69 deletions install_sdpt3.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,126 +18,125 @@ function install_sdpt3( varargin )
mpath = mfilename('fullpath');
mpath = mpath( 1 : max([1,strfind(mpath,fs)]) - 1 );
mbase = [ mpath, fs, 'Solver', fs, 'Mexfun' ];
mdir = '';
ISOCTAVE = exist('OCTAVE_VERSION','builtin');
% Note the use of 0.01 here. That's because version 7 had more than 10
% minor releases, so 7.10-7.14 need to be ordered after 7.01-7.09.
VERSION = [1,0.01]*sscanf(version,'%d.%d');
if ISOCTAVE, prog = 'Octave'; else prog = 'Matlab'; end
COMPUTER = computer;
IS64BIT = strcmp(COMPUTER(end-1:end), '64');
mext = mexext;
mdir = '';
ISOCTAVE = exist('OCTAVE_VERSION','builtin');
if ISOCTAVE
prog = 'Octave';
page_output_immediately( true, 'local' );
switch COMPUTER
case 'x86_64-pc-linux-gnu'
mdir = 'o_lin';
case 'x86_64-apple-darwin21.6.0'
mdir = 'o_maci';
case 'aarch64-apple-darwin23.4.0'
mdir = 'o_maca';
case 'i686-w64-mingw32'
mdir = 'o_win';
end
mext = 'mex';
else
prog = 'Matlab';
mext = mexext;
end

%
% We don't want to rebuild the binaries if they're already present, unless
% the user has specifically asked for a rebuild. Frankly, we can't
% guarantee that rebuilding will work.
%

if ISOCTAVE,
page_output_immediately( true, 'local' );
end


line = '---------------------------------------------------------------------------';
fprintf( '\n%s\nSDPT3 installation script\n Directory: %s\n %s %s on %s\n%s\n', ...
line, mpath, prog, version, COMPUTER, line );

if ~need_rebuild,
if ~need_rebuild
fprintf( 'Looking for existing binaries...' );
mdir = '';
if ISOCTAVE && VERSION >= 4,
switch computer,
case 'x86_64-pc-linux-gnu',
mdir = 'o_lin';
case 'x86_64-apple-darwin21.6.0',
mdir = 'o_maci';
case 'aarch64-apple-darwin23.4.0',
mdir = 'o_maca';
case 'i686-w64-mingw32',
mdir = 'o_win';
end
end
if ~isempty(mdir) && ~exist( [ mbase, fs, mdir ], 'dir' ),
mdir = '';
end
nfound = [ 0, 0 ];
for k = 1 : length(targets64),
for k = 1 : length(targets64)
targ = [ targets64{k}, '.', mext ];
if exist( [ mbase, fs, targ ], 'file' ),
if exist( [ mbase, fs, targ ], 'file' )
nfound(1) = nfound(1) + 1;
elseif ~isempty(mdir) && exist( [ mbase, fs, mdir, fs, targ ], 'file' ),
elseif ~isempty(mdir) && exist( [ mbase, fs, mdir, fs, targ ], 'file' )
nfound(2) = nfound(2) + 1;
end
end
if sum(nfound) == 0,
if sum(nfound) == 0
fprintf( 'none found; building...\n' );
need_rebuild = true;
elseif sum(nfound) < length(targets64),
elseif sum(nfound) < length(targets64)
fprintf( 'incomplete set found.\n' );
disp( line );
warning(['Some of the binaries for this platform were found, but some', char(10), ...
'were missing as well. This may mean your download was corrupt;', char(10), ...
'consider downloading and unpacking SDPT3 again. Otherwise, to', char(10), ...
'try rebuilding the MEX files yourself, run this command:', char(10), ...
' install_sdpt3 -rebuild', char(10), ...
line, char(10), char(10)]);
warning(['Some of the binaries for this platform were found, but some', newline, ...
'were missing as well. This may mean your download was corrupt;', newline, ...
'consider downloading and unpacking SDPT3 again. Otherwise, to', newline, ...
'try rebuilding the MEX files yourself, run this command:', newline, ...
' install_sdpt3 -rebuild', newline, ...
line, newline, newline]);
return;
else
fprintf( 'found!\n' );
fprintf( ' If for some reason you need to rebuild the binaries, use this command:\n' );
fprintf( ' install_sdpt3 -rebuild\n' );
end
else
nfound = [1,0];
nfound = [ 1, 0 ];
end

if need_rebuild,
if need_rebuild
disp( 'Attempting to recompile the SDPT3 binaries:' );
% Note the use of 0.01 here. That's because version 7 had more than 10
% minor releases, so 7.10-7.14 need to be ordered after 7.01-7.09.
mdir = '';
libs = {};
flags = {};
if ISOCTAVE,
if ISOCTAVE
% Octave has mwSize and mwIndex hardcoded in mex.h as ints.
% There is no definition for mwSignedIndex so include it here.
% This means that Octave ignores the -largeArrayDims flag.
cmd = 'mkoctfile';
flags{end+1} = '--mex';
if VERSION < 3.08,
if VERSION < 3.08
flags{end+1} = '-DmwSignedIndex=int';
end
else
cmd = 'mex';
flags = {'-O'};
if ispc,
if ispc
flags{end+1} = '-DPC';
elseif isunix,
elseif isunix
flags{end+1} = '-DUNIX';
end
if strcmp(COMPUTER(end-1:end),'64') && ( VERSION >= 7.03 ),
if strcmp(COMPUTER(end-1:end),'64') && ( VERSION >= 7.03 )
flags{end+1} = '-largeArrayDims';
elseif VERSION < 7.03,
elseif VERSION < 7.03
flags{end+1} = '-DmwIndex=int';
flags{end+1} = '-DmwSize=int';
flags{end+1} = '-DmwSignedIndex=int';
end
if VERSION >= 7 && ispc,
if IS64BIT, dirval = 'win64'; else dirval = 'win32'; end
if VERSION >= 7 && ispc
if strcmp(COMPUTER(end-1:end), '64')
dirval = 'win64';
else
dirval = 'win32';
end
libdir = [ matlabroot, fs, 'extern', fs, 'lib', fs, dirval, fs ];
if exist( [ libdir, 'microsoft' ], 'dir' ),
if exist( [ libdir, 'microsoft' ], 'dir' )
libdir = [ libdir, 'microsoft' ];
found = true;
elseif exist( [ libdir, 'msvc60' ], 'dir' ),
elseif exist( [ libdir, 'msvc60' ], 'dir' )
libdir = [ libdir, 'msvc60' ];
found = true;
elseif exist( [ libdir, 'lcc' ], 'dir' ),
elseif exist( [ libdir, 'lcc' ], 'dir' )
libdir = [ libdir, 'lcc' ];
found = true;
end
if found,
if found
libs{end+1} = [ '-L"', libdir, '"' ];
end
end
if VERSION >= 7.05,
if VERSION >= 7.05
libs{end+1} = '-lmwblas';
else
libs{end+1} = '-lmwlapack';
Expand All @@ -147,31 +146,35 @@ function install_sdpt3( varargin )
cd( mbase );
failed = false;
fprintf( 'Template: %s%s <source>%s\n', cmd, sprintf( ' %s', flags{:} ), sprintf( ' %s', libs{:} ) );
for i=1:length(targets64),
for i=1:length(targets64)
targ = [ targets64{i}, '.', mext ];
sfile = [ targets64{i}, '.c' ];
fprintf( ' %s\n', targ );
if ISOCTAVE,
mkoctfile(flags{:}, sfile, libs{:});
else
mex(flags{:}, sfile, libs{:});
try
if ISOCTAVE
mkoctfile(flags{:}, sfile, libs{:});
else
mex(flags{:}, sfile, libs{:});
end
catch
failed = true;
end
end
cd( olddir );
if failed,
fprintf( 'At least one compilation failure occurred.\n' ); %#ok
if failed
fprintf( 'At least one compilation failure occurred.\n' );
nfound = [0,0];
else
fprintf( 'Compilation successful.\n' );
nfound = [1,0];
end
end

if ~any(nfound),
if ~any(nfound)
disp( line );
error(['SDPT3 was not successfully installed.', char(10), ...
error(['SDPT3 was not successfully installed.', newline, ...
'Please attempt to correct the errors and try again.']);
elseif ~no_path,
elseif ~no_path
disp( line );
fprintf( 'Adding SDPT3 to the %s path:\n', prog );
paths = { 'Base', 'Solver', 'HSDSolver', 'Binaries', 'Binaries', 'Examples' ; ...
Expand All @@ -181,22 +184,22 @@ function install_sdpt3( varargin )
ps = pathsep;
pp = [ ps, path, ps ];
already = true;
for k = 1 : size(paths,2),
for k = 1 : size(paths,2)
if paths{3,k} ~= 0 && nfound(paths{3,k}) == 0, continue; end
fprintf( ' %s...', paths{1,k} );
t_dir = mpath;
if ~isempty(paths{2,k}),
if ~isempty(paths{2,k})
t_dir = [ t_dir, fs, paths{2,k} ]; %#ok
end
if ~any(strfind(pp,[ps,t_dir,ps])),
if ~any(strfind(pp,[ps,t_dir,ps]))
already = false;
pp = [ pp, t_dir, ps ]; %#ok
fprintf( 'added.\n' );
else
fprintf( 'already there.\n' );
end
end
if ~already,
if ~already
path(pp);
fprintf( 'Please save the %s path if you want to use SDPT3 from any directory.\n', prog );
end
Expand Down

0 comments on commit 8b46dcb

Please sign in to comment.