function cqp

%
%                    min (x-1)^2 + (y-0.5)^2
%                          st   x+ y <= 1
%                               3x+y <= 1.5
%                              (x,y) >= 0
%
% 22/Jun/99
%

clear

h_space = 0.005;
%h_space = 0.05;
v_space = 0.2;
c_space = 1.0;

[X,Y]=meshgrid(-1.0:h_space:1.5,-0.5:h_space:2.0) ;
[f,fc1,fc2,fc3,fc4,fint] = pf( X , Y ) ;

colormap gray

contourf(X,Y,-fc1,[0 0], 'k' );

hold on

contourf(X,Y,-fc2,[0 0], 'k' );
contourf(X,Y,-fc3,[0 0], 'k' );
contourf(X,Y,-fc4,[0 0], 'k' );

colormap flag

%colormap cool
colormap summer

%colormap('default')

nz = -15:v_space:30 ;
nz2 = -15:c_space:2 ;
contour(X,Y,f,nz,'y');
%contour(X,Y,f,nz,'g');
%[C,h] = contour(X,Y,f,nz,'y');
%clabel(C,nz2)

hold on

contour(X,Y,fint,nz,'g');

contour(X,Y,-fc1,[0 0], 'k' );
contour(X,Y,-fc2,[0 0], 'k' );
contour(X,Y,fc3,[0 0], 'k' );
contour(X,Y,fc4,[0 0], 'k' );

% end

hold off

print -depsc eps/cqp

% penalty function

function [f,fc1,fc2,fc3,fc4,fint] = pf( x, y )
rho = 1000000000000000.0 ;
f = obj( x, y ) ;
fc1= - c1( x, y ) ;
fc2= - c2( x, y ) ;
fc3= c3( x, y ) ;
fc4= c4( x, y ) ;
fint = f-rho*(min(fc1,0)+min(fc2,0)+min(fc3,0)+min(fc4,0)) ;

function o = obj( x, y )
o = (x-1).^2 + (y-0.5).^2 ;

function c = c1( x, y )
c = x + y - 1;

function c = c2( x, y )
c = 3 * x + y - 1.5 ;

function c = c3( x, y )
c = x ;

function c = c4( x, y )
c = y ;

