Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph/coloring: warm start optimisation of exact coloring algorithm #1705

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

kortschak
Copy link
Member

@kortschak kortschak commented Aug 11, 2021

DO NOT MERGE

This is here to make the optimisation public. It can be used to demonstrate the improvement in the number of recursive calls, but it not yet complete since the underlying implementation of Dsatur is quite inefficient wrt allocations. This is something that I want to improve before I complete this addition so that the comparison between the optimisation and naive implementation can be made with respect to time as well.

The optimisation is in the final two commits, the first three being from #1615.

The graphs were obtained from https://mat.tepper.cmu.edu/COLOR/instances.html
and converted to graph6 using the following code:

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"

	"gonum.org/v1/gonum/graph/encoding/graph6"
	"gonum.org/v1/gonum/graph/simple"
)

func main() {
	g := simple.NewUndirectedGraph()
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		line := sc.Text()
		if len(line) == 0 || line[0] != 'e' {
			continue
		}
		f := strings.Fields(line)
		g.SetEdge(simple.Edge{F: node(f[1]), T: node(f[2])})
	}
	fmt.Printf("%q\n", graph6.Encode(g))
}

func node(s string) simple.Node {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return simple.Node(i)
}

To convert graphs (ASCII col format only), use `go run main.go < <input>.col'.
There is an optimisation that is available for the Dsatur recursive search
that takes advantage of the trivial observation that the colouring of a
maximum clique in the graph must be consistent with the colouring of the
graph and that a maximum clique will therefore constrain the colouring of
the graph. This means that if the maximum clique is first trivially coloured
the search can continue from there. However, if there are multiple co-equal
maximum cliques it is possible for a clique to be chosen that will force the
search down a pessimal search path, so we choose the clique to start from as
the clique with the least constraining effect on the rest of the graph. The
optimisation has the effect of excluding large sections of the search tree
with a small amount of initial work to assess the maximum cliques.

This change chooses the maximum clique with the lowest degree into the rest
of the graph and assigns colours to all its nodes and progresses from there.
@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2021

Codecov Report

Merging #1705 (9f1e9d8) into master (326e41e) will increase coverage by 0.13%.
The diff coverage is 90.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1705      +/-   ##
==========================================
+ Coverage   73.22%   73.36%   +0.13%     
==========================================
  Files         502      511       +9     
  Lines       59536    60462     +926     
==========================================
+ Hits        43598    44355     +757     
- Misses      13487    13605     +118     
- Partials     2451     2502      +51     
Impacted Files Coverage Δ
graph/coloring/coloring.go 90.30% <90.30%> (ø)
spatial/r3/vector.go 88.70% <0.00%> (-8.80%) ⬇️
graph/iterator/map.go 48.57% <0.00%> (-7.96%) ⬇️
mat/matrix.go 78.00% <0.00%> (-3.18%) ⬇️
mat/diagonal.go 75.20% <0.00%> (-2.78%) ⬇️
graph/multi/weighted_undirected.go 90.36% <0.00%> (-2.75%) ⬇️
graph/multi/weighted_directed.go 92.35% <0.00%> (-2.62%) ⬇️
interp/cubic.go 97.52% <0.00%> (-2.48%) ⬇️
mat/tridiag.go 87.83% <0.00%> (-1.90%) ⬇️
graph/multi/undirected.go 89.55% <0.00%> (-1.76%) ⬇️
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 326e41e...9f1e9d8. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants