Skip to content

Commit

Permalink
* Updated Greet algorithm
Browse files Browse the repository at this point in the history
  * Specification of guard group
  * Initial push into auctions (not hooked up but running performance tests)
* Updated Greet simulations
  * Specifying target group correctly
  * Creating guard group
* Updated MinimumDistanceAuction to be faster
  • Loading branch information
jredmondson committed Mar 25, 2019
1 parent 2d9b8a8 commit b8cd591
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 43 deletions.
7 changes: 5 additions & 2 deletions scripts/simulation/unreal/greet/greet.mf
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
// home.location
// target.group

group.targets.members.size=1;
group.targets.members.0='agent.0';
group.targets.members.size=.targets;

.i[0 -> group.targets.members.size)(
group.targets.members.{.i} = "agent." + .i;
);

{.prefix}.algorithm="greet";
{.prefix}.algorithm.args.home.location=.origin;
Expand Down
13 changes: 11 additions & 2 deletions scripts/simulation/unreal/greet/greet_and_follow.mf
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@
// home.location
// target.group

group.targets.members.size=1;
group.targets.members.0='agent.0';
group.targets.members.size=.targets;

.i[0 -> group.targets.members.size)(
group.targets.members.{.i} = "agent." + .i;
);

.group.guards.members.size=swarm.size-.targets;

.i[0 -> .group.guards.members.size)(
.group.guards.members.{.i} = "agent." + (.i + .targets);
);

{.prefix}.algorithm="greet";
{.prefix}.algorithm.args.home.location=.origin;
Expand Down
2 changes: 1 addition & 1 deletion scripts/simulation/unreal/greet/run_greet_and_follow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NT=0
TARGETS=1
SCRIPTS_DIR=`dirname $0`
SCRIPT="$SCRIPTS_DIR/greet_and_follow.mf"
LOG_LEVEL=1
LOG_LEVEL=4

if [ $# -ge 1 ]; then
if [ "$1" == "help" ] || [ "$1" == "-h" ]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/simulation/unreal/joystick/run_joystick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SCRIPTS_DIR=`dirname $0`

if [ $# -ge 1 ]; then
if [ "$1" == "help" ] || [ "$1" == "-h" ]; then
echo "$0 [scriptfile] [agent id] [num agent controllers]"
echo "$0 [scriptfile=init.mf] [agent id=0] [num agent controllers=1]"
exit 0
fi

Expand Down
30 changes: 0 additions & 30 deletions scripts/simulation/unreal/run_script.sh

This file was deleted.

77 changes: 76 additions & 1 deletion src/gams/algorithms/Greet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include <math.h>
#include <memory>

#include "madara/utility/Timer.h"
#include "gams/utility/ArgumentParser.h"
#include "gams/auctions/AuctionMinimumDistance.h"

using std::stringstream;

Expand All @@ -39,6 +41,7 @@ namespace containers = knowledge::containers;
typedef knowledge::KnowledgeRecord KnowledgeRecord;
typedef KnowledgeRecord::Integer Integer;
typedef knowledge::KnowledgeMap KnowledgeMap;
typedef madara::utility::Timer<madara::utility::Clock> Timer;

gams::algorithms::BaseAlgorithm *
gams::algorithms::GreetFactory::create(
Expand All @@ -54,6 +57,7 @@ gams::algorithms::GreetFactory::create(
// set defaults
std::string target;
std::string target_group = "group.targets";
std::string guard_group = ".group.guards";
double guard_distance = 20.0;
std::vector <double> guard_location;
double guard_max_follow_distance = -1;
Expand Down Expand Up @@ -134,6 +138,17 @@ gams::algorithms::GreetFactory::create(

break;
}
else if (i->first == "guard.group")
{
guard_group = i->second.to_string();

madara_logger_ptr_log(gams::loggers::global_logger.get(),
gams::loggers::LOG_MAJOR,
"gams::algorithms::GreetFactory:" \
" guard group set to %s\n", guard_group);

break;
}
else if (i->first == "guard.max_follow_distance")
{
guard_max_follow_distance = i->second.to_double();
Expand Down Expand Up @@ -198,7 +213,7 @@ gams::algorithms::GreetFactory::create(
{
result = new Greet(
target, target_group,
guard_distance, guard_location, guard_max_follow_distance,
guard_distance, guard_group, guard_location, guard_max_follow_distance,
home_location,
follow, follow_group, follow_max_agents,
knowledge, platform, sensors, self);
Expand All @@ -211,6 +226,7 @@ gams::algorithms::GreetFactory::create(
gams::algorithms::Greet::Greet(
const std::string & target, const std::string & target_group,
double guard_distance,
const std::string & guard_group,
const std::vector<double> & guard_location,
double guard_max_follow_distance,
const std::vector<double> & home_location,
Expand All @@ -236,6 +252,12 @@ gams::algorithms::Greet::Greet(
target_.init_vars(*knowledge, target);
}

if (guard_group != "")
{
guard_group_.reset(
group_factory_.create(guard_group));
}

if (target_group != "")
{
target_group_.reset(
Expand Down Expand Up @@ -387,6 +409,59 @@ gams::algorithms::Greet::analyze(void)
xy_location.z(0);
xy_guard_location.z(0);

std::vector<auctions::AuctionMinimumDistance> distance_auctions(
targets.size());
std::vector<auctions::AuctionBids> distance_bids(
targets.size());

if (follow_)
{
Timer overall_timer;
overall_timer.start();

// determine distances to targets
std::string auction_prefix = "auction.";
for (size_t i = 0; i < targets.size(); ++i)
{
containers::NativeDoubleVector target_container(
targets[i] + ".location", *knowledge_);
target_location.from_container(target_container);
target_location.z(0);

distance_auctions[i].add_group(guard_group_.get());
distance_auctions[i].set_knowledge_base(knowledge_);
distance_auctions[i].set_platform(platform_);

distance_auctions[i].set_auction_prefix(auction_prefix + targets[i]);
distance_auctions[i].set_agent_prefix(self_->agent.prefix);
distance_auctions[i].set_target(target_location);

// under the hood, we're using containers::Map and variables::Agents
// for the entire group. There are a couple of things to learn here.
// calculate_bids(), even though it is semantically accurate, will
// cause unnecessary computation since the other agents are modifying
// the value with their own loops. Best solution here is to just bid
// but we can optimize this way more. We're spending a lot of time in
// the KB in the current implementation
// action 50 100 150 200 250
// bid 0.0012s 0.0022s 0.0032s 0.0049s 0.0063s
// calc_bids 0.0022s 0.0054s 0.0072s 0.0099s 0.0143s
distance_auctions[i].bid(KnowledgeRecord(
xy_location.distance_to(target_location)));
// distance_auctions[i].calculate_bids();
distance_auctions[i].get_bids(distance_bids[i]);
auctions::sort_ascending(distance_bids[i]);
}

overall_timer.stop();

madara_logger_ptr_log(gams::loggers::global_logger.get(),
gams::loggers::LOG_MINOR,
"gams::algorithms::Greet::analyze:" \
" Time taken for all target calculate_bids and sorting = %f s.\n",
overall_timer.duration_ds());
}

if (is_following_)
{
target_location.from_container(target_.location);
Expand Down
4 changes: 4 additions & 0 deletions src/gams/algorithms/Greet.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace gams
Greet(
const std::string & target, const std::string & target_group,
double guard_distance,
const std::string & guard_group,
const std::vector<double> & guard_location,
double guard_max_follow_distance,
const std::vector<double> & home_location,
Expand Down Expand Up @@ -157,6 +158,9 @@ namespace gams
/// the distance from guard location (max of dimensions)
pose::Epsilon guard_epsilon_;

/// a group of agents guarding
std::unique_ptr<groups::GroupBase> guard_group_ = 0;

/// the location for the agent to guard
pose::Position guard_location_;

Expand Down
25 changes: 19 additions & 6 deletions src/gams/auctions/AuctionMinimumDistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <algorithm>

#include "madara/knowledge/containers/Integer.h"
#include "madara/knowledge/containers/NativeDoubleVector.h"

#include "AuctionMinimumDistance.h"
#include "gams/loggers/GlobalLogger.h"
Expand Down Expand Up @@ -129,25 +130,29 @@ void gams::auctions::AuctionMinimumDistance::calculate_bids(void)
if (knowledge_ && platform_)
{
// initialize the agent list within the group
variables::Agents agents;
variables::init_vars(agents, *knowledge_, group_);
// variables::Agents agents;
// variables::init_vars(agents, *knowledge_, group_);
std::vector<std::string> agents;
group_.get_members(agents);

for (size_t i = 0; i < agents.size(); ++i)
{
// import the agents's location into the GAMS Pose system
containers::NativeDoubleVector agent_location(
agents[i] + ".location", *knowledge_);
gams::pose::Position location(platform_->get_frame());
location.from_container(agents[i].location);
location.from_container(agent_location);

double distance = location.distance_to(target_);

madara_logger_ptr_log(gams::loggers::global_logger.get(),
gams::loggers::LOG_MINOR,
gams::loggers::LOG_DETAILED,
"gams::auctions::AuctionMinimumDistance::calculate_bids:" \
" agent %s distance is %f. Bidding distance.\n",
agents[i].prefix.c_str(), distance);
agents[i].c_str(), distance);

// bid for the agent using their distance to the target
bids_.set(agents[i].prefix, distance);
bids_.set(agents[i], distance);
}
}
else
Expand Down Expand Up @@ -189,3 +194,11 @@ pose::Position target)
{
target_ = target;
}

void
gams::auctions::AuctionMinimumDistance::set_platform(
platforms::BasePlatform * platform)
{
platform_ = platform;
}

0 comments on commit b8cd591

Please # to comment.