Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
autumn_rrs
autumn_agent_2023
Commits
a830e49c
Commit
a830e49c
authored
Nov 03, 2023
by
k20066
Browse files
remove unnecessary module
parent
8c3c2b65
Changes
5
Hide whitespace changes
Inline
Side-by-side
config/module.cfg
View file @
a830e49c
...
@@ -3,7 +3,7 @@ DefaultTacticsAmbulanceTeam.HumanDetector : autumn_2023.module.complex.Centraliz
...
@@ -3,7 +3,7 @@ DefaultTacticsAmbulanceTeam.HumanDetector : autumn_2023.module.complex.Centraliz
DefaultTacticsAmbulanceTeam.Search : sample_team.module.complex.SampleSearch
DefaultTacticsAmbulanceTeam.Search : sample_team.module.complex.SampleSearch
DefaultTacticsAmbulanceTeam.ExtActionTransport : adf.impl.extaction.DefaultExtActionTransport
DefaultTacticsAmbulanceTeam.ExtActionTransport : adf.impl.extaction.DefaultExtActionTransport
DefaultTacticsAmbulanceTeam.ExtActionMove : adf.impl.extaction.DefaultExtActionMove
DefaultTacticsAmbulanceTeam.ExtActionMove : adf.impl.extaction.DefaultExtActionMove
#
DefaultTacticsAmbulanceTeam.CommandExecutorAmbulance : adf.impl.centralized.DefaultCommandExecutorAmbulance
DefaultTacticsAmbulanceTeam.CommandExecutorAmbulance : adf.impl.centralized.DefaultCommandExecutorAmbulance
DefaultTacticsAmbulanceTeam.CommandExecutorAmbulance : autumn_2023.centralized.CentralizedControlCommandExecutorA
DefaultTacticsAmbulanceTeam.CommandExecutorAmbulance : autumn_2023.centralized.CentralizedControlCommandExecutorA
DefaultTacticsAmbulanceTeam.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout
DefaultTacticsAmbulanceTeam.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout
...
@@ -24,13 +24,10 @@ DefaultTacticsPoliceForce.CommandExecutorPolice : adf.impl.centralized.DefaultCo
...
@@ -24,13 +24,10 @@ DefaultTacticsPoliceForce.CommandExecutorPolice : adf.impl.centralized.DefaultCo
DefaultTacticsPoliceForce.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScoutPolice
DefaultTacticsPoliceForce.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScoutPolice
## DefaultTacticsAmbulanceCentre
## DefaultTacticsAmbulanceCentre
#DefaultTacticsAmbulanceCentre.TargetAllocator : sample_team.module.complex.SampleAmbulanceTargetAllocator
DefaultTacticsAmbulanceCentre.TargetAllocator : sample_team.module.complex.SampleAmbulanceTargetAllocator
#DefaultTacticsAmbulanceCentre.CommandPicker : adf.impl.centralized.DefaultCommandPickerAmbulance
DefaultTacticsAmbulanceCentre.CommandPicker : adf.impl.centralized.DefaultCommandPickerAmbulance
DefaultTacticsAmbulanceCentre.TargetAllocator : autumn_2023.module.complex.CentralizedControlATAllocator
DefaultTacticsAmbulanceCentre.CommandPicker : autumn_2023.centralized.CentralizedControlCommandPickerA
## DefaultTacticsFireStation
## DefaultTacticsFireStation
#DefaultTacticsFireStation.TargetAllocator : sample_team.module.complex.SampleFireTargetAllocator
DefaultTacticsFireStation.CommandPicker : adf.impl.centralized.DefaultCommandPickerFire
DefaultTacticsFireStation.CommandPicker : adf.impl.centralized.DefaultCommandPickerFire
TacticsFireStation.TargetAllocator : autumn_2023.module.complex.CentralizedControlFBAllocator
TacticsFireStation.TargetAllocator : autumn_2023.module.complex.CentralizedControlFBAllocator
...
@@ -96,8 +93,8 @@ DefaultCommandExecutorScoutPolice.PathPlanning : adf.impl.module.algorithm.Dijks
...
@@ -96,8 +93,8 @@ DefaultCommandExecutorScoutPolice.PathPlanning : adf.impl.module.algorithm.Dijks
DefaultCommandExecutorScoutPolice.ExtActionClear : adf.impl.extaction.DefaultExtActionClear
DefaultCommandExecutorScoutPolice.ExtActionClear : adf.impl.extaction.DefaultExtActionClear
## MessageManager
## MessageManager
MessageManager.PlatoonChannelSubscriber : a
utumn_2023
.module.comm.DefaultChannelSubscriber
MessageManager.PlatoonChannelSubscriber : a
df.impl
.module.comm.DefaultChannelSubscriber
MessageManager.CenterChannelSubscriber : a
utumn_2023
.module.comm.DefaultChannelSubscriber
MessageManager.CenterChannelSubscriber : a
df.impl
.module.comm.DefaultChannelSubscriber
MessageManager.PlatoonMessageCoordinator : autumn_2023.module.comm.CentralizedControlMessageCoordinator
MessageManager.PlatoonMessageCoordinator : autumn_2023.module.comm.CentralizedControlMessageCoordinator
MessageManager.CenterMessageCoordinator : autumn_2023.module.comm.CentralizedControlMessageCoordinator
MessageManager.CenterMessageCoordinator : autumn_2023.module.comm.CentralizedControlMessageCoordinator
...
...
src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorA.java
deleted
100644 → 0
View file @
8c3c2b65
package
autumn_2023.centralized
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
AMBULANCE_TEAM
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
CIVILIAN
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
import
adf.core.agent.action.common.ActionMove
;
import
adf.core.agent.action.common.ActionRest
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandAmbulance
;
import
adf.core.agent.communication.standard.bundle.centralized.MessageReport
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.centralized.CommandExecutor
;
import
adf.core.component.extaction.ExtAction
;
import
adf.core.component.module.algorithm.PathPlanning
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Objects
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.worldmodel.EntityID
;
public
class
CentralizedControlCommandExecutorA
extends
CommandExecutor
<
CommandAmbulance
>
{
private
static
final
int
ACTION_UNKNOWN
=
-
1
;
private
static
final
int
ACTION_REST
=
CommandAmbulance
.
ACTION_REST
;
private
static
final
int
ACTION_MOVE
=
CommandAmbulance
.
ACTION_MOVE
;
private
static
final
int
ACTION_RESCUE
=
CommandAmbulance
.
ACTION_RESCUE
;
private
static
final
int
ACTION_LOAD
=
CommandAmbulance
.
ACTION_LOAD
;
private
static
final
int
ACTION_UNLOAD
=
CommandAmbulance
.
ACTION_UNLOAD
;
private
static
final
int
ACTION_AUTONOMY
=
CommandAmbulance
.
ACTION_AUTONOMY
;
private
PathPlanning
pathPlanning
;
private
ExtAction
actionTransport
;
private
ExtAction
actionExtMove
;
private
int
commandType
;
private
EntityID
target
;
private
EntityID
commanderID
;
public
CentralizedControlCommandExecutorA
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
commandType
=
ACTION_UNKNOWN
;
switch
(
scenarioInfo
.
getMode
())
{
case
PRECOMPUTATION_PHASE:
case
PRECOMPUTED:
case
NON_PRECOMPUTE:
this
.
pathPlanning
=
moduleManager
.
getModule
(
"DefaultCommandExecutorAmbulance.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
this
.
actionTransport
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorAmbulance.ExtActionTransport"
,
"adf.impl.extaction.DefaultExtActionTransport"
);
this
.
actionExtMove
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorAmbulance.ExActionMove"
,
"adf.impl.extaction.DefaultExtActionMove"
);
break
;
}
}
@Override
public
CommandExecutor
setCommand
(
CommandAmbulance
command
)
{
EntityID
agentID
=
this
.
agentInfo
.
getID
();
if
(
command
.
isToIDDefined
()
&&
Objects
.
requireNonNull
(
command
.
getToID
())
.
getValue
()
==
agentID
.
getValue
())
{
this
.
commandType
=
command
.
getAction
();
this
.
target
=
command
.
getTargetID
();
this
.
commanderID
=
command
.
getSenderID
();
}
return
this
;
}
@Override
public
CommandExecutor
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
if
(
this
.
getCountUpdateInfo
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
updateInfo
(
messageManager
);
this
.
actionTransport
.
updateInfo
(
messageManager
);
this
.
actionExtMove
.
updateInfo
(
messageManager
);
if
(
this
.
isCommandCompleted
())
{
if
(
this
.
commandType
!=
ACTION_UNKNOWN
)
{
messageManager
.
addMessage
(
new
MessageReport
(
true
,
true
,
false
,
this
.
commanderID
));
if
(
this
.
commandType
==
ACTION_LOAD
)
{
this
.
commandType
=
ACTION_UNLOAD
;
this
.
target
=
null
;
}
else
{
this
.
commandType
=
ACTION_UNKNOWN
;
this
.
target
=
null
;
this
.
commanderID
=
null
;
}
}
}
return
this
;
}
@Override
public
CommandExecutor
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
if
(
this
.
getCountPrecompute
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
precompute
(
precomputeData
);
this
.
actionTransport
.
precompute
(
precomputeData
);
this
.
actionExtMove
.
precompute
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
resume
(
precomputeData
);
this
.
actionTransport
.
resume
(
precomputeData
);
this
.
actionExtMove
.
resume
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPreparate
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
preparate
();
this
.
actionTransport
.
preparate
();
this
.
actionExtMove
.
preparate
();
return
this
;
}
@Override
public
CommandExecutor
calc
()
{
this
.
result
=
null
;
//System.out.println("time:"+this.agentInfo.getTime()+" id:"+this.agentInfo.getID()+" excutor");
switch
(
this
.
commandType
)
{
case
ACTION_REST:
EntityID
position
=
this
.
agentInfo
.
getPosition
();
if
(
this
.
target
==
null
)
{
Collection
<
EntityID
>
refuges
=
this
.
worldInfo
.
getEntityIDsOfType
(
REFUGE
);
if
(
refuges
.
contains
(
position
))
{
this
.
result
=
new
ActionRest
();
}
else
{
this
.
pathPlanning
.
setFrom
(
position
);
this
.
pathPlanning
.
setDestination
(
refuges
);
List
<
EntityID
>
path
=
this
.
pathPlanning
.
calc
().
getResult
();
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
this
.
result
=
new
ActionMove
(
path
);
}
else
{
this
.
result
=
new
ActionRest
();
}
}
return
this
;
}
if
(
position
.
getValue
()
!=
this
.
target
.
getValue
())
{
List
<
EntityID
>
path
=
this
.
pathPlanning
.
getResult
(
position
,
this
.
target
);
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
this
.
result
=
new
ActionMove
(
path
);
return
this
;
}
}
this
.
result
=
new
ActionRest
();
return
this
;
case
ACTION_MOVE:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionExtMove
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_RESCUE:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_LOAD:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_UNLOAD:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_AUTONOMY:
if
(
this
.
target
==
null
)
{
return
this
;
}
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
instanceof
Area
)
{
if
(
this
.
agentInfo
.
someoneOnBoard
()
==
null
)
{
this
.
result
=
this
.
actionExtMove
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
else
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
else
if
(
targetEntity
instanceof
Human
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
return
this
;
}
private
boolean
isCommandCompleted
()
{
Human
agent
=
(
Human
)
this
.
agentInfo
.
me
();
switch
(
this
.
commandType
)
{
case
ACTION_REST:
if
(
this
.
target
==
null
)
{
return
(
agent
.
getDamage
()
==
0
);
}
if
(
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
))
.
getStandardURN
()
==
REFUGE
)
{
if
(
agent
.
getPosition
().
getValue
()
==
this
.
target
.
getValue
())
{
return
(
agent
.
getDamage
()
==
0
);
}
}
return
false
;
case
ACTION_MOVE:
return
this
.
target
==
null
||
this
.
agentInfo
.
getPosition
()
.
getValue
()
==
this
.
target
.
getValue
();
case
ACTION_RESCUE:
if
(
this
.
target
==
null
)
{
return
true
;
}
Human
human
=
(
Human
)
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
));
return
human
.
isBuriednessDefined
()
&&
human
.
getBuriedness
()
==
0
||
(
human
.
isHPDefined
()
&&
human
.
getHP
()
==
0
);
case
ACTION_LOAD:
if
(
this
.
target
==
null
)
{
return
true
;
}
Human
human1
=
(
Human
)
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
));
if
((
human1
.
isHPDefined
()
&&
human1
.
getHP
()
==
0
))
{
return
true
;
}
if
(
human1
.
getStandardURN
()
!=
CIVILIAN
)
{
this
.
commandType
=
ACTION_RESCUE
;
return
this
.
isCommandCompleted
();
}
if
(
human1
.
isPositionDefined
())
{
EntityID
position
=
human1
.
getPosition
();
if
(
this
.
worldInfo
.
getEntityIDsOfType
(
AMBULANCE_TEAM
)
.
contains
(
position
))
{
return
true
;
}
else
if
(
this
.
worldInfo
.
getEntity
(
position
)
.
getStandardURN
()
==
REFUGE
)
{
return
true
;
}
}
return
false
;
case
ACTION_UNLOAD:
if
(
this
.
target
!=
null
)
{
StandardEntity
entity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
entity
!=
null
&&
entity
instanceof
Area
)
{
if
(
this
.
target
.
getValue
()
!=
this
.
agentInfo
.
getPosition
()
.
getValue
())
{
return
false
;
}
}
}
return
(
this
.
agentInfo
.
someoneOnBoard
()
==
null
);
case
ACTION_AUTONOMY:
if
(
this
.
target
!=
null
)
{
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
instanceof
Area
)
{
this
.
commandType
=
this
.
agentInfo
.
someoneOnBoard
()
==
null
?
ACTION_MOVE
:
ACTION_UNLOAD
;
return
this
.
isCommandCompleted
();
}
else
if
(
targetEntity
instanceof
Human
)
{
Human
h
=
(
Human
)
targetEntity
;
if
((
h
.
isHPDefined
()
&&
h
.
getHP
()
==
0
))
{
return
true
;
}
this
.
commandType
=
h
.
getStandardURN
()
==
CIVILIAN
?
ACTION_LOAD
:
ACTION_RESCUE
;
return
this
.
isCommandCompleted
();
}
}
return
true
;
}
return
true
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/CentralizedControlCommandPickerA.java
deleted
100644 → 0
View file @
8c3c2b65
package
autumn_2023.centralized
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandAmbulance
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandScout
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.component.centralized.CommandPicker
;
import
adf.core.component.communication.CommunicationMessage
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Map
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.standard.entities.StandardEntityURN
;
import
rescuecore2.worldmodel.EntityID
;
public
class
CentralizedControlCommandPickerA
extends
CommandPicker
{
private
int
scoutDistance
;
private
Collection
<
CommunicationMessage
>
messages
;
private
Map
<
EntityID
,
EntityID
>
allocationData
;
public
CentralizedControlCommandPickerA
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
messages
=
new
ArrayList
<>();
this
.
allocationData
=
null
;
this
.
scoutDistance
=
developData
.
getInteger
(
"adf.impl.centralized.DefaultCommandPickerAmbulance.scoutDistance"
,
40000
);
}
@Override
public
CommandPicker
setAllocatorResult
(
Map
<
EntityID
,
EntityID
>
allocationData
)
{
this
.
allocationData
=
allocationData
;
return
this
;
}
@Override
public
CommandPicker
calc
()
{
//System.out.println("time:"+this.agentInfo.getTime()+" id:"+this.agentInfo.getID()+" picker");
this
.
messages
.
clear
();
if
(
this
.
allocationData
==
null
)
{
return
this
;
}
for
(
EntityID
agentID
:
this
.
allocationData
.
keySet
())
{
StandardEntity
agent
=
this
.
worldInfo
.
getEntity
(
agentID
);
if
(
agent
!=
null
&&
agent
.
getStandardURN
()
==
StandardEntityURN
.
AMBULANCE_TEAM
)
{
StandardEntity
target
=
this
.
worldInfo
.
getEntity
(
this
.
allocationData
.
get
(
agentID
));
if
(
target
!=
null
)
{
if
(
target
instanceof
Human
)
{
CommandAmbulance
command
=
new
CommandAmbulance
(
true
,
agentID
,
target
.
getID
(),
CommandAmbulance
.
ACTION_AUTONOMY
);
this
.
messages
.
add
(
command
);
}
else
if
(
target
instanceof
Area
)
{
CommandScout
command
=
new
CommandScout
(
true
,
agentID
,
target
.
getID
(),
this
.
scoutDistance
);
this
.
messages
.
add
(
command
);
}
}
}
}
return
this
;
}
@Override
public
Collection
<
CommunicationMessage
>
getResult
()
{
return
this
.
messages
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/module/comm/DefaultChannelSubscriber.java
deleted
100644 → 0
View file @
8c3c2b65
package
autumn_2023.module.comm
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.component.communication.ChannelSubscriber
;
import
rescuecore2.standard.entities.StandardEntityURN
;
public
class
DefaultChannelSubscriber
extends
ChannelSubscriber
{
@Override
public
void
subscribe
(
AgentInfo
agentInfo
,
WorldInfo
worldInfo
,
ScenarioInfo
scenarioInfo
,
MessageManager
messageManager
)
{
// subscribe only once at the beginning
if
(
agentInfo
.
getTime
()
==
1
)
{
int
numChannels
=
scenarioInfo
.
getCommsChannelsCount
()
-
1
;
// 0th channel
// is the
// voice
// channel
int
maxChannelCount
=
0
;
boolean
isPlatoon
=
isPlatoonAgent
(
agentInfo
,
worldInfo
);
if
(
isPlatoon
)
{
maxChannelCount
=
scenarioInfo
.
getCommsChannelsMaxPlatoon
();
}
else
{
maxChannelCount
=
scenarioInfo
.
getCommsChannelsMaxOffice
();
}
StandardEntityURN
agentType
=
getAgentType
(
agentInfo
,
worldInfo
);
int
[]
channels
=
new
int
[
maxChannelCount
];
for
(
int
i
=
0
;
i
<
maxChannelCount
;
i
++)
{
channels
[
i
]
=
getChannelNumber
(
agentType
,
i
,
numChannels
);
}
messageManager
.
subscribeToChannels
(
channels
);
}
}
protected
boolean
isPlatoonAgent
(
AgentInfo
agentInfo
,
WorldInfo
worldInfo
)
{
StandardEntityURN
agentType
=
getAgentType
(
agentInfo
,
worldInfo
);
if
(
agentType
==
StandardEntityURN
.
FIRE_BRIGADE
||
agentType
==
StandardEntityURN
.
POLICE_FORCE
||
agentType
==
StandardEntityURN
.
AMBULANCE_TEAM
)
{
return
true
;
}
return
false
;
}
protected
StandardEntityURN
getAgentType
(
AgentInfo
agentInfo
,
WorldInfo
worldInfo
)
{
StandardEntityURN
agentType
=
worldInfo
.
getEntity
(
agentInfo
.
getID
())
.
getStandardURN
();
return
agentType
;
}
public
static
int
getChannelNumber
(
StandardEntityURN
agentType
,
int
channelIndex
,
int
numChannels
)
{
int
agentIndex
=
0
;
if
(
agentType
==
StandardEntityURN
.
FIRE_BRIGADE
||
agentType
==
StandardEntityURN
.
FIRE_STATION
)
{
agentIndex
=
1
;
}
else
if
(
agentType
==
StandardEntityURN
.
POLICE_FORCE
||
agentType
==
StandardEntityURN
.
POLICE_OFFICE
)
{
agentIndex
=
2
;
}
else
if
(
agentType
==
StandardEntityURN
.
AMBULANCE_TEAM
||
agentType
==
StandardEntityURN
.
AMBULANCE_CENTRE
)
{
agentIndex
=
3
;
}
int
index
=
(
3
*
channelIndex
)
+
agentIndex
;
if
((
index
%
numChannels
)
==
0
)
{
index
=
numChannels
;
}
else
{
index
=
index
%
numChannels
;
}
return
index
;
}
public
static
void
main
(
String
[]
args
)
{
int
numChannels
=
6
;
int
maxChannels
=
2
;
for
(
int
i
=
0
;
i
<
maxChannels
;
i
++)
{
System
.
out
.
println
(
"FIREBRIGADE-"
+
i
+
":"
+
getChannelNumber
(
StandardEntityURN
.
FIRE_BRIGADE
,
i
,
numChannels
));
}
for
(
int
i
=
0
;
i
<
maxChannels
;
i
++)
{
System
.
out
.
println
(
"POLICE-"
+
i
+
":"
+
getChannelNumber
(
StandardEntityURN
.
POLICE_OFFICE
,
i
,
numChannels
));
}
for
(
int
i
=
0
;
i
<
maxChannels
;
i
++)
{
System
.
out
.
println
(
"AMB-"
+
i
+
":"
+
getChannelNumber
(
StandardEntityURN
.
AMBULANCE_CENTRE
,
i
,
numChannels
));
}
}
}
\ No newline at end of file
src/main/java/autumn_2023/module/complex/CentralizedControlATAllocator.java
deleted
100755 → 0
View file @
8c3c2b65
package
autumn_2023.module.complex
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.MessageUtil
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandAmbulance
;
import
adf.core.agent.communication.standard.bundle.centralized.MessageReport
;
import
adf.core.agent.communication.standard.bundle.information.MessageAmbulanceTeam
;
import
adf.core.agent.communication.standard.bundle.information.MessageCivilian
;
import
adf.core.agent.communication.standard.bundle.information.MessageFireBrigade
;
import
adf.core.agent.communication.standard.bundle.information.MessagePoliceForce
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.communication.CommunicationMessage
;
import
adf.core.component.module.complex.AmbulanceTargetAllocator
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
rescuecore2.standard.entities.AmbulanceTeam
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.standard.entities.StandardEntityURN
;
import
rescuecore2.worldmodel.EntityID
;
public
class
CentralizedControlATAllocator
extends
AmbulanceTargetAllocator
{
private
Collection
<
EntityID
>
priorityHumans
;
private
Collection
<
EntityID
>
targetHumans
;
private
Map
<
EntityID
,
AmbulanceTeamInfo
>
ambulanceTeamInfoMap
;
public
CentralizedControlATAllocator
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
priorityHumans
=
new
HashSet
<>();
this
.
targetHumans
=
new
HashSet
<>();
this
.
ambulanceTeamInfoMap
=
new
HashMap
<>();
}
@Override
public
AmbulanceTargetAllocator
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
{
return
this
;
}
for
(
EntityID
id
:
this
.
worldInfo
.
getEntityIDsOfType
(
StandardEntityURN
.
AMBULANCE_TEAM
))
{
this
.
ambulanceTeamInfoMap
.
put
(
id
,
new
AmbulanceTeamInfo
(
id
));
}
return
this
;
}
@Override
public
AmbulanceTargetAllocator
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPrecompute
()
>=
2
)
{
return
this
;
}
for
(
EntityID
id
:
this
.
worldInfo
.
getEntityIDsOfType
(
StandardEntityURN
.
AMBULANCE_TEAM
))
{
this
.
ambulanceTeamInfoMap
.
put
(
id
,
new
AmbulanceTeamInfo
(
id
));
}
return
this
;
}
@Override
public
Map
<
EntityID
,
EntityID
>
getResult
()
{
return
this
.
convert
(
this
.
ambulanceTeamInfoMap
);
}
@Override
public
AmbulanceTargetAllocator
calc
()
{
//System.out.println("time:"+this.agentInfo.getTime()+" id:"+this.agentInfo.getID()+" allocator");
List
<
StandardEntity
>
agents
=
this
.
getActionAgents
(
this
.
ambulanceTeamInfoMap
);
Collection
<
EntityID
>
removes
=
new
ArrayList
<>();
int
currentTime
=
this
.
agentInfo
.
getTime
();
for
(
EntityID
target
:
this
.
priorityHumans
)
{
if
(
agents
.
size
()
>
0
)
{
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
target
);
if
(
targetEntity
!=
null
&&
targetEntity
instanceof
Human
&&
((
Human
)
targetEntity
).
isPositionDefined
())
{
agents
.
sort
(
new
DistanceSorter
(
this
.
worldInfo
,
targetEntity
));
StandardEntity
result
=
agents
.
get
(
0
);
agents
.
remove
(
0
);
AmbulanceTeamInfo
info
=
this
.
ambulanceTeamInfoMap
.
get
(
result
.
getID
());
if
(
info
!=
null
)
{
info
.
canNewAction
=
false
;
info
.
target
=
target
;
info
.
commandTime
=
currentTime
;
this
.
ambulanceTeamInfoMap
.
put
(
result
.
getID
(),
info
);
removes
.
add
(
target
);
}
}
}
}
this
.
priorityHumans
.
removeAll
(
removes
);
removes
.
clear
();
for
(
EntityID
target
:
this
.
targetHumans
)
{
if
(
agents
.
size
()
>
0
)
{
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
target
);
if
(
targetEntity
!=
null
&&
targetEntity
instanceof
Human
&&
((
Human
)
targetEntity
).
isPositionDefined
())
{
agents
.
sort
(
new
DistanceSorter
(
this
.
worldInfo
,
targetEntity
));
StandardEntity
result
=
agents
.
get
(
0
);
agents
.
remove
(
0
);
AmbulanceTeamInfo
info
=
this
.
ambulanceTeamInfoMap
.
get
(
result
.
getID
());
if
(
info
!=
null
)
{
info
.
canNewAction
=
false
;
info
.
target
=
target
;
info
.
commandTime
=
currentTime
;
this
.
ambulanceTeamInfoMap
.
put
(
result
.
getID
(),
info
);
removes
.
add
(
target
);
}
}
}
}
this
.
targetHumans
.
removeAll
(
removes
);
return
this
;
}
@Override
public
AmbulanceTargetAllocator
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
if
(
this
.
getCountUpdateInfo
()
>=
2
)
{
return
this
;
}
int
currentTime
=
this
.
agentInfo
.
getTime
();
for
(
CommunicationMessage
message
:
messageManager
.
getReceivedMessageList
())
{
Class
<?
extends
CommunicationMessage
>
messageClass
=
message
.
getClass
();
if
(
messageClass
==
MessageCivilian
.
class
)
{
MessageCivilian
mc
=
(
MessageCivilian
)
message
;
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mc
);
if
(
mc
.
isBuriednessDefined
()
&&
mc
.
getBuriedness
()
>
0
)
{
this
.
targetHumans
.
add
(
mc
.
getAgentID
());
}
else
{
this
.
priorityHumans
.
remove
(
mc
.
getAgentID
());
this
.
targetHumans
.
remove
(
mc
.
getAgentID
());
}
}
else
if
(
messageClass
==
MessageFireBrigade
.
class
)
{
MessageFireBrigade
mfb
=
(
MessageFireBrigade
)
message
;
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mfb
);
if
(
mfb
.
isBuriednessDefined
()
&&
mfb
.
getBuriedness
()
>
0
)
{
this
.
priorityHumans
.
add
(
mfb
.
getAgentID
());
}
else
{
this
.
priorityHumans
.
remove
(
mfb
.
getAgentID
());
this
.
targetHumans
.
remove
(
mfb
.
getAgentID
());
}
}
else
if
(
messageClass
==
MessagePoliceForce
.
class
)
{
MessagePoliceForce
mpf
=
(
MessagePoliceForce
)
message
;
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mpf
);
if
(
mpf
.
isBuriednessDefined
()
&&
mpf
.
getBuriedness
()
>
0
)
{
this
.
priorityHumans
.
add
(
mpf
.
getAgentID
());
}
else
{
this
.
priorityHumans
.
remove
(
mpf
.
getAgentID
());
this
.
targetHumans
.
remove
(
mpf
.
getAgentID
());
}
}
}
for
(
CommunicationMessage
message
:
messageManager
.
getReceivedMessageList
(
MessageAmbulanceTeam
.
class
))
{
MessageAmbulanceTeam
mat
=
(
MessageAmbulanceTeam
)
message
;
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mat
);
if
(
mat
.
isBuriednessDefined
()
&&
mat
.
getBuriedness
()
>
0
)
{
this
.
priorityHumans
.
add
(
mat
.
getAgentID
());
}
else
{
this
.
priorityHumans
.
remove
(
mat
.
getAgentID
());
this
.
targetHumans
.
remove
(
mat
.
getAgentID
());
}
AmbulanceTeamInfo
info
=
this
.
ambulanceTeamInfoMap
.
get
(
mat
.
getAgentID
());
if
(
info
==
null
)
{
info
=
new
AmbulanceTeamInfo
(
mat
.
getAgentID
());
}
if
(
currentTime
>=
info
.
commandTime
+
2
)
{
this
.
ambulanceTeamInfoMap
.
put
(
mat
.
getAgentID
(),
this
.
update
(
info
,
mat
));
}
}
for
(
CommunicationMessage
message
:
messageManager
.
getReceivedMessageList
(
CommandAmbulance
.
class
))
{
CommandAmbulance
command
=
(
CommandAmbulance
)
message
;
if
(
command
.
getAction
()
==
CommandAmbulance
.
ACTION_RESCUE
&&
command
.
isBroadcast
())
{
this
.
priorityHumans
.
add
(
command
.
getTargetID
());
this
.
targetHumans
.
add
(
command
.
getTargetID
());
}
else
if
(
command
.
getAction
()
==
CommandAmbulance
.
ACTION_LOAD
&&
command
.
isBroadcast
())
{
this
.
priorityHumans
.
add
(
command
.
getTargetID
());
this
.
targetHumans
.
add
(
command
.
getTargetID
());
}
}
for
(
CommunicationMessage
message
:
messageManager
.
getReceivedMessageList
(
MessageReport
.
class
))
{
MessageReport
report
=
(
MessageReport
)
message
;
AmbulanceTeamInfo
info
=
this
.
ambulanceTeamInfoMap
.
get
(
report
.
getSenderID
());
if
(
info
!=
null
&&
report
.
isDone
())
{
info
.
canNewAction
=
true
;
this
.
priorityHumans
.
remove
(
info
.
target
);
this
.
targetHumans
.
remove
(
info
.
target
);
info
.
target
=
null
;
this
.
ambulanceTeamInfoMap
.
put
(
info
.
agentID
,
info
);
}
}
return
this
;
}
private
Map
<
EntityID
,
EntityID
>
convert
(
Map
<
EntityID
,
AmbulanceTeamInfo
>
map
)
{
Map
<
EntityID
,
EntityID
>
result
=
new
HashMap
<>();
for
(
EntityID
id
:
map
.
keySet
())
{
AmbulanceTeamInfo
info
=
map
.
get
(
id
);
if
(
info
!=
null
&&
info
.
target
!=
null
)
{
result
.
put
(
id
,
info
.
target
);
}
}
return
result
;
}
private
List
<
StandardEntity
>
getActionAgents
(
Map
<
EntityID
,
AmbulanceTeamInfo
>
map
)
{
List
<
StandardEntity
>
result
=
new
ArrayList
<>();
for
(
StandardEntity
entity
:
this
.
worldInfo
.
getEntitiesOfType
(
StandardEntityURN
.
POLICE_FORCE
))
{
AmbulanceTeamInfo
info
=
map
.
get
(
entity
.
getID
());
if
(
info
!=
null
&&
info
.
canNewAction
&&
((
AmbulanceTeam
)
entity
).
isPositionDefined
())
{
result
.
add
(
entity
);
}
}
return
result
;
}
private
AmbulanceTeamInfo
update
(
AmbulanceTeamInfo
info
,
MessageAmbulanceTeam
message
)
{
if
(
message
.
isBuriednessDefined
()
&&
message
.
getBuriedness
()
>
0
)
{
info
.
canNewAction
=
false
;
if
(
info
.
target
!=
null
)
{
this
.
targetHumans
.
add
(
info
.
target
);
info
.
target
=
null
;
}
return
info
;
}
if
(
message
.
getAction
()
==
MessageAmbulanceTeam
.
ACTION_REST
)
{
info
.
canNewAction
=
true
;
if
(
info
.
target
!=
null
)
{
this
.
targetHumans
.
add
(
info
.
target
);
info
.
target
=
null
;
}
}
else
if
(
message
.
getAction
()
==
MessageAmbulanceTeam
.
ACTION_MOVE
)
{
if
(
message
.
getTargetID
()
!=
null
)
{
StandardEntity
entity
=
this
.
worldInfo
.
getEntity
(
message
.
getTargetID
());
if
(
entity
!=
null
)
{
if
(
entity
instanceof
Area
)
{
if
(
entity
.
getStandardURN
()
==
REFUGE
)
{
info
.
canNewAction
=
false
;
return
info
;
}
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
info
.
target
);
if
(
targetEntity
!=
null
)
{
if
(
targetEntity
instanceof
Human
)
{
targetEntity
=
this
.
worldInfo
.
getPosition
((
Human
)
targetEntity
);
if
(
targetEntity
==
null
)
{
this
.
priorityHumans
.
remove
(
info
.
target
);
this
.
targetHumans
.
remove
(
info
.
target
);
info
.
canNewAction
=
true
;
info
.
target
=
null
;
return
info
;
}
}
if
(
targetEntity
.
getID
().
getValue
()
==
entity
.
getID
()
.
getValue
())
{
info
.
canNewAction
=
false
;
}
else
{
info
.
canNewAction
=
true
;
if
(
info
.
target
!=
null
)
{
this
.
targetHumans
.
add
(
info
.
target
);
info
.
target
=
null
;
}
}
}
else
{
info
.
canNewAction
=
true
;
info
.
target
=
null
;
}
return
info
;
}
else
if
(
entity
instanceof
Human
)
{
if
(
entity
.
getID
().
getValue
()
==
info
.
target
.
getValue
())
{
info
.
canNewAction
=
false
;
}
else
{
info
.
canNewAction
=
true
;
this
.
targetHumans
.
add
(
info
.
target
);
this
.
targetHumans
.
add
(
entity
.
getID
());
info
.
target
=
null
;
}
return
info
;
}
}
}
info
.
canNewAction
=
true
;
if
(
info
.
target
!=
null
)
{
this
.
targetHumans
.
add
(
info
.
target
);
info
.
target
=
null
;
}
}
else
if
(
message
.
getAction
()
==
MessageAmbulanceTeam
.
ACTION_RESCUE
)
{
info
.
canNewAction
=
true
;
if
(
info
.
target
!=
null
)
{
this
.
targetHumans
.
add
(
info
.
target
);
info
.
target
=
null
;
}
}
else
if
(
message
.
getAction
()
==
MessageAmbulanceTeam
.
ACTION_LOAD
)
{
info
.
canNewAction
=
false
;
}
else
if
(
message
.
getAction
()
==
MessageAmbulanceTeam
.
ACTION_UNLOAD
)
{
info
.
canNewAction
=
true
;
this
.
priorityHumans
.
remove
(
info
.
target
);
this
.
targetHumans
.
remove
(
info
.
target
);
info
.
target
=
null
;
}
return
info
;
}
private
class
AmbulanceTeamInfo
{
EntityID
agentID
;
EntityID
target
;
boolean
canNewAction
;
int
commandTime
;
AmbulanceTeamInfo
(
EntityID
id
)
{
agentID
=
id
;
target
=
null
;
canNewAction
=
true
;
commandTime
=
-
1
;
}
}
private
class
DistanceSorter
implements
Comparator
<
StandardEntity
>
{
private
StandardEntity
reference
;
private
WorldInfo
worldInfo
;
DistanceSorter
(
WorldInfo
wi
,
StandardEntity
reference
)
{
this
.
reference
=
reference
;
this
.
worldInfo
=
wi
;
}
public
int
compare
(
StandardEntity
a
,
StandardEntity
b
)
{
int
d1
=
this
.
worldInfo
.
getDistance
(
this
.
reference
,
a
);
int
d2
=
this
.
worldInfo
.
getDistance
(
this
.
reference
,
b
);
return
d1
-
d2
;
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment