Skip to content

Commit

Permalink
* Fixing segfault that could occur in GroupFixedList and was causing …
Browse files Browse the repository at this point in the history
…issues in test_auctions/CI
  • Loading branch information
jredmondson committed Mar 19, 2019
1 parent 8fcb0f9 commit a730647
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/simulation/unreal/greet/greet.mf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{.prefix}.algorithm="waypoints";
{.prefix}.algorithm.args.locations.size=2;
{.prefix}.algorithm.args.locations.0=[0, swarm.size * 10 + .id * 10, 2];
{.prefix}.algorithm.args.locations.1=.guard;
{.prefix}.algorithm.args.locations.1=.origin;
{.prefix}.algorithm.args.repeat=5;
);

Expand Down
2 changes: 1 addition & 1 deletion scripts/simulation/unreal/greet/greet_and_follow.mf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{.prefix}.algorithm="waypoints";
{.prefix}.algorithm.args.locations.size=2;
{.prefix}.algorithm.args.locations.0=[0, swarm.size * 10 + .id * 10, 2];
{.prefix}.algorithm.args.locations.1=.guard;
{.prefix}.algorithm.args.locations.1=.origin;
{.prefix}.algorithm.args.repeat=5;
);

Expand Down
2 changes: 2 additions & 0 deletions src/gams/groups/GroupFixedList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ gams::groups::GroupFixedList::add_members(const AgentVector & members)
fast_members_.insert(
fast_members_.end(), members.begin(), members.end());

if (knowledge_)
{
knowledge::ContextGuard guard(*knowledge_);

Expand Down Expand Up @@ -185,6 +186,7 @@ gams::groups::GroupFixedList::remove_members(const AgentVector & members)
}
}

if (knowledge_)
{
knowledge::ContextGuard guard(*knowledge_);

Expand Down
25 changes: 24 additions & 1 deletion tests/test_auctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ void test_minimum_distance_auction(knowledge::KnowledgeBase & knowledge)
loggers::global_logger->log(
loggers::LOG_ALWAYS, "Testing AuctionMinimumDistance\n");

// knowledge::KnowledgeBase knowledge;
knowledge.clear(true);

gams::groups::GroupFixedList group;
Expand All @@ -255,6 +254,9 @@ void test_minimum_distance_auction(knowledge::KnowledgeBase & knowledge)
gams::pose::Position target;
gams::platforms::NullPlatform platform(&knowledge, 0, &platforms, 0);

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Adding members to the group\n");

// add some members to the group
members.push_back("agent.0");
members.push_back("agent.1");
Expand All @@ -263,16 +265,25 @@ void test_minimum_distance_auction(knowledge::KnowledgeBase & knowledge)
members.push_back("agent.4");
group.add_members(members);

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Initializing group variables in KB\n");

// initialize agent variables so we can manipulate them directly
gams::variables::init_vars(agents, knowledge, group);

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Creating bids\n");

// setup some handy references for referring to individual bids
containers::Double agent0bid("auction.guard_duty.0.agent.0", knowledge);
containers::Double agent1bid("auction.guard_duty.0.agent.1", knowledge);
containers::Double agent2bid("auction.guard_duty.0.agent.2", knowledge);
containers::Double agent3bid("auction.guard_duty.0.agent.3", knowledge);
containers::Double agent4bid("auction.guard_duty.0.agent.4", knowledge);

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Mimicking agent locations\n");

// create some GPS locations
position.latitude(42.0600);
position.longitude(-72.0600);
Expand All @@ -294,16 +305,28 @@ void test_minimum_distance_auction(knowledge::KnowledgeBase & knowledge)
position.longitude(-72.1000);
position.to_container(agents[4].location);

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Initializing auction\n");

auctions::AuctionMinimumDistance auction(
"auction.guard_duty", "agent.0", &knowledge, &platform);

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Adding group\n");

auction.add_group(&group);

// set the target position

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Setting target and calculating bids\n");

auction.set_target(position);
auction.calculate_bids();

loggers::global_logger->log(
loggers::LOG_ALWAYS, " Electing leader based on proximity\n");

std::string closest = auction.get_leader();

if (closest == "agent.0")
Expand Down

0 comments on commit a730647

Please # to comment.