Created
March 25, 2018 19:42
-
-
Save espoirMur/41e69a1570ea8ed5ce349225f27e6871 to your computer and use it in GitHub Desktop.
Solution about player marking algorithm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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