示例#1
0
// chains must be in order of pb and be subsets of its literals
func (pb *Threshold) TranslateByMDDChain(chains Chains) {
	glob.A(!pb.Empty(), pb.Id, "works only for non-empty mdds")
	glob.A(pb.Positive(), pb.Id, "Weights need to be positive")
	glob.A(pb.Typ == LE, pb.Id, "works only on LE, but is", pb.Typ, pb.String())

	if len(chains) == 0 {
		pb.TransTyp = CMDD
	} else {
		pb.TransTyp = CMDDC
	}

	store := mdd.InitIntervalMdd(len(pb.Entries))
	topId, _, _, err := CreateMDDChain(&store, pb.K, pb.Entries, chains)
	store.Top = topId
	//store.Debug(true)

	if err != nil {
		pb.Err = err
		return
	}

	if *glob.MDD_redundant_flag {
		store.RemoveRedundants()
		//glob.D("remove redundant nodes in MDD", removed)
	}

	pb.Clauses.AddClauseSet(convertMDD2Clauses(store, pb))
}
示例#2
0
func TestMDDChains1(test *testing.T) {
	//glob.Debug_flag = true

	glob.D("TestMDDChains1")

	*glob.MDD_max_flag = 300000
	*glob.MDD_redundant_flag = false

	var t Threshold
	t.Entries = createEntries([]int64{1, 2, 1, 1, 3, 1})
	t.Typ = LE
	t.K = 5
	//t.Print10()

	{ // check
		store := mdd.InitIntervalMdd(len(t.Entries))
		_, _, _, s1 := CreateMDD(&store, t.K, t.Entries)
		//store.Debug(true)
		if s1 != nil {
			test.Fail()
		}
	}

	chain := Chain(t.Literals()) //createLiterals(i, 3)

	//fmt.Println("\n\n Chain on index", i, i+3)

	chains := Chains{chain[0:3], chain[3:6]}
	//chains[0].Print()

	store := mdd.InitIntervalMdd(len(t.Entries))
	_, _, _, s1 := CreateMDDChain(&store, t.K, t.Entries, chains)

	if s1 != nil {
		test.Fail()
	}
	if len(store.Nodes) != 6 {
		store.Debug(true)
		test.Fail()
	}
	//glob.Debug_flag = false
}
示例#3
0
func TestMDDChains2(test *testing.T) {
	//glob.Debug_flag = true

	glob.D("TestMDDChains")

	*glob.MDD_max_flag = 300000
	*glob.MDD_redundant_flag = false

	var t Threshold
	t.Entries = createEntries([]int64{1, 2, 1, 1, 3, 1, 3, 2, 1, 1, 1})
	t.Typ = LE
	t.K = 10
	//t.Print10()

	{ // check
		store := mdd.InitIntervalMdd(len(t.Entries))
		_, _, _, s1 := CreateMDD(&store, t.K, t.Entries)
		//store.Debug(true)
		if s1 != nil {
			test.Fail()
		}
	}

	chain := Chain(t.Literals()) //createLiterals(i, 3)

	chains := Chains{chain[1:3], chain[5:9]}

	store := mdd.InitIntervalMdd(len(t.Entries))
	_, _, _, s1 := CreateMDDChain(&store, t.K, t.Entries, chains)

	if s1 != nil {
		test.Fail()
	}
	if len(store.Nodes) != 31 {
		store.Debug(true)
		test.Fail()
	}
	//glob.Debug_flag = false
}
示例#4
0
func TestMDDRedundant(test *testing.T) {
	//glob.Debug_flag = true
	//glob.Debug_flag = false

	glob.D("TestMDDRedundant")
	*glob.MDD_max_flag = 300000
	*glob.MDD_redundant_flag = false

	var t Threshold
	t.Entries = createEntries([]int64{1, 2, 1, 1, 3, 1})
	t.Typ = LE
	t.K = 5

	store := mdd.InitIntervalMdd(len(t.Entries))
	CreateMDD(&store, t.K, t.Entries)

	if store.RemoveRedundants() != 5 {
		test.Fail()
	}
}