close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/pair-queue.lisp@ 3938

Last change on this file since 3938 was 3938, checked in by Marek Rychlik, 9 years ago

* empty log message *

File size: 5.4 KB
RevLine 
[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
36pairs, ordered by some partial order. Pair queue is a kind of priority queue.")
37 )
[449]38
[450]39(in-package :pair-queue)
40
[3919]41(defclass critical-pair ()
[3921]42 ((first :initform nil :initarg :first :accessor critical-pair-first :type poly)
43 (second :initform nil :initarg :second :accessor critical-pair-second :type poly))
[3930]44 (:documentation "Represents a critical pair, i.e. a pair of two polynomials. The derived
45classes may add extra data used in computing the order of critical pairs."))
[3919]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
[3927]55(defclass selection-strategy ()
[3932]56 ((pair-key-fn :initform (error "Must specify PAIR-KEY-FN") :initarg :pair-key-fn :accessor pair-key-fn)
57 (pair-order-fn :initform (error "Must specify PAIR-ORDER-FN") :initarg :pair-order-fn :accessor pair-order-fn))
[3931]58 (:documentation "Represents a critical pair selection strategy. The
59two ingredients of a strategy is a function PAIR-KEY-FUNCTION which
60computes a key from the critical pair, which can be any type of data,
61and a function PAIR-ORDER-FN used to compaire the calculated keys to
62determine which pair is more promising and should be considered first."))
[60]63
[3932]64(defmethod print-object ((self selection-strategy) stream)
65 (print-unreadable-object (self stream :type t :identity t)
66 (with-accessors ((pair-key-fn pair-key-fn)
67 (pair-order-fn pair-order-fn))
68 self
69 (format stream "PAIR-KEY-FN=~A PAIR-ORDER-FN=~A"
70 pair-key-fn pair-order-fn))))
71
72(defclass normal-selection-strategy (selection-strategy)
73 ((pair-key-fn :initform #'(lambda (p q) (universal-lcm (leading-monomial p) (leading-monomial q))))
74 (pair-order-fn :initform #'lex>))
75 (:documentation "The normal selection strategy for a given monomial order MONOMIAL-ORDER-FN. A pair
76with the minimal LCM of leading monomials is selected."))
77
[3933]78(defclass min-total-degree-strategy (selection-strategy)
79 ((pair-key-fn :initform #'(lambda (p q) (total-degree (universal-lcm (leading-monomial p) (leading-monomial q)))))
[3935]80 (pair-order :initform #'<))
[3933]81 (:documentation "Make a selection strategy where a pair with a
82minimum total degree of LCM of leading monomials is selected."))
[3932]83
[3933]84(defclass minimal-length-strategy (selection-strategy)
[3935]85 ((pair-key-fn :initform #'(lambda (p q) (+ (poly-length p) (poly-length q))))
86 (pair-order :initform #'<))
[3933]87 (:documentation "Make a selection strategy where a pair with the minimum combined length of both
88polynomials is selected."))
89
[3938]90(defclass critical-pair-queue (selection-strategy)
91 ((pq :type priority-queue)))
[3927]92
[3938]93(defmethod initialize-instance :after ((self critical-pair-queue) &key)
94 (make-priority-queue
95 :element-type 'critical-pair
96 :element-key #'(lambda (pair) (funcall pair-key-fn (critical-pair-first pair) (critical-pair-second pair)))
97 :test pair-order-fn))
98
[60]99(defun pair-queue-initialize (pq f start
100 &aux
101 (s (1- (length f)))
[3924]102 (b (nconc (makelist (make-instance 'critical-pair :first (elt f i) :second (elt f j))
[60]103 (i 0 (1- start)) (j start s))
[3924]104 (makelist (make-instance 'critical-pair :first (elt f i) :second (elt f j))
[60]105 (i start (1- s)) (j (1+ i) s)))))
106 "Initializes the priority for critical pairs. F is the initial list of polynomials.
107START is the first position beyond the elements which form a partial
108grobner basis, i.e. satisfy the Buchberger criterion."
109 (declare (type priority-queue pq) (type fixnum start))
110 (dolist (pair b pq)
111 (priority-queue-insert pq pair)))
112
113(defun pair-queue-insert (b pair)
114 (priority-queue-insert b pair))
115
116(defun pair-queue-remove (b)
117 (priority-queue-remove b))
118
119(defun pair-queue-size (b)
120 (priority-queue-size b))
121
122(defun pair-queue-empty-p (b)
123 (priority-queue-empty-p b))
[162]124
[3922]125
[162]126
[3923]127
Note: See TracBrowser for help on using the repository browser.