Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated Code Change #240

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent_based_epidemic_sim/core/distribution_sampler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using ::testing::AnyOf;
using ::testing::ElementsAre;

TEST(DiscreteDistributionSamplerTest, CreatesSingleIntDistribution) {
auto sampler = DiscreteDistributionSampler<int64>::FromProto(
auto sampler = DiscreteDistributionSampler<int64_t>::FromProto(
ParseTextProtoOrDie<DiscreteDistribution>(R"pb(
buckets { count: 1 int_value: 1 }
buckets { count: 2 int_value: 10 }
Expand Down
4 changes: 2 additions & 2 deletions agent_based_epidemic_sim/core/enum_indexed_array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum class TestEnum {
};

TEST(EnumIndexedArray, BracketOperator) {
EnumIndexedArray<int64, TestEnum, 3> a{{1, 4, 6}};
EnumIndexedArray<int64_t, TestEnum, 3> a{{1, 4, 6}};
EXPECT_EQ(a[TestEnum::kCase0], 1);
EXPECT_EQ(a[TestEnum::kCase1], 4);
EXPECT_EQ(a[TestEnum::kCase2], 6);
Expand All @@ -46,7 +46,7 @@ TEST(EnumIndexedArray, BracketOperator) {
}

TEST(EnumIndexedArray, BracketOperatorConst) {
const EnumIndexedArray<int64, TestEnum, 3> a{{2, 5, 8}};
const EnumIndexedArray<int64_t, TestEnum, 3> a{{2, 5, 8}};
EXPECT_EQ(a[TestEnum::kCase0], 2);
EXPECT_EQ(a[TestEnum::kCase1], 5);
EXPECT_EQ(a[TestEnum::kCase2], 8);
Expand Down
27 changes: 14 additions & 13 deletions agent_based_epidemic_sim/core/exposure_store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ absl::Time TestHour(int day, int hour) {
return TestDay(day) + absl::Hours(hour);
}

std::vector<InfectionOutcome> Outcomes(int day, std::vector<int64> uuids) {
std::vector<InfectionOutcome> Outcomes(int day, std::vector<int64_t> uuids) {
std::vector<InfectionOutcome> outcomes;
const absl::Duration duration = absl::Hours(1);
absl::Time start = TestDay(day);
for (int64 uuid : uuids) {
for (int64_t uuid : uuids) {
outcomes.push_back({.exposure = {.start_time = start, .duration = duration},
.source_uuid = uuid});
start += duration;
Expand All @@ -32,7 +32,7 @@ std::vector<InfectionOutcome> Outcomes(int day, std::vector<int64> uuids) {
TEST(ExposureStoreTest, AddsAndRemovesExposures) {
ExposureStore store;

auto get_notification_exposures = [&store](int64 uuid) {
auto get_notification_exposures = [&store](int64_t uuid) {
ContactReport report = {.from_agent_uuid = uuid};
std::vector<absl::Time> times;
store.ProcessNotification(report, [&times](const Exposure& exposure) {
Expand All @@ -55,8 +55,8 @@ TEST(ExposureStoreTest, AddsAndRemovesExposures) {
EXPECT_EQ(store.size(), 9);

auto get_agents = [&store](absl::Time since) {
std::vector<int64> agents;
store.PerAgent(since, [&agents](int64 uuid) { agents.push_back(uuid); });
std::vector<int64_t> agents;
store.PerAgent(since, [&agents](int64_t uuid) { agents.push_back(uuid); });
return agents;
};
EXPECT_THAT(get_agents(TestDay(2)),
Expand All @@ -66,16 +66,17 @@ TEST(ExposureStoreTest, AddsAndRemovesExposures) {
EXPECT_THAT(get_agents(TestDay(4)), testing::UnorderedElementsAre(11, 12));

auto get_exposures = [&store](absl::Time since) {
std::vector<std::tuple<int64, absl::Time, int64>> exposures;
store.PerExposure(since, [&exposures](int64 uuid, const Exposure& exposure,
const ContactReport* report) {
int64 from = report != nullptr ? report->from_agent_uuid : -1;
exposures.push_back({uuid, exposure.start_time, from});
});
std::vector<std::tuple<int64_t, absl::Time, int64_t>> exposures;
store.PerExposure(
since, [&exposures](int64_t uuid, const Exposure& exposure,
const ContactReport* report) {
int64_t from = report != nullptr ? report->from_agent_uuid : -1;
exposures.push_back({uuid, exposure.start_time, from});
});
return exposures;
};
{
std::vector<std::tuple<int64, absl::Time, int64>> expected = {
std::vector<std::tuple<int64_t, absl::Time, int64_t>> expected = {
{10, TestHour(2, 0), -1}, //
{13, TestHour(2, 1), -1}, //
{11, TestHour(2, 2), 11}, //
Expand All @@ -90,7 +91,7 @@ TEST(ExposureStoreTest, AddsAndRemovesExposures) {
testing::UnorderedElementsAreArray(expected));
}
{
std::vector<std::tuple<int64, absl::Time, int64>> expected = {
std::vector<std::tuple<int64_t, absl::Time, int64_t>> expected = {
{10, TestHour(3, 1), -1}, //
{11, TestHour(4, 0), 11}, //
{12, TestHour(4, 1), -1}, //
Expand Down
34 changes: 17 additions & 17 deletions agent_based_epidemic_sim/core/graph_location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ namespace {

class GraphLocation : public Location {
public:
GraphLocation(int64 uuid, std::function<float()> location_transmissibility,
GraphLocation(int64_t uuid, std::function<float()> location_transmissibility,
std::function<float()> drop_probability,
std::vector<std::pair<int64, int64>> graph,
std::vector<std::pair<int64_t, int64_t>> graph,
const ExposureGenerator& exposure_generator)
: graph_(std::move(graph)),
uuid_(uuid),
location_transmissibility_(std::move(location_transmissibility)),
drop_probability_(drop_probability),
exposure_generator_(exposure_generator) {}

int64 uuid() const override { return uuid_; }
int64_t uuid() const override { return uuid_; }

void ProcessVisits(absl::Span<const Visit> visits,
Broker<InfectionOutcome>* infection_broker) override {
thread_local absl::flat_hash_map<int64, Visit> visit_map;
thread_local absl::flat_hash_map<int64_t, Visit> visit_map;
visit_map.clear();
for (const Visit& visit : visits) {
visit_map[visit.agent_uuid] = visit;
Expand All @@ -59,7 +59,7 @@ class GraphLocation : public Location {

absl::BitGenRef gen = GetBitGen();

for (const std::pair<int64, int64>& edge : graph_) {
for (const std::pair<int64_t, int64_t>& edge : graph_) {
// Randomly drop some potential contacts.
if (absl::Bernoulli(gen, drop_probability_())) {
continue;
Expand Down Expand Up @@ -90,20 +90,20 @@ class GraphLocation : public Location {
}

protected:
std::vector<std::pair<int64, int64>> graph_;
std::vector<std::pair<int64_t, int64_t>> graph_;

private:
virtual void MaybeUpdateGraph(absl::Span<const Visit> visits) {}

const int64 uuid_;
const int64_t uuid_;
const std::function<float()> location_transmissibility_;
const std::function<float()> drop_probability_;
const ExposureGenerator& exposure_generator_;
};

class RandomGraphLocation : public GraphLocation {
public:
RandomGraphLocation(int64 uuid,
RandomGraphLocation(int64_t uuid,
std::function<float()> location_transmissibility,
std::function<float()> lockdown_multiplier,
const ExposureGenerator& exposure_generator)
Expand All @@ -117,7 +117,7 @@ class RandomGraphLocation : public GraphLocation {
void MaybeUpdateGraph(absl::Span<const Visit> visits) override {
// Construct list of agent UUIDs as potential endpoints for edges. An agent
// is repeated once for each edge needed by it.
thread_local std::vector<int64> agent_uuids;
thread_local std::vector<int64_t> agent_uuids;
internal::AgentUuidsFromRandomLocationVisits(visits, lockdown_multiplier_(),
agent_uuids);
// Connect random pairs till none remain.
Expand All @@ -136,7 +136,7 @@ namespace internal {

void AgentUuidsFromRandomLocationVisits(absl::Span<const Visit> visits,
const float lockdown_multiplier,
std::vector<int64>& agent_uuids) {
std::vector<int64_t>& agent_uuids) {
agent_uuids.clear();
for (const Visit& visit : visits) {
agent_uuids.resize(
Expand All @@ -146,12 +146,12 @@ void AgentUuidsFromRandomLocationVisits(absl::Span<const Visit> visits,
}
}

void ConnectAdjacentNodes(absl::Span<const int64> agent_uuids,
std::vector<std::pair<int64, int64>>& graph) {
void ConnectAdjacentNodes(absl::Span<const int64_t> agent_uuids,
std::vector<std::pair<int64_t, int64_t>>& graph) {
graph.clear();
while (agent_uuids.size() >= 2) {
int64 a = agent_uuids[0];
int64 b = agent_uuids[1];
int64_t a = agent_uuids[0];
int64_t b = agent_uuids[1];
if (a == b) {
// Self-edges are not allowed. Try next pair.
agent_uuids.remove_prefix(1);
Expand All @@ -170,17 +170,17 @@ void ConnectAdjacentNodes(absl::Span<const int64> agent_uuids,
} // namespace internal

std::unique_ptr<Location> NewGraphLocation(
int64 uuid, std::function<float()> location_transmissibility,
int64_t uuid, std::function<float()> location_transmissibility,
std::function<float()> drop_probability,
std::vector<std::pair<int64, int64>> graph,
std::vector<std::pair<int64_t, int64_t>> graph,
const ExposureGenerator& exposure_generator) {
return absl::make_unique<GraphLocation>(
uuid, std::move(location_transmissibility), std::move(drop_probability),
std::move(graph), exposure_generator);
}

std::unique_ptr<Location> NewRandomGraphLocation(
int64 uuid, std::function<float()> location_transmissibility,
int64_t uuid, std::function<float()> location_transmissibility,
std::function<float()> lockdown_multiplier,
const ExposureGenerator& exposure_generator) {
return absl::make_unique<RandomGraphLocation>(
Expand Down
16 changes: 8 additions & 8 deletions agent_based_epidemic_sim/core/graph_location_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FakeExposureGenerator : public ExposureGenerator {

static constexpr int kLocationUUID = 1;

Visit GenerateVisit(int64 agent, HealthState::State health_state,
Visit GenerateVisit(int64_t agent, HealthState::State health_state,
int random_location_edges = 1) {
return {
.location_uuid = kLocationUUID,
Expand All @@ -62,8 +62,8 @@ Visit GenerateVisit(int64 agent, HealthState::State health_state,
.random_location_edges = random_location_edges,
}};
}
InfectionOutcome ExpectedOutcome(int64 agent, int64 source, float infectivity,
float transmissibility) {
InfectionOutcome ExpectedOutcome(int64_t agent, int64_t source,
float infectivity, float transmissibility) {
return {
.agent_uuid = agent,
.exposure =
Expand Down Expand Up @@ -124,7 +124,7 @@ TEST(GraphLocationTest, AllSamplesDropped) {
}

TEST(AgentUuidsFromRandomLocationVisits, Basic) {
std::vector<int64> agent_uuids;
std::vector<int64_t> agent_uuids;
internal::AgentUuidsFromRandomLocationVisits(
{
GenerateVisit(0, HealthState::SUSCEPTIBLE, 2),
Expand All @@ -142,7 +142,7 @@ TEST(AgentUuidsFromRandomLocationVisits, Basic) {

TEST(AgentUuidsFromRandomLocationVisits, ClearsOutputArg) {
// Tests that pre-existing values are removed from agent_uuids.
std::vector<int64> agent_uuids = {1, 2, 3};
std::vector<int64_t> agent_uuids = {1, 2, 3};
internal::AgentUuidsFromRandomLocationVisits(
{
GenerateVisit(0, HealthState::SUSCEPTIBLE, 2),
Expand All @@ -158,7 +158,7 @@ TEST(AgentUuidsFromRandomLocationVisits, ClearsOutputArg) {
}

TEST(ConnectAdjacentNodes, Basic) {
std::vector<std::pair<int64, int64>> graph;
std::vector<std::pair<int64_t, int64_t>> graph;
internal::ConnectAdjacentNodes({1, 2, 3, 4, 5, 6, 7}, graph);
EXPECT_THAT(graph, testing::ElementsAreArray({
testing::Pair(1, 2),
Expand All @@ -169,7 +169,7 @@ TEST(ConnectAdjacentNodes, Basic) {

TEST(ConnectAdjacentNodes, EdgesAreSortedAndDistinct) {
// Tests that the graph's edges are sorted and distinct.
std::vector<std::pair<int64, int64>> graph;
std::vector<std::pair<int64_t, int64_t>> graph;
internal::ConnectAdjacentNodes({2, 1, 3, 1, 3, 4, 1, 2}, graph);
EXPECT_THAT(graph, testing::ElementsAreArray({
testing::Pair(1, 2),
Expand All @@ -180,7 +180,7 @@ TEST(ConnectAdjacentNodes, EdgesAreSortedAndDistinct) {

TEST(ConnectAdjacentNodes, NoSelfEdges) {
// Tests that the graph does not include self-edges.
std::vector<std::pair<int64, int64>> graph;
std::vector<std::pair<int64_t, int64_t>> graph;
internal::ConnectAdjacentNodes({1, 1, 2, 3, 3, 4}, graph);
EXPECT_THAT(graph, testing::ElementsAreArray({
testing::Pair(1, 2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ constexpr float kEpsilon = 1e-5;
} // namespace

IndexedLocationVisitGenerator::IndexedLocationVisitGenerator(
const std::vector<int64>& location_uuids) {
const std::vector<int64_t>& location_uuids) {
std::vector<LocationDuration> location_durations;
location_durations.reserve(location_uuids.size());
for (const int64 location_uuid : location_uuids) {
for (const int64_t location_uuid : location_uuids) {
location_durations.push_back(
{.location_uuid = location_uuid,
.sample_duration = [](float adjustment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ absl::Duration VisitDuration(const Visit& visit) {
}

TEST(IndexedLocationVisitGeneratorTest, GeneratesVisits) {
std::vector<int64> location_uuids{0LL, 1LL, 2LL};
std::vector<int64_t> location_uuids{0LL, 1LL, 2LL};
IndexedLocationVisitGenerator visit_generator(location_uuids);
auto risk_score = NewNullRiskScore();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace {

class MockUuidGenerator : public UuidGenerator {
public:
MOCK_METHOD(int64, GenerateUuid, (), (const, override));
MOCK_METHOD(int64_t, GenerateUuid, (), (const, override));
};

TEST(LocationDiscreteEventSimulatorBuilderTest, BuildsAgents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const ProximityTrace kFarProximityTrace({kFarProximity});
using testing::UnorderedElementsAreArray;

std::vector<InfectionOutcome> InfectionOutcomesFromContacts(
const absl::Span<const Contact> contacts, const int64 uuid) {
const absl::Span<const Contact> contacts, const int64_t uuid) {
std::vector<InfectionOutcome> infection_outcomes;
for (const Contact& contact : contacts) {
infection_outcomes.push_back(
Expand All @@ -56,7 +56,7 @@ std::vector<InfectionOutcome> InfectionOutcomesFromContacts(
}

TEST(LocationDiscreteEventSimulatorTest, ContactTracing) {
const int64 kUuid = 42LL;
const int64_t kUuid = 42LL;
std::vector<Visit> visits{Visit{.location_uuid = 42LL,
.agent_uuid = 0LL,
.start_time = absl::FromUnixSeconds(0LL),
Expand Down Expand Up @@ -180,7 +180,7 @@ TEST(LocationDiscreteEventSimulatorTest, ContactTracing) {

TEST(LocationDiscreteEventSimulatorTest, ProcessVisitsRejectsWrongUuid) {
auto infection_broker = absl::make_unique<MockBroker<InfectionOutcome>>();
const int64 kUuid = 42LL;
const int64_t kUuid = 42LL;
std::vector<Visit> visits{Visit{.location_uuid = 314LL,
.agent_uuid = 0LL,
.start_time = absl::FromUnixSeconds(0LL),
Expand All @@ -195,7 +195,7 @@ TEST(LocationDiscreteEventSimulatorTest, ProcessVisitsRejectsWrongUuid) {
TEST(LocationDiscreteEventSimulatorTest,
ProcessVisitsRejectsStartTimeNotBeforeEndTime) {
auto infection_broker = absl::make_unique<MockBroker<InfectionOutcome>>();
const int64 kUuid = 42LL;
const int64_t kUuid = 42LL;
std::vector<Visit> visits{Visit{.location_uuid = kUuid,
.agent_uuid = 0LL,
.start_time = absl::FromUnixSeconds(0LL),
Expand Down
2 changes: 1 addition & 1 deletion agent_based_epidemic_sim/core/risk_score.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NullRiskScore : public RiskScore {
const ContactReport& notification) override {}

VisitAdjustment GetVisitAdjustment(const Timestep& timestep,
int64 location_uuid) const override {
int64_t location_uuid) const override {
return {.frequency_adjustment = 1.0, .duration_adjustment = 1.0};
}
TestResult GetTestResult(const Timestep& timestep) const override {
Expand Down
28 changes: 14 additions & 14 deletions agent_based_epidemic_sim/core/seir_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DefaultInfectivityModel : public InfectivityModel {

/* static */
std::unique_ptr<SEIRAgent> SEIRAgent::CreateSusceptible(
const int64 uuid, TransmissionModel* transmission_model,
const int64_t uuid, TransmissionModel* transmission_model,
const InfectivityModel* infectivity_model,
std::unique_ptr<TransitionModel> transition_model,
const VisitGenerator& visit_generator,
Expand All @@ -91,7 +91,7 @@ std::unique_ptr<SEIRAgent> SEIRAgent::CreateSusceptible(

/* static */
std::unique_ptr<SEIRAgent> SEIRAgent::Create(
const int64 uuid, const HealthTransition& health_transition,
const int64_t uuid, const HealthTransition& health_transition,
TransmissionModel* transmission_model,
const InfectivityModel* infectivity_model,
std::unique_ptr<TransitionModel> transition_model,
Expand Down Expand Up @@ -224,18 +224,18 @@ void SEIRAgent::SendContactReports(const Timestep& timestep,
}

std::vector<ContactReport> contact_reports;
exposures_.PerAgent(contact_report_send_cutoff_,
[this, &test_result, &contact_reports](const int64 uuid) {
contact_reports.push_back({
.from_agent_uuid = this->uuid(),
.to_agent_uuid = uuid,
.test_result = test_result,
.initial_symptom_onset_time =
initial_symptom_onset_time_.has_value()
? initial_symptom_onset_time_
: test_result.time_requested,
});
});
exposures_.PerAgent(contact_report_send_cutoff_, [this, &test_result,
&contact_reports](
const int64_t uuid) {
contact_reports.push_back({
.from_agent_uuid = this->uuid(),
.to_agent_uuid = uuid,
.test_result = test_result,
.initial_symptom_onset_time = initial_symptom_onset_time_.has_value()
? initial_symptom_onset_time_
: test_result.time_requested,
});
});
contact_report_send_cutoff_ = timestep.start_time();
broker->Send(contact_reports);
}
Expand Down
Loading