Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/model-view-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest numpy coverage pygame matplotlib
pip install flake8 pytest numpy coverage pygame matplotlib scipy shapely
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
Expand Down
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ For training on triangular meshes, you can use an agent with all three actions:
##### 1. Using `tune/model_RL/PPO_model`

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

- Then run the following command from the `tune/` directory:
```bash
python main.py
python -m training.train_trimesh.py
```



##### 2. Using PPO from Stable Baselines 3 (SB3)

- Configure the model and environment parameters in:
- `tune/environment/environment_config.json`
- `tune/model_RL/parameters/PPO_config.json`
`tune/training/config/trimesh_config_PPO_SB3.yaml`

- Then run the training script in pycharm `tune/training/train_trimesh_SB3.py`
- Then run the following command from the `tune/` directory:
```bash
python -m training.train_trimesh_SB3.py
```

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

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`
> ❗ This environment may be deprecated.

---

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

#### 🚀 Starting Training

##### 1. Configure the model and environment parameters in :
- `tune/environment/environment_config.json`
- `tune/model_RL/parameters/PPO_config.json`

##### 2. Using `tune/model_RL/PPO_model_pers`
Run the following command from the `tune/` directory:
##### 1. Using `tune/model_RL/PPO_model`

- Configure the model and environment parameters in:
`tune/training/config/quadmesh_config_PPO_perso.yaml`

- Then run the following command from the `tune/` directory:
```bash
python -m training.train_quadmesh
python -m training.train_quadmesh.py
```

##### 2. Using PPO from Stable Baselines 3 (SB3)

##### 3. Using PPO from Stable Baselines 3 (SB3)
Run the following command from the `tune/` directory:
- Configure the model and environment parameters in:
`tune/training/config/quadmesh_config_PPO_SB3.yaml`

- Then run the following command from the `tune/` directory:
```bash
python -m training.train_quadmesh_SB3
python -m training.train_quadmesh_SB3.py
```

#### 🧪 Testing a Saved SB3 Policy

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` :
Expand Down
54 changes: 51 additions & 3 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ However, in some configurations, flip action can lead to problematic configurati
<img src="img/actions/flip_c_after.png" width="350"/>

* **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.
*

<img src="img/actions/flip_before_tri.png" width="350"/>
<img src="img/actions/flip_after_tri.png" width="350"/>

Expand Down Expand Up @@ -51,6 +51,54 @@ However, in some configurations, collapse action can also lead to problematic co
* **Adjacency too high :** When nodes A already has an adjacency higher than 10, collapse is not possible.
* **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.


<img src="img/actions/collapse_reversal_before.png" width="400"/>
<img src="img/actions/collapse_reversal_after.png" width="360"/>
<img src="img/actions/collapse_reversal_after.png" width="360"/>

---

# Quadrangular Actions

## Flip

<img src="img/actions/flip_quad.png" width="600"/>

The **flip** action can be decomposed as follows:

* Check whether the dart `d` exists.
* Update the **beta1** relations.
* Update the links from nodes `n1` and `n2`, if they were previously linked to the flipped dart.
* Update the links from faces `F1` and `F2`, if they were previously linked to the flipped dart.
* Update the node links for `d` and `d2`.
* Update the face links depending on the orientation (darts which change of face):
* If **counterclockwise**: update links for `d1` and `d21`.
* If **clockwise**: update links for `d2111` and `d111`.
* Update the scores of the nodes.

## Split

<img src="img/actions/split_quad.png" width="600"/>

The **split** action can be decomposed as follows:

* Check whether the dart `d` exists.
* Create a new node **n10** in the middle of [n1,n2]
* Update node links of `d` and `d21`, they are now linked to `n10`
* Create a new face with yellow darts
* Update the **beta2** relations (`d1112`, `d111`,`d212`, `d21`).
* Update the scores of the nodes.

## Collapse

<img src="img/actions/collapse_quad.png" width="600"/>

The **collapse** action can be decomposed as follows:

* Check whether the dart `d` exists.
* Save the score of node `n1` for later computation.
* If `n3` is not on the boundary, move its coordinates to the midpoint between `n3` and `n1`.
* 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).
* Delete the face associated with `d`, along with its related darts.
* Reassign all darts previously linked to `n1` so they now point to `n3`.
* Link the dart associated with `n3` to an existing node.
* Update the **beta2** relations (`d2`/`d12`, `d112`/`d1112`).
* Recalculate the scores of the affected nodes.
Binary file added docs/img/actions/collapse_quad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/actions/flip_quad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/actions/split_quad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions docs/tests/actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Actions tests

## Triangular actions

### Flip

We want to ensure that **flip** operations are performed correctly.
Consider the following mesh:

<img src="img/tri_flip_before.png" width="300"/>

If we flip the dart between nodes **n0** and **n3**, we should obtain the following mesh:

<img src="img/tri_flip_after.png" width="300"/>

### Split

We want to ensure that **split** operations are performed correctly.
Consider the following mesh:

<img src="img/tri_split_before.png" width="300"/>

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.
We should obtain the following mesh:

<img src="img/tri_split_after.png" width="300"/>

### Collapse

We want to ensure that **split** operations are performed correctly.
Consider the following mesh:

<img src="img/tri_collapse_before.png" width="300"/>

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**.
We should obtain the following mesh:

<img src="img/tri_collapse_after.png" width="300"/>
Binary file added docs/tests/img/tri_collapse_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tests/img/tri_collapse_before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tests/img/tri_flip_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tests/img/tri_flip_before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tests/img/tri_split_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tests/img/tri_split_before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading