openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
k_local.hpp
Go to the documentation of this file.
1// Copyright 2023 Jij Inc.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5
6// http://www.apache.org/licenses/LICENSE-2.0
7
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#pragma once
15
16#include <random>
17
20
21namespace openjij {
22namespace updater {
23
24template <typename System> struct KLocal;
25
29template <typename GraphType>
30struct KLocal<system::KLocalPolynomial<GraphType>> {
31
33 using FloatType = typename GraphType::value_type;
34
40 template <typename RandomNumberEngine>
41 inline static void
43 RandomNumberEngine &random_number_engine,
44 const utility::ClassicalUpdaterParameter &parameter) {
45 auto urd = std::uniform_real_distribution<>(0, 1.0);
46
47 int64_t count = 0;
48
49 for (const auto &index_binary : system.get_active_binaries()) {
50 const FloatType dE_s = system.dE_single(index_binary);
51 if (system.count_call_updater % system.rate_call_k_local == 0 &&
52 dE_s == 0.0) {
53 for (const auto &index_key : system.get_adj(index_binary)) {
54 if (system.GetPolyValue(index_key) >= 0.0) {
55 break;
56 }
57 const FloatType dE_i = system.dE_k_local(index_key);
58 if (dE_i <= 0.0 ||
59 std::exp(-parameter.beta * dE_i) > urd(random_number_engine)) {
60 system.update_system_k_local();
61 } else {
62 system.reset_virtual_system();
63 }
64 }
65 } else if (dE_s <= 0.0 ||
66 std::exp(-parameter.beta * dE_s) > urd(random_number_engine)) {
67 system.update_system_single(index_binary);
68 }
69
70 if (dE_s >= 0.0) {
71 count++;
72 }
73 }
74
75 if (count == static_cast<int64_t>(system.get_active_binaries().size()) &&
76 system.count_call_updater % system.rate_call_k_local != 0) {
77 for (const auto &index_binary : system.get_active_binaries()) {
78 const FloatType dE_s = system.dE_single(index_binary);
79 if (dE_s == 0.0 && system.binaries[index_binary] == 1) {
80 system.update_system_single(index_binary);
81 }
82 }
83 for (int64_t index_key = 0; index_key < system.GetNumInteractions();
84 index_key++) {
85 if (system.GetPolyValue(index_key) >= 0.0) {
86 break;
87 }
88 if (system.GetZeroCount(index_key) != 0) {
89 const FloatType dE_i = system.dE_k_local(index_key);
90 if (dE_i < 0.0) {
91 system.update_system_k_local();
92 } else {
93 system.reset_virtual_system();
94 }
95 }
96 }
97 }
98
99 system.count_call_updater++;
100 }
101};
102
103} // namespace updater
104} // namespace openjij
KLocalPolynomial class, which is a system to solve higher order unconstrained binary optimization (HU...
Definition k_local_polynomial.hpp:32
Definition algorithm.hpp:24
typename GraphType::value_type FloatType
floating point type
Definition k_local.hpp:33
static void update(system::KLocalPolynomial< GraphType > &system, RandomNumberEngine &random_number_engine, const utility::ClassicalUpdaterParameter &parameter)
Operate k-local update for HUBO.
Definition k_local.hpp:42
Definition k_local.hpp:24
updater parameter for classical ising system
Definition schedule_list.hpp:37
double beta
inverse temperature
Definition schedule_list.hpp:46