Solvers Base Classes

class discopygal.solvers.Obstacle(data)

Bases: object

Abstract class that represents the notion of an obstacle in the scene. The obstacle has some geometry.

Parameters:

data (object) – Any metadata appended to the obstacle (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.ObstacleDisc(location, radius, data=None)

Bases: Obstacle

Disc obstacle in the scene. Its geometry is given as a location and radius.

Parameters:
  • location (Point_2) – Disc obstacle location point, as a CGAL point

  • radius (FT) – Disc radius, as a CGAL field type

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.ObstaclePolygon(poly, data=None)

Bases: Obstacle

Polygon obstacle in the scene. Its geometry is given as a polygon.

Parameters:

poly (Polygon2) – Polygon obstacle geometry, as a CGAL polygon

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.Path(points)

Bases: object

Representation of the path a single robot does

Parameters:

points (list<PathPoint>) – points along the path

calculate_length(metric: Metric)

Return the total length of the path (sum of length between each two points)

Parameters:

metric (Metric) – The metric to use for calculating the distance between two points

Returns:

The length of the path

Return type:

FT

static path_from_points(points)

Create a Path object from points as Point_2 or Point_d (not as PathPoint) Converts each point to PathPoint (with default constructor)

Parameters:

points (list<Point_2 or Point_d>) – List of points

Returns:

Path object

Return type:

Path

class discopygal.solvers.PathCollection(paths=None)

Bases: object

Collection of the paths of all the robots in the scene. This is the objects that is returned by a solver.

Parameters:

paths (dict<Robot, Path>) – collection of paths

add_robot_path(robot, path)

Add a robot’s path to the collection

Parameters:
  • robot (Robot) – the robot we add

  • path (Path) – robot’s path

class discopygal.solvers.PathPoint(location, data=None)

Bases: object

A single point in the path (of some robot). Has a 2D location and additional data

Parameters:
  • location (Point_2) – location of point

  • data (dict) – attached data to point

class discopygal.solvers.Robot(start, end, data=None)

Bases: object

Abstact class that represents the notion of a robot in a scene. Reference point is always the origin of the given geometry.

Parameters:
  • start (Point_2) – The start location of the robot, as a CGAL point (unless stated otherwise)

  • end (Point_2) – The end location of the robot, as a CGAL point (unless stated otherwise)

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.RobotDisc(radius, start, end, data=None)

Bases: Robot

A disc robot. Its geometry is defined by its radius.

Parameters:
  • radius (FT) – The radius of the disc robot, as a CGAL field type

  • start (Point_2) – The start location of the robot, as a CGAL point

  • end (Point_2) – The end location of the robot, as a CGAL point

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.RobotPolygon(poly, start, end, data=None)

Bases: Robot

A polygonal robot. Its geometry is given as a CGAL 2D polygon.

Parameters:
  • poly (Polygon2) – The geometry of the robot, as a CGAL 2D Polygon

  • start (Point_2) – The start location of the robot, as a CGAL point

  • end (Point_2) – The end location of the robot, as a CGAL point

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.RobotRod(length, start, end, data=None)

Bases: Robot

A rod robot. Its geometry is defined by its length.

Parameters:
  • length (FT) – The length of the rod, as a CGAL field type

  • start ((Point_2, FT)) – The start location and angle of the robot, as a tuple of CGAL point and angle

  • end ((Point_2, FT)) – The end location and angle of the robot, as a tuple of CGAL point and angle

  • data (object) – Any metadata appended to the robot (could be None)

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.Scene(obstacles=None, robots=None, metadata=None)

Bases: object

The notion of “scene” in DiscoPygal, which is the setting where we conduct motion planning. A scene has robots that can move inside it, and obstacles. Also the scene can have any metadata, saved as a dictionary.

Parameters:
  • obstacles (list<Obstacle>) – list of obstacles

  • robots (list<Robot>) – list of robots

  • metadata (dict) – dict with metadata on the scene

add_obstacle(obstacle)

Add a obstacle to the scene

Parameters:

obstacle (Obstacle) – obstacle to add

add_robot(robot)

Add a robot to the scene

Parameters:

robot (Robot) – Robot to add

calc_max_robot_size()

Return the size of the largest robot in the scene For RobotDisc the is it’s diameter For RobotRod the size is it’s length

static from_dict(d)

Load json dict to object

Parameters:

d (dict) – dict representing json export

Returns:

A scene object build from the given dict

Return type:

Scene

remove_obstacle(obstacle)

Remove a obstacle from the scene

Parameters:

obstacle (Obstacle) – obstacle to remove

remove_robot(robot)

Remove a robot from the scene

Parameters:

robot (Robot) – Robot to remove

to_dict()

Convert current object to json dict

Returns:

dict representing json export

Return type:

dict

class discopygal.solvers.SceneDrawer(gui, scene)

Bases: object

Object for lookup tables and drawing scene objects

Parameters:
clear_scene()

Clear (only) the DiscoPygal scene objects from the GUI

deselect_entity(entity)
draw_obstacle(obstacle, color_select=False)

Draw a single obstacle to the scene You can affect its color by having the data of the obstacle as a dict, and having “color” value (with a string confining to gui.gui.color).

Parameters:
  • obstacle (Obstacle) – obstacle to draw

  • color_select (bool) – if true override color to select color

draw_robot(robot, color_select=False)

Draw a single robot to the scene You can affect its color by having the data of the robot as a dict, and having “color” value (with a string confining to gui.gui.color).

Parameters:
  • obstacle (Robot) – robot to draw

  • color_select (bool) – if true override color to select color

draw_scene()

Draw the scene to the selected GUI

select_entity(entity)
discopygal.solvers.load_object_from_dict(d)

Load a seriallized object from a dict In order for this to work, the dict should have a “__class__” property, which is equal to the exact python name of the class

Parameters:

d (dict) – dict describing an object

Returns:

the serialized object

Return type:

object

class discopygal.solvers.Solver.Solver(bounding_margin_width_factor=-1)

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

disable_verbose()

Call this method to disable verbose running for the solver

static 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() 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:

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

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()

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:

PathCollection

update_arguments(args: dict)

Update the arguments solver

Parameters:

args (dict) – arguments dict