# In intlinprog how can I put condition for x = 1 or 0

3 vues (au cours des 30 derniers jours)
Meriem Ben Kalia le 23 Août 2020
Commenté : Meriem Ben Kalia le 23 Août 2020
hello,
I have optimization problem that i will solve it with intlinprog. But I have a condition in constraint that x must be 0 or 1 how can I put it in the code ?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Thiago Henrique Gomes Lobato le 23 Août 2020
You use a lower and upper bound of 0 and 1, respectively. Then if your number is an integer and should be between 0 and 1, the only possible values it can have are those two. Here is an example direct from the intlinprog documentation page where x(3) can only have values between 0 and 1:
f = [-3;-2;-1];
intcon = 3;
A = [1,1,1];
b = 7;
Aeq = [4,2,1];
beq = 12;2
% Lower and upper bound
lb = zeros(3,1);
ub = [Inf;Inf;1]; % Enforces x(3) is binary
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub) % If you don't need A,b,Aeq etc, make their value equal []
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the
default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
x =
0
5.5000
1.0000
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Meriem Ben Kalia le 23 Août 2020
Thank you

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Linear Least Squares dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by