% General Recourse Model

% Same example as simple recourxe model.
% With decision of x_2,x_3 and x_4 do not have to be made before stage 2.

% Solution
f = [0 -0.5 0 0 -0.5 0 0]; %  cost function
Aeq = [1 1 1 0 0 0 0 ;
    1 3/4 0 1 0 0 0 ;
    1 0 0 0 1 1 0;
    -3 0 0 0 5/4 0 1]; % Equallity constraint matrix
beq = [2;
    2;
    2;
    2]; % Constraint value vector
A = [0 0 0 0 0 0 0]; % Inequallity constraint matrix
b = [0]; % Constraint value vector
lb = [-1; 0; 0; 0; 0; 0; 0]; % Lower bound vector

ub = [1; Inf; Inf; Inf; Inf; Inf; Inf]; % upper bound vector

% Calculation

[x, fval, EF] = linprog(f,A,b,Aeq,beq,lb,ub);

% EF is the existflag and if it is 1, the function linprog found a feasible
% soultion to the problem.
% Check if the solution is feasible 
if EF > 0
    fprintf('Feasbile solution \n ');
else
    fprintf('Unfeasible solution \n ');
end

% Prints results 
string = ['The solution is [%1.4f %1.4f %1.4f %1.4f %1.4f %1.4f %1.4f] \n ' ...
'the cost function is %2.4f \n '];

fprintf(string, x(:,1),fval );
