Skip to content

Commit

Permalink
rename tsp_2opt -> tsp_nls
Browse files Browse the repository at this point in the history
  • Loading branch information
Furffico committed Sep 22, 2023
1 parent a88b2c0 commit 0413773
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Welcome! This repository contains the code implementation of paper [*DeepACO: Ne
---

### Usage
- **Traveling Salesman Problem (TSP).** Please refer to `tsp/` for vanilla DeepACO and `tsp_2opt/` for DeepACO with NLS on TSP.
- **Traveling Salesman Problem (TSP).** Please refer to `tsp/` for vanilla DeepACO and `tsp_nls/` for DeepACO with NLS on TSP.
- **Capacitated Vehicle Routing Problem (CVRP).** Please refer to `cvrp/` for vanilla DeepACO and `cvrp_nls/` for DeepACO with NLS on CVRP.
- **Orienteering Problem (OP).** Please refer to `op/`.
- **Prize Collecting Travelling Salesman Problem (PCTSP).** Please refer to `pctsp/`.
Expand Down
1 change: 1 addition & 0 deletions cvrp/aco.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def check_done(self, visit_mask, actions):
return (visit_mask[:, 1:] == 0).all() and (actions == 0).all()

# ======== code for adaptive elitist AS ========
# These code are unrelated to DeepACO, and are kept for comparisons.
def get_subroutes(self, route, end_with_zero = True):
x = torch.nonzero(route == 0).flatten()
subroutes = []
Expand Down
2 changes: 2 additions & 0 deletions cvrp_nls/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DeepACO with NLS for CVRP

We adopted the C++ implementation of the SWAP* algorithm provided by Vidal T. et al [1,2] ([source repo](https://github.com/vidalt/HGS-CVRP)) and added a C++ interface to directly utilize the local search algorithm in the program. We also utilized and modified the Python wrapper provided by [PyHygese](https://github.com/chkwon/PyHygese). We would like to express our gratitude for the contributions made by the aforementioned paper and project.

To run our program, please follow the steps below to compile the shared library (if the file `./HGS-CVRP-main/build/libhgscvrp.so` we provide isn't compatiable with your setup)
Expand Down
1 change: 1 addition & 0 deletions cvrp_nls/aco.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def positions_cpu(self):
return self.positions.cpu().numpy() if self.positions is not None else None

# ======== code for adaptive elitist AS ========
# These code are unrelated to DeepACO, and are kept for comparisons.
def insertion_single(self, route, index):
# route starts from 0, terminates with 0
insertion_cost = (((self.distances[p1, index]+self.distances[index,p2]-self.distances[p1, p2]).item(), i)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tsp_2opt/README.md → tsp_nls/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## DeepACO with NLS
## DeepACO with NLS for TSP

### Training

The checkpoints will be saved in [`../pretrained/tsp_2opt`](../pretrained/tsp_2opt) with suffix `-best.pt` and `-last.pt` by default.
The checkpoints will be saved in [`../pretrained/tsp_nls`](../pretrained/tsp_nls) with suffix `-best.pt` and `-last.pt` by default.

TSP200:
```raw
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tsp_2opt/test.py → tsp_nls/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def main(n_node, model_file, k_sparse = None, n_ants=48, t_aco = None):

parser = argparse.ArgumentParser()
parser.add_argument("nodes", type=int, help="Problem scale")
parser.add_argument("-m", "--model", type=str, default=None, help="Path to checkpoint file, default to '../pretrained/tsp_2opt/tsp{nodes}.pt'")
parser.add_argument("-m", "--model", type=str, default=None, help="Path to checkpoint file, default to '../pretrained/tsp_nls/tsp{nodes}.pt'")
opt = parser.parse_args()
n_nodes = opt.nodes

filepath = opt.model or f'../pretrained/tsp_2opt/tsp{n_nodes}.pt'
filepath = opt.model or f'../pretrained/tsp_nls/tsp{n_nodes}.pt'
if not os.path.isfile(filepath):
print(f"Checkpoint file '{filepath}' not found!")
exit(1)
Expand Down
6 changes: 3 additions & 3 deletions tsp_2opt/train.py → tsp_nls/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def validation(n_ants, epoch, net, val_dataset):
return avg_stats


def train(n_node, n_ants, steps_per_epoch, epochs, k_sparse = None, batch_size = 3, test_size = None, pretrained = None, savepath = "../pretrained/tsp_2opt"):
def train(n_node, n_ants, steps_per_epoch, epochs, k_sparse = None, batch_size = 3, test_size = None, pretrained = None, savepath = "../pretrained/tsp_nls"):
k_sparse = k_sparse or n_node//10
net = Net().to(device)
if pretrained:
Expand Down Expand Up @@ -121,7 +121,7 @@ def train(n_node, n_ants, steps_per_epoch, epochs, k_sparse = None, batch_size =

print('\ntotal training duration:', sum_time)

return f'../pretrained/tsp_2opt/tsp{n_node}.pt'
return f'../pretrained/tsp_nls/tsp{n_node}.pt'


if __name__ == "__main__":
Expand All @@ -138,7 +138,7 @@ def train(n_node, n_ants, steps_per_epoch, epochs, k_sparse = None, batch_size =
parser.add_argument("-s", "--steps", type=int, default=20, help="Steps per epoch")
parser.add_argument("-e", "--epochs", type=int, default=100, help="Epochs to run")
parser.add_argument("-t", "--test_size", type=int, default=None, help="Number of instances for testing")
parser.add_argument("-o", "--output", type=str, default="../pretrained/tsp_2opt",
parser.add_argument("-o", "--output", type=str, default="../pretrained/tsp_nls",
help="The directory to store checkpoints")
opt = parser.parse_args()

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 0413773

Please sign in to comment.