22template<
typename FloatType,
typename RandType>
32 using SeedType =
typename RandType::result_type;
50 void SetSample(
const std::vector<VariableType> &sample) {
51 if (
static_cast<std::int32_t
>(sample.size()) !=
system_size_) {
52 throw std::runtime_error(
"The size of initial variables is not equal to the system size.");
55 if (!(sample[i] == 0 || sample[i] == 1)) {
56 throw std::runtime_error(
"The initial variables must be 0 or 1.");
66 void Flip(
const std::int32_t index) {
72 const std::int32_t total_zero_count =
zero_count_[index_key];
75 if (total_zero_count +
sample_[v_index] == 2 && v_index != index) {
84 const std::int32_t total_zero_count =
zero_count_[index_key];
87 if (total_zero_count +
sample_[v_index] == 1 && v_index != index) {
133 std::uniform_int_distribution<short> dist(0, 1);
134 RandType random_number_engine(seed);
136 sample_[i] = dist(random_number_engine);
143 std::int32_t count = 0;
Definition binary_polynomial_model.hpp:27
std::int8_t VariableType
The variable type, which here represents binary variables .
Definition binary_polynomial_model.hpp:43
FloatType ValueType
The value type.
Definition binary_polynomial_model.hpp:34
const std::int32_t system_size_
Definition binary_polynomial_sa_system.hpp:121
std::vector< VariableType > sample_
Definition binary_polynomial_sa_system.hpp:125
SASystem(const ModelType &model, const SeedType seed)
Constructor of SASystem for BinaryPolynomialModel.
Definition binary_polynomial_sa_system.hpp:41
void SetRandomConfiguration(const SeedType seed)
Set initial binary variables.
Definition binary_polynomial_sa_system.hpp:131
void SetBaseEnergyDifference()
Definition binary_polynomial_sa_system.hpp:153
void Flip(const std::int32_t index)
Flip a variable.
Definition binary_polynomial_sa_system.hpp:66
const std::vector< ValueType > & GetBaseEnergyDifference() const
Get the energy difference when flipped and sample as list.
Definition binary_polynomial_sa_system.hpp:109
typename RandType::result_type SeedType
The type of seed in random number engine.
Definition binary_polynomial_sa_system.hpp:32
const std::vector< std::vector< std::size_t > > & adjacency_list_
Definition binary_polynomial_sa_system.hpp:123
ValueType GetEnergyDifference(const std::int32_t index) const
Get the energy difference when flipped.
Definition binary_polynomial_sa_system.hpp:116
void SetSample(const std::vector< VariableType > &sample)
Definition binary_polynomial_sa_system.hpp:50
void SetZeroCount()
Definition binary_polynomial_sa_system.hpp:140
std::vector< std::int32_t > zero_count_
Definition binary_polynomial_sa_system.hpp:127
typename ModelType::ValueType ValueType
The value type.
Definition binary_polynomial_sa_system.hpp:36
typename ModelType::VariableType VariableType
The variable type, which here represents binary variables .
Definition binary_polynomial_sa_system.hpp:29
std::vector< ValueType > base_energy_difference_
Definition binary_polynomial_sa_system.hpp:126
const std::vector< std::pair< std::vector< std::int32_t >, ValueType > > & key_value_list_
Definition binary_polynomial_sa_system.hpp:122
graph::BinaryPolynomialModel< FloatType > ModelType
The model type, which must be BinaryPolynomialModel.
Definition binary_polynomial_sa_system.hpp:26
const std::vector< VariableType > & ExtractSample() const
Extract the sample.
Definition binary_polynomial_sa_system.hpp:103
std::int32_t GetSystemSize() const
Get the system size.
Definition binary_polynomial_sa_system.hpp:97
Definition binary_polynomial_model.hpp:24
Definition model/__init__.py:1
Definition binary_polynomial_sa_system.hpp:20
Definition algorithm.hpp:24