Decouple deliberation and metadata.

* Rename ^decision to ^deliberation
* Separate ^decision into ^deliberation and ^deliberation-info
main
Edward L Platt 2 years ago
parent 2d4d20bd54
commit a4c419b773

@ -12,18 +12,12 @@
;;; See the License for the specific language governing permissions and ;;; See the License for the specific language governing permissions and
;;; limitations under the License. ;;; limitations under the License.
(use-modules (srfi srfi-1) (define-module (deliberate)
(goblins) #:use-module (srfi srfi-1)
(goblins vrun) #:use-module (goblins)
(goblins actor-lib methods)) #:use-module (goblins vrun)
#:use-module (goblins actor-lib methods)
;; Commented out until I figure out how to set up a dev environment #:export (^deliberation ^deliberation-info ^ranked-choice-vote ^ranked-ballot ^ranked-preference))
; (define-module (deliberate)
; #:use-module (srfi srfi-1)
; #:use-module (goblins)
; #:use-module (goblins vrun)
; #:use-module (goblins actor-lib methods)
; #:export (^decision ^ranked-choice-vote ^ranked-ballot ^ranked-preference))
;; Constructor for ^cell ;; Constructor for ^cell
;; Stores a single updatable value ;; Stores a single updatable value
@ -41,7 +35,6 @@
((set new-value) (bcom (^cell bcom new-value))) ((set new-value) (bcom (^cell bcom new-value)))
)) ))
;; Constructor for ^attenuated ;; Constructor for ^attenuated
;; Attenuates another goblins object ;; Attenuates another goblins object
;; ;;
@ -57,11 +50,27 @@
(error (format #f "Message not permitted: [~a]" message)) (error (format #f "Message not permitted: [~a]" message))
))) )))
;; Constructor for ^decision ;; Constructor for ^deliberation-info
;; A decision with multiple possible alternative outcomes ;; Information about a deliberation
;;
;; Parameters:
;; title: Title of the deliberation
;;
;; Messages:
;; get-title: Return the title
;; set-title: new-title: Set the title to new-title
;;
(define (^deliberation-info bcom title)
(methods
((get-title) title)
((set-title) (bcom (^decision bcom title)))
))
;; Constructor for ^deliberation
;; A deliberation with multiple possible alternative outcomes
;; ;;
;; Parameters: ;; Parameters:
;; title: Title of the decision ;; title: Title of the deliberation
;; ;;
;; Messages: ;; Messages:
;; get-title: Return the title ;; get-title: Return the title
@ -70,18 +79,19 @@
;; represented by the string alt. ;; represented by the string alt.
;; get-alternatives: Return a list of all alteratives ;; get-alternatives: Return a list of all alteratives
;; ;;
(define (^decision _bcom title) (define (^deliberation _bcom title)
(let ( (let (
(title (spawn ^cell title)) (info (spawn ^deliberation-info title))
(alternatives (spawn ^cell '())) (alternatives (spawn ^cell '()))
) )
(methods (methods
((get-title) ($ title 'get)) ((get-title) ($ info 'get-title))
((set-title new-title) ($ title 'set new-title)) ((set-title new-title) ($ info 'set-title new-title))
((add-alternative alt) ((add-alternative alt)
(define old-alts ($ alternatives 'get)) (define old-alts ($ alternatives 'get))
($ alternatives 'set (cons alt old-alts))) ($ alternatives 'set (cons alt old-alts)))
((get-alternatives) ($ alternatives 'get)) ((get-alternatives) ($ alternatives 'get))
((debug-alternatives) alternatives)
))) )))
;; Constructor for ^ranked-preference ;; Constructor for ^ranked-preference
@ -112,7 +122,8 @@
;; Allow one constituent to update their rank-order preference ;; Allow one constituent to update their rank-order preference
;; ;;
;; Parameters: ;; Parameters:
;; decision: The decision this ballot applies to ;; deliberation-info: deliberation-info relevnt to this ballot
;; alternatives: cell containing a list of alternatives
;; ;;
;; Messages: ;; Messages:
;; update-vote f: Updates the constituent's vote on this ballot. ;; update-vote f: Updates the constituent's vote on this ballot.
@ -122,13 +133,13 @@
;; get-preference: Returns a ^ranked-preference associated with this ballot. ;; get-preference: Returns a ^ranked-preference associated with this ballot.
;; The object is attenuated to be read-only. ;; The object is attenuated to be read-only.
;; ;;
(define (^ranked-ballot _bcom decision) (define (^ranked-ballot _bcom deliberation-info alternatives)
(define ranking (spawn ^ranked-preference '())) (define ranking (spawn ^ranked-preference '()))
(methods (methods
((update-vote f) ((update-vote f)
(let* ((alternatives ($ decision 'get-alternatives)) (let* ((alt-list ($ alternatives 'get))
(ranks (f alternatives)) (ranks (f alt-list))
(new-ranking (reorder alternatives ranks))) (new-ranking (reorder alt-list ranks)))
($ ranking 'set new-ranking))) ($ ranking 'set new-ranking)))
((get-preference) (spawn ^attenuated ranking '(get get-rank))) ((get-preference) (spawn ^attenuated ranking '(get get-rank)))
)) ))
@ -137,24 +148,33 @@
;; A updateable vote using ranked choice preferences ;; A updateable vote using ranked choice preferences
;; ;;
;; Parameters: ;; Parameters:
;; decision: The decision this vote refers to ;; deliberation-info: deliberation-info relevant to this vote
;; alternatives: cell containig list of altenatives
;; ;;
;; Messages: ;; Messages:
;; get-ballots: Return the list of ballots ;; get-ballots: Return the list of ballots
;; add-ballot: Add a new ballot to this vote and return it ;; add-ballot: Add a new ballot to this vote and return it
;; ;;
(define (^ranked-choice-vote bcom decision) (define (^ranked-choice-vote bcom deliberation-info alternatives)
(define ballots (spawn ^cell '())) (define ballots (spawn ^cell '()))
(methods (methods
((get-ballots) ($ ballots 'get)) ((get-ballots) ($ ballots 'get))
((add-ballot) ((add-ballot)
(define ballot (spawn ^ranked-ballot decision)) (define ballot (spawn ^ranked-ballot deliberation-info alternatives))
(define old-ballots ($ ballots 'get)) (define old-ballots ($ ballots 'get))
($ ballots 'set (cons ballot old-ballots)) ($ ballots 'set (cons ballot old-ballots))
ballot) ballot)
((get-profile)
;; This is a very space-heavy representation
;; Would be better to use a hashmap keyed on rankings with counts as values
(map (lambda (ballot) ($ ($ ballot 'get-preference) 'get))
ballots))
)) ))
(define (^social-preference-borda _bcom profile)
#f)
;;; UTILITY CODE ;;; UTILITY CODE
;; Return a list of integers in the half-open interval [low, high) ;; Return a list of integers in the half-open interval [low, high)

@ -1,10 +1,15 @@
(use-modules (deliberate)
(goblins)
(goblins vrun)
(goblins actor-lib methods))
(define a-vat (spawn-vat)) (define a-vat (spawn-vat))
(define-vat-run a-run a-vat) (define-vat-run a-run a-vat)
(define dec (a-run (spawn ^decision "Bike Shed"))) (define delib (a-run (spawn ^deliberation "Bike Shed")))
(a-run ($ dec 'add-alternative "red")) (a-run ($ delib 'add-alternative "red"))
(a-run ($ dec 'add-alternative "green")) (a-run ($ delib 'add-alternative "green"))
(a-run ($ dec 'add-alternative "blue")) (a-run ($ delib 'add-alternative "blue"))
(define vote (a-run (spawn ^ranked-choice-vote dec))) (define vote (a-run (spawn ^ranked-choice-vote delib ($ delib 'debug-alternatives))))
(define ballot (a-run ($ vote 'add-ballot))) (define ballot (a-run ($ vote 'add-ballot)))
(define (rank312 alts) '(3 1 2)) (define (rank312 alts) '(3 1 2))

Loading…
Cancel
Save