packages feed

combinatorial-problems-0.0.2: Test.hs~

import CombinatorialOptimisation.SAT 
import CombinatorialOptimisation.TSP
import FileFormat.SATLIB
import FileFormat.TSPLIB

import System.Random
import qualified Data.Map as M

import System.Directory

{- 
main :: IO()
main = do s<-loadCNFFile "./CBS_k3_n100_m403_b10_0.cnf"
          print s
          saveAsCNF "test.cnf" s

-}

{- 
-- checking basic Symmetric TSP code and mutator algorithms
main :: IO()
main = do gen<-newStdGen
          let meep = makeSymmetricTSPMap (2,5) 5 gen
          -- print meep
          let meep' = randomiseRoute gen meep
          print meep'
          print $ routeElementToIndex meep'
          print $ indexToRouteElement meep'
          print ""
          let meep'' = exchangeCities 1 1 meep'
          print meep''
          print $ routeElementToIndex meep''
          print $ indexToRouteElement meep''
          putStrLn $ showEdgeWeights meep''

-}

{-
main :: IO()
main = do let gen = mkStdGen 5
          let meep = makeSymmetricTSPMap ExplicitMatrix (2,5) 50 gen
          let meep' = makeSymmetricTSPMap TriangularMatrix (2,5) 50 gen
          putStrLn $ show $ showEdgeWeights meep == showEdgeWeights meep'

-}

{-
-- checking stability of arrays, rather than map
main :: IO()
main = do let gen = mkStdGen 5
          let gen' = mkStdGen 10
          let meep = makeEuclideanTSPMap ExplicitMatrix (2,8) (2,8) 100 gen
          let meep' = makeEuclideanTSPMap TriangularMatrix (2,8) (2,8) 100 gen
          let meep'' = makeEuclideanTSPMap Recomputation (2,8) (2,8) 100 gen
          putStrLn $ showEdgeWeights meep
          putStrLn ""
          putStrLn $ showEdgeWeights meep'
          putStrLn $ show $ (showEdgeWeights meep == showEdgeWeights meep') && (showEdgeWeights meep == showEdgeWeights meep'')
-}

{-
-- checking loading TSPs
main :: IO()
main = do b<-loadTSPFile Recomputation "../exampleProblems/ali535.tsp" 
          c<-loadTSPFile TriangularMatrix "../exampleProblems/ali535.tsp" 
          d<-loadTSPFile ExplicitMatrix "../exampleProblems/ali535.tsp" 
          putStrLn $ show $ (showEdgeWeights d == showEdgeWeights c) && (showEdgeWeights d == showEdgeWeights b)
-}

{-
-- still checking the loading of TSPs
main :: IO()
main = do b<-loadTSPFile ExplicitMatrix "../exampleProblems/brazil58.tsp" 
          putStrLn $ showEdgeWeights b -}

-- brute force loading
main :: IO()
main = do xs<-getDirectoryContents "../exampleProblems" >>= (\x->return (drop 2 x))
          mapM_ (\x->do b<-loadTSPFile ExplicitMatrix ("../exampleProblems/"++x)
                        if (numCities b < 1000) then print $ getLastEdge b  
                                                else print $ x++" too big for explicit") xs
          main2
  where
    getLastEdge t = let m = numCities t -1 in edgePrices t m m

problemFiles = ["brazil58.tsp","bayg29.tsp","bays29.tsp","brg180.tsp","dantzig42.tsp"]

customFilter :: [String]->IO [String]
customFilter [] = return []
customFilter (x:xs) = do b<-loadTSPFile ExplicitMatrix ("../exampleProblems/"++x)
                         if numCities b <1000 then customFilter xs
                                              else do ps<-customFilter xs
                                                      return (x:ps)

main2 :: IO()
main2 = do xs<-getDirectoryContents "../exampleProblems" >>= (\x->return (drop 2 x)) 
           xs' <-customFilter xs
           print xs'
           mapM_ (\x->do print x
                         b<-loadTSPFile Recomputation ("../exampleProblems/"++x)
                         print $ getLastEdge b ) xs' 
  where
    getLastEdge t = let m = numCities t -1 in edgePrices t m m