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
# souped up GCP | |
import numpy as np | |
from ortools.sat.python import cp_model | |
class GraphColouringCP: | |
def __init__( | |
self, | |
edge_array: np.array, |
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
import numpy as np | |
def greedy_graph_colouring(edge_array: np.array): | |
def color_nodes(graph): | |
color_map = {} | |
# Consider nodes in descending degree | |
for node in sorted(graph, key=lambda x: len(graph[x]), reverse=True): | |
neighbor_colors = set(color_map.get(neigh) for neigh in graph[node]) | |
color_map[node] = next( | |
color for color in range(len(graph)) if color not in neighbor_colors |
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
import numpy as np | |
from typing import Union | |
def create_test_instance( | |
num_nodes: int, | |
edge_density_power_exponent: float, | |
edge_density_lb: float, | |
edge_density_ub: float, | |
seed: Union[int, None] = None, | |
verbose: bool=False |
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
# simple GCP | |
import numpy as np | |
from ortools.sat.python import cp_model | |
class GraphColouringCP: | |
def __init__( | |
self, | |
edge_array: np.array, |