<jupyter_start><jupyter_text>Path Planning 1. Problem setupThe solver requires an environment and an agent(denominated explorer). The agent determines the cost function definitions.<jupyter_code>from pextant.explorers import Astronaut
from pextant.EnvironmentalModel import load_legacy<jupyter_output><empty_output><jupyter_text>To illustrate the use, our example will use the Apollo 14 map. Maximum slope is set to 15 degrees which is reasonable for astronaut traverses. To speed up the solver for later we need to pass in the argument cached=True to the loadSubSection method. This will carry out some preprocessing that will speed up solution time later on.<jupyter_code>apollo14_gridmesh = load_legacy("Apollo14.txt")
apollo14_model = apollo14_gridmesh.loadSubSection(maxSlope=10, cached=True)
agent = Astronaut(80)
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
# from matplotlib_scalebar.scalebar import ScaleBar
from pextant.viz.utils import hillshade
from pextant.lib.geoshapely import GeoPoint, GeoPolygon
start = GeoPoint(apollo14_model.ROW_COL, 750, 100)
goal = GeoPoint(apollo14_model.ROW_COL, 620, 500)
waypoints = GeoPolygon([start, goal])<jupyter_output><empty_output><jupyter_text>We will choose for start the location of the Lunar lander, and for goal the border of the crater rim, this is to very roughly approximate the actual EVA - which has several intermediate points included.<jupyter_code>hillshade(apollo14_model,1)
plt.imshow(apollo14_model.obstacle_mask(), alpha=0.5, cmap='bwr_r')
plt.plot(*waypoints.to(apollo14_model.COL_ROW), \
         linestyle='None', marker='*', markeredgecolor="k", markersize=15)
red_patch = mpatches.Patch(color='red', alpha=0.5, label='Obstacle map')
plt.legend(handles=[red_patch])
# plt.gca().add_artist(ScaleBar(apollo14_model.resolution, location=4))
plt.show()<jupyter_output><empty_output><jupyter_text>2. Solver setup<jupyter_code>from pextant.solvers.astarMesh import astarSolver<jupyter_output><empty_output><jupyter_text>SEXTANT had a slightly unefficient implementation, so this was just changed at the tailgate of the project. It implements a slightly modified version of networkx's astar solver.<jupyter_code>pathfinder_py = astarSolver(apollo14_model, agent, algorithm_type=astarSolver.PY_NETWORKX)
pathfinder = astarSolver(apollo14_model, agent, algorithm_type=astarSolver.CPP_NETWORKX)
%%time 
out,_,_ = pathfinder.solvemultipoint(waypoints)
%%time 
out,_,_ = pathfinder_py.solvemultipoint(waypoints)<jupyter_output>Wall time: 7.88 s<jupyter_text>Next we can overlay the solution on the map visualization:<jupyter_code>hillshade(apollo14_model,1)
plt.imshow(apollo14_model.obstacle_mask(), alpha=0.5, cmap='bwr_r')
plt.plot(*waypoints.to(apollo14_model.COL_ROW), \
         linestyle='None', marker='*', markeredgecolor="k", markersize=15)
plt.plot(*out.coordinates().to(apollo14_model.COL_ROW))
plt.legend(handles=[red_patch])
# plt.gca().add_artist(ScaleBar(apollo14_model.resolution, location=4))
plt.show()<jupyter_output><empty_output><jupyter_text>3. Post processing of a path<jupyter_code>from pextant.explorers import TraversePath
traverse = TraversePath.frommap(out.coordinates(), apollo14_model)
_, _, dr = agent.path_dl_slopes(traverse)
energies, v = agent.path_energy_expenditure(traverse)
import numpy as np
total_dist = np.cumsum(dr)
total_dist[-1]
plt.plot(np.cumsum(dr), np.cumsum(energies)/1000.)
plt.xlabel('distance [m]')
plt.ylabel('energy [kJ]')
plt.title('Cumulative energy for EVA')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10307822648969217, 'fraction_numerical': 0.02287489409771251, 'mean_word_length': 7.899497487437186, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '414815', 'license': 'MIT', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1197, 'n_words': 276, 'path': 'pextant/notebooks/Documentation/3_Planning.ipynb', 'repo_name': 'nanastas-mit/pextant', 'size': '3541'}