module Interfaces.MZinHaskell (
module Interfaces.MZAST,
module Interfaces.FZSolutionParser,
module Interfaces.MZPrinter,
iTestModel,
testModel,
writeData
) where
import Interfaces.Auxiliary
import System.Process
#ifdef unix
import System.FilePath.Posix
#else
import System.FilePath.Windows
#endif
import Interfaces.MZPrinter
import Interfaces.FZSolutionParser
import Interfaces.MZAST hiding (UserD, PrefBop)
iTestModel :: MZModel -> IO ()
iTestModel m = do
putStrLn "Enter MiniZinc model's filepath:"
path <- getLine
putStrLn "Is there a data file? If yes, provide its filepath:"
dpath <- getLine
putStrLn "Type \"fd\" for G12/FD solver or leave empty for choco solver."
solver <- getLine
putStrLn "Enter 0 to output all solutions."
mode <- getLine
testModel m path dpath solver mode
testModel :: MZModel
-> FilePath
-> FilePath
-> String
-> String
-> IO ()
testModel m mzn dtf s n = do
configuration <- parseConfig
let mz_dir = case minizinc configuration of
"" -> addTrailingPathSeparator "."
str -> addTrailingPathSeparator str
let mfzn = spaceFix $ mz_dir ++ "mzn2fzn"
let flatzinc = spaceFix $ mz_dir ++ "flatzinc"
writeFile (mzn) (Prelude.show $ printModel m)
readCreateProcess (shell (mfzn ++ mzn ++ dtf)) ""
let (filename, _) = splitExtension mzn
let opt = case n of
"0" -> " -a "
_ -> " "
res <- case s of
"" -> let antlr = antlr_path configuration
chocoParser = chocoparser configuration
chocoSolver = chocosolver configuration
in readCreateProcess (shell $ "java -cp ." ++ [searchPathSeparator] ++ chocoSolver ++ [searchPathSeparator] ++ chocoParser ++ [searchPathSeparator] ++ antlr ++ " org.chocosolver.parser.flatzinc.ChocoFZN" ++ opt ++ filename ++ ".fzn> " ++ filename ++ ".fzn.results.txt") ""
_ -> readCreateProcess (shell $ flatzinc ++ opt ++ "-b fd " ++ filename ++ ".fzn > " ++ filename ++ ".fzn.results.txt") ""
getSolution $ filename ++ ".fzn.results.txt"
writeData :: MZModel -> IO ()
writeData m = do
putStrLn "Enter MiniZinc datafile's filepath:"
datapath <- getLine
writeFile datapath (Prelude.show $ printModel m)