File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 2323import numpy as np
2424import torch
2525
26- from ..core import Problem , SolutionBatch
26+ from ..core import Problem , Solution , SolutionBatch
2727from ..tools .misc import Real , Vector
2828from .searchalgorithm import SearchAlgorithm , SinglePopulationAlgorithmMixin
2929
@@ -231,10 +231,14 @@ def __init__(
231231
232232 # If `center_init` is not given, generate an initial solution
233233 # with the help of the problem object.
234+ # If it is given as a Solution, then clone the solution's values
235+ # as a PyTorch tensor.
234236 # Otherwise, use the given initial solution as the starting
235237 # point in the search space.
236238 if center_init is None :
237239 center_init = self ._problem .generate_values (1 )
240+ elif isinstance (center_init , Solution ):
241+ center_init = center_init .values .clone ()
238242
239243 # Store the center
240244 self .m = self ._problem .make_tensor (center_init )
You can’t perform that action at this time.
0 commit comments