Skip to content

Commit b2e6a11

Browse files
authored
Merge pull request #66 from LIHPC-Computational-Geometry/65-only-topological-constraints
New process to constrain actions
2 parents 6982248 + 7cce9d1 commit b2e6a11

File tree

147 files changed

+4094
-1547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+4094
-1547
lines changed

.github/workflows/model-view-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
26-
pip install flake8 pytest numpy coverage pygame matplotlib
26+
pip install flake8 pytest numpy coverage pygame matplotlib scipy shapely
2727
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2828
- name: Lint with flake8
2929
run: |

README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,27 @@ For training on triangular meshes, you can use an agent with all three actions:
3434
##### 1. Using `tune/model_RL/PPO_model`
3535

3636
- Configure the model and environment parameters in:
37-
`tune/training/train.py`
37+
`tune/training/config/trimesh_config_PPO_perso.yaml`
3838

3939
- Then run the following command from the `tune/` directory:
4040
```bash
41-
python main.py
41+
python -m training.train_trimesh.py
4242
```
43-
44-
43+
4544
##### 2. Using PPO from Stable Baselines 3 (SB3)
4645

4746
- Configure the model and environment parameters in:
48-
- `tune/environment/environment_config.json`
49-
- `tune/model_RL/parameters/PPO_config.json`
47+
`tune/training/config/trimesh_config_PPO_SB3.yaml`
5048

51-
- Then run the training script in pycharm `tune/training/train_trimesh_SB3.py`
49+
- Then run the following command from the `tune/` directory:
50+
```bash
51+
python -m training.train_trimesh_SB3.py
52+
```
5253

5354
###### Flip-Only Training (SB3 PPO)
5455

5556
To train an agent using only the flip action with SB3 PPO, run the training script in pycharm `tune/training/train_trimesh_flip_SB3.py`
57+
> ❗ This environment may be deprecated.
5658
5759
---
5860

@@ -65,21 +67,26 @@ For training on quadrangular meshes, you can use an agent with all four actions:
6567

6668
#### 🚀 Starting Training
6769

68-
##### 1. Configure the model and environment parameters in :
69-
- `tune/environment/environment_config.json`
70-
- `tune/model_RL/parameters/PPO_config.json`
71-
72-
##### 2. Using `tune/model_RL/PPO_model_pers`
73-
Run the following command from the `tune/` directory:
70+
##### 1. Using `tune/model_RL/PPO_model`
71+
72+
- Configure the model and environment parameters in:
73+
`tune/training/config/quadmesh_config_PPO_perso.yaml`
74+
75+
- Then run the following command from the `tune/` directory:
7476
```bash
75-
python -m training.train_quadmesh
77+
python -m training.train_quadmesh.py
7678
```
79+
80+
##### 2. Using PPO from Stable Baselines 3 (SB3)
7781

78-
##### 3. Using PPO from Stable Baselines 3 (SB3)
79-
Run the following command from the `tune/` directory:
82+
- Configure the model and environment parameters in:
83+
`tune/training/config/quadmesh_config_PPO_SB3.yaml`
84+
85+
- Then run the following command from the `tune/` directory:
8086
```bash
81-
python -m training.train_quadmesh_SB3
87+
python -m training.train_quadmesh_SB3.py
8288
```
89+
8390
#### 🧪 Testing a Saved SB3 Policy
8491

8592
After training, the model is saved as a `.zip` file in the `tune/training/policy_saved/` directory. To evaluate the policy, follow these steps in `tune/training/exploit_SB3_policy.py` :

docs/actions.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ However, in some configurations, flip action can lead to problematic configurati
1818
<img src="img/actions/flip_c_after.png" width="350"/>
1919

2020
* **triangular quad:** This configuration should be avoided, as it results in the creation of a degenerate (flat) triangle. As illustrated in the figures below, flipping dart 0 leads to a flattened face between nodes 2, 0, and 7.
21-
*
21+
2222
<img src="img/actions/flip_before_tri.png" width="350"/>
2323
<img src="img/actions/flip_after_tri.png" width="350"/>
2424

@@ -51,6 +51,54 @@ However, in some configurations, collapse action can also lead to problematic co
5151
* **Adjacency too high :** When nodes A already has an adjacency higher than 10, collapse is not possible.
5252
* **Configuration who tends to imply edge reversal**: To detect these situations, we look a the type of darts in the surrounding. When there are some darts with concave surrounding, collapse action can lead to edge reversal.
5353

54-
5554
<img src="img/actions/collapse_reversal_before.png" width="400"/>
56-
<img src="img/actions/collapse_reversal_after.png" width="360"/>
55+
<img src="img/actions/collapse_reversal_after.png" width="360"/>
56+
57+
---
58+
59+
# Quadrangular Actions
60+
61+
## Flip
62+
63+
<img src="img/actions/flip_quad.png" width="600"/>
64+
65+
The **flip** action can be decomposed as follows:
66+
67+
* Check whether the dart `d` exists.
68+
* Update the **beta1** relations.
69+
* Update the links from nodes `n1` and `n2`, if they were previously linked to the flipped dart.
70+
* Update the links from faces `F1` and `F2`, if they were previously linked to the flipped dart.
71+
* Update the node links for `d` and `d2`.
72+
* Update the face links depending on the orientation (darts which change of face):
73+
* If **counterclockwise**: update links for `d1` and `d21`.
74+
* If **clockwise**: update links for `d2111` and `d111`.
75+
* Update the scores of the nodes.
76+
77+
## Split
78+
79+
<img src="img/actions/split_quad.png" width="600"/>
80+
81+
The **split** action can be decomposed as follows:
82+
83+
* Check whether the dart `d` exists.
84+
* Create a new node **n10** in the middle of [n1,n2]
85+
* Update node links of `d` and `d21`, they are now linked to `n10`
86+
* Create a new face with yellow darts
87+
* Update the **beta2** relations (`d1112`, `d111`,`d212`, `d21`).
88+
* Update the scores of the nodes.
89+
90+
## Collapse
91+
92+
<img src="img/actions/collapse_quad.png" width="600"/>
93+
94+
The **collapse** action can be decomposed as follows:
95+
96+
* Check whether the dart `d` exists.
97+
* Save the score of node `n1` for later computation.
98+
* If `n3` is not on the boundary, move its coordinates to the midpoint between `n3` and `n1`.
99+
* Check if nodes `n2` and `n4` are linked to the dart being deleted. If so, reassign their links to existing darts (node `n3` will be checked later).
100+
* Delete the face associated with `d`, along with its related darts.
101+
* Reassign all darts previously linked to `n1` so they now point to `n3`.
102+
* Link the dart associated with `n3` to an existing node.
103+
* Update the **beta2** relations (`d2`/`d12`, `d112`/`d1112`).
104+
* Recalculate the scores of the affected nodes.

docs/img/actions/collapse_quad.png

30.3 KB
Loading

docs/img/actions/flip_quad.png

25.7 KB
Loading

docs/img/actions/split_quad.png

29.8 KB
Loading

docs/tests/actions.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Actions tests
2+
3+
## Triangular actions
4+
5+
### Flip
6+
7+
We want to ensure that **flip** operations are performed correctly.
8+
Consider the following mesh:
9+
10+
<img src="img/tri_flip_before.png" width="300"/>
11+
12+
If we flip the dart between nodes **n0** and **n3**, we should obtain the following mesh:
13+
14+
<img src="img/tri_flip_after.png" width="300"/>
15+
16+
### Split
17+
18+
We want to ensure that **split** operations are performed correctly.
19+
Consider the following mesh:
20+
21+
<img src="img/tri_split_before.png" width="300"/>
22+
23+
If we split the dart between nodes **n0** and **n3**, we add a node **n5** on the middle of the edge and two faces are created.
24+
We should obtain the following mesh:
25+
26+
<img src="img/tri_split_after.png" width="300"/>
27+
28+
### Collapse
29+
30+
We want to ensure that **split** operations are performed correctly.
31+
Consider the following mesh:
32+
33+
<img src="img/tri_collapse_before.png" width="300"/>
34+
35+
Here we can't collapse the dart between nodes **n5** and **n2** because n2 is on boundary. However we can collapse the edge between **n4** and **n5**.
36+
We should obtain the following mesh:
37+
38+
<img src="img/tri_collapse_after.png" width="300"/>
18.7 KB
Loading
23.7 KB
Loading

docs/tests/img/tri_flip_after.png

12.3 KB
Loading

0 commit comments

Comments
 (0)