scipplan


Namescipplan JSON
Version 0.1.0a2 PyPI version JSON
download
home_pageNone
SummaryMetric Hybrid Factored Planning in Nonlinear Domains with Constraint Generation in Python.
upload_time2024-04-21 07:05:29
maintainerNone
docs_urlNone
authorAri Gestetner, Buser Say
requires_pythonNone
licenseMIT License
keywords scip automated planner
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

<img src=./visualisation/scipplan_navigation_1.gif width="32%" height="32%"> <img src=./visualisation/scipplan_navigation_2.gif width="32%" height="32%"> <img src=./visualisation/scipplan_navigation_3.gif width="32%" height="32%">


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](https://www.scipopt.org). For more information about SCIP and PySCIPOpt refer to this [installation guide](https://github.com/scipopt/PySCIPOpt/blob/master/INSTALL.md).

After installing SCIP you will be able to install SCIPPlan using
```bash
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
```bash
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.
```py
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
```py
# 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
```py
# 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
```py
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
```txt
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
```txt
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
```
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 - sign 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 available variable types are
- state
- action
- auxiliary

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
```txt
Location_x == 0.0
Location_y == 0.0
Speed_x == 0.0
Speed_y == 0.0
```
notice te use of teh 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
```txt
Location_x == 8.0
Location_y == 8.0
```
### Instantaneous Constraints
This is where the instantaneous constraints go.
An example is as follows
```txt
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
```txt
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
```txt
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
```txt
-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](http://icaps18.icaps-conference.org/fileadmin/alg/conferences/icaps18/workshops/workshop06/docs/proceedings.pdf#page=23). In PlanSOpt, pages 19-25, 2018.

[2] Buser Say and Scott Sanner. [Metric Hybrid Factored Planning in Nonlinear Domains with Constraint Generation](https://link.springer.com/chapter/10.1007/978-3-030-19212-9_33). In CPAIOR, pages 502-518, 2019.

[3] Buser Say. [Robust Metric Hybrid Planning in Stochastic Nonlinear Domains Using Mathematical Optimization](https://ojs.aaai.org/index.php/ICAPS/article/view/27216). In ICAPS, pages 375-383, 2023.

[4] [SCIP](https://www.scipopt.org/)

[5] [PySCIPOpt](https://github.com/SCIP-Interfaces/PySCIPOpt)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "scipplan",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "scip, automated planner",
    "author": "Ari Gestetner, Buser Say",
    "author_email": "ari.gestetner@monash.edu, buser.say@monash.edu",
    "download_url": null,
    "platform": null,
    "description": "# SCIPPlan\n\nSCIPPlan [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.\n\n## Example Domain: Navigation\n\n<img src=./visualisation/scipplan_navigation_1.gif width=\"32%\" height=\"32%\"> <img src=./visualisation/scipplan_navigation_2.gif width=\"32%\" height=\"32%\"> <img src=./visualisation/scipplan_navigation_3.gif width=\"32%\" height=\"32%\">\n\n\nFigure 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. \n\nNote that SCIPPlan does not linearise or discretise the domain to find a valid plan.\n\n## Dependencies\n\ni) 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. \n\n## Installing and Running SCIPPlan\nIn 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](https://www.scipopt.org). For more information about SCIP and PySCIPOpt refer to this [installation guide](https://github.com/scipopt/PySCIPOpt/blob/master/INSTALL.md).\n\nAfter installing SCIP you will be able to install SCIPPlan using\n```bash\npip install scipplan\n```\nNow you will be able to run some of the example domains which include \n- Navigation (3 instances)\n\nTo run one of these examples all you need to do is run\n```bash\nscipplan -D navigation -I 1\n```\nwhich will run the 1st instance of the navigation domain. For more information regarding the available tags and what they mean run `scipplan --help`.\n\nAlternatively you can import scipplan classes to run it using python.\n```py\nfrom scipplan.scipplan import SCIPPlan\nfrom scipplan.config import Config\nfrom scipplan.helpers import write_to_csv\n```\nthis 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\n```py\n# Set params\nconfig = Config(domain=\"navigation\", instance=1)\n# Retrieve cli args\nconfig = Config.get_config()\n```\nafter which you are able to solve problem by either using the solve or optimize methods\n```py\n# The optimize method just optimises the problem for the given horizon\nplan = SCIPPlan(config)\nplan.optimize()\n# Class method which takes input the config, solves the problem \n# with auto incrementing the horizon until a solution is found then \n# returns the plan as well as the time taken to solve the problem\nplan, solve_time = SCIPPlan.solve(config)  \n```\nIn order to save the generated constraints for the horizon solved as well as the results, use the following code\n```py\nwrite_to_csv(\"new_constraints\", plan.new_constraints, config)\nwrite_to_csv(\"results\", plan.results_table, config)\n```\n\n\n\n## Custom Domains\nIf 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).\n\nFor each domain instance the following translation files are required\n- constants\n- pvariables\n- initials\n- goals\n- instantaneous_constraints\n- temporal_constraints\n- transitions\n- reward\n\nAs 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).\n\n### Constants\nThe 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\n```txt\nHalfVal = 0.5\nEpsilon = config_epsilon\nbigM = config_bigM\n```  \n\nSome config values can be accessed in the constants file to be used in other files and are available as \n- `config_epsilon`\n- `config_gap`\n- `config_bigM`  \nNote that these variables are only accessible in the constants file and you will need to define a new constants variable to store the value \n\n### Pvariables\nWhen creating the pvariables file, the variables should be listed in the following format\n```txt\naction_continuous: Accelerate_x\naction_continuous: Accelerate_y\naction_continuous: Dt\naction_boolean: Mode\nstate_continuous: Location_x\nstate_continuous: Location_y\nstate_continuous: Speed_x\nstate_continuous: Speed_y\n```\nwhere 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 - sign 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.  \nAdditionally 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.  \nThe available variable types are\n- state\n- action\n- auxiliary\n\nThe available value types are \n- continuos\n- integer \n- boolean \n\nPlease note that constants don't need to have their variable names defined in pvariables as they are defined in constants.\n\n### Initials\nThe initials file defines the initial state values for time t=0, for example\n```txt\nLocation_x == 0.0\nLocation_y == 0.0\nSpeed_x == 0.0\nSpeed_y == 0.0\n```\nnotice te use of teh constant value defined earlier in the constants file.\n### Goals\nThe goals file should encode the final state values such that t=H+1, for example\n```txt\nLocation_x == 8.0\nLocation_y == 8.0\n```\n### Instantaneous Constraints\nThis is where the instantaneous constraints go.\nAn example is as follows\n```txt\nLocation_x <= 10.0\nLocation_y <= 10.0\nLocation_x >= 0.0\nLocation_y >= 0.0\nAccelerate_x <= 0.5\nAccelerate_y <= 0.5\nAccelerate_x >= -0.5\nAccelerate_y >= -0.5\n(Location_x <= 4.0) or (Location_x >= 6.0) or (Location_y <= 4.0) or (Location_y >= 6.0)\n```\n### Temporal Constraints\nThe 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\n```txt\nLocation_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 10.0\nLocation_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 10.0\nLocation_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 0.0\nLocation_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 0.0\n\n((Location_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 4.0) or \n(Location_x + Speed_x*(Dt + Epsilon*Mode) + 0.5*Accelerate_x*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 6.0) or \n(Location_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) <= 4.0) or \n(Location_y + Speed_y*(Dt + Epsilon*Mode) + 0.5*Accelerate_y*(Dt + Epsilon*Mode)*(Dt + Epsilon*Mode) >= 6.0))\n```\n\nThe 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\n### Transitions\nTransitions are to be added here with the following syntax.  \nFor example $S_{t+1} = \\frac 12 A_t\\cdot t^2 + V_t\\cdot t + S_t$.  \nAlternatively this can be written as $S' = \\frac 12 A\\cdot t^2 + V\\cdot t + S$.\nSince Python doesn't allow variables to use the ' symbol it should be replaced with `_dash`, for example\n```txt\nLocation_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\nLocation_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\nSpeed_x_dash - 1.0*Speed_x - 1.0*Accelerate_x*(Dt + Epsilon*Mode) == 0.0\nSpeed_y_dash - 1.0*Speed_y - 1.0*Accelerate_y*(Dt + Epsilon*Mode) == 0.0\n```\n\n### Reward\nAs for the reward function, SCIPPlan maximises the reward thus if using a cost function it should be negated as per the example\n```txt\n-1.0*(Dt + Mode * Epsilon)\n```\nOnly one reward function is able to be optimised for in SCIPPlan\n\n## Citation\n\nIf you are using SCIPPlan, please cite the papers [1,2,3] and the underlying SCIP solver [4].\n\n## References\n[1] Buser Say and Scott Sanner. [Metric Nonlinear Hybrid Planning with Constraint Generation](http://icaps18.icaps-conference.org/fileadmin/alg/conferences/icaps18/workshops/workshop06/docs/proceedings.pdf#page=23). In PlanSOpt, pages 19-25, 2018.\n\n[2] Buser Say and Scott Sanner. [Metric Hybrid Factored Planning in Nonlinear Domains with Constraint Generation](https://link.springer.com/chapter/10.1007/978-3-030-19212-9_33). In CPAIOR, pages 502-518, 2019.\n\n[3] Buser Say. [Robust Metric Hybrid Planning in Stochastic Nonlinear Domains Using Mathematical Optimization](https://ojs.aaai.org/index.php/ICAPS/article/view/27216). In ICAPS, pages 375-383, 2023.\n\n[4] [SCIP](https://www.scipopt.org/)\n\n[5] [PySCIPOpt](https://github.com/SCIP-Interfaces/PySCIPOpt)\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Metric Hybrid Factored Planning in Nonlinear Domains with Constraint Generation in Python.",
    "version": "0.1.0a2",
    "project_urls": null,
    "split_keywords": [
        "scip",
        " automated planner"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b395b42786e26c89df68f5d50f0f730cd5e9c8054440d15dfdd4222360d15a9",
                "md5": "9b24fc2526493548f64fd076d9a07c2e",
                "sha256": "26316401645731c2770376af4d96731bad9960a2f793609d9e1f3cdb0f41b29f"
            },
            "downloads": -1,
            "filename": "scipplan-0.1.0a2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b24fc2526493548f64fd076d9a07c2e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 24743,
            "upload_time": "2024-04-21T07:05:29",
            "upload_time_iso_8601": "2024-04-21T07:05:29.122377Z",
            "url": "https://files.pythonhosted.org/packages/6b/39/5b42786e26c89df68f5d50f0f730cd5e9c8054440d15dfdd4222360d15a9/scipplan-0.1.0a2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-21 07:05:29",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "scipplan"
}
        
Elapsed time: 0.70563s