function [value] = target(pts,domain,V,deg);

%%%%%
% DE target function
%
% returns configuration value
% in the target function
%
% Parameters 
% pts : points
% domain : 1 for square, 2 for disk, 3 for interval
% V : Vandermonde matrix associated to the WAM
% deg : polynomial degree
%%%%%


        V_pts = vand(deg,pts, domain);		
		if (boundary(pts,domain) == 0)
			value = 10^30;
		else
            value=norm(V_pts'\V',1);
		end

end

function [ok] = boundary(pts,domain);

%%%%%
% Double-checks that no point
% in the configuration is outside
% of the domain
%%%%%

    L = size(pts,1);
	if (size(pts,2) > 1)
        X=pts(:,1); Y=pts(:,2);
	end

    switch domain

	case 1
    XV=[1 -1 -1 1 1]; YV=[1 1 -1 -1 1]; 
    [IN,ON]=inpolygon(X,Y,XV,YV);
	total = sum(IN)+sum(ON);

	case 2
	IN = (X.^2 .+ Y.^2 -1 <= 0);
	total = sum(IN);

	case 3
	IN = (pts <= 1) + (pts >= -1) -2;
	total = L - sum(IN);

	otherwise
	total = 0;

	end

    if (total) < L
	    ok = 0;
    else	
		ok = 1;
	end
end
