A successful run with the large scale set M.
# buckets = 10
fixed bucket size = 20
M=.?. 200#1000
10%~+/M
9757.2
Ideal set:
]IS=. ((,>:)<.av) #~(,~10&-) 10 * (-<.) x: av=.10%~+/M
9757 9757 9757 9757 9757 9757 9757 9757 9758 9758
ds IS
16
A few tries with phase 2 parameters:
ne=.100
ng=.8
mr=.8
ds +/&> U=.10&phaseII ^:_ {. 10 20 PHI M
16
+/&> U
9757 9757 9757 9758 9757 9757 9757 9757 9757 9758
But it could take (much) longer to obtain another 16 result. :-)
Things to do:
- possibility of variable bucket sizes
- make phase 2 an evolutionary algo (variable mutation parameter(s)) .
- simple & fast phase 1 generator
...
> NB. total difference sum of bucket sums
> ds=: [: +/ [: ;<@({. |@- }.)\.
>
> NB. kind of cross mutation on a pair of different buckets
> NB. just swapping 1 element each on the 'low' side of the sorted (/:~) bucket
> contents
> mutate=: 4 :0
> 'a b'=. y
> i=.?x<.#a
> j=.?x<.#b
> ((j{b) i} a);(i{a) j}b
> )
>
> phaseII=: 4 :0
> ne=.100 NB. # elements
> ng=.50 NB. # generations
> mr=.2 NB mutation argument
>
> b=. /:~&.> y
> ws=. ne $<b
> z=.i.0 0
> for. i.ng do.
> p=.i.0 0
> for_e. ws do.
> d=.>e
> en=. mr mutate d{~ ix=.2?x
> p=.p, en (ix) } d
> end.
> z=. z,m=. p {~(i.<./) ds@:(+/&>)"1 p=.p,b
> ws=. ne $< /:~&.> m
> end.
> z {~(i.<./) ds@:(+/&>)"1 z
> )
> * experiment with ne, ng and mr
>
>
> ----------------------------------------
>
> A very simple but not smart phaseI verb
>
> PHI=: 4 :0
> 'a b'=.x
> ns=.2000
> z=.([:<"1 x&$)"1 ns(([: , (,:y) $~ [) {~ (?~@#)) #y
> z {~(i.<./) ds@:(+/&>)"1 z
> )
>
--
Met vriendelijke groet,
=@@i
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm