diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 815e9e7..9362df9 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,4 +1,4 @@ 0.1.1.0 ------- * parse* functions fails if the parser does not consume all of the inputs -* generate '#product=' and 'sizeproduct=' in header line of OPB/WBO files +* generate '#product=', 'sizeproduct=' and '#soft=' in header line of OPB/WBO files diff --git a/src/Data/PseudoBoolean/Builder.hs b/src/Data/PseudoBoolean/Builder.hs index 5c9a430..3c34827 100644 --- a/src/Data/PseudoBoolean/Builder.hs +++ b/src/Data/PseudoBoolean/Builder.hs @@ -60,6 +60,7 @@ wboBuilder wbo = size <> part1 <> part2 sp = Prelude.sum [IntSet.size tm | tm <- Set.toList p] size = fromString (printf "* #variable= %d #constraint= %d" nv nc) <> (if np >= 1 then fromString (printf " #product= %d sizeproduct= %d" np sp) else mempty) + <> fromString (printf " #soft= %d" (wboNumSoft wbo)) <> fromString "\n" part1 = case wboTopCost wbo of diff --git a/src/Data/PseudoBoolean/ByteStringBuilder.hs b/src/Data/PseudoBoolean/ByteStringBuilder.hs index d29c288..1ad68d0 100644 --- a/src/Data/PseudoBoolean/ByteStringBuilder.hs +++ b/src/Data/PseudoBoolean/ByteStringBuilder.hs @@ -66,6 +66,7 @@ wboBuilder wbo = size <> part1 <> part2 sp = Prelude.sum [IntSet.size tm | tm <- Set.toList p] size = string7 "* #variable= " <> intDec nv <> string7 " #constraint= " <> intDec nc <> (if np >= 1 then string7 " #product= " <> intDec np <> string7 " sizeproduct= " <> intDec sp else mempty) + <> string7 " #soft= %d" <> intDec (wboNumSoft wbo) <> char7 '\n' part1 = case wboTopCost wbo of diff --git a/src/Data/PseudoBoolean/Types.hs b/src/Data/PseudoBoolean/Types.hs index c1fce37..785b7bd 100644 --- a/src/Data/PseudoBoolean/Types.hs +++ b/src/Data/PseudoBoolean/Types.hs @@ -36,6 +36,7 @@ module Data.PseudoBoolean.Types , pbProducts , wboComputeNumVars , wboProducts + , wboNumSoft ) where import GHC.Generics (Generic) @@ -140,3 +141,6 @@ wboProducts softformula = Set.fromList $ do let tm2 = IntSet.fromList tm guard $ IntSet.size tm2 > 1 return tm2 + +wboNumSoft :: SoftFormula -> Int +wboNumSoft softformula = length [() | (Just _, _) <- wboConstraints softformula]