Solvers Base Classes
- class discopygal.solvers.Solver.Solver(bounding_margin_width_factor=-1)
Bases:
object
The main solver class. Every implemented solver should derive from it.
- Parameters:
- disable_verbose()
Call this method to disable verbose running for the solver
- classmethod from_arguments(d)
Get a dictionary of arguments and return a solver. Should be overridded by solvers.
- Parameters:
d (
dict
) – arguments dict- Returns:
solver object with arguments as in dict d
- Return type:
Deprecated since version 1.0.3: Use
init_default_solver()
orinit_solver()
instead
- abstract static get_arguments()
Return a list of arguments and their description, defaults and types. Can be used by a GUI to generate fields dynamically. Should be overridded by solvers.
- Returns:
arguments dict
- Return type:
dict
- get_arrangement()
Return an arrangement (if applicable). Can be overridded by solvers.
- Returns:
arrengement
- Return type:
- get_bounding_box_graph()
Return the graph of the bounding box the solver calculated for the loaded scene (if used one)
- Returns:
bounding_box_graph
- Return type:
networkx.Graph
or None
- get_graph()
Return a graph (if applicable). Can be overridded by solvers.
- Returns:
graph whose vertices are Point_2 or Point_d
- Return type:
networkx.Graph
or None
- classmethod init_default_solver()
Create a solver with default parameters of given solver class
- classmethod init_solver(**args)
- Create a solver of given solver class with parameters given in args (as keyword arguments)Each argument is casted according to it’s type in
get_arguments()
.Also for every argument that isn’t given in args, the default value is set.
- load_scene(scene: Scene)
Load a scene into the solver. Derived solvers can override this method to also add some sort of pre-processing to the scene
- Parameters:
scene (
Scene
) – scene to load
- log(text, **kwargs)
- Print a log to screen and to gui is enabledPrints only if set to be verbose (automatically done in solver_viewer)
- Parameters:
text – text to print
kwargs – more key-word arguments to pass to
print()
builtin function
- set_verbose(writer=None)
Call this method to set a verbose solver, i.e. print while solving.
- solve()
Based on the start and end locations of each robot, solve the scene (i.e. return paths for all the robots)
The base solver returns for each robot a simple path of its start and end position - which for most scenes might not be valid!
- Returns:
path collection of motion planning
- Return type:
- update_arguments(args: dict)
Update the arguments solver
- Parameters:
args (
dict
) – arguments dict
- class discopygal.solvers.SamplingSolver.SamplingSolver(nearest_neighbors=None, metric=None, sampler=None, bounding_margin_width_factor=2)
Bases:
Solver
A Base Solver class for sampled based solvers (builds a roadmap from sampled points and searches on it).
- Parameters:
nearest_neighbors (
NearestNeighbors
orNone
) – a nearest neighbors algorithm. if None then use sklearn implementationmetric (
Metric
orNone
) – a metric for weighing edges, can be different then the nearest_neighbors metric! If None then use euclidean metricsampler (
Sampler
) – sampling algorithm/method. if None then use uniform sampling
- abstract build_roadmap()
Constructs the roadmap of points in the configuration space which a path will be searched on to find a solution. Every sampling solver should implement how to build the roadmap.
- Returns:
The built roadmap. Each node represents a point in configuration space (dimension = 2*robots_num)
- Return type:
nx.Graph
- collision_free(p, q)
Get two points in the configuration space and decide if they can be connected
- get_graph()
Return a graph (if applicable). Can be overridded by solvers.
- load_scene(scene: Scene)
Load a scene into the solver. Also build the roadmap.
- Parameters:
scene (
Scene
) – scene to load
- sample_free()
Sample a free random point in configuration space Dimension is 2*robots_num
- Returns:
Sampled free point
- Return type:
- search_path_on_roadmap()
After already constructed a roadmap, plan a path for each robot (i.e. return paths for all the robots) If failed to find a path for each robot return an empty
PathCollection
(PathCollection()
)The search method of the basic class
SamplingSolver
is simply finding the shortest path according to the weights of the edges (the weight attribute should be calledweight
)- Returns:
Path collection of motion planning (path for each robot)
- Return type:
- solve()
Based on the start and end locations of each robot, solve the scene (i.e. return paths for all the robots)
- Returns:
path collection of motion planning
- Return type: