//  -----------------------------------------------------------------
//  Licensed Materials - Property of IBM
//  
//  Satisfiability Solver Selector (3S)
//  
//  (C) Copyright IBM Corporation 2011.  All Rights Reserved.
//  
//  US Government Users Restricted Rights -  Use, duplication or
//  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//  
//  Authors:  Yuri Malitsky, Ashish Sabharwal,
//            Horst Samulowitz, Meinolf Sellmann
//  
//  This program and its associated documentation files ("Software")
//  are provided "as is", without warranty of any kind, express or
//  implied, including but not limited to the warranties of
//  merchantability or fitness for a particular purpose. In no
//  event shall the authors or copyright holders be liable for any
//  claim, damages, or other liability, whether in an action of
//  contract, tort, or otherwise, arising from, out of, or in
//  connection with the use of the Software.
//  -----------------------------------------------------------------

#############################################################################
## Satisfiability Solver Selector (3S)                                     ##
##                                                                         ##
##   version 1.0, March 2011                                               ##
#############################################################################


3S is a portfolio SAT solver. It uses ideas from clusterting and
nearest neighbor classification to perform solver selection without
relying on, e.g., runtime prediction models. Given a new CNF formula,
it computes features of this formula and then recommends a schedule of
solvers (with or without preprocessing) to use for this formula --
starting with a few initial solvers with short timeouts followed by a
solver or two for the remaining time. Note that the current
distribution is designed with the 1200 and 5000 second timeouts used
in SAT Competition 2011.

3S is built upon nearly two dozen solvers, preprocessors, and other
utilities available publically, thanks to the efforts of the SAT
research community over the last several years!

Specifically, 3S uses 21 SAT solvers present in the 'solvers'
folder, the SatElite preprocessor present in the 'preprocessors'
folder, and a SAT instance feature extraction module and a timed
execution module present in the 'utilities' folder.



USAGE EXAMPLE IN A NUTSHELL
---------------------------

  ## NOTE: YOU MUST BE IN THE '3S-1.0' FOLDER TO RUN THE PORTFOLIO SOLVER!
  ## To emphasize this, you will find "./" added to the files referenced below.
  cd 3S-1.0

  ## one-time test to ensure everything works fine on your system
  ./3S-executables-test.sh
  
  ## solve a CNF formula
  python ./3S-1.0.py example-sat.cnf



DIRECTORY STRUCTURE
-------------------

3S-1.0.py: MAIN FRONT END of the solver; see usage below

3S-executables-test.sh: a shell script to ensure all 25 executables
  needed by the portfolio are in proper working condition; see usage below.
  The log file generated by this should look similar to the file
  3S-executables-test.LOG-SAMPLE in the main folder.

WORKING_DIR: default folder used for writing temporary files; this can
  be changed by a commandline option to 3S-1.0.py; see below

COACH: folder containing the 'intelligence module' of 3S

solvers: folder containing binaries of all SAT solvers used by the portfolio

preprocessors: folder containing a binary of the SatElite preprocessor

utilities: folder containing binaries for the feature extraction code
  and the timed run code (based on the code available from UBC,
  extended with a module that takes machine speed into account when
  computing speed-dependent features)

unif-k3-r4.2-v18000-c75600-S914323646-060.cnf: file used by 'features'
  for calibration

SourceCode: folder containing the source code for every module used



USAGE EXAMPLES
--------------

## NOTE: YOU MUST BE IN THE '3S-1.0' FOLDER TO RUN THE PORTFOLIO SOLVER!
## To emphasize this, you will find "./" added to the files referenced below.

  cd 3S-1.0


(A) BEFORE using this portfolio solver for the first time on any
machine, we STRONGLY RECOMMEND that you test that all 25 executables
required by it function properly on your machine. An easy way to do
this is to execute the following from the solver folder:  

  ./3S-executables-test.sh [TMPDIR]

where TMPDIR is an optional argument specifying where to create log
files during the test; it defaults to the WORKING-DIR folder. This
script will check all required executables and report whether there
was a problem; the detailed runtime log, helpful for figuring out what
didn't work and gave what kind of error, may be found in:

  TMPDIR/3S-executables-test.LOG

If all works properly, this file should have 25 "TEST SUCCESSFUL"
lines and should look somewhat similar to:

  3S-executables-test.LOG-SAMPLE

A success indicator file, 3S-executables-test-SUCCESS.txt, containing
the timestamp of the test will also be created in TMPDIR and will be
later used by 3S-1.0.py to ensure that this executables test was run
successfully at least once in the current setup.

If there are errors with some of the executables, "TEST FAILED" will
be reported, with details in the LOG file. Please compile the
corresponding solver using the source code provided in the SourceCode
folder and copy the binary file over; then re-run this test until
successful.

For example, if the binary "COACH/coach" has trouble during the test,
the following will re-compile it and place it in the appropriate
folder:

  cd SourceCode/COACH
  make clean
  make
  mv coach ../../COACH/


(B) USING THE PORTFOLIO SOLVER -- here are some sample command-lines:

  ## SOLVE A CNF FORMULA ##

  python ./3S-1.0.py example-sat.cnf


  ## display all command-line options

  python ./3S-1.0.py -h
  python ./3S-1.0.py --help


  ## solve example-sat.cnf assuming the process will be killed after
  ## 1200 seconds. NOTE: "-t xx" will *not* automatically stop the
  ## portfolio solver after xx seconds; instead this parameter is
  ## simply used as a guidance to determine which solver(s) may be the
  ## best *if* we were alloted only xx seconds to solve this instance.

  python ./3S-1.0.py -t 1200 example-sat.cnf


  ## specify which directory to use for storing temporary files;
  ## defaults to the WORKING-DIR folder. Note that
  ## "3S-executables-test.sh TMPDIR" must have been run once
  ## prior to using the portfolio solver with this argument.

  python ./3S-1.0.py -d TMPDIR example-sat.cnf


  ## specify a random seed

  python ./3S-1.0.py -s 31415926 example-sat.cnf


  ## don't erase temporary files when done; helpful for debugging
  python ./3S-1.0.py --nofilecleanup example-sat.cnf
  


SUGGESTIONS / COMMENTS / TROUBLESHOOTING
----------------------------------------

Please contact any of us if you are having trouble using the solver
and/or have comments or suggestions.

  ynm@cs.brown.edu
  ashish.sabharwal@us.ibm.com
  samulowitz@us.ibm.com
  meinolf@us.ibm.com

-------------------------------------------------------------------
