packages feed

pseudo-boolean 0.1.5.0 → 0.1.6.0

raw patch · 5 files changed

+95/−24 lines, 5 filesdep +voiddep ~basedep ~megaparsecdep ~tasty-hunitPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: void

Dependency ranges changed: base, megaparsec, tasty-hunit, tasty-quickcheck

API changes (from Hackage documentation)

- Data.PseudoBoolean.Megaparsec: opbParser :: (MonadParsec e s m, Token s ~ Char) => m Formula
+ Data.PseudoBoolean.Megaparsec: opbParser :: (MonadParsec e s m, Token s ~ Word8, IsString (Tokens s)) => m Formula
- Data.PseudoBoolean.Megaparsec: parseOPBByteString :: String -> ByteString -> Either (ParseError Char Dec) Formula
+ Data.PseudoBoolean.Megaparsec: parseOPBByteString :: String -> ByteString -> Either (ParseError Word8 Void) Formula
- Data.PseudoBoolean.Megaparsec: parseOPBFile :: FilePath -> IO (Either (ParseError Char Dec) Formula)
+ Data.PseudoBoolean.Megaparsec: parseOPBFile :: FilePath -> IO (Either (ParseError Word8 Void) Formula)
- Data.PseudoBoolean.Megaparsec: parseOPBString :: String -> String -> Either (ParseError Char Dec) Formula
+ Data.PseudoBoolean.Megaparsec: parseOPBString :: String -> String -> Either (ParseError Word8 Void) Formula
- Data.PseudoBoolean.Megaparsec: parseWBOByteString :: String -> ByteString -> Either (ParseError Char Dec) SoftFormula
+ Data.PseudoBoolean.Megaparsec: parseWBOByteString :: String -> ByteString -> Either (ParseError Word8 Void) SoftFormula
- Data.PseudoBoolean.Megaparsec: parseWBOFile :: FilePath -> IO (Either (ParseError Char Dec) SoftFormula)
+ Data.PseudoBoolean.Megaparsec: parseWBOFile :: FilePath -> IO (Either (ParseError Word8 Void) SoftFormula)
- Data.PseudoBoolean.Megaparsec: parseWBOString :: String -> String -> Either (ParseError Char Dec) SoftFormula
+ Data.PseudoBoolean.Megaparsec: parseWBOString :: String -> String -> Either (ParseError Word8 Void) SoftFormula
- Data.PseudoBoolean.Megaparsec: wboParser :: (MonadParsec e s m, Token s ~ Char) => m SoftFormula
+ Data.PseudoBoolean.Megaparsec: wboParser :: (MonadParsec e s m, Token s ~ Word8, IsString (Tokens s)) => m SoftFormula

Files

CHANGELOG.markdown view
@@ -1,3 +1,7 @@+0.1.6.0+-------+* include #mincost=, #maxcost=, #sumcost= in the hint line of WBO files+ 0.1.5.0 ------- * support megaparsec-5.*
pseudo-boolean.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                pseudo-boolean-version:             0.1.5.0+version:             0.1.6.0 synopsis:            Reading/Writing OPB/WBO files used in pseudo boolean competition description:         Reading\/Writing OPB\/WBO files used in pseudo boolean competition homepage:            https://github.com/msakai/pseudo-boolean@@ -46,16 +46,17 @@      FlexibleContexts      OverloadedStrings   build-depends:-     base >=4.6.0.1 && <4.10,+     base >=4.6.0.1 && <4.11,      containers >=0.4.2.1,      parsec >=3.1.2 && <4,-     megaparsec >=4 && <6,+     megaparsec >=4 && <7,      bytestring >=0.9.2.1 && <0.11,      bytestring-builder,-     dlist >=0.7.0 && <0.8.0,+     dlist >=0.7.0 && <0.9.0,      attoparsec >=0.10.4.0,      deepseq >=1.3.0.0,-     hashable >=1.1.2.5 && <1.3.0.0+     hashable >=1.1.2.5 && <1.3.0.0,+     void   hs-source-dirs:      src   default-language:    Haskell2010 @@ -69,7 +70,7 @@     bytestring,     tasty >=0.10.1,     tasty-hunit ==0.9.*,-    tasty-quickcheck ==0.8.*,+    tasty-quickcheck >=0.8 && <0.10,     tasty-th,     HUnit,     QuickCheck >=2.5 && <3,
src/Data/PseudoBoolean/Builder.hs view
@@ -60,9 +60,16 @@     p = wboProducts wbo     np = Set.size p     sp = Prelude.sum [IntSet.size tm | tm <- Set.toList p]+    mincost =+      case [c | (Just c, _) <- wboConstraints wbo] of+        [] -> 1 -- this should not happen+        cs -> minimum cs+    maxcost = maximum $ 0 : [c | (Just c, _) <- wboConstraints wbo]+    sumcost = Prelude.sum [c | (Just c, _) <- wboConstraints wbo]     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 (printf " #mincost= %d #maxcost= %d #sumcost= %d" mincost maxcost sumcost)          <> fromString "\n"     part1 =        case wboTopCost wbo of
src/Data/PseudoBoolean/ByteStringBuilder.hs view
@@ -66,9 +66,18 @@     p = wboProducts wbo     np = Set.size p     sp = Prelude.sum [IntSet.size tm | tm <- Set.toList p]+    mincost =+      case [c | (Just c, _) <- wboConstraints wbo] of+        [] -> 1 -- this should not happen+        cs -> minimum cs+    maxcost = maximum $ 0 : [c | (Just c, _) <- wboConstraints wbo]+    sumcost = Prelude.sum [c | (Just c, _) <- wboConstraints wbo]     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= " <> intDec (wboNumSoft wbo)+         <> string7 " #mincost= " <> integerDec mincost+         <> string7 " #maxcost= " <> integerDec maxcost+         <> string7 " #sumcost= " <> integerDec sumcost          <> char7 '\n'     part1 =        case wboTopCost wbo of
src/Data/PseudoBoolean/Megaparsec.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE BangPatterns, FlexibleContexts, TypeFamilies, CPP, ConstraintKinds #-}+{-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -Wall #-} ----------------------------------------------------------------------------- -- |@@ -38,21 +39,46 @@ import Control.Applicative ((<*)) import Control.Monad import Data.ByteString.Lazy (ByteString)-import qualified Data.ByteString.Lazy as BL+import qualified Data.ByteString.Lazy.Char8 as BL import Data.Maybe+#if MIN_VERSION_megaparsec(6,0,0)+import Data.String+import Data.Word+import Data.Void+#endif import Text.Megaparsec+#if MIN_VERSION_megaparsec(6,0,0)+import Text.Megaparsec.Byte+#else import Text.Megaparsec.Prim (MonadParsec ())+#endif import Data.PseudoBoolean.Types import Data.PseudoBoolean.Internal.TextUtil +#if MIN_VERSION_megaparsec(6,0,0)++type C e s m = (MonadParsec e s m, Token s ~ Word8, IsString (Tokens s))++char8 :: C e s m => Char -> m Word8+char8 = char . fromIntegral . fromEnum++#else+ #if MIN_VERSION_megaparsec(5,0,0) type C e s m = (MonadParsec e s m, Token s ~ Char) #else type C e s m = (MonadParsec s m Char) #endif +char8 :: C e s m => Char -> m Char+char8 = char++#endif+ -- | Parser for OPB files-#if MIN_VERSION_megaparsec(5,0,0)+#if MIN_VERSION_megaparsec(6,0,0)+opbParser :: (MonadParsec e s m, Token s ~ Word8, IsString (Tokens s)) => m Formula+#elif MIN_VERSION_megaparsec(5,0,0) opbParser :: (MonadParsec e s m, Token s ~ Char) => m Formula #else opbParser :: (MonadParsec s m Char) => m Formula@@ -60,7 +86,9 @@ opbParser = formula  -- | Parser for WBO files-#if MIN_VERSION_megaparsec(5,0,0)+#if MIN_VERSION_megaparsec(6,0,0)+wboParser :: (MonadParsec e s m, Token s ~ Word8, IsString (Tokens s)) => m SoftFormula+#elif MIN_VERSION_megaparsec(5,0,0) wboParser :: (MonadParsec e s m, Token s ~ Char) => m SoftFormula #else wboParser :: (MonadParsec s m Char) => m SoftFormula@@ -84,7 +112,7 @@  hint :: C e s m => m (Int,Int) hint = try $ do-  _ <- char '*'+  _ <- char8 '*'   zeroOrMoreSpace   _ <- string "#variable="   zeroOrMoreSpace@@ -103,7 +131,7 @@ -- <comment>::= "*" <any_sequence_of_characters_other_than_EOL> <EOL> comment :: C e s m => m () comment = do-  _ <- char '*' +  _ <- char8 '*'    _ <- manyTill anyChar eol   space -- We relax the grammer and allow spaces in the beggining of next component.   return ()@@ -156,15 +184,19 @@ integer :: C e s m => m Integer integer = msum   [ unsigned_integer-  , char '+' >> unsigned_integer-  , char '-' >> liftM negate unsigned_integer+  , char8 '+' >> unsigned_integer+  , char8 '-' >> liftM negate unsigned_integer   ]  -- <unsigned_integer>::= <digit> | <digit><unsigned_integer> unsigned_integer :: C e s m => m Integer unsigned_integer = do   ds <- some digitChar+#if MIN_VERSION_megaparsec(6,0,0)+  return $! readUnsignedInteger (map (toEnum . fromIntegral) ds)+#else   return $! readUnsignedInteger ds+#endif  -- <relational_operator>::= ">=" | "=" relational_operator :: C e s m => m Op@@ -173,22 +205,22 @@ -- <variablename>::= "x" <unsigned_integer> variablename :: C e s m => m Var variablename = do-  _ <- char 'x'+  _ <- char8 'x'   i <- unsigned_integer   return $! fromIntegral i  -- <oneOrMoreSpace>::= " " [<oneOrMoreSpace>] oneOrMoreSpace :: C e s m => m ()-oneOrMoreSpace  = skipSome (char ' ')+oneOrMoreSpace  = skipSome (char8 ' ')  -- <zeroOrMoreSpace>::= [" " <zeroOrMoreSpace>] zeroOrMoreSpace :: C e s m => m ()--- zeroOrMoreSpace = skipMany (char ' ')+-- zeroOrMoreSpace = skipMany (char8 ' ') zeroOrMoreSpace = space -- We relax the grammer and allow more type of spacing  semi :: C e s m => m ()-semi = char ';' >> space+semi = char8 ';' >> space -- We relax the grammer and allow spaces in the beginning of next component.  {-@@ -212,18 +244,25 @@  -- <literal>::= <variablename> | "~"<variablename> literal :: C e s m => m Lit-literal = variablename <|> (char '~' >> liftM negate variablename)+literal = variablename <|> (char8 '~' >> liftM negate variablename)  -- | Parse a OPB format string containing pseudo boolean problem.+#if MIN_VERSION_megaparsec(6,0,0)+parseOPBString :: String -> String -> Either (ParseError Word8 Void) Formula+parseOPBString info s = parse (formula <* eof) info (BL.pack s)+#else #if MIN_VERSION_megaparsec(5,0,0) parseOPBString :: String -> String -> Either (ParseError Char Dec) Formula #else parseOPBString :: String -> String -> Either ParseError Formula #endif parseOPBString = parse (formula <* eof)+#endif  -- | Parse a OPB format lazy bytestring containing pseudo boolean problem.-#if MIN_VERSION_megaparsec(5,0,0)+#if MIN_VERSION_megaparsec(6,0,0)+parseOPBByteString :: String -> ByteString -> Either (ParseError Word8 Void) Formula+#elif MIN_VERSION_megaparsec(5,0,0) parseOPBByteString :: String -> ByteString -> Either (ParseError Char Dec) Formula #else parseOPBByteString :: String -> ByteString -> Either ParseError Formula@@ -231,7 +270,9 @@ parseOPBByteString = parse (formula <* eof)  -- | Parse a OPB file containing pseudo boolean problem.-#if MIN_VERSION_megaparsec(5,0,0)+#if MIN_VERSION_megaparsec(6,0,0)+parseOPBFile :: FilePath -> IO (Either (ParseError Word8 Void) Formula)+#elif MIN_VERSION_megaparsec(5,0,0) parseOPBFile :: FilePath -> IO (Either (ParseError Char Dec) Formula) #else parseOPBFile :: FilePath -> IO (Either ParseError Formula)@@ -280,25 +321,32 @@ -- <softconstraint>::= "[" <zeroOrMoreSpace> <unsigned_integer> <zeroOrMoreSpace> "]" <constraint> softconstraint :: C e s m => m SoftConstraint softconstraint = do-  _ <- char '['+  _ <- char8 '['   zeroOrMoreSpace   cost <- unsigned_integer   zeroOrMoreSpace-  _ <- char ']'+  _ <- char8 ']'   zeroOrMoreSpace -- XXX   c <- constraint   return (Just cost, c)  -- | Parse a WBO format string containing weighted boolean optimization problem.+#if MIN_VERSION_megaparsec(6,0,0)+parseWBOString :: String -> String -> Either (ParseError Word8 Void) SoftFormula+parseWBOString info s = parse (softformula <* eof) info (BL.pack s)+#else #if MIN_VERSION_megaparsec(5,0,0) parseWBOString :: String -> String -> Either (ParseError Char Dec) SoftFormula #else parseWBOString :: String -> String -> Either ParseError SoftFormula #endif parseWBOString = parse (softformula <* eof)+#endif  -- | Parse a WBO format lazy bytestring containing pseudo boolean problem.-#if MIN_VERSION_megaparsec(5,0,0)+#if MIN_VERSION_megaparsec(6,0,0)+parseWBOByteString :: String -> ByteString -> Either (ParseError Word8 Void) SoftFormula+#elif MIN_VERSION_megaparsec(5,0,0) parseWBOByteString :: String -> ByteString -> Either (ParseError Char Dec) SoftFormula #else parseWBOByteString :: String -> ByteString -> Either ParseError SoftFormula@@ -306,7 +354,9 @@ parseWBOByteString = parse (softformula <* eof)  -- | Parse a WBO file containing weighted boolean optimization problem.-#if MIN_VERSION_megaparsec(5,0,0)+#if MIN_VERSION_megaparsec(6,0,0)+parseWBOFile :: FilePath -> IO (Either (ParseError Word8 Void) SoftFormula)+#elif MIN_VERSION_megaparsec(5,0,0) parseWBOFile :: FilePath -> IO (Either (ParseError Char Dec) SoftFormula) #else parseWBOFile :: FilePath -> IO (Either ParseError SoftFormula)