Hcy2c-0.1.1.0: Generate C code for cycle algorithms

Safe HaskellNone
LanguageHaskell2010

Main

Synopsis

Documentation

maxNumCyForTest :: Int

Because the number of cycles and edges tried by quickcheck can blow up quickly, these are the ranges allowable for (reasonably) fast tests Tested on Macbook Pro 15", Late 2011, 8 GB RAM, 2.5 GHZ Intel Core i7, 64-bit

prop_readInt :: Int -> Property

This tests the readInt function in Cycles.IO (notice the little endian interpretation)

prop_readIntList :: [Int] -> Property

This tests the readIntList function in Cycles.IO (similar to s->read s :: [Int], but faster)

sort2 :: Ord a => [[a]] -> [[a]]

This function sorts an [[Ord a]] on both levels (because FindCy and MaxCy both use ordered lists for undirected graphs)

cutUntoChar :: String -> Char -> String

This function takes a string and char and returns everything up to (but not including) that char

readBins :: String -> [Int]

This function converts a string like "0101010101001010" into a list of Ints

solutionStrToTup :: String -> ([Int], Int)

This function converts a solution string (such as "[10101010, 2384]") to a (list of bins, number)

strSolutionPipe1 :: String -> [[Int]] -> (([Int], Int), [[Int]])

This is the first level of the pipe strSolutionPipe

strSolutionPipe2 :: (([Int], Int), [[Int]]) -> ([[Int]], Int)

This is the second level of the pipe strSolutionPipe

strSolutionPipe3 :: ([[Int]], Int) -> IO Bool

This is the third level of the pipe strSolutionPipe

strSolutionPipe :: String -> [[Int]] -> IO Bool

This function takes a solution string and a graph and returns whether the solution agrees with the graphToNumCycles interpretation

checkMaxCySolution :: FilePath -> IO Bool

This function takes a file (path) and checks each solution against the graphToNumCycles interpretation

cycleGraph :: Int -> [[Int]]

This is the cycleGraph $C_n$, composed of a single undirected cycle

completeGraph :: Int -> [[Int]]

This function returns the complete graph with n vertices

completeGraphNumCy :: Int -> Int

This function returns the number of undirected cycles in (completeGraph n) The formula is divided by k because with cycles of size k, there are k orientation of each cycle. cycles size k require three choices: n possibilities, n-1, n-2 etc. Sum[Product[(i - k + n)2 k, {i, 1, k}], {k, 3, n}] (Undirected cycles, '2' removed for directed cycles)

shuttleGraph :: Int -> [[Int]]

This function returns the shuttle graph of size n, which looks like |=|=|=| The following shows how the formula was derived: 3->1,4 4->2,3 5->3,6 6->4,5 n->n - 2, n - 1 + 2 * (mod n 2) The shuttle graph is good for debugging because of the following property: There are (n+1) cycles that are a cap or middle square (units) There are (n+0) cycles that are an adjacent pair of units There are (n-1) cycles that are an adjacent triple of units etc. Because of this property, this graph has exactly (2 + 3 n + n^2)/2 cycles (equal to TriangularNumber(n+1)). This graph has 8 + 3*n edges

shuttleGraphNumCy :: Int -> Int

Returns the number of undirected cycles in (shuttleGraph n)

wheelGraph :: Int -> [[Int]]

This function returns the wheel graph of size n Constructed by making the spokes from '0', adding all but one of the outer cycle, then adding the final edge This graph has 2*(n+1) edges

wheelGraphNumCy :: Int -> Int

For the wheel graph, starting with n == 4 (by mathematica's definition, isomorphic to K4), The nth graph is (n-1) triangles joined at a common central vertex and each joined to the next in a wheel. The number of cycles may be found as follows: ( 1 ) There are (n-1) 1-triangle cycles ( 2 ) There are (n-1) 2-triangle cycles ( . ) ... (n-2) There are (n-1) (n-2)-triangle cycles With the addition of the single cycle of all the triangles, this gives that there is a total of (n-1)*(n-2) + 1 cycles

resizeN :: Int -> Int -> Int

This function resizes an input for "sane" use in testing, based on facts about the graph given

listSwap :: [Int] -> [Int] -> [Int]

This function takes a list and the two first elements (if they exist) from swaps and swaps the elements at those indices, or those indices mod (the length of the list)

prop_listSwapReversible :: [Int] -> [Int] -> Property

This tests that listSwap is its own inverse for lists without duplicates

permuteList :: [Int] -> [Int] -> [Int]

This function performs listSwap on the list using the first two (if they exist) elements of seeds, removes the first element of seeds and repeats. Thus, it can take a list of seeds to permute the list in any fashion (as any permutation is the composition of some list of transpositions)

shuffleGraph :: [[Int]] -> [Int] -> [[Int]]

This function uses a list of seeds to shuffle the vertex labels (indices) in a graph

testNumCyShuffled :: [[Int]] -> Int -> t -> Property

This is a general monadic tester for the graphToNumCycles function, using a known result for the number of cycles testNumCyShuffled :: [[Int]] -> Int -> [Int] -> Property

testNumCy :: [[Int]] -> Int -> Property

This property takes a graph and a known result for the number of undirected cycles to test graphToNumCycles

prop_goodCycleGraphNumCy :: Int -> Property

This property checks that a cycle graph of any valid size has two (directed) cycles

prop_goodCycleGraphNumCyShuffled :: Int -> [Int] -> Property

This property check that a cycle graph of any valid size and permutation of vertex labels has two (directed) cycles

goodCompleteGraph :: Int -> [[Int]]

This function returns a complete graph with resized input

prop_goodCompleteGraphNumCy :: Int -> Property

This property performs as prop_goodCycleGraphNumCy, except for complete graphs

prop_goodCompleteGraphNumCyShuffled :: Int -> [Int] -> Property

This property performs as prop_goodCycleGraphNumCyShuffled, except for complete graphs

prop_goodShuttleGraphNumCy :: Int -> Property

This property performs as prop_goodCycleGraphNumCy, except for shuttle graphs

prop_goodShuttleGraphNumCyShuffled :: Int -> [Int] -> Property

This property performs as prop_goodCycleGraphNumCyShuffled, except for shuttle graphs

prop_goodWheelGraphNumCy :: Int -> Property

This property performs as prop_goodCycleGraphNumCy, except for wheel graphs

prop_goodWheelGraphNumCyShuffled :: Int -> [Int] -> Property

This property performs as prop_goodCycleGraphNumCyShuffled, except for wheel graphs

trimByLenMod :: [a] -> Int -> [a]

This function allows one to randomly trim a list of any size, given an arbitrary seed (here called moddedsize)

testMaxCy' :: [[Int]] -> Int -> Int -> IO Bool

This is the non-property form of testMaxCy

testMaxCy :: [[Int]] -> Int -> Int -> Property

This is a general monadic tester for the graphToMaxCyCode function, using graphToNumCycles to check a random subset of its results

maxsplitbits :: Int

This value should be kept small; it will generate 2^maxsplitbits MaxCy code pieces, each of which will generate an exponential (by back of a napkin calculation) number of possible solutions, each of which will be checked by graphToNumCycles.

prop_goodCompleteGraphMaxCy :: Int -> Int -> Int -> Property

This property checks the graphToMaxcyCode function for complete graphs of reasonable and valid size

prop_goodShuttleGraphMaxCy :: Int -> Int -> Int -> Property

This property checks the graphToMaxcyCode function for shuttle graphs of reasonable and valid size

prop_goodWheelGraphMaxCy :: Int -> Int -> Int -> Property

This property checks the graphToMaxcyCode function for wheel graphs of reasonable and valid size

makeMaxcyForAll :: [(String, [[Int]])] -> IO ()

makeCode :: (Int, [[Int]]) -> IO String

main' :: IO ()

Checks all properties with HSpec

prop_collectByInvertible :: Ord a => (a -> Bool) -> [a] -> Property

main'' :: IO ()

main :: IO ()