SCARS
Model was written in NetLogo 5.3.1
•
Viewed 396 times
•
Downloaded 22 times
•
Run 0 times
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
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%%%%%%%% Experimention for SCARS %%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%%%%% SCARS == SPATIO-TEMPORAL COGNITIVE AGENT-BASED RECOMMENDER SYSTEM %%%%%% __includes [ "communication.nls" ;; Library for ACL exchanging messages "bdi.nls" ;; Library for Beliefs-desire-intention architecture "UserAgent.nls" ;; Cars BDI behavior ] extensions [gis array table] globals [ autobleue_data ;; GIS dataset about electric recharge points in Nice streets_data ;; GIS dataset about streets in Nice Ville nice_buildings ;; GIS dataset about touristic POI in Nice Ville center-x ;; center of the map center-y ;; center of the map mean-wait-time number random-accident-place counter ] breed [cars car] breed [workPlaces workPlace] breed [vertices vertice] cars-own [ speed ;; speed (optional in this demo) myposition ;; my actual position last-stop ;; last item in my path destination ;; a destination where to go mypath ;; a list of vertices to go to a destination step-in-path ;; steps in the path destination-entrance beliefs ;; information about their environment desires ;; state of affairs that an agent want to accomplish intentions ;; plan that allow an agent to achive its goals goals ;; list of possible desires that an agent want to achieve trust ;; the confidence degree distrust ;; the non-confidence degree incoming-queue;; exchanged messages with others agents wait-time ;; time waiting in traffic congestion time-of-simulation ] patches-own[road? distance-work distance-home centroid? id entrance] vertices-own [ myneighbors ;;agentset of neighboring vertices entrance? ;;if it is an entrance to a building test ;;used to delete in test ;;the follwoing variables are used and renewed in each path-selection dist ;;distance from original point to here doone ;;1 if has calculated the shortest path through this point, 0 otherwise lastnode ;;last node to this point in shortest path ] ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Setup%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% to setup ca reset-ticks load-data make-streets ;; setup-destinations add-agents set number 15 end to load-data ask patches [set pcolor white] set streets_data gis:load-dataset "paca/gis.osm_roads_free_1.shp";;;route sur Nice Ville set autobleue_data gis:load-dataset "Nice_shapefile/autobleue/autobleue.SHP";; Cartographie de point de recharge des autobleue sur Nice et environs ; set nice_buildings gis:load-dataset "Nice_shapefile/POI/export_musees_galeries_RGF93L93_shapefile.shp" draw end to draw setup-world-envelope gis:set-drawing-color white gis:draw streets_data 1 gis:set-drawing-color blue foreach gis:feature-list-of autobleue_data [ gis:draw ? 1] ;gis:set-drawing-color black gis:draw nice_buildings 1 ;gis:set-drawing-color 25 gis:draw gmu-walkway 1.0 ;identify centroids and assign IDs to centroids foreach gis:feature-list-of autobleue_data[ let center-point gis:location-of gis:centroid-of ? if not empty? center-point [ ask patch item 0 center-point item 1 center-point [ set centroid? true set id gis:property-value ? "IDENT" ] ]] end to setup-world-envelope gis:set-world-envelope gis:envelope-of autobleue_data let world gis:world-envelope let x0 (item 0 world + item 1 world) / 2 + center-x; center let y0 (item 2 world + item 3 world) / 2 + center-y let W0 zoom * (item 1 world - item 0 world) / 2 ; half-widths let H0 zoom * (item 3 world - item 2 world) / 2 set world (list (x0 - W0) (x0 + W0) (y0 - H0) (y0 + H0)) gis:set-world-envelope world end to center while [not mouse-down?] [wait .01] set center-x center-x + (mouse-xcor * gis-patch-size) set center-y center-y + (mouse-ycor * gis-patch-size) draw end to-report gis-patch-size ;; note: assume width & height same let world gis:world-envelope report (item 1 world - item 0 world) / (max-pxcor - min-pxcor) end to zoom-in set zoom max list .01 precision (zoom - .1) 2 draw end to zoom-out set zoom min list 1.2 precision (zoom + .1) 2 draw end to make-streets foreach gis:feature-list-of streets_data[ foreach gis:vertex-lists-of ? ; for the road feature, get the list of vertices [ let previous-node-pt nobody foreach ? ; for each vertex in road segment feature [ let location gis:location-of ? if not empty? location [ ;ifelse any? vertices with [(xcor = item 0 location and ycor = item 1 location) ] ; if there is not a road-vertex here already ;[] ;[ create-vertices 1 [set myneighbors n-of 0 turtles ;;empty set xcor item 0 location set ycor item 1 location ask patch xcor ycor [set road? true] set size 0.2 set shape "circle" set color brown set hidden? true ;; create link to previous node ifelse previous-node-pt = nobody [] ; first vertex in feature [create-link-with previous-node-pt] ; create link to previous node set previous-node-pt self] ;] ]]] ] ;;delete duplicate vertices (there may be more than one vertice on the same patch due to reducing size of the map). therefore, this map is simplified from the original map. delete-duplicates ;;delete some nodes not connected to the network ask vertices [set myneighbors link-neighbors] delete-not-connected ask vertices [set myneighbors link-neighbors] ;;find nearest node to become entrance ask patches with [centroid? = true][set entrance min-one-of vertices in-radius 5 [distance myself] ask entrance [set entrance? true]] ; if show_nodes? [ask vertices [set hidden? false]] ; if show_entrances? [ask entrance [set hidden? false set shape "star" set size 0.5]]] ask links [set thickness 0.1 set color orange] end to delete-duplicates ask vertices [ if count vertices-here > 1[ ask other vertices-here [ ask myself [create-links-with other [link-neighbors] of myself] die] ] ] end to delete-not-connected ask vertices [set test 0] ask one-of vertices [set test 1] repeat 500 [ ask vertices with [test = 1] [ask myneighbors [set test 1]]] ask vertices with [test = 0][die] end to add-agents create-cars cars_number[ set shape "car" set destination nobody set last-stop nobody set myposition one-of vertices move-to myposition set intentions [] set desires table:make table:put desires "go-to-dest" 0.6 set beliefs table:make set trust precision(random-float 1) 1 ;;random value in [0 1] interval set wait-time 0 set incoming-queue [] ] ; create-cars 1[ ; set shape "car" ; set label "BOB" set label-color black ; set myposition one-of vertices ; move-to myposition ; set destination nobody ; set last-stop nobody ; set beliefs table:make ; set desires table:make ; table:put desires "go-to-dest" 0.9 ; set intentions [] ; set trust precision(random-float 1) 1 ;;random value in [0 1] interval ; set wait-time 0 ; set incoming-queue [] ; ; ] end ;%%%%%%%%%%%%%%%%%%%%% To Go %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% to shortest-path-select[todest] ;;use the A-star algorithm to find the shortest path (shortest in terms of distance) set mypath [] set step-in-path 0 ask vertices [set dist 9999 set doone 0 set lastnode nobody set color brown] ask myposition [set dist 0 ] ;;distance to original node is 0 while [count vertices with [doone = 0] > 0][ ask vertices with [dist < 9999 and doone = 0][ ask myneighbors [ let dist0 distance myself + [dist] of myself ;;renew the shorstest distance to this point if it is smaller if dist > dist0 [set dist dist0 set doone 0 ;;done=0 if dist renewed, so that it will renew the dist of its neighbors set lastnode myself] ;;record the last node to reach here in the shortest path ;set color red ;;all roads searched will get red ] set doone 1 ;;set done 1 when it has renewed it neighbors ]] ;;put nodes in shortest path into a list let x todest while [x != myposition] [ if show_path? = true [ask x [set color black] ] ;;highlight the shortest path set mypath fput x mypath add-intention (word "move-to" word "" x) (word "true") set x [lastnode] of x ] set last-stop last mypath end to go-to-dest if destination = nobody or destination = 0 [ set destination one-of patches with [centroid? = true] set destination-entrance [entrance] of destination shortest-path-select destination-entrance ] end to go ask cars [ move-forward listen-to-messages set goals objectives beliefs desires get-recommendation(goals) execute-intentions random-event if (speed = 0) and (not any? patches with [centroid? = true] in-radius 3) [ set wait-time wait-time + 1] if not any? patches with [centroid? = true] in-radius 3 [set time-of-simulation ticks ] ] ask cars [if not empty? table:to-list beliefs [send-messages(one-of table:to-list beliefs)] listen-to-messages] tick end to random-event if (ticks > 15) [set number number - 1 if number >= 0 [ set random-accident-place one-of vertices ask random-accident-place [set pcolor red set entrance? false] if (any? patches with [pcolor = red] in-radius 10) [ ;print "An accident just occured nearby" table:put beliefs (word "" random-accident-place ) 0.7 set trust 0.7 ] ] ] ;min-one-of vertices in-radius 100 [distance myself] end to move-forward let turtles-ahead turtles in-cone 2 45 ifelse any? turtles-ahead [ slow rt 7 + random-float 3 ] [speed-up] end to slow if (speed > 0) [set speed speed - 1] end to speed-up let turtles-ahead turtles-at 0 1 if (not any? turtles-ahead) [ set speed speed + 1] ;if ([road?] of patch-ahead 1 = true) and (not any? turtles-ahead) [ set speed speed + 1] end to draw-plots set mean-wait-time mean [wait-time] of cars set-current-plot-pen "mean-wait-time" plot mean-wait-time end to close-street[identifier] ask vertice identifier [die] end to compute-new-path-to-dest[dest] set destination-entrance [entrance] of dest shortest-path-select destination-entrance end to-report meters-per-patch ;; maybe should be in gis: extension? let world gis:world-envelope ; [ minimum-x maximum-x minimum-y maximum-y ] let x-meters-per-patch (item 1 world - item 0 world) / (max-pxcor - min-pxcor) let y-meters-per-patch (item 3 world - item 2 world) / (max-pycor - min-pycor) report mean list x-meters-per-patch y-meters-per-patch end ;%%%%%%%%%%%%%%%%%%%%%%%%% Cars BDI Behavior %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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 to get-recommendation [g] ifelse (member? "go-to-dest" map first table:to-list g)[go-to-dest] [do-nothing] end to evaluate-proposal[msg] ;send add-receiver get-sender msg add-content msg create-message "Accept proposal" ifelse (([trust] of turtle read-from-string get-sender msg) >= 0.5);; and (item 3 get-content 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 cars 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) update-beliefs(msg) ;; update-desires(msg) ] if performative = "Reject proposal" [do-nothing] ] end to update-beliefs [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 cars [ ifelse table:has-key? beliefs item 0 proposal[do-nothing] [ table:put beliefs item 0 proposal min list (item 1 proposal) ([trust] of turtle read-from-string trustee) foreach intentions [if item 0 ? = word "move-to" word "" item 0 proposal [ set speed 0 set intentions [] compute-new-path-to-dest destination execute-intentions] ;[let confiance [trust] of car read-from-string trustee set confiance 0 ] ] ] ] ;;;with Trust end
There is only one version of this model, created about 8 years ago by AAMAS 2017.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
SCARS.png | preview | A preview of the simulation at a specific time point | about 8 years ago, by AAMAS 2017 | Download |
SCARS.png | png | A preview of the simulation at a specific time point. | about 8 years ago, by AAMAS 2017 | Download |
This model does not have any ancestors.
This model does not have any descendants.