Skip to content

Commit

Permalink
New function to assign constraint matrices to cliques
Browse files Browse the repository at this point in the history
  • Loading branch information
duembgen committed Dec 9, 2024
1 parent 8e2df58 commit a8db5cf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cert_tools/hom_qcqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,31 @@ def get_consistency_constraints(self):

return eq_list

def assign_matrix(self, pmat: PolyMatrix):
"""Assign a matrix to the clique that it corresponds to.
Returns the index of the clique that this matrix applies to.
"""
assert isinstance(pmat, PolyMatrix), TypeError("Input should be a PolyMatrix")
assert pmat.symmetric, ValueError("PolyMatrix input should be symmetric")

if not len(self.var_clique_map):
raise ValueError(
"var_clique_map is empty. Did you run clique_decomposition?"
)

involved_variables = set(pmat.get_variables())
valid_cliques = []
for clique in self.cliques:
if involved_variables.issubset(clique.var_list):
valid_cliques.append(clique.index)

if not len(valid_cliques):
raise ValueError(
f"Error assigning constraint to a single clique: {len(valid_cliques)} matches"
)
return valid_cliques

def decompose_matrix(self, pmat: PolyMatrix, method="split"):
"""Decompose a matrix according to clique decomposition.
Expand Down

0 comments on commit a8db5cf

Please sign in to comment.