Skip to content

Commit

Permalink
DOCS: horizontal lighter gif
Browse files Browse the repository at this point in the history
  • Loading branch information
bruscalia committed Nov 17, 2023
1 parent 6f08a7e commit d7d2d5d
Show file tree
Hide file tree
Showing 25 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Welcome to `tsp-grasp`! A Python package with Heuristics for solving the Traveli
[Documentation](https://tsp-grasp.readthedocs.io/en/latest/)

<p align="center">
<img src="./assets/grasp.gif" width="300" title="icon tsp">
<img src="./assets/grasp_arc_horizontal.gif" width="600" title="icon tsp">
</p>

## Install
Expand Down
6 changes: 3 additions & 3 deletions assets/combine_gifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def combine_gifs(gif1_path, gif2_path, output_path):


if __name__ == "__main__":
gif1_path = 'greedy_arc.gif'
gif2_path = 'ls_arc.gif'
output_path = 'grasp_arc.gif'
gif1_path = 'greedy_arc_horizontal.gif'
gif2_path = 'ls_arc_horizontal.gif'
output_path = 'grasp_arc_horizontal.gif'
combine_gifs(gif1_path, gif2_path, output_path)
20 changes: 10 additions & 10 deletions assets/create_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def plot_frame(coordinates, solution):
fig, ax = plt.subplots(figsize=[3, 3], dpi=300)
fig, ax = plt.subplots(figsize=[6, 3], dpi=150)
tour = np.array(solution, dtype=int)
ax.scatter(coordinates[:, 0], coordinates[:, 1], color="#D2003C", s=4) #FF4EBF
ax.plot(coordinates[tour, 0], coordinates[tour, 1], color="#D2003C")
Expand All @@ -33,13 +33,13 @@ def create_gif(output: str, files: List[str], duration=50, **kwargs):
np.random.seed(12)

# Initialize data
N = 300
X = np.random.random((N, 2)) * np.array([[1, 1]])
N = 200
X = np.random.random((N, 2)) * np.array([[2, 1]])
D = squareform(pdist(X))

plot_frame(X, [])
filename = f"empty.png"
plt.savefig(filename, transparent=True, dpi=300)
plt.savefig(filename, transparent=True, dpi=150)

# Greedy phase
greedy = HistoryGreedyArc(seed=12)
Expand All @@ -57,30 +57,30 @@ def create_gif(output: str, files: List[str], duration=50, **kwargs):
plot_frame(X, s[:-1])
filename = f"tmp/greedy_frame_{j}.png"
greedy_frames.append(filename)
plt.savefig(filename, transparent=True, dpi=300)
plt.savefig(filename, transparent=True, dpi=150)
plt.close()

plot_frame(X, ls.history[0])
filename = f"tmp/greedy_frame_{j + 1}.png"
greedy_frames.append(filename)
plt.savefig(filename, transparent=True, dpi=300)
plt.savefig(filename, transparent=True, dpi=150)
plt.close()

ls_frames = []
for j, s in enumerate(ls.history):
plot_frame(X, s)
filename = f"tmp/ls_frame_{j}.png"
ls_frames.append(filename)
plt.savefig(filename, transparent=True, dpi=300)
plt.savefig(filename, transparent=True, dpi=150)
plt.close()

# Save last frame from LS
plot_frame(X, ls.history[-1])
plt.savefig("solution_arcs.png", transparent=True, dpi=300)
plt.savefig("solution_arcs_horizontal.png", transparent=True, dpi=150)

# Step 2: Convert PNGs into GIF
create_gif('greedy_arc.gif', greedy_frames, duration=30)
create_gif('ls_arc.gif', ls_frames, duration=150)
create_gif('greedy_arc_horizontal.gif', greedy_frames, duration=30)
create_gif('ls_arc_horizontal.gif', ls_frames, duration=150)

# Optionally, remove the PNGs to cleanup
for png_file in greedy_frames:
Expand Down
Binary file removed assets/empty.png
Binary file not shown.
Binary file removed assets/grasp.gif
Binary file not shown.
Binary file removed assets/grasp_arc.gif
Binary file not shown.
Binary file added assets/grasp_arc_horizontal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/grasp_compare.gif
Binary file not shown.
Binary file removed assets/grasp_insert.gif
Binary file not shown.
Binary file removed assets/greedy.gif
Binary file not shown.
Binary file removed assets/greedy_arc.gif
Binary file not shown.
Binary file removed assets/greedy_horizontal.gif
Binary file not shown.
Binary file removed assets/greedy_insert.gif
Binary file not shown.
Binary file removed assets/horizontal_empty.png
Binary file not shown.
Binary file removed assets/ls.gif
Binary file not shown.
Binary file removed assets/ls_arc.gif
Binary file not shown.
Binary file removed assets/ls_horizontal.gif
Binary file not shown.
Binary file removed assets/ls_insert.gif
Binary file not shown.
Binary file removed assets/solution.png
Binary file not shown.
Binary file removed assets/solution_arcs.png
Binary file not shown.
Binary file removed assets/solution_horizontal.png
Binary file not shown.
Binary file removed assets/solution_insert.png
Binary file not shown.
Binary file removed assets/tsp_1000.png
Binary file not shown.
Binary file added docs/source/_static/grasp_arc_horizontal.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Welcome to `tspgrasp`! A Python package with Heuristics for solving the Travelin
* :ref:`Simple coding example <use>`
* :doc:`Detailed examples <Examples>`

.. image:: _static/grasp.gif
.. image:: _static/grasp_arc_horizontal.gif
:alt: header
:align: center
:width: 300
:width: 600
:target: https://github.com/bruscalia/tsp-grasp.git


Expand Down

0 comments on commit d7d2d5d

Please sign in to comment.