#include <stdio.h>
#include <math.h>
#include "define.h"

#define PI	3.141592
#define	NVAR	2	// number of variables
#define NINQ	0	// number of inequality constraint 
#define	NCND	1	// number of equality constraint

double ans;

double obj(int n, double *x)	// target function
{
	ans = pow(x[0],2)+pow(x[1],2)-2*x[0]-3*x[1]-3; // f(x,y)=x^2+y^2-2x-3y-3

	return ans;
}

double *ineq(int n, double *x, int m, double *d)	// inequality constraint 
{
	d[0] = -x[0];	// x[0]>0
	d[1] = -x[1];	// x[1]>0
 
	return 0;
}

double *cond(int n, double *x, int l, double *d)	// equality constraint 
{
	d[0] = x[0]+x[1]-10;  // Constraint : x+y-10=0
  
	return 0;
}

int main()
{
	double	x[NVAR];
	 double	length = 1.00;
	 enum status	stat;
	int cnt=0;

	ans = 0;

    x[0] = 0.00001;		// input initial value
    x[1] = 0.00001;

	stat = MultiplierMethodSimplex(NVAR, obj, NINQ, ineq, NCND, cond, x, length, 100, 1.0e-6);
    if (stat == success) {
      printf("x = %lf, y = %lf, Min = %lf\n",x[0],x[1],ans);
    } else {
      printf("status = %d\n", stat);
    }
 
  return 0;
}