Commit 3a6f78e0 authored by K20014's avatar K20014
Browse files

作業途中の保存

parent 43c47343
...@@ -79,7 +79,7 @@ DefaultCommandExecutorAmbulance.ExtActionMove : adf.impl.extaction.DefaultExtAct ...@@ -79,7 +79,7 @@ DefaultCommandExecutorAmbulance.ExtActionMove : adf.impl.extaction.DefaultExtAct
## DefaultCommandExecutorFire ## DefaultCommandExecutorFire
DefaultCommandExecutorFire.PathPlanning : adf.impl.module.algorithm.DijkstraPathPlanning DefaultCommandExecutorFire.PathPlanning : adf.impl.module.algorithm.DijkstraPathPlanning
DefaultCommandExecutorFire.EtxActionFireRescue : adf.impl.extaction.DefaultExtActionFireRescue DefaultCommandExecutorFire.EtxActionFireRescue : adf.impl.extaction.DefaultExtActionFireRescue
DefaultCommandExecutorFire.EtxActionFireFighting : adf.impl.extaction.DefaultExtActionFireFighting DefaultCommandExecutorFire.ExtActionFireFighting : adf.impl.extaction.DefaultExtActionFireFighting
DefaultCommandExecutorFire.ExtActionMove : adf.impl.extaction.DefaultExtActionMove DefaultCommandExecutorFire.ExtActionMove : adf.impl.extaction.DefaultExtActionMove
## DefaultCommandExecutorPolice ## DefaultCommandExecutorPolice
......
package autumn_2023.centralized; 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.MessageManager;
import adf.core.agent.communication.standard.bundle.StandardMessagePriority; import adf.core.agent.communication.standard.bundle.StandardMessagePriority;
import adf.core.agent.communication.standard.bundle.centralized.CommandFire; import adf.core.agent.communication.standard.bundle.centralized.CommandFire;
...@@ -9,7 +11,9 @@ import adf.core.agent.info.AgentInfo; ...@@ -9,7 +11,9 @@ import adf.core.agent.info.AgentInfo;
import adf.core.agent.info.ScenarioInfo; import adf.core.agent.info.ScenarioInfo;
import adf.core.agent.info.WorldInfo; import adf.core.agent.info.WorldInfo;
import adf.core.agent.module.ModuleManager; import adf.core.agent.module.ModuleManager;
import adf.core.agent.precompute.PrecomputeData;
import adf.core.component.centralized.CommandExecutor; import adf.core.component.centralized.CommandExecutor;
import adf.core.component.extaction.ExtAction;
import adf.core.component.module.algorithm.PathPlanning; import adf.core.component.module.algorithm.PathPlanning;
import autumn_2023.module.comm.infomation.MessageCost; import autumn_2023.module.comm.infomation.MessageCost;
import rescuecore2.standard.entities.*; import rescuecore2.standard.entities.*;
...@@ -23,17 +27,57 @@ import static rescuecore2.standard.entities.StandardEntityURN.REFUGE; ...@@ -23,17 +27,57 @@ import static rescuecore2.standard.entities.StandardEntityURN.REFUGE;
public class AuctionCommandExecutorFire extends CommandExecutor<CommandFire> { 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の集合 救急司令所からすでに受け取った埋没市民のIDの集合
*/ */
private final Set<EntityID> bidCentreCivilians = new HashSet<>(); private final Set<EntityID> bidCentreCivilians = new HashSet<>();
private final PathPlanning pathPlanning;
public AuctionCommandExecutorFire(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) { public AuctionCommandExecutorFire(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.pathPlanning = moduleManager.getModule("SampleHumanDetector.PathPlanning", switch (scenarioInfo.getMode()) {
case PRECOMPUTATION_PHASE:
case PRECOMPUTED:
case NON_PRECOMPUTE:
this.pathPlanning = moduleManager.getModule(
"AuctionCommandExecutorFire.PathPlanning",
"adf.impl.module.algorithm.DijkstraPathPlanning"); "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();
}
return this;
} }
@Override @Override
...@@ -49,9 +93,12 @@ public class AuctionCommandExecutorFire extends CommandExecutor<CommandFire> { ...@@ -49,9 +93,12 @@ public class AuctionCommandExecutorFire extends CommandExecutor<CommandFire> {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// 新規メッセージクラスを用いてタスク実行時のコストを救急司令所に送信 // 新規メッセージクラスを用いてタスク実行時のコストを救急司令所に送信
if (this.result == null)
{
receivedCentreCivilians.parallelStream() receivedCentreCivilians.parallelStream()
.map(e -> new MessageCost(true, StandardMessagePriority.HIGH, e, CalculationCost(e))) .map(e -> new MessageCost(true, StandardMessagePriority.HIGH, e, CalculationCost(e)))
.forEach(messageManager::addMessage); .forEach(messageManager::addMessage);
}
// 知覚した救助対象の市民の情報をMessageCivilianとして指令所に送信 // 知覚した救助対象の市民の情報をMessageCivilianとして指令所に送信
this.worldInfo.getChanged().getChangedEntities().parallelStream() this.worldInfo.getChanged().getChangedEntities().parallelStream()
...@@ -68,14 +115,110 @@ public class AuctionCommandExecutorFire extends CommandExecutor<CommandFire> { ...@@ -68,14 +115,110 @@ public class AuctionCommandExecutorFire extends CommandExecutor<CommandFire> {
} }
@Override @Override
public CommandExecutor<CommandFire> setCommand(CommandFire command) { public CommandExecutor<CommandFire> precompute(PrecomputeData precomputeData)
// TODO {
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; return this;
} }
@Override @Override
public CommandExecutor<CommandFire> calc() { 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; return this;
} }
......
package autumn_2023.module.complex; 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;
}
} }
...@@ -33,6 +33,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{ ...@@ -33,6 +33,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
// 分散エージェントからのコストのメッセージリスト // 分散エージェントからのコストのメッセージリスト
private List<MessageCost> rescueCosts; private List<MessageCost> rescueCosts;
private Map<EntityID, EntityID> rescueResult; private Map<EntityID, EntityID> rescueResult;
private Map<EntityID, RescueCivilianCost> calclationResult;
public AuctionFireTargetAllocator(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) public AuctionFireTargetAllocator(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData)
{ {
...@@ -42,6 +43,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{ ...@@ -42,6 +43,7 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
this.finishreceivedCivilians = new ArrayList<>(); this.finishreceivedCivilians = new ArrayList<>();
this.rescueCosts = new ArrayList<>(); this.rescueCosts = new ArrayList<>();
this.rescueResult = new HashMap<>(); this.rescueResult = new HashMap<>();
this.calclationResult = new HashMap<>();
} }
...@@ -66,13 +68,41 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{ ...@@ -66,13 +68,41 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
@Override @Override
public Map<EntityID, EntityID> getResult() public Map<EntityID, EntityID> getResult()
{ {
return this.rescueResult; return rescueResult;
} }
@Override @Override
public FireTargetAllocator calc() 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; return this;
} }
...@@ -92,16 +122,16 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{ ...@@ -92,16 +122,16 @@ 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) if(mesCiv.getHP() != 0 && mesCiv.getBuriedness() != 0)
{ {
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)
{ {
if(!receivedAgentCivilians.contains(mesCiv.getAgentID()) if(!this.receivedAgentCivilians.contains(mesCiv.getAgentID())
|| !finishreceivedCivilians.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{ ...@@ -111,20 +141,31 @@ public class AuctionFireTargetAllocator extends FireTargetAllocator{
MessageCost mesCos = (MessageCost) mes; MessageCost mesCos = (MessageCost) mes;
if (this.worldInfo.getEntity(mesCos.getSenderID()) instanceof FireBrigade) 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))); 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; return this;
} }
private class RescueCivilianCost {
EntityID agentID;
int rescueCost;
RescueCivilianCost(EntityID id, int cost)
{
agentID = id;
rescueCost = cost;
}
}
} }
\ 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