/*******************************************************************\

Module:

Author: Daniel Kroening, kroening@kroening.com

\*******************************************************************/

#include <assert.h>

#include <stack>

#include <i2string.h>

#include "satcheck_minisat_interpolation.h"

#include <Solver.h>
#include <Proof.h>

class minisat_prooft:public ProofTraverser
{
public:
  virtual void root(const vec<Lit> &c)
  {
  }
  
  virtual void chain(const vec<ClauseId> &cs, const vec<Var> &xs)
  {
  }

  virtual void deleted(ClauseId c) { }
  virtual void done() { }
  virtual ~minisat_prooft() { }
  
  struct clauset
  {
  };
  
  typedef std::vector<clauset> clausest;
  clausest clauses;
  
  void build_interpolant();
};

/*******************************************************************\

Function: minisat_prooft::build_interpolant

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

void minisat_prooft::build_interpolant()
{
}

/*******************************************************************\

Function: satcheck_minisat_interpolationt::satcheck_minisat_interpolationt

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

satcheck_minisat_interpolationt::satcheck_minisat_interpolationt()
{
  minisat_proof=new minisat_prooft;
  proof=new Proof(*minisat_proof);
  solver=new Solver;
  solver->proof=proof;
  
  init_const();
}

/*******************************************************************\

Function: satcheck_minisat_interpolationt::~satcheck_minisat_interpolationt

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

satcheck_minisat_interpolationt::~satcheck_minisat_interpolationt()
{
  delete proof;
  delete minisat_proof;
}

/*******************************************************************\

Function: satcheck_minisat_interpolationt::prop_solve

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

propt::resultt satcheck_minisat_interpolationt::prop_solve()
{
  assert(status!=ERROR);

  {
    std::string msg=
      i2string(_no_literals)+" variables, "+
      i2string(solver->nClauses())+" clauses";
    messaget::status(msg);
  }

  add_variables();
  
  if(solver->okay())
    solver->solve();

  {
    std::string msg;

    if(solver->okay())
      msg="SAT checker: negated claim is SATISFIABLE, i.e., does not hold";
    else
      msg="SAT checker: negated claim is UNSATISFIABLE, i.e., holds";

    messaget::status(msg);
  }

  if(solver->okay())
  {
    status=SAT;
    return P_SATISFIABLE;
  }
  
  status=UNSAT;

  /*
  in_core.resize(no_literals()+1, false);
  minisat_core->build_core(in_core);
  */
  
  return P_UNSATISFIABLE;
}

/*******************************************************************\

Function: satcheck_minisat_interpolationt::solver_text

  Inputs:

 Outputs:

 Purpose:

\*******************************************************************/

const std::string satcheck_minisat_interpolationt::solver_text()
{
  return "MiniSAT + Interpolation";
}

