Source code for qlauncher.problems.optimization.jssp_utils.qiskit_scheduler

 1from typing import Literal
 2
 3from qlauncher import hampy
 4from qlauncher.hampy import Equation, Variable
 5
 6from .scheduler import JobShopScheduler, Task
 7
 8
[docs] 9class HamPyScheduler(JobShopScheduler): 10 equation: hampy.Equation 11 onehot: Literal['exact', 'quadratic'] 12 13 def __init__(self, job_dict: dict, max_time: int | None = None, onehot: Literal['exact', 'quadratic'] = 'exact'): 14 super().__init__(job_dict, max_time) 15 self.equation = hampy.Equation(self.n) 16 self.onehot = onehot 17 18 def _get_variable(self, task: Task, time: int) -> Variable: 19 return self.equation[self.assignment_index[(task, time)]] 20 21 def _add_expression(self, var1: Variable, var2: Variable, lagrange_factor: float) -> None: 22 self.equation += lagrange_factor * (var1 & var2) 23 24 def _add_expression_one_start(self, variables: list[int | Variable], lagrange_factor: float) -> None: 25 if self.onehot == 'exact': 26 self.equation += lagrange_factor * (~hampy.one_in_n(variables, self.n)) 27 elif self.onehot == 'quadratic': 28 self.equation += lagrange_factor * hampy.one_in_n(variables, self.n, quadratic=True) 29 30 def _add_variable(self, var: Variable, bias: float) -> None: 31 self.equation += var.to_equation() * bias 32 33 def _get_final(self) -> Equation: 34 return self.equation