#
# An experimental comparison of hybrid algorithms for Bayesian network structure learning
# H2PC code and benchmark results
#
# License :
#   GPL (>= 2)
# Contacts :
#   maxime.gasse@gmail.com
#   alexandre.aussem@univ-lyon1.fr
# Content :
#   figures/ - many PNG graphs with the benchmark results
#   networks/ - the networks used in the benchmark, in the DSC format
#   package/ - the bnlearn R package source code, with an patch to add H2PC
#   example.R - some R code to perform a simple benchmark of H2PC versus MMHC
#   include.R - some boring R code necessary to run the example
#   README.txt - this file
#   results.csv - the detailed benchmark results

# Linux install

- R SETUP
1 - Install R and the R build tools available for your distribution.
    Preferably use the last version of R from the CRAN project's website
    (http://cran.r-project.org/bin/linux/)
2 - Install Rstudio if you want a nice IDE
    (http://rstudio.org/download/desktop)

- BNLEARN PATCH
1 - Go to the "package" directory
2 - Extract the bnlearn 2.9 package:
    zcat bnlearn_2.9_vanilla.tar.gz | tar -x
3 - Patch it:
    patch -d bnlearn -p1 < h2pc.diff

- BNLEARN BUILD
1 - Run R (or Rstudio) and install the dependency package "graph"
    (http://bioconductor.org/packages/release/bioc/html/graph.html)
2 - Close R (or Rstudio)
3 - Build and install bnlearn 
    R CMD INSTALL --build bnlearn

# Windows install (tested with windows 7)

- R SETUP
1 - Install R
    (http://cran.r-project.org/bin/windows/base/)
2 - Install Rtools
    (http://cran.r-project.org/bin/windows/Rtools/)
3 - Install Rstudio if you want a nice IDE
    (http://rstudio.org/download/desktop)
4 - Open your environment variables editor : right-click "My Computer"
    then click "Properties" -> "Advanced System Settings" -> "System
    Properties" -> "Environment variables..."
5 - Make sure your PATH system variable contains the paths to the R and
    Rtools binaries. They by default look like this :
    C:\Program files\R\R-2.15.0\bin
    C:\Rtools\bin
    C:\Rtools\gcc-4.6.3\bin
    (new pathes have to be added semicolons-separated in the PATH chain)

- BNLEARN PATCH
1 - Go to the "package" directory
2 - Extract the bnlearn 2.9 package to obtain the "bnlearn" directory.
    You can do it with 7-zip (http://www.7-zip.org/download.html)
3 - Apply the patch H2PC file (h2pc.diff) to the package sources.
    You can do it with the TortoiseMerge tool
    (http://sourceforge.net/projects/tortoisesvn/files/Tools/1.6.7/TortoiseDiff-1.6.7.zip)
    Run winmerge, select "apply unified diff" and choose the bnlearn
    directory and the h2pc.diff file. Then right click on the file
    patches list and select "apply all".

- BNLEARN BUILD
1 - Open R (or Rstudio)
2 - Create your local library directory (to be able to install packages) by
    running the following command :
    dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)
3 - Install the dependency package "graph"
    (http://bioconductor.org/packages/release/bioc/html/graph.html)
4 - Close R (or Rstudio)
5 - Open a terminal and go to the "package" directory
    _YOUR_DRIVE_:
    cd _YOUR_DRIVE_:\_YOUR_CODE_LOCATION_\package
    Should be something like :
    E:
    cd E:\tmp\h2pc\package
6 - Build and install bnlearn 
    R CMD INSTALL --build bnlearn
