Skip to content

Instantly share code, notes, and snippets.

@espoirMur
Created March 25, 2018 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espoirMur/41e69a1570ea8ed5ce349225f27e6871 to your computer and use it in GitHub Desktop.
Save espoirMur/41e69a1570ea8ed5ce349225f27e6871 to your computer and use it in GitHub Desktop.
Solution about player marking algorithm.
def optimal_markings(input_graph):
"""
The following function will return the most optimal marking for an input graph.
To do it, we will try all possibles markings, and check if they are valid markings by using the previous function.
Once all valid markings are found,
we need to sort them according to the number of the element it required to achieve a full marking.
The most optimal markings are the markings with the lowest number of players.
"""
results_counts = []
for combination in itertools.product([1, 0], repeat=len(input_graph)):
results = combination
if valid_markings(results, input_graph):
results_counts.append((results.count(1), results))
optimal_required = sorted(results_counts, key = lambda x : x[0] )[0][0]
optimal_marking = list(filter( lambda x : x[0] == optimal_required, results_counts))
return optimal_marking[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment