Skip to main content

Metric Hybrid Factored Planning in Nonlinear Domains with Constraint Generation in Python.

Project description

SCIPPlan

SCIPPlan [1,2,3] is a SCIP-based [4] hybrid planner for domains with i) mixed (i.e., real and/or discrete valued) state and action spaces, ii) nonlinear state transitions that are functions of time, and iii) general reward functions. SCIPPlan iteratively i) finds violated constraints (i.e., zero-crossings) by simulating the state transitions, and ii) adds the violated (symbolic) constraints back to its underlying optimisation model, until a valid plan is found.

Example Domain: Navigation

Figure 1: Visualisation of different plans generated by SCIPPlan [1,2,3] for example navigation domains where the red square represents the agent, the blue shapes represent the obstacles, the gold star represents the goal location and the delta represents time. The agent can control its acceleration and the duration of its control input to modify its speed and location in order to navigate in a two-dimensional maze. The purpose of the domain is to find a path for the agent with minimum makespan such that the agent reaches its the goal without colliding with the obstacles.

Note that SCIPPlan does not linearise or discretise the domain to find a valid plan.

Dependencies

i) Solver: SCIP (the current implementation uses the python interface to the SCIP solver, i.e., PySCIPOpt [5]). This version of SCIPPlan has only been tested on PySCIOpt>=4.0.0 using earlier an version of pyscipopt may result in unintended behaviour.

Installing and Running SCIPPlan

In order to Install SCIPPlan you need to ensure you have a working version of the SCIP optimisation suite on your system which can be installed from the SCIP website. For more information about SCIP and PySCIPOpt refer to this installation guide.

After installing SCIP you will be able to install SCIPPlan using

pip install scipplan

Now you will be able to run some of the example domains which include

  • Navigation (3 instances)

To run one of these examples all you need to do is run

scipplan -D navigation -I 1

which will run the 1st instance of the navigation domain. For more information regarding the available tags and what they mean run scipplan --help.

Alternatively you can import scipplan classes to run it using python.

from scipplan.scipplan import SCIPPlan
from scipplan.config import Config
from scipplan.helpers import write_to_csv

this will import the only 2 classes and function needed to run SCIPPlan. Then to set the configuration either create an instance of the Config class by setting the params or by retrieving the cli input

# Set params
config = Config(domain="navigation", instance=1)
# Retrieve cli args
config = Config.get_config()

after which you are able to solve problem by either using the solve or optimize methods

# The optimize method just optimises the problem for the given horizon
plan = SCIPPlan(config)
plan.optimize()
# Class method which takes input the config, solves the problem 
# with auto incrementing the horizon until a solution is found then 
# returns the plan as well as the time taken to solve the problem
plan, solve_time = SCIPPlan.solve(config)  

In order to save the generated constraints for the horizon solved as well as the results, use the following code

write_to_csv("new_constraints", plan.new_constraints, config)
write_to_csv("results", plan.results_table, config)

Custom Domains

If you would like to create your own domain you will need to create a directory named "translation" in the directory which scipplan is run from with txt files of the format "{translation type}_{domain name}_{instance number}.txt" (e.g. "pvariables_navigation_1.txt"). Note that the files in the translation directory will override any example files if they share domain name and instance number (e.g. navigation 1 would override the example).

For each domain instance the following translation files are required

  • constants
  • pvariables
  • initials
  • goals
  • instantaneous_constraints
  • temporal_constraints
  • transitions
  • reward

As a part of SCIPPlan, all the constraint files allow for the use of "and" and "or" expressions, polynomials and exp, log, sqrt, sin and cos functions (Note: sin and cos are only available in PySCIPOpt>=4.3.0 so if your version is below that you will not be able to use the trig functions unless you update).

Constants

The constants file allows for constant values to be defined as a variable to be used in other files in the model. To use add constants as follows

HalfVal = 0.5
Epsilon = config_epsilon
bigM = config_bigM

Some config values can be accessed in the constants file to be used in other files and are available as

  • config_epsilon
  • config_gap
  • config_bigM
    Note that these variables are only accessible in the constants file and you will need to define a new constants variable to store the value

Pvariables

When creating the pvariables file, the variables should be listed in the following format

action_continuous: Accelerate_x
action_continuous: Accelerate_y
action_continuous: Dt
action_boolean: Mode
state_continuous: Location_x
state_continuous: Location_y
state_continuous: Speed_x
state_continuous: Speed_y
global_boolean: aux_1

where the variable and value type of the variable is set in the format "{variable type}{value type}" and the variable itself has to be in a Python compatible format (e.g. variables can't use - symbol like some-var but can use _ like some_var as well as the dash sign ' cannot be used). The use of next state variables which is often written using the dash symbol will be explained further in the Transitions section.
Additionally a variable for Dt has to be defined and has to be the same as the dt_var in the config object so if you would like to use a different variable name for Dt (e.g. dt) please also ensure you add it to the config via the --dt-var tag or the dt_var parameter.
The variable type global is used when you would like a non state variable to be equal over every time step over the horizon (e.g. if $v_t$ is a variable at time $t$ and $H$ is the horizon, then $v_1 = v_2 = \dots = v
{H+1}$).

The available variable types are

  • state
  • action
  • auxiliary
  • global

The available value types are

  • continuos
  • integer
  • boolean

Please note that constants don't need to have their variable names defined in pvariables as they are defined in constants.

Initials

The initials file defines the initial state values for time t=0, for example

Location_x == 0.0
Location_y == 0.0
Speed_x == 0.0
Speed_y == 0.0

notice the use of the constant value defined earlier in the constants file.

Goals

The goals file should encode the final state values such that t=H+1, for example

Location_x == 8.0
Location_y == 8.0

Instantaneous Constraints

This is where the instantaneous constraints go. An example is as follows

Location_x <= 10.0
Location_y <= 10.0
Location_x >= 0.0
Location_y >= 0.0
Accelerate_x <= 0.5
Accelerate_y <= 0.5
Accelerate_x >= -0.5
Accelerate_y >= -0.5
(Location_x <= 4.0) or (Location_x >= 6.0) or (Location_y <= 4.0) or (Location_y >= 6.0)

Temporal Constraints

The temporal constraints are the constraints which SCIPPlan will ensure that the solution never violates by iterating through every epsilon value of Dt and checking for zero crossings. An example of a temporal constraint is as follows

Location_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 10.0
Location_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 10.0
Location_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 0.0
Location_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 0.0

((Location_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 4.0) or 
(Location_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 6.0) or 
(Location_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 4.0) or 
(Location_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 6.0))

The use of mode switches are used in these constraints (Dt + Epsilon*Mode). Please note that the or expression is enclosed in round brackets which allows the constraints to be parsed as a singular expression

Transitions

Transitions are to be added here with the following syntax.
For example $S_{t+1} = \frac 12 A_t\cdot t^2 + V_t\cdot t + S_t$.
Alternatively this can be written as $S' = \frac 12 A\cdot t^2 + V\cdot t + S$. Since Python doesn't allow variables to use the ' symbol it should be replaced with _dash, for example

Location_x_dash - 1.0*Location_x - 1.0*Speed_x*(Dt + Epsilon*Mode) - 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) == 0.0
Location_y_dash - 1.0*Location_y - 1.0*Speed_y*(Dt + Epsilon*Mode) - 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) == 0.0
Speed_x_dash - 1.0*Speed_x - 1.0*Accelerate_x*(Dt + Epsilon*Mode) == 0.0
Speed_y_dash - 1.0*Speed_y - 1.0*Accelerate_y*(Dt + Epsilon*Mode) == 0.0

Reward

As for the reward function, SCIPPlan maximises the reward thus if using a cost function it should be negated as per the example

-1.0*(Dt + Mode * Epsilon)

Only one reward function is able to be optimised for in SCIPPlan

Citation

If you are using SCIPPlan, please cite the papers [1,2,3] and the underlying SCIP solver [4].

References

[1] Buser Say and Scott Sanner. Metric Nonlinear Hybrid Planning with Constraint Generation. In PlanSOpt, pages 19-25, 2018.

[2] Buser Say and Scott Sanner. Metric Hybrid Factored Planning in Nonlinear Domains with Constraint Generation. In CPAIOR, pages 502-518, 2019.

[3] Buser Say. Robust Metric Hybrid Planning in Stochastic Nonlinear Domains Using Mathematical Optimization. In ICAPS, pages 375-383, 2023.

[4] SCIP

[5] PySCIPOpt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scipplan-0.1.1a0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scipplan-0.1.1a0-py2.py3-none-any.whl (25.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file scipplan-0.1.1a0.tar.gz.

File metadata

  • Download URL: scipplan-0.1.1a0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for scipplan-0.1.1a0.tar.gz
Algorithm Hash digest
SHA256 d7f0b00dc8307f957dbe173cbd78d28939345d7b77634a0eeeb610d6d3a68266
MD5 0f9621428a70cc9c30ba2250081d1d23
BLAKE2b-256 fceb22055c206decb3c249d076c64d4bfdef247949bd30cf842c1bf8fafb6cf3

See more details on using hashes here.

File details

Details for the file scipplan-0.1.1a0-py2.py3-none-any.whl.

File metadata

  • Download URL: scipplan-0.1.1a0-py2.py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.2

File hashes

Hashes for scipplan-0.1.1a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8525feb00ca59485d8c6b75477285b39412015fd631ec2fdbd92499670b78b2b
MD5 d37247ee39c40187e5b6d7467065ef4d
BLAKE2b-256 1e3827ba74bf3ec552ded998a38a872dd445ba2e18a4af23a3af0c0c02757692

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page