function [Pareto_Fmat, Pareto_xmat, NBImultiplrs] = NBI(x0, spac_1, nvars, n, ne, ni, NBImultip, VLB, VUB, tol)

% [Pareto_Fmat, Pareto_xmat, NBImultiplrs] = NBI(x0, spac_1, nvars, n, ne, ni, NBImultip, VLB, VUB, tol)
%
% 	This is an implementation of Normal-Boundary Intersection for finding 
%	Pareto optimal points of multi-objective problems using the quasi-normal
% 	as developed by Das and Dennis (1996). 
%	
%	The user inputs are as follows:
%
%	x0 :	Starting point for the finding the min of f_1
%	spac_1:	an integer whose reciprocal is the discretization gridsize on each
%		each component of w
%	nvars:	number of variables, i.e. dim(x0)
%	n:	number of objective functions
%	ne:	number of equality constraints
%	ni:	number of inequality constraints
%	NBImultip: 1, if multipliers of \Phi \beta + t n_hat + F(x) are needed, 0 if not
%	VLB:	vector of lower bounds on the variables
%	VUB:	vector of upper bounds on the variables
%
%	User-defined files required:
%	Fns.m (evaluates the objective vector F(x) at a given x)
%	FUN.m (evaluates the constraints at a given x)
%	FUN1.m (needed for finding the shadow minimum)
%	shadow_data.m ([shadowMin,shadow_x] = shadow_data, for user-provided F*)
%		If the functions and constraints are in closed algebraic form,
%		the above can be generated by calling createshootfiles.m
%
%	Other pre-written files required:
%	max_tFUN.m (returns function and constraints for actual NBI subproblem)
%	NBIgeneral5.m (performs NBI for n = 2)
%	NBImorethan2.m (NBI for n > 2)
%	constr_mo.m (a slightly customized version of Matlab's NLP solver 'constr')
%	assert_col_vec.m
%       plot_options.m
%	axes_relabel.m
%	NBImultipliers.m (calls NBImultplrFUN.m)
%	Pareto_lincomb.m
%	lincombFUN.m
%		
%	For n > 2, the following files are specifically needed:
%	Generate_wts.m
%	wtgener_test.m
%	num_subahead.m
%	numberOfwts.m
%	
% 	Copyright (c) 1996  Indraneel Das, Rice University 
%

	
	if nargin<3, nvars = input('Enter the number of variables in your problem   '); end
	if nargin<4, n = input('Enter the number of objective functions in your problem   '); end
	if nargin<5, ne = input('Enter the number of equality constraints      '); end
	if nargin<6, ni = input('Enter the number of inequality constraints      '); end
	if ne > 0,
		options(13) = ne;
	end
	

	if nargin < 1, x0 = input('Enter xo   '); end
	if length(x0) ~= nvars,
		disp(' The xo you entered has incorrect dimensions')
		x0 = input('Enter xo correctly  ');
	end

	if nargin < 7, NBImultip = 0; end
	if nargin < 8, VLB = []; end
	if nargin < 9, VUB = []; end
	if nargin < 10, tol = 1e-4; end
	options(1) = 1;
	options(2) = tol; % constr.m tolerance for x
	options(3) = tol; % constr.m tolerance for f
	options(14) = 150*nvars; % max # of iterations

	if n==2
		W = [0:1/spac_1:1]; W = [W; 1 - W]';
		[Pareto_Fmat, Pareto_xmat, NBImultiplrs] = NBIgeneral5(x0, W, nvars, n, ne, ni, NBImultip,VLB, VUB, tol);
	elseif n>2
		[Pareto_Fmat, Pareto_xmat, NBImultiplrs] = NBImorethan2(x0, spac_1, nvars, n, ne, ni, NBImultip, VLB, VUB, tol);
	end

response = input('Want special plots ? (1 for yes, anything else otherwise)   ');
if  (response == 1),
	plot_options ( Pareto_Fmat, Pareto_xmat)
end

more_plots = 1;

while ((more_plots == 1)&(response == 1))
	more_plots = input('Want more special plots ? (1 for yes)  ');
	if more_plots == 1
		plot_options(Pareto_Fmat, Pareto_xmat);
	end
end	

%***********************************************************************

if (n == 2)
 disp('  ')
 disp('-------------------------------------')
 disp('  ')

 fprintf('Solve the same problem using convex combinations?');
 LCquery =input('(i.e. min wTF(x) for various w,  1 for yes)  ');

 if LCquery == 1
	fprintf('Using the uniformly spread NBI parameters beta for w')
	options(13) = ne;
	[Fmatrix, xmatrix] = Pareto_lincomb(x0, W, VLB,VUB,options)

	waiting = input('Hit return to continue. ....');

	if NBImultip == 1,
		ask_again = input(' Solve using NBI multipliers as w ? (1 for yes)  ');
		if ask_again == 1,
			Pareto_lincomb(x0, NBImultiplrs, VLB,VUB,options)
		end
	end
 end

end