Commit 0d776ef2 authored by k20066's avatar k20066
Browse files

initialize

parents
extends: default
font:
catalog:
Libertinus-Serif:
normal: LibertinusSerif-Regular.ttf
italic: LibertinusSerif-Italic.ttf
bold: LibertinusSerif-Bold.ttf
bold_italic: LibertinusSerif-BoldItalic.ttf
Libertinus-Sans:
normal: LibertinusSans-Regular.ttf
italic: LibertinusSans-Italic.ttf
bold: LibertinusSans-Bold.ttf
page:
layout: portrait
margin: [2.5cm, 2.5cm, 2.5cm, 2.5cm]
size: A4
base:
text-align: left
font-family: Libertinus-Serif
font-size: 12
line-height: 1.25
title-page:
text-align: center
font-family: Libertinus-Serif
title:
font-color: #000000
font-size: 26
font-style: bold
top: 20%
authors:
font-color: #000000
font-size: 18
margin-top: 5cm
revision:
font-color: #000000
font-size: 14
margin-top: 10cm
toc-title:
text-align: center
font-family: Libertinus-Serif
font-size: 18
font-style: bold
line-height: 1.25
heading:
text-align: left
font-family: Libertinus-Sans
font-size: 14
font-style: bold
margin-top: 0.25cm
margin-bottom: 0.15cm
list:
indent: 30
item-spacing: 2
text-align: left
thematic-break:
border-color: #000000
border-style: solid
border-width: 0.15
code:
background-color: #f5f5f5
border-color: #ffffff
font-family: Courier
font-size: 11
padding: 0.1cm
caption:
text-align: center
font-size: 12
margin-inside: 0.1cm
margin-outside: 0.5cm
codespan:
font-family: Courier
font-size: 11
image:
text-align: center
header:
border-color: #ffffff
border-style: solid
border-width: 0.25
font-size: 10
height: 1.5cm
padding: [0.5cm, 0cm, 0cm, 0cm]
recto:
right:
content: ''
left:
content: ''
center:
content: ''
verso:
right:
content: ''
left:
content: ''
center:
content: ''
footer:
border-color: #000000
border-style: solid
border-width: 0.15
font-size: 10
height: 1.75cm
padding: [0.0cm, 0cm, 0cm, 0cm]
recto:
right:
content: ''
left:
content: ''
center:
content: '{page-number}'
verso:
right:
content: ''
left:
content: ''
center:
content: '{page-number}'
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
#!/bin/bash
LOADER="adf.impl.DefaultLoader"
PARAMS=$*
cd `dirname $0`
if [ ! -z "$1" ]; then
./gradlew launch --args="${LOADER} ${PARAMS}"
else
echo "Options:"
echo "-tn Team name"
echo "-t [FB],[FS],[PF],[PO],[AT],[AC] Number of agents"
echo "-fb [FB] Number of FireBrigade"
echo "-fs [FS] Number of FireStation"
echo "-pf [PF] Number of PoliceForce"
echo "-po [PO] Number of PoliceOffice"
echo "-at [AT] Number of AmbulanceTeam"
echo "-ac [AC] Number of AmbulanceCentre"
echo "-s [HOST]:[PORT] RCRS server host and port"
echo "-h [HOST] RCRS server host (port:27931)"
echo "-pre [0|1] Precompute flag"
echo "-d [0|1] Debug flag"
echo "-dev [0|1] Development mode"
echo "-mc [FILE] ModuleConfig file name"
echo "-md [JSON] ModuleConfig JSON"
echo "-df [FILE] DevelopData JSON file"
echo "-dd [JSON] DevelopData JSON"
echo "-all [alias] -t -1,-1,-1,-1,-1,-1"
echo "-allp [alias] -t 1,0,1,0,1,0,"
echo "-local [alias] -h localhost"
echo "-precompute [alias] -pre 1"
echo "-debug [alias] -d 1"
echo "-develop [alias] -dev 1"
fi
\ No newline at end of file
rootProject.name = 'adf-sample-agent-java'
\ No newline at end of file
package sample_team.module.complex;
import adf.core.agent.communication.MessageManager;
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.agent.precompute.PrecomputeData;
import adf.core.component.module.complex.AmbulanceTargetAllocator;
import java.util.HashMap;
import java.util.Map;
import rescuecore2.worldmodel.EntityID;
public class SampleAmbulanceTargetAllocator extends AmbulanceTargetAllocator {
public SampleAmbulanceTargetAllocator(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData);
}
@Override
public AmbulanceTargetAllocator resume(PrecomputeData precomputeData) {
super.resume(precomputeData);
return this;
}
@Override
public AmbulanceTargetAllocator preparate() {
super.preparate();
return this;
}
@Override
public Map<EntityID, EntityID> getResult() {
return new HashMap<>();
}
@Override
public AmbulanceTargetAllocator calc() {
return this;
}
@Override
public AmbulanceTargetAllocator updateInfo(MessageManager messageManager) {
super.updateInfo(messageManager);
return this;
}
}
\ No newline at end of file
package sample_team.module.complex;
import adf.core.agent.communication.MessageManager;
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.algorithm.Clustering;
import adf.core.component.module.complex.BuildingDetector;
import adf.core.debug.DefaultLogger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import org.apache.log4j.Logger;
import rescuecore2.standard.entities.Building;
import rescuecore2.standard.entities.StandardEntity;
import rescuecore2.standard.entities.StandardEntityURN;
import rescuecore2.worldmodel.EntityID;
public class SampleBuildingDetector extends BuildingDetector {
private EntityID result;
private Clustering clustering;
private Logger logger;
public SampleBuildingDetector(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData);
logger = DefaultLogger.getLogger(agentInfo.me());
this.clustering = moduleManager.getModule(
"SampleBuildingDetector.Clustering",
"adf.impl.module.algorithm.KMeansClustering");
registerModule(this.clustering);
}
@Override
public BuildingDetector updateInfo(MessageManager messageManager) {
logger.debug("Time:" + agentInfo.getTime());
super.updateInfo(messageManager);
return this;
}
@Override
public BuildingDetector calc() {
this.result = this.calcTarget();
return this;
}
private EntityID calcTarget() {
Collection<StandardEntity> entities = this.worldInfo.getEntitiesOfType(
StandardEntityURN.BUILDING, StandardEntityURN.GAS_STATION,
StandardEntityURN.AMBULANCE_CENTRE, StandardEntityURN.FIRE_STATION,
StandardEntityURN.POLICE_OFFICE);
List<Building> fireyBuildings = filterFiery(entities);
List<Building> clusterBuildings = filterInCluster(fireyBuildings);
List<Building> targets = clusterBuildings;
if (clusterBuildings.isEmpty())
targets = fireyBuildings;
logger.debug("FieryBuildingsTargets: " + targets);
if (targets.isEmpty())
return null;
Collections.sort(targets, new DistanceSorter(worldInfo, agentInfo.me()));
Building selectedBuilding = targets.get(0);
logger.debug("Selected:" + selectedBuilding);
return selectedBuilding.getID();
}
private List<Building>
filterFiery(Collection<? extends StandardEntity> input) {
ArrayList<Building> fireBuildings = new ArrayList<>();
for (StandardEntity entity : input) {
if (entity instanceof Building && ((Building) entity).isOnFire()) {
fireBuildings.add((Building) entity);
}
}
return fireBuildings;
}
private List<Building> filterInCluster(Collection<Building> targetAreas) {
int clusterIndex = clustering.getClusterIndex(this.agentInfo.getID());
List<Building> clusterTargets = new ArrayList<>();
HashSet<StandardEntity> inCluster = new HashSet<>(
clustering.getClusterEntities(clusterIndex));
for (Building target : targetAreas) {
if (inCluster.contains(target))
clusterTargets.add(target);
}
return clusterTargets;
}
@Override
public EntityID getTarget() {
return this.result;
}
private class DistanceSorter implements Comparator<Building> {
private StandardEntity reference;
private WorldInfo worldInfo;
DistanceSorter(WorldInfo wi, StandardEntity reference) {
this.reference = reference;
this.worldInfo = wi;
}
public int compare(Building a, Building b) {
if (a.getFieryness() == 3 && b.getFieryness() != 3) {
return 1;
}
if (a.getFieryness() != 3 && b.getFieryness() == 3) {
return -1;
}
int d1 = this.worldInfo.getDistance(this.reference, a);
int d2 = this.worldInfo.getDistance(this.reference, b);
return d1 - d2;
}
}
}
\ No newline at end of file
package sample_team.module.complex;
import adf.core.agent.communication.MessageManager;
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.agent.precompute.PrecomputeData;
import adf.core.component.module.complex.FireTargetAllocator;
import java.util.HashMap;
import java.util.Map;
import rescuecore2.worldmodel.EntityID;
public class SampleFireTargetAllocator extends FireTargetAllocator {
public SampleFireTargetAllocator(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData);
}
@Override
public FireTargetAllocator resume(PrecomputeData precomputeData) {
super.resume(precomputeData);
return this;
}
@Override
public FireTargetAllocator preparate() {
super.preparate();
return this;
}
@Override
public Map<EntityID, EntityID> getResult() {
return new HashMap<>();
}
@Override
public FireTargetAllocator calc() {
return this;
}
@Override
public FireTargetAllocator updateInfo(MessageManager messageManager) {
super.updateInfo(messageManager);
return this;
}
}
\ No newline at end of file
package sample_team.module.complex;
import static rescuecore2.standard.entities.StandardEntityURN.AMBULANCE_TEAM;
import static rescuecore2.standard.entities.StandardEntityURN.CIVILIAN;
import static rescuecore2.standard.entities.StandardEntityURN.REFUGE;
import adf.core.agent.communication.MessageManager;
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.algorithm.Clustering;
import adf.core.component.module.complex.HumanDetector;
import adf.core.debug.DefaultLogger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import org.apache.log4j.Logger;
import rescuecore2.standard.entities.Human;
import rescuecore2.standard.entities.StandardEntity;
import rescuecore2.standard.entities.StandardEntityURN;
import rescuecore2.worldmodel.EntityID;
public class SampleHumanDetector extends HumanDetector {
private Clustering clustering;
private EntityID result;
private Logger logger;
public SampleHumanDetector(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData);
logger = DefaultLogger.getLogger(agentInfo.me());
this.clustering = moduleManager.getModule("SampleHumanDetector.Clustering",
"adf.impl.module.algorithm.KMeansClustering");
registerModule(this.clustering);
}
@Override
public HumanDetector updateInfo(MessageManager messageManager) {
logger.debug("Time:" + agentInfo.getTime());
super.updateInfo(messageManager);
return this;
}
@Override
public HumanDetector calc() {
Human transportHuman = this.agentInfo.someoneOnBoard();
if (transportHuman != null) {
logger.debug("someoneOnBoard:" + transportHuman);
this.result = transportHuman.getID();
return this;
}
if (this.result != null) {
Human target = (Human) this.worldInfo.getEntity(this.result);
if (!isValidHuman(target)) {
logger.debug("Invalid Human:" + target + " ==>reset target");
this.result = null;
}
}
if (this.result == null) {
this.result = calcTarget();
}
return this;
}
private EntityID calcTarget() {
List<Human> rescueTargets = filterRescueTargets(
this.worldInfo.getEntitiesOfType(CIVILIAN));
List<Human> rescueTargetsInCluster = filterInCluster(rescueTargets);
List<Human> targets = rescueTargetsInCluster;
if (targets.isEmpty())
targets = rescueTargets;
logger.debug("Targets:" + targets);
if (!targets.isEmpty()) {
targets.sort(new DistanceSorter(this.worldInfo, this.agentInfo.me()));
Human selected = targets.get(0);
logger.debug("Selected:" + selected);
return selected.getID();
}
return null;
}
@Override
public EntityID getTarget() {
return this.result;
}
private List<Human>
filterRescueTargets(Collection<? extends StandardEntity> list) {
List<Human> rescueTargets = new ArrayList<>();
for (StandardEntity next : list) {
if (!(next instanceof Human))
continue;
Human h = (Human) next;
if (!isValidHuman(h))
continue;
if (h.getBuriedness() == 0)
continue;
rescueTargets.add(h);
}
return rescueTargets;
}
private List<Human>
filterInCluster(Collection<? extends StandardEntity> entities) {
int clusterIndex = clustering.getClusterIndex(this.agentInfo.getID());
List<Human> filter = new ArrayList<>();
HashSet<StandardEntity> inCluster = new HashSet<>(
clustering.getClusterEntities(clusterIndex));
for (StandardEntity next : entities) {
if (!(next instanceof Human))
continue;
Human h = (Human) next;
if (!h.isPositionDefined())
continue;
StandardEntity position = this.worldInfo.getPosition(h);
if (position == null)
continue;
if (!inCluster.contains(position))
continue;
filter.add(h);
}
return filter;
}
private class DistanceSorter implements Comparator<StandardEntity> {
private StandardEntity reference;
private WorldInfo worldInfo;
DistanceSorter(WorldInfo wi, StandardEntity reference) {
this.reference = reference;
this.worldInfo = wi;
}
public int compare(StandardEntity a, StandardEntity b) {
int d1 = this.worldInfo.getDistance(this.reference, a);
int d2 = this.worldInfo.getDistance(this.reference, b);
return d1 - d2;
}
}
private boolean isValidHuman(StandardEntity entity) {
if (entity == null)
return false;
if (!(entity instanceof Human))
return false;
Human target = (Human) entity;
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();
if (positionURN == REFUGE || positionURN == AMBULANCE_TEAM)
return false;
return true;
}
}
\ No newline at end of file
package sample_team.module.complex;
import adf.core.agent.communication.MessageManager;
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.agent.precompute.PrecomputeData;
import adf.core.component.module.complex.PoliceTargetAllocator;
import java.util.HashMap;
import java.util.Map;
import rescuecore2.worldmodel.EntityID;
public class SamplePoliceTargetAllocator extends PoliceTargetAllocator {
public SamplePoliceTargetAllocator(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData);
}
@Override
public PoliceTargetAllocator resume(PrecomputeData precomputeData) {
super.resume(precomputeData);
if (this.getCountResume() >= 2) {
return this;
}
return this;
}
@Override
public PoliceTargetAllocator preparate() {
super.preparate();
if (this.getCountPrecompute() >= 2) {
return this;
}
return this;
}
@Override
public Map<EntityID, EntityID> getResult() {
return new HashMap<>();
}
@Override
public PoliceTargetAllocator calc() {
return this;
}
@Override
public PoliceTargetAllocator updateInfo(MessageManager messageManager) {
super.updateInfo(messageManager);
if (this.getCountUpdateInfo() >= 2) {
return this;
}
return this;
}
}
\ No newline at end of file
package sample_team.module.complex;
import static rescuecore2.standard.entities.StandardEntityURN.AMBULANCE_TEAM;
import static rescuecore2.standard.entities.StandardEntityURN.CIVILIAN;
import static rescuecore2.standard.entities.StandardEntityURN.FIRE_BRIGADE;
import static rescuecore2.standard.entities.StandardEntityURN.GAS_STATION;
import static rescuecore2.standard.entities.StandardEntityURN.POLICE_FORCE;
import static rescuecore2.standard.entities.StandardEntityURN.REFUGE;
import adf.core.agent.communication.MessageManager;
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.algorithm.Clustering;
import adf.core.component.module.algorithm.PathPlanning;
import adf.core.component.module.complex.RoadDetector;
import adf.core.debug.DefaultLogger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
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 SampleRoadDetector extends RoadDetector {
private Set<Area> openedAreas = new HashSet<>();
private Clustering clustering;
private PathPlanning pathPlanning;
private EntityID result;
private Logger logger;
public SampleRoadDetector(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData);
logger = DefaultLogger.getLogger(agentInfo.me());
this.pathPlanning = moduleManager.getModule(
"SampleRoadDetector.PathPlanning",
"adf.impl.module.algorithm.DijkstraPathPlanning");
this.clustering = moduleManager.getModule("SampleRoadDetector.Clustering",
"adf.impl.module.algorithm.KMeansClustring");
registerModule(this.clustering);
registerModule(this.pathPlanning);
this.result = null;
}
@Override
public RoadDetector updateInfo(MessageManager messageManager) {
logger.debug("Time:" + agentInfo.getTime());
super.updateInfo(messageManager);
return this;
}
@Override
public RoadDetector calc() {
EntityID positionID = this.agentInfo.getPosition();
StandardEntity currentPosition = worldInfo.getEntity(positionID);
openedAreas.add((Area) currentPosition);
if (positionID.equals(result)) {
logger.debug("reach to " + currentPosition + " resetting target");
this.result = null;
}
if (this.result == null) {
HashSet<Area> currentTargets = calcTargets();
logger.debug("Targets: " + currentTargets);
if (currentTargets.isEmpty()) {
this.result = null;
return this;
}
this.pathPlanning.setFrom(positionID);
this.pathPlanning.setDestination(toEntityIds(currentTargets));
List<EntityID> path = this.pathPlanning.calc().getResult();
if (path != null && path.size() > 0) {
this.result = path.get(path.size() - 1);
}
logger.debug("Selected Target: " + this.result);
}
return this;
}
private Collection<EntityID>
toEntityIds(Collection<? extends StandardEntity> entities) {
ArrayList<EntityID> eids = new ArrayList<>();
for (StandardEntity standardEntity : entities) {
eids.add(standardEntity.getID());
}
return eids;
}
private HashSet<Area> calcTargets() {
HashSet<Area> targetAreas = new HashSet<>();
for (StandardEntity e : this.worldInfo.getEntitiesOfType(REFUGE,
GAS_STATION)) {
targetAreas.add((Area) e);
}
for (StandardEntity e : this.worldInfo.getEntitiesOfType(CIVILIAN,
AMBULANCE_TEAM, FIRE_BRIGADE, POLICE_FORCE)) {
if (isValidHuman(e)) {
Human h = (Human) e;
targetAreas.add((Area) worldInfo.getEntity(h.getPosition()));
}
}
HashSet<Area> inClusterTarget = filterInCluster(targetAreas);
inClusterTarget.removeAll(openedAreas);
return inClusterTarget;
}
private HashSet<Area> filterInCluster(HashSet<Area> targetAreas) {
int clusterIndex = clustering.getClusterIndex(this.agentInfo.getID());
HashSet<Area> clusterTargets = new HashSet<>();
HashSet<StandardEntity> inCluster = new HashSet<>(
clustering.getClusterEntities(clusterIndex));
for (Area target : targetAreas) {
if (inCluster.contains(target))
clusterTargets.add(target);
}
return clusterTargets;
}
@Override
public EntityID getTarget() {
return this.result;
}
private boolean isValidHuman(StandardEntity entity) {
if (entity == null)
return false;
if (!(entity instanceof Human))
return false;
Human target = (Human) entity;
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();
if (positionURN == REFUGE || positionURN == AMBULANCE_TEAM)
return false;
return true;
}
}
\ No newline at end of file
package sample_team.module.complex;
import static rescuecore2.standard.entities.StandardEntityURN.AMBULANCE_CENTRE;
import static rescuecore2.standard.entities.StandardEntityURN.AMBULANCE_TEAM;
import static rescuecore2.standard.entities.StandardEntityURN.BUILDING;
import static rescuecore2.standard.entities.StandardEntityURN.FIRE_BRIGADE;
import static rescuecore2.standard.entities.StandardEntityURN.FIRE_STATION;
import static rescuecore2.standard.entities.StandardEntityURN.GAS_STATION;
import static rescuecore2.standard.entities.StandardEntityURN.POLICE_FORCE;
import static rescuecore2.standard.entities.StandardEntityURN.POLICE_OFFICE;
import static rescuecore2.standard.entities.StandardEntityURN.REFUGE;
import adf.core.agent.communication.MessageManager;
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.algorithm.Clustering;
import adf.core.component.module.algorithm.PathPlanning;
import adf.core.component.module.complex.Search;
import adf.core.debug.DefaultLogger;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import org.apache.log4j.Logger;
import rescuecore2.standard.entities.Building;
import rescuecore2.standard.entities.StandardEntity;
import rescuecore2.standard.entities.StandardEntityURN;
import rescuecore2.worldmodel.EntityID;
public class SampleSearch extends Search {
private PathPlanning pathPlanning;
private Clustering clustering;
private EntityID result;
private Collection<EntityID> unsearchedBuildingIDs;
private Logger logger;
public SampleSearch(AgentInfo ai, WorldInfo wi, ScenarioInfo si, ModuleManager moduleManager, DevelopData developData) {
super(ai, wi, si, moduleManager, developData);
logger = DefaultLogger.getLogger(agentInfo.me());
this.unsearchedBuildingIDs = new HashSet<>();
StandardEntityURN agentURN = ai.me().getStandardURN();
if (agentURN == AMBULANCE_TEAM) {
this.pathPlanning = moduleManager.getModule(
"SampleSearch.PathPlanning.Ambulance",
"adf.impl.module.algorithm.DijkstraPathPlanning");
this.clustering = moduleManager.getModule(
"SampleSearch.Clustering.Ambulance",
"adf.impl.module.algorithm.KMeansClustering");
} else if (agentURN == FIRE_BRIGADE) {
this.pathPlanning = moduleManager.getModule(
"SampleSearch.PathPlanning.Fire",
"adf.impl.module.algorithm.DijkstraPathPlanning");
this.clustering = moduleManager.getModule("SampleSearch.Clustering.Fire",
"adf.impl.module.algorithm.KMeansClustering");
} else if (agentURN == POLICE_FORCE) {
this.pathPlanning = moduleManager.getModule(
"SampleSearch.PathPlanning.Police",
"adf.impl.module.algorithm.DijkstraPathPlanning");
this.clustering = moduleManager.getModule(
"SampleSearch.Clustering.Police",
"adf.impl.module.algorithm.KMeansClustering");
}
registerModule(this.clustering);
registerModule(this.pathPlanning);
}
@Override
public Search updateInfo(MessageManager messageManager) {
logger.debug("Time:" + agentInfo.getTime());
super.updateInfo(messageManager);
this.unsearchedBuildingIDs
.removeAll(this.worldInfo.getChanged().getChangedEntities());
if (this.unsearchedBuildingIDs.isEmpty()) {
this.reset();
this.unsearchedBuildingIDs
.removeAll(this.worldInfo.getChanged().getChangedEntities());
}
return this;
}
@Override
public Search calc() {
this.result = null;
if (unsearchedBuildingIDs.isEmpty())
return this;
logger.debug("unsearchedBuildingIDs: " + unsearchedBuildingIDs);
this.pathPlanning.setFrom(this.agentInfo.getPosition());
this.pathPlanning.setDestination(this.unsearchedBuildingIDs);
List<EntityID> path = this.pathPlanning.calc().getResult();
logger.debug("best path is: " + path);
if (path != null && path.size() > 2) {
this.result = path.get(path.size() - 3);
} else if (path != null && path.size() > 0) {
this.result = path.get(path.size() - 1);
}
logger.debug("chose: " + result);
return this;
}
private void reset() {
this.unsearchedBuildingIDs.clear();
int clusterIndex = this.clustering.getClusterIndex(this.agentInfo.getID());
Collection<StandardEntity> clusterEntities = this.clustering
.getClusterEntities(clusterIndex);
if (clusterEntities != null && clusterEntities.size() > 0) {
for (StandardEntity entity : clusterEntities) {
if (entity instanceof Building && entity.getStandardURN() != REFUGE) {
this.unsearchedBuildingIDs.add(entity.getID());
}
}
} else {
this.unsearchedBuildingIDs
.addAll(this.worldInfo.getEntityIDsOfType(BUILDING, GAS_STATION,
AMBULANCE_CENTRE, FIRE_STATION, POLICE_OFFICE));
}
}
@Override
public EntityID getTarget() {
return this.result;
}
}
\ No newline at end of file
name: asciidoctor-ghpages
on:
push:
paths:
- 'docs/**'
jobs:
build:
runs-on: ubuntu-latest
container: asciidoctor/docker-asciidoctor
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Generate HTML
run: asciidoctor -b html5 -r asciidoctor-bibtex -a bibtex-file=docs/references.bib docs/adf-manual.adoc -o docs/index.html
- name: Generate PDF
run: asciidoctor-pdf -r asciidoctor-bibtex -r asciidoctor-mathematical -a bibtex-file=docs/references.bib -a mathematical-format=svg -a optimize -a pdf-theme=docs/resources/themes/manual.yml -a pdf-fontsdir=docs/resources/fonts docs/adf-manual.adoc -o docs/adf-manual.pdf
- name: Deploy to GitHub Pages
uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
build_dir: docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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