-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BV,CP): Use a FIFO queue for constraint propagation
This patch changes the bit-vector propagator to use a FIFO queue to select which propagator to run. Using a FIFO queue gives fairness guarantees on the constraints that get propagated, and does not depend on hash-consing shenanigans as in the current implementation. The implementation is a simple wrapper around the `Queue` module from the stdlib and a hash table to ensure uniqueness of constraints in the queue.
- Loading branch information
1 parent
2174392
commit 4f40796
Showing
5 changed files
with
226 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* Alt-Ergo: The SMT Solver For Software Verification *) | ||
(* Copyright (C) 2024 --- OCamlPro SAS *) | ||
(* *) | ||
(* This file is distributed under the terms of OCamlPro *) | ||
(* Non-Commercial Purpose License, version 1. *) | ||
(* *) | ||
(* As an exception, Alt-Ergo Club members at the Gold level can *) | ||
(* use this file under the terms of the Apache Software License *) | ||
(* version 2.0. *) | ||
(* *) | ||
(* More details can be found in the directory licenses/ *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
module type S = sig | ||
type elt | ||
|
||
type t | ||
|
||
val create : int -> t | ||
|
||
val push : t -> elt -> unit | ||
|
||
exception Empty | ||
|
||
val pop : t -> elt | ||
|
||
val peek : t -> elt | ||
|
||
val is_empty : t -> bool | ||
|
||
val clear : t -> unit | ||
end | ||
|
||
module Make(H : Hashtbl.HashedType) : S with type elt = H.t = struct | ||
module HT = Hashtbl.Make(H) | ||
|
||
type elt = H.t | ||
|
||
type t = { queue : H.t Queue.t ; elements : unit HT.t} | ||
|
||
let create n = | ||
{ queue = Queue.create () ; elements = HT.create n } | ||
|
||
let push { queue ; elements } x = | ||
if HT.mem elements x then () else ( | ||
HT.replace elements x (); | ||
Queue.push x queue | ||
) | ||
|
||
exception Empty = Queue.Empty | ||
|
||
let pop { queue ; elements } = | ||
let x = Queue.pop queue in | ||
HT.remove elements x; x | ||
|
||
let peek { queue; _ } = Queue.peek queue | ||
|
||
let is_empty { queue; _ } = Queue.is_empty queue | ||
|
||
let clear { queue ; elements } = | ||
Queue.clear queue; HT.clear elements | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* Alt-Ergo: The SMT Solver For Software Verification *) | ||
(* Copyright (C) 2024 --- OCamlPro SAS *) | ||
(* *) | ||
(* This file is distributed under the terms of OCamlPro *) | ||
(* Non-Commercial Purpose License, version 1. *) | ||
(* *) | ||
(* As an exception, Alt-Ergo Club members at the Gold level can *) | ||
(* use this file under the terms of the Apache Software License *) | ||
(* version 2.0. *) | ||
(* *) | ||
(* More details can be found in the directory licenses/ *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
(** First-in first-out *unique* queues. | ||
This module implements queues (FIFOs) without duplicates, with in-place | ||
modifications. Implemented as a wrapper around the [Queue] and [Hashtbl] (to | ||
ensure uniqueness) modules from the stdlib. *) | ||
|
||
module type S = sig | ||
type elt | ||
(** The type of elements in the unique queue. *) | ||
|
||
type t | ||
(** The type of unique queues with [elt] elements. *) | ||
|
||
val create : int -> t | ||
(** Create a new empty unique queue. The [int] parameter is passed to the | ||
backing [Hashtbl] used to ensure uniqueness. *) | ||
|
||
val push : t -> elt -> unit | ||
(** [push q x] adds [x] at the end of the queue [q]. Does nothing if [x] is | ||
already present in the queue. *) | ||
|
||
exception Empty | ||
(** Raised when [pop] or [peek] are applied to an empty queue. *) | ||
|
||
val pop : t -> elt | ||
(** [pop q] removes and returns the first element in queue [q], or raises | ||
[Empty] if the queue is empty. | ||
@raise Empty if the queue is empty. *) | ||
|
||
val peek : t -> elt | ||
(** [peek q] returns the first element in queue [q] without removing it, or | ||
raises [Empty] if the queue is empty. | ||
@raise Empty if the queue is empty. *) | ||
|
||
val is_empty : t -> bool | ||
(** Returns [true] if the queue is empty, [false] otherwise. *) | ||
|
||
val clear : t -> unit | ||
(** Discard all elements from the queue. *) | ||
end | ||
|
||
module Make(H : Hashtbl.HashedType) : S with type elt = H.t |