def by_amplify(qubits, model, token, timeout=5000): client = FixstarsClient() client.token = token client.parameters.timeout = timeout solver = Solver(client) solver.filter_solution = False result = solver.solve(model) values = result[0].values q_values = decode_solution(qubits, values, 1) return np.where(np.array(q_values) == 1)[1]
def solve(self, c_weight: float = 3, timeout: int = 1000, num_unit_step: int = 10) -> Setlist: """ Args: c_weight (float): 時間制約の強さ timeout (int, optional): Fixstars AE のタイムアウト[ms] (デフォルト: 10000) num_unit_step (int, optional): Fixstars AE のステップ数 (デフォルト: 10) Returns: Setlist: セットリスト """ self.q = gen_symbols(BinaryPoly, self.num_tracks) energy_function = self.energy(c_weight) model = BinaryQuadraticModel(energy_function) fixstars_client = FixstarsClient() fixstars_client.token = os.environ.get("FIXSTARS_API_TOKEN") fixstars_client.parameters.timeout = timeout fixstars_client.parameters.num_unit_steps = num_unit_step amplify_solver = Solver(fixstars_client) amplify_solver.filter_solution = False result = amplify_solver.solve(model) q_values = decode_solution(self.q, result[0].values) tracks = [self.candidates[i] for i, v in enumerate(q_values) if v == 1] total_time = 0 user_scores = np.zeros(self.num_users) for track in tracks: user_scores += np.array(track.p) total_time += track.duration_ms return Setlist(tracks=tracks, scores=user_scores.tolist(), score_sum=user_scores.sum(), score_avg=user_scores.mean(), score_var=user_scores.var(), total_time=total_time)