Skip to content

Commit

Permalink
Optimized ClusterGraph( const FactorGraph&, bool) constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris Mooij committed Jul 26, 2011
1 parent 0107d07 commit 4776e48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Include flags
INC=-I../include
# Library path flags
LIBS=
LIBS=-lgmpxx -lgmp
# Location of libDAI library
LIB=../lib
# Compiler
CC=g++
# Compiler flags
CCFLAGS=-Wno-deprecated -Wall -W -Wextra -fpic -O3 -static $(INC) $(LIBS)
CCFLAGS=-Wno-deprecated -Wall -W -Wextra -fpic -O3 -static $(INC)

all : uai2010-aie-solver

uai2010-aie-solver : uai2010-aie-solver.cpp $(LIB)/libdai.a
$(CC) $(CCFLAGS) -o$@ $< $(LIB)/libdai.a
$(CC) $(CCFLAGS) -o$@ $< $(LIB)/libdai.a $(LIBS)

# CLEAN
########
Expand Down
25 changes: 17 additions & 8 deletions src/clustergraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,28 @@ ClusterGraph::ClusterGraph( const std::vector<VarSet> & cls ) : _G(), _vars(), _
}


ClusterGraph::ClusterGraph( const FactorGraph& fg, bool onlyMaximal ) : _G( fg.bipGraph() ), _vars(), _clusters() {
ClusterGraph::ClusterGraph( const FactorGraph& fg, bool onlyMaximal ) : _G( fg.nrVars(), 0 ), _vars(), _clusters() {
// copy variables
_vars.reserve( fg.nrVars() );
for( size_t i = 0; i < fg.nrVars(); i++ )
_vars.push_back( fg.var(i) );

// copy clusters
_clusters.reserve( fg.nrFactors() );
for( size_t I = 0; I < fg.nrFactors(); I++ )
_clusters.push_back( fg.factor(I).vars() );

if( onlyMaximal )
eraseNonMaximal();
if( onlyMaximal ) {
for( size_t I = 0; I < fg.nrFactors(); I++ )
if( fg.isMaximal( I ) ) {
_clusters.push_back( fg.factor(I).vars() );
size_t clind = _G.addNode2();
foreach( const Neighbor &i, fg.nbF(I) )
_G.addEdge( i, clind, true );
}
} else {
// copy clusters
_clusters.reserve( fg.nrFactors() );
for( size_t I = 0; I < fg.nrFactors(); I++ )
_clusters.push_back( fg.factor(I).vars() );
// copy bipartite graph
_G = fg.bipGraph();
}
}


Expand Down

0 comments on commit 4776e48

Please sign in to comment.