function[Fmatrix, xmatrix] = Pareto_lincomb(xo,W, VLB,VUB,options)

% function[Fmatrix, xmatrix] = Pareto_lincomb(x0,W,VLB,VUB,options)
%
% This program solves the same MOP as the one being solved by the NBI method,
% and is mainly used for comparison of Pareto point spreads and flop counts.
% This finds Pareto optimal points by minimizing w'F(x).
% The weights can be specified as rows in W
% The user must pass the number of equality constraints in options(13) 
%
% The function and constraints [f,g] are specified in lincombFUN.m
%	Other files called :	Fns.m (to evaluate objectives - shadowMin)
%				shadow_data.m (to get shadowMin)

global w shadowMin

% shadowMin is needed only so that Fns.m can be used
more off
if nargin==0, xo = input(' Enter xo as a vector  '); end
xo = assert_col_vec(xo);
x = xo';
nvars = length(xo);
if nargin < 5, options(1) = 1; end
if nargin < 4, VUB = []; end
if nargin < 3, VLB = []; end



 if nargin < 2
  W = [1 0; 10 1; 8 1; 6 1; 5 1; 4 1; 3 1; 2.5  1; 2 1; 1.5 1; 1 1; 1 1.5; 1 2; 1 2.5; 1 3; 1 4; 1 5; 1 6; 1 8; 1 9; 1 10; 0 1]; 
  end

  W = W'; % n x number of separate weight vectors


n = size(W, 1); % no. of objective functions
[shadowMin, shadow_x]  = shadow_data; % only needed for using Fns.m

% if resp == 1 % INCORPORATE LATER
Flop = 0;
Failures = 0;
% Start at minimizer of f2
Fmatrix = Fns(shadow_x(2,:)) + shadowMin;
xmatrix = shadow_x(2,:);


for i = 2: (size(W,2) - 1)

	w = W(:,i); % ith column of W
	w = w/sum(w); % ASSUMING there are no negative weights

	flops(0);

	[x, fiasco, f] = constr_mo('lincombFUN',x,options,VLB,VUB)
% starting point is the previous optimal point

	Fmatrix = [Fmatrix, Fns(x) + shadowMin]; % n x num_wts
	xmatrix = [xmatrix; x];
  
	Flop = [Flop, flops];
	Failures = [Failures, fiasco];

end

% Append minimizer of f1 to list
Fmatrix = [Fmatrix, Fns(shadow_x(1,:)) + shadowMin];
xmatrix = [xmatrix; shadow_x(1,:)];
Flop = [Flop, 0];
Failures = [Failures, 0];

% Flop report

format short
disp('Report on number of floating point operations')

Flop_report = [W; Flop/1000; Failures]';

net_flops = sum(Flop);
disp('	 	  w	       #flops(in K)     failure')
disp(Flop_report)
net_flops

pause = input(' Hit return to cont ...');


if n == 2, % plot Pareto points
	plot(Fmatrix(1,:), Fmatrix(2,:), 'r*', Fmatrix(1,:), Fmatrix(2,:), 'b--');
	xlabel('F(1)')
	ylabel('F(2)')
	title('Efficient points obtained by minimizing convex combinations of objectives')
	
	save_plot = input('Save plot to a .ps file ? (1 for yes, anything else for no)  ');
	if (save_plot == 1)
		enter_title = input('Want to enter a new title for the plot ? (1 for yes) ');
		if (enter_title == 1)
			plot_title = input('Enter title in single quotes  ');
			eval(['title(' 'plot_title' ')']);
		end
	
		axes_relabel;

		filename = input('Enter name of file with .ps extension (in single quotes)   ');
		eval(['print -depsc ' filename]);
	end
end
Fmatrix = Fmatrix';
