CollaborationProject

CollaborationProject preview image

1 collaborator

Avatar_black leo wonay (Author)

Tags

collaborations 

Tagged by leo wonay almost 5 years ago

task 

Tagged by leo wonay almost 5 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.5 • Viewed 253 times • Downloaded 11 times • Run 0 times
Download the 'CollaborationProject' 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

;; declaration des races
breed [entities entite]
breed [objects objet]
breed [stocks stock]
breed [chargeurs chargeur]
breed [halos halo]

;; pour voir lorsque des entit�s s'aide
halos-own [
  temps
]

;; les chargeurs
chargeurs-own [
  energie
]

;; les stocks
stocks-own [
  place
]

;; les camions
entities-own [
  energie
  need-help?
  position-chargeur
  ]

;; initialisation

to Setup
  ;; (for this model to work with NetLogo's new plotting features,
  ;; __clear-all-and-reset-ticks should be replaced with clear-all at
  ;; the beginning of your setup procedure and reset-ticks at the end
  ;; of the procedure.)
  __clear-all-and-reset-ticks
  prepare-patches
  prepare-entities
  ask turtles [ set size 1.5 ]
end 

;; procedure go classique

to Go
  ;;deplacement des entit�s
  move-entite
  ;; recharge des chargeurs
  recharge_chargeur
  ;; actualisation du graph
  dessine-graph
  ;; arret de la simulation
  if count entities = 0 [ stop ]
  ;; affichage ou pas des labels
  if not verbose? [ask turtles [ set label "" ] ]
end 

;; procedure pour le graph

to dessine-graph
  set-current-plot "Stat"
  set-current-plot-pen "Entities"
  plot (count entities)
  set-current-plot-pen "Objects"
  plot (count objects) + (count entities with [color = green])
  if (Communication?)
  [
    set-current-plot-pen "Help"
    plot count entities with [need-help?]
  ]
end 

;; creation de la carte aleatoire

to prepare-patches
    ask patches [
      set pcolor black
      if random 100 < quantite_mur [ set pcolor grey ]
    ]
end 

;; creation des stocks, chargeurs, voitures et objets

to prepare-entities
    set-default-shape halos "face happy"
    
    ask n-of quantite_objet (patches with [pcolor = black])
  [
    sprout 1
      [ set color blue 
        set breed objects
        let ran random 2
        set shape "dot"
  ]
  ]
    ask n-of quantite_stock (patches with [pcolor = black])
  [
    sprout 1
      [ set color blue 
        set breed stocks
        set shape "factory"
        set place 0
        if verbose? [set label place]
        ]
  ]
      ask n-of quantite_chargeur (patches with [pcolor = black])
  [
    sprout 1
      [ set color yellow 
        set breed chargeurs
        set shape "building store"
        set energie energie_transportable
if verbose? [        set label energie]
        ]
  ]
  
ask n-of nombre_entite (patches with [pcolor = black])
  [
    sprout 1
      [ set color red 
        set breed entities
        set need-help? false
        set shape "car"
        set size 1.5
        set need-help? false
        set energie random (energie_transportable)
        set position-chargeur one-of chargeurs
        ]
  ]
end 

;; deplacement des entit�s

to move-entite
  ;; suppression des halos
  ask halos[
    set temps temps - 1
    if temps <= 0 [ die ]
  ]
  ;; modification de l'apparence des camions
  ask entities [
   if color = green [drop-object]
   if color = red [catch-object]
   
   ;; appel a laide en fonction de l'energie
   ifelse energie <= (energie_transportable * niveau_appel_aide / 100 ) 
   [
     if Communication? [
       set need-help? true
       ]
   ]
   [
   set need-help? false
   ]
   
   ;; autre fonctions de la simulation
   aide
   move
   recharge
   death
  ]
end 

;; aide des camions pour transmettre les localisations des postes de recharges

to aide 
;; acquisition de la meilleur position du chargeurs
let helpless entities with [need-help?]
set helpless helpless with [distance myself < 5]
set helpless min-one-of other helpless [distance myself]
let temp position-chargeur

;; transmition de l'informations
if helpless != nobody [
  let chargeur-etranger [position-chargeur] of helpless
  if 
  (distance position-chargeur < [energie] of helpless) 
  and 
  (distance position-chargeur < distance [position-chargeur] of helpless)
  and
  ([energie] of chargeur-etranger > 0)
    [
    ask helpless [
      set position-chargeur temp
      ]
    ;; creation du halo
    make-halo
    ]
]
end 

;; creation du halo

to make-halo
  hatch-halos 1
  [ set size 3
    set color lput 70 extract-rgb orange
    __set-line-thickness 0.5
    set temps 20
]
end 

;; recharge de lenergie des chargeurs

to recharge_chargeur
ask chargeurs[
if  energie <= energie_transportable [ set energie energie + regen_chargeur ] 
]
end 

;; prend de lenergie au chargeur pour recharger le vehicule

to recharge
  let prey one-of chargeurs-here
  if prey != nobody [ 
    set position-chargeur prey
    if energie <= energie_transportable [
    let temp energie_transportable - energie
    ifelse [energie] of prey >= temp [
      ask prey [ 
        set energie energie - temp
        ]
      set energie energie + temp
    ]
    
    [
    set energie [energie] of prey
    ask prey [ 
      set energie 0
      ]
    ]
    ask prey [if verbose? [set label energie]]
  ]
  ]
end 


;; mort et relache objet si objet poss�d�

to death
  if energie <= 0 [ 
    if color = green [
      hatch 1 [ 
        set color blue 
        set breed objects
        set shape "dot"
        let ran random 2
        set size 1.5
        set label ""
        ]
      set color red
    ]
    die
    ]
end 

;; procedure de deplacement pour eviter les murs

to move-avoid-wall
  ifelse ([pcolor] of patch-ahead 1 = black)
     [
     forward 1 
     ] 
     [
     right ( random 180 ) + 90
     forward 1
     ]
  set energie energie - 1
if verbose? [  set label energie]
end 

to move
  ifelse need-help? 
    [
      ;; deplacement vers le chargeur
    ifelse (distance position-chargeur < 1)
       [
       move-to position-chargeur 
       set need-help? false
       ]
      [
      face position-chargeur
      move-avoid-wall
      ]
    ] 
    [
      ;; deplacement aleatoire
    left random 50
    right random 50
    move-avoid-wall
    ]
end 

;; prend un objet

to catch-object
  let prey one-of objects-here
  if prey != nobody[ 
    ask prey [ die ]
      set color green
      set shape "truck"
      ]
end 

;; lache un objet sur le stock

to drop-object
  let prey one-of stocks-here
  if prey != nobody[ 
    ask prey [
      set place place + 1
if verbose? [set label place]
      ]
    set color red
    set shape "car"
      ]
end 

There is only one version of this model, created almost 5 years ago by leo wonay.

Attached files

File Type Description Last updated
CollaborationProject.png preview Preview for 'CollaborationProject' almost 5 years ago, by leo wonay Download

This model does not have any ancestors.

This model does not have any descendants.