Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ _deps
.vscode/*
build/*

data/*
*.xml
*.json
10 changes: 10 additions & 0 deletions scripts/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: df pa rj

df:
grep -o -w id ../data/train/df-$(id)/cvrp-$(id)-df-$(f).json | wc -l

pa:
grep -o -w id ../data/train/pa-$(id)/cvrp-$(id)-pa-$(f).json | wc -l

rj:
grep -o -w id ../data/train/rj-$(id)/cvrp-$(id)-rj-$(f).json | wc -l
47 changes: 47 additions & 0 deletions scripts/gen_bounding_boxes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json

def get_bounding_boxes():
bounding_box = {}
folder_id = [("df", range(0, 3)), ("pa", range(0, 2)), ("rj", range(0, 6))]
for (folder, id_range) in folder_id:
for id in id_range:
for n in range(0, 90):
file_path = f"data/train/{folder}-{id}/cvrp-{id}-{folder}-{n}.json"
box = calculate_bounding_box(file_path)
bounding_box[folder] = better_box(bounding_box.get(folder, None), box)
return bounding_box

def better_box(box1, box2):
if box1 == None:
return box2
min_lat = min(box1["latitude" ][0], box2["latitude" ][0])
max_lat = max(box1["latitude" ][1], box2["latitude" ][1])
min_long = min(box1["longitude"][0], box2["longitude"][0])
max_long = max(box1["longitude"][1], box2["longitude"][1])
return {"latitude": [min_lat, max_lat], "longitude": [min_long, max_long]}

def calculate_bounding_box(file_path : str) -> dict:

with open(file_path) as f:
points = json.load(f)

min_lat = max_lat = points["origin"]["lat"]
min_lon = max_lon = points["origin"]["lng"]

for point in points["deliveries"]:
point_lat = point["point"]["lat"]
point_lon = point["point"]["lng"]

if min_lat > point_lat:
min_lat = point_lat
elif max_lat < point_lat:
max_lat = point_lat

if min_lon > point_lon:
min_lon = point_lon
elif max_lon < point_lon:
max_lon = point_lon

return {"latitude" : [min_lat, max_lat], "longitude" : [min_lon, max_lon]}

print(get_bounding_boxes())
22 changes: 22 additions & 0 deletions scripts/n_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

min = [1037, 279, 3728]
max = [1037, 279, 3728]

files = ["df.txt", "pa.txt", "rj.txt"]
for (index, file) in enumerate(files):
with open(file, "r") as f:
while (True):
check = f.readline()
if check is None:
break
check = f.readline()
if check == '':
break
number = int(check)
if (number < min[index]):
min[index] = number
if (number > max[index]):
max[index] = number

for (index, file) in enumerate(files):
print(file, min[index], max[index])
7 changes: 7 additions & 0 deletions scripts/points-df.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for ID in {0..2}
do
for VAR in {0..89}
do
make df id=$ID f=$VAR
done
done
7 changes: 7 additions & 0 deletions scripts/points-pa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for ID in {0..1}
do
for VAR in {0..89}
do
make pa id=$ID f=$VAR
done
done
7 changes: 7 additions & 0 deletions scripts/points-rj.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for ID in {0..5}
do
for VAR in {0..89}
do
make rj id=$ID f=$VAR
done
done
3 changes: 3 additions & 0 deletions scripts/points.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./points-df.sh > df.txt
./points-pa.sh > pa.txt
./points-rj.sh > rj.txt
4 changes: 2 additions & 2 deletions src/analysis/complexity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ void quadtreeRealDataComplexityAnalysis(u32 seed) {
Quadtree quadtree(boundary);

// Insert nodes into Quadtree
for (const pair<u64, OsmNode>& node : data.graph.getNodes()) {
quadtree.insert(data.graph.getNode(node.first));
for (const pair<u64, const OsmNode&>& node : data.graph.getNodes()) {
quadtree.insert(node.second);
}

srand(seed);
Expand Down
21 changes: 20 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "data_structures/kd_tree.hpp"
#include "coordinates.hpp"
#include "graph.hpp"
#include "analysis/complexity.hpp"

using namespace std;

Expand Down Expand Up @@ -77,7 +78,25 @@ void aStarTest() {
}

int main() {
//aStarTest();
// aStarTest();
// quadtreeRealDataComplexityAnalysis();
OsmXmlData data;

cout << endl << "-------------------- PA --------------------" << endl << endl;

data = parseOsmXml("../data/pa.xml");
cout << data.graph.getNodes().size() << " nodes - " << data.graph.getSize() << " edges" << endl;

cout << endl << "-------------------- DF --------------------" << endl << endl;

data = parseOsmXml("../data/df.xml");
cout << data.graph.getNodes().size() << " nodes - " << data.graph.getSize() << " edges" << endl;

cout << endl << "-------------------- RJ --------------------" << endl << endl;

data = parseOsmXml("../data/rj.xml");
cout << data.graph.getNodes().size() << " nodes - " << data.graph.getSize() << " edges" << endl;

cout << endl;
return 0;
}