1+ r"""
2+ Graph Matching Tools.
3+ """
4+
5+ # Copyright (c) 2022 Thinklab@SJTU
6+ # pygmtools is licensed under Mulan PSL v2.
7+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
8+ # You may obtain a copy of Mulan PSL v2 at:
9+ # http://license.coscl.org.cn/MulanPSL2
10+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13+ # See the Mulan PSL v2 for more details.
14+
15+
16+ from torch import Tensor
17+ from .astar import pygm_astar
18+ from .hungarian import pygm_hungarian
19+ from .ipfp import pygm_ipfp
20+ from .rrwm import pygm_rrwm
21+ from .sinkhorn import pygm_sinkhorn
22+ from .sm import pygm_sm
23+
24+
25+ class PyGMToolsQAPSolver (object ):
26+ def __init__ (
27+ self ,
28+ solver_name = "rrwm" ,
29+ astar_beam_width : int = 0 ,
30+ ipfp_x0 : Tensor = None ,
31+ ipfp_max_iter : int = 50 ,
32+ rrwm_x0 : Tensor = None ,
33+ rrwm_max_iter : int = 50 ,
34+ rrwm_sk_iter : int = 10 ,
35+ rrwm_alpha : float = 0.2 ,
36+ rrwm_beta : float = 30 ,
37+ sm_x0 : Tensor = None ,
38+ sm_max_iter : int = 50
39+ ):
40+ # Initialize Attributes (Solver Name)
41+ self .solver_name = solver_name
42+
43+ # Initialize Attributes (ASTAR)
44+ self .astar_beam_width = astar_beam_width
45+
46+ # Initialize Attributes (IPFP)
47+ self .ipfp_x0 = ipfp_x0
48+ self .ipfp_max_iter = ipfp_max_iter
49+
50+ # Initialize Attributes (RRWM)
51+ self .rrwm_x0 = rrwm_x0
52+ self .rrwm_max_iter = rrwm_max_iter
53+ self .rrwm_sk_iter = rrwm_sk_iter
54+ self .rrwm_alpha = rrwm_alpha
55+ self .rrwm_beta = rrwm_beta
56+
57+ # Initialize Attributes (SM)
58+ self .sm_x0 = sm_x0
59+ self .sm_max_iter = sm_max_iter
60+
61+ def solve (self , K : Tensor , n1 : Tensor , n2 : Tensor , n1max : int , n2max : int ):
62+ if self .solver_name == "astar" :
63+ return pygm_astar (
64+ K = K , n1 = n1 , n2 = n2 , n1max = n1max , n2max = n2max ,
65+ beam_width = self .astar_beam_width
66+ )
67+ elif self .solver_name == "ipfp" :
68+ return pygm_ipfp (
69+ K = K , n1 = n1 , n2 = n2 , n1max = n1max , n2max = n2max ,
70+ x0 = self .ipfp_x0 , max_iter = self .ipfp_max_iter
71+ )
72+ elif self .solver_name == "rrwm" :
73+ return pygm_rrwm (
74+ K = K , n1 = n1 , n2 = n2 , n1max = n1max , n2max = n2max ,
75+ x0 = self .rrwm_x0 , max_iter = self .rrwm_max_iter ,
76+ sk_iter = self .rrwm_sk_iter , alpha = self .rrwm_alpha ,
77+ beta = self .rrwm_beta
78+ )
79+ elif self .solver_name == "sm" :
80+ return pygm_sm (
81+ K = K , n1 = n1 , n2 = n2 , n1max = n1max , n2max = n2max ,
82+ x0 = self .sm_x0 , max_iter = self .sm_max_iter
83+ )
84+ else :
85+ raise ValueError (f"Solver { self .solver_name } is not supported!" )
0 commit comments