22template<
typename FloatType>
24 static_assert(std::is_floating_point<FloatType>::value,
25 "Template parameter FloatType must be floating point type");
42 std::vector<ValueType> &value_list) {
47 std::unordered_set<IndexType, IndexHash> index_set;
49 for (std::size_t i = 0; i < key_list.size(); ++i) {
50 if (std::abs(value_list[i]) > std::numeric_limits<ValueType>::epsilon()) {
51 std::sort(key_list[i].begin(), key_list[i].end());
52 const std::int32_t key_size =
static_cast<std::int32_t
>(key_list[i].size()) - 1;
53 for (std::int32_t j = key_size; j >= 1; --j) {
54 if (key_list[i][j] == key_list[i][j - 1]) {
55 std::swap(key_list[i][j], key_list[i].back());
56 key_list[i].pop_back();
58 std::swap(key_list[i][j], key_list[i].back());
59 key_list[i].pop_back();
62 index_set.insert(key_list[i].begin(), key_list[i].end());
63 if (std::abs(value_list[i]) > abs_max_interaction) {
64 abs_max_interaction = std::abs(value_list[i]);
69 index_list_ = std::vector<IndexType>(index_set.begin(), index_set.end());
82 poly.reserve(key_list.size());
83 for (std::size_t i = 0; i < key_list.size(); ++i) {
84 if (std::abs(value_list[i]) > std::numeric_limits<ValueType>::epsilon()) {
85 std::vector<std::int32_t> int_key(key_list[i].size());
86 for (std::size_t j = 0; j < key_list[i].size(); ++j) {
89 poly[int_key] += value_list[i];
91 degree_ =
static_cast<std::int32_t
>(int_key.size());
97 for (
const auto &it: poly) {
105 return a.first < b.first;
129 if (std::abs(
key_value_list_[interaction_index].second) >= relevant_abs_min_interaction) {
130 abs_row_sum_interaction += std::abs(
key_value_list_[interaction_index].second);
157 return static_cast<std::int32_t
>(
index_list_.size());
168 const std::unordered_map<IndexType, std::int32_t, IndexHash> &
GetIndexMap()
const {
202 throw std::runtime_error(
"The size of variables is not equal to the system size");
208 prod *= variables[index];
227 std::unordered_map<IndexType, std::int32_t, IndexHash>
index_map_;
const ValueType min_max_energy_difference_ratio_
The ratio of minimum and maximum energy difference set by 1e-08.
Definition ising_polynomial_model.hpp:244
std::vector< std::pair< std::vector< std::int32_t >, ValueType > > key_value_list_
The integer key and value list as pair.
Definition ising_polynomial_model.hpp:230
std::int32_t GetSystemSize() const
Get the system size.
Definition ising_polynomial_model.hpp:156
ValueType estimated_max_energy_difference_
The estimated maximum energy difference.
Definition ising_polynomial_model.hpp:240
ValueType GetEstimatedMaxEnergyDifference() const
Get estimated maximum energy difference.
Definition ising_polynomial_model.hpp:193
const std::vector< IndexType > & GetIndexList() const
Get the index list of the polynomial interactions.
Definition ising_polynomial_model.hpp:162
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 ising_polynomial_model.hpp:181
const std::unordered_map< IndexType, std::int32_t, IndexHash > & GetIndexMap() const
Get the mapping from the index to the integer.
Definition ising_polynomial_model.hpp:168
IsingPolynomialModel(std::vector< std::vector< IndexType > > &key_list, std::vector< ValueType > &value_list)
Definition ising_polynomial_model.hpp:41
std::int32_t GetDegree() const
Get the degree of the polynomial interactions.
Definition ising_polynomial_model.hpp:150
utility::IndexHash IndexHash
The hash for IndexType.
Definition ising_polynomial_model.hpp:35
std::vector< IndexType > index_list_
The index list of the interactions.
Definition ising_polynomial_model.hpp:224
utility::IndexType IndexType
The index type.
Definition ising_polynomial_model.hpp:32
std::int8_t VariableType
The variable type, which here represents binary variables .
Definition ising_polynomial_model.hpp:38
ValueType estimated_min_energy_difference_
The estimated minimum energy difference.
Definition ising_polynomial_model.hpp:237
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 ising_polynomial_model.hpp:234
const std::vector< std::pair< std::vector< std::int32_t >, ValueType > > & GetKeyValueList() const
Get the integer key and value list as pair.
Definition ising_polynomial_model.hpp:174
ValueType GetEstimatedMinEnergyDifference() const
Get estimated minimum energy difference.
Definition ising_polynomial_model.hpp:187
FloatType ValueType
The value type.
Definition ising_polynomial_model.hpp:29
std::int32_t system_size_
The system size.
Definition ising_polynomial_model.hpp:221
std::int32_t degree_
The degree of the interactions.
Definition ising_polynomial_model.hpp:218
ValueType CalculateEnergy(const std::vector< VariableType > &variables) const
Calculate energy corresponding to the variable configuration.
Definition ising_polynomial_model.hpp:200
std::unordered_map< IndexType, std::int32_t, IndexHash > index_map_
The mapping from the index to the integer.
Definition ising_polynomial_model.hpp:227
Definition binary_polynomial_model.hpp:24
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