Lectures TDDD10 AI Programming Introduction to RoboRescue

advertisement
Lectures
AIProgramming:
IntroductiontoRoboRescue
3
AgentsandAgentsArchitecture
4
Communication
5
MultiagentDecision
6
CooperationAndCoordination
7
CooperationAndCoordination
8
MachineLearning
9
Knowledge
10
PuttingItAllTogether
1
2
TDDD10AIProgramming
IntroductiontoRoboRescue
CyrilleBerger
2/55
Lecturecontent
Lecturegoals
SimulatorOverview
SimulatorsandFramework
ProgrammingAgents
Communication
VisualisationandLogging
Scenarios
LabsOverview
Competition
Acquireknowledgeaboutthe
RoboRescuerulesandhow
theRoboRescueSimulator
Acquireknowledgeonhowto
programtheRoboRescueSimulator
3/55
4/55
Simulatorarchitecture
SimulatorOverview
6
Simulators
SimulationTime
theclearsimulatorisresponsibleforblockaderemoval;
thecollapsesimulator,isresponsibleformanaging
buildings’structuraldamageandblockadecreation;
theignitionsimulatorisresponsibleforfiringuprandom
buildingsduringthesimulation;
thefiresimulatorisresponsibleforthefirespreadbetween
buildings;
thetrafficsimulatorisresponsibleforallagents’movement;
themiscsimulatorisresponsibleforhumandamageand
buriedness.
Thekernelupdatesallagents’perception(visualand
communication).
2
Theagentsupdatestheirworldmodelandmaketheir
decisions(1s)
3
Thekernelsendstheagents’commandstothesimulators.
4
Thesimulatorsprocesstheagents’commandsandsend
thechangessufferedbytheenvironmentbacktothe
kernel.
5
Thekernelsendstheenvironmentchangestotheviewers.
6
Thekernelupdatesallagents’perception...
1
7
8
SimulatorView
Buildings
Fromlefttoright:refuge,ambulancecentre,
firestation,hydrant,policeoffice,gasstation
Listofproperties:brokeness,fieryness,floors,
groundarea,ignite,temperature
9
Humans
10
Perception
Listofproperties:buriedness,
damage,HP,positionhistory
Typeof
policeforce:canclear
firemen:canextinguish
ambulance:candigouthumansandbringthem
tosafety
civilians
11
12
Scorecomputation
Canonlydecreaseovertime
LegacyScoreFunction:
sqrt(buildingareasaved)
*(civiliansalive+civilian
SimulatorsandFramework
13
Modules
Exampleofsimulator:firesimulator
Sourcecodeisin/home/TDDD10/RescueSimulator/
clear:clear
collapse:collapse
gis2:worldmodelandscenarios
human:agentthatcanbecontrolledbya
ignition:ignition
kernel
maps:worldmodeland
misc:humanhealth
misc-new:alternativeimplementationofthemisc
rescuecore2:corelibrary(withinterfacesandabstract
resq-fire:fire
sample:sourcecodeofthesample
standard:corelibrary(basicimplementationofthe
traffic3:traffic
15
16
Rescuecore2/standard
rescuecore2:corelibrary(withinterfacesandabstract
components:baseagents...
config
connection:kerneltosimulator/agents
log
messages:usedforcommunicationwithkernel
misc/registry
scenario
score:ascorecomputationlibrary
view:interfaceforaviewer
worldmodel
ProgrammingAgents
standard:corelibrary(basicimplementationofthe
components:agents...
entities:mapitemsandagents
kernel:classusedbythekernel
messages:commandssentbytheagent
misc
score:implementationoftheLegacyScore
view:implementationoftheviewer
17
WorldModel
Everyagenthasa
StandardWorldModel
getObjectsInRange:listofobjects
model
WorldModel:exampleofusegetObjectsInRange
List<EntityID>planPathToFire(EntityIDtarget)
{
//TrytogettoanythingwithinmaxDistance
//ofthetarget
Collection<StandardEntity>targets
=model.getObjectsInRange(target,maxDistance);
if(targets.isEmpty()){
returnnull;
}
returnsearch.breadthFirstSearch(
me().getPosition(),objectsToIDs(targets));
}
getObjectsInRectangle:listof
objectsinagivenrectangle
nearanotherobject
getEntitiesOfType:listallentitiesofa
giventype
getDistance
getEntity
uselistenertomonitor
changes
19
20
WorldModel:entities
Area
ThebaseelementofthemapisEntity
Area:Building,Road...
Blockade
Human:Civilian,PoliceForce...
getNeighbours(),returnalltheneighboursofanarea
A,B,C
getEdges(),returnalltheedgesofanarea
1,2,3,4,
getEdgeTo(EntityIDneighbour),returntheedgewithaspecific
neighbour
getEdgeTo(B)->
21
22
Commands
Blockade
ListofcommandsandStandardAgentfunctionused
tocreatethem:
getApexes()returnsthecoordinateof
apexes
AKClearArea/sendClear:usedtoclearablockade(policeforce)
AKExtinguish/sendExtinguish:usedtoextinguishabuilding(firemen)
AKLoad/sendLoad:usedtoloadacivilian(ambulance)
AKMove/sendMove:usedtomovetheagent(all)
AKRescue/sendRescue:digoutahuman(ambulance)
AKRest/sendRest:forthelazyagents(all)
AKUnload/sendUnload:usedtouloadacivilian(ambulance)
x_i=getApexes(2*
y_i=getApexes(2*i+
count=getApexes().length/2;
getShape()returnsajava.awt.Shape
Atmostoneofthosecommandspercycle!
nocommandsentmeanstheagentdoesnothing
23
24
AKClearArea:clearablockade
AKMove:moveanagent
voidsendClear(inttime,intdestX,intdestY)
voidsendMove(inttime,List<EntityID>
path)
time:thecurrenttime
destX:ThedestinationXcoordinatetoclear
destY:thedestinationYcoordinatetoclear
time:thecurrenttime
path:thepathtosend.
Pitfalls
Thefirstentryofthepathmustbeyourcurrentposition
Alwayssendmorethantwoelements
Youneedtosendamovecommandeveryturnuntilyou
decidethatyouhavereachedyourdestination
25
26
ChannelCommunicationModel
Multiple"radio"channels
Noisy
Communication
dropouts
corruption
Twotypesof
Voicechannel
Alwaysavailable(limitedrange
Usuallyonemessageof256bytesper
Radio
Notalways
Usuallynorange
Sharedbandwidthbetweenagent(from256to4000bytesdepending
onconfiguration)
28
CommunicationCommands
AKSpeak:speak
ListofcommandsandStandardAgent
functionusedtocreatethem:
voidsendSpeak(inttime,intchannel,
byte[]data)
AKSpeak/sendSpeak:usedtosenddataona
channel
AKSubscribe/sendSubscribe:usedtosubscribetoa
channel
time:thecurrenttime
channel:thechanneltospeakon
data:thedatatosend
eachagentcanhaveasmany
AKSpeakcommandashewants
butdonotclogupyourchannels
29
AKSubscribe:subscribe
30
Receivemessages
voidthink(inttime,ChangeSetchanged,Collection<Command>
heard)
voidsendSubscribe(inttime,int...channels)
time:thecurrenttime
channels:listofchannels
listofmessagesisinheard
Pitfalls
Sendinganewcommand,erasewhatwassetinthepast
Insomemaps,limitednumberofchannelsyoucanregister
Commandsatthebeginningofthesimulationareignored
(untilconfig.getIntValue(kernel.KernelConstants.
IGNORE_AGENT_COMMANDS_KEY))
Youdon'thavetoberegisteronachanneltospeakonit,itis
onlyforlistening
31
32
Importanceofvisualisation
Toknowwhyyouragentsare
doingsomething
Spendingacoupleofhoursonfinding
abugislosttime
Spendingacoupleofhoursona
visualisationtoolisnotlosttime
VisualisationandLogging
34
Whattovisualise?
Viewer
SampleViewer:workslikeanagent
AnimatedWorldModelVieweralayeredmap
Everything
Graphoflong
Whatyouragents
Whatdecisionthey
Displaytherankingof
...
Standardlayers:building,road,areaneighbours,road
blockade,areaicons,humans,commands,positionhistory
ImplementsyourownbysubclassingStandardViewLayer
CollectionT<RenderedObject>render(Graphics2Dg,ScreenTransform
transform,intwidth,intheight);
Remember:youcanuse
AnimatedWorldModelViewertoviewyour
agentmodel
35
36
Logging(1/2)
Logging(2/2)
OtrosLogViewer(https://code.google.com/p/
Using
Logger.info()
Logger.debug()
37
38
Logviewer
Scenarios
cd~/RescueSimulator/boot
bashlogviewer.shlogs/rescue.log
39
Structureofamap
Scenario.xml
<?xmlversion="1.0"encoding="UTF-8"?>
Two
map.gml:buildingsandroad
scenario.xml:definesnumberofagents,
initialfires,stations...
<scenario:scenarioxmlns:scenario="urn:roborescue:map:scenario">
<scenario:firestationscenario:location="19100"/>
<scenario:policeofficescenario:location="15738"/>
<scenario:ambulancecentrescenario:location="36012"/>
<scenario:refugescenario:location="20337"/>
<scenario:firescenario:location="10756"/>
<scenario:hydrantscenario:location="8628"/>
<scenario:gasstationscenario:location="12933"/>
<scenario:civilianscenario:location="17175"/>
<scenario:firebrigadescenario:location="20597"/>
<scenario:policeforcescenario:location="31006"/>
<scenario:ambulanceteamscenario:location="317"/>
</scenario:scenario>
41
42
Configuration
letshavealook
config.getIntValue("...")
LabsOverview
43
Labs
Lab1:PathPlanning
Thelabsarefewbut(mostare)
Thisiswhyyouneedtodistributethe
labsandworkontheminparallel
Usegitbranches
Attheendofthelabs,everything
shouldbemergedinmaster
Alonggraphtoreducethecomputational
complexityofA*
Reachthestartnode/endnodeusing
thebreadthfirstsearch
45
Lab2:ObstacleDetection
46
Lab3:Communication
Shareknowledgeofthe
Transmitorders
Thechallengeistocompressthe
information,tofitinthelimited
bandwidth
Detectroadblockades
47
48
Lab5:CooperativeSensingandTeamExploration
Lab4:Cooperation
Agentscommunicatewhenthey
areburiedortheirpathisblocked
AmbulanceCentredispatches
anambulancetounburryan
PoliceCentredispatchesapolice
agenttoclearthepath
Requires:lab2and
Goalistofindallthevictims
Usingthefrontiercellalgorithm
Requires:lab3
49
50
Lab6:CentralizedTaskAllocation
Thegoalistoimplementafire
stationthatdispatchesfirebrigades
toextinguishfiresusingacentralized
assignmentalgorithm
Requires:lab3
Competition
51
Competition
Scoring
Scoreisgivenas
weekly
Usingthreemaps(/home/
TDDD10/maps/competition/):
1st->10pts,2nd->7pt,3rd->5pt,4th->3,5th->2,6th
->1
Pointsaregiveneach
Attheendthewinnersgeta1ptofbonuson
theirgrade
Secondandthirdget0.5pt
Thosearebonuspoint,writtinggoodreportsis
goingtogiveyouthehighestgradepossible
Kobe:normal
Berlin:nocommunication(except
Paris:largemapwithunreliabe
53
Summary
Overviewofthesimulatorarchitecture
andAPI.
Howtoprogram
Labsand
55/55
54
Download