Source code for quantum_launcher.problems.problem_initialization.ec
1""" This module contains the EC class.""" 2importast 3fromcollectionsimportdefaultdict 4fromtypingimportList,Optional,Set 5importnetworkxasnx 6importmatplotlib.pyplotasplt 7 8fromquantum_launcher.baseimportProblem 9 10
[docs] 11classEC(Problem): 12""" 13 Class for exact cover problem. 14 15 The exact cover problem is a combinatorial optimization problem that involves finding a subset of a given set 16 of elements such that the subset covers all elements and the number of elements in the subset is minimized. 17 The class contains an instance of the problem, so it can be passed into Quantum Launcher. 18 19 Attributes: 20 onehot (str): The one-hot encoding used for the problem. 21 instance (any): The instance of the problem. 22 instance_name (str | None): The name of the instance. 23 instance_path (str): The path to the instance file. 24 25 """ 26 27def__init__(self,instance:List[Set[int]]=None,instance_name:str='unnamed')->None: 28super().__init__(instance=instance,instance_name=instance_name) 29 30@property 31defsetup(self)->dict: 32return{ 33'instance_name':self.instance_name 34} 35 36def_get_path(self)->str: 37returnf'{self.name}@{self.instance_name}' 38