[1201] | 1 | ;;; -*- Mode: Lisp -*-
|
---|
[76] | 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 3 | ;;;
|
---|
| 4 | ;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
|
---|
| 5 | ;;;
|
---|
| 6 | ;;; This program is free software; you can redistribute it and/or modify
|
---|
| 7 | ;;; it under the terms of the GNU General Public License as published by
|
---|
| 8 | ;;; the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | ;;; (at your option) any later version.
|
---|
| 10 | ;;;
|
---|
| 11 | ;;; This program is distributed in the hope that it will be useful,
|
---|
| 12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | ;;; GNU General Public License for more details.
|
---|
| 15 | ;;;
|
---|
| 16 | ;;; You should have received a copy of the GNU General Public License
|
---|
| 17 | ;;; along with this program; if not, write to the Free Software
|
---|
| 18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 19 | ;;;
|
---|
| 20 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 21 |
|
---|
[449] | 22 | (defpackage "PAIR-QUEUE"
|
---|
[3910] | 23 | (:use :cl :priority-queue :monom :polynomial :utils)
|
---|
[3920] | 24 | (:export "CRITICAL-PAIR"
|
---|
| 25 | "CRITICAL-PAIR-FIRST"
|
---|
| 26 | "CRITICAL-PAIR-SECOND"
|
---|
[449] | 27 | "MAKE-PAIR-QUEUE"
|
---|
| 28 | "PAIR-QUEUE-INITIALIZE"
|
---|
| 29 | "PAIR-QUEUE-INSERT"
|
---|
| 30 | "PAIR-QUEUE-REMOVE"
|
---|
| 31 | "PAIR-QUEUE-SIZE"
|
---|
| 32 | "PAIR-QUEUE-EMPTY-P"
|
---|
| 33 | "SET-PAIR-HEURISTIC"
|
---|
[3918] | 34 | )
|
---|
| 35 | (:documentation "Critical pair queue implementation. The pair queue is a list of critical
|
---|
| 36 | pairs, ordered by some partial order. Pair queue is a kind of priority queue.")
|
---|
| 37 | )
|
---|
[449] | 38 |
|
---|
| 39 |
|
---|
[450] | 40 | (in-package :pair-queue)
|
---|
| 41 |
|
---|
[3919] | 42 | (defclass critical-pair ()
|
---|
[3921] | 43 | ((first :initform nil :initarg :first :accessor critical-pair-first :type poly)
|
---|
| 44 | (second :initform nil :initarg :second :accessor critical-pair-second :type poly))
|
---|
[3919] | 45 | (:documentation "Represents a critical pair."))
|
---|
| 46 |
|
---|
[3921] | 47 | (defmethod print-object ((self critical-pair) stream)
|
---|
[3920] | 48 | (print-unreadable-object (self stream :type t :identity t)
|
---|
| 49 | (with-accessors ((first critical-pair-first)
|
---|
| 50 | (second critical-pair-second))
|
---|
| 51 | self
|
---|
| 52 | (format stream "FIRST=~A SECOND=~A"
|
---|
| 53 | first second))))
|
---|
| 54 |
|
---|
[3922] | 55 | (defun make-pair-queue (pair-key-fn pair-order-fn)
|
---|
[60] | 56 | "Constructs a priority queue for critical pairs."
|
---|
| 57 | (make-priority-queue
|
---|
[3922] | 58 | :element-type 'critical-pair
|
---|
| 59 | :element-key #'(lambda (pair) (funcall pair-key-fn (critical-pair-first pair) (critical-pair-second pair)))
|
---|
| 60 | :test pair-order-fn))
|
---|
[60] | 61 |
|
---|
| 62 | (defun pair-queue-initialize (pq f start
|
---|
| 63 | &aux
|
---|
| 64 | (s (1- (length f)))
|
---|
| 65 | (b (nconc (makelist (make-pair (elt f i) (elt f j))
|
---|
| 66 | (i 0 (1- start)) (j start s))
|
---|
| 67 | (makelist (make-pair (elt f i) (elt f j))
|
---|
| 68 | (i start (1- s)) (j (1+ i) s)))))
|
---|
| 69 | "Initializes the priority for critical pairs. F is the initial list of polynomials.
|
---|
| 70 | START is the first position beyond the elements which form a partial
|
---|
| 71 | grobner basis, i.e. satisfy the Buchberger criterion."
|
---|
| 72 | (declare (type priority-queue pq) (type fixnum start))
|
---|
| 73 | (dolist (pair b pq)
|
---|
| 74 | (priority-queue-insert pq pair)))
|
---|
| 75 |
|
---|
| 76 | (defun pair-queue-insert (b pair)
|
---|
| 77 | (priority-queue-insert b pair))
|
---|
| 78 |
|
---|
| 79 | (defun pair-queue-remove (b)
|
---|
| 80 | (priority-queue-remove b))
|
---|
| 81 |
|
---|
| 82 | (defun pair-queue-size (b)
|
---|
| 83 | (priority-queue-size b))
|
---|
| 84 |
|
---|
| 85 | (defun pair-queue-empty-p (b)
|
---|
| 86 | (priority-queue-empty-p b))
|
---|
[162] | 87 |
|
---|
[3922] | 88 | (defclass selection-strategy ()
|
---|
| 89 | (:documentation "Sets up variables *PAIR-KEY-FUNCTION* and *PAIR-ORDER* used
|
---|
| 90 | to determine the priority of critical pairs in the priority queue.")
|
---|
| 91 | ((pair-key-fn :initform nil :accessor pair-key-fn)
|
---|
[3923] | 92 | (pair-order-fn :initform nil :accessor monomial-order-fn)))
|
---|
[3922] | 93 |
|
---|
[3923] | 94 | (defun make-normal-strategy (monomial-order-fn)
|
---|
| 95 | "Make a normal selection strategy for a given monomial order. A pair
|
---|
| 96 | with the minimal LCM of leading monomials is selected."
|
---|
| 97 | (make-instance 'selection-strategy
|
---|
| 98 | :pair-key-fn #'(lambda (p q) (universal-lcm (leading-monomial p) (leading-monomial q)))
|
---|
| 99 | :pair-order-fn #'monomial-order-fn))
|
---|
[162] | 100 |
|
---|
[3923] | 101 | (defun make-min-total-degree-strategy ()
|
---|
| 102 | "Make a selection strategy where a pair with a minimum total degree of LCM
|
---|
| 103 | of leading monomials is selected."
|
---|
| 104 | (make-instance 'selection-strategy
|
---|
| 105 | :pair-key-fn #'(lambda (p q) (total-degree (universal-lcm (leading-monomial p) (leading-monomial q))))
|
---|
| 106 | :pair-order* #'<))
|
---|
| 107 |
|
---|
| 108 | (defun make-minimal-length-strategy ()
|
---|
| 109 | "Make a selection strategy where a pair with the minimum combined length of both
|
---|
| 110 | polynomials is selected."
|
---|
| 111 | (make-instance 'selection-strategy
|
---|
| 112 | :pair-key-fn #'(lambda (p q) (+ (poly-length p) (poly-length q)))
|
---|
| 113 | :pair-order #'<))
|
---|
| 114 |
|
---|