Hong-Phuc Bui
5 days ago 478693d804680fa6c206ce47159c0740a6f32d51
stundenplan/src/graphdemo.py
@@ -113,3 +113,27 @@
    def to_dot(self) -> str:
        pass
    def greedy_color(self, vertex_order:[int]) -> dict[int,int]:
        pass
def first_available(color_list:[]) -> int:
    color_set = set(color_list)
    count = 0
    while True:
        if count not in color_set:
            return count
        count += 1# count = count + 1
    pass
def greedy_color(g:Graph, vertex_order:[int]) -> dict[int,int]:
    color:dict[int,int] = {}
    for vertex in vertex_order:
        used_neighbor_colors = []
        for nbr in g.adjacent_of(vertex):
            if nbr in color:
                used_neighbor_colors.append(color[nbr])
        color[vertex] = first_available(used_neighbor_colors)
        pass
    return color