kaiwu.hobo package#
Module contents#
Module: hobo
Function: HOBO modeling tool
- class kaiwu.hobo.HoboModel(objective=None)#
Bases:
BinaryModelHOBO model class that supports adding constraints
- reduce(predefined_pairs=None)#
Reduce the order of high-order expressions in the HOBO Model (to second-order)
- Args:
predefined_pairs (list): Predefined list of variable pairs to merge, formatted as [(var1, var2), …]
- Returns:
QuboModel: QuboModel after order reduction
- add_constraint(constraint_in, name=None, constr_type: Literal['soft', 'hard'] = 'hard', penalty=None)#
Add constraint terms (supports single or multiple constraints)
- Args:
constraint_in (ConstraintDefinition or iterable): The constraint expression or its iterable object.
name (str or list, optional): Constraint name or list of names; automatically named by default.
constr_type(str, optional): Constraint type, can be set to “soft” or “hard”, defaults to “hard”
penalty (float): Default penalty coefficient
- compile_constraints()#
Convert constraint terms to Expression according to different styles. For inequality constraints, the penalty function method is currently supported.
- get_constraints_expr_list()#
Get all current constraints.
- Returns:
List of all constraints.
- get_value(solution_dict)#
Substitute variable values into QUBO variables based on the result dictionary.
- Args:
solution_dict (dict): Result dictionary generated by get_sol_dict.
- Returns:
float: Value obtained after substituting into the QUBO
- initialize_penalties()#
Automatically initialize all penalty coefficients
- set_constraint_handler(constraint_handler)#
Set the unconstrained conversion method for constraint terms
- Args:
constraint_handler: Class for setting the unconstrained representation method of constraint terms
- set_objective(objective)#
Set the objective function
- Args:
objective (BinaryExpression): Objective function expression
- verify_constraint(solution_dict, constr_type: Literal['soft', 'hard'] = 'hard')#
Verify whether constraints are satisfied
- Args:
solution_dict (dict): QUBO model solution dictionary
constr_type(str, optional): Constraint type, can be set to “soft” or “hard”, defaults to “hard”
- Returns:
- tuple: Constraint satisfaction information
int: Number of unsatisfied constraints
dict: Dictionary containing constraint values