Hi there,
I am tinkering with an optimal coloring algorithm for sparse autodiff. Here is the most basic constraint programming formulation I could find for partial distance-2 column coloring.
Problem statement: color all columns of a matrix such that if two columns have a non-zero coefficient in the same row, they have different colors.
using JuMP
using HiGHS
using SparseArrays
using Random
function partial_distance2_column_coloring(A)
m, n = size(A)
model = Model(optimizer_with_attributes(HiGHS.Optimizer, "time_limit" => 1.0))
# one color per column
@variable(model, 1 <= color[j=1:n] <= n, Int)
@variable(model, ncolors, Int)
# count and minimize number of distinct colors
@constraint(model, [ncolors; color] in MOI.CountDistinct(n + 1))
@objective(model, Min, ncolors)
# start values don't work??
for j in 1:n
set_start_value(color[j], j)
end
set_start_value(ncolors, n)
# all neighbors of a row must have distinct colors
for i in 1:m
neighbors = [j for j in 1:n if A[i, j]]
@constraint(model, color[neighbors] in MOI.AllDifferent(length(neighbors)))
end
optimize!(model)
@assert primal_status(model) == MOI.FEASIBLE_POINT
return round.(Int, value.(color))
end
A = sprand(MersenneTwister(0), Bool, 100, 100, 0.05) # too large to solve in 1s
partial_distance2_column_coloring(A)
Ideally, I’d like the solver to return a feasible solution no matter when it is cut off.
My problem is that the trivial start values I provide don’t seem to work: HiGHS tell me they are infeasible, even though they assign a different color to each column. As a result, it doesn’t find a feasible solution:
[more log]
Attempting to find feasible solution by solving LP for user-supplied values of discrete variables
Coefficient ranges:
Matrix [1e+00, 1e+02]
Cost [1e+00, 1e+00]
Bound [1e+00, 1e+02]
RHS [1e+00, 1e+02]
Presolving model
Problem status detected on presolve: Infeasible
[more log]
ERROR: AssertionError: primal_status(model) == MOI.FEASIBLE_POINT
Did I miss something obvious in the constraints? Or do I misunderstand the point of start_value
?