Commit 088d09de authored by k20066's avatar k20066
Browse files

finished

parent 68c5b1e6
## DefaultTacticsAmbulanceTeam ## DefaultTacticsAmbulanceTeam
DefaultTacticsAmbulanceTeam.HumanDetector : autumn_2023.module.complex.CentralizedControlATHumanDetector DefaultTacticsAmbulanceTeam.HumanDetector : autumn_2023.module.complex.CentralizedControlATHumanDetector
DefaultTacticsAmbulanceTeam.Search : sample_team.module.complex.SampleSearch DefaultTacticsAmbulanceTeam.Search : autumn_2023.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.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout DefaultTacticsAmbulanceTeam.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout
## DefaultTacticsFireBrigade ## DefaultTacticsFireBrigade
DefaultTacticsFireBrigade.HumanDetector : autumn_2023.module.complex.CentralizedControlFBHumanDetector DefaultTacticsFireBrigade.HumanDetector : autumn_2023.module.complex.CentralizedControlFBHumanDetector
DefaultTacticsFireBrigade.Search : sample_team.module.complex.SampleSearch DefaultTacticsFireBrigade.Search : autumn_2023.module.complex.SampleSearch
DefaultTacticsFireBrigade.ExtActionFireRescue : autumn_2023.extaction.ComplimentTacticsExtActionFireRescue DefaultTacticsFireBrigade.ExtActionFireRescue : autumn_2023.extaction.ComplimentTacticsExtActionFireRescue
DefaultTacticsFireBrigade.ExtActionMove : adf.impl.extaction.DefaultExtActionMove DefaultTacticsFireBrigade.ExtActionMove : adf.impl.extaction.DefaultExtActionMove
DefaultTacticsFireBrigade.CommandExecutorFire : autumn_2023.centralized.CentralizedControlCommandExecutorF DefaultTacticsFireBrigade.CommandExecutorFire : autumn_2023.centralized.CentralizedControlCommandExecutorFire
DefaultTacticsFireBrigade.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout DefaultTacticsFireBrigade.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout
## DefaultTacticsPoliceForce ## DefaultTacticsPoliceForce
...@@ -28,7 +27,7 @@ DefaultTacticsAmbulanceCentre.TargetAllocator : sample_team.module.complex.Sampl ...@@ -28,7 +27,7 @@ DefaultTacticsAmbulanceCentre.TargetAllocator : sample_team.module.complex.Sampl
DefaultTacticsAmbulanceCentre.CommandPicker : adf.impl.centralized.DefaultCommandPickerAmbulance DefaultTacticsAmbulanceCentre.CommandPicker : adf.impl.centralized.DefaultCommandPickerAmbulance
## DefaultTacticsFireStation ## DefaultTacticsFireStation
DefaultTacticsFireStation.CommandPicker : adf.impl.centralized.DefaultCommandPickerFire DefaultTacticsFireStation.CommandPicker : autumn_2023.centralized.CentralizedControlCommandPickerFire
TacticsFireStation.TargetAllocator : autumn_2023.module.complex.CentralizedControlFBAllocator TacticsFireStation.TargetAllocator : autumn_2023.module.complex.CentralizedControlFBAllocator
## DefaultTacticsPoliceOffice ## DefaultTacticsPoliceOffice
...@@ -93,8 +92,8 @@ DefaultCommandExecutorScoutPolice.PathPlanning : adf.impl.module.algorithm.Dijks ...@@ -93,8 +92,8 @@ DefaultCommandExecutorScoutPolice.PathPlanning : adf.impl.module.algorithm.Dijks
DefaultCommandExecutorScoutPolice.ExtActionClear : adf.impl.extaction.DefaultExtActionClear DefaultCommandExecutorScoutPolice.ExtActionClear : adf.impl.extaction.DefaultExtActionClear
## MessageManager ## MessageManager
MessageManager.PlatoonChannelSubscriber : adf.impl.module.comm.DefaultChannelSubscriber MessageManager.PlatoonChannelSubscriber : autumn_2023.module.comm.CentralizedControlChannelSubscriber
MessageManager.CenterChannelSubscriber : adf.impl.module.comm.DefaultChannelSubscriber MessageManager.CenterChannelSubscriber : autumn_2023.module.comm.CentralizedControlChannelSubscriber
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
......
...@@ -26,7 +26,7 @@ import rescuecore2.standard.entities.Human; ...@@ -26,7 +26,7 @@ import rescuecore2.standard.entities.Human;
import rescuecore2.standard.entities.StandardEntity; import rescuecore2.standard.entities.StandardEntity;
import rescuecore2.worldmodel.EntityID; import rescuecore2.worldmodel.EntityID;
public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandFire> { public class CentralizedControlCommandExecutorFire extends CommandExecutor<CommandFire> {
private static final int ACTION_UNKNOWN = -1; private static final int ACTION_UNKNOWN = -1;
private static final int ACTION_REST = CommandFire.ACTION_REST; private static final int ACTION_REST = CommandFire.ACTION_REST;
...@@ -45,7 +45,7 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -45,7 +45,7 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
private boolean commandCompleted; private boolean commandCompleted;
public CentralizedControlCommandExecutorF(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) { public CentralizedControlCommandExecutorFire(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData); super(ai, wi, si, moduleManager, developData);
this.commandType = ACTION_UNKNOWN; this.commandType = ACTION_UNKNOWN;
this.target = null; this.target = null;
...@@ -67,21 +67,26 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -67,21 +67,26 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
} }
} }
/**
* 受信した司令を入力するためのメソッド
* @param command 受信した司令
*/
@Override @Override
public CommandExecutor setCommand(CommandFire command) { public CommandExecutor setCommand(CommandFire command) {
EntityID agentID = this.agentInfo.getID(); EntityID agentID = this.agentInfo.getID();
if(!this.commandCompleted) return this; if(!this.commandCompleted) return this;
if (command.isToIDDefined() && Objects.requireNonNull(command.getToID()) if (command.isToIDDefined() && Objects.requireNonNull(command.getToID()).getValue() == agentID.getValue()) {
.getValue() == agentID.getValue()) { this.commandType = command.getAction();// 司令で出された行動内容
this.commandType = command.getAction(); this.target = command.getTargetID();// タスクとなる対象のID
this.target = command.getTargetID(); this.commanderID = command.getSenderID();// 司令を出した司令所のID
this.commanderID = command.getSenderID();
} }
return this; return this;
} }
/**
* 現在実行している司令が完了しているかを判定する
* 完了しているなら,消防司令所へ救助完了の報告を送る
*/
@Override @Override
public CommandExecutor updateInfo(MessageManager messageManager) { public CommandExecutor updateInfo(MessageManager messageManager) {
super.updateInfo(messageManager); super.updateInfo(messageManager);
...@@ -95,8 +100,7 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -95,8 +100,7 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
this.commandCompleted = this.isCommandCompleted(this.commandType); this.commandCompleted = this.isCommandCompleted(this.commandType);
if (this.commandCompleted) { if (this.commandCompleted) {
if (this.commandType != ACTION_UNKNOWN) { if (this.commandType != ACTION_UNKNOWN) {
messageManager messageManager.addMessage(new MessageReport(true, true, false, this.target));
.addMessage(new MessageReport(true, true, false, this.target));
this.commandType = ACTION_UNKNOWN; this.commandType = ACTION_UNKNOWN;
this.target = null; this.target = null;
...@@ -145,7 +149,12 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -145,7 +149,12 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
return this; return this;
} }
/**
* 受け取った司令を元に行動を決定・実行するためのメソッド
*
* 司令で出された行動内容によって救助活動を決定する
* ※実装では司令で出される行動内容はACTION_AUTONOMYになっている
*/
@Override @Override
public CommandExecutor calc() { public CommandExecutor calc() {
this.result = null; this.result = null;
...@@ -153,8 +162,7 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -153,8 +162,7 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
case ACTION_REST: case ACTION_REST:
EntityID position = this.agentInfo.getPosition(); EntityID position = this.agentInfo.getPosition();
if (this.target == null) { if (this.target == null) {
Collection< Collection<EntityID> refuges = this.worldInfo.getEntityIDsOfType(REFUGE);
EntityID> refuges = this.worldInfo.getEntityIDsOfType(REFUGE);
if (refuges.contains(position)) { if (refuges.contains(position)) {
this.result = new ActionRest(); this.result = new ActionRest();
} else { } else {
...@@ -181,14 +189,12 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -181,14 +189,12 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
return this; return this;
case ACTION_MOVE: case ACTION_MOVE:
if (this.target != null) { if (this.target != null) {
this.result = this.actionExtMove.setTarget(this.target).calc() this.result = this.actionExtMove.setTarget(this.target).calc().getAction();
.getAction();
} }
return this; return this;
case ACTION_RESCUE: case ACTION_RESCUE:
if (this.target != null) { if (this.target != null) {
this.result = this.actionFireRescue.setTarget(this.target).calc() this.result = this.actionFireRescue.setTarget(this.target).calc().getAction();
.getAction();
} }
return this; return this;
case ACTION_AUTONOMY: case ACTION_AUTONOMY:
...@@ -197,16 +203,20 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -197,16 +203,20 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
} }
StandardEntity targetEntity = this.worldInfo.getEntity(this.target); StandardEntity targetEntity = this.worldInfo.getEntity(this.target);
if (targetEntity instanceof Area) { if (targetEntity instanceof Area) {
this.result = this.actionExtMove.setTarget(this.target).calc() this.result = this.actionExtMove.setTarget(this.target).calc().getAction();
.getAction();
} else if (targetEntity instanceof Human) { } else if (targetEntity instanceof Human) {
this.result = this.actionFireRescue.setTarget(this.target).calc() this.result = this.actionFireRescue.setTarget(this.target).calc().getAction();
.getAction();
} }
} }
return this; return this;
} }
/**
* 司令が完了したかを判定するメソッド
*
* @param commandType 司令の種類
* @return true : 完了 false : 実行中
*/
private boolean isCommandCompleted(int commandType) { private boolean isCommandCompleted(int commandType) {
Human agent = (Human) this.agentInfo.me(); Human agent = (Human) this.agentInfo.me();
switch (commandType) { switch (commandType) {
...@@ -228,10 +238,10 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF ...@@ -228,10 +238,10 @@ public class CentralizedControlCommandExecutorF extends CommandExecutor<CommandF
if (this.target == null) { if (this.target == null) {
return true; return true;
} }
Human human = (Human) Objects Human human = (Human) Objects.requireNonNull(this.worldInfo.getEntity(this.target));
.requireNonNull(this.worldInfo.getEntity(this.target));
return human.isBuriednessDefined() && human.getBuriedness() == 0 return human.isBuriednessDefined() && human.getBuriedness() == 0
|| (human.isHPDefined() && human.getHP() == 0); || (human.isHPDefined() && human.getHP() == 0);
case ACTION_AUTONOMY: case ACTION_AUTONOMY:
if (this.target != null) { if (this.target != null) {
StandardEntity targetEntity = this.worldInfo.getEntity(this.target); StandardEntity targetEntity = this.worldInfo.getEntity(this.target);
......
package autumn_2023.centralized;
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 CentralizedControlCommandPickerFire extends CommandPicker {
private int scoutDistance;
private Collection<CommunicationMessage> messages;
private Map<EntityID, EntityID> allocationData;
public CentralizedControlCommandPickerFire(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);
}
/**
* TargetAllocatorの計算結果を入力するためのメソッド
*
* @param allocationData TargetAllocatorのgetResultメソッドの戻り値
*/
@Override
public CommandPicker
setAllocatorResult(Map<EntityID, EntityID> allocationData) {
this.allocationData = allocationData;
return this;
}
/**
* 司令を生成・リスト化するためのメソッド
* 司令はTargetAllocatorから受け取った司令内容をもとに生成される
*/
@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);
}
}
}
}
return this;
}
/**
* calcメソッドで生成した司令リストを取得するためのメソッド
* @return 司令リスト
*/
@Override
public Collection<CommunicationMessage> getResult() {
return this.messages;
}
}
\ No newline at end of file
...@@ -24,6 +24,7 @@ import rescuecore2.standard.entities.Human; ...@@ -24,6 +24,7 @@ import rescuecore2.standard.entities.Human;
import rescuecore2.standard.entities.StandardEntity; import rescuecore2.standard.entities.StandardEntity;
import rescuecore2.worldmodel.EntityID; import rescuecore2.worldmodel.EntityID;
// ADFのDefaultTacticsFireBrigadeの修正用プログラム 無視してよい
public class ComplimentTacticsExtActionFireRescue extends ExtAction { public class ComplimentTacticsExtActionFireRescue extends ExtAction {
private MessageManager mm; private MessageManager mm;
......
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 CentralizedControlChannelSubscriber 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
...@@ -52,7 +52,11 @@ public class CentralizedControlATHumanDetector extends HumanDetector { ...@@ -52,7 +52,11 @@ public class CentralizedControlATHumanDetector extends HumanDetector {
registerModule(this.clustering); registerModule(this.clustering);
} }
/**
* 新しく受信したメッセージから情報を取得するためのメソッド
*
* 現在のステップで知覚した埋没市民を送信する
*/
@Override @Override
public HumanDetector updateInfo(MessageManager messageManager) { public HumanDetector updateInfo(MessageManager messageManager) {
logger.debug("Time:" + agentInfo.getTime()); logger.debug("Time:" + agentInfo.getTime());
...@@ -76,7 +80,9 @@ public class CentralizedControlATHumanDetector extends HumanDetector { ...@@ -76,7 +80,9 @@ public class CentralizedControlATHumanDetector extends HumanDetector {
return this; return this;
} }
/**
* 搬送対象のIDを求めるメソッド
*/
@Override @Override
public HumanDetector calc() { public HumanDetector calc() {
Human transportHuman = this.agentInfo.someoneOnBoard(); Human transportHuman = this.agentInfo.someoneOnBoard();
...@@ -118,7 +124,9 @@ public class CentralizedControlATHumanDetector extends HumanDetector { ...@@ -118,7 +124,9 @@ public class CentralizedControlATHumanDetector extends HumanDetector {
return null; return null;
} }
/**
* 救助対象IDを返すメソッド
*/
@Override @Override
public EntityID getTarget() { public EntityID getTarget() {
return this.result; return this.result;
......
...@@ -80,12 +80,22 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { ...@@ -80,12 +80,22 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator {
return this; return this;
} }
/**
* calcメソッドで算出した司令内容を返すためのメソッド
*/
@Override @Override
public Map<EntityID, EntityID> getResult() { public Map<EntityID, EntityID> getResult() {
return this.convert(this.fireBrigadeInfoMap); return this.convert(this.fireBrigadeInfoMap);
} }
/**
* 消防隊情報を
* key:命令対象のエージェントのID
* value:やるべきタスク(市民)のID
* のMapに変換するメソッド
* @param map 消防隊IDと消防隊情報に関連するMap
* @return 司令情報となるMap
*/
private Map<EntityID, EntityID> convert(Map<EntityID, FireBrigadeInfo> map) { private Map<EntityID, EntityID> convert(Map<EntityID, FireBrigadeInfo> map) {
Map<EntityID, EntityID> result = new HashMap<>(); Map<EntityID, EntityID> result = new HashMap<>();
for (EntityID id : map.keySet()) { for (EntityID id : map.keySet()) {
...@@ -97,6 +107,11 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { ...@@ -97,6 +107,11 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator {
return result; return result;
} }
/**
* 分散エージェントへの司令内容を算出するためのメソッド
*
* ハンガリアンアルゴリズムを利用して消防隊に担当させるタスクを決定する
*/
@Override @Override
public FireTargetAllocator calc() { public FireTargetAllocator calc() {
if(this.agentInfo.getTime() < scenarioInfo.getKernelAgentsIgnoreuntil()) return this; if(this.agentInfo.getTime() < scenarioInfo.getKernelAgentsIgnoreuntil()) return this;
...@@ -154,7 +169,13 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { ...@@ -154,7 +169,13 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator {
return this; return this;
} }
/**
* 新しく受信したメッセージから情報を取得するためのメソッド
*
* 埋没市民Setを更新
* 消防隊情報Setを更新
* 消防隊から司令完了を受けたときタスク完了リストを更新
*/
@Override @Override
public FireTargetAllocator updateInfo(MessageManager messageManager) { public FireTargetAllocator updateInfo(MessageManager messageManager) {
super.updateInfo(messageManager); super.updateInfo(messageManager);
...@@ -194,6 +215,12 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { ...@@ -194,6 +215,12 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator {
return this; return this;
} }
/**
* ある市民について消防隊による救助が必要かを判定するメソッド
*
* @param entity エンティティ
* @return true : 救助必要 false : 救助不必要
*/
private boolean isNeedRescueHuman(StandardEntity entity){ private boolean isNeedRescueHuman(StandardEntity entity){
if (entity == null) if (entity == null)
return false; return false;
...@@ -219,6 +246,13 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { ...@@ -219,6 +246,13 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator {
return true; return true;
} }
/**
* ハンガリアンアルゴリズムの割当結果をみるためのメソッド
* @param allocate 消防隊に対応するタスク割当結果配列
* @param rowlist 消防隊IDリスト
* @param collist 埋没市民IDリスト
* @param row 消防隊の数
*/
private void printAllocate(int[] allocate, List<EntityID> rowlist, List<EntityID> collist, int row){ private void printAllocate(int[] allocate, List<EntityID> rowlist, List<EntityID> collist, int row){
String str = " allocate"; String str = " allocate";
for(int i = 0; i<row; i++){ for(int i = 0; i<row; i++){
...@@ -228,6 +262,9 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { ...@@ -228,6 +262,9 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator {
System.out.println("[FBCenter] time:"+this.agentInfo.getTime()+" id:"+this.agentInfo.getID()+str); System.out.println("[FBCenter] time:"+this.agentInfo.getTime()+" id:"+this.agentInfo.getID()+str);
} }
/**
* 消防隊情報クラス
*/
private class FireBrigadeInfo { private class FireBrigadeInfo {
EntityID agentID; EntityID agentID;
...@@ -247,6 +284,9 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { ...@@ -247,6 +284,9 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator {
canNewAction = true; canNewAction = true;
commandTime = -1; commandTime = -1;
} }
/**
* 消防隊に関する情報をセットするメソッド
*/
public void setInfo(EntityID prevtarget, EntityID position, int buriedness, boolean canNewAction, int commandTime){ public void setInfo(EntityID prevtarget, EntityID position, int buriedness, boolean canNewAction, int commandTime){
this.prevtarget = prevtarget; this.prevtarget = prevtarget;
this.position = position; this.position = position;
......
...@@ -56,6 +56,12 @@ public class CentralizedControlFBHumanDetector extends HumanDetector { ...@@ -56,6 +56,12 @@ public class CentralizedControlFBHumanDetector extends HumanDetector {
} }
/**
* 新しく受信したメッセージから情報を取得するためのメソッド
*
* 現在のステップで知覚した埋没市民の情報を送信する
* ※ここに消防隊の情報を送信する記述はないが,Tacticsの方で常に送信しているので記述しなくてもいい
*/
@Override @Override
public HumanDetector updateInfo(MessageManager messageManager) { public HumanDetector updateInfo(MessageManager messageManager) {
logger.debug("Time:" + agentInfo.getTime()); logger.debug("Time:" + agentInfo.getTime());
...@@ -80,7 +86,11 @@ public class CentralizedControlFBHumanDetector extends HumanDetector { ...@@ -80,7 +86,11 @@ public class CentralizedControlFBHumanDetector extends HumanDetector {
return this; return this;
} }
/**
* 救助対象のIDを求めるメソッド
*
* 司令所の司令で行動するため,救助対象を決定しないようにしている
*/
@Override @Override
public HumanDetector calc() { public HumanDetector calc() {
if(this.agentInfo.getTime() < scenarioInfo.getKernelAgentsIgnoreuntil()) return this; if(this.agentInfo.getTime() < scenarioInfo.getKernelAgentsIgnoreuntil()) return this;
...@@ -110,7 +120,9 @@ public class CentralizedControlFBHumanDetector extends HumanDetector { ...@@ -110,7 +120,9 @@ public class CentralizedControlFBHumanDetector extends HumanDetector {
return null; return null;
} }
/**
* 救助対象IDを返すメソッド
*/
@Override @Override
public EntityID getTarget() { public EntityID getTarget() {
return this.result; return this.result;
......
package autumn_2023.module.complex;
import adf.core.agent.communication.MessageManager;
import adf.core.agent.communication.standard.bundle.StandardMessagePriority;
import adf.core.agent.communication.standard.bundle.centralized.CommandAmbulance;
import adf.core.agent.communication.standard.bundle.information.MessageCivilian;
import adf.core.agent.info.*;
import adf.core.agent.precompute.PrecomputeData;
import adf.core.component.communication.CommunicationMessage;
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.standard.entities.*;
import rescuecore2.worldmodel.EntityID;
import java.util.*;
import java.util.stream.Collectors;
import static java.lang.Double.POSITIVE_INFINITY;
import static rescuecore2.standard.entities.StandardEntityURN.AMBULANCE_TEAM;
public class SampleSearch extends Search
{
private EntityID result;
private Clustering clustering;
private Set<EntityID> searchedSet = new HashSet<>();
private List<EntityID> list;
private MessageManager messageManager;
private static final int ACTION_LOAD = CommandAmbulance.ACTION_LOAD;
public SampleSearch(
AgentInfo ai, WorldInfo wi, ScenarioInfo si,
ModuleManager mm, DevelopData dd)
{
super(ai, wi, si, mm, dd);
String clusteringKey = "SampleSearch.Clustering.Ambulance";
this.clustering =
mm.getModule(clusteringKey,
"adf.sample.module.algorithm.SampleKMeans");
this.registerModule(this.clustering);
}
@Override
public EntityID getTarget()
{
return this.result;
}
@Override
public Search updateInfo(MessageManager mm)
{
super.updateInfo(mm);
if (this.getCountUpdateInfo() > 1) return this;
// そのステップで受信した(前ステップで送信された)メッセージ一覧
List<CommunicationMessage> messages = mm.getReceivedMessageList();
this.messageManager = mm;
// エージェントが現在位置する建物や道路のIDを取得する
EntityID position = this.agentInfo.getPosition();
// 探索済みの (辿り着いたことがある) 対象を候補から除外する
this.searchedSet.add(position);
return this;
}
@Override
public Search calc()
{
EntityID me = this.agentInfo.getID();
int idx = this.clustering.getClusterIndex(me);
if (idx == -1) {
return this;
}
//System.out.println("time:"+this.agentInfo.getTime()+" id:"+me+" target:"+this.getTarget());
Collection<EntityID> cluster =
this.clustering.getClusterEntityIDs(idx);
if (cluster == null) {
return this;
}
// Listに変換
if (this.result == null){
list = new ArrayList<>(cluster);
//System.out.println(list);
}
// エージェントが現在位置する建物や道路のIDを取得する
EntityID position = this.agentInfo.getPosition();
if (this.getTarget() != null && !position.equals(this.getTarget())) {
return this;
}
// 探索済みの (辿り着いたことがある) 対象を候補から除外する
list.removeAll(this.searchedSet);
// すべての対象が探索済みの場合,候補をリセットする
if (list.size() <= 0) {
this.searchedSet.clear();
list = new ArrayList<>(cluster);
}
double near = Double.MAX_VALUE;
for (EntityID lists : this.list) {
StandardEntity test = this.worldInfo.getEntity(lists);
if(test instanceof Building) {
double distance = this.worldInfo.getDistance(position, lists);
if (distance < near){
near = distance;
this.result = lists;
}
}
}
return this;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment