container_weights = [1, 5, 9, 21, 35, 5, 3, 5, 10, 11] # Create a problem for the list of containers: problem = create_problem_for_container_weights(container_weights) # Submit problem to Azure Quantum using the ParallelTempering solver: from azure.quantum.optimization import ParallelTempering import time # Instantiate a solver to solve the problem. solver = ParallelTempering(workspace, timeout=100) # Optimize the problem print('Submitting problem...') start = time.time() result = solver.optimize(problem) timeElapsed = time.time() - start print(f'\nResult in {timeElapsed} seconds:\n{result}\n') # Print out a summary of the results: def print_result_summary(result): # Print a summary of the result ship_a_weight = 0 ship_b_weight = 0 for container in result['configuration']: container_assignment = result['configuration'][container] container_weight = container_weights[int(container)] ship = '' if container_assignment == 1: ship = 'A'
# This allows you to connect to the Workspace you've previously deployed in Azure. # Be sure to fill in the settings below which can be retrieved by running 'az quantum workspace show' in the terminal. from azure.quantum import Workspace # Copy the settings for your workspace below workspace = Workspace(subscription_id="", resource_group="", name="", location="") # Define the problem problem = Problem(name="My First Problem", problem_type=ProblemType.ising) terms = [ Term(c=-9, indices=[0]), Term(c=-3, indices=[1, 0]), Term(c=5, indices=[2, 0]), Term(c=9, indices=[2, 1]), Term(c=2, indices=[3, 0]), Term(c=-4, indices=[3, 1]), Term(c=4, indices=[3, 2]) ] problem.add_terms(terms=terms) # Create the solver solver = ParallelTempering(workspace, timeout=100) # Solve the problem result = solver.optimize(problem) print(result)