mCPs2fond 1.0.3
CPs + m ==> FOND
Requires Python: >=3.6

Main Page {#mainpage}
=========

[TOC]

# m+CPs$\rightarrow$ FOND

Given a fine-grained mapping of abstract predicate vectors, given a sufficient set of instances, autogenerate the FOND file which can be solved by FOND-Solver and get the $\pi$.

# install

```bash
pip install mCPs2fond
```

## visitall demo

put PDDL domain file and PDDL problem files of CPs under path `domain/{domainname}/`, then make a python file:


```python
#!/usr/bin/env python 
# -*- coding:UTF-8 -*-
import mCPs2fond.mCPs2fond as mCPs2fond_Python_source_code
print("'mCPs2fond' is loacated in" , mCPs2fond_Python_source_code.__file__)
from mCPs2fond.mCPs2fond import mCPs2fond

if __name__ == '__main__':
    """
    python runDemos.py -domainname "llvisitall" -cpn "3" -debug "True"
    """
    import argparse
    args_parser = argparse.ArgumentParser(description='code autoGenerator')
    args_parser.add_argument('-domainname', default = "llvisitall", help='Path to fond domain files(default=dfs). -- OPTIONAL')
    args_parser.add_argument('-cpn', default="3", help='number of classical plans,like \'3\' for \'*p1,*p2,*p3\'. -- NOT OPTIONAL')
    args_parser.add_argument('-debug', default = 'True', help='print DEBUG message or not. -- OPTIONAL FOR TEST')
    params = vars(args_parser.parse_args()) 
    if params['debug'] == 'False':
        DEBUG = False
    else:
        DEBUG = True

    domainname = params['domainname']
    cpn = int(params['cpn']) # 1,2,...,cpn = range(1,cpn+1)

    import time, os
    os.path.dirname(os.path.realpath(__file__))
    father_dir_for_PDDL = os.path.dirname(os.path.realpath(__file__))
    father_dir_for_FOND = os.path.dirname(os.path.realpath(__file__))
    start_time = time.perf_counter()
    mCPs2fond(father_dir_for_PDDL,father_dir_for_FOND,domainname,cpn,DEBUG)
    print(\
        father_dir_for_FOND+"/generated/{0}/fond_{0}_d.pddl \n".format(domainname),\
        father_dir_for_FOND+"/generated/fond_{0}_p.pddl\n".format(domainname))
    end_time = time.perf_counter()
    print('it cost: ',end_time - start_time,'(s).')
```

Then,files `fond_{domainname}_d.pddl` and `fond_{domainname}_p.pddl` will made under path `./generated`.


or change to the path for the packkage `mCPs2fond` and write this in that path(also you can see how the demo input files wrote):
- command:

```bash
python -m mCPs2fond -domainname llvisitall -cpn 3 -debug True
python -m mCPs2fond -domainname reversell -cpn 2 -debug True
python -m mCPs2fond -domainname blocks_clear -cpn 1 -debug True
```

- input:

`python -m mCPs2fond -domainname {domainName} -cpn n -debug True`

 `n` CPs  under "`./domains/{domainName}`" folder :

```cmd
./domains/{domainName}/low_{domainName}_d.pddl
./domains/{domainName}/low_{domainName}_p1.pddl
./domains/{domainName}/low_{domainName}_p2.pddl
......
./domains/{domainName}/low_{domainName}_pn.pddl
```

- output:
FOND file in PDDL extend with "oneof" non-deterministic effects under `./autogenerated`,which can be solved be And/Or tree pruning algorithm like LAO*, the most famous FOND-Solver is :

  - myND [https://github.com/JackyCSer/MyNDPlanner](https://github.com/JackyCSer/MyNDPlanner) 
  - PRP [https://github.com/QuMuLab/planner-for-relevant-policies](https://github.com/QuMuLab/planner-for-relevant-policies) 
  - FOND-SAT [https://github.com/tomsons22/FOND-SAT](https://github.com/tomsons22/FOND-SAT)

```
./autogenerated/fond_{domainName}_d.pddl
./autogenerated/fond_{domainName}_p.pddl # the same contents in all domains
```

- Policy $\pi$ convert to CFG(control flow graph)

  then we can change the $\pi$ to the equivalent AST then get the structure programming (c-like)code,maybe like Lua. First,we assumpt we had got the policy for the FOND problem from FOND-Solver above, and we read the policy $\pi$ into a Control Flow Graph (by Lengauer - Tarjan Algorithm, etc).