17#include <unordered_map>
26template<
typename FloatType>
28 static_assert(std::is_floating_point<FloatType>::value,
29 "Template parameter FloatType must be floating point type");
46 const std::vector<ValueType> &value_list) {
48 if (key_list.size() != value_list.size()) {
49 throw std::runtime_error(
"The size of keys and values does not match each other.");
55 std::unordered_set<IndexType, IndexHash> index_set;
57 for (std::size_t i = 0; i < key_list.size(); ++i) {
58 if (std::abs(value_list[i]) > std::numeric_limits<ValueType>::epsilon()) {
59 index_set.insert(key_list[i].begin(), key_list[i].end());
60 if (std::abs(value_list[i]) > abs_max_interaction) {
61 abs_max_interaction = std::abs(value_list[i]);
66 index_list_ = std::vector<IndexType>(index_set.begin(), index_set.end());
79 poly.reserve(key_list.size());
80 for (std::size_t i = 0; i < key_list.size(); ++i) {
81 if (std::abs(value_list[i]) > std::numeric_limits<ValueType>::epsilon()) {
82 std::vector<std::int32_t> int_key(key_list[i].size());
83 for (std::size_t j = 0; j < key_list[i].size(); ++j) {
86 std::sort(int_key.begin(), int_key.end());
87 int_key.erase(std::unique(int_key.begin(), int_key.end()), int_key.end());
88 poly[int_key] += value_list[i];
90 degree_ =
static_cast<std::int32_t
>(int_key.size());
96 for (
const auto &it: poly) {
104 return a.first < b.first;
128 if (std::abs(
key_value_list_[interaction_index].second) >= relevant_abs_min_interaction) {
129 abs_row_sum_interaction += std::abs(
key_value_list_[interaction_index].second);
156 return static_cast<std::int32_t
>(
index_list_.size());
167 const std::unordered_map<IndexType, std::int32_t, IndexHash> &
GetIndexMap()
const {
201 throw std::runtime_error(
"The size of variables is not equal to the system size");
207 if (variables[index] == 0) {
210 hot_count += variables[index];
231 std::unordered_map<IndexType, std::int32_t, IndexHash>
index_map_;
Definition binary_polynomial_model.hpp:27
const std::unordered_map< IndexType, std::int32_t, IndexHash > & GetIndexMap() const
Get the mapping from the index to the integer.
Definition binary_polynomial_model.hpp:167
const std::vector< std::vector< std::size_t > > & GetAdjacencyList() const
Get the adjacency list, which stored the integer index of the polynomial interaction specified by the...
Definition binary_polynomial_model.hpp:180
std::int32_t degree_
The degree of the interactions.
Definition binary_polynomial_model.hpp:222
const std::vector< IndexType > & GetIndexList() const
Get the index list of the polynomial interactions.
Definition binary_polynomial_model.hpp:161
std::int32_t GetSystemSize() const
Get the system size.
Definition binary_polynomial_model.hpp:155
std::vector< IndexType > index_list_
The index list of the interactions.
Definition binary_polynomial_model.hpp:228
const ValueType min_max_energy_difference_ratio_
The ratio of minimum and maximum energy difference set by 1e-08.
Definition binary_polynomial_model.hpp:248
utility::IndexType IndexType
The index type.
Definition binary_polynomial_model.hpp:37
ValueType CalculateEnergy(const std::vector< VariableType > &variables) const
Calculate energy corresponding to the variable configuration.
Definition binary_polynomial_model.hpp:199
ValueType estimated_max_energy_difference_
The estimated maximum energy difference.
Definition binary_polynomial_model.hpp:244
ValueType GetEstimatedMaxEnergyDifference() const
Get estimated maximum energy difference.
Definition binary_polynomial_model.hpp:192
std::vector< std::vector< std::size_t > > adjacency_list_
The adjacency list, which stored the integer index of the polynomial interaction specified by the sit...
Definition binary_polynomial_model.hpp:238
std::int8_t VariableType
The variable type, which here represents binary variables .
Definition binary_polynomial_model.hpp:43
ValueType GetEstimatedMinEnergyDifference() const
Get estimated minimum energy difference.
Definition binary_polynomial_model.hpp:186
std::int32_t system_size_
The system size.
Definition binary_polynomial_model.hpp:225
ValueType estimated_min_energy_difference_
The estimated minimum energy difference.
Definition binary_polynomial_model.hpp:241
std::vector< std::pair< std::vector< std::int32_t >, ValueType > > key_value_list_
The integer key and value list as pair.
Definition binary_polynomial_model.hpp:234
std::unordered_map< IndexType, std::int32_t, IndexHash > index_map_
The mapping from the index to the integer.
Definition binary_polynomial_model.hpp:231
BinaryPolynomialModel(const std::vector< std::vector< IndexType > > &key_list, const std::vector< ValueType > &value_list)
Definition binary_polynomial_model.hpp:45
std::int32_t GetDegree() const
Get the degree of the polynomial interactions.
Definition binary_polynomial_model.hpp:149
const std::vector< std::pair< std::vector< std::int32_t >, ValueType > > & GetKeyValueList() const
Get the integer key and value list as pair.
Definition binary_polynomial_model.hpp:173
FloatType ValueType
The value type.
Definition binary_polynomial_model.hpp:34
std::variant< std::int32_t, std::string, AnyTupleType > IndexType
The index type of binary variables.
Definition index_type.hpp:28
Definition algorithm.hpp:24
double FloatType
Note:
Definition compile_config.hpp:37
Hash struct of IndexType.
Definition pairhash.hpp:49
Hash struct of std::vector<T>.
Definition pairhash.hpp:92