Haskell: how to treat big combinatorial Lists? -


just tried write program simulates simple system online game. idea behind is, let program calculate efficient set of items possible stat efficiency set. clarify bit more: you've got 8 item slots , 74 different items, can't use item twice, , doesn't matter item in slot. i'am not yet trying calculate 1 set of stats, i'am stuck way earlier!

so problem number of possibilities (74^8) before filtering , (74 choose 8) after filtering. program starts lagging when try head(permu' 2). since know haskell supposed work infinite lists, how work list of 899 trillion entries? know takes lot of capacity pc that's why here ask:

how treat big list in haskell can work it?

the function simplified looks this:

quicksort :: (ord a) => [a] -> [a] quicksort [] = [] quicksort [a] = [a] quicksort (x:xs) = (quicksort [y | y <- xs, y <= x]) ++ [x] ++ (quicksort [z | z <- xs , z > x])  eliminatedouble [] = [] eliminatedouble (x:xs) = if x `elem` xs eliminatedouble xs else x:(eliminatedouble xs)  permu' n | n>8 = error "8 max"          | otherwise = eliminatedouble (filter allsatisfied (generate n))          generate 0 = [[]]       generate x = [quicksort (a:xs) | <- [1..74], xs <- generate (x-1)]       allsatisfied [] = true       allsatisfied (x:xs) = (checkconstraint x xs) && (allsatisfied xs)       checkconstraint x xs = not (doubled x xs)       doubled x xs = x `elem` xs 

would interesting know how way cheaper.

thanks in advance, regards.

you're making more difficult needs be.

choose 0 xs = [[]] choose n [] = [] choose n (x:xs) = map (x:) (choose (n-1) xs) ++ choose n xs 

in interpreter, choose 5 [1..74] takes 22 seconds compute entries , choose 6 [1..74] takes 273 seconds. additionally, choose 8 [1..74] starts chugging through combinations straight away; estimate take 6 hours generate them all. n.b. in interpreter, no optimization or other fanciness going on; possibly go faster if give ghc chance figure out how.

assuming intend nontrivial computation on each element of choose 8 [1..74], suggest either schedule largish chunk of time or else think solutions not exhaustive search -- perhaps using heuristics approximate answer, or figuring out how pruning cut out large, uninteresting swaths of search space.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -