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
8d0dc09a
Commit
8d0dc09a
authored
Nov 02, 2023
by
K20014
Browse files
作業途中の保存
parent
367bf39b
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/autumn_2023/centralized/AuctionCommandExecutorFire.java
View file @
8d0dc09a
package
autumn_2023.centralized
;
public
class
AuctionCommandExecutorFire
{
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.StandardMessagePriority
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandFire
;
import
adf.core.agent.communication.standard.bundle.information.MessageCivilian
;
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.CommandExecutor
;
import
adf.core.component.module.algorithm.PathPlanning
;
import
autumn_2023.module.comm.infomation.MessageCost
;
import
rescuecore2.standard.entities.*
;
import
rescuecore2.worldmodel.EntityID
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
AMBULANCE_TEAM
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
public
class
AuctionCommandExecutorFire
extends
CommandExecutor
<
CommandFire
>
{
/*
救急司令所からすでに受け取った埋没市民のIDの集合
*/
private
final
Set
<
EntityID
>
bidCentreCivilians
=
new
HashSet
<>();
private
final
PathPlanning
pathPlanning
;
public
AuctionCommandExecutorFire
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
pathPlanning
=
moduleManager
.
getModule
(
"SampleHumanDetector.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
}
@Override
public
CommandExecutor
<
CommandFire
>
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
// FireStationから受信したMessageCivilianを収集
final
Set
<
EntityID
>
receivedCentreCivilians
=
messageManager
.
getReceivedMessageList
(
MessageCivilian
.
class
).
parallelStream
()
.
map
(
MessageCivilian
.
class
::
cast
)
.
filter
(
e
->
this
.
worldInfo
.
getEntity
(
e
.
getSenderID
())
instanceof
FireStation
)
.
map
(
MessageCivilian:
:
getAgentID
)
.
filter
(
e
->
!
this
.
bidCentreCivilians
.
contains
(
e
))
.
collect
(
Collectors
.
toSet
());
// 新規メッセージクラスを用いてタスク実行時のコストを救急司令所に送信
receivedCentreCivilians
.
parallelStream
()
.
map
(
e
->
new
MessageCost
(
true
,
StandardMessagePriority
.
HIGH
,
e
,
CalculationCost
(
e
)))
.
forEach
(
messageManager:
:
addMessage
);
// 知覚した救助対象の市民の情報をMessageCivilianとして指令所に送信
this
.
worldInfo
.
getChanged
().
getChangedEntities
().
parallelStream
()
.
filter
(
this
::
isRescueTarget
)
.
map
(
this
.
worldInfo
::
getEntity
)
.
filter
(
Civilian
.
class
::
isInstance
)
.
map
(
Civilian
.
class
::
cast
)
.
map
(
e
->
new
MessageCivilian
(
true
,
StandardMessagePriority
.
HIGH
,
e
))
.
forEach
(
messageManager:
:
addMessage
);
this
.
bidCentreCivilians
.
addAll
(
receivedCentreCivilians
);
return
this
;
}
@Override
public
CommandExecutor
<
CommandFire
>
setCommand
(
CommandFire
command
)
{
// TODO
return
this
;
}
@Override
public
CommandExecutor
<
CommandFire
>
calc
()
{
// TODO
return
this
;
}
/**
* 対象が救助活動の対象であるか否かを判定するメソッド
* @param entity 対象のエンティティ
* @return entityが救助活動の対象であるか否か
*/
private
boolean
isValidHuman
(
StandardEntity
entity
)
{
if
(
entity
==
null
)
return
false
;
if
(!(
entity
instanceof
Human
target
))
return
false
;
if
(!
target
.
isHPDefined
()
||
target
.
getHP
()
==
0
)
return
false
;
if
(!
target
.
isPositionDefined
())
return
false
;
if
(!
target
.
isDamageDefined
()
||
target
.
getDamage
()
==
0
)
return
false
;
if
(!
target
.
isBuriednessDefined
())
return
false
;
StandardEntity
position
=
worldInfo
.
getPosition
(
target
);
if
(
position
==
null
)
return
false
;
StandardEntityURN
positionURN
=
position
.
getStandardURN
();
return
positionURN
!=
REFUGE
&&
positionURN
!=
AMBULANCE_TEAM
;
}
/**
* 消防隊が対象を救出をするためのコストを計算するメソッド
* @param target 埋没したエージェントのID
* @return targetへ移動するためのステップ数
*/
private
int
CalculationCost
(
EntityID
target
){
double
targetDistance
=
this
.
pathPlanning
.
getDistance
(
this
.
agentInfo
.
getID
(),
target
);
return
(
int
)(
Math
.
ceil
(
targetDistance
/
40000
));
}
/**
* 対象が消防隊による救出の対象であるか否かを判定するメソッド
* @param target 判定対象のエンティティID
* @return targetが救出対象であるか否か
*/
private
boolean
isRescueTarget
(
EntityID
target
)
{
final
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
target
);
if
(!
isValidHuman
(
targetEntity
))
return
false
;
final
Human
targetHuman
=
(
Human
)
targetEntity
;
return
targetHuman
.
getBuriedness
()
>
0
;
}
}
src/main/java/autumn_2023/centralized/AuctionCommandPickerFire.java
View file @
8d0dc09a
package
autumn_2023.centralized
;
public
class
AuctionCommandPickerFire
{
import
adf.core.agent.communication.standard.bundle.centralized.CommandFire
;
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
AuctionCommandPickerFire
extends
CommandPicker
{
private
int
scoutDistance
;
private
Collection
<
CommunicationMessage
>
messages
;
private
Map
<
EntityID
,
EntityID
>
allocationData
;
public
AuctionCommandPickerFire
(
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.DefaultCommandPickerFire.scoutDistance"
,
40000
);
}
@Override
public
CommandPicker
setAllocatorResult
(
Map
<
EntityID
,
EntityID
>
allocationData
)
{
this
.
allocationData
=
allocationData
;
return
this
;
}
@Override
public
CommandPicker
calc
()
{
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
.
FIRE_BRIGADE
)
{
StandardEntity
target
=
this
.
worldInfo
.
getEntity
(
this
.
allocationData
.
get
(
agentID
));
if
(
target
!=
null
)
{
if
(
target
instanceof
Human
)
{
CommandFire
command
=
new
CommandFire
(
true
,
agentID
,
target
.
getID
(),
CommandFire
.
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
;
}
}
src/main/java/autumn_2023/module/complex/AuctionFBHumanDetector.java
View file @
8d0dc09a
package
autumn_2023.module.complex
;
public
class
AuctionFBHumanDetector
{
}
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.module.complex.HumanDetector
;
import
rescuecore2.standard.entities.Civilian
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.worldmodel.EntityID
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
public
class
AuctionFBHumanDetector
extends
HumanDetector
{
private
EntityID
result
=
null
;
public
AuctionFBHumanDetector
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
}
@Override
public
EntityID
getTarget
()
{
return
this
.
result
;
}
@Override
public
HumanDetector
calc
()
{
final
Set
<
EntityID
>
rescueTargetInSamePosition
=
this
.
worldInfo
.
getChanged
().
getChangedEntities
().
parallelStream
()
.
map
(
this
.
worldInfo
::
getEntity
)
.
filter
(
Civilian
.
class
::
isInstance
)
.
map
(
Civilian
.
class
::
cast
)
.
filter
(
e
->
this
.
agentInfo
.
getPosition
().
equals
(
e
.
getPosition
()))
.
filter
(
Human:
:
isHPDefined
)
.
filter
(
e
->
e
.
getHP
()
>
0
)
.
filter
(
Human:
:
isBuriednessDefined
)
.
filter
(
e
->
e
.
getBuriedness
()
>
0
)
.
map
(
StandardEntity:
:
getID
)
.
collect
(
Collectors
.
toSet
());
if
(
rescueTargetInSamePosition
.
isEmpty
())
{
this
.
result
=
null
;
return
this
;
}
if
(
rescueTargetInSamePosition
.
contains
(
this
.
result
))
{
return
this
;
}
this
.
result
=
rescueTargetInSamePosition
.
stream
().
findAny
().
orElse
(
null
);
return
this
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/module/complex/AuctionFireTargetAllocator.java
View file @
8d0dc09a
...
...
@@ -2,6 +2,7 @@ package autumn_2023.module.complex;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.MessageUtil
;
import
adf.core.agent.communication.standard.bundle.StandardMessagePriority
;
import
adf.core.agent.communication.standard.bundle.information.MessageCivilian
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
...
...
@@ -18,87 +19,112 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
rescuecore2.standard.entities.AmbulanceCentre
;
import
rescuecore2.standard.entities.AmbulanceTeam
;
import
rescuecore2.standard.entities.Civilian
;
import
rescuecore2.standard.entities.FireBrigade
;
import
rescuecore2.worldmodel.EntityID
;
public
class
AuctionFireTargetAllocator
extends
FireTargetAllocator
{
// 分散エージェントからの埋没市民のメッセージリスト
private
List
<
EntityID
>
receivedAgentCivilians
=
new
ArrayList
<>()
;
private
List
<
EntityID
>
finishreceivedCivilians
=
new
ArrayList
<>()
;
private
List
<
EntityID
>
receivedAgentCivilians
;
private
List
<
EntityID
>
finishreceivedCivilians
;
// 分散エージェントからのコストのメッセージリスト
private
List
<
MessageCost
>
RescueCosts
=
new
ArrayList
<>();
private
List
<
MessageCost
>
rescueCosts
;
private
Map
<
EntityID
,
EntityID
>
rescueResult
;
public
AuctionFireTargetAllocator
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
receivedAgentCivilians
=
new
ArrayList
<>();
this
.
finishreceivedCivilians
=
new
ArrayList
<>();
this
.
rescueCosts
=
new
ArrayList
<>();
this
.
rescueResult
=
new
HashMap
<>();
}
@Override
public
FireTargetAllocator
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
public
FireTargetAllocator
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
return
this
;
}
return
this
;
}
@Override
public
FireTargetAllocator
preparate
()
{
super
.
preparate
();
@Override
public
FireTargetAllocator
preparate
()
{
super
.
preparate
();
return
this
;
}
return
this
;
}
@Override
public
Map
<
EntityID
,
EntityID
>
getResult
()
{
return
new
HashMap
<>()
;
}
@Override
public
Map
<
EntityID
,
EntityID
>
getResult
()
{
return
this
.
rescueResult
;
}
@Override
public
FireTargetAllocator
calc
()
{
return
this
;
}
@Override
public
FireTargetAllocator
calc
()
{
return
this
;
}
@Override
public
FireTargetAllocator
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
// そのステップで受信した(前ステップで送信された)メッセージ一覧
List
<
CommunicationMessage
>
messages
=
messageManager
.
getReceivedMessageList
();
for
(
CommunicationMessage
mes
:
messages
)
@Override
public
FireTargetAllocator
updateInfo
(
MessageManager
messageManager
)
{
// mesが市民の情報であれば
if
(
mes
instanceof
MessageCivilian
)
{
MessageCivilian
mesCiv
=
(
MessageCivilian
)
mes
;
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mesCiv
);
if
(
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
AmbulanceTeam
||
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
FireBrigade
)
super
.
updateInfo
(
messageManager
);
// 受信処理
// そのステップで受信した(前ステップで送信された)メッセージ一覧
List
<
CommunicationMessage
>
messages
=
messageManager
.
getReceivedMessageList
();
for
(
CommunicationMessage
mes
:
messages
)
{
// mesが市民の情報であれば
if
(
mes
instanceof
MessageCivilian
)
{
MessageCivilian
mesCiv
=
(
MessageCivilian
)
mes
;
if
(
mesCiv
.
getSendingPriority
()
==
StandardMessagePriority
.
HIGH
)
{
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mesCiv
);
if
(
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
AmbulanceTeam
||
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
FireBrigade
)
{
if
(!
receivedAgentCivilians
.
contains
(
mesCiv
.
getAgentID
())
||
!
finishreceivedCivilians
.
contains
(
mesCiv
.
getAgentID
()))
{
receivedAgentCivilians
.
add
(
mesCiv
.
getAgentID
());
}
}
}
}
// mesがコストの情報であれば
if
(
mes
instanceof
MessageCost
)
{
MessageCost
mesCos
=
(
MessageCost
)
mes
;
if
(
this
.
worldInfo
.
getEntity
(
mesCos
.
getSenderID
())
instanceof
FireBrigade
)
{
rescueCosts
.
add
(
mesCos
);
}
}
}
// 送信処理
// 埋没している市民の情報の送信
for
(
EntityID
res
:
receivedAgentCivilians
)
{
if
(!
receivedAgentCivilians
.
contains
(
mesCiv
.
getAgentID
())
||
!
finishreceivedCivilians
.
contains
(
mesCiv
.
getAgentID
()))
{
receivedAgentCivilians
.
add
(
mesCiv
.
getAgentID
());
}
messageManager
.
addMessage
(
new
MessageCivilian
(
true
,
StandardMessagePriority
.
HIGH
,
(
Civilian
)
this
.
worldInfo
.
getEntity
(
res
)));
finishreceivedCivilians
.
add
(
res
);
}
}
// mesがコストの情報であれば
if
(
mes
instanceof
MessageCost
)
{
}
receivedAgentCivilians
.
clear
();
return
this
;
}
return
this
;
}
}
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