示例#1
0
func PairwiseMajority(pp PreferenceProfile) Preference {
	u := ProfileUniverse(pp)

	return relation.NewFunctionBinaryRelation(u, func(x, y set.Element) bool {
		return CountPreferenceOf(x, y, pp) >= CountPreferenceOf(y, x, pp)
	})
}
示例#2
0
func BordaCounting(pp PreferenceProfile) Preference {
	u := ProfileUniverse(pp)

	return relation.NewFunctionBinaryRelation(u, func(x, y set.Element) bool {
		return ProfileBordaCount(x, pp) >= ProfileBordaCount(y, pp)
	})
}
示例#3
0
func WeightedMajority(pp PreferenceProfile, w func(uint) float64) Preference {
	u := ProfileUniverse(pp)

	return relation.NewFunctionBinaryRelation(u, func(x, y set.Element) bool {
		return CountWeightedPreferenceOf(x, y, pp, w) >= CountWeightedPreferenceOf(y, x, pp, w)
	})
}
	"testing"

	"github.com/nlandolfi/set"
	"github.com/nlandolfi/set/relation"
)

var numbers set.Interface = set.New()

func init() {
	for n := 0; n < 100; n++ {
		numbers.Add(n)
	}
}

var equality relation.AbstractInterface = relation.NewFunctionBinaryRelation(numbers, func(x, y set.Element) bool {
	return x == y
})

var lessEqual relation.AbstractInterface = relation.NewFunctionBinaryRelation(numbers, func(x, y set.Element) bool {
	return x.(int) <= y.(int)
})

func BenchmarkSymmetric(b *testing.B) {
	for n := 0; n < b.N; n++ {
		if relation.Symmetric(equality) != true {
			b.Fatalf("The equality relation should be symmetric")
		}
	}
}

func BenchmarkTransitive(b *testing.B) {