-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid quadratic time processing in solver-(assert,min/maximize) (#261)
* avoid quadratic time processing in solver-(assert,min/maximize) The time complexity of n calls to solver-assert / solver-minimize / solver-maximize is currently O(n^2) due to list appending at the tail, which requires traversal. This PR fixes the problem. The ordering of solver-minimize and solver-maximize matters, however (it specifies the lexicographic ordering minimization), so rearranging them is slightly more complicated. * Add an optimization order test * Clear the solver
- Loading branch information
Showing
4 changed files
with
43 additions
and
12 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,27 @@ | ||
#lang rosette | ||
|
||
;; This test is taken from https://www.philipzucker.com/z3-rise4fun/optimization.html | ||
|
||
(require rackunit rackunit/text-ui racket/generator | ||
rosette/lib/roseunit) | ||
|
||
(current-bitwidth #f) | ||
(define-symbolic x y z integer?) | ||
|
||
(define (check-model sol m) | ||
(check-pred sat? sol) | ||
(check-equal? (model sol) m)) | ||
|
||
(define optimization-order-tests | ||
(test-suite+ "Tests for the optimization order" | ||
#:features '(optimize) | ||
|
||
(define solver (current-solver)) | ||
(solver-clear solver) | ||
(solver-assert solver (list (< x z) (< y z) (< z 5) (not (= x y)))) | ||
(solver-maximize solver (list x)) | ||
(solver-maximize solver (list y)) | ||
(check-model (solver-check solver) (hash x 3 y 2 z 4)))) | ||
|
||
(module+ test | ||
(time (run-tests optimization-order-tests))) |