Solvers Base Classes

class discopygal.solvers.Solver.Solver(bounding_margin_width_factor=-1, **kwargs)

Bases: object

The main solver class. Every implemented solver should derive from it.

Parameters:
  • bounding_margin_width_factor (FT) –

    The factor which by to increase the solver’s bounding box margin
    Set 0 for a tight bounding box
    Set -1 for no bounding box (default)

  • scene (Scene) – The loaded scene object the solver will solve

  • verbose (bool) – Should solver print logs during solving process

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 at self.scene.
Returns:

path collection of motion planning

Return type:

PathCollection

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:

Solver

Deprecated since version 1.0.3: Use init_default_solver() or init_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:

Arrangement_2

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 from get_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 enabled
Prints 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(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 parameter scene is given it first loads it with load_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:

PathCollection

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, **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 or None) – a nearest neighbors algorithm. if None then use sklearn implementation

  • metric (Metric or None) – a metric for weighing edges, can be different then the nearest_neighbors metric! If None then use euclidean metric

  • sampler (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

Parameters:
Returns:

Can they be connected

Return type:

bool

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

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:

Point_d

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 called weight)

Returns:

Path collection of motion planning (path for each robot)

Return type:

PathCollection

TensorSolver