a = spot.translate('a U b U c')

"""
Explanation: This notebook shows you different ways in which states or transitions can be highlighted in Spot.  
It should be noted that highlighting works using some special named properties: basically, two maps that are attached to the automaton, and associated state or edge numbers to color numbers.  This named properties are fragile: they will be lost if the automaton is transformed into a new automaton, and they can become meaningless of the automaton is modified in place (e.g., if the transitions or states are reordered).
Nonetheless, highlighting is OK to use right before displaying or printing the automaton.  The dot and hoa printer both know how to represent highlighted states and transitions.
Manual highlighting
End of explanation
"""


a.show('.#')

"""
Explanation: The # option of print_dot() can be used to display the internal number of each transition
End of explanation
"""


a.highlight_edges([2, 4, 5], 1)

"""
Explanation: Using these numbers you can selectively hightlight some transitions.  The second argument is a color number (from a list of predefined colors).
End of explanation
"""


a.highlight_edge(6, 2).highlight_states((0, 1), 0)

"""
Explanation: Note that these highlight_ functions work for edges and states, and come with both singular (changing the color of single state or edge) and plural versions.
They modify the automaton in place.
End of explanation
"""


a.highlight_states([False, True, True], 5)

"""
Explanation: The plural version can take a list or tuple of state numbers (as above) or of Booleans (as below).  In the latter case the indices of the True values give the states to highlight.
End of explanation
"""


print(a.to_str('HOA', '1'))
print()
print(a.to_str('HOA', '1.1'))

"""
Explanation: Saving to HOA 1.1
When saving to HOA format, the highlighting is only output if version 1.1 of the format is selected, because the headers spot.highlight.edges and spot.highlight.states contain dots, which are disallowed in version 1.  Compare these two outputs:
End of explanation
"""


b = spot.translate('X (F(Ga <-> b) & GF!b)'); b

r = b.accepting_run(); r

r.highlight(5) # the parameter is a color number

"""
Explanation: Highlighting a run
One use of this highlighting is to highlight a run in an automaton.
The following few command generate an automaton, then an accepting run on this automaton, and highlight that accepting run on the automaton.  Note that a run knows the automaton from which it was generated, so calling highlight() will directly decorate that automaton.
End of explanation
"""


b

"""
Explanation: The call of highlight(5) on the accepting run r modified the original automaton b:
End of explanation
"""


left = spot.translate('a U b')
right = spot.translate('GFa')
display(left, right)

prod = spot.product(left, right); prod

run = prod.accepting_run(); run

run.highlight(5)
# Note that by default project() needs to know on which side you project, but it cannot 
# guess it.  The left-side is assumed unless you pass True as a second argument.
run.project(left).highlight(5)
run.project(right, True).highlight(5)

display(prod, left, right)

"""
Explanation: Highlighting from a product
Pretty often, accepting runs are found in a product but we want to display them on one of the original automata.  This can be done by projecting the runs on those automata before displaying them.
End of explanation
"""


left2 = spot.translate('!b & FG a')
right2 = spot.translate('XXXb')
prod2 = spot.otf_product(left2, right2)  # Note "otf_product()"
run2 = prod2.accepting_run()
run2.project(left2).highlight(5)
run2.project(right2, True).highlight(5)
display(run2, prod2, left2, right2)

"""
Explanation: The projection also works for products generated on-the-fly, but the on-the-fly product itself cannot be highlighted (it does not store states or transitions).
End of explanation
"""


b = spot.translate('X (F(Ga <-> b) & GF!b)')
spot.highlight_nondet_states(b, 5)
spot.highlight_nondet_edges(b, 4)
b

"""
Explanation: Highlighting nondeterminism
Sometimes its is hard to locate non-deterministic states inside a large automaton.  Here are two functions that can help for that.
End of explanation
"""


spot.randomize(b); b

"""
Explanation: Disappearing highlights
As explained at the top of this notebook, named properties (such as highlights) are fragile, and you should not really on them being preserved across algorithms.  In-place algorithm are probably the worst, because they might modify the automaton and ignore the attached named properties.  
randomize() is one such in-place algorithm: it reorder states or transitions of the automaton.   By doing so it renumber the states and edges, and that process would completely invalidate the highlights information.  Fortunately randomize() know about highlights: it will preserve highlighted states, but it will drop all highlighted edges.
End of explanation
"""


spot.highlight_nondet_edges(b, 4)  # let's get those highlighted edges back
display(b, b.show('.<4'), b.show('.<2'))

"""
Explanation: Highlighting with partial output
For simplicity, rendering of partial automata is actually implemented by copying the original automaton and marking some states as "incomplete".  This also allows the same display code to work with automata generated on-the-fly.  However since there is a copy, propagating the highlighting information requires extra work. Let's make sure it has been done:
End of explanation
"""


aut = spot.translate('(b W Xa) & GF(c <-> Xb) | a', 'generic', 'det')
spot.highlight_languages(aut)
aut.show('.bas')

"""
Explanation: Highlighting languages
For deterministic automata, the function spot.highlight_languages() can be used to highlight states that recognize the same language.  This can be a great help in reading automata.  States with a colored border share their language, and states with a black border all have a language different from all other states.
End of explanation
"""


