Skip to content

Commit

Permalink
Merge pull request #341 from PESchoenberg/develop
Browse files Browse the repository at this point in the history
Improved comments.
  • Loading branch information
PESchoenberg authored Jan 6, 2024
2 parents 5b0b7d7 + 145f6c6 commit e1d9c8d
Show file tree
Hide file tree
Showing 17 changed files with 418 additions and 239 deletions.
45 changes: 42 additions & 3 deletions grsp0.scm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
;; (Accessed: 29 July 2023).
;; - [14] https://www.gnu.org/software/guile/manual/html_node/Pipes.html
;; - [15] https://askubuntu.com/questions/859975/how-to-know-the-vertical-position-of-the-command-prompt

;; - [16] https://www.codeproject.com/Articles/5329247/How-to-Change-Text-Color-in-a-Linux-Terminal

(define-module (grsp grsp0)
#:use-module (grsp grsp3)
Expand Down Expand Up @@ -188,7 +188,9 @@
grsp-piped
clearl
grsp-clear-cup
grsp-repos))
grsp-repos
grsp-color-set
grsp-wrc))


;;;; pline - Displays string p_s1 p_l1 times in one line at the console.
Expand Down Expand Up @@ -1390,7 +1392,7 @@
;;
;; Keywords:
;;
;; - console, strings
;; - console, strings, justification
;;
;; Parameters:
;;
Expand Down Expand Up @@ -2162,6 +2164,7 @@
;; Output:
;;
;; - String.
;;
(define (grsp-b2s p_b1)
(let ((res1 ""))

Expand Down Expand Up @@ -2665,6 +2668,8 @@
(s1 "")
(s2 ""))

(grsp-color-set "fcyan")

;; Present exit option in all cases.
(grsp-ld "0 - Exit")

Expand All @@ -2682,6 +2687,8 @@

(loop (+ j1 1)))))

(grsp-color-set "fdefault")

(set! res1 (grsp-ask "? "))

res1))
Expand Down Expand Up @@ -2829,4 +2836,36 @@

res1))

;; grsp-color-set - Changes the terminal background and foregrond colors.
;;
;; Keyword:
;;
;; - terminal, colors
;;
;; Paramters:
;;
;; - p_s1: color identifier.
;;
;; Sources:
;;
;; - [16].
;;
(define (grsp-color-set p_s1)
(let ((s1 "")
(s2 "printf \"\\033[")
(s3 "m\""))

(set! s1 (grsp-n2s (gconstt p_s1)))
(system (strings-append (list s2 s1 s3) 0))))


;;;; grsp-wrc - Displays a "wrong choice message."
;;
;; Keywords:
;;
;; - info, errors
;;
(define (grsp-wrc)
(grsp-color-set "fred")
(grsp-askn (gconsts "wrc"))
(grsp-color-set "fdefault"))
102 changes: 94 additions & 8 deletions grsp1.scm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
(define-module (grsp grsp1)
#:use-module (grsp grsp0)
#:export (gconst
gconstt
gconsts
gconsten))

Expand Down Expand Up @@ -255,7 +256,7 @@
((equal? p_n1 "Asamkhyeya2")
(set! res (expt 10 (* 7 (expt 2 103)))))

;; Asamkhyeya 4 [1].
;; Asamkhyeya 4 [1].
((equal? p_n1 "Asamkhyeya4")
(set! res (expt 10 (* 10 (expt 2 104)))))

Expand Down Expand Up @@ -477,9 +478,9 @@
((equal? p_n1 "Yobi")
(set! res (expt 1024 8)))

;; -------------------------------------------------------------
;; -------------------------------------------------------------

;; Archimedes' constant. Pi [1][2].
;; Archimedes' constant. Pi [1][2].
((equal? p_n1 "A000796")
(set! res 3.14159265358979323846))

Expand Down Expand Up @@ -546,7 +547,7 @@
;; Riemann Z(-1) [1][2][3].
((equal? p_n1 "Z-1")
(set! res -1/12))

;; Riemann Z(-2) [1][2][3].
((equal? p_n1 "Z-2")
(set! res 0))
Expand Down Expand Up @@ -648,7 +649,7 @@
(set! res 2.80777024202851936522))

;; Robbins constant. Delta3 [1][2].
((equal? p_n1 "A073012")
((equal? p_n1 "A073012")
(set! res 0.66170718226717623515))

;; Prevost constant. Psi [1][2].
Expand Down Expand Up @@ -787,7 +788,7 @@
((equal? p_n1 "A074785")
(set! res 0.36651292058166432701))


;; --------------------------------------------------------------
;; Physics

Expand Down Expand Up @@ -1121,6 +1122,91 @@
res))


;;;; gconstt - Constants, terminal colors.
;;
;; Keywords:
;;
;; - constants.
;;
;; Parameters:
;;
;; - p_s1: string, constant identifier.
;;
(define (gconstt p_s1)
(let ((res1 0))

(cond ((equal? p_s1 "fdefault")
(set! res1 39))
((equal? p_s1 "bdefault")
(set! res1 49))
((equal? p_s1 "fblack")
(set! res1 30))
((equal? p_s1 "bblack")
(set! res1 40))
((equal? p_s1 "fdred")
(set! res1 31))
((equal? p_s1 "bdred")
(set! res1 41))
((equal? p_s1 "fdgreen")
(set! res1 32))
((equal? p_s1 "bdgreen")
(set! res1 42))
((equal? p_s1 "fdyellow")
(set! res1 33))
((equal? p_s1 "bdyellow")
(set! res1 43))
((equal? p_s1 "fdblue")
(set! res1 34))
((equal? p_s1 "bdblue")
(set! res1 44))
((equal? p_s1 "fdmagenta")
(set! res1 35))
((equal? p_s1 "bdmagenta")
(set! res1 45))
((equal? p_s1 "fdcyan")
(set! res1 36))
((equal? p_s1 "bdcyan")
(set! res1 46))
((equal? p_s1 "flgrey")
(set! res1 37))
((equal? p_s1 "blgrey")
(set! res1 47))
((equal? p_s1 "fdgrey")
(set! res1 90))
((equal? p_s1 "bdgrey")
(set! res1 100))
((equal? p_s1 "fred")
(set! res1 91))
((equal? p_s1 "bred")
(set! res1 101))
((equal? p_s1 "fgreen")
(set! res1 92))
((equal? p_s1 "bgreen")
(set! res1 102))
((equal? p_s1 "forange")
(set! res1 93))
((equal? p_s1 "borange")
(set! res1 103))
((equal? p_s1 "fblue")
(set! res1 94))
((equal? p_s1 "bblue")
(set! res1 104))
((equal? p_s1 "fmagenta")
(set! res1 95))
((equal? p_s1 "bmagenta")
(set! res1 105))
((equal? p_s1 "fcyan")
(set! res1 96))
((equal? p_s1 "bcyan")
(set! res1 106))
((equal? p_s1 "fwhite")
(set! res1 97))
((equal? p_s1 "bwhite")
(set! res1 107)))

res1))


;;;; gconsten - Constants, strings, in English.
;;
;; Keywords:
Expand Down Expand Up @@ -1232,8 +1318,8 @@
(set! res1 "Updated p_a1 "))
((equal? p_s1 "Vpa2ae")
(set! res1 "Value of p_a2 after eval "))
((equal? p_s1 "wrch")
((equal? p_s1 "wrc")
(set! res1 "Wrong choice. Please try again.\n")))

res1))

1 change: 1 addition & 0 deletions grsp10.scm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
;;;; General notes:
;;
;; - Read sources for limitations on function parameters.
;;


(define-module (grsp grsp10)
Expand Down
4 changes: 2 additions & 2 deletions grsp11.scm
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
;;
;; Keywords:
;;
;; - function, algebra, lists, lenght, quantity
;; - function, algebra, lists, lenght, quantity, listings
;;
;; Parameters:
;;
Expand Down Expand Up @@ -250,7 +250,7 @@
;;
;; Keywords:
;;
;; - function, algebra, lists
;; - function, algebra, lists, data, structures
;;
;; Parameters;
;;
Expand Down
48 changes: 26 additions & 22 deletions grsp12.scm
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
;; =============================================================================
;; =========================================================================
;;
;; grsp12.scm
;;
;; Evolutionary and genetic functions.
;;
;; =============================================================================
;; =========================================================================
;;
;; Copyright (C) 2021 - 2024 Pablo Edronkin (pablo.edronkin at yahoo.com)
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; it under the terms of the GNU Lesser General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;; You should have received a copy of the GNU Lesser General Public
;; License along with this program. If not, see
;; <https://www.gnu.org/licenses/>.
;;
;; =============================================================================
;; =========================================================================


;;;; General notes:
Expand All @@ -33,8 +34,9 @@
;; See code of functions used and their respective source files for more
;; credits and references.
;;
;; - [1] En.wikipedia.org. 2021. Differential evolution - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Differential_evolution
;; - [1] En.wikipedia.org. 2021. Differential evolution - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Differential_evolution
;; [Accessed 21 October 2021].


Expand All @@ -49,14 +51,14 @@
grsp-evo-mod1-evolve))


;;;; grsp-evo-mod1-ff1 - Calculates the fitness of each individual as a measure
;; of it attaining proximity to the problem's goal expressed as a succesive
;; base operation p_s1 on all elements corresponding to columns contaiend in
;; p_l1 of matrix p_a1. Differential evolution.
;;;; grsp-evo-mod1-ff1 - Calculates the fitness of each individual as a
;; measure of it attaining proximity to the problem's goal expressed as a
;; succesive base operation p_s1 on all elements corresponding to columns
;; contaiend in p_l1 of matrix p_a1. Differential evolution.
;;
;; Keywords:
;;
;; - function, evolution, genetic, differential
;; - function, evolution, genetic, differential, fitting
;;
;; Parameters:
;;
Expand Down Expand Up @@ -101,16 +103,18 @@
(if (<= i1 hm1)
(begin (set! r1 (grsp-matrix-opio p_s1 p_a1 i1))
(array-set! res1 r1 i1 p_n1)
;; Evaluate fitness as the inverse of absolute "distance" to the
;; goal (col 3 has fitness).
(array-set! res1 (abs (/ 1 (- p_g1 (array-ref res1 i1 p_n1)))) i1 3)
;; Evaluate fitness as the inverse of absolute "distance"
;; to the goal (col 3 has fitness).
(array-set! res1
(abs (/ 1 (- p_g1 (array-ref res1 i1 p_n1))))
i1 3)
(loop (+ i1 1)))))

res1))


;;;; grsp-evo-mod1-pop-create - Creates a population matrix according to the
;; following structure:
;;;; grsp-evo-mod1-pop-create - Creates a population matrix according to
;; the following structure:
;;
;; - Col 0: id.
;; - Col 1: status.
Expand Down Expand Up @@ -256,8 +260,8 @@

(set! i1 (in i1)))

;; At this point only the best solution attained should be returned (i.e.
;; individual or row with highest fitness value).
;; At this point only the best solution attained should be returned
;; (i.e. individual or row with highest fitness value).
(set! res1 (grsp-matrix-row-sort "#des" res1 3))
(set! res1 (grsp-matrix-row-selectn res1 '(0)))

Expand Down
Loading

0 comments on commit e1d9c8d

Please sign in to comment.