cimod
C++ library for a binary (and polynomial) quadratic model.
vartypes.hpp
Go to the documentation of this file.
1 // Copyright 2022 Jij Inc.
2 
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 // http://www.apache.org/licenses/LICENSE-2.0
8 
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <iostream>
18 
19 namespace cimod {
24  enum class Vartype {
25  SPIN = 0,
26  BINARY,
27  NONE = -1,
28  };
29 
37  inline bool check_vartype( const int32_t &var, const Vartype &vartype ) {
38  if ( vartype == Vartype::SPIN ) {
39  if ( var == 1 || var == -1 ) {
40  return true;
41  } else {
42  std::cerr << "Spin variable must be +1 or -1." << std::endl;
43  return false;
44  }
45  } else if ( vartype == Vartype::BINARY ) {
46  if ( var == 1 || var == 0 ) {
47  return true;
48  } else {
49  std::cerr << "Binary variable must be 1 or 0." << std::endl;
50  return false;
51  }
52  } else {
53  std::cerr << "Unknown variable type." << std::endl;
54  return false;
55  }
56  }
57 } // namespace cimod
vartype
Definition: legacy/binary_quadratic_model.py:182
Definition: binary_polynomial_model.hpp:139
bool check_vartype(const int32_t &var, const Vartype &vartype)
Check that the variable has appropriate value.
Definition: vartypes.hpp:37
Vartype
Enum class for representing problem type.
Definition: vartypes.hpp:24