function [prob] = fiveconprob(p)

prob = struct('n',{0},'m',{0},'bl',{0},'bu',{0},'cl',{0},'cu',{0},'obj',{0},'cons',{0},'hess',{0},'x',0,'name',0);
prob.n = 3;
prob.m = 6;
prob.me = 1;
%prob.cl = [0;p(2);p(1)];
%prob.cu = [Inf;Inf;p(1)];

prob.dcdp = [-1; 0; 0; 0; 0; 0];

prob.name = 'Problem with Four Active Constraints';
prob.x = zeros(3,1);

prob.obj = (@(x)(objective(x,p)));
prob.cons = (@(x)(constraint(x,p)));
prob.hess = (@(x,y)(hessian(x,y,p)));
prob.chess = (@(x)(conhess(x,p)));
end

function [f,g] = objective(x,p)

f = -x(2);
g = [0; -1; 0];
end

function [c,J] = constraint(x,p)
    c=[x(3)-p;x(1);-x(2)^3-x(1)*x(2)-x(1)^2+(x(3))^3;-exp(x(1))-exp(x(2))+exp(x(3))+1;-x(1)^2-x(1)*x(2)+(x(2)-(2.5+0.5*x(3)))^2-1*(2.5+0.5*x(3))^4*x(1)-100*(x(2)-(2.5+0.5*x(3)));...
        -x(1)^2+x(1)*x(2)+(x(2)-(2.5+0.5*x(3)))^2+1*(2.5+0.5*x(3))^4*x(1)-100*(x(2)-(2.5+0.5*x(3)))];
    
    J=zeros(6,3);
    J(1,3) = 1;
    J(2,1) = 1;
    
    J(3,1) = -x(2)-2*x(1);
    J(3,2) = -3*x(2)^2-x(1);
    J(3,3) = 3*(x(3)^2);
    J(4,1) = -exp(x(1));
    J(4,2) = -exp(x(2));
    J(4,3) = exp(x(3));
    J(5,1) = -2*x(1)-x(2)-1*(2.5+0.5*x(3))^4;
    J(5,2) = -x(1)+2*(x(2)-(2.5+0.5*x(3)))-100;
    J(5,3) = -(x(2)-(2.5+0.5*x(3)))-2*(2.5+0.5*x(3))^3*x(1)+50;
    J(6,1) = -2*x(1)+x(2)+1*(2.5+0.5*x(3))^4;
    J(6,2) = x(1)+2*(x(2)-(2.5+0.5*x(3)))-100;
    J(6,3) = -(x(2)-(2.5+0.5*x(3)))+2*(2.5+0.5*x(3))^3*x(1)+50;
end

function [H] = hessian(x,y,p)
H=zeros(3);
y=y;
H(1,1) = 2*y(3)+y(4)*exp(x(1))+2*y(5)+2*y(6);
H(1,2) = y(3)+y(5)-y(6);
H(1,3) = 2*(2.5+0.5*x(3))^3*y(5)-2*(2.5+0.5*x(3))^3*y(6);

H(2,1) = y(3)+y(5)-y(6);
H(2,2) = 6*y(3)*x(2)+y(4)*exp(x(2))-2*y(5)-2*y(6);
H(2,3) = y(5)+y(6);

H(3,1) = 2*(2.5+0.5*x(3))^3*y(5)-2*(2.5+0.5*x(3))^3*y(6);
H(3,2) = y(5)+y(6);
H(3,3) = -2*y(3)*3*x(3)-y(4)*exp(x(3))-y(5)*(0.5-3*(2.5+0.5*x(3))^2*x(1))-y(6)*(0.5+3*(2.5+0.5*x(3))^2*x(1));
end

function HC = conhess(x,p)
HC = zeros(3,3,6);
HC(1,1,3) = -2;
HC(1,2,3) = -1;
HC(2,1,3) = -1;
HC(2,2,3) = -6*x(2);
HC(3,3,3) = 6*x(3);
HC(1,1,4) = -exp(x(1));
HC(2,2,4) = -exp(x(2));
HC(3,3,4) = exp(x(3));

HC(1,1,5) = -2;
HC(1,2,5) = -1;
HC(1,3,5) = -2*(2.5+0.5*x(3))^3;
HC(2,1,5) = -1;
HC(2,2,5) = 2;
HC(2,3,5) = -1;
HC(3,1,5) = -2*(2.5+0.5*x(3))^3;
HC(3,2,5) = -1;
HC(3,3,5) = (0.5-3*(2.5+0.5*x(3))^2*x(1));
HC(1,1,6) = -2;
HC(1,2,6) = 1;
HC(1,3,6) = 2*(2.5+0.5*x(3))^3;
HC(2,1,6) = 1;
HC(2,2,6) = 2;
HC(2,3,6) = -1;
HC(3,1,6) = 2*(2.5+0.5*x(3))^3;
HC(3,2,6) = -1;
HC(3,3,6) = (0.5+3*(2.5+0.5*x(3))^2*x(1));

end