Skip to content

Commit

Permalink
optimize includes
Browse files Browse the repository at this point in the history
  • Loading branch information
foolnotion committed Apr 23, 2024
1 parent 33e5b50 commit 32c0b5a
Show file tree
Hide file tree
Showing 25 changed files with 198 additions and 31 deletions.
16 changes: 14 additions & 2 deletions cli/source/util.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include "util.hpp"

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fmt/core.h>
#include <fmt/format.h>
#include <iterator>
#include <limits>
#include <memory>
#include <scn/scan.h>
#include <sstream>
#include <stdexcept>

#include "util.hpp"

#include "operon/core/node.hpp"
#include "operon/core/pset.hpp"
#include "operon/core/version.hpp"
#include "operon/core/types.hpp"

using Operon::NodeType;

Expand Down
9 changes: 5 additions & 4 deletions cli/source/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#ifndef OPERON_CLI_UTIL_HPP
#define OPERON_CLI_UTIL_HPP

#include <charconv>
#include <chrono>
#include <cstddef>
#include <cxxopts.hpp>
#include <fmt/core.h>
#include <sstream>
#include <string>

#include <cxxopts.hpp>
#include <tuple>
#include <utility>
#include <vector>

#include "operon/core/node.hpp"

Expand Down
6 changes: 3 additions & 3 deletions include/operon/core/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#ifndef OPERON_CORE_NODE_HPP
#define OPERON_CORE_NODE_HPP

#include "operon/operon_export.hpp"
#include <cstddef>
#include <cstdint>
#include <type_traits>

#include "operon/operon_export.hpp"
#include "types.hpp"

namespace Operon {
Expand Down Expand Up @@ -210,4 +211,3 @@ struct Node {
};
} // namespace Operon
#endif

1 change: 0 additions & 1 deletion include/operon/core/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#define OPERON_TYPES_HPP

#include <ankerl/unordered_dense.h>
#include <cstddef>
#include <cstdint>
#include <span>
#include <utility>
Expand Down
8 changes: 8 additions & 0 deletions include/operon/operators/crossover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
#ifndef OPERON_CROSSOVER_HPP
#define OPERON_CROSSOVER_HPP

#include <cstddef>
#include <vector>
#include <algorithm>
#include <iterator>
#include <type_traits>
#include <utility>

#include "operon/operon_export.hpp"
#include "operon/core/operator.hpp"
#include "operon/core/tree.hpp"
#include "operon/core/node.hpp"
#include "operon/core/types.hpp"

namespace Operon {
// crossover takes two parent trees and returns a child
Expand Down
11 changes: 9 additions & 2 deletions include/operon/operators/mutation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
#ifndef OPERON_MUTATION_HPP
#define OPERON_MUTATION_HPP

#include <cstddef>
#include <utility>
#include <functional>
#include <vector>

#include "operon/operon_export.hpp"
#include "operon/core/operator.hpp"
#include "operon/core/pset.hpp"
#include "operon/core/tree.hpp"
#include "operon/core/variable.hpp"
#include "operon/core/contracts.hpp"
#include "operon/core/node.hpp"
#include "operon/core/types.hpp"
#include "operon/random/random.hpp"

namespace Operon {

Expand Down Expand Up @@ -147,7 +154,7 @@ struct OPERON_EXPORT InsertSubtreeMutation final : public MutatorBase {

struct OPERON_EXPORT ReplaceSubtreeMutation : public MutatorBase {
ReplaceSubtreeMutation(CreatorBase& creator, CoefficientInitializerBase& coeffInit, size_t maxDepth, size_t maxLength)
: creator_(creator)
: creator_(creator)
, coefficientInitializer_(coeffInit)
, maxDepth_(maxDepth)
, maxLength_(maxLength)
Expand Down
2 changes: 1 addition & 1 deletion include/operon/random/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>
#include <random>
#include <type_traits>

#include "operon/core/contracts.hpp"

#include "jsf.hpp"
Expand Down Expand Up @@ -64,4 +65,3 @@ auto Sample(R& random, InputIterator start, InputIterator end, OutputIterator ou
} // namespace Operon::Random

#endif

10 changes: 9 additions & 1 deletion source/algorithms/solution_archive.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <cstdint>
#include <algorithm>
#include <iterator>
#include <span>
#include <vector>

#include "operon/algorithms/solution_archive.hpp"
#include "operon/operators/non_dominated_sorter.hpp"
#include "operon/core/comparison.hpp"
#include "operon/core/individual.hpp"
#include "operon/core/types.hpp"

namespace Operon {

Expand Down
3 changes: 3 additions & 0 deletions source/core/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include "operon/core/node.hpp"

#include <iterator> // for pair
#include <unordered_map> // for unordered_map, _Map_base<>::mapped_type
#include <utility> // for make_pair, pair
#include <string> // for string

#include "operon/core/types.hpp"

using std::pair;
using std::string;
using std::unordered_map;
Expand Down
14 changes: 12 additions & 2 deletions source/core/pset.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <numeric>
#include <fmt/format.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <fmt/core.h>
#include <random>
#include <stdexcept>
#include <tuple>
#include <utility>
#include <vector>

#include "operon/core/pset.hpp"
#include "operon/core/contracts.hpp"
#include "operon/core/node.hpp"
#include "operon/core/types.hpp"

namespace Operon {
[[nodiscard]] auto PrimitiveSet::GetPrimitive(Operon::Hash hash) const -> Primitive const& {
Expand Down
10 changes: 9 additions & 1 deletion source/core/tree.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <cstddef>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <ranges>
#include <functional>
#include <iterator>
#include <span>
#include <vector>

#include "operon/core/tree.hpp"
#include "operon/hash/hash.hpp"
#include "operon/core/constants.hpp"
#include "operon/core/node.hpp"
#include "operon/core/types.hpp"

namespace Operon {
auto Tree::UpdateNodes() -> Tree&
Expand Down
5 changes: 5 additions & 0 deletions source/core/version.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <fmt/core.h>
#include <fmt/format.h>
#include <iterator>
#include <string>

#include "buildinfo.hpp"
#include "operon/core/version.hpp"

Expand Down
11 changes: 10 additions & 1 deletion source/operators/creator/balanced.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <cstddef>
#include <algorithm>
#include <random>
#include <span>
#include <tuple>
#include <vector>

#include "operon/operators/creator.hpp"
#include "operon/core/pset.hpp"
#include "operon/core/tree.hpp"
#include "operon/core/variable.hpp"
#include "operon/core/node.hpp"
#include "operon/core/types.hpp"
#include "operon/random/random.hpp"

namespace Operon {
auto BalancedTreeCreator::operator()(Operon::RandomGenerator& random, size_t targetLen, size_t /*args*/, size_t /*args*/) const -> Tree
Expand Down
10 changes: 9 additions & 1 deletion source/operators/creator/koza.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <cstddef>
#include <algorithm>
#include <random>
#include <span>

#include "operon/operators/creator.hpp"
#include "operon/core/pset.hpp"
#include "operon/core/tree.hpp"
#include "operon/core/variable.hpp"
#include "operon/core/contracts.hpp"
#include "operon/core/node.hpp"
#include "operon/core/types.hpp"
#include "operon/random/random.hpp"

namespace Operon {
auto GrowTreeCreator::operator()(Operon::RandomGenerator& random, size_t /*args*/, size_t minDepth, size_t maxDepth) const -> Tree
Expand Down
13 changes: 11 additions & 2 deletions source/operators/creator/ptc2.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <cstddef>
#include <cstdint>
#include <vector>
#include <deque>
#include <algorithm>
#include <random>
#include <span>
#include <utility>

#include "operon/operators/creator.hpp"
#include "operon/core/pset.hpp"
#include "operon/core/tree.hpp"
#include "operon/core/variable.hpp"
#include "operon/core/contracts.hpp"
#include "operon/core/node.hpp"
#include "operon/core/types.hpp"
#include "operon/random/random.hpp"

namespace Operon {
auto ProbabilisticTreeCreator::operator()(Operon::RandomGenerator& random, size_t targetLen, size_t /*args*/, size_t /*args*/) const -> Tree
Expand All @@ -21,7 +30,7 @@ auto ProbabilisticTreeCreator::operator()(Operon::RandomGenerator& random, size_
node.HashValue = *Random::Sample(random, variables.begin(), variables.end());
node.CalculatedHashValue = node.HashValue;
}
node.Value = 1;
node.Value = 1;
}
};

Expand Down
8 changes: 6 additions & 2 deletions source/operators/crossover.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <random>

#include "operon/core/contracts.hpp"
#include "operon/operators/crossover.hpp"
#include "operon/random/random.hpp"

namespace Operon {

Expand Down Expand Up @@ -49,7 +53,7 @@ static auto SelectRandomBranch(Operon::RandomGenerator& random, Tree const& tree
return *Operon::Random::Sample(random, candidates.rbegin(), tail);
}
return *Operon::Random::Sample(random, candidates.begin(), head);

}

auto SubtreeCrossover::FindCompatibleSwapLocations(Operon::RandomGenerator& random, Tree const& lhs, Tree const& rhs) const -> std::pair<size_t, size_t>
Expand All @@ -58,7 +62,7 @@ auto SubtreeCrossover::FindCompatibleSwapLocations(Operon::RandomGenerator& rand
auto diff = static_cast<Signed>(lhs.Length() - maxLength_ + 1); // +1 to account for at least one node that gets swapped in

auto i = SelectRandomBranch(random, lhs, internalProbability_, Limits{std::max(diff, Signed{1}), lhs.Length()}, Limits{size_t{1}, lhs.Depth()}, Limits{size_t{1}, lhs.Depth()});
// we have to make some small allowances here due to the fact that the provided trees
// we have to make some small allowances here due to the fact that the provided trees
// might actually be larger than the maxDepth and maxLength limits given here
auto maxBranchDepth = static_cast<Signed>(maxDepth_ - lhs[i].Level);
maxBranchDepth = std::max(maxBranchDepth, Signed{1});
Expand Down
10 changes: 8 additions & 2 deletions source/operators/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include "operon/operators/mutation.hpp"
#include "operon/core/variable.hpp"

#include <algorithm>
#include <cstdint>
#include <iterator>
#include <numeric>
#include <random>
#include <type_traits>

#include "operon/operators/creator.hpp"
#include "operon/operators/initializer.hpp"
#include <numeric>

namespace Operon {

Expand Down
9 changes: 9 additions & 0 deletions source/operators/non_dominated_sorter/deductive_sort.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <cstdint>
#include <algorithm>
#include <cstddef>
#include <limits>
#include <span>
#include <vector>

#include "operon/operators/non_dominated_sorter.hpp"
#include "operon/core/individual.hpp"
#include "operon/core/comparison.hpp"
#include "operon/core/types.hpp"

namespace Operon {
auto DeductiveSorter::Sort(Operon::Span<Operon::Individual const> pop, Operon::Scalar /*unused*/) const -> NondominatedSorterBase::Result
Expand Down
10 changes: 9 additions & 1 deletion source/operators/non_dominated_sorter/merge_sort.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2019-2023 Heal Research

#include <bit>
#include <cpp-sort/sorters/merge_sorter.h>
#include <cstddef>
#include <cstdint>
#include <bit>
#include <algorithm>
#include <array>
#include <limits>
#include <span>
#include <vector>

#include "operon/operators/non_dominated_sorter.hpp"
#include "operon/core/individual.hpp"
#include "operon/core/types.hpp"

namespace Operon {

Expand Down
Loading

0 comments on commit 32c0b5a

Please sign in to comment.