File Exchange

image thumbnail


version (138 KB) by Koert Kuipers
BNB20 solves mixed integer nonlinear optimization problems


Updated 15 Aug 2003

No License

BNB20 solves mixed integer nonlinear optimization problems. It is a branch-and-bound type algorithm.

Cite As

Koert Kuipers (2021). bnb (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (55)

karim el moutaouakil

Koert Kuipers it will be very intersting to give an example about how to use input/out put of your BNB20 (a simple example that works on). Many thanks!!


One important thing seems to be to define the functions in separate file and not in the same file as the call to bnb.
Also from what I saw it is required to refer to the function in the call under the form 'fun' and not another one @fun etc.
Despite following these points, I'm also getting an issue with nonlcon since I get the rather upsetting message "nonlcon cause error". It would be so helpful to have one good example here which includes the definition of the functions!

Shalanika Dayarathna

Has anyone solved the issue with defining the function?


rihane siham

rihane siham

it is possible to solve multi objectifs problèmes with this algorithm

qiang zhang

qiang zhang

Edouard Schaal

Is it possible to solve continuous non convex optimization problems with this package?

Karsten Labusch

When i try to start the BNBGUI I always get this error message:

Cannot find an exact (case-sensitive) match for 'bnbguicb'

The closest match is: BNBGUICB in C:\Users\User\Documents\MatlabProgramm\Hauptprogramm\bnb20\BNBGUICB.m

Error while evaluating Menu Callback

Does this work with black-box objective function ?



I used this package for portfolio optimization with threshold trade constraints. Thanks Koert for posting it! One suggestion for other users: the BNB GUI does not work anymore. So if you get errors with the last rows of BNB20, you can delete them:
%if ishandle(handleupdate)
% taghandleupdate=get(handleupdate,'Tag');
% if strcmp(taghandleupdate,'update BNB GUI')
% close(handleupdate);
% end;
% end;
% eval(['warning ',currentwarningstate]);

Bradley Ridder

It doesn't work at all!

zhneghong jin

fun must be a string

function f=fun(x)



fun must be a string
Can you please let us know how to define the function?

Monique Bakker

M N Alam, I have the same issue of errmsg= fun must be a string.
How did you solve it?


amna sakli

please houw to use this BNB with rosenbrock function ? what inputs should i put ? thkx

Chucolate Brownies

Dear Koert Kuipers and all user,

I have just used bnb file and I try to run it on MATLAB2012. I found error like this below.

>> BNB20

ans =

BNB needs at least 2 input arguments.

How to fix it? Could you please explain me? and How to use this code with my function?

If you have something to share, please suggest me.

Thank you in advance.

M N Alam

The problem is

function f = myfun(x)
f = x(1)^2 + 2*x(2)^2;

function [c,ceq] = mycon(x)
c = 1.5/x(1) - x(2);
ceq = [];

M N Alam

I will be very much thankful to the person who can solve my problem.

When I am running the problem with the following run file within stars (***);
clear all
opts = optimset;

[errmsg,Z,X,t,c,fail] = BNB20(@myfun,x0,xstat,xl,xu,a,b,aeq,beq,@mycon,setts,opts,varargin)

The results are as follows:

errmsg =

fun must be a string.

Z =


X =


t =


c =


fail =



Kindly find out the error with the codes:
Thanking you


Thank for your great job in practical BNB implementation.

I wonder does the method of B&B can always find the "optimal value" of Convex Mixed Integer Nonlinear Programming? Is there any reference or prove to above statement?

Thanks a lot.

mehrdad nyazi

i want to solve the flow shop scheduling with branch and bound algorithm.i can not write and write it in matlab code! can any body help me? :(

Jehan Ziad Ghafuri

How can I write & run this example??
%function (maxz)=-x1+4x2
%subject to
% 5x1+10x2<=49
% x1 <= 5
%x1,x2>=0, x1&x2 are integers

And by using which file??



I am using Matlab R2011b -

And when I type BNBGUI this message appear:

Cannot find an exact (case-sensitive) match for 'bnbguicb'.
Do you want: BNBGUICB
(in C:\MATLAB\R2011b\BNBGUICB.m)?

Error in BNBGUI (line 29)

What is wrong? Thanks!!!!


Thank you so much for providing this file. It really helps.


I had to dig into the code to get this sucker to work (sans GUI). Below is a matlab file for a function of a single variable in FuncEval with nonlinears in constraintEval. Also, note that you will get an error when it's done. You can either ignore it, or comment out the very last line of BNB20.m . If your function requires separate inputs other than x, put those in the call to BNB20 after options.

%% BNB Call
% Initialize x0, Column Vector
x0 = [1];
% BNB variable types
% Continuous for xstatus(i)=0
% Integer for xstatus(i)= 1
% Fixed for xstatus(i)=2
xstat = [1];
% this problem has no inequality constraints
A = [];
b = [];
% this problem has no equality constraints
Aeq = [];
beq = [];
% Given Bounds in problem statement
lb = [ ...
ub = [ ...
% Set settings
setts = []; % Leave as default
% Set options
options = optimset('Display','iter','TolX',1e-4,'maxSQPiter',Inf)
%% Run the BNB Code!
[errmsg,Z,X,t,c,fail] = BNB20('FuncEval',x0, ...


I get the same error every time as well, and can't figure out what's going on.
who can submit a successful example?


I get the same error every time as well, and can't figure out what's going on.


I'm trying to run a mixed integer nonlinear programming (MINLP) problem using BNB20. However, irrespective of the complexity of my algorithm, I'm always getting the following results. It would be great if anyone can explain this result.

*** searched 0 % of tree
*** Z : Inf
*** t : 0.0 secs
*** c : 0 cycles
*** fail : 0 cycles
Optimization terminated: first-order optimality measure less
than options.TolFun and maximum constraint violation is less
than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
11 31
12 32
13 33
??? Error using ==> lt
Matrix dimensions must agree.

Error in ==> BNB20 at 247
elseif all(abs(round(x(K))-x(K))<errx) & convflag>0


I have a problem with this algorithm I start it like that
[errmsg,Z,X,t,c,fail] = BNB20(fun,para',[0 0 1 1 1 1]',[150 125 3 2 11 1]',ub',[],[],[],[],'problemconstraints',[],options,dmodel,SampMin,weight,constraints)
yet one of the parameters is assigned a negative value during the operation of the algorithm

liu bingbing

very good!

Luo chengjin

I think it's good!

Guo Xiaoyu

Thank you very mucn

Sun Qiyue

I can not work it out? the example is not so good and I always get the error: fun caused error

Yubin Bao

easy to use

mark elec

Does the algorithm support for non-convex problem ???

jacky LI

the example is not good enough!

wang lingli


Mojtaba Hajihasani

Your proposed method suffers from big problem, beacuse in sub-problem you have brought the problem into continues domain.

asd sad

Dingyu Xue

Further suggestions
1) better to allow function handles
2) fine-tuning of the argument and results for integer variables:
2a. in the starting part of the function, give xlb(xstat)=ceil(xlb(xstat)); xub(xstat)=floor(xub(xstat))
2b. at the end of the function, X(xstat)=round(X(xstat))

Naresh Nandola

Puthut Wibowo


Bess Bai

Thanks! is there the manual for bnb.m (matlab) file?

kinky leung

Thanks!But is it free?

shrinivas pradeep

can you please send the manual for bnb.m (matlab) file.

Pradeep Shrinivas

Dear sir,
Your work is excellent, we are using your work for our project.

Pradeep &Shrinivas
( BE (CSE)Final Year)
BCET Bangalore-560081

Bakhtiyar Tokpayev

vinod kumar

please provide pdf help files and pseudo codes and comments on each step.

Andrew Odjo

Atanas Chervenkov

Nguyen Quoc Vo

H hasper

George Pau

Very good basic implementation of branch and bound.

MATLAB Release Compatibility
Created with R11
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Inspired: MINLP: Mixed Integer Nonlinear Programming

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!