Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/adalisan/RGraphM
Browse files Browse the repository at this point in the history
  • Loading branch information
adalisan committed Sep 11, 2017
2 parents f091307 + 8b91dc8 commit 952842f
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 104 deletions.
22 changes: 19 additions & 3 deletions src/graphm/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,28 @@
algorithm::algorithm(std::string fconfig)
: rpc(fconfig)
{
gm_ldh=NULL;dalpha_ldh=0;bnosymm=false;
gm_ldh=NULL;
dalpha_ldh=0;
bnosymm=false;
df_norm=0;
N=0;
bverbose=false;
sverbfile=std::string("");

}
algorithm::algorithm()
: rpc()
{
gm_ldh=NULL;dalpha_ldh=0;bnosymm=false;df_norm=0;N=0;cdesc_matrix='A';cscore_matrix='A';
gm_ldh=NULL;
dalpha_ldh=0;
bnosymm=false;
df_norm=0;
N=0;
cdesc_matrix='A';
cscore_matrix='A';
bverbose=false;
sverbfile=std::string("");

}

//common framework for graph matching algorithm
Expand Down Expand Up @@ -102,7 +118,7 @@ double algorithm::graph_dist(graph &g,graph &h,gsl_matrix* gm_P,char cscore_matr
bool print_debug = false;
if ((pdebug.ivalue != -1) && (pdebug.ivalue))
print_debug = true;
long N=g.getN();
N=g.getN();
gsl_matrix* gm_Ag=g.get_descmatrix(cscore_matrix);
gsl_matrix* gm_At=gsl_matrix_alloc(N,N);
gsl_matrix* gm_Ah=gsl_matrix_alloc(N,N);
Expand Down
4 changes: 2 additions & 2 deletions src/graphm/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class match_result
match_result() {
gm_P=NULL;
salgo = "";
gm_P_exact=NULL;
gm_P_exact=NULL;
inum_iteration=-1;
dres = 0.0;
dtime = 0.0;
Expand Down Expand Up @@ -75,7 +75,7 @@ class algorithm : public rpc
{
public:
algorithm(std::string );
algorithm();
algorithm() ;
match_result gmatch(graph& g, graph& h,gsl_matrix* gm_P_i=NULL, gsl_matrix* gm_ldh=NULL,double dalpha_ldh=-1);//common stuff,
virtual match_result match(graph& g, graph& h, gsl_matrix* gm_P_i=NULL, gsl_matrix* gm_ldh=NULL,double dalpha_ldh=-1)=0;//particular method implementation
double graph_dist(graph &g,graph &h,gsl_matrix* gm_P,char cscore_matrix);
Expand Down
1 change: 1 addition & 0 deletions src/graphm/algorithm_ca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
match_result algorithm_ca::match(graph &g, graph &h, gsl_matrix *gm_P_i, gsl_matrix *_gm_ldh, double dalpha_ldh)
{
double dhung_max = get_param_d("hungarian_max");
N=g.getN();
//bool bblast_match_end = (get_param_i("blast_match_proj") == 1);
bool bblast_match = (get_param_i("blast_match") == 1);
//double dfw_xeps = get_param_d("algo_fw_xeps");
Expand Down
6 changes: 3 additions & 3 deletions src/graphm/algorithm_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

match_result algorithm_NEW::match(graph& g, graph& h,gsl_matrix* gm_P_i,gsl_matrix* gm_ldh,double dalpha_ldh)
{
if (bverbose) *gout<<"The best matching algorithm"<<std::endl;
if (bverbose) *gout<<"The best matching algorithm"<<std::endl;
match_result mres; //class with results
gsl_matrix* gm_Ag_d=g.get_descmatrix(cdesc_matrix);//get the adjacency matrix of graph g
gsl_matrix* gm_Ah_d=h.get_descmatrix(cdesc_matrix);//get the adjacency matrix of graph h
//the similarity matrix C is defined in the algorithm class memeber gm_ldh
//dalpha_ldh is corresponding is corresponding to the linear combination coefficent alpha

N=g.getN();
gsl_matrix* P=gsl_matrix_alloc(N,N);
//YOUR OPERATIONS WITH MATRICES, RESULT IS A PERMUTATION MATRIX P

Expand All @@ -41,4 +41,4 @@ mres.gm_P_exact=NULL; //you can save here the matrix which was used as an approx

mres.dres=graph_dist(g,h,mres.gm_P,cscore_matrix);// distance between graph adjacency matrices
return mres;
}
}
7 changes: 4 additions & 3 deletions src/graphm/algorithm_fsol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
match_result algorithm_fsol::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matrix* gm_ldh,double dalpha_ldh)
{
if (bverbose)
*gout<<"FSol matching"<<std::endl;
*gout<<"FSol matching"<<std::endl;
//some duplicate variables
match_result mres;
N=g.getN();
mres.gm_P=gsl_matrix_alloc(N,N);
std::string sfile=get_param_s("solution_file");
FILE *f=fopen(sfile.c_str(),"r");
if (f!=NULL){
if (f!=NULL){
gsl_matrix_fscanf(f,mres.gm_P);
fclose(f);
}
else{
if (bverbose) *gout<<"Can't load solution file, fsoltity matrix is used"<<std::endl;
if (bverbose) *gout<<"Can't load solution file, fsoltity matrix is used"<<std::endl;
gsl_matrix_set_identity(mres.gm_P);
}
mres.gm_P_exact=NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/graphm/algorithm_iden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
match_result algorithm_iden::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matrix* gm_ldh,double dalpha_ldh)
{
if (bverbose)
*gout<<"Identity matching"<<std::endl;
*gout<<"Identity matching"<<std::endl;
//some duplicate variables
match_result mres;
N=g.getN();
mres.gm_P=gsl_matrix_alloc(N,N);
gsl_matrix_set_identity(mres.gm_P);
mres.gm_P_exact=NULL;
Expand Down
17 changes: 9 additions & 8 deletions src/graphm/algorithm_lp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
match_result algorithm_lp::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matrix* gm_ldh,double dalpha_ldh)
{
if (bverbose)
*gout<<"Linear programming matching"<<std::endl;
*gout<<"Linear programming matching"<<std::endl;
gsl_matrix* gm_Ag_d=g.get_descmatrix(cdesc_matrix);
gsl_matrix* gm_Ah_d=h.get_descmatrix(cdesc_matrix);
N=g.getN();
//linear program parameters
int* ia = new int[N*N*(N+N-1)+N*N+N*N+N*N+1];
int* ja = new int[N*N*(N+N-1)+N*N+N*N+N*N+1];
Expand All @@ -40,7 +41,7 @@ match_result algorithm_lp::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matr
gsl_matrix_set(gm_Agh,i*N+j,j*N+k,gsl_matrix_get(gm_Ag_d,i,k));
ia[icounter]=i*N+j+1;ja[icounter]=j*N+k+1;ar[icounter]=gsl_matrix_get(gm_Ag_d,i,k);
icounter++;
};
};
for (int k=0;k<N;k++){
//sometimes we have to change yet allocated constaints
if (k!=j){
Expand Down Expand Up @@ -80,7 +81,7 @@ match_result algorithm_lp::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matr
};
//glpk package
LPX* lp;
lp=lpx_create_prob();
lp=lpx_create_prob();
lpx_set_prob_name(lp,"glpk");
lpx_add_rows(lp,N*N+N);
for (int i=0;i<N*N;i++)
Expand All @@ -94,7 +95,7 @@ match_result algorithm_lp::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matr
lpx_set_obj_dir(lp,LPX_MIN);
//the label cost matrix introduce the coefficients for the first part of objective function
if (dalpha_ldh>0)
{
{
for (int i=0;i<N*N;i++)
lpx_set_obj_coef(lp,i+1,dalpha_ldh*gm_ldh->data[i]);
for (int i=0;i<2*N*N;i++)
Expand All @@ -115,7 +116,7 @@ match_result algorithm_lp::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matr
for (int j=0;j<N;j++)
gsl_matrix_set(C,i,j,lpx_get_col_prim(lp,i*N+j+1));
lpx_delete_prob(lp);
if (pdebug.ivalue) gsl_matrix_printout(C,"C=lp solution",pdebug.strvalue);
if (pdebug.ivalue) gsl_matrix_printout(C,"C=lp solution",pdebug.strvalue);
match_result mres;
mres.gm_P_exact=gsl_matrix_alloc(N,N);
gsl_matrix_transpose_memcpy(mres.gm_P_exact,C);
Expand All @@ -125,9 +126,9 @@ match_result algorithm_lp::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matr
dscale_factor=10000/dscale_factor;
gsl_matrix_scale(C,-dscale_factor);
//gsl_matrix_transpose(C);
if (pdebug.ivalue) gsl_matrix_printout(C,"scale(C)",pdebug.strvalue);
if (pdebug.ivalue) gsl_matrix_printout(C,"scale(C)",pdebug.strvalue);
gsl_matrix* gm_P=gsl_matrix_hungarian(C);
if (pdebug.ivalue) gsl_matrix_printout(gm_P,"gm_P",pdebug.strvalue);
if (pdebug.ivalue) gsl_matrix_printout(gm_P,"gm_P",pdebug.strvalue);
mres.gm_P=gm_P;
gsl_matrix_free(gm_Ag_d);
gsl_matrix_free(gm_Ah_d);
Expand All @@ -148,4 +149,4 @@ match_result algorithm_lp::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matr
return mres;
}

#endif
#endif
7 changes: 5 additions & 2 deletions src/graphm/algorithm_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

match_result algorithm_path::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_matrix* _gm_ldh, double dalpha_ldh)
{
bool bblast_match=(get_param_i("blast_match")==1);
bool bblast_match_end=(get_param_i("blast_match_proj")==1);
bool bblast_match=false;
bblast_match=(get_param_i("blast_match")==1);
bool bblast_match_end=false;
bblast_match_end=(get_param_i("blast_match_proj")==1);
bool bbest_path_proj=(get_param_i("best_path_proj_sol")==1);
bool bbest_path_blast_proj=(get_param_i("best_path_blast_proj_sol")==1);
bool bbest_path_greedy=(get_param_i("best_path_greedy_sol")==1);
Expand All @@ -45,6 +47,7 @@ match_result algorithm_path::match(graph& g, graph& h,gsl_matrix* gm_P_i, gsl_ma
if (pdebug.ivalue) gsl_matrix_printout(gm_Ag_d, "Ag", pdebug.strvalue);
if (pdebug.ivalue) gsl_matrix_printout(gm_Ah_d, "Ah", pdebug.strvalue);
//laplacian construction
N=g.getN();
gsl_matrix* gm_Lg_d=gsl_matrix_alloc(N, N);
gsl_matrix* gm_Lh_d=gsl_matrix_alloc(N, N);
gsl_matrix_memcpy(gm_Lg_d, gm_Ag_d);
Expand Down
Loading

0 comments on commit 952842f

Please sign in to comment.