Skip to content

Solvers

Solvers choose a binding at each decision when a problem is tested with GymProblem.testing_run.

gympn.solvers.BaseSolver

Bases: ABC

Base class for solvers. Solvers are used to select a binding from a list of bindings according to a policy.

solve abstractmethod

solve(observable_net, bindings: List) -> Any

Select a binding from a list of bindings according to a policy.

Parameters

Parameters:

Name Type Description Default
observable_net

the GymProblem object representing the (observable) petri net.

required
bindings List

list of possible bindings to choose from.

required

gympn.solvers.GymSolver

Bases: BaseSolver

Gym solvers are used to select a binding from a list of bindings according to a traind DRL policy. The policy is a neural network that takes as input the current state of the observable net and returns a binding. The weights of the policy are loaded from a file.

Attributes:

Name Type Description
policy_model Module

The neural network model that represents the trained policy.

gympn.solvers.HeuristicSolver

Bases: BaseSolver

Heuristic solver that can choose among REAL action bindings and, when exposed, a postpone pseudo-binding.

Heuristic return formats supported: - 'postpone' - int (index into the provided 'bindings' list) - tuple (a binding tuple that must be present in 'bindings') - dict {action_id: token_values} -> mapped to a timed binding

solve

solve(observable_net, bindings: List) -> Any

Parameters:

Name Type Description Default
observable_net GymProblem or observation-like object

Used by the heuristic to inspect places/actions and flags.

required
bindings List

List of candidates to choose from. Items are either REAL action timed bindings, ([(place, token), ...], time, transition), or the postpone pseudo-binding, (['postpone'], current_clock, None).

required

Returns:

Type Description
str or tuple

Either 'postpone' or a REAL timed binding from bindings.

set_heuristic_function

set_heuristic_function(heuristic_function: Any)

Set the heuristic function to be used by the solver.

Parameters

Parameters:

Name Type Description Default
heuristic_function Any

Heuristic function to be used by the solver.

Returns

None

required

get_place_tokens staticmethod

get_place_tokens(place_id: str, pn) -> List

Get the tokens of a place in the process network.

Parameters

Parameters:

Name Type Description Default
place_id str

the id of the place.

required
pn

the GymProblem object representing the (observable) petri net.

Returns
required

Returns:

Type Description
List

list of token values in the place.

get_place_tokens_by_type staticmethod

get_place_tokens_by_type(place_id: str, desired_values: Dict, pn) -> List

Get the tokens of a place in the process network.

Parameters

Parameters:

Name Type Description Default
place_id str

the id of the place.

required
desired_values Dict

a dictionary having as key the attribute name and as value the desired value of the attribute (NOTE: this function assumes that token attributes are represented as dictionaries).

required
pn

the GymProblem object representing the (observable) petri net.

Returns
required

Returns:

Type Description
List

list of token values in the place.

get_action_available_assignments staticmethod

get_action_available_assignments(action, actions_dict)

Get the available assignments for an action.

Parameters

Parameters:

Name Type Description Default
action

the action to be fired.

required
actions_dict

the dictionary of actions and their available assignments.

Returns
required

Returns:

Type Description

list of available assignments for the action.

get_attribute_based_assignments staticmethod

get_attribute_based_assignments(action, attribute_dict, actions_dict)

Get the available assignments for an action based on a specific attribute.

Parameters

Parameters:

Name Type Description Default
action

the action to be fired.

required
attribute_dict

the dictionary of attributes and their values.

required
actions_dict

the dictionary of actions and their available assignments.

Returns
required

Returns:

Type Description

list of available assignments for the action based on the specified attribute.

gympn.solvers.RandomSolver

Bases: BaseSolver

solve

solve(observable_net, bindings: List) -> Any

Select a binding randomly from a list of bindings. Parameters


Parameters:

Name Type Description Default
observable_net

the GymProblem object representing the (observable) petri net.

required
bindings List

list of possible bindings to choose from.

Returns
required

Returns:

Type Description
Any

a randomly selected binding from the list of bindings.