Jim (trail-name Sagebrush) codes audio software for Windows, Linux, Android, and embedded systems. When not working at sagebrush.com, he enjoys backpacking, which this blog is about.
About 28 volunteers celebrated National Public Lands Day by building 1.0 miles of the 3.5 mile Landavaso Trail just west of Magdalena. Socorro Trails partnered with BLM Socorro and several Magdalena volunteers, with donations from Socorro Walmart and Tumbleweeds Cafe/SCOPE.
Mike and Marty from BLM had already roughed out the trail with a custom-built drag-plow, so volunteers used McLeods and pick-mattocks to remove grass and rock and smooth out trail, in rolling grassland among scattered juniper and piñon.
Rocky Mountain Youth Corps is expected to finish the trail next month. We look forward to hiking this trail… often!
Six NMVFO volunteers returned to the Jemez, picking up litter along dispersed campsites along Forest Road 144, in a joint project with NMWild and the Jemez Ranger District.
I do not know of a way to make gripping photos of people using litter pickup tools. But we did find that a litter picker makes a good improvised selfie-stick…
In our last post, we found a single Euler Graph that is a subset of the Gila National Forest trail system, but we were left with the question of how to find other, possibly better, solutions. We might try several alternatives, so the first thing is to save the input graph that we massaged by removing 1-nodes and collapsing 2-nodes from the full Gila trail graph, so we do not have to repeat that step each time we try something new. The Python library pickle is just what we need, as it will save any arbitrary Python object to disk so we only need to compute this initial graph once.
Recall that in a previous post we had found a function all_maximal_matchings(graph G) that should help us find candidates for longer Euler graphs than we found in our previous post. Unfortunately, for our size graph, the function is unbearably slow, so we have added a timing function to better gauge our progress.
Oof, over a day of computation, and no helpful results yet.
For n nodes, all_maximal_matchings() seems to be higher than order O(n³), too large for a graph with 128 odd nodes, and in practice the “worst” maximal matchings are discovered first. We need an alternative approach.
Recall that we used a library function networkx.algorithms.min_weight_matching() to find a single solution last time, and that function is rather fast, using the Blossom algorithm. As a first attempt, let us introduce some “noise”, or “fuzz “in the weights of the graph, and see if that results in alternate solutions that might be longer.
import random
def fuzz_min_weight_matching(Q):
T = nx.Graph()
for u, v, d in Q.edges(data=True):
len = d['length']
len = len * (1 + random.random())
T.add_edge(u,v,length=len)
return nx.min_weight_matching(T,weight='length')
We run this function many times, and see if we can find longer Euler loops. The results are displayed in an animated GIF file, using techniques adapted from the article Graph Optimization with NetworkX in Python. Each iteration we display a graph, and compare it to the current maximum length graph, using the function save_png(). Plotting onto map tiles is unnecessary, so let us simplify matters by drawing onto a white background.
(The bounds code is necessary to ensure that each PNG file is the same size and displays exactly the same map coordinates, otherwise the graphs jump around in the movie.)
Now, combine all those .PNG files into an animated GIF.
import glob
import numpy as np
import imageio.v3 as iio
import os
def make_circuit_video(image_path, movie_filename, fps=5):
# sorting filenames in order
filenames = glob.glob(image_path + 'img*.png')
filenames_sort_indices = np.argsort([int(os.path.basename(filename).split('.')[0][3:]) for filename in filenames])
filenames = [filenames[i] for i in filenames_sort_indices]
# make movie
frames = []
for filename in filenames:
frames.append(iio.imread(filename))
iio.imwrite(movie_filename, frames, duration = 1000/fps, loop=1)
The resulting animated GIF is optimized and displayed below:
Download the complete source code for this article here.
What is next to try? Gradient fuzz? A genetic search? Fixing some fundamental error I missed? Stay tuned (subscribed) until next time…