Example of a BDI Recommender Agent

Example of a BDI Recommender Agent preview image

1 collaborator

Default-person AAMAS 2017 (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.3.1 • Viewed 471 times • Downloaded 34 times • Run 0 times
Download the 'Example of a BDI Recommender Agent' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals[number in dxcor dycor]
__includes ["bdi.nls" "communication.nls"]
extensions [array table]
breed [users user]
breed [doctors doctor]
users-own[beliefs desires goals intentions trust incoming-queue]
doctors-own [beliefs desires goals intentions trust incoming-queue]
patches-own [ road street-name]

to setup
  clear-all
  set number 1
  set in 1
  setup-users
  setup-doctors
  setup-links
  reset-ticks
end 
;;%%%%%%%%%%%% setting up Bob's initial variables %%%%%%%%%%%

to setup-users
  create-users 1[
    set shape "person"
    set size 3
    set color red
    set label "BOB"
    set trust 0.5
    setxy random-xcor random-ycor
    set beliefs table:make
    table:put beliefs "Not-eh" 0.4
    table:put beliefs "bs" 0.9
    set incoming-queue[]
    set desires table:make
    table:put desires "pa" 0.8
    table:put desires "wr" 0.8
    table:put desires "eh" 0.9
    table:put desires "w" 0.75
   ;; table:put desires "wr-and-Not-eh" 0.95
    set intentions []

    ]
end 
;;%%%%%%%%%%%% setting up Bob's Doctor initial variables %%%%%%%%%%%

to setup-doctors
  create-doctors 1[
    set shape "person doctor"
    setxy random-xcor random-ycor
    set dxcor xcor
    set dycor ycor
    set size 3
    set color cyan
    set label-color red
    set label "DOCTOR"
    set trust 0.9
    set beliefs table:make
    table:put beliefs "Not-pa"  1
    set incoming-queue[]
    ]
end 
;;%%%%%%%% Create link between Bob and his doctor %%%%%%%%%%%%%%%%%%

to setup-links
  ask users [create-link-with doctor 1]
end 

;;%%%%%%%%%%% Defining Bob's behavior %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

to go
  user-behaviour
  tick
end 

to user-behaviour
 ask users [  listen-to-messages
              set number number - 1
              if number >= 0 [
              print word "Bob's Initial Beliefs Base: " beliefs
              print word "Bob's Initial Desires Base: " desires
              set goals objectives beliefs desires
              print word "Elected goals:" goals
              get-recommendation(goals)
              ]
              execute-intentions

              ]

if ticks >= 50 [ask doctors [set in in - 1 if in >= 0 [send-messages(one-of table:to-list beliefs)] listen-to-messages]]
end 

to-report objectives[B D]
;; input: beliefs and desires
;; output : goals which are the most desired and possible set of desires
let gamma 0
let g possible-desires B D gamma
report g stop
;;while [gamma < 1][
ifelse empty? table:to-list g [report g]
[
  let alpha min(map [last ?] table:to-list B)
   if alpha <= gamma [
     set alpha 1
     set gamma alpha]
   ]
;;]
end 
;;;;;Elect a list of possible and coherent desires as goals ragrding a list of beliefs

to-report possible-desires [B D x]

loop [
let delta max(map [last ?] table:to-list D)
let Des table:make
foreach  table:keys D [
  if table:get D ? = delta
  [ let i ?
    table:put Des ? (table:get D ?)
   ;; if empty? table:to-list B [report Des]
   foreach table:keys B
     [ ;;print word "Not-"i
     if ? = word "Not-" i and table:get B  ? > x [table:remove Des i
                                                  table:remove D i
                                                 ]


     ]
  ]
  ]  if not empty? table:to-list Des [report Des  stop]]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; Axioms and Inferences Rules ;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to execute-rule-1[table-name]
   ;;;for every value of desire/belief/goal, if its value greater than 0 then its opposite is not possible(its value is equal to zero)
   ifelse empty? table:to-list table-name [][
     foreach table:keys table-name[
       if table:get table-name ? > 0
       [table:put table-name  (word "Not-"?)  0]

       ]]
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;Bridge rules;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to exucute-bridge-rule-1[table1 table2]
   foreach table:keys table1[
     if table:get table1 ? > 0
     [ table:put table2 (word "Not-" ?) 0 ]
    ]
end 

to get-recommendation [g]
   ;; if (member? "pa" map first table:to-list g) and (member? "wr" map first table:to-list g) [print "Trueeeeeeeee"]
    ifelse (member? "pa" map first table:to-list g) and (member? "wr" map first table:to-list g)[
    add-intention (word "move-to-dest -9 16 ") (word "at-dest -9  16 ")
    add-intention (word "move-to-dest 4 2 ") (word "at-dest 4  2 ")
    add-intention (word "move-to-dest -14 -11 ") (word "at-dest -14  -11 ")
    ]
    [print "%%%%%%%%%%%%%% You should have a special diet program %%%%%%%%%%%"
     print "%%%%%%%%%%%%%% Please Consider to see a health provider %%%%%%%%%"
     ;;add-intention (word "move-to-dest 19 -15 ") (word "at-dest 19  -15 ")
     add-intention (word "move-to-dest dxcor dycor") (word "at-dest dxcor dycor")]
end 

to move-along-circle
  ;;pen-down
  fd (pi * 15 / 180) * (25 / 50)
  rt 25 / 50
end 

to move-to-dest [x y]
     face patch x y
     fd 1
end 

to-report at-dest [x y]
  if patch-here = patch x y [
  print  "Executing intentions...."
  ]
  report patch-here = patch x y
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;; Communication Context ;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to evaluate-proposal[msg]
  ;;if the sender agent is trusted regarding the information he sends then we accept proposal else it is rejected
  ;; if (trust of first (filter [not is-number? ? and member? "sender:" ?] msg) > 0.5
 ;; print who
 ;;  print trust
 ;; print get-sender msg
   ;;ifelse (any? link-neighbors with [trust > 0.5])
   ifelse ([trust] of doctor read-from-string get-sender msg > 0.5)

   [send add-receiver get-sender msg add-content msg create-message "Accept proposal"]
   [send add-receiver get-sender msg  create-message "Reject proposal"]
end 
  ;;sending a proposal for similar agents

to send-messages [msg]
   broadcast-to other turtles with [link-neighbor? myself] add-content msg create-message "proposal"
end 

 ;;;to keep Listening to messages when running

to listen-to-messages
   let msg 0
   let performative 0
   while [not empty? incoming-queue ][
     set msg get-message
     set performative get-performative msg
     if performative = "proposal" [evaluate-proposal(msg)]
     if performative = "Accept proposal" [
                                           update-intentions(msg)
                                         ]
     if performative = "Reject proposal" [do-nothing]

     ]
end 

to update-intentions [msg]
  let proposal item 3 get-content msg
  let trustee  item 0 get-receivers msg

;      ;;;;;;;;;;;;;;;;;;;;;;;;;Re-compute the recommandation if the proposal is accepted;;;;;;;;
ask user 0 [
          table:put beliefs item 0 proposal min list (item 1 proposal) ([trust] of doctor read-from-string trustee)
          foreach intentions [remove-intention get-intention ]
          print word "Intentions" intentions
          print word "Bob's New beliefs base: " beliefs
          set goals objectives beliefs desires
          get-recommendation(goals)
          print word "Bob's New Goals: "goals
                    print word "Intentions" intentions
          execute-intentions ]
end 

There is only one version of this model, created over 8 years ago by AAMAS 2017.

Attached files

File Type Description Last updated
Example of a BDI Recommender Agent.png preview Preview for 'Example of a BDI Recommender Agent' over 8 years ago, by AAMAS 2017 Download

This model does not have any ancestors.

This model does not have any descendants.