17#include <unordered_map>
18#include <unordered_set>
33 template<
class C_key,
class C_value,
class Hash>
36 if (
um.count(
key ) == 0 ) {
49 template<
typename IndexType>
51 if ( ( *key ).size() <= 1 ) {
53 }
else if ( ( *key ).size() == 2 ) {
54 if ( ( *
key )[ 0 ] == ( *
key )[ 1 ] ) {
62 throw std::runtime_error(
"Unknown vartype detected" );
64 }
else if ( ( *
key )[ 0 ] < ( *
key )[ 1 ] ) {
67 std::swap( ( *
key )[ 0 ], ( *
key )[ 1 ] );
71 std::sort( ( *key ).begin(), ( *key ).end() );
74 if ( ( *
key )[
i ] == ( *key )[
i - 1 ] ) {
75 std::swap( ( *
key )[
i ], ( *key ).back() );
78 std::swap( ( *
key )[
i ], ( *key ).back() );
84 ( *key ).erase( std::unique( ( *key ).begin(), ( *key ).end() ), ( *key ).end() );
87 throw std::runtime_error(
"Unknown vartype detected" );
101 throw std::runtime_error(
"Unknown vartype detected" );
109 template<
typename IntegerType>
113 if ( !(
v == -1 ||
v == +1 ) ) {
114 throw std::runtime_error(
"The initial variables must be -1 or +1" );
119 if ( !(
v == 0 ||
v == 1 ) ) {
120 throw std::runtime_error(
"The initial variables must be 0 or 1" );
124 throw std::runtime_error(
"Unknown vartype detected" );
132 throw std::runtime_error(
"Unknow vartype detected" );
void declare_BQM(py::module &m, const std::string &name)
Definition main.hpp:41
Definition binary_polynomial_model.hpp:139
void insert_or_assign(std::unordered_map< C_key, C_value, Hash > &um, const C_key &key, const C_value &val)
Insert or assign a element of unordered_map (for C++14 or C++11)
Definition utilities.hpp:34
void CheckVartypeNotNONE(const Vartype &vartype)
Check if the input vartype is not Vartype::NONE.
Definition utilities.hpp:130
void CheckVariables(const std::vector< IntegerType > &configurations, const Vartype &vartype)
Convert vartype from string to cimod::Vartype.
Definition utilities.hpp:110
void FormatPolynomialKey(std::vector< IndexType > *key, const Vartype &vartype)
Format the input key: for example, {2,1,1}-->{1,2} for BINARY variable and {2,1,1}-->{2} for SPIN var...
Definition utilities.hpp:50
cimod::Vartype ToCimodVartype(const std::string &vartype_str)
Convert vartype from string to cimod::Vartype.
Definition utilities.hpp:95
Vartype
Enum class for representing problem type.
Definition vartypes.hpp:24