ANNOUNCE: A Simple Genetic Algorithm in NewLisp...

Started by oofoe, September 17, 2016, 07:38:10 AM

Previous topic - Next topic

oofoe

Hi!



In my quest to construct a program to derive the question to the answer of Life, the Universe and Everything (which is, as any schoolchild knows, 42), I wrote a very simple genetic algorithm solver.



I don't mean simple as in "simple to use", I mean absolute braindead simple. By some definitions, this is not really a genetic algorithm because the "genome" is the same as the data being operated on (there is no "expression"), but it's a cute toy and somebody else might find it entertaining as well:



https://bitbucket.org/oofoe/ga/src/9523e44cb284aa8e9f030610d0e84e2d922ff10c/adder/?at=default">https://bitbucket.org/oofoe/ga/src/9523 ... at=default">https://bitbucket.org/oofoe/ga/src/9523e44cb284aa8e9f030610d0e84e2d922ff10c/adder/?at=default



I am currently hard at work on a new program which will use a genetic algorithm to do lossy image compression through vector shapes, just have to teach NewLisp about reading %.png files...
Testing can show the presence of bugs, but not their absence.

oofoe

#1
Incidentally, here's how to determine if a file is a png image using the standard libpng library:


;; C library functions.
(import "msvcrt.dll" "fopen")
(import "msvcrt.dll" "fread")

;; PNG library functions.
(import "libpng16-16.dll" "png_sig_cmp")

(define (pngfile? path)
  "( path -- f) Determines if path is a %.png file."

  (letn ((header "XXXXXXXX")
(fp (fopen path "rb")))
(fread header 1 (length header) fp)
(zero? (png_sig_cmp header 0 (length header)))))


Sorry, Windows only at this point. UNIX users please substitute library names as appropriate.
Testing can show the presence of bugs, but not their absence.

Lutz

#2
Genetic algorithms are great. You also might be interested in fuzzy logic. Similarly to genetic algorithms, fuzzy logic can solve mathematically complex problems in a simple way. This book uses newLISP for all examples:





A Practical Introduction to Fuzzy Logic using LISP

By Luis Argüelles Méndez (arguelles on this forum)



http://www.springer.com/us/book/9783319231853">http://www.springer.com/us/book/9783319231853