|
|
@ -17,39 +17,10 @@
|
|
|
|
#:use-module (goblins)
|
|
|
|
#:use-module (goblins)
|
|
|
|
#:use-module (goblins vrun)
|
|
|
|
#:use-module (goblins vrun)
|
|
|
|
#:use-module (goblins actor-lib methods)
|
|
|
|
#:use-module (goblins actor-lib methods)
|
|
|
|
|
|
|
|
#:use-module (deliberate utils)
|
|
|
|
|
|
|
|
#:use-module (deliberate preference)
|
|
|
|
#:export (^deliberation ^deliberation-info ^ranked-choice-vote ^ranked-ballot ^ranked-preference))
|
|
|
|
#:export (^deliberation ^deliberation-info ^ranked-choice-vote ^ranked-ballot ^ranked-preference))
|
|
|
|
|
|
|
|
|
|
|
|
;; Constructor for ^cell
|
|
|
|
|
|
|
|
;; Stores a single updatable value
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Parameters:
|
|
|
|
|
|
|
|
;; value: The value to store
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Messages:
|
|
|
|
|
|
|
|
;; get: returns the current value
|
|
|
|
|
|
|
|
;; set new-value: updates object to store new-value
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
(define (^cell bcom value)
|
|
|
|
|
|
|
|
(methods
|
|
|
|
|
|
|
|
((get) value)
|
|
|
|
|
|
|
|
((set new-value) (bcom (^cell bcom new-value)))
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Constructor for ^attenuated
|
|
|
|
|
|
|
|
;; Attenuates another goblins object
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Parameters:
|
|
|
|
|
|
|
|
;; obj: Object to attenuate
|
|
|
|
|
|
|
|
;; allowed: List of messages that will be delegated to obj, others will
|
|
|
|
|
|
|
|
;; raise an error
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
(define (^attenuated _bcom obj allowed)
|
|
|
|
|
|
|
|
(lambda (message)
|
|
|
|
|
|
|
|
(if (memq message allowed)
|
|
|
|
|
|
|
|
($ obj message)
|
|
|
|
|
|
|
|
(error (format #f "Message not permitted: [~a]" message))
|
|
|
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Constructor for ^deliberation-info
|
|
|
|
;; Constructor for ^deliberation-info
|
|
|
|
;; Information about a deliberation
|
|
|
|
;; Information about a deliberation
|
|
|
|
;;
|
|
|
|
;;
|
|
|
@ -82,48 +53,21 @@
|
|
|
|
(define (^deliberation _bcom title)
|
|
|
|
(define (^deliberation _bcom title)
|
|
|
|
(let (
|
|
|
|
(let (
|
|
|
|
(info (spawn ^deliberation-info title))
|
|
|
|
(info (spawn ^deliberation-info title))
|
|
|
|
(alternatives (spawn ^cell '()))
|
|
|
|
(alternatives (spawn ^alternatives title))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(methods
|
|
|
|
(methods
|
|
|
|
((get-title) ($ info 'get-title))
|
|
|
|
((get-title) ($ info 'get-title))
|
|
|
|
((set-title new-title) ($ info 'set-title new-title))
|
|
|
|
((set-title new-title) ($ info 'set-title new-title))
|
|
|
|
((add-alternative alt)
|
|
|
|
((add-alternative alt) ($ alternatives 'add alt))
|
|
|
|
(define old-alts ($ alternatives 'get))
|
|
|
|
((get-alternatives) ($ alternatives 'alternatives))
|
|
|
|
($ alternatives 'set (cons alt old-alts)))
|
|
|
|
|
|
|
|
((get-alternatives) ($ alternatives 'get))
|
|
|
|
|
|
|
|
((debug-alternatives) alternatives)
|
|
|
|
|
|
|
|
)))
|
|
|
|
)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Constructor for ^ranked-preference
|
|
|
|
|
|
|
|
;; One constituent's preferences as an ordered ranking
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Parameters:
|
|
|
|
|
|
|
|
;; ranking: A list of alternatives from most to least preferred
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Messages:
|
|
|
|
|
|
|
|
;; get: Return the ranked list of alternatives
|
|
|
|
|
|
|
|
;; set new-ranking: Updates the ranking to new-ranking
|
|
|
|
|
|
|
|
;; get-rank alternative: Return the rank of alternative (1 is most
|
|
|
|
|
|
|
|
;; preferred).
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
(define (^ranked-preference bcom ranking)
|
|
|
|
|
|
|
|
(methods
|
|
|
|
|
|
|
|
((get) ranking)
|
|
|
|
|
|
|
|
((set new-ranking) (bcom (^ranked-preference bcom new-ranking)))
|
|
|
|
|
|
|
|
((get-rank alternative)
|
|
|
|
|
|
|
|
(let ((alt-index
|
|
|
|
|
|
|
|
(list-index (lambda (alt) (equal? alt alternative)) ranking)))
|
|
|
|
|
|
|
|
(if (number? alt-index)
|
|
|
|
|
|
|
|
(+ 1 alt-index)
|
|
|
|
|
|
|
|
(+ 1 (length ranking)))))
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Constructor for ^ranked-ballot
|
|
|
|
;; Constructor for ^ranked-ballot
|
|
|
|
;; Allow one constituent to update their rank-order preference
|
|
|
|
;; Allow one constituent to update their rank-order preference
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
;; Parameters:
|
|
|
|
;; Parameters:
|
|
|
|
;; deliberation-info: deliberation-info relevnt to this ballot
|
|
|
|
;; deliberation-info: ^deliberation-info relevnt to this ballot
|
|
|
|
;; alternatives: cell containing a list of alternatives
|
|
|
|
;; alternatives: ^alternatives object representing possible outcomes
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
;; Messages:
|
|
|
|
;; Messages:
|
|
|
|
;; update-vote f: Updates the constituent's vote on this ballot.
|
|
|
|
;; update-vote f: Updates the constituent's vote on this ballot.
|
|
|
@ -170,54 +114,3 @@
|
|
|
|
(map (lambda (ballot) ($ ($ ballot 'get-preference) 'get))
|
|
|
|
(map (lambda (ballot) ($ ($ ballot 'get-preference) 'get))
|
|
|
|
ballots))
|
|
|
|
ballots))
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (^social-preference-borda _bcom profile)
|
|
|
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; UTILITY CODE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Return a list of integers in the half-open interval [low, high)
|
|
|
|
|
|
|
|
(define (range low high)
|
|
|
|
|
|
|
|
(if (eq? low high)
|
|
|
|
|
|
|
|
'()
|
|
|
|
|
|
|
|
(cons low (range (+ 1 low) high))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Combine lists component-wise
|
|
|
|
|
|
|
|
;; Similar to python zip()
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Parameters:
|
|
|
|
|
|
|
|
;; args: Any number of lists
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Returns:
|
|
|
|
|
|
|
|
;; A list. The nth element is a list of the
|
|
|
|
|
|
|
|
;; nth elements of each argument
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
(define (zip . args)
|
|
|
|
|
|
|
|
(if (or (nil? args) (memq '() args))
|
|
|
|
|
|
|
|
'()
|
|
|
|
|
|
|
|
(cons (map car args)
|
|
|
|
|
|
|
|
(apply zip (map cdr args)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Reorder one list by another
|
|
|
|
|
|
|
|
;; A reordering is applied to lst such that the same reordering would
|
|
|
|
|
|
|
|
;; Put rank in asending oder.
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Parameters:
|
|
|
|
|
|
|
|
;; lst: The list to reorder
|
|
|
|
|
|
|
|
;; ranks: The list to sort by
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Returns:
|
|
|
|
|
|
|
|
;; A reordered copy of lst
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
(define (reorder lst ranks)
|
|
|
|
|
|
|
|
(let* ((pairs (zip lst ranks))
|
|
|
|
|
|
|
|
(ranked-pairs
|
|
|
|
|
|
|
|
(filter (lambda (pair) (not (eq? #f (cadr pair))))
|
|
|
|
|
|
|
|
pairs))
|
|
|
|
|
|
|
|
(sorted-pairs
|
|
|
|
|
|
|
|
(sort ranked-pairs (lambda (a b) (< (cadr a) (cadr b))))))
|
|
|
|
|
|
|
|
(map car sorted-pairs)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|