Daniel@0: function success = save_svmlight_inequalities(lhs, rhs, factors, file) Daniel@0: % success = save_svmlight_inequalities(lhs, rhs, file) Daniel@0: % Daniel@0: % saves the optimisation problem given by lhs and rhs to Daniel@0: % a svmlight data file. the individual equations can Daniel@0: % be weighted using Daniel@0: % Daniel@0: % success = save_svmlight_inequalities(lhs, rhs, factors, file) Daniel@0: Daniel@0: if nargin == 3 Daniel@0: file = factors; Daniel@0: factors = []; Daniel@0: end Daniel@0: Daniel@0: % open file Daniel@0: fid = fopen(file, 'w+'); Daniel@0: if fid < 1 Daniel@0: success = 0; Daniel@0: return; Daniel@0: end Daniel@0: Daniel@0: try Daniel@0: % write individual constraint rows Daniel@0: for i = 1:size(lhs,1) Daniel@0: Daniel@0: % --- Daniel@0: % print rows:" rhs #fnum:#fval #fnum:#fval #fnum:#fval ..." Daniel@0: % --- Daniel@0: Daniel@0: % print right hand side Daniel@0: fprintf(fid,'%d ', rhs(i)); Daniel@0: Daniel@0: % print cost factors if availablefactor Daniel@0: if (numel(lhs{i,1}) > 0) && (numel(factors) >= i) Daniel@0: Daniel@0: fprintf(fid,'cost:%f ', factors(i)); Daniel@0: end Daniel@0: Daniel@0: % print left hand side Daniel@0: for j = 1:numel(lhs{i,1}) Daniel@0: Daniel@0: fprintf(fid,'%d:%2.16f ', lhs{i,1}(j), lhs{i,2}(j)); Daniel@0: end Daniel@0: Daniel@0: % finish line Daniel@0: fprintf(fid,'\n'); Daniel@0: end Daniel@0: catch Daniel@0: success = 0; Daniel@0: fclose(fid); Daniel@0: return; Daniel@0: end Daniel@0: success = 1; Daniel@0: fclose(fid); Daniel@0: Daniel@0: Daniel@0: