The applet requires Java 1.4.1 or higher. It will not run on Windows 95 or Mac OS 8 or 9. Mac users must have OS X 10.2.6 or higher and use a browser that supports Java 1.4. (Safari works, IE does not. Mac OS X comes with Safari. Open Safari and set it as your default web browser under Safari/Preferences/General.) On other operating systems, you may obtain the latest Java plugin from Sun's Java site.
powered by NetLogo
view/download model file: green_car.nlogo
This section could give a general understanding of what the model is trying to show or explain.
This section could explain what rules the agents use to create the overall behavior of the model.
This section could explain how to use the model, including a description of each of the items in the interface tab.
This section could give some ideas of things for the user to notice while running the model.
This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.
This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.
This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
globals [destinations
charging_destinations
t]
breed [ bases base ]
breed [ schools school ]
breed [ shoppings shopping ]
breed [ officies office ]
breed [green_cars green_car]
breed [fuel_cars fuel_car]
breed [stations station]
green_cars-own [ destination
charging_destination
energy
pollution
consumption
]
fuel_cars-own [destination
pollution
consumption]
to setup
ca
setup-roads
setup-bases
setup-schools
setup-shoppings
setup-officies
setup-stations
setup-green_cars
setup-fuel_cars
choose_destination
low-battery
end
to setup-roads
ask patches with [ pycor >= -13 and pycor < -12]
[set pcolor grey]
ask patches with [ pycor >= 0 and pycor < 1]
[set pcolor grey]
ask patches with [ pycor >= 12 and pycor < 13]
[set pcolor grey]
ask patches with [ pxcor >= -13 and pxcor < -12]
[set pcolor grey]
ask patches with [ pxcor >= 0 and pxcor < 1]
[set pcolor grey]
ask patches with [ pxcor >= 12 and pxcor < 13]
[set pcolor grey]
end
to setup-bases
set-default-shape bases "house colonial"
create-bases 2
ask bases
[ set size 3
set color red]
ask base 0
[ setxy 12 -15
]
ask base 1
[ setxy -15 0
]
end
to setup-schools
set-default-shape schools "house colonial"
create-schools 2
ask schools
[ set size 3
set color brown]
ask school 2
[ setxy 2 -13]
ask school 3
[ setxy 10 12]
end
to setup-shoppings
set-default-shape shoppings "house colonial"
create-shoppings 2
ask shoppings
[set size 3
set color green]
ask shopping 4
[ setxy 2 0]
ask shopping 5
[ setxy -15 12]
end
to setup-officies
set-default-shape officies "house colonial"
create-officies 2
ask officies
[ set size 3
set color yellow]
ask office 6
[ setxy 12 -2]
ask office 7
[ setxy -6 -13]
end
to setup-stations
set-default-shape stations "fire"
create-stations 4
ask stations
[set size 2.5
set color yellow]
ask station 8
[setxy 6 0]
ask station 9
[setxy -13 -11]
ask station 10
[setxy -5 13]
ask station 11
[setxy 12 6]
end
to setup-green_cars
set-default-shape green_cars "car top"
create-green_cars green-cars
[ set size 2
set color green
set energy 200]
ask green_cars
[ifelse random (10) < 5
[setxy -15 0]
[setxy 12 -15]]
end
to setup-fuel_cars
set-default-shape fuel_cars "car top"
create-fuel_cars fuel-cars
[ set size 2
set color blue
move-to one-of patches with [pcolor = grey]]
ask green_cars ;direzione delle auto.
[if ((heading >= 0) and (heading < 90)) ; se la loro direzione è nord o nord-est, si muoveranno verso nord
[set heading 0]
if ((heading >= 90) and (heading < 180)) ; se la loro direzione è est o sud-est, si muoveranno verso est
[set heading 90]
if ((heading >= 180) and (heading < 270)) ; se la loro direzione è sud o sud-ovest, si muoveranno verso sud
[set heading 180]
if ((heading >= 270) and (heading < 360)) ; se la loro direzione è ovest o nord-ovest, si muoveranno verso ovest
[set heading 270]]
ask fuel_cars
[if ((heading >= 0) and (heading < 90))
[set heading 0]
if ((heading >= 90) and (heading < 180))
[set heading 90]
if ((heading >= 180) and (heading < 270))
[set heading 180]
if ((heading >= 270) and (heading < 360))
[set heading 270]]
end
to choose_destination ; possibili destinazioni che le auto possono raggiungere
ask green_cars
[set destinations (list school 2 school 3 shopping 4 shopping 5 office 6 office 7)
set destination item random 6 destinations ; scelta casuale dalla lista
set destination one-of destinations
]
ask fuel_cars
[set destinations (list school 2 school 3 shopping 4 shopping 5 office 6 office 7)
set destination item random 6 destinations
set destination one-of destinations
]
end
to low-battery ; possibili destinazioni per la ricarica delle batterie
ask green_cars
[ set charging_destinations (list base 0 base 1 station 8 station 9 station 10 station 11 )
set charging_destination item random 6 charging_destinations ; scelta casuale dalla lista
set destination one-of charging_destinations]
end
to go
tick
move-cars
imitation
if ticks = 10 [set t (t + 1)
pollute
consume
reset-ticks]
pollution_plot
consume_plot
energy_plot
end
to move-cars
ask green_cars ; condizione per far muovere le auto solo sulle strade
[if[pcolor] of patch-ahead 1 != grey
[ifelse random (10) < 5 ; se la patch difronte non è grigia gira casualmente a dx o sx
[lt 90]
[rt 90]]]
ask fuel_cars
[if[pcolor] of patch-ahead 1 != grey
[ifelse random (10) < 5
[lt 90]
[rt 90]]]
ask green_cars with [color = green]
[if distance destination = 0
[set destination one-of destinations] ;sceglie una nuova destinazione
ifelse distance destination < 1
[move-to destination]
[fd 1
set energy (energy - 1)]
if [xcor] of green_car who > [xcor] of destination and
[ycor] of green_car who > [ycor] of destination and
heading = 0 and
[pcolor] of patch-at -1 0 = grey
[lt 90]
if [xcor] of green_car who > [xcor] of destination and
[ycor] of green_car who <= [ycor] of destination and
heading = 0 and
[pcolor] of patch-at -1 0 = grey
[lt 90]
if [xcor] of green_car who < [xcor] of destination and
[ycor] of green_car who > [ycor] of destination and
heading = 0 and
[pcolor] of patch-at 1 0 = grey
[rt 90]
if [xcor] of green_car who < [xcor] of destination and
[ycor] of green_car who <= [ycor] of destination and
heading = 0 and
[pcolor] of patch-at 1 0 = grey
[rt 90]
if [xcor] of green_car who > [xcor] of destination and
[ycor] of green_car who > [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 -1 = grey
[rt 90]
if [xcor] of green_car who > [xcor] of destination and
[ycor] of green_car who < [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 1 = grey
[lt 90]
if [xcor] of green_car who <= [xcor] of destination and
[ycor] of green_car who > [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 -1 = grey
[rt 90]
if [xcor] of green_car who <= [xcor] of destination and
[ycor] of green_car who < [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 1 = grey
[lt 90]
if [xcor] of green_car who > [xcor] of destination and
[ycor] of green_car who >= [ycor] of destination and
heading = 180 and
[pcolor] of patch-at -1 0 = grey
[rt 90]
if [xcor] of green_car who > [xcor] of destination and
[ycor] of green_car who < [ycor] of destination and
heading = 180 and
[pcolor] of patch-at -1 0 = grey
[rt 90]
if [xcor] of green_car who < [xcor] of destination and
[ycor] of green_car who >= [ycor] of destination and
heading = 180 and
[pcolor] of patch-at 1 0 = grey
[lt 90]
if [xcor] of green_car who < [xcor] of destination and
[ycor] of green_car who < [ycor] of destination and
heading = 180 and
[pcolor] of patch-at 0 1 = grey
[lt 90]
if [xcor] of green_car who >= [xcor] of destination and
[ycor] of green_car who > [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 -1 = grey
[lt 90]
if [xcor] of green_car who > [xcor] of destination and
[ycor] of green_car who < [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 1 = grey
[rt 90]
if [xcor] of green_car who < [xcor] of destination and
[ycor] of green_car who > [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 -1 = grey
[lt 90]
if [xcor] of green_car who <= [xcor] of destination and
[ycor] of green_car who < [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 1 = grey
[rt 90]]
ask fuel_cars
[if distance destination = 0
[set destination one-of destinations]
ifelse distance destination < 1
[move-to destination]
[fd 1]
if [xcor] of fuel_car who > [xcor] of destination and
[ycor] of fuel_car who > [ycor] of destination and
heading = 0 and
[pcolor] of patch-at -1 0 = grey
[lt 90]
if [xcor] of fuel_car who > [xcor] of destination and
[ycor] of fuel_car who <= [ycor] of destination and
heading = 0 and
[pcolor] of patch-at -1 0 = grey
[lt 90]
if [xcor] of fuel_car who < [xcor] of destination and
[ycor] of fuel_car who > [ycor] of destination and
heading = 0 and
[pcolor] of patch-at 1 0 = grey
[rt 90]
if [xcor] of fuel_car who < [xcor] of destination and
[ycor] of fuel_car who <= [ycor] of destination and
heading = 0 and
[pcolor] of patch-at 1 0 = grey
[rt 90]
if [xcor] of fuel_car who > [xcor] of destination and
[ycor] of fuel_car who > [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 -1 = grey
[rt 90]
if [xcor] of fuel_car who > [xcor] of destination and
[ycor] of fuel_car who < [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 1 = grey
[lt 90]
if [xcor] of fuel_car who <= [xcor] of destination and
[ycor] of fuel_car who > [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 -1 = grey
[rt 90]
if [xcor] of fuel_car who <= [xcor] of destination and
[ycor] of fuel_car who < [ycor] of destination and
heading = 90 and
[pcolor] of patch-at 0 1 = grey
[lt 90]
if [xcor] of fuel_car who > [xcor] of destination and
[ycor] of fuel_car who >= [ycor] of destination and
heading = 180 and
[pcolor] of patch-at -1 0 = grey
[rt 90]
if [xcor] of fuel_car who > [xcor] of destination and
[ycor] of fuel_car who < [ycor] of destination and
heading = 180 and
[pcolor] of patch-at -1 0 = grey
[rt 90]
if [xcor] of fuel_car who < [xcor] of destination and
[ycor] of fuel_car who >= [ycor] of destination and
heading = 180 and
[pcolor] of patch-at 1 0 = grey
[lt 90]
if [xcor] of fuel_car who < [xcor] of destination and
[ycor] of fuel_car who < [ycor] of destination and
heading = 180 and
[pcolor] of patch-at 0 1 = grey
[lt 90]
if [xcor] of fuel_car who >= [xcor] of destination and
[ycor] of fuel_car who > [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 -1 = grey
[lt 90]
if [xcor] of fuel_car who > [xcor] of destination and
[ycor] of fuel_car who < [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 1 = grey
[rt 90]
if [xcor] of fuel_car who < [xcor] of destination and
[ycor] of fuel_car who > [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 -1 = grey
[lt 90]
if [xcor] of fuel_car who <= [xcor] of destination and
[ycor] of fuel_car who < [ycor] of destination and
heading = 270 and
[pcolor] of patch-at 0 1 = grey
[rt 90]]
ask green_cars
[if energy = 0
[ set color red]]
ask green_cars ;fissa la destinazione in uno dei punti di ricarica
[if energy = 50
[set destination one-of charging_destinations]]
ask green_cars
[if distance base 0 = 0 and energy < 50
[set energy 200]]
ask green_cars
[if distance base 1 = 0 and energy < 50
[set energy 200]]
ask green_cars
[if distance station 8 = 0 and energy < 50
[set energy 200]]
ask green_cars
[if distance station 9 = 0 and energy < 50
[set energy 200]]
ask green_cars
[if distance station 10 = 0 and energy < 50
[set energy 200]]
ask green_cars
[if distance station 11 = 0 and energy < 50
[set energy 200]]
ask green_cars
[if energy = 200
[set destination one-of destinations]]
end
to pollute
if t > 0 [ask fuel_cars [set pollution (pollution + 1.5)] ;milligrammi/ metri cubi
ask green_cars [set pollution (pollution + 0.2)]
ask green_cars
[if count fuel_cars = 0
[set pollution (pollution - 0.25)]]]
end
to consume
if t > 0 [ask fuel_cars [set consumption (consumption + 0.5)] ; consumi calcolati come kw/km
ask green_cars
[ifelse random (10) < 5
[set consumption (consumption + 0.1)]
[set consumption (consumption + 0.2)]]]
end
to imitation
ask fuel_cars
[if imitation?
[if count green_cars in-radius 1 > 2
[set color green
set breed green_cars
set energy 200]]]
ask stations
[if imitation?
[if count green_cars in-radius 8 > 5
[set shape "lightning"
set size 2.5
set color yellow - 1]]]
end
to pollution_plot
set-current-plot "pollution"
set-current-plot-pen "fuel_cars_pollution"
plot sum [pollution] of fuel_cars
set-current-plot-pen "green_cars_pollution"
plot sum [pollution] of green_cars
set-current-plot-pen "total_pollution"
plot sum [pollution] of fuel_cars + sum [pollution] of green_cars
end
to consume_plot
set-current-plot "consumption"
set-current-plot-pen "fuel_cars_cons"
plot 0.5
set-current-plot-pen "green_cars_cons"
ifelse random (10) < 5
[plot 0.1]
[plot 0.2]
end
to energy_plot
set-current-plot "energy"
set-current-plot-pen "range"
plot sum [energy] of green_cars
end