90#include <unordered_map>
91#include <unordered_set>
96#include <Eigen/Sparse>
110 template<
typename IndexType,
typename FloatType>
111 using Linear = std::unordered_map<IndexType, FloatType>;
118 template<
typename IndexType,
typename FloatType>
126 template<
typename IndexType,
typename FloatType>
127 using Adjacency = std::unordered_map<IndexType, std::unordered_map<IndexType, FloatType>>;
134 template<
typename IndexType>
135 using Sample = std::unordered_map<IndexType, int32_t>;
147 template<
typename IndexType,
typename FloatType,
typename DataType>
157 template<
typename T,
typename U>
158 using dispatch_t = std::enable_if_t<std::is_same_v<T, U>, std::nullptr_t>;
167 using DenseMatrix = Eigen::Matrix<FloatType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
169 using SpIter =
typename SparseMatrix::InnerIterator;
173 using Vector = Eigen::Matrix<FloatType, Eigen::Dynamic, 1>;
237 template<
typename T = DataType>
252 template<
typename T = DataType>
267 template<
typename T = DataType>
282 template<
typename T = DataType>
301 throw std::runtime_error(
"No self-loop (mat(i,i)) allowed" );
331 throw std::runtime_error(
"No self-loop (mat(i,i)) allowed" );
351 template<
typename T = DataType>
354 return _quadmat.block( 0,
N - 1,
N - 1, 1 ).maxCoeff();
362 template<
typename T = DataType>
365 return _quadmat.block( 0, 0,
N - 1,
N - 1 ).maxCoeff();
373 template<
typename T = DataType>
376 return _quadmat.block( 0,
N - 1,
N - 1, 1 ).minCoeff();
384 template<
typename T = DataType>
387 return _quadmat.block( 0, 0,
N - 1,
N - 1 ).minCoeff();
395 template<
typename T = DataType>
400 return mat.coeffs().maxCoeff();
408 template<
typename T = DataType>
413 return mat.coeffs().maxCoeff();
421 template<
typename T = DataType>
426 return mat.coeffs().minCoeff();
434 template<
typename T = DataType>
439 return mat.coeffs().minCoeff();
447 template<
typename T = DataType>
467 template<
typename T = DataType>
478 std::vector<Eigen::Triplet<FloatType>>
triplets;
487 if (
r >=
i &&
c >=
i ) {
489 }
else if (
r >=
i ) {
491 }
else if (
c >=
i ) {
508 template<
typename T = DataType>
528 template<
typename T = DataType>
538 std::vector<Eigen::Triplet<FloatType>>
triplets;
547 if (
r ==
i ||
c ==
i )
550 if (
r >
i &&
c >
i ) {
552 }
else if (
r >
i ) {
554 }
else if (
c >
i ) {
597 if (
_quadmat.col(
i ).squaredNorm() > std::numeric_limits<FloatType>::epsilon()
598 ||
_quadmat.row(
i ).squaredNorm() > std::numeric_limits<FloatType>::epsilon() ) {
619 template<
typename T = DataType>
625 std::unordered_set<IndexType>
labels;
627 for (
const auto &
kv : linear ) {
631 for (
const auto &
kv : quadratic ) {
648 for (
const auto &
kv : linear ) {
654 for (
const auto &
kv : quadratic ) {
655 std::pair<IndexType, IndexType>
key =
kv.first;
667 template<
typename T = DataType>
673 std::unordered_set<IndexType>
labels;
675 for (
const auto &
kv : linear ) {
679 for (
const auto &
kv : quadratic ) {
693 std::vector<Eigen::Triplet<FloatType>>
triplets;
698 for (
const auto &
kv : linear ) {
707 for (
const auto &
kv : quadratic ) {
728 template<
typename T = DataType>
748 throw std::runtime_error(
"the number of variables and dimension do not match." );
759 template<
typename T = DataType>
790 throw std::runtime_error(
"the number of variables and dimension do not match." );
842 if (
mat.rows() !=
mat.cols() ) {
843 throw std::runtime_error(
"matrix must be a square matrix" );
864 template<
typename T = DataType>
878 template<
typename T = DataType>
915 this->_quadmat =
mat;
936 template<
typename T = DataType>
975 template<
typename T = DataType>
1016 std::vector<Eigen::Triplet<FloatType>>
triplets;
1022 for (
int k = 0;
k <
_quadmat.outerSize();
k++ ) {
1025 size_t r =
it.row();
1026 size_t c =
it.col();
1055 template<
typename T = DataType>
1093 template<
typename T = DataType>
1106 for (
int k = 0;
k <
_quadmat.outerSize();
k++ ) {
1109 size_t r =
it.row();
1110 size_t c =
it.col();
1134 std::vector<Eigen::Triplet<FloatType>>
triplets;
1140 for (
int k = 0;
k <
_quadmat.outerSize();
k++ ) {
1143 size_t r =
it.row();
1144 size_t c =
it.col();
1202 const Eigen::Ref<const DenseMatrix> &
mat,
1221 const Eigen::Ref<const DenseMatrix> &
mat,
1389 for (
auto &
it : linear ) {
1414 for (
auto &
it : quadratic ) {
1492 throw std::runtime_error(
"scalar must not be zero" );
1526 const std::pair<FloatType, FloatType> &
bias_range = { 1.0, 1.0 },
1528 const std::pair<FloatType, FloatType> &
quadratic_range = { 1.0, 1.0 },
1534 std::pair<FloatType, FloatType>
q_range;
1547 std::vector<FloatType>
v_scale
1565 std::vector<std::pair<IndexType, IndexType>>
interactions;
1567 for (
const auto &
it : quadratic ) {
1568 if (
it.first.first ==
v ) {
1571 }
else if (
it.first.second ==
v ) {
1607 size_t i = _label_to_idx.at(
v );
1673 new_bqm.change_vartype( vartype );
1705 std::vector<FloatType>
en_vec;
1725 for (
const auto &
it : linear ) {
1726 Q[ std::make_pair(
it.first,
it.first ) ] =
it.second;
1728 return std::make_tuple( Q, offset );
1744 for (
auto &&
elem : Q ) {
1747 if (
key.first ==
key.second ) {
1750 quadratic[ std::make_pair(
key.first,
key.second ) ] =
value;
1769 return std::make_tuple( linear, quadratic, offset );
1816 template<
typename T = DataType>
1835 if (
typeid(
m_offset ) ==
typeid(
float ) ) {
1837 }
else if (
typeid(
m_offset ) ==
typeid(
double ) ) {
1840 throw std::runtime_error(
"FloatType must be float or double." );
1850 throw std::runtime_error(
"Variable type must be SPIN or BINARY." );
1857 output[
"type" ] =
"BinaryQuadraticModel";
1860 output[
"use_bytes" ] =
false;
1877 template<
typename T = DataType>
1897 if (
typeid(
m_offset ) ==
typeid(
float ) ) {
1899 }
else if (
typeid(
m_offset ) ==
typeid(
double ) ) {
1902 throw std::runtime_error(
"FloatType must be float or double." );
1912 throw std::runtime_error(
"Variable type must be SPIN or BINARY." );
1916 output[
"type" ] =
"BinaryQuadraticModel";
1919 output[
"use_bytes" ] =
false;
1935 std::vector<FloatType>
q_bias;
1936 std::vector<size_t>
q_head;
1937 std::vector<size_t>
q_tail;
1943 for (
int k = 0;
k <
_quadmat.outerSize();
k++ ) {
1945 size_t r =
it.row();
1946 size_t c =
it.col();
1974 template<
typename IndexType_serial = IndexType,
typename FloatType_serial = FloatType,
typename T = DataType>
1979 if (
type !=
"BinaryQuadraticModel" ) {
1980 throw std::runtime_error(
"Type must be \"BinaryQuadraticModel\".\n" );
1982 std::string version =
input[
"version" ][
"bqm_schema" ];
1983 if ( version !=
"3.0.0-dense" ) {
1984 throw std::runtime_error(
"bqm_schema must be 3.0.0-dense.\n" );
1995 throw std::runtime_error(
"variable_type must be SPIN or BINARY." );
1999 std::vector<IndexType_serial>
variables =
input[
"variable_labels" ];
2000 std::vector<FloatType_serial>
biases =
input[
"biases" ];
2018 template<
typename IndexType_serial = IndexType,
typename FloatType_serial = FloatType,
typename T = DataType>
2023 if (
type !=
"BinaryQuadraticModel" ) {
2024 throw std::runtime_error(
"Type must be \"BinaryQuadraticModel\".\n" );
2026 std::string version =
input[
"version" ][
"bqm_schema" ];
2027 if ( version !=
"3.0.0" ) {
2028 throw std::runtime_error(
"bqm_schema must be 3.0.0.\n" );
2039 throw std::runtime_error(
"variable_type must be SPIN or BINARY." );
2043 std::vector<IndexType_serial>
variables =
input[
"variable_labels" ];
2046 std::vector<FloatType_serial>
l_bias =
input[
"linear_biases" ];
2047 std::vector<size_t>
q_head =
input[
"quadratic_head" ];
2048 std::vector<size_t>
q_tail =
input[
"quadratic_tail" ];
2049 std::vector<FloatType_serial>
q_bias =
input[
"quadratic_biases" ];
2052 std::vector<Eigen::Triplet<FloatType_serial>>
triplets;
2057 for (
size_t i = 0;
i <
l_bias.size();
i++ ) {
2062 for (
size_t i = 0;
i <
q_bias.size();
i++ ) {
Class for dense binary quadratic model.
Definition binary_quadratic_model.hpp:148
FloatType _max_quadratic(dispatch_t< T, Sparse >=nullptr) const
calculate maximum element in quadratic term for dense graph
Definition binary_quadratic_model.hpp:409
size_t get_num_variables() const
get the number of variables
Definition binary_quadratic_model.hpp:1268
void add_variables_from(const Linear< IndexType, FloatType > &linear)
Add variables and/or linear biases to a binary quadratic model.
Definition binary_quadratic_model.hpp:1388
FloatType & _mat(IndexType label_i)
get reference of _quadmat(i,i)
Definition binary_quadratic_model.hpp:311
bool contains(const IndexType &v) const
Return true if the variable contains v.
Definition binary_quadratic_model.hpp:1288
FloatType & _quadmat_get(size_t i, size_t j, dispatch_t< T, Sparse >=nullptr)
access elements for sparse matrix
Definition binary_quadratic_model.hpp:268
static BinaryQuadraticModel< IndexType, FloatType, DataType > from_ising(const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, FloatType offset=0.0)
Create a binary quadratic model from an Ising problem.
Definition binary_quadratic_model.hpp:1781
void add_interaction(const IndexType &u, const IndexType &v, const FloatType &bias)
Add an interaction and/or quadratic bias to a binary quadratic model.
Definition binary_quadratic_model.hpp:1401
static BinaryQuadraticModel< IndexType_serial, FloatType_serial, DataType > from_serializable(const json &input, dispatch_t< T, Sparse >=nullptr)
Create a BinaryQuadraticModel instance from a serializable object.
Definition binary_quadratic_model.hpp:2020
void _set_label_to_idx()
set _label_to_idx from _idx_to_label
Definition binary_quadratic_model.hpp:218
void fix_variables(const std::vector< std::pair< IndexType, int32_t > > &fixed)
Fix the value of the variables and remove it from a binary quadratic model.
Definition binary_quadratic_model.hpp:1586
BinaryQuadraticModel< IndexType, FloatType, DataType > change_vartype(const Vartype &vartype, bool inplace)
Create a binary quadratic model with the specified vartype.
Definition binary_quadratic_model.hpp:1668
void _binary_to_spin(dispatch_t< T, Dense >=nullptr)
change internal variable from QUBO to Ising ones for dense matrix The following conversion is applied...
Definition binary_quadratic_model.hpp:1056
Quadratic< IndexType, FloatType > _generate_quadratic(dispatch_t< T, Sparse >=nullptr) const
Definition binary_quadratic_model.hpp:879
std::vector< IndexType > _idx_to_label
vector for converting index to label the list is asssumed to be sorted
Definition binary_quadratic_model.hpp:196
FloatType _quadmat_get(size_t i, size_t j, dispatch_t< T, Dense >=nullptr) const
access elements for dense matrix
Definition binary_quadratic_model.hpp:253
FloatType _min_quadratic(dispatch_t< T, Sparse >=nullptr) const
calculate minimum element in quadratic term for dense graph
Definition binary_quadratic_model.hpp:435
void _initialize_quadmat(const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, dispatch_t< T, Dense >=nullptr)
initialize matrix with linear and quadratic dicts (for dense matrix)
Definition binary_quadratic_model.hpp:620
void normalize(const std::pair< FloatType, FloatType > &bias_range={ 1.0, 1.0 }, const bool use_quadratic_range=false, const std::pair< FloatType, FloatType > &quadratic_range={ 1.0, 1.0 }, const std::vector< IndexType > &ignored_variables={}, const std::vector< std::pair< IndexType, IndexType > > &ignored_interactions={}, const bool ignored_offset=false)
Normalizes the biases of the binary quadratic model such that they fall in the provided range(s),...
Definition binary_quadratic_model.hpp:1525
static BinaryQuadraticModel< IndexType_serial, FloatType_serial, DataType > from_serializable(const json &input, dispatch_t< T, Dense >=nullptr)
Create a BinaryQuadraticModel instance from a serializable object.
Definition binary_quadratic_model.hpp:1976
void _spin_to_binary(dispatch_t< T, Dense >=nullptr)
change internal variable from Ising to QUBO ones for dense matrix The following conversion is applied...
Definition binary_quadratic_model.hpp:937
void _delete_label_from_mat(IndexType label_i, dispatch_t< T, Sparse >=nullptr)
delete row and column that corresponds to existing label from _quadmat for sparse matrix
Definition binary_quadratic_model.hpp:529
FloatType _min_quadratic(dispatch_t< T, Dense >=nullptr) const
calculate minimum element in quadratic term for dense graph
Definition binary_quadratic_model.hpp:385
FloatType _min_linear(dispatch_t< T, Dense >=nullptr) const
calculate minimum element in linear term for dense graph
Definition binary_quadratic_model.hpp:374
void remove_variables_from(const std::vector< IndexType > &variables)
Remove specified variables and all of their interactions from a binary quadratic model.
Definition binary_quadratic_model.hpp:1433
void _initialize_quadmat(const DenseMatrix &mat, const std::vector< IndexType > &labels_vec, bool fix_format)
initialize matrix with matrix and labels the form of matrix is assumed to be the following two forms:
Definition binary_quadratic_model.hpp:834
Eigen::Matrix< FloatType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > DenseMatrix
Eigen Matrix if DataType is Dense , Matrix is equal to Eigen::Matrix if DataType is Sparse,...
Definition binary_quadratic_model.hpp:167
FloatType _mat(IndexType label_i, IndexType label_j) const
get reference of _quadmat(i,j)
Definition binary_quadratic_model.hpp:324
Matrix interaction_matrix() const
generate (Dense or Sparse) interaction matrix with given list of indices The generated matrix will be...
Definition binary_quadratic_model.hpp:1805
FloatType & _mat(IndexType label_i, IndexType label_j)
get reference of _quadmat(i,j)
Definition binary_quadratic_model.hpp:295
FloatType _min_linear(dispatch_t< T, Sparse >=nullptr) const
calculate minimum element in linear term for dense graph
Definition binary_quadratic_model.hpp:422
void _binary_to_spin(dispatch_t< T, Sparse >=nullptr)
change internal variable from QUBO to Ising ones for sparse matrix The following conversion is applie...
Definition binary_quadratic_model.hpp:1094
void _spin_to_binary(dispatch_t< T, Sparse >=nullptr)
change internal variable from Ising to QUBO ones for sparse matrix The following conversion is applie...
Definition binary_quadratic_model.hpp:976
nlohmann::json json
Definition binary_quadratic_model.hpp:1809
Vartype get_vartype() const
Get the vartype object.
Definition binary_quadratic_model.hpp:1346
std::unordered_map< IndexType, size_t > _label_to_idx
dict for converting label to index
Definition binary_quadratic_model.hpp:201
std::conditional_t< std::is_same_v< DataType, Dense >, DenseMatrix, SparseMatrix > Matrix
Definition binary_quadratic_model.hpp:171
FloatType _max_linear(dispatch_t< T, Dense >=nullptr) const
calculate maximum element in linear term for dense graph
Definition binary_quadratic_model.hpp:352
size_t length() const
Return the number of variables.
Definition binary_quadratic_model.hpp:1278
void _delete_label(IndexType label_i, bool force_delete=true)
delete label if label_i does not exist, this process is skipped.
Definition binary_quadratic_model.hpp:591
json to_serializable(dispatch_t< T, Dense >=nullptr) const
Convert the binary quadratic model to a dense-version serializable object.
Definition binary_quadratic_model.hpp:1817
const std::vector< IndexType > & get_variables() const
Get variables.
Definition binary_quadratic_model.hpp:1355
FloatType m_offset
The energy offset associated with the model.
Definition binary_quadratic_model.hpp:207
FloatType _mat(IndexType label_i) const
get reference of _quadmat(i,i)
Definition binary_quadratic_model.hpp:341
void remove_interaction(const IndexType &u, const IndexType &v)
Remove interaction of variables u, v from a binary quadratic model.
Definition binary_quadratic_model.hpp:1445
void scale(const FloatType &scalar, const std::vector< IndexType > &ignored_variables={}, const std::vector< std::pair< IndexType, IndexType > > &ignored_interactions={}, const bool ignored_offset=false)
Multiply by the specified scalar all the biases and offset of a binary quadratic model.
Definition binary_quadratic_model.hpp:1486
Eigen::Matrix< FloatType, Eigen::Dynamic, 1 > Vector
Definition binary_quadratic_model.hpp:173
BinaryQuadraticModel(const BinaryQuadraticModel &)=default
BinaryQuadraticModel(const Eigen::Ref< const DenseMatrix > &mat, const std::vector< IndexType > &labels_vec, const FloatType &offset, const Vartype vartype, bool fix_format=true)
BinaryQuadraticModel constructor (with matrix);.
Definition binary_quadratic_model.hpp:1201
std::vector< FloatType > energies(const std::vector< Sample< IndexType > > &samples_like) const
Determine the energies of the given samples.
Definition binary_quadratic_model.hpp:1704
static BinaryQuadraticModel< IndexType, FloatType, DataType > from_qubo(const Quadratic< IndexType, FloatType > &Q, FloatType offset=0.0)
Create a binary quadratic model from a QUBO model.
Definition binary_quadratic_model.hpp:1740
Quadratic< IndexType, FloatType > _generate_quadratic(dispatch_t< T, Dense >=nullptr) const
Definition binary_quadratic_model.hpp:865
FloatType _max_quadratic(dispatch_t< T, Dense >=nullptr) const
calculate maximum element in quadratic term for dense graph
Definition binary_quadratic_model.hpp:363
Eigen::SparseMatrix< FloatType, Eigen::RowMajor > SparseMatrix
Definition binary_quadratic_model.hpp:168
std::enable_if_t< std::is_same_v< T, U >, std::nullptr_t > dispatch_t
template type for dispatch used for SFINAE
Definition binary_quadratic_model.hpp:158
BinaryQuadraticModel(const SparseMatrix &mat, const std::vector< IndexType > &labels_vec, const Vartype vartype)
BinaryQuadraticModel constructor (with sparse matrix); this constructor is for developers.
Definition binary_quadratic_model.hpp:1257
void _insert_label_into_mat(IndexType label_i, dispatch_t< T, Dense >=nullptr)
insert row and column that corresponds to added label into _quadmat for dense matrix
Definition binary_quadratic_model.hpp:448
BinaryQuadraticModel(const Eigen::Ref< const DenseMatrix > &mat, const std::vector< IndexType > &labels_vec, const Vartype vartype, bool fix_format=true)
BinaryQuadraticModel constructor (with matrix);.
Definition binary_quadratic_model.hpp:1220
void add_offset(const FloatType &offset)
Add specified value to the offset of a binary quadratic model.
Definition binary_quadratic_model.hpp:1467
BinaryQuadraticModel(const SparseMatrix &mat, const std::vector< IndexType > &labels_vec, const FloatType &offset, const Vartype vartype)
BinaryQuadraticModel constructor (with sparse matrix); this constructor is for developers.
Definition binary_quadratic_model.hpp:1238
FloatType get_linear(IndexType label_i) const
Get the element of linear object.
Definition binary_quadratic_model.hpp:1301
void add_variable(const IndexType &v, const FloatType &bias)
Add variable v and/or its bias to a binary quadratic model.
Definition binary_quadratic_model.hpp:1377
Matrix _quadmat
quadratic dense-type matrix The stored matrix has the following triangular form:
Definition binary_quadratic_model.hpp:190
std::tuple< Linear< IndexType, FloatType >, Quadratic< IndexType, FloatType >, FloatType > to_ising()
Convert a binary quadratic model to Ising format.
Definition binary_quadratic_model.hpp:1762
FloatType _quadmat_get(size_t i, size_t j, dispatch_t< T, Sparse >=nullptr) const
access elements for sparse matrix
Definition binary_quadratic_model.hpp:283
void _initialize_quadmat(const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, dispatch_t< T, Sparse >=nullptr)
initialize matrix with linear and quadratic dicts (for sparse matrix)
Definition binary_quadratic_model.hpp:668
json to_serializable(dispatch_t< T, Sparse >=nullptr) const
Convert the binary quadratic model to a serializable object.
Definition binary_quadratic_model.hpp:1878
FloatType get_offset() const
Get the offset.
Definition binary_quadratic_model.hpp:1337
void _delete_label_from_mat(IndexType label_i, dispatch_t< T, Dense >=nullptr)
delete row and column that corresponds to existing label from _quadmat for dense matrix
Definition binary_quadratic_model.hpp:509
BinaryQuadraticModel< IndexType, FloatType, DataType > empty(Vartype vartype)
Create an empty BinaryQuadraticModel.
Definition binary_quadratic_model.hpp:1364
void _insert_label_into_mat(IndexType label_i, dispatch_t< T, Sparse >=nullptr)
insert row and column that corresponds to added label into _quadmat for sparse matrix
Definition binary_quadratic_model.hpp:468
typename SparseMatrix::InnerIterator SpIter
Definition binary_quadratic_model.hpp:169
FloatType _max_linear(dispatch_t< T, Sparse >=nullptr) const
calculate maximum element in linear term for dense graph
Definition binary_quadratic_model.hpp:396
BinaryQuadraticModel(const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, const Vartype vartype)
BinaryQuadraticModel constructor.
Definition binary_quadratic_model.hpp:1185
Vartype m_vartype
The model's type.
Definition binary_quadratic_model.hpp:213
Quadratic< IndexType, FloatType > get_quadratic() const
Get uadratic object.
Definition binary_quadratic_model.hpp:1328
Linear< IndexType, FloatType > _generate_linear() const
Definition binary_quadratic_model.hpp:853
void remove_offset()
Set the binary quadratic model's offset to zero.
Definition binary_quadratic_model.hpp:1474
std::tuple< Quadratic< IndexType, FloatType >, FloatType > to_qubo()
Convert a binary quadratic model to QUBO format.
Definition binary_quadratic_model.hpp:1718
void _add_new_label(IndexType label_i)
add new label if label_i already exists, this process is skipped.
Definition binary_quadratic_model.hpp:572
void remove_variable(const IndexType &v)
Remove variable v and all its interactions from a binary quadratic model.
Definition binary_quadratic_model.hpp:1424
void _initialize_quadmat(const SparseMatrix &mat, const std::vector< IndexType > &labels_vec)
initialize matrix with matrix and labels the form of matrix is assumed to be the following form:
Definition binary_quadratic_model.hpp:914
void fix_variable(const IndexType &v, const int32_t &value)
Fix the value of a variable and remove it from a binary quadratic model.
Definition binary_quadratic_model.hpp:1564
void flip_variable(const IndexType &v)
Flip variable v in a binary quadratic model.
Definition binary_quadratic_model.hpp:1597
FloatType energy(const Sample< IndexType > &sample) const
Determine the energy of the specified sample of a binary quadratic model.
Definition binary_quadratic_model.hpp:1686
Linear< IndexType, FloatType > get_linear() const
Get linear object.
Definition binary_quadratic_model.hpp:1310
void _add_triangular_elements(const DenseMatrix &mat, bool fix_format, dispatch_t< T, Sparse >=nullptr)
add non-diagonal elements to upper triangular components for sparse matrix
Definition binary_quadratic_model.hpp:760
void add_interactions_from(const Quadratic< IndexType, FloatType > &quadratic)
Add interactions and/or quadratic biases to a binary quadratic model.
Definition binary_quadratic_model.hpp:1413
void change_vartype(const Vartype &vartype)
**
Definition binary_quadratic_model.hpp:1649
BinaryQuadraticModel(const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, const FloatType &offset, const Vartype vartype)
BinaryQuadraticModel constructor.
Definition binary_quadratic_model.hpp:1167
void remove_interactions_from(const std::vector< std::pair< IndexType, IndexType > > &interactions)
Remove all specified interactions from the binary quadratic model.
Definition binary_quadratic_model.hpp:1456
FloatType & _quadmat_get(size_t i, size_t j, dispatch_t< T, Dense >=nullptr)
access elements for dense matrix
Definition binary_quadratic_model.hpp:238
void _add_triangular_elements(const DenseMatrix &mat, bool fix_format, dispatch_t< T, Dense >=nullptr)
add non-diagonal elements to upper triangular components for dense matrix
Definition binary_quadratic_model.hpp:729
FloatType get_quadratic(IndexType label_i, IndexType label_j) const
Get the element of quadratic object.
Definition binary_quadratic_model.hpp:1319
void declare_BQM(py::module &m, const std::string &name)
Definition main.hpp:41
Definition binary_polynomial_model.hpp:139
std::unordered_map< IndexType, std::unordered_map< IndexType, FloatType > > Adjacency
Type alias for adjacency list.
Definition binary_quadratic_model.hpp:127
std::unordered_map< IndexType, int32_t > Sample
Type alias for sample, which represents the spin or binary configurations.
Definition binary_polynomial_model.hpp:162
std::unordered_map< IndexType, FloatType > Linear
Type alias for linear bias.
Definition binary_quadratic_model.hpp:111
std::unordered_map< std::pair< IndexType, IndexType >, FloatType, pair_hash > Quadratic
Type alias for quadratic bias.
Definition binary_quadratic_model.hpp:119
Vartype
Enum class for representing problem type.
Definition vartypes.hpp:24
Definition binary_quadratic_model.hpp:137
Definition binary_quadratic_model.hpp:138
Hash function for std::unordered_map.
Definition hash.hpp:65