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
3a6f78e0
Commit
3a6f78e0
authored
Nov 03, 2023
by
K20014
Browse files
作業途中の保存
parent
43c47343
Changes
4
Hide whitespace changes
Inline
Side-by-side
config/module.cfg
View file @
3a6f78e0
...
...
@@ -79,7 +79,7 @@ DefaultCommandExecutorAmbulance.ExtActionMove : adf.impl.extaction.DefaultExtAct
## DefaultCommandExecutorFire
DefaultCommandExecutorFire.PathPlanning : adf.impl.module.algorithm.DijkstraPathPlanning
DefaultCommandExecutorFire.EtxActionFireRescue : adf.impl.extaction.DefaultExtActionFireRescue
DefaultCommandExecutorFire.E
t
xActionFireFighting : adf.impl.extaction.DefaultExtActionFireFighting
DefaultCommandExecutorFire.Ex
t
ActionFireFighting : adf.impl.extaction.DefaultExtActionFireFighting
DefaultCommandExecutorFire.ExtActionMove : adf.impl.extaction.DefaultExtActionMove
## DefaultCommandExecutorPolice
...
...
src/main/java/autumn_2023/centralized/AuctionCommandExecutorFire.java
View file @
3a6f78e0
package
autumn_2023.centralized
;
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.StandardMessagePriority
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandFire
;
...
...
@@ -9,7 +11,9 @@ 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
autumn_2023.module.comm.infomation.MessageCost
;
import
rescuecore2.standard.entities.*
;
...
...
@@ -23,17 +27,57 @@ import static rescuecore2.standard.entities.StandardEntityURN.REFUGE;
public
class
AuctionCommandExecutorFire
extends
CommandExecutor
<
CommandFire
>
{
private
static
final
int
ACTION_UNKNOWN
=
-
1
;
private
static
final
int
ACTION_REST
=
CommandFire
.
ACTION_REST
;
private
static
final
int
ACTION_MOVE
=
CommandFire
.
ACTION_MOVE
;
private
static
final
int
ACTION_RESCUE
=
CommandFire
.
ACTION_RESCUE
;
private
static
final
int
ACTION_AUTONOMY
=
CommandFire
.
ACTION_AUTONOMY
;
private
PathPlanning
pathPlanning
;
private
ExtAction
actionFireRescue
;
private
ExtAction
actionExtMove
;
private
int
commandType
;
private
EntityID
target
;
private
EntityID
commanderID
;
/*
救急司令所からすでに受け取った埋没市民の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
.
commandType
=
ACTION_UNKNOWN
;
switch
(
scenarioInfo
.
getMode
())
{
case
PRECOMPUTATION_PHASE:
case
PRECOMPUTED:
case
NON_PRECOMPUTE:
this
.
pathPlanning
=
moduleManager
.
getModule
(
"AuctionCommandExecutorFire.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
this
.
actionFireRescue
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorFire.ExtActionFireRescue"
,
"adf.impl.extaction.DefaultExtActionFireRescue"
);
this
.
actionExtMove
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorFire.ExtActionMove"
,
"adf.impl.extaction.DefaultExtActionMove"
);
break
;
}
}
@Override
public
CommandExecutor
<
CommandFire
>
setCommand
(
CommandFire
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
();
}
this
.
pathPlanning
=
moduleManager
.
getModule
(
"SampleHumanDetector.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
return
this
;
}
@Override
...
...
@@ -49,9 +93,12 @@ public class AuctionCommandExecutorFire extends CommandExecutor<CommandFire> {
.
collect
(
Collectors
.
toSet
());
// 新規メッセージクラスを用いてタスク実行時のコストを救急司令所に送信
receivedCentreCivilians
.
parallelStream
()
if
(
this
.
result
==
null
)
{
receivedCentreCivilians
.
parallelStream
()
.
map
(
e
->
new
MessageCost
(
true
,
StandardMessagePriority
.
HIGH
,
e
,
CalculationCost
(
e
)))
.
forEach
(
messageManager:
:
addMessage
);
}
// 知覚した救助対象の市民の情報をMessageCivilianとして指令所に送信
this
.
worldInfo
.
getChanged
().
getChangedEntities
().
parallelStream
()
...
...
@@ -68,14 +115,110 @@ public class AuctionCommandExecutorFire extends CommandExecutor<CommandFire> {
}
@Override
public
CommandExecutor
<
CommandFire
>
setCommand
(
CommandFire
command
)
{
// TODO
public
CommandExecutor
<
CommandFire
>
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
if
(
this
.
getCountPrecompute
()
>=
2
)
return
this
;
this
.
pathPlanning
.
precompute
(
precomputeData
);
this
.
actionFireRescue
.
precompute
(
precomputeData
);
this
.
actionExtMove
.
precompute
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
<
CommandFire
>
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
return
this
;
this
.
pathPlanning
.
resume
(
precomputeData
);
this
.
actionFireRescue
.
resume
(
precomputeData
);
this
.
actionExtMove
.
resume
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
<
CommandFire
>
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPreparate
()
>=
2
)
return
this
;
this
.
pathPlanning
.
preparate
();
this
.
actionFireRescue
.
preparate
();
this
.
actionExtMove
.
preparate
();
return
this
;
}
@Override
public
CommandExecutor
<
CommandFire
>
calc
()
{
// TODO
this
.
result
=
null
;
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
.
actionFireRescue
.
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
)
{
this
.
result
=
this
.
actionExtMove
.
setTarget
(
this
.
target
).
calc
().
getAction
();
}
else
if
(
targetEntity
instanceof
Human
)
{
this
.
result
=
this
.
actionFireRescue
.
setTarget
(
this
.
target
).
calc
().
getAction
();
}
}
return
this
;
}
...
...
src/main/java/autumn_2023/module/complex/AuctionFBSearch.java
View file @
3a6f78e0
package
autumn_2023.module.complex
;
public
class
AuctionFBSearch
{
import
adf.core.agent.info.*
;
import
adf.core.component.module.complex.Search
;
import
adf.core.component.module.algorithm.Clustering
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.develop.DevelopData
;
import
rescuecore2.worldmodel.EntityID
;
import
java.util.*
;
public
class
AuctionFBSearch
extends
Search
{
private
EntityID
result
;
private
Random
random
=
new
Random
(
1
);
private
Clustering
clustering
;
public
AuctionFBSearch
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
mm
,
DevelopData
dd
)
{
super
(
ai
,
wi
,
si
,
mm
,
dd
);
this
.
clustering
=
mm
.
getModule
(
"SampleSearch.Clustering.Fire"
,
"adf.sample.module.algorithm.SampleKMeans"
);
this
.
registerModule
(
this
.
clustering
);
}
@Override
public
EntityID
getTarget
()
{
return
this
.
result
;
}
@Override
public
Search
calc
()
{
EntityID
me
=
this
.
agentInfo
.
getID
();
int
idx
=
this
.
clustering
.
getClusterIndex
(
me
);
Collection
<
EntityID
>
cluster
=
this
.
clustering
.
getClusterEntityIDs
(
idx
);
// 擬似乱数を用いてランダムに選択するために,Listに変換します
List
<
EntityID
>
list
=
new
ArrayList
<>(
cluster
);
// 擬似乱数を用いてランダムに選択します
int
n
=
list
.
size
();
int
r
=
this
.
random
.
nextInt
(
n
);
this
.
result
=
list
.
get
(
r
);
return
this
;
}
}
src/main/java/autumn_2023/module/complex/AuctionFireTargetAllocator.java
View file @
3a6f78e0
...
...
@@ -33,6 +33,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
// 分散エージェントからのコストのメッセージリスト
private
List
<
MessageCost
>
rescueCosts
;
private
Map
<
EntityID
,
EntityID
>
rescueResult
;
private
Map
<
EntityID
,
RescueCivilianCost
>
calclationResult
;
public
AuctionFireTargetAllocator
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
...
...
@@ -42,6 +43,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
this
.
finishreceivedCivilians
=
new
ArrayList
<>();
this
.
rescueCosts
=
new
ArrayList
<>();
this
.
rescueResult
=
new
HashMap
<>();
this
.
calclationResult
=
new
HashMap
<>();
}
...
...
@@ -66,13 +68,41 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
@Override
public
Map
<
EntityID
,
EntityID
>
getResult
()
{
return
this
.
rescueResult
;
return
rescueResult
;
}
@Override
public
FireTargetAllocator
calc
()
{
// mapの初期化
if
(!
this
.
calclationResult
.
isEmpty
())
this
.
calclationResult
.
clear
();
if
(!
this
.
rescueResult
.
isEmpty
())
this
.
rescueResult
.
clear
();
// メッセージがなければ
if
(
this
.
rescueCosts
.
isEmpty
())
{
return
this
;
}
else
{
for
(
MessageCost
mesCos
:
this
.
rescueCosts
)
{
// コスト計算用マップが初期化状態もしくはキーがない場合
if
(
this
.
calclationResult
.
isEmpty
()
||
!
this
.
calclationResult
.
containsKey
(
mesCos
.
getTargetID
()))
{
this
.
calclationResult
.
put
(
mesCos
.
getTargetID
(),
new
RescueCivilianCost
(
mesCos
.
getSenderID
(),
mesCos
.
cost
()));
// コストが現状より小さい場合
}
else
if
(
this
.
calclationResult
.
get
(
mesCos
.
getTargetID
()).
rescueCost
>
mesCos
.
cost
())
{
this
.
calclationResult
.
replace
(
mesCos
.
getTargetID
(),
new
RescueCivilianCost
(
mesCos
.
getSenderID
(),
mesCos
.
cost
()));
}
}
// CommandPicker送信用のマップに変更
for
(
EntityID
id
:
this
.
calclationResult
.
keySet
())
{
this
.
rescueResult
.
put
(
this
.
calclationResult
.
get
(
id
).
agentID
,
id
);
}
this
.
rescueCosts
.
clear
();
}
return
this
;
}
...
...
@@ -92,16 +122,16 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
if
(
mes
instanceof
MessageCivilian
)
{
MessageCivilian
mesCiv
=
(
MessageCivilian
)
mes
;
if
(
mesCiv
.
get
SendingPriority
()
==
StandardMessagePriority
.
HIGH
)
if
(
mesCiv
.
get
HP
()
!=
0
&&
mesCiv
.
getBuriedness
()
!=
0
)
{
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
()))
if
(!
this
.
receivedAgentCivilians
.
contains
(
mesCiv
.
getAgentID
())
||
!
this
.
finishreceivedCivilians
.
contains
(
mesCiv
.
getAgentID
()))
{
receivedAgentCivilians
.
add
(
mesCiv
.
getAgentID
());
this
.
receivedAgentCivilians
.
add
(
mesCiv
.
getAgentID
());
}
}
}
...
...
@@ -111,20 +141,31 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
MessageCost
mesCos
=
(
MessageCost
)
mes
;
if
(
this
.
worldInfo
.
getEntity
(
mesCos
.
getSenderID
())
instanceof
FireBrigade
)
{
rescueCosts
.
add
(
mesCos
);
this
.
rescueCosts
.
add
(
mesCos
);
}
}
}
// 送信処理
// 埋没している市民の情報の送信
for
(
EntityID
res
:
receivedAgentCivilians
)
for
(
EntityID
res
:
this
.
receivedAgentCivilians
)
{
messageManager
.
addMessage
(
new
MessageCivilian
(
true
,
StandardMessagePriority
.
HIGH
,
(
Civilian
)
this
.
worldInfo
.
getEntity
(
res
)));
finishreceivedCivilians
.
add
(
res
);
this
.
finishreceivedCivilians
.
add
(
res
);
}
receivedAgentCivilians
.
clear
();
this
.
receivedAgentCivilians
.
clear
();
return
this
;
}
}
private
class
RescueCivilianCost
{
EntityID
agentID
;
int
rescueCost
;
RescueCivilianCost
(
EntityID
id
,
int
cost
)
{
agentID
=
id
;
rescueCost
=
cost
;
}
}
}
\ 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