Skip to content
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
8 changes: 6 additions & 2 deletions back_end/a_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ def reconstruct_path():
distance.update({node_data[0]:g})
boundary_nodes.update({tuple(node_data):(g+h)})
return []

print(a_star([21.0347047,105.8143796],[21.0346086,105.8147965]))
#3,6,14,16,9
print(a_star([21.0347047,105.8143796],[21.0346086,105.8147965]))
print(a_star([21.0370748,105.8151156],[21.0335594,105.8170105]))
print(a_star([21.0372027,105.8149064],[21.034173,105.8172348]))
print(a_star([21.0379433,105.8133858],[21.0348241,105.8175344]))
print(a_star([21.0343185,105.8160597],[21.0419711,105.8163784]))
3 changes: 1 addition & 2 deletions back_end/nearest_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ def find_nearest_node(point):
print("Execution time:",execution_time)

return nearest_node_id

print(find_nearest_node([21.0347047,105.8143797]))
#print(find_nearest_node([21.0347047,105.8143797]))
61 changes: 61 additions & 0 deletions back_end/testRandoms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import random
import pandas as pd
from a_star import a_star
# Read the CSV file into a DataFrame
node_df = pd.read_csv("./data/nodes.csv")

# Define a function to get a random node from the DataFrame
def get_random_node():
# Get a random row index
random_index = random.randint(0, len(node_df) - 1)

# Get the row at the random index
random_node = node_df.loc[random_index, ['y', 'x']].tolist()

return random_node

# Define a function to compare results
def compare_results(a_star_result, other_program_result):
return a_star_result == other_program_result

# Generate 1000 random test cases
test_cases = []
for _ in range(1000):
start_node = get_random_node()
end_node = get_random_node()
test_cases.append((start_node, end_node))

# Compare results for each test case
same_results = 0
different_results = []
for start_node, end_node in test_cases:
print(start_node, end_node)
# Run a_star.py and get the result
a_star_result = a_star(start_node, end_node)

# Run the other program and get the result

# TODO ORTHER PROGRAM
other_program_result = a_star(start_node, end_node)

# Compare the results
if compare_results(a_star_result, other_program_result):
same_results += 1
else:
different_results.append((start_node, end_node, a_star_result, other_program_result))

# Calculate accuracy
accuracy = same_results / 1000

# Print accuracy
print("Accuracy:", accuracy)

# Print wrong cases
if accuracy < 1:
print("Wrong cases:")
for case in different_results:
start_node, end_node, a_star_result, other_program_result = case
print("Case's input:", start_node, end_node)
print("Case's output of a_star.py:", a_star_result)
print("Case's output of the other program:", other_program_result)
print()