(*
This file is part of the dpll(t) engine sammy
Copyright (C) 2004  The University of Iowa
George Hagen

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*)

(* lset.ml *)

(* lemmas (and instantiated clauses) are stored in a 2 tiered list:
   they are classified as either "active" (recently used) or "inactive" 
   (ready to be discarded).  A clause is intitally inserted at the head of the
   inactive sublist; if the table is full, the tail of the inactive list is
   dropped.  If a clause generates a conflict, increase_relevance is called 
   on it, and it is moved to the head of the active sublist, with the tail of
   the active sublist possibly being pushed down to the inactive sublist.

   This is done because we want to keep around relevant clauses, but may be
   adding many instance clause at once, which have not yet proven to be
   useful.  A sorted array, for example, would have difficulty in placing
   these new clauses (overwrite the least relevant each time?  Then new
   clauses would not have a chance to be noticed...)  This preserves
   the intent of a VSIDS-like ranking without sorting that might be required.
*)

open Global

exception IsetOutOfSpace

class iset =
object
  val mutable current_isize = 0 (* current number of instances *)
  val mutable isize = 0 (* number of instances *)
  val mutable csize = 0 (* number of clauses *)
  val max_isize = Global.pars.max_instance_lemmas
  val mutable instance_list = [[]]

  method add_instance (ilist:Global.pred_id list list) =
    csize <- csize + List.length ilist;
    current_isize <- current_isize + 1;
    isize <- isize + 1;
    if current_isize >= max_isize then
      raise IsetOutOfSpace;
    instance_list <- ilist::instance_list

  method clear =
    isize <- 0;
    csize <- 0;
    instance_list <- [[]] 

  method print = Printf.printf "Instance formulas: %d\n" isize;
                 Printf.printf "Instance clauses: %d\n" csize

end
