func (pb *Threshold) Evaluate(a sat.Assignment) (r int64) { for _, e := range pb.Entries { v, b := a[e.Literal.A.Id()] glob.DT(!b, "Literal not found in assignment: ", e.Literal.ToTxt()) if e.Literal.Sign { r += int64(v) * e.Weight } else { r += (1 - int64(v)) * e.Weight } } glob.D("evaluate", r, pb.Offset) return r - pb.Offset }
func CategorizeTranslate2(pbs []*Threshold) { //1) Categorize simplOcc := make(map[sat.Literal][]int, len(pbs)) // literal to list of simplifiers it occurs in complOcc := make(map[sat.Literal][]int, len(pbs)) // literal to list of complex pbs it occurs in litSets := make([]intsets.Sparse, len(pbs)) // pb.Id -> intsSet of literalIds nextId := 0 lit2id := make(map[sat.Literal]int, 0) // literal to its id for i, pb := range pbs { if pb.Empty() { glob.D("pb is empty. pb.Id:", pb.Id) continue } pb.Normalize(LE, true) pb.SortVar() pb.CatSimpl() switch pb.TransTyp { case UNKNOWN: addToCategory(&nextId, pb, complOcc, lit2id, &litSets[i]) case AMO, EX1: //fmt.Println(pb.Id, len(pbs)) //pb.Print10() addToCategory(&nextId, pb, simplOcc, lit2id, &litSets[i]) default: // already translated glob.DT(pb.Clauses.Size() == 0, "Translated pb should contain clauses, special case?", pb.Id) pb.Translated = true } } if *glob.Amo_chain_flag || *glob.Ex_chain_flag { doChaining(pbs, complOcc, simplOcc, lit2id, litSets) } for _, pb := range pbs { if pb.IsComplexTranslation() { sort.Sort(EntriesDescending(pb.Entries[pb.PosAfterChains():])) if *glob.Rewrite_same_flag { pb.RewriteSameWeights() //glob.D("rewrite same weights:", pb.Id, len(pb.Chains)) } //pb.Print10() if pb.Typ != OPT && len(pb.Chains) > 0 { //TODO: decide on what to use ... pb.TranslateByMDDChain(pb.Chains) //pbTMP := pb.Copy() //pbTMP.Chains = nil //pbTMP.TranslateBySN() //pb.Clauses = pbTMP.Clauses pb.Translated = true } } if !pb.Translated && pb.Typ != OPT { glob.A(len(pb.Chains) == 0, "At this point no chain.", pb) //glob.A(pb.Clauses.Size() == 0, pb.Id, pb, "not translation means also that there should not be any clauses.") pb.CategorizeTranslate1() pb.Translated = true } if pb.Err != nil { panic(pb.Err.Error()) } //pb.Print10() } }