How to write an optimization constraint related to neighbors of a node in a graph
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello All,
I am trying to implement an SDP optimzation problem in CVX. The language is Matalb. My question is mainly related to Matlab coding.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/867510/image.png)
In this problem, W, P, and P_{ij} are n-by-n matrices. Also, in this problem, E is a set of neighbors of a node i. Constraint P_{ij}=0 if \{i,j\}\not\in E means that P_{ij} is zero if nodes i and j are not neighbors.
Does anyone can help with how to implement this neighborhood relationship? Any help is greatly appreiciated.
For n=3, neighbors.xlsx can look like:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/867515/image.png)
I wrote this piece of code:
agt = struct([]);
neighbors = readcell('neighbors.xlsx');
N = 2;
for i = 1:N
agt(i).neighbors = neighbors{i};
end
j = 1;
for i = 1:N
D =[i,j];
if ~ismember(D,agt(i).neighbors)
W(i,j)== 0;
end
j = j+1;
end
0 Kommentare
Akzeptierte Antwort
Matt J
am 19 Jan. 2022
Bearbeitet: Matt J
am 19 Jan. 2022
You can get the graph adjacency matrix A from the adjacency() command,
Then, the constraints are:
P>=0,
dot(1-A(:),P(:))=0;
sum(P.*A,2)=1;
3 Kommentare
Matt J
am 19 Jan. 2022
Bearbeitet: Matt J
am 19 Jan. 2022
A is the adjacency matrix of the graph. I recommended that you generate it using the adjacency() command.
The second constraint is implied by the two constraints,
P>=0
dot(1-A(:),P(:))=0;
because Q=1-A is a matrix such that Q(i,j)=1 if
and zero otherwise. Therefore dot(1-A(:),P(:))=0 is the same as
. Because we have applied the additional constraint
, the constraint
follows.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/867630/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/867635/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/867640/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/867645/image.png)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!