This is an R package, which is on CRAN, that searches for all hierarchical submodels of a specified GLM with criterion (AIC, BIC, or AICc) within a specified cutoff of the minimum value. Alternatively, all the same thing except with just graphical models rather than hierarchical models. It uses the branch and bound algorithm so it does not have to fit all models.
There are also functions
isGraphical that say whether
a formula corresponds to a hierarchical or graphical model.