coloring[idx] += gamma * np.dot(r, u[short_idx])
                short_idx += 1
        for (idx, flag) in enumerate(alive_points):
            if flag:
                if (not (inf_alive <= coloring[idx]
                         and coloring[idx] <= sup_alive)):
                    alive_points[idx] = False
                    num_alive_points -= 1
        if time_with_mod == print_per_time:
            print("t =", time, ", alive points =", num_alive_points, ",",
                  coloring)
            time_with_mod = 0
        time_with_mod += 1

    final_coloring = np.round(coloring)
    for idx in range(n):
        if final_coloring[idx] == 0:
            final_coloring[idx] = np.random.randint(0, 2) * 2 - 1
    print("Final coloring (float): ", coloring)
    print("Final coloring (int): ", final_coloring)


if __name__ == '__main__':
    graph = Hypergraph.random(2, 4)

    print("n =", graph.n, ", m =", graph.m)
    print("Incidence matrix:\n", graph.incidence)
    print("degree=", graph.degree)

    solve_beck_fiala(graph, print_per_time=100)
Esempio n. 2
0
    x = np.zeros(n)  # fractional
    l = math.ceil(math.log2(math.log2(m)))
    print("l =", l)
    alive_points = np.full(n, True)
    for i in range(0, l):
        x = sub_routine(graph, x, alive_points)

    x_int = np.copy(x)
    for i in range(0, n):
        if alive_points[i]:
            if random.random() <= (1 - x[i]) * 0.5:
                x_int[i] = -1
            else:
                x_int[i] = 1
    return x, x_int


if __name__ == '__main__':
    # For test
    np.random.seed(0)
    graph = Hypergraph.random(6, 6)
    np.random.seed()

    print("n =", graph.n, ", m =", graph.m)
    print("Incidence matrix:\n", graph.incidence)
    print("degree=", graph.degree)

    coloring, fractional = main_routine(graph)
    print("coloring =", coloring)
    print("fractional =", fractional)