kaiwu_community.solver package#
Module contents#
模块: solver
功能: 提供一系列基于cim/classical中的opitimizer进行求解的solver
- class kaiwu_community.solver.SimpleSolver(optimizer)#
基类:
SolverBase实现用Optimizer直接对QuboModel进行求解
- Examples:
>>> import kaiwu_community as kw >>> n = 10 >>> W = 5 >>> p = [i + 1 for i in range(n)] >>> w = [(i + 2) / 2 for i in range(n)] >>> x = kw.core.ndarray(n, 'x', kw.core.Binary) >>> qubo_model = kw.qubo.QuboModel() >>> qubo_model.set_objective(sum(x[i] * p[i] * (-1) for i in range(n))) >>> qubo_model.add_constraint(sum(x[i] * w[i] for i in range(n)) <= W, "c", penalty=10) >>> solver = kw.solver.SimpleSolver(kw.classical.BruteForceOptimizer()) >>> sol_dict, qubo_val = solver.solve_qubo(qubo_model) >>> unsatisfied_count, result_dict = qubo_model.verify_constraint(sol_dict) >>> unsatisfied_count 0
- Returns:
tuple: Result dictionary and Result dictionary.
dict: Result dictionary. The key is the variable name, and the value is the corresponding spin value.
float: qubo value.
- solve_qubo(qubo_model)#
求解QUBO
- Args:
qubo_model (QuboModel): QUBO模型
- Returns:
- tuple: 元组,包含求解结果信息
dict: 解字典
float: QUBO值