intlinprog
Output Function and Plot Function Syntaxintlinprog
can call an output function
or plot function after certain events occur in the algorithm. These
events include completing a phase of the algorithm such as solving
the root LP problem, adding cuts, completing a heuristic successfully,
finding a new integer feasible solution during branchandbound, appreciably
improving the relative gap, or exploring a number of nodes in a branchandbound
tree.
Caution
intlinprog
output functions and plot functions differ from those in other
solvers. For output functions or plot functions in other Optimization Toolbox™ solvers, see Output Function and Plot Function Syntax and Plot Functions.
There is one builtin output function: savemilpsolutions
.
This function collects the integer feasible points that the algorithm
finds at event times. It puts the feasible points in a matrix named xIntSol
in
your base workspace, where each column is one integer feasible point.
It saves the objective function values in a vector named fIntSol
,
where each entry is the objective function of the corresponding column
in xIntSol
.
There is one builtin plot function: optimplotmilp
.
This function plots the internallycalculated bounds on the best objective
function value. For an example of its use, see Factory, Warehouse, Sales Allocation Model: SolverBased.
Call output functions or plot functions by passing the OutputFcn
or PlotFcn
namevalue
pairs, including the handle to the output function or plot function.
For example,
options = optimoptions(@intlinprog,'OutputFcn',@savemilpsolutions,'PlotFcn',@optimplotmilp); x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,options);
If you have several output functions or plot functions, pass them as a cell array.
options = optimoptions(@intlinprog,'OutputFcn',{@savemilpsolutions,@customFcn});
Write your own output function or plot function using this syntax:
function stop = customFcn(x,optimValues,state)
intlinprog
passes the data x
, optimValues
,
and state
to your function.
stop
— Set to true
to
halt intlinprog
. Set to false
to
allow intlinprog
to continue.
x
— Either an empty matrix []
or
an N
by1
vector that is a feasible
point. x
is nonempty only when intlinprog
finds
a new integer feasible solution. x
can be nonempty
when phase
is 'heuristics'
or 'branching'
.
optimValues
— A structure
whose details are in optimValues Structure.
state
— One of these values:
'init'
— intlinprog
is
starting. Use this state to set up any plots or data structures that
you need.
'iter'
— intlinprog
is
solving the problem. Access data related to the solver’s progress.
For example, plot or perform file operations.
'done'
— intlinprog
has
finished solving the problem. Close any files, finish annotating plots,
etc.
For examples of writing output or plot functions, see the builtin
functions savemilpsolutions.m
or optimplotmilp.m
.
optimValues
StructureoptimValues Field  Meaning 

phase  Phase of the algorithm. Possible values:

fval  Best objective function found so far at an integer feasible
point. When 
lowerbound  Global lower bound of the objective function value. Empty
when 
relativegap  Relative gap between 
numnodes  Number of explored nodes. Nonzero only when 
numfeaspoints  Number of integer feasible solutions found. 
time  Time in seconds spent so far, measured with 