Zopt = 
The QUBO function cannot yield the correct solution to my problem.
Mostrar comentarios más antiguos
I want use QUBO function (https://ww2.mathworks.cn/help/matlab/math/what-is-a-qubo.html) to solve my question in the following:
min Z=2*x12 + 2*x23 + 10*x25 + x34 + 3*x45 + 3*x46 + 2*x54 + x56 + 2*x67 + 2*x12*x23 + 3*x12*x25 + 2*x23*x34 + x25*x54 + 2*x34*x45 + x34*x46 + x25*x56 + 5*x46*x54 + 10*x45*x56 + 20*x46*x67 + x56*x67 ;
s.t. x12 - 1=0;
x23 - x12 + x25 =0;
x23 - x34=0;
x25 + x45 - x54 - x56 =0;
x34 - x45 - x46 + x54 =0;
x46 + x56 - x67=0;
x67 - 1 =0;
all variables: x12,x23, x25,x34,x45,x46,x54,x56,x67 are binary variables
I already know that the optimal solution to this problem is :
x12=x25=x56=x67=1, other variables =0 the optimal value =20
however when I try to use QUBO function to solve it, I converted all the constraints into penalty factors and added them to the objective function, thereby transforming the problem into an unconstrained one, the code is:
clc
clear
syms x12 x23 x25 x34 x45 x46 x54 x56 x67
P=50; %Penalty coefficient
Z=2*x12+2*x23+10*x25+1*x34+3*x45+ 3*x46+2*x54+1*x56+2*x67 + ...
2*x12*x23 + 3*x12*x25 + 2*x23*x34 + x25*x54 + x25*x56 +2*x34*x45+ ...
x34*x46+10*x45*x56+ 20*x46*x67 +5*x54*x46 +x56*x67 ...
+ P*(x12-1)^2 +P*(x12-x23-x25)^2 +P*(x23-x34)^2 ...
+P*(x45+x25-x54-x56)^2 + P*(x54+x34-x45-x46)^2 + P*(x46+x56-x67)^2 ...
+ P*(x67-1)^2
Q = hessian(Z, [x12 x23 x25 x34 x45 x46 x54 x56 x67])
Q=double(Q)
d = jacobian(Z, [x12 x23 x25 x34 x45 x46 x54 x56 x67]);
d = subs(d, [x12 x23 x25 x34 x45 x46 x54 x56 x67], [0 0 0 0 0 0 0 0 0]);
d = double(d);
qprob = qubo(Q,d)
result = solve(qprob)
in the code, the Hessian matrix and the coefficients of the linear terms of the objective function are determined using the relevant functions. the result is: 

It can be seen that the solution obtained by the QUBO function has all 0-1 variable values as 0, and the objective function value is also 0. This result is clearly wrong. I would like to know why caused this result.
2 comentarios
Chuguang Pan
el 28 de Sept. de 2026 a las 3:31
Du Wei
el 28 de Sept. de 2026 a las 4:36
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Quadratic Unconstrained Binary Optimization (QUBO) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


