module ToySolver.Converter.MaxSAT2NLPB
( convert
) where
import qualified ToySolver.Text.PBFile as PBFile
import qualified ToySolver.Text.MaxSAT as MaxSAT
convert :: MaxSAT.WCNF -> PBFile.Formula
convert
MaxSAT.WCNF
{ MaxSAT.topCost = top
, MaxSAT.clauses = cs
, MaxSAT.numVars = nv
} =
PBFile.Formula
{ PBFile.pbObjectiveFunction = Just obj
, PBFile.pbConstraints = cs2
, PBFile.pbNumVars = nv
, PBFile.pbNumConstraints = length cs2
}
where
obj = [(w, [l | l <- ls]) | (w,ls) <- cs, w /= top]
cs2 = [([(1,[l]) | l <- ls], PBFile.Ge, 1) | (w,ls) <- cs, w == top]