From f9f134f9e1c96062b50eac976e650fa6fb950cd8 Mon Sep 17 00:00:00 2001 From: k20066 <87357429+k20066@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:41:31 +0900 Subject: [PATCH 1/2] analysis allocate --- ...CentralizedControlCommandExecutorFire.java | 1 + .../CentralizedControlFBAllocator.java | 50 +++++++++++++------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java b/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java index 2dc706a..7f37c42 100644 --- a/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java +++ b/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java @@ -74,6 +74,7 @@ public class CentralizedControlCommandExecutorFire extends CommandExecutor recievetasks = messageManager.getReceivedMessageList(MessageCivilian.class).stream() - .map(e -> { - MessageCivilian mesciv = (MessageCivilian) e; - MessageUtil.reflectMessage(this.worldInfo, mesciv); - return(mesciv); - }) - .map(MessageCivilian::getAgentID) - .filter(e -> this.isNeedRescueHuman(this.worldInfo.getEntity(e))) - .filter(e -> !(finishEntityIDs.contains(e))) - .collect(Collectors.toSet()); - + .map(e -> { + MessageCivilian mesciv = (MessageCivilian) e; + MessageUtil.reflectMessage(this.worldInfo, mesciv); + return(mesciv); + }) + .map(MessageCivilian::getAgentID) + .filter(e -> this.isNeedRescueHuman(this.worldInfo.getEntity(e))) + .filter(e -> !(finishEntityIDs.contains(e))) + .collect(Collectors.toSet()); + + System.out.println("time:"+this.agentInfo.getTime()+" centerid:"+this.agentInfo.getID()+" recievetasks:"+recievetasks); this.taskSet.addAll(recievetasks); + // 消防隊の情報をリセット + for(EntityID fbid : this.fireBrigadeInfoMap.keySet()){ + FireBrigadeInfo fbi = this.fireBrigadeInfoMap.get(fbid); + fbi.resetInfo(); + } + List fblist = new ArrayList<>(); List mesfblist = messageManager.getReceivedMessageList(MessageFireBrigade.class); for(CommunicationMessage mes : mesfblist){ MessageFireBrigade mesfb = (MessageFireBrigade) mes; MessageUtil.reflectMessage(this.worldInfo, mesfb); EntityID fbID = mesfb.getAgentID(); + fblist.add(fbID); FireBrigadeInfo fbi = this.fireBrigadeInfoMap.get(fbID); fbi.setInfo(mesfb.getTargetID(), mesfb.getPosition(), mesfb.getBuriedness(), (mesfb.getAction() == MessageFireBrigade.ACTION_RESCUE) ? false : true, this.agentInfo.getTime()); } + System.out.println("time:"+this.agentInfo.getTime()+" centerid:"+this.agentInfo.getID()+" fblist:"+fblist); List reportlist = messageManager.getReceivedMessageList(MessageReport.class).stream() - .map(MessageReport.class::cast) - .filter(MessageReport::isDone) - .map(MessageReport::getFromID) - .collect(Collectors.toList()); + .map(MessageReport.class::cast) + .filter(MessageReport::isDone) + .map(MessageReport::getFromID) + .collect(Collectors.toList()); this.finishEntityIDs.addAll(reportlist); this.taskSet.removeAll(reportlist); @@ -294,5 +303,16 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { this.canNewAction = canNewAction; this.commandTime = commandTime; } + /** + * 消防隊に関する情報をリセットするメソッド + */ + public void resetInfo(){ + prevtarget = null; + position = null; + buriedness = -1; + target = null; + canNewAction = true; + commandTime = -1; + } } } \ No newline at end of file -- GitLab From af8744d9e5c5bea08f5e0b82e46fcb0c18ea5c0f Mon Sep 17 00:00:00 2001 From: k20066 <87357429+k20066@users.noreply.github.com> Date: Tue, 7 Nov 2023 21:43:33 +0900 Subject: [PATCH 2/2] search modify --- ...CentralizedControlCommandExecutorFire.java | 1 - .../CentralizedControlFBAllocator.java | 4 +- .../module/complex/SampleSearch.java | 79 +++++++++++-------- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java b/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java index 7f37c42..2dc706a 100644 --- a/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java +++ b/src/main/java/autumn_2023/centralized/CentralizedControlCommandExecutorFire.java @@ -74,7 +74,6 @@ public class CentralizedControlCommandExecutorFire extends CommandExecutor !(finishEntityIDs.contains(e))) .collect(Collectors.toSet()); - System.out.println("time:"+this.agentInfo.getTime()+" centerid:"+this.agentInfo.getID()+" recievetasks:"+recievetasks); this.taskSet.addAll(recievetasks); // 消防隊の情報をリセット @@ -210,7 +209,6 @@ public class CentralizedControlFBAllocator extends FireTargetAllocator { fbi.setInfo(mesfb.getTargetID(), mesfb.getPosition(), mesfb.getBuriedness(), (mesfb.getAction() == MessageFireBrigade.ACTION_RESCUE) ? false : true, this.agentInfo.getTime()); } - System.out.println("time:"+this.agentInfo.getTime()+" centerid:"+this.agentInfo.getID()+" fblist:"+fblist); List reportlist = messageManager.getReceivedMessageList(MessageReport.class).stream() .map(MessageReport.class::cast) diff --git a/src/main/java/autumn_2023/module/complex/SampleSearch.java b/src/main/java/autumn_2023/module/complex/SampleSearch.java index 4762efa..2134a6c 100644 --- a/src/main/java/autumn_2023/module/complex/SampleSearch.java +++ b/src/main/java/autumn_2023/module/complex/SampleSearch.java @@ -14,6 +14,7 @@ import adf.core.agent.develop.DevelopData; import rescuecore2.standard.entities.*; import rescuecore2.worldmodel.EntityID; import java.util.*; +import java.util.stream.Collector; import java.util.stream.Collectors; import static java.lang.Double.POSITIVE_INFINITY; @@ -57,11 +58,39 @@ public class SampleSearch extends Search List messages = mm.getReceivedMessageList(); this.messageManager = mm; + int idx = this.clustering.getClusterIndex(this.agentInfo.me()); + Collection cluster = this.clustering.getClusterEntityIDs(idx); + if (cluster == null) return this; + + // エージェントが動けるステップではないなら + if(this.agentInfo.getTime() < this.scenarioInfo.getKernelAgentsIgnoreuntil()) return this; + // エージェントが動けるステップのはじめに + if(this.agentInfo.getTime() == this.scenarioInfo.getKernelAgentsIgnoreuntil()){ + this.list = new ArrayList<>(cluster); + } + + // エージェントが現在位置する建物や道路のIDを取得する EntityID position = this.agentInfo.getPosition(); // 探索済みの (辿り着いたことがある) 対象を候補から除外する this.searchedSet.add(position); + // 探索済みの (辿り着いたことがある) 対象を候補から除外する + list.removeAll(this.searchedSet); + + // クラスタ内の建物や道路のIDリストから建物のIDリストを取得 + List buildinglist = this.list.stream()// listのストリームを取得 + .map(this.worldInfo::getEntity)// EntityIDをStandardEntityに変換 + .filter(e -> (e instanceof Building))// StandardEntityオブジェクトのうちBuildingクラスのものだけ抽出 + .map(StandardEntity::getID)// StandardEntityをEntityIDに変換 + .collect(Collectors.toList());// ストリームをリストにして取得 + + // すべての対象が探索済みの場合,探索済みリストをリセット候補をリセットする + if (buildinglist.isEmpty()){ + this.searchedSet.clear(); + this.list = new ArrayList<>(cluster); + } + return this; } @@ -69,24 +98,17 @@ public class SampleSearch extends Search @Override public Search calc() { + // エージェントが動けるステップではないなら + if(this.agentInfo.getTime() < this.scenarioInfo.getKernelAgentsIgnoreuntil()) return this; + 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()); + if (idx == -1) return this; - Collection cluster = - this.clustering.getClusterEntityIDs(idx); - if (cluster == null) { - return this; - } + Collection cluster = this.clustering.getClusterEntityIDs(idx); + if (cluster == null) return this; - // Listに変換 - if (this.result == null){ - list = new ArrayList<>(cluster); - //System.out.println(list); - } + //System.out.println("time:"+this.agentInfo.getTime()+" id:"+me+" target:"+this.getTarget()); // エージェントが現在位置する建物や道路のIDを取得する EntityID position = this.agentInfo.getPosition(); @@ -94,25 +116,20 @@ public class SampleSearch extends Search 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); - } + + // クラスタ内の建物や道路のIDリストから建物のIDリストを取得 + List buildinglist = list.stream()// listのストリームを取得 + .map(this.worldInfo::getEntity)// EntityIDをStandardEntityに変換 + .filter(e -> (e instanceof Building))// StandardEntityオブジェクトのうちBuildingクラスのものだけ抽出 + .map(StandardEntity::getID)// StandardEntityをEntityIDに変換 + .collect(Collectors.toList());// ストリームをリストにして取得 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; - } + for (EntityID lists : buildinglist) { + double distance = this.worldInfo.getDistance(position, lists); + if (distance < near){ + near = distance; + this.result = lists; } } -- GitLab