program tminer;
uses
	xMatDefs, MatReal, {$I xCrt}, miner;

const
	MaxNIters= 10000;
	errx= 1e-5;
	Memoria= 0.4;
	AmpV= 10000;


var
	x: TVectR;
label CPS;


function costo( kf: integer; var X: TVectR ): NReal; far;
var
	m: NReal;
begin
	m:= sqr( X.e(1) - 1) + AmpV* sqr( X.e(2) -5 );{abs( X.e(2) -5 );}
	 costo:= m;
end;

procedure grad(kf: integer; var g, x: TVectR); far;
begin
	g.pon_e(1, 1*2*(X.e(1)-1));
	g.pon_e(2, 1*(X.e(2)-5));
	{
	if x.e(2) > 5 then
		g.pon_e(2, AmpV)
	else
		g.pon_e(2, -AmpV);
		}
end;

var
	NIters: longint;
	Convergio: boolean;
	kmem: integer;
	Valcosto: NReal;

begin
	x.init( 2);

		x.ceros;

		MinerCPX(
				costo,
				grad,
				X,
				0.5,
				errx,
				MaxNIters,
				NIters,
				Valcosto,
				Convergio);

		writeln('CPXMult: ',CPXMult:12:4,' CPXDiv: ',CPXDiv:12:4,'  CPXNIters: ', NIters);
		if convergio then
			writeln( 'x1: ',X.e(1), '  x2: ', X.e(2),' f(x): ', costo(1, X) )
		else
			writeln(' NO CONVERGIO ');
		readln;

		x.ceros;
		MinerCPS(
				costo,
				grad,
				X,
				0.3,
				errx,
				MaxNIters,
				NIters,
				Valcosto,
				Convergio);

		writeln('CPSMult: ',CPSMult:12:4,' CPSDiv: ',CPSDiv:12:4,'  CPSNIters: ', NIters);
		if convergio then
			writeln( 'x1: ',X.e(1), '  x2: ', X.e(2),' f(x): ', costo(1, X) )
		else
			writeln(' NO CONVERGIO ');
		readln;

		 x.ceros;
		 MinerFPP(
					 costo,
					 grad,
					 X,
					 1,
					 errx,
					 MaxNIters,
					 NIters,
					 Valcosto,
					 Convergio,
					 memoria);
		 writeln(	'  NIters: ',	NIters );
		 if convergio then
			 writeln( 'x1: ',X.e(1), '  x2: ', X.e(2),' f(x): ', costo(1, X) )
		 else
			 writeln(' NO CONVERGIO ');
	x.done;
end.





