File Exchange

image thumbnail


version (11.7 KB) by Ingar Solberg
Solves constrained minimization problems, some of the variables are restricted to discrete values


Updated 14 Jan 2000

No License

fminconset: Solves constrained minimization problems where some
of the variables are restricted to discrete values. (Mixed Integer
Nonlinear optimization). Based on fmincon from Optimization Toolbox
version 2.0.

Cite As

Ingar Solberg (2021). fminconset (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)


I looking in the code and I believe following line provides explanation to my question:
if ~any(abs(x(i) - set{i}) < optimget(options,'TolX'))

=> by setting TolX, you set the maximum possible interval between the value of your set (like [0 1] for a binary variable) and the calculated value for the variable.
Therefore, unless you set TolX to 0, I guess you could always get some non-integer values for your variable.


Thanks Ingar for posting this piece!

However I have got some unconsistency in the results provided by the function for my problem:
It seems to work well in first approach (exitflat=2) and I get a "good" comment in the command window: Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.

But when I look at the values for my variable, I see that I obtained non-integer values!!

I set:
set={[0 1],[0 1]};
x0=[0 0]'; xlb=[0 0]'; xub=[1 1]';

[x,h,exitflag,output,lambda,grad,hessian] = fminconset(fun,x0,[],[],[],[],xlb,xub,'nonlcon',options,set,Inf);

Do you have any idea what could be going wrong in the script? (I know it has been a while that you posted it!!)
I ran your example and it works well...

Dmitrey Kroshko

you could compare it with translation of the routine to Python, see for details.

dinesh birla

I have not been able to download so far then send comments

moussa almou

matlab code for the diet problem

Girija Chetty

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!