Solvers Base Classes
- class discopygal.solvers_infra.Solver.Solver(bounding_margin_width_factor=-1, **kwargs)
Bases:
object
The main solver class. Every implemented solver should derive from it.
- Parameters:
- abstract _solve()
The actual motion planning algorithm.
This is the function that every solver must override and implement it’s algorithm.May assume that the scene if already loaded and is atself.scene
.- Returns:
path collection of motion planning
- Return type:
- analyze_solution(path_collection)
- Print info about the found solution - path_collection.Prints: distance of path of each robot, total distance of all paths (sum of all paths) and makespan
- Parameters:
path_collection (
PathCollection
) – The path_collection to print info for
- 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
- classmethod 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 fromget_arguments()
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
- return_arguments()
Return a dict of the solver’s arguments with there value
- Return type:
dict
- set_verbose(writer=None)
Call this method to set a verbose solver, i.e. print while solving.
- solve(scene=None)
- Based on the start and end locations of each robot, solve the scene(i.e. return paths for all the robots)Do not override this function! (override
_solve()
)This function is the exported function that should be used outside of the solver class to make the solver object to solve.If parameterscene
is given it first loads it withload_scene()
and then solves it.Otherwise solves again the already pre-loaded scene (if no scene was already loaded it fails)- Parameters:
scene (
Scene
) – scene to solve- Returns:
path collection of motion planning
- Return type:
- update_arguments(args: dict)
Update the arguments solver
- Parameters:
args (
dict
) – arguments dict
- class discopygal.solvers_infra.SamplingSolver.SamplingSolver(nearest_neighbors_class=None, metric=None, sampler=None, **kwargs)
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:
- get_graph()
Return a graph (if applicable). Can be overridded by solvers.
- init_roadmap(scene=None, metric=None, nearest_neighbors_class=None, sampler=None, robots=None, is_directed=False)
A wrapper function to easily initialize a new empty roadmap with the given attributes or, if not given, with the solvers attributes
- Returns:
Newly created roadmap
- 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: