%% Solve Mixed-Integer Linear Program Starting from Initial Point
% Compare the number of steps to solve an integer programming problem both with and without an initial feasible point. The problem has eight integer variables and four linear equality constraints, and all variables are restricted to be positive.

prob = optimproblem;
x = optimvar('x',8,1,'LowerBound',0,'Type','integer');

% Create four linear equality constraints and include them in the problem.

Aeq = [22    13    26    33    21     3    14    26
    39    16    22    28    26    30    23    24
    18    14    29    27    30    38    26    26
    41    26    28    36    18    38    16    26];
beq = [ 7872
       10466
       11322
       12058];
cons = Aeq*x == beq;
prob.Constraints.cons = cons;

% Create an objective function and include it in the problem.

f = [2    10    13    17     7     5     7     3];
prob.Objective = f*x;

% Solve the problem without using an initial point, and examine the display to see the number of branch-and-bound nodes.

[x1,fval1,exitflag1,output1] = solve(prob);

% For comparison, find the solution using an initial feasible point.

x0.x = [8 62 23 103 53 84 46 34]';
[x2,fval2,exitflag2,output2] = solve(prob,x0);

%

fprintf('Without an initial point, solve took %d steps.\nWith an initial point, solve took %d steps.',output1.numnodes,output2.numnodes)

% Giving an initial point does not always improve the problem. For this problem, using an initial point saves time and computational steps. However, for some problems, an initial point can cause solve to take more steps.
% Copyright 2012 The MathWorks, Inc.