Exemplo n.º 1
0
func setZerosDistanceToZero(n *coupling.Node, nonzero []*coupling.Node, exact [][]bool, d [][]float64, c *coupling.Coupling) {
	reachables := coupling.Reachable(n)

	for _, node := range nonzero {
		coupling.DeleteNodeInSlice(node, &reachables)
	}

	for _, node := range reachables {
		d[node.S][node.T] = 0
		exact[node.S][node.T] = true
	}
}
Exemplo n.º 2
0
func TestCorrectFilterNonZero(t *testing.T) {
	c, m, visited, exact, d := coupling.SetUpTest()

	w := matching.FindFeasibleMatching(m, 0, 3, &c)
	setpair.Setpair(m, w, exact, visited, d, &c)

	reachables := coupling.Reachable(w)
	nonZeroReachables := filterZeros(reachables, exact, d)

	assert.Equal(t, len(nonZeroReachables), 3, "the filtered node slice did not have length 3")
	assert.False(t, coupling.IsNodeInSlice(w.Adj[2][2].To, nonZeroReachables), "node (2,3) was not filtered")
	assert.True(t, coupling.IsNodeInSlice(w.Adj[0][0].To, nonZeroReachables), "node (0,1) was filtered")
	assert.True(t, coupling.IsNodeInSlice(w.Adj[3][2].To, nonZeroReachables), "node (2,5) was filtered")
	assert.False(t, coupling.IsNodeInSlice(w.Adj[2][2].To.Adj[0][1].To, nonZeroReachables), "node (1,1) was not filtered")
}
Exemplo n.º 3
0
func findNonZero(n *coupling.Node, exact [][]bool, d [][]float64, c *coupling.Coupling) []*coupling.Node {
	// finds all reachable from (s,t)
	reachables := coupling.Reachable(n)

	// remove nodes not exact or distance less than 0
	reachablesNonZero := filterZeros(reachables, exact, d)

	// every node can always reach itself, so we copy the reachablesNonZeros into the final nonZeros slice
	nonZeros := make([]*coupling.Node, len(reachablesNonZero))
	copy(nonZeros, reachablesNonZero)

	// finds all reachable using the successor slice Succ
	for _, node := range reachablesNonZero {
		nonZeros = findReverseReachable(node, nonZeros)
	}

	return nonZeros
}