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
Show whitespace changes
Inline
Side-by-side
src/main/java/autumn_2023/centralized/AuctionCommandExecutorFire.java
View file @
8d0dc09a
package
autumn_2023.centralized
;
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
;
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
;
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;
...
@@ -2,6 +2,7 @@ package autumn_2023.module.complex;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.MessageUtil
;
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.communication.standard.bundle.information.MessageCivilian
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.AgentInfo
;
...
@@ -18,23 +19,29 @@ import java.util.HashMap;
...
@@ -18,23 +19,29 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
rescuecore2.standard.entities.AmbulanceCentre
;
import
rescuecore2.standard.entities.AmbulanceTeam
;
import
rescuecore2.standard.entities.AmbulanceTeam
;
import
rescuecore2.standard.entities.Civilian
;
import
rescuecore2.standard.entities.FireBrigade
;
import
rescuecore2.standard.entities.FireBrigade
;
import
rescuecore2.worldmodel.EntityID
;
import
rescuecore2.worldmodel.EntityID
;
public
class
AuctionFireTargetAllocator
extends
FireTargetAllocator
{
public
class
AuctionFireTargetAllocator
extends
FireTargetAllocator
{
// 分散エージェントからの埋没市民のメッセージリスト
// 分散エージェントからの埋没市民のメッセージリスト
private
List
<
EntityID
>
receivedAgentCivilians
=
new
ArrayList
<>()
;
private
List
<
EntityID
>
receivedAgentCivilians
;
private
List
<
EntityID
>
finishreceivedCivilians
=
new
ArrayList
<>()
;
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
)
public
AuctionFireTargetAllocator
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
receivedAgentCivilians
=
new
ArrayList
<>();
this
.
finishreceivedCivilians
=
new
ArrayList
<>();
this
.
rescueCosts
=
new
ArrayList
<>();
this
.
rescueResult
=
new
HashMap
<>();
}
}
...
@@ -59,13 +66,14 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
...
@@ -59,13 +66,14 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
@Override
@Override
public
Map
<
EntityID
,
EntityID
>
getResult
()
public
Map
<
EntityID
,
EntityID
>
getResult
()
{
{
return
new
HashMap
<>()
;
return
this
.
rescueResult
;
}
}
@Override
@Override
public
FireTargetAllocator
calc
()
public
FireTargetAllocator
calc
()
{
{
return
this
;
return
this
;
}
}
...
@@ -75,6 +83,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
...
@@ -75,6 +83,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
{
{
super
.
updateInfo
(
messageManager
);
super
.
updateInfo
(
messageManager
);
// 受信処理
// そのステップで受信した(前ステップで送信された)メッセージ一覧
// そのステップで受信した(前ステップで送信された)メッセージ一覧
List
<
CommunicationMessage
>
messages
=
messageManager
.
getReceivedMessageList
();
List
<
CommunicationMessage
>
messages
=
messageManager
.
getReceivedMessageList
();
for
(
CommunicationMessage
mes
:
messages
)
for
(
CommunicationMessage
mes
:
messages
)
...
@@ -83,6 +92,8 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
...
@@ -83,6 +92,8 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
if
(
mes
instanceof
MessageCivilian
)
if
(
mes
instanceof
MessageCivilian
)
{
{
MessageCivilian
mesCiv
=
(
MessageCivilian
)
mes
;
MessageCivilian
mesCiv
=
(
MessageCivilian
)
mes
;
if
(
mesCiv
.
getSendingPriority
()
==
StandardMessagePriority
.
HIGH
)
{
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mesCiv
);
MessageUtil
.
reflectMessage
(
this
.
worldInfo
,
mesCiv
);
if
(
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
AmbulanceTeam
if
(
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
AmbulanceTeam
||
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
FireBrigade
)
||
this
.
worldInfo
.
getEntity
(
mesCiv
.
getSenderID
())
instanceof
FireBrigade
)
...
@@ -94,11 +105,26 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
...
@@ -94,11 +105,26 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
}
}
}
}
}
}
}
// mesがコストの情報であれば
// mesがコストの情報であれば
if
(
mes
instanceof
MessageCost
)
{
if
(
mes
instanceof
MessageCost
)
{
MessageCost
mesCos
=
(
MessageCost
)
mes
;
if
(
this
.
worldInfo
.
getEntity
(
mesCos
.
getSenderID
())
instanceof
FireBrigade
)
{
rescueCosts
.
add
(
mesCos
);
}
}
}
}
}
// 送信処理
// 埋没している市民の情報の送信
for
(
EntityID
res
:
receivedAgentCivilians
)
{
messageManager
.
addMessage
(
new
MessageCivilian
(
true
,
StandardMessagePriority
.
HIGH
,
(
Civilian
)
this
.
worldInfo
.
getEntity
(
res
)));
finishreceivedCivilians
.
add
(
res
);
}
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