@@ -142,7 +142,7 @@ def preprocess(self, graph: BaseGraph, data: Data) -> Tuple[BaseGraph, Data]:
142142 pass
143143
144144 @abstractmethod
145- def create_problem (self , graph : BaseGraph , data : Data ):
145+ def create_problem (self , graph : BaseGraph , data : Data ) -> ProblemDef :
146146 """Create the optimization problem.
147147
148148 This method should define variables, constraints, and objectives according to the method's
@@ -157,7 +157,7 @@ def create_problem(self, graph: BaseGraph, data: Data):
157157 """
158158 pass
159159
160- def build (self , graph : BaseGraph , data : Data ) -> ProblemDef :
160+ def build (self , graph : BaseGraph , data : Optional [ Data ] = None ) -> ProblemDef :
161161 """Build the complete optimization problem.
162162
163163 The process involves:
@@ -175,6 +175,8 @@ def build(self, graph: BaseGraph, data: Data) -> ProblemDef:
175175 Raises:
176176 ValueError: If lambda_reg > 0 but no regularization variable name is provided.
177177 """
178+ if data is None :
179+ data = Data .empty ()
178180 self .processed_graph , self .processed_data = self .preprocess (graph , data )
179181 self .problem = self .create_problem (self .processed_graph , self .processed_data )
180182
@@ -502,7 +504,7 @@ def create_problem(self, graph: BaseGraph, data: Data):
502504 # is selected or not, to the edges in the original graph, using the selected_edges list that
503505 # contains the indexes of the edges in the original graph. The variable selected_edges contains
504506 # None for edges that are not selected in the original graph, those we ignore.
505- # --- Step 1: Filter out None entries ---
507+
506508 # Create a boolean mask that is True for valid indices (not None)
507509 valid_mask = np .array ([edge is not None for edge in selected_edges ])
508510
@@ -512,7 +514,7 @@ def create_problem(self, graph: BaseGraph, data: Data):
512514 # Extract the valid edge indices (they are already 0-indexed)
513515 valid_edges = np .array ([edge for edge in selected_edges if edge is not None ])
514516
515- # --- Step 2: Build the indicator matrix E ---
517+ # Build the indicator matrix E
516518 # m is the number of edges in the original graph
517519 m = graph .num_edges # Total number of rows in the target vector
518520
@@ -524,7 +526,7 @@ def create_problem(self, graph: BaseGraph, data: Data):
524526 # resulting in an indicator matrix E of shape (m, n_valid).
525527 E = (rows == valid_edges .reshape (1 , - 1 )).astype (int )
526528
527- # --- Step 3: Matrix multiplication to scatter the values ---
529+ # Matrix multiplication to scatter the values
528530 # Here the "@" operator multiplies the indicator matrix E with valid_vec.
529531 # Y is then a vector of shape (m, 1) with the values from vec mapped
530532 # to their corresponding positions in the original graph.
0 commit comments